]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mon: handle MStatfs using PGStatService
authorSage Weil <sage@redhat.com>
Wed, 31 May 2017 14:19:25 +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.ClusterStat 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/PGMap.h
src/mon/PGMonitor.cc
src/mon/PGMonitor.h
src/mon/PGStatService.h

index b6ffe8695e638810071c9ce5a0d5bc6d98c2b479..ef1fd8789d0e5334e41c434a6e4ea271c64dbaa2 100644 (file)
@@ -4,6 +4,8 @@
 #include "MgrStatMonitor.h"
 #include "mon/PGMap.h"
 #include "messages/MMonMgrReport.h"
+#include "messages/MStatfs.h"
+#include "messages/MStatfsReply.h"
 
 class MgrPGStatService : public PGStatService {
   PGMapDigest& digest;
@@ -36,6 +38,10 @@ public:
     return digest.get_num_pg_by_osd(osd);
   }
 
+  ceph_statfs get_statfs() const override {
+    return digest.get_statfs();
+  }
+
   void print_summary(Formatter *f, ostream *out) const override {
     digest.print_summary(f, out);
   }
@@ -157,6 +163,8 @@ bool MgrStatMonitor::preprocess_query(MonOpRequestRef op)
 {
   auto m = static_cast<PaxosServiceMessage*>(op->get_req());
   switch (m->get_type()) {
+  case CEPH_MSG_STATFS:
+    return preprocess_statfs(op);
   case MSG_MON_MGR_REPORT:
     return preprocess_report(op);
   default:
@@ -194,3 +202,34 @@ bool MgrStatMonitor::prepare_report(MonOpRequestRef op)
   pending_health_detail.swap(m->health_detail);
   return true;
 }
+
+bool MgrStatMonitor::preprocess_statfs(MonOpRequestRef op)
+{
+  op->mark_pgmon_event(__func__);
+  auto statfs = static_cast<MStatfs*>(op->get_req());
+  auto session = statfs->get_session();
+  if (!session)
+    return true;
+  if (!session->is_capable("pg", MON_CAP_R)) {
+    dout(0) << "MStatfs received from entity with insufficient privileges "
+            << session->caps << dendl;
+    return true;
+  }
+  if (statfs->fsid != mon->monmap->fsid) {
+    dout(0) << __func__ << " on fsid " << statfs->fsid
+            << " != " << mon->monmap->fsid << dendl;
+    return true;
+  }
+  dout(10) << __func__ << " " << *statfs
+           << " from " << statfs->get_orig_source() << dendl;
+  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 MStatfsReply(statfs->fsid, statfs->get_tid(), ver);
+  reply->h.st = mon->pgservice->get_statfs();
+  mon->send_reply(op, reply);
+  return true;
+}
index e1e02cd4089961013b7a884a9ea2ae8a1b5c4d53..ecfafd4eaeb0b06009fa2ceabce069dcfbd3ee2e 100644 (file)
@@ -45,6 +45,8 @@ public:
   bool preprocess_report(MonOpRequestRef op);
   bool prepare_report(MonOpRequestRef op);
 
+  bool preprocess_statfs(MonOpRequestRef op);
+
   void check_sub(Subscription *sub);
   void check_subs();
   void send_digests();
index 13994bab1138ed7823cc0547e24b7dcaf8812730..55ff38082469f49f33377c77ceedc93cec491bf3 100644 (file)
@@ -36,6 +36,7 @@
 #include "messages/MGenericMessage.h"
 #include "messages/MMonCommand.h"
 #include "messages/MMonCommandAck.h"
+#include "messages/MMonHealth.h"
 #include "messages/MMonMetadata.h"
 #include "messages/MMonSync.h"
 #include "messages/MMonScrub.h"
@@ -51,7 +52,6 @@
 #include "messages/MAuthReply.h"
 
 #include "messages/MTimeCheck.h"
-#include "messages/MMonHealth.h"
 #include "messages/MPing.h"
 
 #include "common/strtol.h"
@@ -3831,12 +3831,13 @@ void Monitor::dispatch_op(MonOpRequestRef op)
       paxos_service[PAXOS_MGR]->dispatch(op);
       break;
 
+    // MgrStat
     case MSG_MON_MGR_REPORT:
+    case CEPH_MSG_STATFS:
       paxos_service[PAXOS_MGRSTAT]->dispatch(op);
       break;
 
     // pg
-    case CEPH_MSG_STATFS:
     case MSG_PGSTATS:
     case MSG_GETPOOLSTATS:
       paxos_service[PAXOS_PGMAP]->dispatch(op);
index a33bfe6bd53517431dd72ef4d8dc5a872c04b684..8359785b901f807504a41ee6652a2d3e32adfc91 100644 (file)
@@ -167,6 +167,16 @@ public:
       return p->second.primary;
   }
 
+  ceph_statfs get_statfs() const {
+    ceph_statfs statfs;
+    // these are in KB.
+    statfs.kb = osd_sum.kb;
+    statfs.kb_used = osd_sum.kb_used;
+    statfs.kb_avail = osd_sum.kb_avail;
+    statfs.num_objects = pg_sum.stats.sum.num_objects;
+    return statfs;
+  }
+
   int64_t get_rule_avail(const OSDMap& osdmap, int ruleno) const;
 
   // kill me post-luminous:
index 19a0fa6d1a80498d2e0612a9bcdb19331c061888..0130bf228f3cba58f3bc59377a48f625702a64fa 100644 (file)
@@ -26,8 +26,6 @@
 #include "messages/MGetPoolStats.h"
 #include "messages/MGetPoolStatsReply.h"
 
-#include "messages/MStatfs.h"
-#include "messages/MStatfsReply.h"
 #include "messages/MOSDPGCreate.h"
 #include "messages/MMonCommand.h"
 #include "messages/MOSDScrub.h"
@@ -567,10 +565,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 CEPH_MSG_STATFS:
-    handle_statfs(op);
-    return true;
-
   case MSG_GETPOOLSTATS:
     return preprocess_getpoolstats(op);
 
@@ -609,45 +603,6 @@ bool PGMonitor::prepare_update(MonOpRequestRef op)
   }
 }
 
-void PGMonitor::handle_statfs(MonOpRequestRef op)
-{
-  op->mark_pgmon_event(__func__);
-  MStatfs *statfs = static_cast<MStatfs*>(op->get_req());
-  // check caps
-  MonSession *session = statfs->get_session();
-  if (!session)
-    return;
-
-  if (!session->is_capable("pg", MON_CAP_R)) {
-    dout(0) << "MStatfs received from entity with insufficient privileges "
-            << session->caps << dendl;
-    return;
-  }
-
-  if (statfs->fsid != mon->monmap->fsid) {
-    dout(0) << "handle_statfs on fsid " << statfs->fsid
-            << " != " << mon->monmap->fsid << dendl;
-    return;
-  }
-
-
-  dout(10) << "handle_statfs " << *statfs
-           << " from " << statfs->get_orig_source() << dendl;
-
-  // fill out stfs
-  MStatfsReply *reply = new MStatfsReply(mon->monmap->fsid, statfs->get_tid(),
-    get_last_committed());
-
-  // these are in KB.
-  reply->h.st.kb = pg_map.osd_sum.kb;
-  reply->h.st.kb_used = pg_map.osd_sum.kb_used;
-  reply->h.st.kb_avail = pg_map.osd_sum.kb_avail;
-  reply->h.st.num_objects = pg_map.pg_sum.stats.sum.num_objects;
-
-  // reply
-  mon->send_reply(op, reply);
-}
-
 bool PGMonitor::preprocess_getpoolstats(MonOpRequestRef op)
 {
   op->mark_pgmon_event(__func__);
@@ -1343,7 +1298,14 @@ public:
   size_t get_num_pg_by_osd(int osd) const override {
     return pgmap.get_num_pg_by_osd(osd);
   }
-
+  ceph_statfs get_statfs() const override {
+    ceph_statfs statfs;
+    statfs.kb = pgmap.osd_sum.kb;
+    statfs.kb_used = pgmap.osd_sum.kb_used;
+    statfs.kb_avail = pgmap.osd_sum.kb_avail;
+    statfs.num_objects = pgmap.pg_sum.stats.sum.num_objects;
+    return statfs;
+  }
   void print_summary(Formatter *f, ostream *out) const override {
     pgmap.print_summary(f, out);
   }
index 654441591dca08e50521582f4baefb1cba89f0e7..d84aa5016a596b9676e952851567f49e6b3acfda 100644 (file)
@@ -77,7 +77,6 @@ private:
 
   struct C_Stats;
 
-  void handle_statfs(MonOpRequestRef op);
   bool preprocess_getpoolstats(MonOpRequestRef op);
 
   bool preprocess_command(MonOpRequestRef op);
index c714c6e4c90938d252064b249595287940f19cf1..4916f90500de1ee8433641d10965affa77e576af 100644 (file)
@@ -84,6 +84,7 @@ public:
   }
 
   virtual size_t get_num_pg_by_osd(int osd) const = 0;
+  virtual ceph_statfs get_statfs() const = 0;
   virtual void print_summary(Formatter *f, ostream *out) const = 0;
   virtual void dump_info(Formatter *f) const = 0;
   virtual void dump_fs_stats(stringstream *ss, Formatter *f, bool verbose) const = 0;