]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/MgrClient: add start_command variant that takes a target
authorSage Weil <sage@redhat.com>
Fri, 6 Sep 2019 14:43:01 +0000 (09:43 -0500)
committerSage Weil <sage@redhat.com>
Tue, 1 Oct 2019 21:30:53 +0000 (16:30 -0500)
Note that the initial implementation can only target the active mgr!

Signed-off-by: Sage Weil <sage@redhat.com>
src/mgr/MgrClient.cc
src/mgr/MgrClient.h

index a1075952bf9c21e06840204813b781021bc8460d..2e48b70320974b4ca5ce23ddc46c09de9844446e 100644 (file)
@@ -184,13 +184,35 @@ void MgrClient::reconnect()
   }
 
   // resend any pending commands
-  for (const auto &p : command_table.get_commands()) {
-    auto m = p.second.get_message(
-      {},
-      HAVE_FEATURE(map.active_mgr_features, SERVER_OCTOPUS));
+  auto p = command_table.get_commands().begin();
+  while (p != command_table.get_commands().end()) {
+    auto tid = p->first;
+    auto& op = p->second;
+    ldout(cct,10) << "resending " << tid << dendl;
+    MessageRef m;
+    if (op.name.size()) {
+      if (op.name != map.active_name) {
+       // FIXME someday!
+       ldout(cct, 10) << "active mgr " << map.active_name << " != target "
+                      << op.name << dendl;
+       if (op.on_finish) {
+         op.on_finish->complete(-ENXIO);
+       }
+       ++p;
+       command_table.erase(tid);
+       continue;
+      }
+      // note: will not work for pre-octopus mgrs
+      m = op.get_message({}, false);
+    } else {
+      m = op.get_message(
+       {},
+       HAVE_FEATURE(map.active_mgr_features, SERVER_OCTOPUS));
+    }
     ceph_assert(session);
     ceph_assert(session->con);
     session->con->send_message2(std::move(m));
+    ++p;
   }
 }
 
@@ -462,6 +484,42 @@ int MgrClient::start_command(const vector<string>& cmd, const bufferlist& inbl,
   return 0;
 }
 
+int MgrClient::start_tell_command(
+  const string& name,
+  const vector<string>& cmd, const bufferlist& inbl,
+  bufferlist *outbl, string *outs,
+  Context *onfinish)
+{
+  std::lock_guard l(lock);
+
+  ldout(cct, 20) << "target: " << name << " cmd: " << cmd << dendl;
+
+  if (map.epoch == 0 && mgr_optional) {
+    ldout(cct,20) << " no MgrMap, assuming EACCES" << dendl;
+    return -EACCES;
+  }
+
+  auto &op = command_table.start_command();
+  op.name = name;
+  op.cmd = cmd;
+  op.inbl = inbl;
+  op.outbl = outbl;
+  op.outs = outs;
+  op.on_finish = onfinish;
+
+  if (session && session->con && map.active_name == name) {
+    // Leaving fsid argument null because it isn't used.
+    // Note: this simply won't work we pre-octopus mgrs because they route
+    // MCommand to the cluster command handler.
+    auto m = op.get_message({}, false);
+    session->con->send_message2(std::move(m));
+  } else {
+    ldout(cct, 5) << "no mgr session (no running mgr daemon?), or "
+                 << name << " not active mgr, waiting" << dendl;
+  }
+  return 0;
+}
+
 bool MgrClient::handle_command_reply(
   uint64_t tid,
   bufferlist& data,
index b6be89c187db47159841650ceae1cbb57392037f..fa96ff4661578120cb8aa8077c49b31b28aa527b 100644 (file)
@@ -46,6 +46,7 @@ class MgrSessionState
 class MgrCommand : public CommandOp
 {
   public:
+  std::string name;
 
   explicit MgrCommand(ceph_tid_t t) : CommandOp(t) {}
   MgrCommand() : CommandOp() {}
@@ -144,9 +145,15 @@ public:
     pgstats_cb = std::move(cb_);
   }
 
-  int start_command(const std::vector<std::string>& cmd, const ceph::buffer::list& inbl,
-                   ceph::buffer::list *outbl, std::string *outs,
-                   Context *onfinish);
+  int start_command(
+    const std::vector<std::string>& cmd, const ceph::buffer::list& inbl,
+    ceph::buffer::list *outbl, std::string *outs,
+    Context *onfinish);
+  int start_tell_command(
+    const string& name,
+    const std::vector<std::string>& cmd, const ceph::buffer::list& inbl,
+    ceph::buffer::list *outbl, std::string *outs,
+    Context *onfinish);
 
   int service_daemon_register(
     const std::string& service,