]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
common/admin_socket: refactor with sync and async execute_command variants
authorSage Weil <sage@redhat.com>
Tue, 10 Sep 2019 21:39:37 +0000 (16:39 -0500)
committerSage Weil <sage@redhat.com>
Tue, 1 Oct 2019 21:30:53 +0000 (16:30 -0500)
Signed-off-by: Sage Weil <sage@redhat.com>
src/common/admin_socket.cc
src/common/admin_socket.h
src/os/bluestore/bluestore_tool.cc

index 63652dc6ee9f44245ac2b19add4cf10e698d7118..ead558a1ca0d57ab0044519633367154d002acab 100644 (file)
@@ -349,27 +349,9 @@ bool AdminSocket::do_accept()
   }
 
   std::vector<std::string> cmdvec = { c };
-  bufferlist out;
-  string rs;
-  int rval = 0;
-
-  bool done = false;
-  ceph::mutex mylock = ceph::make_mutex("admin_socket::do_accept::mylock");
-  ceph::condition_variable mycond;
-  C_SafeCond fin(mylock, mycond, &done, &rval);
-  bufferlist empty;
-  execute_command(
-    cmdvec,
-    empty /* inbl */,
-    [&rs, &out, &fin](int r, const std::string& err, bufferlist& outbl) {
-      rs = err;
-      out.claim(outbl);
-      fin.finish(r);
-    });
-  {
-    std::unique_lock l{mylock};
-    mycond.wait(l, [&done] { return done;});
-  }
+  bufferlist empty, out;
+  ostringstream err;
+  int rval = execute_command(cmdvec, empty /* inbl */, err, &out);
 
   // Unfortunately, the asok wire protocol does not let us pass an error code,
   // and many asok command implementations return helpful error strings.  So,
@@ -419,6 +401,32 @@ void AdminSocket::do_tell_queue()
   }
 }
 
+int AdminSocket::execute_command(
+  const std::vector<std::string>& cmd,
+  const bufferlist& inbl,
+  std::ostream& errss,
+  bufferlist *outbl)
+{
+  bool done = false;
+  int rval = 0;
+  ceph::mutex mylock = ceph::make_mutex("admin_socket::excute_command::mylock");
+  ceph::condition_variable mycond;
+  C_SafeCond fin(mylock, mycond, &done, &rval);
+  execute_command(
+    cmd,
+    inbl,
+    [&errss, outbl, &fin](int r, const std::string& err, bufferlist& out) {
+      errss << err;
+      outbl->claim(out);
+      fin.finish(r);
+    });
+  {
+    std::unique_lock l{mylock};
+    mycond.wait(l, [&done] { return done;});
+  }
+  return rval;
+}
+
 void AdminSocket::execute_command(
   const std::vector<std::string>& cmdvec,
   const bufferlist& inbl,
index b6e634768d1526de68d418996b395d5c3528414a..22606e7785d522788c00382fbea517a733855326 100644 (file)
@@ -96,11 +96,20 @@ public:
 
   void chown(uid_t uid, gid_t gid);
   void chmod(mode_t mode);
+
+  /// execute (async)
   void execute_command(
     const std::vector<std::string>& cmd,
     const bufferlist& inbl,
     std::function<void(int,const std::string&,bufferlist&)> on_fin);
 
+  /// execute (blocking)
+  int execute_command(
+    const std::vector<std::string>& cmd,
+    const bufferlist& inbl,
+    std::ostream& errss,
+    bufferlist *outbl);
+
   void queue_tell_command(ref_t<MCommand> m);
 
 private:
index dd227cad67bf6366c43672c15d8d90d5af9b19bc..e9a904502ee7b7935902c60c6da6b00f44f22ad7 100644 (file)
@@ -844,9 +844,11 @@ int main(int argc, char **argv)
     }
 
     for (auto alloc_name : allocs_name) {
-      ceph::bufferlist out;
+      ceph::bufferlist in, out;
+      ostringstream err;
       bool b = admin_socket->execute_command(
-       {"{\"prefix\": \"bluestore allocator " + action_name + " " + alloc_name + "\"}"}, out);
+       {"{\"prefix\": \"bluestore allocator " + action_name + " " + alloc_name + "\"}"},
+       in, err, &out);
       if (!b) {
         cerr << "failure querying '" << alloc_name << "'" << std::endl;
         exit(EXIT_FAILURE);