Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mgr: various cleanups #14802

Merged
merged 3 commits into from
Apr 27, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions src/include/config-h.in.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -310,4 +310,6 @@
/* Support POWER8 instructions */
#cmakedefine HAVE_POWER8

#cmakedefine PYTHON_EXECUTABLE "@PYTHON_EXECUTABLE@"

#endif /* CONFIG_H */
10 changes: 5 additions & 5 deletions src/mgr/MgrPyModule.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{}

Expand All @@ -60,8 +60,6 @@ MgrPyModule::~MgrPyModule()
gstate = PyGILState_Ensure();

Py_XDECREF(pClassInstance);
Py_XDECREF(pClass);
Py_XDECREF(pModule);

PyGILState_Release(gstate);
}
Expand All @@ -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;
Expand All @@ -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;
Expand All @@ -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) {
Expand Down
2 changes: 0 additions & 2 deletions src/mgr/MgrPyModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@ class MgrPyModule
{
private:
const std::string module_name;
PyObject *pModule;
PyObject *pClass;
PyObject *pClassInstance;

std::vector<ModuleCommand> commands;
Expand Down
3 changes: 2 additions & 1 deletion src/mgr/PyModules.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down