From 3394b70ba18cffa49317141ff444ba9990d6170b Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 19 Nov 2019 11:36:11 +0800 Subject: [PATCH] mon: register tell/asock commands using info from local_mon_commands since all tell/asock commands are listed in local_mon_command, and all of them are noforward, also all noforward commands are tell/asock commands. we can just use the information from local_mon_command to register them, to avoid the repeating, and for better readability. Signed-off-by: Kefu Chai --- src/mon/Monitor.cc | 92 +++++++++------------------------------------- 1 file changed, 17 insertions(+), 75 deletions(-) diff --git a/src/mon/Monitor.cc b/src/mon/Monitor.cc index f34cc1c55c8..8566ea0c464 100644 --- a/src/mon/Monitor.cc +++ b/src/mon/Monitor.cc @@ -850,81 +850,23 @@ int Monitor::preinit() // unlock while registering to avoid mon_lock -> admin socket lock dependency. l.unlock(); - - r = admin_socket->register_command("compact", admin_hook, - "cause compaction of monitor's " - "leveldb/rocksdb storage"); - ceph_assert(r == 0); - r = admin_socket->register_command("mon compact", admin_hook, - "cause compaction of monitor's " - "leveldb/rocksdb storage"); - ceph_assert(r == 0); - r = admin_socket->register_command("mon_status", admin_hook, - "show current monitor status"); - ceph_assert(r == 0); - r = admin_socket->register_command("quorum_status", - admin_hook, "show current quorum status"); - ceph_assert(r == 0); - r = admin_socket->register_command( - "sync_force " - //"name=yes_i_really_mean_it,type=CephBool,req=false", - "name=validate,type=CephChoices,strings=--yes-i-really-mean-it,req=false", - admin_hook, - "force sync of and clear monitor store"); - ceph_assert(r == 0); - r = admin_socket->register_command("add_bootstrap_peer_hint name=addr," - "type=CephIPAddr", - admin_hook, - "add peer address as potential bootstrap" - " peer for cluster bringup"); - ceph_assert(r == 0); - r = admin_socket->register_command("add_bootstrap_peer_hintv name=addrv," - "type=CephString", - admin_hook, - "add peer address vector as potential bootstrap" - " peer for cluster bringup"); - ceph_assert(r == 0); - r = admin_socket->register_command("quorum enter", - admin_hook, - "force monitor back into quorum"); - ceph_assert(r == 0); - r = admin_socket->register_command("quorum exit", - admin_hook, - "force monitor out of the quorum"); - ceph_assert(r == 0); - r = admin_socket->register_command("ops", - admin_hook, - "show the ops currently in flight"); - ceph_assert(r == 0); - r = admin_socket->register_command("sessions", - admin_hook, - "list existing sessions"); - ceph_assert(r == 0); - r = admin_socket->register_command("dump_historic_ops", - admin_hook, - "show recent ops"); - ceph_assert(r == 0); - r = admin_socket->register_command("dump_historic_ops_by_duration", - admin_hook, - "show recent ops, sorted by duration"); - ceph_assert(r == 0); - r = admin_socket->register_command("dump_historic_slow_ops", - admin_hook, - "show recent slow ops"); - ceph_assert(r == 0); - r = admin_socket->register_command("smart name=devid,type=CephString,req=false", - admin_hook, - "probe OSD devices for SMART data."); - ceph_assert(r == 0); - r = admin_socket->register_command( - "heap " \ - "name=heapcmd,type=CephChoices,strings=" \ - "dump|start_profiler|stop_profiler|release|get_release_rate|set_release_rate|stats " \ - "name=value,type=CephString,req=false", - admin_hook, - "show heap usage info (available only if compiled with tcmalloc)"); - ceph_assert(r == 0); - + // register tell/asock commands + for (const auto& command : local_mon_commands) { + // all asock commands are noforward, vice versa + if (!command.is_noforward()) { + continue; + } + const auto prefix = cmddesc_get_prefix(command.cmdstring); + if (prefix == "injectargs" || + prefix == "version" || + prefix == "tell") { + // not registerd by me + continue; + } + r = admin_socket->register_command(prefix, admin_hook, + command.helpstring); + ceph_assert(r == 0); + } l.lock(); // add ourselves as a conf observer -- 2.39.5