diff options
author | Joao Eduardo Luis <joao.luis@inktank.com> | 2013-10-15 17:49:40 +0100 |
---|---|---|
committer | Joao Eduardo Luis <joao.luis@inktank.com> | 2013-10-23 02:52:01 +0100 |
commit | 2d7ccab3824eeb9b133ceb5fe8d723f6a664221b (patch) | |
tree | d6607163094997c44c65541c7765c11cbbd10545 | |
parent | 6a4b196a5b2933224bb50dfbc79a850a903ce115 (diff) | |
download | ceph-2d7ccab3824eeb9b133ceb5fe8d723f6a664221b.tar.gz |
librados: support pinging a monitor without auth via RadosClient
Signed-off-by: Joao Eduardo Luis <joao.luis@inktank.com>
-rw-r--r-- | src/include/rados/librados.h | 17 | ||||
-rw-r--r-- | src/librados/RadosClient.cc | 20 | ||||
-rw-r--r-- | src/librados/RadosClient.h | 1 | ||||
-rw-r--r-- | src/librados/librados.cc | 16 |
4 files changed, 54 insertions, 0 deletions
diff --git a/src/include/rados/librados.h b/src/include/rados/librados.h index 515663c2335..a67b85ec3d3 100644 --- a/src/include/rados/librados.h +++ b/src/include/rados/librados.h @@ -224,6 +224,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. * * @note BUG: Before calling this, calling a function that communicates with the diff --git a/src/librados/RadosClient.cc b/src/librados/RadosClient.cc index 1be3ebd10f9..d6700c83d7c 100644 --- a/src/librados/RadosClient.cc +++ b/src/librados/RadosClient.cc @@ -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); diff --git a/src/librados/RadosClient.h b/src/librados/RadosClient.h index 2244788d876..7c5c8af1ca0 100644 --- a/src/librados/RadosClient.h +++ b/src/librados/RadosClient.h @@ -77,6 +77,7 @@ public: RadosClient(CephContext *cct_); ~RadosClient(); + int ping_monitor(string mon_id, string *result); int connect(); void shutdown(); diff --git a/src/librados/librados.cc b/src/librados/librados.cc index 217a0a7bfb2..95abbc2f260 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -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, |