Skip to content

Commit

Permalink
mgr: move injection to ClusterState
Browse files Browse the repository at this point in the history
Signed-off-by: Pere Diaz Bou <pdiazbou@redhat.com>
  • Loading branch information
pereman2 committed Jul 5, 2021
1 parent 2846141 commit 951b526
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 25 deletions.
10 changes: 0 additions & 10 deletions src/mgr/ActivePyModules.cc
Expand Up @@ -23,7 +23,6 @@
#include "mon/MonMap.h"

#include "mgr/MgrContext.h"
#include "mgr/Injector.h"

// For ::mgr_store_prefix
#include "PyModule.h"
Expand Down Expand Up @@ -164,17 +163,8 @@ PyObject *ActivePyModules::get_daemon_status_python(
return f.get();
}

bool inject_python_on() {
return g_conf().get_val<bool>("mgr_inject");
}
PyObject *ActivePyModules::get_python(const std::string &what)
{
if(inject_python_on()) {
PyObject *injected_map = Injector::get_python(what);
// Structures which have no injection implemented should
// return the usual PyObject*
if (injected_map != Py_None) return injected_map;
}
PyFormatter f;

// Drop the GIL, as most of the following blocks will block on
Expand Down
20 changes: 15 additions & 5 deletions src/mgr/ClusterState.h
Expand Up @@ -21,6 +21,7 @@
#include "osdc/Objecter.h"
#include "mon/MonClient.h"
#include "mon/PGMap.h"
#include "mgr/Injector.h"
#include "mgr/ServiceMap.h"

class MMgrDigest;
Expand Down Expand Up @@ -118,12 +119,21 @@ class ClusterState
return monc->with_monmap(std::forward<Args>(args)...);
}

template<typename... Args>
auto with_osdmap(Args &&... args) const ->
decltype(objecter->with_osdmap(std::forward<Args>(args)...))
bool inject_python_on() const {
return g_conf().get_val<bool>("mgr_inject");
}
template <typename Callback, typename ...Args>
auto with_osdmap(Callback&& cb, Args&& ...args) const ->
decltype(objecter->with_osdmap(std::forward<Callback>(cb),
std::forward<Args>(args)...))
{
ceph_assert(objecter != nullptr);
return objecter->with_osdmap(std::forward<Args>(args)...);
if(inject_python_on()) {
OSDMap *osdmap = Injector::get_osdmap();
return std::forward<Callback>(cb)(*osdmap, std::forward<Args>(args)...);
} else {
ceph_assert(objecter != nullptr);
return objecter->with_osdmap(std::forward<Callback>(cb), std::forward<Args>(args)...);
}
}

// call cb(osdmap, pg_map, ...args) with the appropriate locks
Expand Down
25 changes: 16 additions & 9 deletions src/mgr/Injector.cc
Expand Up @@ -9,35 +9,42 @@

#include "PyUtil.h"


using namespace std;

int64_t Injector::get_num_osds() {
return g_conf().get_val<int64_t>("mgr_inject_num_osds");
}

void Injector::mark_exists_osds(OSDMap* osdmap) {
for(int osd = 0; osd < Injector::get_num_osds(); osd++) {
// OSDMap::dump_osds filters not existent osds so we need
// to set the state so we dump non existent ones too
void Injector::mark_exists_osds(OSDMap *osdmap) {
for (int osd = 0; osd < Injector::get_num_osds(); osd++) {
osdmap->set_state(osd, CEPH_OSD_EXISTS);
}
}

PyObject* Injector::get_python(const std::string& what) {
PyObject *Injector::get_python(const std::string &what) {
PyFormatter f;

if (what == "osd_map") {
int64_t num_osds = Injector::get_num_osds();
OSDMap* osdmap = new OSDMap;
OSDMap *osdmap = new OSDMap;
uuid_d id = uuid_d();
osdmap->build_simple(g_ceph_context, 1, id, num_osds);
// OSDMap::dump_osds filters not existent osds so we need
// to set the state so we dump non existent ones too
Injector::mark_exists_osds(osdmap);
osdmap->dump(&f);
} else {
Py_RETURN_NONE
Py_RETURN_NONE;
}
PyObject *obj = f.get();
Py_INCREF(obj);
return obj;
}

OSDMap *Injector::get_osdmap() {
int64_t num_osds = Injector::get_num_osds();
OSDMap *osdmap = new OSDMap;
uuid_d id = uuid_d();
osdmap->build_simple(g_ceph_context, 1, id, num_osds);
Injector::mark_exists_osds(osdmap);
return osdmap;
}
3 changes: 2 additions & 1 deletion src/mgr/Injector.h
Expand Up @@ -10,9 +10,10 @@
class Injector {
private:
static int64_t get_num_osds();
static void mark_exists_osds(OSDMap* osdmap);
static void mark_exists_osds(OSDMap *osdmap);

public:
static PyObject *get_python(const std::string &what);
static OSDMap *get_osdmap();
};

0 comments on commit 951b526

Please sign in to comment.