]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
PG: add formatted output to pg <pgid> query, list_missing
authorDan Mick <dan.mick@inktank.com>
Sat, 20 Jul 2013 01:04:29 +0000 (18:04 -0700)
committerDan Mick <dan.mick@inktank.com>
Fri, 26 Jul 2013 20:51:09 +0000 (13:51 -0700)
Signed-off-by: Dan Mick <dan.mick@inktank.com>
src/osd/PG.h
src/osd/ReplicatedPG.cc
src/osd/ReplicatedPG.h

index 5525c7f46dd26efd29646864fc3f1abf29fa080e..10e9a2544a9b0951e940d1605a64589859710f4f 100644 (file)
@@ -43,6 +43,7 @@
 #include "msg/Messenger.h"
 #include "messages/MOSDRepScrub.h"
 #include "messages/MOSDPGLog.h"
+#include "common/cmdparse.h"
 #include "common/tracked_int_ptr.hpp"
 #include "common/WorkQueue.h"
 #include "include/str_list.h"
@@ -109,7 +110,6 @@ struct PGRecoveryStats {
          << i.total_time << "\t"
          << i.min_time << "\t" << i.max_time << "\t"
          << p->first << "\n";
-              
     }
   }
 
@@ -1814,7 +1814,7 @@ public:
   virtual void do_push_reply(OpRequestRef op) = 0;
   virtual void snap_trimmer() = 0;
 
-  virtual int do_command(vector<string>& cmd, ostream& ss,
+  virtual int do_command(cmdmap_t cmdmap, ostream& ss,
                         bufferlist& idata, bufferlist& odata) = 0;
 
   virtual bool same_for_read_since(epoch_t e) = 0;
index 298d38d6ace647c631ce8af1a00a3125e5b08cc0..4a59a23cdb79498dcb67dab1cd23bf3354a1ae45 100644 (file)
@@ -268,23 +268,12 @@ int ReplicatedPG::get_pgls_filter(bufferlist::iterator& iter, PGLSFilter **pfilt
 
 // ==========================================================
 
-int ReplicatedPG::do_command(vector<string>& cmd, ostream& ss,
+int ReplicatedPG::do_command(cmdmap_t cmdmap, ostream& ss,
                             bufferlist& idata, bufferlist& odata)
 {
   const pg_missing_t &missing = pg_log.get_missing();
-  map<string, cmd_vartype> cmdmap;
   string prefix;
-
-  if (cmd.empty()) {
-    ss << "no command given";
-    return -EINVAL;
-  }
-
-  stringstream ss2;
-  if (!cmdmap_from_json(cmd, &cmdmap, ss2)) {
-    ss << ss2.str();
-    return -EINVAL;
-  }
+  string format;
 
   cmd_getval(g_ceph_context, cmdmap, "prefix", prefix);
   if (prefix != "pg") {
@@ -292,33 +281,36 @@ int ReplicatedPG::do_command(vector<string>& cmd, ostream& ss,
     return -EINVAL;
   }
 
+  cmd_getval(g_ceph_context, cmdmap, "format", format);
+  boost::scoped_ptr<Formatter> f(new_formatter(format));
+  // demand that we have a formatter
+  if (!f)
+    f.reset(new_formatter("json"));
+
   string command;
   cmd_getval(g_ceph_context, cmdmap, "cmd", command);
   if (command == "query") {
-    JSONFormatter jsf(true);
-    jsf.open_object_section("pg");
-    jsf.dump_string("state", pg_state_string(get_state()));
-    jsf.dump_unsigned("epoch", get_osdmap()->get_epoch());
-    jsf.open_array_section("up");
+    f->open_object_section("pg");
+    f->dump_string("state", pg_state_string(get_state()));
+    f->dump_unsigned("epoch", get_osdmap()->get_epoch());
+    f->open_array_section("up");
     for (vector<int>::iterator p = up.begin(); p != up.end(); ++p)
-      jsf.dump_unsigned("osd", *p);
-    jsf.close_section();
-    jsf.open_array_section("acting");
+      f->dump_unsigned("osd", *p);
+    f->close_section();
+    f->open_array_section("acting");
     for (vector<int>::iterator p = acting.begin(); p != acting.end(); ++p)
-      jsf.dump_unsigned("osd", *p);
-    jsf.close_section();
-    jsf.open_object_section("info");
-    info.dump(&jsf);
-    jsf.close_section();
-
-    jsf.open_array_section("recovery_state");
-    handle_query_state(&jsf);
-    jsf.close_section();
-
-    jsf.close_section();
-    stringstream dss;
-    jsf.flush(dss);
-    odata.append(dss);
+      f->dump_unsigned("osd", *p);
+    f->close_section();
+    f->open_object_section("info");
+    info.dump(f.get());
+    f->close_section();
+
+    f->open_array_section("recovery_state");
+    handle_query_state(f.get());
+    f->close_section();
+
+    f->close_section();
+    f->flush(odata);
     return 0;
   }
   else if (command == "mark_unfound_lost") {
@@ -352,7 +344,6 @@ int ReplicatedPG::do_command(vector<string>& cmd, ostream& ss,
     return 0;
   }
   else if (command == "list_missing") {
-    JSONFormatter jf(true);
     hobject_t offset;
     string offset_json;
     if (cmd_getval(g_ceph_context, cmdmap, "offset", offset_json)) {
@@ -366,50 +357,48 @@ int ReplicatedPG::do_command(vector<string>& cmd, ostream& ss,
        return -EINVAL;
       }
     }
-    jf.open_object_section("missing");
+    f->open_object_section("missing");
     {
-      jf.open_object_section("offset");
-      offset.dump(&jf);
-      jf.close_section();
+      f->open_object_section("offset");
+      offset.dump(f.get());
+      f->close_section();
     }
-    jf.dump_int("num_missing", missing.num_missing());
-    jf.dump_int("num_unfound", get_num_unfound());
+    f->dump_int("num_missing", missing.num_missing());
+    f->dump_int("num_unfound", get_num_unfound());
     map<hobject_t,pg_missing_t::item>::const_iterator p = missing.missing.upper_bound(offset);
     {
-      jf.open_array_section("objects");
+      f->open_array_section("objects");
       int32_t num = 0;
       bufferlist bl;
       while (p != missing.missing.end() && num < g_conf->osd_command_max_records) {
-       jf.open_object_section("object");
+       f->open_object_section("object");
        {
-         jf.open_object_section("oid");
-         p->first.dump(&jf);
-         jf.close_section();
+         f->open_object_section("oid");
+         p->first.dump(f.get());
+         f->close_section();
        }
-       p->second.dump(&jf);  // have, need keys
+       p->second.dump(f.get());  // have, need keys
        {
-         jf.open_array_section("locations");
+         f->open_array_section("locations");
          map<hobject_t,set<int> >::iterator q = missing_loc.find(p->first);
          if (q != missing_loc.end())
            for (set<int>::iterator r = q->second.begin(); r != q->second.end(); ++r)
-             jf.dump_int("osd", *r);
-         jf.close_section();
+             f->dump_int("osd", *r);
+         f->close_section();
        }
-       jf.close_section();
+       f->close_section();
        ++p;
        num++;
       }
-      jf.close_section();
+      f->close_section();
     }
-    jf.dump_int("more", p != missing.missing.end());
-    jf.close_section();
-    stringstream jss;
-    jf.flush(jss);
-    odata.append(jss);
+    f->dump_int("more", p != missing.missing.end());
+    f->close_section();
+    f->flush(odata);
     return 0;
   };
 
-  ss << "unknown command " << cmd;
+  ss << "unknown pg command " << prefix;
   return -EINVAL;
 }
 
index 9dafe23faa1fb91b1403e7fb2c3280c60837a430..7b70b4381ea4f8b8d77cfea7d2e16871f1ef6805 100644 (file)
@@ -17,6 +17,7 @@
 #include <boost/optional.hpp>
 
 #include "include/assert.h" 
+#include "common/cmdparse.h"
 
 #include "PG.h"
 #include "OSD.h"
@@ -930,7 +931,8 @@ public:
               const hobject_t& ioid);
   ~ReplicatedPG() {}
 
-  int do_command(vector<string>& cmd, ostream& ss, bufferlist& idata, bufferlist& odata);
+  int do_command(cmdmap_t cmdmap, ostream& ss, bufferlist& idata,
+                bufferlist& odata);
 
   void do_op(OpRequestRef op);
   bool pg_op_must_wait(MOSDOp *op);