f.close_section();
});
return f.get();
- } else if (what == "health" || what == "mon_status") {
- bufferlist json;
- if (what == "health") {
- json = cluster_state.get_health();
- } else if (what == "mon_status") {
- json = cluster_state.get_mon_status();
- } else {
- ceph_abort();
- }
-
- PyEval_RestoreThread(tstate);
- f.dump_string("json", json.to_str());
+ } else if (what == "health") {
+ cluster_state.with_health(
+ [&f, &tstate](const ceph::bufferlist &health_json) {
+ PyEval_RestoreThread(tstate);
+ f.dump_string("json", health_json.to_str());
+ });
+ return f.get();
+ } else if (what == "mon_status") {
+ cluster_state.with_mon_status(
+ [&f, &tstate](const ceph::bufferlist &mon_status_json) {
+ PyEval_RestoreThread(tstate);
+ f.dump_string("json", mon_status_json.to_str());
+ });
return f.get();
} else if (what == "mgr_map") {
cluster_state.with_mgrmap([&f, &tstate](const MgrMap &mgr_map) {
void ClusterState::load_digest(MMgrDigest *m)
{
+ std::lock_guard l(lock);
health_json = std::move(m->health_json);
mon_status_json = std::move(m->mon_status_json);
}
void update_delta_stats();
- const bufferlist &get_health() const {return health_json;}
- const bufferlist &get_mon_status() const {return mon_status_json;}
-
ClusterState(MonClient *monc_, Objecter *objecter_, const MgrMap& mgrmap);
void set_objecter(Objecter *objecter_);
pg_map,
std::forward<Args>(args)...);
}
+
+ template<typename Callback, typename...Args>
+ void with_health(Callback&& cb, Args&&...args) const
+ {
+ std::lock_guard l(lock);
+ std::forward<Callback>(cb)(health_json, std::forward<Args>(args)...);
+ }
+
+ template<typename Callback, typename...Args>
+ void with_mon_status(Callback&& cb, Args&&...args) const
+ {
+ std::lock_guard l(lock);
+ std::forward<Callback>(cb)(mon_status_json, std::forward<Args>(args)...);
+ }
+
void final_init();
void shutdown();
bool asok_command(std::string_view admin_command, const cmdmap_t& cmdmap,