From 5c071a61f41f20e563909c90d2c054e97a4a747d Mon Sep 17 00:00:00 2001 From: John Spray Date: Mon, 9 Oct 2017 17:08:38 +0100 Subject: [PATCH] mgr: expose osdmap pg_to_up_acting_osds It's not efficient to have python calling this O(pg_num) times to find the pgs for an OSD, but I'm just shooting for something functional for now. Signed-off-by: John Spray --- src/mgr/PyOSDMap.cc | 38 ++++++++++++++++++++++++++++++++++++ src/pybind/mgr/mgr_module.py | 4 ++++ 2 files changed, 42 insertions(+) diff --git a/src/mgr/PyOSDMap.cc b/src/mgr/PyOSDMap.cc index f2381dc2cf084..4ec585d50fa34 100644 --- a/src/mgr/PyOSDMap.cc +++ b/src/mgr/PyOSDMap.cc @@ -217,6 +217,42 @@ BasePyOSDMap_dealloc(BasePyOSDMap *self) Py_TYPE(self)->tp_free(self); } +static PyObject *osdmap_pg_to_up_acting_osds(BasePyOSDMap *self, PyObject *args) +{ + int pool_id = 0; + int ps = 0; + if (!PyArg_ParseTuple(args, "ii:pg_to_up_acting_osds", + &pool_id, &ps)) { + return nullptr; + } + + std::vector up; + int up_primary; + std::vector acting; + int acting_primary; + pg_t pg_id(ps, pool_id); + self->osdmap->pg_to_up_acting_osds(pg_id, + &up, &up_primary, + &acting, &acting_primary); + + // (Ab)use PyFormatter as a convenient way to generate a dict + PyFormatter f; + f.dump_int("up_primary", up_primary); + f.dump_int("acting_primary", acting_primary); + f.open_array_section("up"); + for (const auto &i : up) { + f.dump_int("osd", i); + } + f.close_section(); + f.open_array_section("acting"); + for (const auto &i : acting) { + f.dump_int("osd", i); + } + f.close_section(); + + return f.get(); +} + PyMethodDef BasePyOSDMap_methods[] = { {"_get_epoch", (PyCFunction)osdmap_get_epoch, METH_NOARGS, "Get OSDMap epoch"}, @@ -234,6 +270,8 @@ PyMethodDef BasePyOSDMap_methods[] = { "Calculate new pg-upmap values"}, {"_map_pool_pgs_up", (PyCFunction)osdmap_map_pool_pgs_up, METH_VARARGS, "Calculate up set mappings for all PGs in a pool"}, + {"_pg_to_up_acting_osds", (PyCFunction)osdmap_pg_to_up_acting_osds, METH_VARARGS, + "Calculate up+acting OSDs for a PG ID"}, {NULL, NULL, 0, NULL} }; diff --git a/src/pybind/mgr/mgr_module.py b/src/pybind/mgr/mgr_module.py index fd427bd074047..700f624d1ac56 100644 --- a/src/pybind/mgr/mgr_module.py +++ b/src/pybind/mgr/mgr_module.py @@ -135,6 +135,10 @@ class OSDMap(ceph_module.BasePyOSDMap): def map_pool_pgs_up(self, poolid): return self._map_pool_pgs_up(poolid) + def pg_to_up_acting_osds(self, pool_id, ps): + return self._pg_to_up_acting_osds(self._handle, pool_id, ps) + + class OSDMapIncremental(ceph_module.BasePyOSDMapIncremental): def get_epoch(self): return self._get_epoch() -- 2.39.5