mirror of
https://github.com/ceph/ceph
synced 2025-01-03 09:32:43 +00:00
Merge pull request #14802 from tchaikov/wip-mgr-cleanup
mgr: various cleanups Reviewed-by: Sage Weil <sage@redhat.com>
This commit is contained in:
commit
40699a61b2
@ -651,7 +651,7 @@ if (WITH_MGR)
|
||||
add_executable(ceph-mgr ${mgr_srcs}
|
||||
$<TARGET_OBJECTS:heap_profiler_objs>)
|
||||
target_include_directories(ceph-mgr PRIVATE "${PYTHON_INCLUDE_DIRS}")
|
||||
target_link_libraries(ceph-mgr mds osdc global-static common
|
||||
target_link_libraries(ceph-mgr osdc global-static common
|
||||
${Boost_PYTHON_LIBRARY} ${PYTHON_LIBRARIES} ${BLKID_LIBRARIES} ${CMAKE_DL_LIBS} ${ALLOC_LIBS})
|
||||
install(TARGETS ceph-mgr DESTINATION bin)
|
||||
endif (WITH_MGR)
|
||||
|
@ -310,4 +310,6 @@
|
||||
/* Support POWER8 instructions */
|
||||
#cmakedefine HAVE_POWER8
|
||||
|
||||
#cmakedefine PYTHON_EXECUTABLE "@PYTHON_EXECUTABLE@"
|
||||
|
||||
#endif /* CONFIG_H */
|
||||
|
@ -50,7 +50,7 @@ std::string handle_pyerror()
|
||||
#define dout_prefix *_dout << "mgr " << __func__ << " "
|
||||
|
||||
MgrPyModule::MgrPyModule(const std::string &module_name_)
|
||||
: module_name(module_name_), pModule(nullptr), pClass(nullptr),
|
||||
: module_name(module_name_),
|
||||
pClassInstance(nullptr)
|
||||
{}
|
||||
|
||||
@ -60,8 +60,6 @@ MgrPyModule::~MgrPyModule()
|
||||
gstate = PyGILState_Ensure();
|
||||
|
||||
Py_XDECREF(pClassInstance);
|
||||
Py_XDECREF(pClass);
|
||||
Py_XDECREF(pModule);
|
||||
|
||||
PyGILState_Release(gstate);
|
||||
}
|
||||
@ -70,7 +68,7 @@ int MgrPyModule::load()
|
||||
{
|
||||
// Load the module
|
||||
PyObject *pName = PyString_FromString(module_name.c_str());
|
||||
pModule = PyImport_Import(pName);
|
||||
auto pModule = PyImport_Import(pName);
|
||||
Py_DECREF(pName);
|
||||
if (pModule == nullptr) {
|
||||
derr << "Module not found: '" << module_name << "'" << dendl;
|
||||
@ -79,7 +77,8 @@ int MgrPyModule::load()
|
||||
|
||||
// Find the class
|
||||
// TODO: let them call it what they want instead of just 'Module'
|
||||
pClass = PyObject_GetAttrString(pModule, (const char*)"Module");
|
||||
auto pClass = PyObject_GetAttrString(pModule, (const char*)"Module");
|
||||
Py_DECREF(pModule);
|
||||
if (pClass == nullptr) {
|
||||
derr << "Class not found in module '" << module_name << "'" << dendl;
|
||||
return -EINVAL;
|
||||
@ -91,6 +90,7 @@ int MgrPyModule::load()
|
||||
auto pyHandle = PyString_FromString(module_name.c_str());
|
||||
auto pArgs = PyTuple_Pack(1, pyHandle);
|
||||
pClassInstance = PyObject_CallObject(pClass, pArgs);
|
||||
Py_DECREF(pClass);
|
||||
Py_DECREF(pyHandle);
|
||||
Py_DECREF(pArgs);
|
||||
if (pClassInstance == nullptr) {
|
||||
|
@ -43,8 +43,6 @@ class MgrPyModule
|
||||
{
|
||||
private:
|
||||
const std::string module_name;
|
||||
PyObject *pModule;
|
||||
PyObject *pClass;
|
||||
PyObject *pClassInstance;
|
||||
|
||||
std::vector<ModuleCommand> commands;
|
||||
|
@ -360,7 +360,8 @@ int PyModules::init()
|
||||
global_handle = this;
|
||||
|
||||
// Set up global python interpreter
|
||||
Py_Initialize();
|
||||
Py_SetProgramName(const_cast<char*>(PYTHON_EXECUTABLE));
|
||||
Py_InitializeEx(0);
|
||||
|
||||
// Some python modules do not cope with an unpopulated argv, so lets
|
||||
// fake one. This step also picks up site-packages into sys.path.
|
||||
|
Loading…
Reference in New Issue
Block a user