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 <dillaman@redhat.com>
*
* @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
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<std::string>& v);
+ int pool_list2(std::list<std::pair<int64_t, std::string> >& v);
int get_pool_stats(std::list<std::string>& v,
stats_map& result);
/// deprecated; use simpler form. categories no longer supported.
}
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),
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
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;
return 0;
}
-int librados::RadosClient::pool_list(std::list<std::string>& v)
+int librados::RadosClient::pool_list(std::list<std::pair<int64_t, string> >& v)
{
int r = wait_for_osdmap();
if (r < 0)
for (map<int64_t,pg_pool_t>::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;
}
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);
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<string>& ls);
+ int pool_list(std::list<std::pair<int64_t, string> >& ls);
int get_pool_stats(std::list<string>& ls, map<string,::pool_stat_t>& result);
int get_fs_stats(ceph_statfs& result);
}
int librados::Rados::pool_list(std::list<std::string>& v)
+{
+ std::list<std::pair<int64_t, std::string> > pools;
+ int r = client->pool_list(pools);
+ if (r < 0) {
+ return r;
+ }
+
+ v.clear();
+ for (std::list<std::pair<int64_t, std::string> >::iterator it = pools.begin();
+ it != pools.end(); ++it) {
+ v.push_back(it->second);
+ }
+ return 0;
+}
+
+int librados::Rados::pool_list2(std::list<std::pair<int64_t, std::string> >& v)
{
return client->pool_list(v);
}
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);
{
tracepoint(librados, rados_pool_list_enter, cluster, len);
librados::RadosClient *client = (librados::RadosClient *)cluster;
- std::list<std::string> pools;
+ std::list<std::pair<int64_t, std::string> > pools;
int r = client->pool_list(pools);
if (r < 0) {
tracepoint(librados, rados_pool_list_exit, r);
if (b)
memset(b, 0, len);
int needed = 0;
- std::list<std::string>::const_iterator i = pools.begin();
- std::list<std::string>::const_iterator p_end = pools.end();
+ std::list<std::pair<int64_t, std::string> >::const_iterator i = pools.begin();
+ std::list<std::pair<int64_t, std::string> >::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;
b += rl;
}
for (; i != p_end; ++i) {
- int rl = i->length() + 1;
+ int rl = i->second.length() + 1;
needed += rl;
}
int retval = needed + 1;
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);
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);
)
)
+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),