From: John Spray Date: Sat, 23 Sep 2017 17:21:47 +0000 (-0400) Subject: mgr: fix crashable DaemonStateIndex::get calls X-Git-Tag: v12.2.2~65^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F18412%2Fhead;p=ceph.git mgr: fix crashable DaemonStateIndex::get calls This function was recently fixed to return null on missing entries: handle that properly. Fixes: http://tracker.ceph.com/issues/17737 Signed-off-by: John Spray (cherry picked from commit ade4827d86bb2bc79466a2da040475651c2aae0d) --- diff --git a/src/mgr/PyModules.cc b/src/mgr/PyModules.cc index 5fa6df9cf7a5..6b3b50e599c9 100644 --- a/src/mgr/PyModules.cc +++ b/src/mgr/PyModules.cc @@ -119,10 +119,15 @@ PyObject *PyModules::list_servers_python() PyObject *PyModules::get_metadata_python( std::string const &handle, - const std::string &svc_name, + const std::string &svc_type, const std::string &svc_id) { - auto metadata = daemon_state.get(DaemonKey(svc_name, svc_id)); + auto metadata = daemon_state.get(DaemonKey(svc_type, svc_id)); + if (metadata == nullptr) { + derr << "Requested missing service " << svc_type << "." << svc_id << dendl; + Py_RETURN_NONE; + } + Mutex::Locker l(metadata->lock); PyFormatter f; f.dump_string("hostname", metadata->hostname); @@ -135,10 +140,15 @@ PyObject *PyModules::get_metadata_python( PyObject *PyModules::get_daemon_status_python( std::string const &handle, - const std::string &svc_name, + const std::string &svc_type, const std::string &svc_id) { - auto metadata = daemon_state.get(DaemonKey(svc_name, svc_id)); + auto metadata = daemon_state.get(DaemonKey(svc_type, svc_id)); + if (metadata == nullptr) { + derr << "Requested missing service " << svc_type << "." << svc_id << dendl; + Py_RETURN_NONE; + } + Mutex::Locker l(metadata->lock); PyFormatter f; for (const auto &i : metadata->service_status) { diff --git a/src/mgr/PyModules.h b/src/mgr/PyModules.h index c7aad4e5df88..ef94c3b99379 100644 --- a/src/mgr/PyModules.h +++ b/src/mgr/PyModules.h @@ -69,10 +69,10 @@ public: PyObject *list_servers_python(); PyObject *get_metadata_python( std::string const &handle, - const std::string &svc_name, const std::string &svc_id); + const std::string &svc_type, const std::string &svc_id); PyObject *get_daemon_status_python( std::string const &handle, - const std::string &svc_name, const std::string &svc_id); + const std::string &svc_type, const std::string &svc_id); PyObject *get_counter_python( std::string const &handle, const std::string &svc_name,