diff --git a/src/mgr/ClusterState.cc b/src/mgr/ClusterState.cc index 6b3b800a143..8bc88c530f0 100644 --- a/src/mgr/ClusterState.cc +++ b/src/mgr/ClusterState.cc @@ -23,7 +23,7 @@ #define dout_prefix *_dout << "mgr " << __func__ << " " ClusterState::ClusterState(MonClient *monc_, Objecter *objecter_) - : monc(monc_), objecter(objecter_), lock("ClusterState") + : monc(monc_), objecter(objecter_), lock("ClusterState"), pgservice(pg_map) {} void ClusterState::set_objecter(Objecter *objecter_) diff --git a/src/mgr/ClusterState.h b/src/mgr/ClusterState.h index b748c647574..ae08c75daa1 100644 --- a/src/mgr/ClusterState.h +++ b/src/mgr/ClusterState.h @@ -42,6 +42,8 @@ protected: PGMap pg_map; PGMap::Incremental pending_inc; + PGMapStatService pgservice; + bufferlist health_json; bufferlist mon_status_json; @@ -82,6 +84,14 @@ public: return std::forward(cb)(pg_map, std::forward(args)...); } + template + auto with_pgservice(Callback&& cb, Args&&...args) const -> + decltype(cb(pgservice, std::forward(args)...)) + { + Mutex::Locker l(lock); + return std::forward(cb)(pg_map, std::forward(args)...); + } + template void with_monmap(Args &&... args) const { diff --git a/src/mgr/DaemonServer.cc b/src/mgr/DaemonServer.cc index 9446a125744..a4f53333e93 100644 --- a/src/mgr/DaemonServer.cc +++ b/src/mgr/DaemonServer.cc @@ -778,6 +778,20 @@ bool DaemonServer::handle_command(MCommand *m) &on_finish->from_mon, &on_finish->outs, on_finish); return true; } + } else if (prefix == "osd df") { + string method; + cmd_getval(g_ceph_context, cmdctx->cmdmap, "output_method", method); + r = cluster_state.with_pgservice([&](const PGMapStatService& pgservice) { + return cluster_state.with_osdmap([&](const OSDMap& osdmap) { + print_osd_utilization(osdmap, &pgservice, ss, + f.get(), method == "tree"); + + cmdctx->odata.append(ss); + return 0; + }); + }); + cmdctx->reply(r, ""); + return true; } else { r = cluster_state.with_pgmap([&](const PGMap& pg_map) { return cluster_state.with_osdmap([&](const OSDMap& osdmap) { diff --git a/src/mon/OSDMonitor.cc b/src/mon/OSDMonitor.cc index 8188dd33b75..5686bd4e89f 100644 --- a/src/mon/OSDMonitor.cc +++ b/src/mon/OSDMonitor.cc @@ -3927,7 +3927,7 @@ bool OSDMonitor::preprocess_command(MonOpRequestRef op) string method; cmd_getval(g_ceph_context, cmdmap, "output_method", method); print_osd_utilization(osdmap, mon->pgservice, ds, - f ? f.get() : NULL, method == "tree"); + f.get(), method == "tree"); rdata.append(ds); } else if (prefix == "osd getmaxosd") { if (f) {