From 71d3e68ba2a709bd4f80369c4f980b350b532eda Mon Sep 17 00:00:00 2001 From: Dongsheng Yang Date: Tue, 14 Mar 2017 17:58:31 +0800 Subject: [PATCH] rbd: introduce a new constructor for ImageOptions Signed-off-by: Dongsheng Yang --- src/include/rbd/librbd.hpp | 1 + src/librbd/internal.cc | 25 +++++++++++++++++++++++++ src/librbd/internal.h | 2 ++ src/librbd/librbd.cc | 5 +++++ 4 files changed, 33 insertions(+) diff --git a/src/include/rbd/librbd.hpp b/src/include/rbd/librbd.hpp index 3c667d2e871..9110e6d896f 100644 --- a/src/include/rbd/librbd.hpp +++ b/src/include/rbd/librbd.hpp @@ -183,6 +183,7 @@ class CEPH_RBD_API ImageOptions { public: ImageOptions(); ImageOptions(rbd_image_options_t opts); + ImageOptions(const ImageOptions &imgopts); ~ImageOptions(); int set(int optname, const std::string& optval); diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index 3432ae71c45..6074711ef41 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -383,6 +383,31 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { *opts = static_cast(opts_); } + void image_options_copy(rbd_image_options_t* opts, + const ImageOptions &orig) + { + image_options_ref* opts_ = new image_options_ref(new image_options_t()); + + *opts = static_cast(opts_); + + std::string str_val; + uint64_t uint64_val; + for (auto &i : IMAGE_OPTIONS_TYPE_MAPPING) { + switch (i.second) { + case STR: + if (orig.get(i.first, &str_val) == 0) { + image_options_set(*opts, i.first, str_val); + } + continue; + case UINT64: + if (orig.get(i.first, &uint64_val) == 0) { + image_options_set(*opts, i.first, uint64_val); + } + continue; + } + } + } + void image_options_destroy(rbd_image_options_t opts) { image_options_ref* opts_ = static_cast(opts); diff --git a/src/librbd/internal.h b/src/librbd/internal.h index 65bb5a40eab..8f91d3c15f2 100644 --- a/src/librbd/internal.h +++ b/src/librbd/internal.h @@ -79,6 +79,8 @@ namespace librbd { void image_options_create(rbd_image_options_t* opts); void image_options_create_ref(rbd_image_options_t* opts, rbd_image_options_t orig); + void image_options_copy(rbd_image_options_t *opts, + const ImageOptions &orig); void image_options_destroy(rbd_image_options_t opts); int image_options_set(rbd_image_options_t opts, int optname, const std::string& optval); diff --git a/src/librbd/librbd.cc b/src/librbd/librbd.cc index 92704f65138..d4238f907b5 100644 --- a/src/librbd/librbd.cc +++ b/src/librbd/librbd.cc @@ -642,6 +642,11 @@ namespace librbd { librbd::image_options_create_ref(&opts, opts_); } + ImageOptions::ImageOptions(const ImageOptions &imgopts) + { + librbd::image_options_copy(&opts, imgopts); + } + ImageOptions::~ImageOptions() { librbd::image_options_destroy(opts);