]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: add rbd_image_options_is_set helper method to API
authorJason Dillaman <dillaman@redhat.com>
Mon, 2 May 2016 18:51:31 +0000 (14:51 -0400)
committerAbhishek Varshney <abhishek.varshney@flipkart.com>
Fri, 6 May 2016 14:34:06 +0000 (20:04 +0530)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit 2633b045e0b57827cc10c2e7707bd5a5e344e59a)

src/include/rbd/librbd.h
src/include/rbd/librbd.hpp
src/librbd/internal.cc
src/librbd/internal.h
src/librbd/librbd.cc
src/test/librbd/test_librbd.cc

index 49ed98e9d7d85aaaf349c5b04ff9899b211136bb..3bfa927a793b00287ec42cd7cc4efe9023ff780c 100644 (file)
@@ -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);
index f328c424a24a0509af37a37b8e18e8e0a2be4e69..19c0efbc948c2c7119d259ee1dca113cfca39da0 100644 (file)
@@ -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;
index 5276052c5190fd18f9031b27809082663c764625..365e7918a6149f31d7bea55f3c624d4df8ad57ad 100644 (file)
@@ -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<image_options_ref*>(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<image_options_ref*>(opts);
index c2413f4e0695083cb0bb802ebebc85c0d63a6192..41c8f1f0b108cf0e200b679500b589e8ee2882f5 100644 (file)
@@ -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);
index 0cc3f9521650171e86c2eb51a45989a744f304df..a98739ea752260454132a1cece03963a47f1c893 100644 (file)
@@ -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);
index cd9decf171e83e6d1adbaa117c853be58d5b19e7..52b5d457267348aba1ffeac328ba5b9dbd2e5fe0 100644 (file)
@@ -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