]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: expose CephContext via C API
authorSage Weil <sage@newdream.net>
Tue, 14 Feb 2012 21:59:30 +0000 (13:59 -0800)
committerSage Weil <sage@newdream.net>
Tue, 14 Feb 2012 21:59:30 +0000 (13:59 -0800)
We can already create rados cluster handles with an existing CephContext,
but that is only useful if you are building something that has access to
ceph internals; the cct isn't exposed via the API itself.

Do so, for both teh cluster and pool handles.  Add cluster handle accessor
for the C++ API too.

Fixes: #1821
Signed-off-by: Sage Weil <sage@newdream.net>
src/include/rados/librados.h
src/include/rados/librados.hpp
src/librados.cc

index 4d113fc8a126f6344419452afe5da56283672e59..5d16f94a7ce46179d5b117b93a71a55bca47072e 100644 (file)
@@ -184,8 +184,6 @@ int rados_create(rados_t *cluster, const char * const id);
  *
  * Copies all configuration, as retrieved by the C++ API.
  *
- * @note BUG: Since CephContext isn't accessible from the C API, this function is useless
- *
  * @param cluster where to store the handle
  * @param cct_ the existing configuration to use
  * @returns 0 on success, negative error code on failure
@@ -370,6 +368,14 @@ int rados_cluster_stat(rados_t cluster, struct rados_cluster_stat_t *result);
  */
 int rados_pool_list(rados_t cluster, char *buf, size_t len);
 
+/**
+ * Get CephContext for a rados cluster handle
+ *
+ * @param cluster cluster handle
+ * @returns CephContext for this cluster
+ */
+struct CephContext *rados_cct(rados_t cluster);
+
 /**
  * Create an io context
  *
@@ -399,6 +405,14 @@ int rados_ioctx_create(rados_t cluster, const char *pool_name, rados_ioctx_t *io
  */
 void rados_ioctx_destroy(rados_ioctx_t io);
 
+/**
+ * Get CephContext for a pool handle
+ *
+ * @param io pool handle
+ * @returns CephContext for this cluster
+ */
+struct CephContext *rados_ioctx_cct(rados_ioctx_t io);
+
 /**
  * Get pool usage statistics
  *
index 251324b139c26acc7eabf72809d062f165f2b9a0..ea4798152c189e690ee70ad33cd64cc60f1dbdb1 100644 (file)
@@ -351,6 +351,7 @@ namespace librados
 
     int init(const char * const id);
     int init_with_context(CephContext *cct_);
+    CephContext *cct();
     int connect();
     void shutdown();
     int conf_read_file(const char * const path) const;
index e8e8bbadb0d737e35938aefa91ac3043e5e2d0a4..0540373a2dcbf8d1adf1ba4c16627f89f0e9ba48 100644 (file)
@@ -3199,6 +3199,11 @@ int librados::Rados::connect()
   return client->connect();
 }
 
+CephContext *librados::Rados::cct()
+{
+  return client->cct;
+}
+
 void librados::Rados::shutdown()
 {
   if (!client)
@@ -3439,6 +3444,12 @@ extern "C" int rados_create_with_context(rados_t *pcluster, CephContext *cct)
   return 0;
 }
 
+extern "C" CephContext *rados_cct(rados_t cluster)
+{
+  librados::RadosClient *client = (librados::RadosClient *)cluster;
+  return client->cct;
+}
+
 extern "C" int rados_connect(rados_t cluster)
 {
   librados::RadosClient *client = (librados::RadosClient *)cluster;
@@ -3620,6 +3631,11 @@ extern "C" int rados_ioctx_pool_stat(rados_ioctx_t io, struct rados_pool_stat_t
   return 0;
 }
 
+extern "C" struct CephContext *rados_ioctx_cct(rados_ioctx_t io)
+{
+  librados::IoCtxImpl *ctx = (librados::IoCtxImpl *)io;
+  return ctx->client->cct;
+}
 
 extern "C" void rados_ioctx_snap_set_read(rados_ioctx_t io, rados_snap_t seq)
 {