From: Jason Dillaman Date: Fri, 12 Dec 2014 14:44:28 +0000 (-0500) Subject: librados: Added new API methods to create an ioctx by pool id X-Git-Tag: v0.92~61^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f79b7fe4513a386623b7f102daeeb5b1657ddbc6;p=ceph.git librados: Added new API methods to create an ioctx by pool id A new pool_list method includes the unique pool id for all pools. This pool id can be used with the new rados_ioctx_create2 / ioctx_create methods to create an ioctx by pool id instead of by pool name. Creating ioctx's by pool id helps avoid certain race conditions when pools are renamed or deleted. Signed-off-by: Jason Dillaman --- diff --git a/src/include/rados/librados.h b/src/include/rados/librados.h index 9c4a5732ff69..6c5eb326f17d 100644 --- a/src/include/rados/librados.h +++ b/src/include/rados/librados.h @@ -603,11 +603,14 @@ CEPH_RADOS_API uint64_t rados_get_instance_id(rados_t cluster); * * @param cluster which cluster the pool is in * @param pool_name name of the pool + * @param pool_id unique id of the pool * @param ioctx where to store the io context * @returns 0 on success, negative error code on failure */ CEPH_RADOS_API int rados_ioctx_create(rados_t cluster, const char *pool_name, rados_ioctx_t *ioctx); +CEPH_RADOS_API int rados_ioctx_create2(rados_t cluster, int64_t pool_id, + rados_ioctx_t *ioctx); /** * The opposite of rados_ioctx_create diff --git a/src/include/rados/librados.hpp b/src/include/rados/librados.hpp index 402ede006872..918022c065ff 100644 --- a/src/include/rados/librados.hpp +++ b/src/include/rados/librados.hpp @@ -984,12 +984,14 @@ namespace librados bufferlist *outbl, std::string *outs); int ioctx_create(const char *name, IoCtx &pioctx); + int ioctx_create2(int64_t pool_id, IoCtx &pioctx); // Features useful for test cases void test_blacklist_self(bool set); /* listing objects */ int pool_list(std::list& v); + int pool_list2(std::list >& v); int get_pool_stats(std::list& v, stats_map& result); /// deprecated; use simpler form. categories no longer supported. diff --git a/src/librados/IoCtxImpl.cc b/src/librados/IoCtxImpl.cc index f5a8a5badce2..c9ec7223d4d9 100644 --- a/src/librados/IoCtxImpl.cc +++ b/src/librados/IoCtxImpl.cc @@ -33,7 +33,7 @@ librados::IoCtxImpl::IoCtxImpl() : } librados::IoCtxImpl::IoCtxImpl(RadosClient *c, Objecter *objecter, - Mutex *client_lock, int poolid, + Mutex *client_lock, int64_t poolid, const char *pool_name, snapid_t s) : ref_cnt(0), client(c), poolid(poolid), pool_name(pool_name), snap_seq(s), assert_ver(0), notify_timeout(c->cct->_conf->client_notify_timeout), diff --git a/src/librados/IoCtxImpl.h b/src/librados/IoCtxImpl.h index 76cebf67e3b8..3147ae5dc0d8 100644 --- a/src/librados/IoCtxImpl.h +++ b/src/librados/IoCtxImpl.h @@ -52,7 +52,7 @@ struct librados::IoCtxImpl { IoCtxImpl(); IoCtxImpl(RadosClient *c, Objecter *objecter, Mutex *client_lock, - int poolid, const char *pool_name, snapid_t s); + int64_t poolid, const char *pool_name, snapid_t s); void dup(const IoCtxImpl& rhs) { // Copy everything except the ref count diff --git a/src/librados/RadosClient.cc b/src/librados/RadosClient.cc index 56f52bb43140..e0e78464f7fc 100644 --- a/src/librados/RadosClient.cc +++ b/src/librados/RadosClient.cc @@ -344,6 +344,19 @@ int librados::RadosClient::create_ioctx(const char *name, IoCtxImpl **io) return 0; } +int librados::RadosClient::create_ioctx(int64_t pool_id, IoCtxImpl **io) +{ + std::string pool_name; + int r = pool_get_name(pool_id, &pool_name); + if (r < 0) { + return r; + } + + *io = new librados::IoCtxImpl(this, objecter, &lock, pool_id, pool_name.c_str(), + CEPH_NOSNAP); + return 0; +} + bool librados::RadosClient::ms_dispatch(Message *m) { bool ret; @@ -464,7 +477,7 @@ int librados::RadosClient::wait_for_latest_osdmap() return 0; } -int librados::RadosClient::pool_list(std::list& v) +int librados::RadosClient::pool_list(std::list >& v) { int r = wait_for_osdmap(); if (r < 0) @@ -473,7 +486,7 @@ int librados::RadosClient::pool_list(std::list& v) for (map::const_iterator p = osdmap->get_pools().begin(); p != osdmap->get_pools().end(); ++p) - v.push_back(osdmap->get_pool_name(p->first)); + v.push_back(std::make_pair(p->first, osdmap->get_pool_name(p->first))); objecter->put_osdmap_read(); return 0; } diff --git a/src/librados/RadosClient.h b/src/librados/RadosClient.h index 23960622521b..c138b3a617ae 100644 --- a/src/librados/RadosClient.h +++ b/src/librados/RadosClient.h @@ -87,6 +87,7 @@ public: int wait_for_latest_osdmap(); int create_ioctx(const char *name, IoCtxImpl **io); + int create_ioctx(int64_t, IoCtxImpl **io); int get_fsid(std::string *s); int64_t lookup_pool(const char *name); @@ -95,7 +96,7 @@ public: int pool_get_auid(uint64_t pool_id, unsigned long long *auid); int pool_get_name(uint64_t pool_id, std::string *auid); - int pool_list(std::list& ls); + int pool_list(std::list >& ls); int get_pool_stats(std::list& ls, map& result); int get_fs_stats(ceph_statfs& result); diff --git a/src/librados/librados.cc b/src/librados/librados.cc index 573fae7ee7c2..b20e85633f2a 100644 --- a/src/librados/librados.cc +++ b/src/librados/librados.cc @@ -1929,6 +1929,22 @@ int librados::Rados::pool_delete_async(const char *name, PoolAsyncCompletion *c) } int librados::Rados::pool_list(std::list& v) +{ + std::list > pools; + int r = client->pool_list(pools); + if (r < 0) { + return r; + } + + v.clear(); + for (std::list >::iterator it = pools.begin(); + it != pools.end(); ++it) { + v.push_back(it->second); + } + return 0; +} + +int librados::Rados::pool_list2(std::list >& v) { return client->pool_list(v); } @@ -1961,6 +1977,16 @@ int librados::Rados::ioctx_create(const char *name, IoCtx &io) return 0; } +int librados::Rados::ioctx_create2(int64_t pool_id, IoCtx &io) +{ + rados_ioctx_t p; + int ret = rados_ioctx_create2((rados_t)client, pool_id, &p); + if (ret) + return ret; + io.io_ctx_impl = (IoCtxImpl*)p; + return 0; +} + void librados::Rados::test_blacklist_self(bool set) { client->blacklist_self(set); @@ -2390,7 +2416,7 @@ extern "C" int rados_pool_list(rados_t cluster, char *buf, size_t len) { tracepoint(librados, rados_pool_list_enter, cluster, len); librados::RadosClient *client = (librados::RadosClient *)cluster; - std::list pools; + std::list > pools; int r = client->pool_list(pools); if (r < 0) { tracepoint(librados, rados_pool_list_exit, r); @@ -2406,13 +2432,14 @@ extern "C" int rados_pool_list(rados_t cluster, char *buf, size_t len) if (b) memset(b, 0, len); int needed = 0; - std::list::const_iterator i = pools.begin(); - std::list::const_iterator p_end = pools.end(); + std::list >::const_iterator i = pools.begin(); + std::list >::const_iterator p_end = + pools.end(); for (; i != p_end; ++i) { - int rl = i->length() + 1; + int rl = i->second.length() + 1; if (len < (unsigned)rl) break; - const char* pool = i->c_str(); + const char* pool = i->second.c_str(); tracepoint(librados, rados_pool_list_pool, pool); strncat(b, pool, rl); needed += rl; @@ -2420,7 +2447,7 @@ extern "C" int rados_pool_list(rados_t cluster, char *buf, size_t len) b += rl; } for (; i != p_end; ++i) { - int rl = i->length() + 1; + int rl = i->second.length() + 1; needed += rl; } int retval = needed + 1; @@ -2623,7 +2650,6 @@ extern "C" int rados_monitor_log(rados_t cluster, const char *level, rados_log_c return retval; } - extern "C" int rados_ioctx_create(rados_t cluster, const char *name, rados_ioctx_t *io) { tracepoint(librados, rados_ioctx_create_enter, cluster, name); @@ -2643,6 +2669,26 @@ extern "C" int rados_ioctx_create(rados_t cluster, const char *name, rados_ioctx return retval; } +extern "C" int rados_ioctx_create2(rados_t cluster, int64_t pool_id, + rados_ioctx_t *io) +{ + tracepoint(librados, rados_ioctx_create2_enter, cluster, pool_id); + librados::RadosClient *client = (librados::RadosClient *)cluster; + librados::IoCtxImpl *ctx; + + int r = client->create_ioctx(pool_id, &ctx); + if (r < 0) { + tracepoint(librados, rados_ioctx_create2_exit, r, NULL); + return r; + } + + *io = ctx; + ctx->get(); + int retval = 0; + tracepoint(librados, rados_ioctx_create2_exit, retval, ctx); + return retval; +} + extern "C" void rados_ioctx_destroy(rados_ioctx_t io) { tracepoint(librados, rados_ioctx_destroy_enter, io); diff --git a/src/tracing/librados.tp b/src/tracing/librados.tp index 78146acacc59..028db43a3989 100644 --- a/src/tracing/librados.tp +++ b/src/tracing/librados.tp @@ -635,6 +635,26 @@ TRACEPOINT_EVENT(librados, rados_ioctx_create_exit, ) ) +TRACEPOINT_EVENT(librados, rados_ioctx_create2_enter, + TP_ARGS( + rados_t, cluster, + int64_t, pool_id), + TP_FIELDS( + ctf_integer_hex(rados_t, cluster, cluster) + ctf_integer(int64_t, pool_id, pool_id) + ) +) + +TRACEPOINT_EVENT(librados, rados_ioctx_create2_exit, + TP_ARGS( + int, retval, + rados_ioctx_t, ioctx), + TP_FIELDS( + ctf_integer(int, retval, retval) + ctf_integer_hex(rados_ioctx_t, ioctx, ioctx) + ) +) + TRACEPOINT_EVENT(librados, rados_ioctx_destroy_enter, TP_ARGS( rados_ioctx_t, ioctx),