From: Xiaoxi Chen Date: Wed, 22 Nov 2017 07:57:35 +0000 (-0700) Subject: OSD/admin_socket: add get_mapped_pools X-Git-Tag: v13.0.1~76^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F19112%2Fhead;p=ceph.git OSD/admin_socket: add get_mapped_pools get_mapped_pools will return all pool_id that mapped to the paticular OSD. It is super useful for monitoring system that want to **group** OSDs based on application. PoolID is a nature grouping tag to be attached to OSDs. Signed-off-by: Xiaoxi Chen --- diff --git a/src/osd/OSD.cc b/src/osd/OSD.cc index 901b518dca3..2613b28d9ac 100644 --- a/src/osd/OSD.cc +++ b/src/osd/OSD.cc @@ -2074,6 +2074,14 @@ public: } }; +std::set OSD::get_mapped_pools() { + std::set pools; + RWLock::RLocker l(pg_map_lock); + for (const auto &i : pg_map) + pools.insert(i.first.pool()); + return pools; +} + bool OSD::asok_command(string admin_command, cmdmap_t& cmdmap, string format, ostream& ss) { @@ -2292,6 +2300,11 @@ will start to track new ops received afterwards."; f->open_object_section("compact_result"); f->dump_float("elapsed_time", duration); f->close_section(); + } else if (admin_command == "get_mapped_pools") { + f->open_object_section("mapped_pools"); + set poollist = get_mapped_pools(); + f->dump_stream("pool_list") << poollist; + f->close_section(); } else { assert(0 == "broken asok registration"); } @@ -2822,6 +2835,10 @@ void OSD::final_init() " WARNING: Compaction probably slows your requests"); assert(r == 0); + r = admin_socket->register_command("get_mapped_pools", "get_mapped_pools", + asok_hook, + "dump pools whose PG(s) are mapped to this OSD."); + test_ops_hook = new TestOpsSocketHook(&(this->service), this->store); // Note: pools are CephString instead of CephPoolname because // these commands traditionally support both pool names and numbers @@ -3307,6 +3324,7 @@ int OSD::shutdown() 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"); delete asok_hook; asok_hook = NULL; diff --git a/src/osd/OSD.h b/src/osd/OSD.h index 9e3d4a0c84e..7b4e681714f 100644 --- a/src/osd/OSD.h +++ b/src/osd/OSD.h @@ -1944,6 +1944,8 @@ public: return pg_map.size(); } + std::set get_mapped_pools(); + protected: PG *_open_lock_pg(OSDMapRef createmap, spg_t pg, bool no_lockdep_check=false);