]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mds: switch asok calls over to call_async interface
authorSage Weil <sage@redhat.com>
Tue, 29 Oct 2019 20:23:09 +0000 (15:23 -0500)
committerSage Weil <sage@redhat.com>
Fri, 15 Nov 2019 18:42:40 +0000 (12:42 -0600)
A bit of cleanup here with the error messages (just let the caller end
print a generic error message).

Signed-off-by: Sage Weil <sage@redhat.com>
src/mds/MDSDaemon.cc
src/mds/MDSDaemon.h
src/mds/MDSRank.cc
src/mds/MDSRank.h

index 45356177b990c6da84b90fb0fe39438efc963d1f..3f9f4ebafbf24e989d0d8faacbc87e4f73b2f416 100644 (file)
@@ -109,23 +109,36 @@ class MDSSocketHook : public AdminSocketHook {
   MDSDaemon *mds;
 public:
   explicit MDSSocketHook(MDSDaemon *m) : mds(m) {}
-  int call(std::string_view command, const cmdmap_t& cmdmap,
-          Formatter *f,
-          std::ostream& ss,
-          bufferlist& out) override {
-    stringstream outss;
-    int r = mds->asok_command(command, cmdmap, f, outss);
-    out.append(outss);
-    return r;
+  int call(
+    std::string_view command,
+    const cmdmap_t& cmdmap,
+    Formatter *f,
+    std::ostream& errss,
+    ceph::buffer::list& out) override {
+    ceph_abort("shoudl go to call_async");
+  }
+  void call_async(
+    std::string_view command,
+    const cmdmap_t& cmdmap,
+    Formatter *f,
+    const bufferlist& inbl,
+    std::function<void(int,const std::string&,bufferlist&)> on_finish) override {
+    mds->asok_command(command, cmdmap, f, inbl, on_finish);
   }
 };
 
-int MDSDaemon::asok_command(std::string_view command, const cmdmap_t& cmdmap,
-                           Formatter *f, std::ostream& ss)
+void MDSDaemon::asok_command(
+  std::string_view command,
+  const cmdmap_t& cmdmap,
+  Formatter *f,
+  const bufferlist& inbl,
+  std::function<void(int,const std::string&,bufferlist&)> on_finish)
 {
-  dout(1) << "asok_command: " << command << " (starting...)" << dendl;
+  dout(1) << "asok_command: " << command << " " << cmdmap
+         << " (starting...)" << dendl;
 
   int r = -ENOSYS;
+  stringstream ss;
   if (command == "status") {
     dump_status(f);
     r = 0;
@@ -135,15 +148,16 @@ int MDSDaemon::asok_command(std::string_view command, const cmdmap_t& cmdmap,
       f->dump_string("error", "mds_not_active");
     } else {
       try {
-       r = mds_rank->handle_asok_command(command, cmdmap, f, ss);
+       mds_rank->handle_asok_command(command, cmdmap, f, inbl, on_finish);
+       return;
       } catch (const bad_cmd_get& e) {
        ss << e.what();
        r = -EINVAL;
       }
     }
   }
-  dout(1) << "asok_command: " << command << " (complete)" << dendl;
-  return r;
+  bufferlist outbl;
+  on_finish(r, ss.str(), outbl);
 }
 
 void MDSDaemon::dump_status(Formatter *f)
index a4568ee9c738b74849d9b1be11c760589da9a4fe..a3117679862cfea7978a6400c495ef5792a91adc 100644 (file)
@@ -93,8 +93,12 @@ class MDSDaemon : public Dispatcher {
   void set_up_admin_socket();
   void clean_up_admin_socket();
   void check_ops_in_flight(); // send off any slow ops to monitor
-  int asok_command(std::string_view command, const cmdmap_t& cmdmap,
-                  Formatter *f, ostream& ss);
+  void asok_command(
+    std::string_view command,
+    const cmdmap_t& cmdmap,
+    Formatter *f,
+    const bufferlist &inbl,
+    std::function<void(int,const std::string&,bufferlist&)> on_finish);
 
   void dump_status(Formatter *f);
 
index 3f5ed581c56dce806ce3c6ec082061d590c9ba28..81b576d0c77bd3b8c446729d98934e21a48f5f3a 100644 (file)
@@ -2426,11 +2426,16 @@ void MDSRank::handle_mds_failure(mds_rank_t who)
   snapclient->handle_mds_failure(who);
 }
 
-int MDSRankDispatcher::handle_asok_command(std::string_view command,
-                                          const cmdmap_t& cmdmap,
-                                          Formatter *f,
-                                          std::ostream& ss)
-{
+void MDSRankDispatcher::handle_asok_command(
+  std::string_view command,
+  const cmdmap_t& cmdmap,
+  Formatter *f,
+  const bufferlist &inbl,
+  std::function<void(int,const std::string&,bufferlist&)> on_finish)
+{
+  int r = 0;
+  ostringstream ss;
+  bufferlist outbl;
   if (command == "dump_ops_in_flight" ||
       command == "ops") {
     if (!op_tracker.dump_ops_in_flight(f)) {
@@ -2458,7 +2463,8 @@ int MDSRankDispatcher::handle_asok_command(std::string_view command,
 
     if (!got_val) {
       ss << "no target epoch given";
-      return -EINVAL;
+      r = -EINVAL;
+      goto out;
     }
     {
       std::lock_guard l(mds_lock);
@@ -2481,15 +2487,15 @@ int MDSRankDispatcher::handle_asok_command(std::string_view command,
     const bool got_arg = cmd_getval(g_ceph_context, cmdmap, "client_id", client_id);
     if(!got_arg) {
       ss << "Invalid client_id specified";
-      return -ENOENT;
+      r = -ENOENT;
+      goto out;
     }
     std::lock_guard l(mds_lock);
-    std::stringstream dss;
     bool evicted = evict_client(strtol(client_id.c_str(), 0, 10), true,
-        g_conf()->mds_session_blacklist_on_evict, dss);
+        g_conf()->mds_session_blacklist_on_evict, ss);
     if (!evicted) {
-      dout(15) << dss.str() << dendl;
-      ss << dss.str();
+      dout(15) << ss.str() << dendl;
+      r = -EBUSY;
     }
   } else if (command == "session config") {
     int64_t client_id;
@@ -2501,7 +2507,7 @@ int MDSRankDispatcher::handle_asok_command(std::string_view command,
     bool got_value = cmd_getval(g_ceph_context, cmdmap, "value", value);
 
     std::lock_guard l(mds_lock);
-    config_client(client_id, !got_value, option, value, ss);
+    r = config_client(client_id, !got_value, option, value, ss);
   } else if (command == "scrub_path") {
     string path;
     vector<string> scrubop_vec;
@@ -2529,28 +2535,24 @@ int MDSRankDispatcher::handle_asok_command(std::string_view command,
     string path;
     if(!cmd_getval(g_ceph_context, cmdmap, "path", path)) {
       ss << "malformed path";
-      return -EINVAL;
+      r = -EINVAL;
+      goto out;
     }
     int64_t rank;
     if(!cmd_getval(g_ceph_context, cmdmap, "rank", rank)) {
       ss << "malformed rank";
-      return -EINVAL;
+      r = -EINVAL;
+      goto out;
     }
     command_export_dir(f, path, (mds_rank_t)rank);
   } else if (command == "dump cache") {
     std::lock_guard l(mds_lock);
     string path;
-    int r;
-    if(!cmd_getval(g_ceph_context, cmdmap, "path", path)) {
+    if (!cmd_getval(g_ceph_context, cmdmap, "path", path)) {
       r = mdcache->dump_cache(f);
     } else {
       r = mdcache->dump_cache(path);
     }
-
-    if (r != 0) {
-      ss << "Failed to dump cache: " << cpp_strerror(r);
-      f->reset();
-    }
   } else if (command == "cache status") {
     std::lock_guard l(mds_lock);
     mdcache->cache_status(f);
@@ -2558,11 +2560,7 @@ int MDSRankDispatcher::handle_asok_command(std::string_view command,
     command_dump_tree(cmdmap, ss, f);
   } else if (command == "dump loads") {
     std::lock_guard l(mds_lock);
-    int r = balancer->dump_loads(f);
-    if (r != 0) {
-      ss << "Failed to dump loads: " << cpp_strerror(r);
-      f->reset();
-    }
+    r = balancer->dump_loads(f);
   } else if (command == "dump snaps") {
     std::lock_guard l(mds_lock);
     string server;
@@ -2571,14 +2569,11 @@ int MDSRankDispatcher::handle_asok_command(std::string_view command,
       if (mdsmap->get_tableserver() == whoami) {
        snapserver->dump(f);
       } else {
+       r = -EXDEV;
        ss << "Not snapserver";
       }
     } else {
-      int r = snapclient->dump_cache(f);
-      if (r != 0) {
-       ss << "Failed to dump snapclient: " << cpp_strerror(r);
-       f->reset();
-      }
+      r = snapclient->dump_cache(f);
     }
   } else if (command == "force_readonly") {
     std::lock_guard l(mds_lock);
@@ -2594,10 +2589,10 @@ int MDSRankDispatcher::handle_asok_command(std::string_view command,
   } else if (command == "dump inode") {
     command_dump_inode(f, cmdmap, ss);
   } else {
-    return -ENOSYS;
+    r = -ENOSYS;
   }
-
-  return 0;
+out:
+  on_finish(r, ss.str(), outbl);
 }
 
 class C_MDS_Send_Command_Reply : public MDSInternalContext {
index 1944e2f17bde2349403a4d489c56d332cee0f3a7..016af1a4bf2a42f82bff5433f681d41b6a18b69c 100644 (file)
@@ -630,8 +630,12 @@ public:
   void init();
   void tick();
   void shutdown();
-  int handle_asok_command(std::string_view command, const cmdmap_t& cmdmap,
-                         Formatter *f, std::ostream& ss);
+  void handle_asok_command(
+    std::string_view command,
+    const cmdmap_t& cmdmap,
+    Formatter *f,
+    const bufferlist &inbl,
+    std::function<void(int,const std::string&,bufferlist&)> on_finish);
   void handle_mds_map(const cref_t<MMDSMap> &m, const MDSMap &oldmap);
   void handle_osd_map();
   void update_log_config();