From: Ilya Dryomov Date: Tue, 8 Jul 2014 15:21:54 +0000 (+0400) Subject: librbd: make rbd_get_parent_info() accept NULL out params X-Git-Tag: v0.84~51^2~3 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=eb697dd9ee87b62150582b93246ab664fbe42fd2;p=ceph.git librbd: make rbd_get_parent_info() accept NULL out params 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 --- diff --git a/src/librbd/librbd.cc b/src/librbd/librbd.cc index b265343e0250..6fbf3c0afa45 100644 --- a/src/librbd/librbd.cc +++ b/src/librbd/librbd.cc @@ -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; } diff --git a/src/test/librbd/test_librbd.cc b/src/test/librbd/test_librbd.cc index fdc33d3d3deb..2f0e5d26be88 100644 --- a/src/test/librbd/test_librbd.cc +++ b/src/test/librbd/test_librbd.cc @@ -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