]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
OSD/admin_socket: add get_mapped_pools 19112/head
authorXiaoxi Chen <xiaoxchen@ebay.com>
Wed, 22 Nov 2017 07:57:35 +0000 (00:57 -0700)
committerXiaoxi Chen <xiaoxchen@ebay.com>
Fri, 24 Nov 2017 03:37:25 +0000 (20:37 -0700)
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 <xiaoxchen@ebay.com>
src/osd/OSD.cc
src/osd/OSD.h

index 901b518dca3cd1b9e046750f8c8ad89d7de477e0..2613b28d9ac75977ac7a2f613c37f0c456c4d8bc 100644 (file)
@@ -2074,6 +2074,14 @@ public:
   }
 };
 
+std::set<int> OSD::get_mapped_pools() {
+    std::set<int> 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<int> 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;
 
index 9e3d4a0c84e1b6d95eebc5d039ff2ce79d06ea45..7b4e681714f26368a51a84edc00d692397341a83 100644 (file)
@@ -1944,6 +1944,8 @@ public:
     return pg_map.size();
   }
 
+  std::set<int> get_mapped_pools();
+
 protected:
   PG   *_open_lock_pg(OSDMapRef createmap,
                      spg_t pg, bool no_lockdep_check=false);