From 2281a00942b546f428579b3d939e95624b1a36ca Mon Sep 17 00:00:00 2001 From: Sage Weil Date: Tue, 14 Feb 2012 13:59:30 -0800 Subject: [PATCH] librados: expose CephContext via C API 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 --- src/include/rados/librados.h | 18 ++++++++++++++++-- src/include/rados/librados.hpp | 1 + src/librados.cc | 16 ++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/include/rados/librados.h b/src/include/rados/librados.h index 4d113fc8a126f..5d16f94a7ce46 100644 --- a/src/include/rados/librados.h +++ b/src/include/rados/librados.h @@ -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 * diff --git a/src/include/rados/librados.hpp b/src/include/rados/librados.hpp index 251324b139c26..ea4798152c189 100644 --- a/src/include/rados/librados.hpp +++ b/src/include/rados/librados.hpp @@ -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; diff --git a/src/librados.cc b/src/librados.cc index e8e8bbadb0d73..0540373a2dcbf 100644 --- a/src/librados.cc +++ b/src/librados.cc @@ -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) { -- 2.39.5