From 0c73e433ab6583fca6eea7678c23b469d643ae04 Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Thu, 27 Jul 2017 23:33:06 -0400 Subject: [PATCH] mgr/PyOSDMap: OSDMap.map_pool_pgs_up, CRUSHMap.get_item_name Signed-off-by: Sage Weil (cherry picked from commit a928bf62316c32f37dd1791192fd9a2ddaef0d33) --- src/mgr/PyOSDMap.cc | 50 ++++++++++++++++++++++++++++++++++++ src/pybind/mgr/mgr_module.py | 5 ++++ 2 files changed, 55 insertions(+) diff --git a/src/mgr/PyOSDMap.cc b/src/mgr/PyOSDMap.cc index 69bcea42a2ade..e630cadef3779 100644 --- a/src/mgr/PyOSDMap.cc +++ b/src/mgr/PyOSDMap.cc @@ -150,6 +150,37 @@ static PyObject *osdmap_calc_pg_upmaps(PyObject *self, PyObject *args) return PyInt_FromLong(r); } +static PyObject *osdmap_map_pool_pgs_up(PyObject *self, PyObject *args) +{ + PyObject *mapobj; + int poolid; + if (!PyArg_ParseTuple(args, "Oi:map_pool_pgs_up", + &mapobj, &poolid)) { + return nullptr; + } + OSDMap *osdmap = static_cast(PyCapsule_GetPointer(mapobj, nullptr)); + if (!osdmap) + return nullptr; + auto pi = osdmap->get_pg_pool(poolid); + if (!pi) + return nullptr; + map> pm; + for (unsigned ps = 0; ps < pi->get_pg_num(); ++ps) { + pg_t pgid(ps, poolid); + osdmap->pg_to_up_acting_osds(pgid, &pm[pgid], nullptr, nullptr, nullptr); + } + PyFormatter f; + for (auto p : pm) { + string pg = stringify(p.first); + f.open_array_section(pg.c_str()); + for (auto o : p.second) { + f.dump_int("osd", o); + } + f.close_section(); + } + return f.get(); +} + PyMethodDef OSDMapMethods[] = { {"get_epoch", osdmap_get_epoch, METH_O, "Get OSDMap epoch"}, {"get_crush_version", osdmap_get_crush_version, METH_O, "Get CRUSH version"}, @@ -163,6 +194,8 @@ PyMethodDef OSDMapMethods[] = { "Get pools that have CRUSH rules that TAKE the given root"}, {"calc_pg_upmaps", osdmap_calc_pg_upmaps, METH_VARARGS, "Calculate new pg-upmap values"}, + {"map_pool_pgs_up", osdmap_map_pool_pgs_up, METH_VARARGS, + "Calculate up set mappings for all PGs in a pool"}, {NULL, NULL, 0, NULL} }; @@ -282,6 +315,22 @@ static PyObject *crush_dump(PyObject *self, PyObject *obj) return f.get(); } +static PyObject *crush_get_item_name(PyObject *self, PyObject *args) +{ + PyObject *obj; + int item; + if (!PyArg_ParseTuple(args, "Oi:get_item_name", + &obj, &item)) { + return nullptr; + } + CrushWrapper *crush = static_cast( + PyCapsule_GetPointer(obj, nullptr)); + if (!crush->item_exists(item)) { + Py_RETURN_NONE; + } + return PyString_FromString(crush->get_item_name(item)); +} + static PyObject *crush_find_takes(PyObject *self, PyObject *obj) { CrushWrapper *crush = static_cast( @@ -322,6 +371,7 @@ static PyObject *crush_get_take_weight_osd_map(PyObject *self, PyObject *args) PyMethodDef CRUSHMapMethods[] = { {"dump", crush_dump, METH_O, "Dump map"}, + {"get_item_name", crush_get_item_name, METH_VARARGS, "Get item name"}, {"find_takes", crush_find_takes, METH_O, "Find distinct TAKE roots"}, {"get_take_weight_osd_map", crush_get_take_weight_osd_map, METH_VARARGS, "Get OSD weight map for a given TAKE root node"}, diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index 9f5781fbc5027..0806c9e1c55df 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -65,6 +65,8 @@ class OSDMap(object): inc._handle, max_deviation, max_iterations, pools) + def map_pool_pgs_up(self, poolid): + return ceph_osdmap.map_pool_pgs_up(self._handle, poolid) class OSDMapIncremental(object): def __init__(self, handle): @@ -101,6 +103,9 @@ class CRUSHMap(object): def dump(self): return ceph_crushmap.dump(self._handle) + def get_item_name(self, item): + return ceph_crushmap.get_item_name(self._handle, item) + def find_takes(self): return ceph_crushmap.find_takes(self._handle).get('takes',[]) -- 2.39.5