]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
common/admin_socket: add new api unregister_commands(AdminSocketHook *hook) 21718/head
authorJianpeng Ma <jianpeng.ma@intel.com>
Sat, 5 May 2018 02:11:18 +0000 (10:11 +0800)
committerJianpeng Ma <jianpeng.ma@intel.com>
Sat, 5 May 2018 02:11:18 +0000 (10:11 +0800)
We can unregister all commands which belong to this hook. Make code
looks clean and avoid forgeting unregister command.

Signed-off-by: Jianpeng Ma <jianpeng.ma@intel.com>
src/client/Client.cc
src/common/admin_socket.cc
src/common/admin_socket.h
src/common/ceph_context.cc
src/mds/MDSDaemon.cc
src/mon/Monitor.cc
src/osd/OSD.cc
src/rgw/rgw_rados.cc
src/rgw/rgw_sync_trace.cc

index 131f80ce451b41ca35abd87673ffc8a9bd290144..642ae929ade5fb7f0979538424875ec891322182 100644 (file)
@@ -545,12 +545,7 @@ void Client::shutdown()
 
   cct->_conf->remove_observer(this);
 
-  AdminSocket* admin_socket = cct->get_admin_socket();
-  admin_socket->unregister_command("mds_requests");
-  admin_socket->unregister_command("mds_sessions");
-  admin_socket->unregister_command("dump_cache");
-  admin_socket->unregister_command("kick_stale_sessions");
-  admin_socket->unregister_command("status");
+  cct->get_admin_socket()->unregister_commands(&m_command_hook);
 
   if (ino_invalidate_cb) {
     ldout(cct, 10) << "shutdown stopping cache invalidator finisher" << dendl;
index d23ca645169f59a22abfdbddd29fed50427aaaa0..a49298c6b403a9e97acfcee44f1dbe24b7b4f386 100644 (file)
@@ -484,6 +484,25 @@ int AdminSocket::unregister_command(std::string_view command)
   return ret;
 }
 
+void AdminSocket::unregister_commands(const AdminSocketHook *hook)
+{
+  std::unique_lock l(lock);
+  auto i = hooks.begin();
+  while (i != hooks.end()) {
+    if (i->second.hook == hook) {
+      ldout(m_cct, 5) << __func__ << " " << i->first << dendl;
+
+      // If we are currently processing a command, wait for it to
+      // complete in case it referenced the hook that we are
+      // unregistering.
+      in_hook_cond.wait(l, [this]() { return !in_hook; });
+      hooks.erase(i++);
+    } else {
+      i++;
+    }
+  }
+}
+
 class VersionHook : public AdminSocketHook {
 public:
   bool call(std::string_view command, const cmdmap_t& cmdmap,
@@ -623,9 +642,7 @@ void AdminSocket::shutdown()
 
   retry_sys_call(::close, m_sock_fd);
 
-  unregister_command("version");
-  unregister_command("git_version");
-  unregister_command("0");
+  unregister_commands(version_hook.get());
   version_hook.reset();
 
   unregister_command("help");
index 2178d711cfeed6353d4711e8ff916781c5e908fb..ec3d5ae04fba21f3c8a4ea86c2569ec491db0ee5 100644 (file)
@@ -85,6 +85,11 @@ public:
    */
   int unregister_command(std::string_view command);
 
+  /*
+   * unregister all commands belong to hook.
+   */
+  void unregister_commands(const AdminSocketHook *hook);
+
   bool init(const std::string& path);
 
   void chown(uid_t uid, gid_t gid);
index f8988ca74644b95a2644b22dafc1eabf006fcb2a..80ee593dfeee82169344e3e134865b3f5ca236eb 100644 (file)
@@ -626,25 +626,7 @@ CephContext::~CephContext()
 
   delete _plugin_registry;
 
-  _admin_socket->unregister_command("perfcounters_dump");
-  _admin_socket->unregister_command("1");
-  _admin_socket->unregister_command("perf dump");
-  _admin_socket->unregister_command("perfcounters_schema");
-  _admin_socket->unregister_command("perf histogram dump");
-  _admin_socket->unregister_command("2");
-  _admin_socket->unregister_command("perf schema");
-  _admin_socket->unregister_command("perf histogram schema");
-  _admin_socket->unregister_command("perf reset");
-  _admin_socket->unregister_command("config show");
-  _admin_socket->unregister_command("config unset");
-  _admin_socket->unregister_command("config set");
-  _admin_socket->unregister_command("config get");
-  _admin_socket->unregister_command("config help");
-  _admin_socket->unregister_command("config diff");
-  _admin_socket->unregister_command("config diff get");
-  _admin_socket->unregister_command("log flush");
-  _admin_socket->unregister_command("log dump");
-  _admin_socket->unregister_command("log reopen");
+  _admin_socket->unregister_commands(_admin_hook);
   delete _admin_hook;
   delete _admin_socket;
 
index 7c752919a2b7ab70eae568c76f54c3ac8db8d082..a14c0e9e22bfe614b30b624ca1d03f48a0498471 100644 (file)
@@ -327,32 +327,7 @@ void MDSDaemon::set_up_admin_socket()
 
 void MDSDaemon::clean_up_admin_socket()
 {
-  AdminSocket *admin_socket = g_ceph_context->get_admin_socket();
-  admin_socket->unregister_command("status");
-  admin_socket->unregister_command("dump_ops_in_flight");
-  admin_socket->unregister_command("ops");
-  admin_socket->unregister_command("dump_blocked_ops");
-  admin_socket->unregister_command("dump_historic_ops");
-  admin_socket->unregister_command("dump_historic_ops_by_duration");
-  admin_socket->unregister_command("scrub_path");
-  admin_socket->unregister_command("tag path");
-  admin_socket->unregister_command("flush_path");
-  admin_socket->unregister_command("export dir");
-  admin_socket->unregister_command("dump cache");
-  admin_socket->unregister_command("cache status");
-  admin_socket->unregister_command("dump tree");
-  admin_socket->unregister_command("dump loads");
-  admin_socket->unregister_command("dump snaps");
-  admin_socket->unregister_command("session evict");
-  admin_socket->unregister_command("osdmap barrier");
-  admin_socket->unregister_command("session ls");
-  admin_socket->unregister_command("flush journal");
-  admin_socket->unregister_command("force_readonly");
-  admin_socket->unregister_command("get subtrees");
-  admin_socket->unregister_command("dirfrag split");
-  admin_socket->unregister_command("dirfrag merge");
-  admin_socket->unregister_command("dirfrag ls");
-  admin_socket->unregister_command("openfiles ls");
+  g_ceph_context->get_admin_socket()->unregister_commands(asok_hook);
   delete asok_hook;
   asok_hook = NULL;
 }
index 9c60431cb1884f27878e5484dfd5934753be5c15..31d46c38b845c990e2fd5327d87a235937e88a5c 100644 (file)
@@ -923,18 +923,7 @@ void Monitor::shutdown()
   g_conf->remove_observer(this);
 
   if (admin_hook) {
-    AdminSocket* admin_socket = cct->get_admin_socket();
-    admin_socket->unregister_command("mon_status");
-    admin_socket->unregister_command("quorum_status");
-    admin_socket->unregister_command("sync_force");
-    admin_socket->unregister_command("add_bootstrap_peer_hint");
-    admin_socket->unregister_command("quorum enter");
-    admin_socket->unregister_command("quorum exit");
-    admin_socket->unregister_command("ops");
-    admin_socket->unregister_command("sessions");
-    admin_socket->unregister_command("dump_historic_ops");
-    admin_socket->unregister_command("dump_historic_ops_by_duration");
-    admin_socket->unregister_command("dump_historic_slow_ops");
+    cct->get_admin_socket()->unregister_commands(admin_hook);
     delete admin_hook;
     admin_hook = NULL;
   }
index bbed5d14b92c73c07aee2e6182cbd1199ba9f710..92f70d6e6d7dedc4f7b5f54e3534d2416fe2bc7c 100644 (file)
@@ -3300,44 +3300,11 @@ int OSD::shutdown()
   }
 
   // unregister commands
-  cct->get_admin_socket()->unregister_command("status");
-  cct->get_admin_socket()->unregister_command("flush_journal");
-  cct->get_admin_socket()->unregister_command("dump_ops_in_flight");
-  cct->get_admin_socket()->unregister_command("ops");
-  cct->get_admin_socket()->unregister_command("dump_blocked_ops");
-  cct->get_admin_socket()->unregister_command("dump_historic_ops");
-  cct->get_admin_socket()->unregister_command("dump_historic_ops_by_duration");
-  cct->get_admin_socket()->unregister_command("dump_historic_slow_ops");
-  cct->get_admin_socket()->unregister_command("dump_op_pq_state");
-  cct->get_admin_socket()->unregister_command("dump_blacklist");
-  cct->get_admin_socket()->unregister_command("dump_watchers");
-  cct->get_admin_socket()->unregister_command("dump_reservations");
-  cct->get_admin_socket()->unregister_command("get_latest_osdmap");
-  cct->get_admin_socket()->unregister_command("heap");
-  cct->get_admin_socket()->unregister_command("set_heap_property");
-  cct->get_admin_socket()->unregister_command("get_heap_property");
-  cct->get_admin_socket()->unregister_command("dump_objectstore_kv_stats");
-  cct->get_admin_socket()->unregister_command("dump_scrubs");
-  cct->get_admin_socket()->unregister_command("calc_objectstore_db_histogram");
-  cct->get_admin_socket()->unregister_command("flush_store_cache");
-  cct->get_admin_socket()->unregister_command("dump_pgstate_history");
-  cct->get_admin_socket()->unregister_command("compact");
-  cct->get_admin_socket()->unregister_command("get_mapped_pools");
-  cct->get_admin_socket()->unregister_command("smart");
-  cct->get_admin_socket()->unregister_command("list_devices");
+  cct->get_admin_socket()->unregister_commands(asok_hook);
   delete asok_hook;
   asok_hook = NULL;
 
-  cct->get_admin_socket()->unregister_command("setomapval");
-  cct->get_admin_socket()->unregister_command("rmomapkey");
-  cct->get_admin_socket()->unregister_command("setomapheader");
-  cct->get_admin_socket()->unregister_command("getomap");
-  cct->get_admin_socket()->unregister_command("truncobj");
-  cct->get_admin_socket()->unregister_command("injectdataerr");
-  cct->get_admin_socket()->unregister_command("injectmdataerr");
-  cct->get_admin_socket()->unregister_command("set_recovery_delay");
-  cct->get_admin_socket()->unregister_command("trigger_scrub");
-  cct->get_admin_socket()->unregister_command("injectfull");
+  cct->get_admin_socket()->unregister_commands(test_ops_hook);
   delete test_ops_hook;
   test_ops_hook = NULL;
 
index 51c6ef990dfd766bf4ccee7d6a53e5c55d7f211a..91eeb425fe68c1a558169784c577a291fab8b4aa 100644 (file)
@@ -3683,14 +3683,7 @@ bool RGWIndexCompletionManager::handle_completion(completion_t cb, complete_op_d
 
 void RGWRados::finalize()
 {
-  auto admin_socket = cct->get_admin_socket();
-  for (auto cmd : admin_commands) {
-    int r = admin_socket->unregister_command(cmd[0]);
-    if (r < 0) {
-      lderr(cct) << "ERROR: fail to unregister admin socket command (r=" << r
-                 << ")" << dendl;
-    }
-  }
+  cct->get_admin_socket()->unregister_commands(this);
 
   if (run_sync_thread) {
     Mutex::Locker l(meta_sync_thread_lock);
index 38219f9cd6d0c824f138730d68cddd8456daf29f..912ad8f0dd8590159b0fdda6149406ac73283320 100644 (file)
@@ -127,11 +127,7 @@ void RGWSyncTraceManager::init(RGWRados *store)
 
 RGWSyncTraceManager::~RGWSyncTraceManager()
 {
-  AdminSocket *admin_socket = cct->get_admin_socket();
-  for (auto cmd : admin_commands) {
-    admin_socket->unregister_command(cmd[0]);
-  }
-
+  cct->get_admin_socket()->unregister_commands(this);
   service_map_thread->stop();
   delete service_map_thread;
 }