From 7858b5680432b156eedd7fd9babe5be87fdd2c20 Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Wed, 26 May 2021 20:05:29 +0800 Subject: [PATCH] mgr: expose CRUSHMap.find_roots() 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 --- src/mgr/PyOSDMap.cc | 15 +++++++++++++++ src/pybind/mgr/ceph_module.pyi | 1 + src/pybind/mgr/mgr_module.py | 3 +++ 3 files changed, 19 insertions(+) diff --git a/src/mgr/PyOSDMap.cc b/src/mgr/PyOSDMap.cc index a4715d6735216..70813ca528773 100644 --- a/src/mgr/PyOSDMap.cc +++ b/src/mgr/PyOSDMap.cc @@ -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 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 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, diff --git a/src/pybind/mgr/ceph_module.pyi b/src/pybind/mgr/ceph_module.pyi index 2a7f2d2711e5c..75575aeca150f 100644 --- a/src/pybind/mgr/ceph_module.pyi +++ b/src/pybind/mgr/ceph_module.pyi @@ -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):... diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 07ed288199eaa..ef418e84cac26 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -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()} -- 2.39.5