]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: new rados_mon_command_target to talk to a specific monitor
authorSage Weil <sage@inktank.com>
Wed, 12 Jun 2013 23:36:39 +0000 (16:36 -0700)
committerSage Weil <sage@inktank.com>
Thu, 13 Jun 2013 16:26:44 +0000 (09:26 -0700)
Signed-off-by: Sage Weil <sage@inktank.com>
src/include/rados/librados.h
src/librados/RadosClient.cc
src/librados/RadosClient.h
src/librados/librados.cc
src/pybind/rados.py

index 69eeccb323bb02ca55b01d007e29867399048091..eb1a30632b7e491c975d174f91841e18c04ed4bd 100644 (file)
@@ -1712,7 +1712,7 @@ int rados_break_lock(rados_ioctx_t io, const char *o, const char *name,
  * @note Takes command string in carefully-formatted JSON; must match
  * defined commands, types, etc.
  *
- * The result buffers are allocated on the heapt; the caller is
+ * The result buffers are allocated on the heap; the caller is
  * expected to release that memory with rados_buffer_free().  The
  * buffer and length pointers can all be NULL, in which case they are
  * not filled in.
@@ -1732,6 +1732,34 @@ int rados_mon_command(rados_t cluster, const char **cmd, size_t cmdlen,
                      char **outbuf, size_t *outbuflen,
                      char **outs, size_t *outslen);
 
+/**
+ * Send monitor command to a specific monitor.
+ *
+ * @note Takes command string in carefully-formatted JSON; must match
+ * defined commands, types, etc.
+ *
+ * The result buffers are allocated on the heap; the caller is
+ * expected to release that memory with rados_buffer_free().  The
+ * buffer and length pointers can all be NULL, in which case they are
+ * not filled in.
+ *
+ * @param cluster cluster handle
+ * @param name target monitor's name
+ * @param cmd an array of char *'s representing the command
+ * @param cmdlen count of valid entries in cmd
+ * @param inbuf any bulk input data (crush map, etc.)
+ * @param outbuf double pointer to output buffer
+ * @param outbuflen pointer to output buffer length
+ * @param outs double pointer to status string
+ * @param outslen pointer to status string length
+ * @returns 0 on success, negative error code on failure
+ */
+int rados_mon_command_target(rados_t cluster, const char *name,
+                            const char **cmd, size_t cmdlen,
+                            const char *inbuf, size_t inbuflen,
+                            char **outbuf, size_t *outbuflen,
+                            char **outs, size_t *outslen);
+
 /**
  * free a rados-allocated buffer
  *
index a2b54abf0583383bcbd4959552f25d5dce0b8c3d..3b5fabe3f829b5e2e9c5ada2395e06f4fc98190c 100644 (file)
@@ -583,6 +583,44 @@ int librados::RadosClient::mon_command(const vector<string>& cmd,
   return rval;
 }
 
+int librados::RadosClient::mon_command(int rank, const vector<string>& cmd,
+                                             bufferlist &inbl,
+                                             bufferlist *outbl, string *outs)
+{
+  Mutex mylock("RadosClient::mon_command::mylock");
+  Cond cond;
+  bool done;
+  int rval;
+  lock.Lock();
+  monclient.start_mon_command(rank, cmd, inbl, outbl, outs,
+                              new C_SafeCond(&mylock, &cond, &done, &rval));
+  lock.Unlock();
+  mylock.Lock();
+  while (!done)
+    cond.Wait(mylock);
+  mylock.Unlock();
+  return rval;
+}
+
+int librados::RadosClient::mon_command(string name, const vector<string>& cmd,
+                                             bufferlist &inbl,
+                                             bufferlist *outbl, string *outs)
+{
+  Mutex mylock("RadosClient::mon_command::mylock");
+  Cond cond;
+  bool done;
+  int rval;
+  lock.Lock();
+  monclient.start_mon_command(name, cmd, inbl, outbl, outs,
+                              new C_SafeCond(&mylock, &cond, &done, &rval));
+  lock.Unlock();
+  mylock.Lock();
+  while (!done)
+    cond.Wait(mylock);
+  mylock.Unlock();
+  return rval;
+}
+
 int librados::RadosClient::osd_command(int osd, vector<string>& cmd,
                                        bufferlist& inbl,
                                        bufferlist *poutbl, string *prs)
index 9374553b0ad203d05c4f60214d878aa3ac9cd8a6..337beff575031fdd009a09c62833675095a2e3b3 100644 (file)
@@ -108,6 +108,12 @@ public:
   void watch_notify(MWatchNotify *m);
   int mon_command(const vector<string>& cmd, bufferlist &inbl,
                  bufferlist *outbl, string *outs);
+  int mon_command(int rank,
+                 const vector<string>& cmd, bufferlist &inbl,
+                 bufferlist *outbl, string *outs);
+  int mon_command(string name,
+                 const vector<string>& cmd, bufferlist &inbl,
+                 bufferlist *outbl, string *outs);
   int osd_command(int osd, vector<string>& cmd, bufferlist& inbl,
                   bufferlist *poutbl, string *prs);
   int pg_command(pg_t pgid, vector<string>& cmd, bufferlist& inbl,
index 1dda70828fd039be53aa6ac01f5f48eba55adfe4..43c2584c3907679b5648dc4d0f1f93efa6b09586 100644 (file)
@@ -1857,6 +1857,45 @@ extern "C" int rados_mon_command(rados_t cluster, const char **cmd,
   return ret;
 }
 
+extern "C" int rados_mon_command_target(rados_t cluster, const char *name,
+                                       const char **cmd,
+                                       size_t cmdlen,
+                                       const char *inbuf, size_t inbuflen,
+                                       char **outbuf, size_t *outbuflen,
+                                       char **outs, size_t *outslen)
+{
+  librados::RadosClient *client = (librados::RadosClient *)cluster;
+  bufferlist inbl;
+  bufferlist outbl;
+  string outstring;
+  vector<string> cmdvec;
+
+  // is this a numeric id?
+  char *endptr;
+  errno = 0;
+  long rank = strtol(name, &endptr, 10);
+  if ((errno == ERANGE && (rank == LONG_MAX || rank == LONG_MIN)) ||
+      (errno != 0 && rank == 0) ||
+      endptr == name ||    // no digits
+      *endptr != '\0') {   // extra characters
+    rank = -1;
+  }
+
+  for (size_t i = 0; i < cmdlen; i++)
+    cmdvec.push_back(cmd[i]);
+
+  inbl.append(inbuf, inbuflen);
+  int ret;
+  if (rank >= 0)
+    ret = client->mon_command(rank, cmdvec, inbl, &outbl, &outstring);
+  else
+    ret = client->mon_command(name, cmdvec, inbl, &outbl, &outstring);
+
+  do_out_buffer(outbl, outbuf, outbuflen);
+  do_out_buffer(outstring, outs, outslen);
+  return ret;
+}
+
 extern "C" int rados_osd_command(rados_t cluster, int osdid, const char **cmd,
                                 size_t cmdlen,
                                 const char *inbuf, size_t inbuflen,
index 4a5ed961603b5dbe3bdaf2eb156b45c40ca3b2f0..c40004652727977b85e16419845eaa533d150dec 100644 (file)
@@ -518,9 +518,9 @@ Rados object in state %s." % (self.state))
             raise make_ex(ret, "error opening ioctx '%s'" % ioctx_name)
         return Ioctx(ioctx_name, self.librados, ioctx)
 
-    def mon_command(self, cmd, inbuf, timeout=0):
+    def mon_command(self, cmd, inbuf, timeout=0, target=None):
         """
-        mon_command(cmd, inbuf, outbuf, outbuflen, outs, outslen)
+        mon_command[_target](cmd, inbuf, outbuf, outbuflen, outs, outslen)
         returns (int ret, string outbuf, string outs)
         """
         import sys
@@ -531,11 +531,18 @@ Rados object in state %s." % (self.state))
         outslen = c_long()
         cmdarr = (c_char_p * len(cmd))(*cmd)
 
-        ret = run_in_thread(self.librados.rados_mon_command,
-                            (self.cluster, cmdarr, len(cmd),
-                            c_char_p(inbuf), len(inbuf),
-                            outbufp, byref(outbuflen), outsp, byref(outslen)),
-                            timeout)
+        if target:
+            ret = run_in_thread(self.librados.rados_mon_command_target,
+                                (self.cluster, target, cmdarr, len(cmd),
+                                 c_char_p(inbuf), len(inbuf),
+                                 outbufp, byref(outbuflen), outsp, byref(outslen)),
+                                timeout)
+        else:
+            ret = run_in_thread(self.librados.rados_mon_command,
+                                (self.cluster, cmdarr, len(cmd),
+                                 c_char_p(inbuf), len(inbuf),
+                                 outbufp, byref(outbuflen), outsp, byref(outslen)),
+                                timeout)
 
         if ret == 0:
             # copy returned memory (ctypes makes a copy, not a reference)