]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr: expose CRUSHMap.find_roots() 41552/head
authorKefu Chai <kchai@redhat.com>
Wed, 26 May 2021 12:05:29 +0000 (20:05 +0800)
committerKefu Chai <kchai@redhat.com>
Wed, 26 May 2021 12:08:00 +0000 (20:08 +0800)
so mgr module could use it to enumerate all nodes without parents

See-also: https://tracker.ceph.com/issues/50971
Signed-off-by: Kefu Chai <kchai@redhat.com>
src/mgr/PyOSDMap.cc
src/pybind/mgr/ceph_module.pyi
src/pybind/mgr/mgr_module.py

index a4715d67352166032806296f0916a926259a66fc..70813ca528773dd60d242e21ae9739c315455ce2 100644 (file)
@@ -575,6 +575,19 @@ static PyObject *crush_get_item_weight(BasePyCRUSH *self, PyObject *args)
   return PyFloat_FromDouble(self->crush->get_item_weightf(item));
 }
 
+static PyObject *crush_find_roots(BasePyCRUSH *self)
+{
+  set<int> roots;
+  self->crush->find_roots(&roots);
+  PyFormatter f;
+  f.open_array_section("roots");
+  for (auto root : roots) {
+    f.dump_int("root", root);
+  }
+  f.close_section();
+  return f.get();
+}
+
 static PyObject *crush_find_takes(BasePyCRUSH *self, PyObject *obj)
 {
   set<int> takes;
@@ -618,6 +631,8 @@ PyMethodDef BasePyCRUSH_methods[] = {
     "Get item name"},
   {"_get_item_weight", (PyCFunction)crush_get_item_weight, METH_VARARGS,
     "Get item weight"},
+  {"_find_roots", (PyCFunction)crush_find_roots, METH_NOARGS,
+   "Find all tree roots"},
   {"_find_takes", (PyCFunction)crush_find_takes, METH_NOARGS,
     "Find distinct TAKE roots"},
   {"_get_take_weight_osd_map", (PyCFunction)crush_get_take_weight_osd_map,
index 2a7f2d2711e5c06403c88ea4a6cd08f918af8b8e..75575aeca150f2df17349c65f139428a5ed476b9 100644 (file)
@@ -33,6 +33,7 @@ class BasePyCRUSH(object):
     def _dump(self):...
     def _get_item_weight(self, item):...
     def _get_item_name(self, item):...
+    def _find_roots(self):...
     def _find_takes(self):...
     def _get_take_weight_osd_map(self, root):...
 
index 07ed288199eaaec4bd06812b540989f11522b846..ef418e84cac2666a7973779f3fd7450333561325 100644 (file)
@@ -221,6 +221,9 @@ class CRUSHMap(ceph_module.BasePyCRUSH):
     def find_takes(self) -> List[int]:
         return self._find_takes().get('takes', [])
 
+    def find_roots(self) -> List[int]:
+        return self._find_roots().get('roots', [])
+
     def get_take_weight_osd_map(self, root: int) -> Dict[int, float]:
         uglymap = self._get_take_weight_osd_map(root)
         return {int(k): v for k, v in uglymap.get('weights', {}).items()}