]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librados: fix rados_pool_list when buf is null
authorSage Weil <sage@redhat.com>
Fri, 28 Apr 2017 03:02:25 +0000 (23:02 -0400)
committerSage Weil <sage@redhat.com>
Fri, 28 Apr 2017 03:02:25 +0000 (23:02 -0400)
This was the original intent, but buf==NULL wasn't documented
and only half-way implemented.

Signed-off-by: Sage Weil <sage@redhat.com>
src/include/rados/librados.h
src/librados/librados.cc
src/test/librados/pool.cc

index fde863ad70e7586c46438617e9e8274e5548bc4b..401d7d4453f0ebce1f1f1dbec6503aef3659751a 100644 (file)
@@ -649,6 +649,8 @@ CEPH_RADOS_API int rados_wait_for_latest_osdmap(rados_t cluster);
  * If len is too short to fit all the pool name entries we need, we will fill
  * as much as we can.
  *
+ * Buf may be null to determine the buffer size needed to list all pools.
+ *
  * @param cluster cluster handle
  * @param buf output buffer
  * @param len output buffer length
index 8883fd9c07db0c155970f136da29fbfd9731e5ac..271ec3859e0a1bee969e27c4224e0544faa398de 100644 (file)
@@ -3068,10 +3068,12 @@ extern "C" int rados_pool_list(rados_t cluster, char *buf, size_t len)
       break;
     const char* pool = i->second.c_str();
     tracepoint(librados, rados_pool_list_pool, pool);
-    strncat(b, pool, rl);
+    if (b) {
+      strncat(b, pool, rl);
+      b += rl;
+    }
     needed += rl;
     len -= rl;
-    b += rl;
   }
   for (; i != p_end; ++i) {
     int rl = i->second.length() + 1;
index 2c01ee91b03e52b27d18904b248446f9849db476..5764fa8758807293b6aa13775425a1c35817f010 100644 (file)
@@ -15,6 +15,9 @@ TEST(LibRadosPools, PoolList) {
   ASSERT_EQ("", create_one_pool(pool_name, &cluster));
   ASSERT_LT(rados_pool_list(cluster, buf, POOL_LIST_BUF_SZ), POOL_LIST_BUF_SZ);
 
+  // we can pass a null buffer too.
+  ASSERT_LT(rados_pool_list(cluster, NULL, POOL_LIST_BUF_SZ), POOL_LIST_BUF_SZ);
+
   bool found_pool = false;
   while (buf[0] != '\0') {
     if ((found_pool == false) && (strcmp(buf, pool_name.c_str()) == 0)) {