From ade4827d86bb2bc79466a2da040475651c2aae0d Mon Sep 17 00:00:00 2001 From: John Spray Date: Sat, 23 Sep 2017 13:21:47 -0400 Subject: [PATCH] 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 --- src/mgr/PyModules.cc | 18 ++++++++++++++---- src/mgr/PyModules.h | 4 ++-- 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/mgr/PyModules.cc b/src/mgr/PyModules.cc index 0fdf21654ab..ffbc6d9d384 100644 --- a/src/mgr/PyModules.cc +++ b/src/mgr/PyModules.cc @@ -121,10 +121,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); @@ -137,10 +142,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 894c42db3f3..3bb5449d156 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, -- 2.39.5