]> 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)
committerJason Dillaman <dillaman@redhat.com>
Mon, 2 May 2016 21:11:48 +0000 (17:11 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
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 03c85b7185f6648e28d6aa900c006639f1876d7a..eefa689d63029e7a9a5354b9ae3a652abaa6717d 100644 (file)
@@ -155,6 +155,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 3cba391d3ebb3f8b209113a3cf05ab06485920bd..1ead0909bad750bc1424f0b0fcebd3f396f1cffe 100644 (file)
@@ -163,6 +163,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 3ec1f35e11ad0787a732a7df4ef0ce462ad74bea..8a5161f4a96a20750f1138c241bf91aeb83bed38 100644 (file)
@@ -750,6 +750,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 c58c5f2c3d27087c61577962a1bcd07822652a8e..47f6f3381541af2dd4cfc049f378fca1707f2785 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 339bbf367f6d5039166331f5608b05e48dd37b3a..c3cc7e8ef3bfbd37eb7c5c971efef93ae6cf59fe 100644 (file)
@@ -514,6 +514,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);
@@ -1352,6 +1357,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 064af73bcef1891125c151c23315ecc48c16bec3..c3754610b12d05469d9f1f68e004dbcbfe0da8b9 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