]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: handle MGetPoolStats using PGStatService
authorSage Weil <sage@redhat.com>
Wed, 31 May 2017 14:19:33 +0000 (10:19 -0400)
committerSage Weil <sage@redhat.com>
Fri, 2 Jun 2017 17:06:47 +0000 (13:06 -0400)
otherwise ceph_test_rados_api_stat: LibRadosStat.PoolStat will always
timeout once the cluster is switched to luminous

Signed-off-by: Kefu Chai <kchai@redhat.com>
src/mon/MgrStatMonitor.cc
src/mon/MgrStatMonitor.h
src/mon/Monitor.cc
src/mon/PGMonitor.cc
src/mon/PGMonitor.h

index ef1fd8789d0e5334e41c434a6e4ea271c64dbaa2..44ef1074d0a27eec5a118d032e4199b1077a2b03 100644 (file)
@@ -2,7 +2,11 @@
 // vim: ts=8 sw=2 smarttab
 
 #include "MgrStatMonitor.h"
+#include "mon/OSDMonitor.h"
 #include "mon/PGMap.h"
+#include "mon/PGMonitor.h"
+#include "messages/MGetPoolStats.h"
+#include "messages/MGetPoolStatsReply.h"
 #include "messages/MMonMgrReport.h"
 #include "messages/MStatfs.h"
 #include "messages/MStatfsReply.h"
@@ -167,6 +171,8 @@ bool MgrStatMonitor::preprocess_query(MonOpRequestRef op)
     return preprocess_statfs(op);
   case MSG_MON_MGR_REPORT:
     return preprocess_report(op);
+  case MSG_GETPOOLSTATS:
+    return preprocess_getpoolstats(op);
   default:
     mon->no_reply(op);
     derr << "Unhandled message type " << m->get_type() << dendl;
@@ -203,6 +209,43 @@ bool MgrStatMonitor::prepare_report(MonOpRequestRef op)
   return true;
 }
 
+bool MgrStatMonitor::preprocess_getpoolstats(MonOpRequestRef op)
+{
+  op->mark_pgmon_event(__func__);
+  auto m = static_cast<MGetPoolStats*>(op->get_req());
+  auto session = m->get_session();
+  if (!session)
+    return true;
+  if (!session->is_capable("pg", MON_CAP_R)) {
+    dout(0) << "MGetPoolStats received from entity with insufficient caps "
+            << session->caps << dendl;
+    return true;
+  }
+  if (m->fsid != mon->monmap->fsid) {
+    dout(0) << __func__ << " on fsid "
+           << m->fsid << " != " << mon->monmap->fsid << dendl;
+    return true;
+  }
+  epoch_t ver = 0;
+  if (mon->pgservice == get_pg_stat_service()) {
+    ver = get_last_committed();
+  } else {
+    ver = mon->pgmon()->get_last_committed();
+  }
+  auto reply = new MGetPoolStatsReply(m->fsid, m->get_tid(), ver);
+  for (const auto& pool_name : m->pools) {
+    const auto pool_id = mon->osdmon()->osdmap.lookup_pg_pool_name(pool_name);
+    if (pool_id == -ENOENT)
+      continue;
+    auto pool_stat = mon->pgservice->get_pool_stat(pool_id);
+    if (!pool_stat)
+      continue;
+    reply->pool_stats[pool_name] = *pool_stat;
+  }
+  mon->send_reply(op, reply);
+  return true;
+}
+
 bool MgrStatMonitor::preprocess_statfs(MonOpRequestRef op)
 {
   op->mark_pgmon_event(__func__);
index ecfafd4eaeb0b06009fa2ceabce069dcfbd3ee2e..c6e4bea0c95f88da57264bcad7db939c86054e22 100644 (file)
@@ -45,6 +45,7 @@ public:
   bool preprocess_report(MonOpRequestRef op);
   bool prepare_report(MonOpRequestRef op);
 
+  bool preprocess_getpoolstats(MonOpRequestRef op);
   bool preprocess_statfs(MonOpRequestRef op);
 
   void check_sub(Subscription *sub);
index 55ff38082469f49f33377c77ceedc93cec491bf3..804bd1e6472e978f1aeb06a3fb1dfa1bbad9355d 100644 (file)
@@ -3834,12 +3834,12 @@ void Monitor::dispatch_op(MonOpRequestRef op)
     // MgrStat
     case MSG_MON_MGR_REPORT:
     case CEPH_MSG_STATFS:
+    case MSG_GETPOOLSTATS:
       paxos_service[PAXOS_MGRSTAT]->dispatch(op);
       break;
 
     // pg
     case MSG_PGSTATS:
-    case MSG_GETPOOLSTATS:
       paxos_service[PAXOS_PGMAP]->dispatch(op);
       break;
 
index 0130bf228f3cba58f3bc59377a48f625702a64fa..b75d1e7681583605c762554b98731d098ba17ce6 100644 (file)
@@ -23,8 +23,6 @@
 
 #include "messages/MPGStats.h"
 #include "messages/MPGStatsAck.h"
-#include "messages/MGetPoolStats.h"
-#include "messages/MGetPoolStatsReply.h"
 
 #include "messages/MOSDPGCreate.h"
 #include "messages/MMonCommand.h"
@@ -565,9 +563,6 @@ bool PGMonitor::preprocess_query(MonOpRequestRef op)
   PaxosServiceMessage *m = static_cast<PaxosServiceMessage*>(op->get_req());
   dout(10) << "preprocess_query " << *m << " from " << m->get_orig_source_inst() << dendl;
   switch (m->get_type()) {
-  case MSG_GETPOOLSTATS:
-    return preprocess_getpoolstats(op);
-
   case MSG_PGSTATS:
     return preprocess_pg_stats(op);
 
@@ -603,46 +598,6 @@ bool PGMonitor::prepare_update(MonOpRequestRef op)
   }
 }
 
-bool PGMonitor::preprocess_getpoolstats(MonOpRequestRef op)
-{
-  op->mark_pgmon_event(__func__);
-  MGetPoolStats *m = static_cast<MGetPoolStats*>(op->get_req());
-  MGetPoolStatsReply *reply;
-
-  MonSession *session = m->get_session();
-  if (!session)
-    goto out;
-  if (!session->is_capable("pg", MON_CAP_R)) {
-    dout(0) << "MGetPoolStats received from entity with insufficient caps "
-            << session->caps << dendl;
-    goto out;
-  }
-
-  if (m->fsid != mon->monmap->fsid) {
-    dout(0) << "preprocess_getpoolstats on fsid " << m->fsid << " != " << mon->monmap->fsid << dendl;
-    goto out;
-  }
-
-  reply = new MGetPoolStatsReply(m->fsid, m->get_tid(), get_last_committed());
-
-  for (list<string>::iterator p = m->pools.begin();
-       p != m->pools.end();
-       ++p) {
-    int64_t poolid = mon->osdmon()->osdmap.lookup_pg_pool_name(p->c_str());
-    if (poolid < 0)
-      continue;
-    if (pg_map.pg_pool_sum.count(poolid) == 0)
-      continue;
-    reply->pool_stats[*p] = pg_map.pg_pool_sum[poolid];
-  }
-
-  mon->send_reply(op, reply);
-
-out:
-  return true;
-}
-
-
 bool PGMonitor::preprocess_pg_stats(MonOpRequestRef op)
 {
   op->mark_pgmon_event(__func__);
index d84aa5016a596b9676e952851567f49e6b3acfda..0e2171d3ebce1154cd548a584e6d5bd3ed34bdaa 100644 (file)
@@ -77,8 +77,6 @@ private:
 
   struct C_Stats;
 
-  bool preprocess_getpoolstats(MonOpRequestRef op);
-
   bool preprocess_command(MonOpRequestRef op);
   bool prepare_command(MonOpRequestRef op);