From: Jason Dillaman Date: Mon, 2 May 2016 18:51:31 +0000 (-0400) Subject: librbd: add rbd_image_options_is_set helper method to API X-Git-Tag: v10.2.1~26^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ca13a9554d8a9d97428c2096b5a2ae8e25d08a9e;p=ceph.git librbd: add rbd_image_options_is_set helper method to API Signed-off-by: Jason Dillaman (cherry picked from commit 2633b045e0b57827cc10c2e7707bd5a5e344e59a) --- diff --git a/src/include/rbd/librbd.h b/src/include/rbd/librbd.h index 49ed98e9d7d8..3bfa927a793b 100644 --- a/src/include/rbd/librbd.h +++ b/src/include/rbd/librbd.h @@ -138,6 +138,8 @@ CEPH_RBD_API int rbd_image_options_get_string(rbd_image_options_t opts, size_t maxlen); CEPH_RBD_API int rbd_image_options_get_uint64(rbd_image_options_t opts, int optname, uint64_t* optval); +CEPH_RBD_API int rbd_image_options_is_set(rbd_image_options_t opts, + int optname, bool* is_set); CEPH_RBD_API int rbd_image_options_unset(rbd_image_options_t opts, int optname); CEPH_RBD_API void rbd_image_options_clear(rbd_image_options_t opts); CEPH_RBD_API int rbd_image_options_is_empty(rbd_image_options_t opts); diff --git a/src/include/rbd/librbd.hpp b/src/include/rbd/librbd.hpp index f328c424a24a..19c0efbc948c 100644 --- a/src/include/rbd/librbd.hpp +++ b/src/include/rbd/librbd.hpp @@ -149,6 +149,7 @@ public: int set(int optname, uint64_t optval); int get(int optname, std::string* optval) const; int get(int optname, uint64_t* optval) const; + int is_set(int optname, bool* is_set); int unset(int optname); void clear(); bool empty() const; diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 5276052c5190..365e7918a614 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -749,6 +749,19 @@ remove_mirroring_image: return 0; } + int image_options_is_set(rbd_image_options_t opts, int optname, + bool* is_set) + { + if (IMAGE_OPTIONS_TYPE_MAPPING.find(optname) == + IMAGE_OPTIONS_TYPE_MAPPING.end()) { + return -EINVAL; + } + + image_options_ref* opts_ = static_cast(opts); + *is_set = ((*opts_)->find(optname) != (*opts_)->end()); + return 0; + } + int image_options_unset(rbd_image_options_t opts, int optname) { image_options_ref* opts_ = static_cast(opts); diff --git a/src/librbd/internal.h b/src/librbd/internal.h index c2413f4e0695..41c8f1f0b108 100644 --- a/src/librbd/internal.h +++ b/src/librbd/internal.h @@ -81,6 +81,8 @@ namespace librbd { std::string* optval); int image_options_get(rbd_image_options_t opts, int optname, uint64_t* optval); + int image_options_is_set(rbd_image_options_t opts, int optname, + bool* is_set); int image_options_unset(rbd_image_options_t opts, int optname); void image_options_clear(rbd_image_options_t opts); bool image_options_is_empty(rbd_image_options_t opts); diff --git a/src/librbd/librbd.cc b/src/librbd/librbd.cc index 0cc3f9521650..a98739ea7522 100644 --- a/src/librbd/librbd.cc +++ b/src/librbd/librbd.cc @@ -487,6 +487,11 @@ namespace librbd { return librbd::image_options_get(opts, optname, optval); } + int ImageOptions::is_set(int optname, bool* is_set) + { + return librbd::image_options_is_set(opts, optname, is_set); + } + int ImageOptions::unset(int optname) { return librbd::image_options_unset(opts, optname); @@ -1318,6 +1323,12 @@ extern "C" int rbd_image_options_get_uint64(rbd_image_options_t opts, int optnam return librbd::image_options_get(opts, optname, optval); } +extern "C" int rbd_image_options_is_set(rbd_image_options_t opts, int optname, + bool* is_set) +{ + return librbd::image_options_is_set(opts, optname, is_set); +} + extern "C" int rbd_image_options_unset(rbd_image_options_t opts, int optname) { return librbd::image_options_unset(opts, optname); diff --git a/src/test/librbd/test_librbd.cc b/src/test/librbd/test_librbd.cc index cd9decf171e8..52b5d4572673 100644 --- a/src/test/librbd/test_librbd.cc +++ b/src/test/librbd/test_librbd.cc @@ -3935,6 +3935,13 @@ TEST_F(TestLibRBD, TestImageOptions) uint64_t stripe_count = 16; rbd_image_options_t opts; rbd_image_options_create(&opts); + + bool is_set; + ASSERT_EQ(-EINVAL, rbd_image_options_is_set(opts, 12345, &is_set)); + ASSERT_EQ(0, rbd_image_options_is_set(opts, RBD_IMAGE_OPTION_FORMAT, + &is_set)); + ASSERT_FALSE(is_set); + ASSERT_EQ(0, rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_FORMAT, 2)); ASSERT_EQ(0, rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_FEATURES, @@ -3946,6 +3953,10 @@ TEST_F(TestLibRBD, TestImageOptions) ASSERT_EQ(0, rbd_image_options_set_uint64(opts, RBD_IMAGE_OPTION_STRIPE_COUNT, stripe_count)); + ASSERT_EQ(0, rbd_image_options_is_set(opts, RBD_IMAGE_OPTION_FORMAT, + &is_set)); + ASSERT_TRUE(is_set); + std::string parent_name = get_temp_image_name(); // make parent