]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: Added new API methods to create an ioctx by pool id
authorJason Dillaman <dillaman@redhat.com>
Fri, 12 Dec 2014 14:44:28 +0000 (09:44 -0500)
committerJason Dillaman <dillaman@redhat.com>
Sat, 13 Dec 2014 09:37:55 +0000 (04:37 -0500)
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>
src/include/rados/librados.h
src/include/rados/librados.hpp
src/librados/IoCtxImpl.cc
src/librados/IoCtxImpl.h
src/librados/RadosClient.cc
src/librados/RadosClient.h
src/librados/librados.cc
src/tracing/librados.tp

index 9c4a5732ff69613b975f3cc555d7eb30422f0a3b..6c5eb326f17dd2b88cdbad9c5a31f2a1aa6ec21f 100644 (file)
@@ -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
index 402ede00687220d3dcb768558e3bcdcb57f5ae47..918022c065ff1320646c7dd59bc43d3340ab2741 100644 (file)
@@ -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<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.
index f5a8a5badce23b28720382acbd6215e8d6bbb928..c9ec7223d4d976140446936686eea0972d03033d 100644 (file)
@@ -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),
index 76cebf67e3b8e131758a8502b90fdc594a856570..3147ae5dc0d8336aeaf27e947ee44f0812757f78 100644 (file)
@@ -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
index 56f52bb4314081e2ebbde81e5ee255e57c090aa7..e0e78464f7fc859be87f916a5af08e27844dfcf0 100644 (file)
@@ -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<std::string>& v)
+int librados::RadosClient::pool_list(std::list<std::pair<int64_t, string> >& v)
 {
   int r = wait_for_osdmap();
   if (r < 0)
@@ -473,7 +486,7 @@ int librados::RadosClient::pool_list(std::list<std::string>& v)
   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;
 }
index 23960622521bf9f49af97c050df7c0c3a56d8aef..c138b3a617ae267ce0787062affdb6e518406aba 100644 (file)
@@ -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<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);
 
index 573fae7ee7c24efe6c37eec347d14f10dd44e5a1..b20e85633f2a2752e47638eaed0e6da7128913ad 100644 (file)
@@ -1929,6 +1929,22 @@ int librados::Rados::pool_delete_async(const char *name, PoolAsyncCompletion *c)
 }
 
 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);
 }
@@ -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<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);
@@ -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<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;
@@ -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);
index 78146acacc591fb3d23aeb7db9ef64f14a67936e..028db43a3989ef584e882d08962db82f3122da2e 100644 (file)
@@ -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),