]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
osd: simplify asok to single callback
authorSage Weil <sage@inktank.com>
Mon, 21 Jan 2013 23:50:33 +0000 (15:50 -0800)
committerSamuel Just <sam.just@inktank.com>
Sat, 26 Jan 2013 01:17:04 +0000 (17:17 -0800)
Signed-off-by: Sage Weil <sage@inktank.com>
(cherry picked from commit 33efe32151e04beaafd9435d7f86dc2eb046214d)

src/osd/OSD.cc
src/osd/OSD.h

index e94229277e018c4dda70720748e4d1989872f122..d794fa8bdcd5039cae4411a7add8b94b8ec02b3e 100644 (file)
@@ -761,6 +761,7 @@ OSD::OSD(int id, Messenger *internal_messenger, Messenger *external_messenger,
   whoami(id),
   dev_path(dev), journal_path(jdev),
   dispatch_running(false),
+  asok_hook(NULL),
   osd_compat(get_osd_compat_set()),
   state(STATE_INITIALIZING), boot_epoch(0), up_epoch(0), bind_epoch(0),
   op_tp(external_messenger->cct, "OSD::op_tp", g_conf->osd_op_threads, "osd_op_threads"),
@@ -776,8 +777,6 @@ OSD::OSD(int id, Messenger *internal_messenger, Messenger *external_messenger,
   heartbeat_dispatcher(this),
   stat_lock("OSD::stat_lock"),
   finished_lock("OSD::finished_lock"),
-  admin_ops_hook(NULL),
-  historic_ops_hook(NULL),
   op_wq(this, g_conf->osd_op_thread_timeout, &op_tp),
   peering_wq(this, g_conf->osd_op_thread_timeout, &op_tp, 200),
   map_lock("OSD::map_lock"),
@@ -846,30 +845,31 @@ int OSD::pre_init()
   return 0;
 }
 
-class HistoricOpsSocketHook : public AdminSocketHook {
+// asok
+
+class OSDSocketHook : public AdminSocketHook {
   OSD *osd;
 public:
-  HistoricOpsSocketHook(OSD *o) : osd(o) {}
+  OSDSocketHook(OSD *o) : osd(o) {}
   bool call(std::string command, std::string args, bufferlist& out) {
     stringstream ss;
-    osd->dump_historic_ops(ss);
+    bool r = osd->asok_command(command, args, ss);
     out.append(ss);
-    return true;
+    return r;
   }
 };
 
-
-class OpsFlightSocketHook : public AdminSocketHook {
-  OSD *osd;
-public:
-  OpsFlightSocketHook(OSD *o) : osd(o) {}
-  bool call(std::string command, std::string args, bufferlist& out) {
-    stringstream ss;
-    osd->dump_ops_in_flight(ss);
-    out.append(ss);
-    return true;
+bool OSD::asok_command(string command, string args, ostream& ss)
+{
+  if (command == "dump_ops_in_flight") {
+    op_tracker.dump_ops_in_flight(ss);
+  } else if (command == "dump_historic_ops") {
+    op_tracker.dump_historic_ops(ss);
+  } else {
+    assert(0 == "broken asok registration");
   }
-};
+  return true;
+}
 
 int OSD::init()
 {
@@ -964,13 +964,12 @@ int OSD::init()
   // tick
   timer.add_event_after(g_conf->osd_heartbeat_interval, new C_Tick(this));
 
-  admin_ops_hook = new OpsFlightSocketHook(this);
+  asok_hook = new OSDSocketHook(this);
   AdminSocket *admin_socket = cct->get_admin_socket();
-  r = admin_socket->register_command("dump_ops_in_flight", admin_ops_hook,
-                                         "show the ops currently in flight");
-  historic_ops_hook = new HistoricOpsSocketHook(this);
-  r = admin_socket->register_command("dump_historic_ops", historic_ops_hook,
-                                         "show slowest recent ops");
+  r = admin_socket->register_command("dump_ops_in_flight", asok_hook,
+                                    "show the ops currently in flight");
+  r = admin_socket->register_command("dump_historic_ops", asok_hook,
+                                    "show slowest recent ops");
   assert(r == 0);
 
   service.init();
@@ -1124,10 +1123,9 @@ int OSD::shutdown()
   dout(10) << "no ops" << dendl;
 
   cct->get_admin_socket()->unregister_command("dump_ops_in_flight");
-  delete admin_ops_hook;
-  delete historic_ops_hook;
-  admin_ops_hook = NULL;
-  historic_ops_hook = NULL;
+  cct->get_admin_socket()->unregister_command("dump_historic_ops");
+  delete asok_hook;
+  asok_hook = NULL;
 
   recovery_tp.stop();
   dout(10) << "recovery tp stopped" << dendl;
@@ -2292,11 +2290,6 @@ void OSD::check_ops_in_flight()
   return;
 }
 
-void OSD::dump_ops_in_flight(ostream& ss)
-{
-  op_tracker.dump_ops_in_flight(ss);
-}
-
 // =========================================
 void OSD::RemoveWQ::_process(boost::tuple<coll_t, SequencerRef, DeletingStateRef> *item)
 {
index fd6e97eb7c9f66099e49603bac53441ce3747903..17bea46e2b8c55ff1ee46b2deb3aff5c1f554af4 100644 (file)
@@ -440,6 +440,11 @@ protected:
 
   void check_osdmap_features();
 
+  // asok
+  friend class OSDSocketHook;
+  class OSDSocketHook *asok_hook;
+  bool asok_command(string command, string args, ostream& ss);
+
 public:
   ClassHandler  *class_handler;
   int get_nodeid() { return whoami; }
@@ -620,15 +625,7 @@ private:
   // -- op tracking --
   OpTracker op_tracker;
   void check_ops_in_flight();
-  void dump_ops_in_flight(ostream& ss);
-  void dump_historic_ops(ostream& ss) {
-    return op_tracker.dump_historic_ops(ss);
-  }
-  friend class OpsFlightSocketHook;
-  friend class HistoricOpsSocketHook;
   friend class C_CompleteSplits;
-  OpsFlightSocketHook *admin_ops_hook;
-  HistoricOpsSocketHook *historic_ops_hook;
 
   // -- op queue --