Skip to content

Commit

Permalink
librbd: add rbd_image_options_is_set helper method to API
Browse files Browse the repository at this point in the history
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
(cherry picked from commit 2633b04)
  • Loading branch information
Jason Dillaman authored and Abhishek Varshney committed May 6, 2016
1 parent 791eba8 commit ca13a95
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/include/rbd/librbd.h
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/include/rbd/librbd.hpp
Expand Up @@ -149,6 +149,7 @@ class CEPH_RBD_API ImageOptions {
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;
Expand Down
13 changes: 13 additions & 0 deletions src/librbd/internal.cc
Expand Up @@ -749,6 +749,19 @@ int mirror_image_disable_internal(ImageCtx *ictx, bool force) {
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);
Expand Down
2 changes: 2 additions & 0 deletions src/librbd/internal.h
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/librbd/librbd.cc
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions src/test/librbd/test_librbd.cc
Expand Up @@ -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,
Expand All @@ -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
Expand Down

0 comments on commit ca13a95

Please sign in to comment.