]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: support pinging a monitor without auth via RadosClient
authorJoao Eduardo Luis <joao.luis@inktank.com>
Tue, 15 Oct 2013 16:49:40 +0000 (17:49 +0100)
committerJoao Eduardo Luis <joao.luis@inktank.com>
Wed, 23 Oct 2013 01:52:01 +0000 (02:52 +0100)
Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
src/include/rados/librados.h
src/librados/RadosClient.cc
src/librados/RadosClient.h
src/librados/librados.cc

index 515663c23356c8261d7e0b31e782751ec0556f1f..a67b85ec3d3095845323026e7d594d99a999728e 100644 (file)
@@ -223,6 +223,23 @@ int rados_create2(rados_t *pcluster, const char *const clustername,
  */
 int rados_create_with_context(rados_t *cluster, rados_config_t cct);
 
+/**
+ * Ping the monitor with ID @p mon_id, storing the resulting reply in
+ * @p buf (if specified) with a maximum size of @p len.
+ *
+ * The result buffer is allocated on the heap; the caller is
+ * expected to release that memory with rados_buffer_free().  The
+ * buffer and length pointers can be NULL, in which case they are
+ * not filled in.
+ *
+ * @param      cluster    cluster handle
+ * @param[in]  mon_id     ID of the monitor to ping
+ * @param[out] outstr     double pointer with the resulting reply
+ * @param[out] outstrlen  pointer with the size of the reply in @p outstr
+ */
+int rados_ping_monitor(rados_t cluster, const char *mon_id,
+                       char **outstr, size_t *outstrlen);
+
 /**
  * Connect to the cluster.
  *
index 1be3ebd10f902fd502061a7ecd35b105145d9cde..d6700c83d7c500304e62cfaf0a4e605d43dc38e0 100644 (file)
@@ -131,6 +131,26 @@ int librados::RadosClient::get_fsid(std::string *s)
   return 0;
 }
 
+int librados::RadosClient::ping_monitor(const string mon_id, string *result)
+{
+  int err = 0;
+  /* If we haven't yet connected, we have no way of telling whether we
+   * already built monc's initial monmap.  IF we are in CONNECTED state,
+   * then it is safe to assume that we went through connect(), which does
+   * build a monmap.
+   */
+  if (state != CONNECTED) {
+    ldout(cct, 10) << __func__ << " build monmap" << dendl;
+    err = monclient.build_initial_monmap();
+  }
+  if (err < 0) {
+    return err;
+  }
+
+  err = monclient.ping_monitor(mon_id, result);
+  return err;
+}
+
 int librados::RadosClient::connect()
 {
   common_init_finish(cct);
index 2244788d876aac3123f81eb84659c38e7c4beeed..7c5c8af1ca0887e1d42b4eebb0190cd8ce8f4de0 100644 (file)
@@ -77,6 +77,7 @@ public:
 
   RadosClient(CephContext *cct_);
   ~RadosClient();
+  int ping_monitor(string mon_id, string *result);
   int connect();
   void shutdown();
 
index 217a0a7bfb2651656db9f66969b4cc67d97faad8..95abbc2f2609d73008a3f911129cf6dbfbe7773b 100644 (file)
@@ -1900,6 +1900,22 @@ static void do_out_buffer(string& outbl, char **outbuf, size_t *outbuflen)
     *outbuflen = outbl.length();
 }
 
+extern "C" int rados_ping_monitor(rados_t cluster, const char *mon_id,
+                                  char **outstr, size_t *outstrlen)
+{
+  librados::RadosClient *client = (librados::RadosClient *)cluster;
+  string str;
+
+  if (!mon_id)
+    return -EINVAL;
+
+  int ret = client->ping_monitor(mon_id, &str);
+  if (ret == 0 && !str.empty() && outstr && outstrlen) {
+    do_out_buffer(str, outstr, outstrlen);
+  }
+  return ret;
+}
+
 extern "C" int rados_mon_command(rados_t cluster, const char **cmd,
                                 size_t cmdlen,
                                 const char *inbuf, size_t inbuflen,