]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: make rbd_get_parent_info() accept NULL out params
authorIlya Dryomov <ilya.dryomov@inktank.com>
Tue, 8 Jul 2014 15:21:54 +0000 (19:21 +0400)
committerIlya Dryomov <ilya.dryomov@inktank.com>
Mon, 28 Jul 2014 09:53:54 +0000 (13:53 +0400)
The C++ version of rbd_get_parent_info() allows passing NULL for parent
image name, image name and snapshot name out parameters.  Make C API do
the same both for consistency and to make it easier to check whether
the image at hand has a parent or not.

Signed-off-by: Ilya Dryomov <ilya.dryomov@inktank.com>
src/librbd/librbd.cc
src/test/librbd/test_librbd.cc

index b265343e0250cbe0a08484c65b742e96d014bc9f..6fbf3c0afa45be5f6614f6cf0b3d398fa3178ecd 100644 (file)
@@ -796,16 +796,25 @@ extern "C" int rbd_get_parent_info(rbd_image_t image,
   if (r < 0)
     return r;
 
-  // compare against input bufferlen, leaving room for \0
-  if (p_pool_name.length() + 1 > ppool_namelen ||
-      p_name.length() + 1 > pnamelen ||
-      p_snap_name.length() + 1 > psnap_namelen) {
-    return -ERANGE;
+  if (parent_pool_name) {
+    if (p_pool_name.length() + 1 > ppool_namelen)
+      return -ERANGE;
+
+    strcpy(parent_pool_name, p_pool_name.c_str());
+  }
+  if (parent_name) {
+    if (p_name.length() + 1 > pnamelen)
+      return -ERANGE;
+
+    strcpy(parent_name, p_name.c_str());
+  }
+  if (parent_snap_name) {
+    if (p_snap_name.length() + 1 > psnap_namelen)
+      return -ERANGE;
+
+    strcpy(parent_snap_name, p_snap_name.c_str());
   }
 
-  strcpy(parent_pool_name, p_pool_name.c_str());
-  strcpy(parent_name, p_name.c_str());
-  strcpy(parent_snap_name, p_snap_name.c_str());
   return 0;
 }
 
index fdc33d3d3deba3a47b25822ca4baa7bc3f788c7d..2f0e5d26be888bd209d492543fba0e363063162e 100644 (file)
@@ -1037,9 +1037,7 @@ TEST(LibRBD, TestClone)
   EXPECT_NE(0, rbd_clone(ioctx, "parent", NULL, ioctx, "child", features, &order));
 
   // verify that there is no parent info on "parent"
-  char ppool[1], pname[1], psnapname[1];
-  ASSERT_EQ(-ENOENT, rbd_get_parent_info(parent, ppool, sizeof(ppool),
-           pname, sizeof(pname), psnapname, sizeof(psnapname)));
+  ASSERT_EQ(-ENOENT, rbd_get_parent_info(parent, NULL, 0, NULL, 0, NULL, 0));
   printf("parent has no parent info\n");
 
   // create a snapshot, reopen as the parent we're interested in
@@ -1153,9 +1151,7 @@ TEST(LibRBD, TestClone2)
   EXPECT_NE(0, rbd_clone(ioctx, "parent", NULL, ioctx, "child", features, &order));
 
   // verify that there is no parent info on "parent"
-  char ppool[1], pname[1], psnapname[1];
-  ASSERT_EQ(-ENOENT, rbd_get_parent_info(parent, ppool, sizeof(ppool),
-           pname, sizeof(pname), psnapname, sizeof(psnapname)));
+  ASSERT_EQ(-ENOENT, rbd_get_parent_info(parent, NULL, 0, NULL, 0, NULL, 0));
   printf("parent has no parent info\n");
 
   // create a snapshot, reopen as the parent we're interested in