From c701e0689790a1dec84aea33354d62677e19fb94 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Thu, 2 Feb 2017 13:54:13 -0500 Subject: [PATCH] librbd: move group and diff API functions The group and diff_iterate API functions are already in separate units, so it's trivial to move them to the new 'api' namespace. Signed-off-by: Jason Dillaman --- src/librbd/CMakeLists.txt | 4 +- src/librbd/Group.h | 30 --------- src/librbd/{ => api}/DiffIterate.cc | 96 +++++++++++++++++++++-------- src/librbd/{ => api}/DiffIterate.h | 42 ++++++++----- src/librbd/{ => api}/Group.cc | 84 +++++++++++++++---------- src/librbd/api/Group.h | 42 +++++++++++++ src/librbd/internal.cc | 32 ---------- src/librbd/internal.h | 4 -- src/librbd/librbd.cc | 52 +++++++++------- src/test/librbd/test_internal.cc | 6 +- 10 files changed, 224 insertions(+), 168 deletions(-) delete mode 100644 src/librbd/Group.h rename src/librbd/{ => api}/DiffIterate.cc (87%) rename src/librbd/{ => api}/DiffIterate.h (60%) rename src/librbd/{ => api}/Group.cc (81%) create mode 100644 src/librbd/api/Group.h diff --git a/src/librbd/CMakeLists.txt b/src/librbd/CMakeLists.txt index c7b003b46675b..456c2d8f58295 100644 --- a/src/librbd/CMakeLists.txt +++ b/src/librbd/CMakeLists.txt @@ -7,9 +7,7 @@ set(librbd_internal_srcs AsyncObjectThrottle.cc AsyncOperation.cc AsyncRequest.cc - DiffIterate.cc ExclusiveLock.cc - Group.cc ImageCtx.cc ImageState.cc ImageWatcher.cc @@ -23,6 +21,8 @@ set(librbd_internal_srcs Operations.cc Utils.cc Watcher.cc + api/DiffIterate.cc + api/Group.cc api/Image.cc api/Mirror.cc cache/ImageWriteback.cc diff --git a/src/librbd/Group.h b/src/librbd/Group.h deleted file mode 100644 index 87b638b9c8c9f..0000000000000 --- a/src/librbd/Group.h +++ /dev/null @@ -1,30 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab - -#ifndef CEPH_LIBRBD_GROUP_H -#define CEPH_LIBRBD_GROUP_H - -#include "include/rados/librados.hpp" -#include "include/rbd/librbd.hpp" -#include -#include - -namespace librbd { - -struct ImageCtx; - -// Consistency groups functions -int group_create(librados::IoCtx& io_ctx, const char *imgname); -int group_remove(librados::IoCtx& io_ctx, const char *group_name); -int group_list(librados::IoCtx& io_ctx, std::vector *names); -int group_image_add(librados::IoCtx& group_ioctx, const char *group_name, - librados::IoCtx& image_ioctx, const char *image_name); -int group_image_remove(librados::IoCtx& group_ioctx, const char *group_name, - librados::IoCtx& image_ioctx, const char *image_name); -int group_image_list(librados::IoCtx& group_ioctx, const char *group_name, - std::vector *images); -int image_get_group(ImageCtx *ictx, group_spec_t *group_spec); - -} // namespace librbd - -#endif // CEPH_LIBRBD_GROUP_H diff --git a/src/librbd/DiffIterate.cc b/src/librbd/api/DiffIterate.cc similarity index 87% rename from src/librbd/DiffIterate.cc rename to src/librbd/api/DiffIterate.cc index d24153e13f440..28b3b83eefd65 100644 --- a/src/librbd/DiffIterate.cc +++ b/src/librbd/api/DiffIterate.cc @@ -1,10 +1,12 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab -#include "librbd/DiffIterate.h" +#include "librbd/api/DiffIterate.h" #include "librbd/ImageCtx.h" +#include "librbd/ImageState.h" #include "librbd/ObjectMap.h" #include "librbd/Utils.h" +#include "librbd/internal.h" #include "include/rados/librados.hpp" #include "include/interval_set.h" #include "common/errno.h" @@ -20,6 +22,7 @@ #define dout_prefix *_dout << "librbd::DiffIterate: " namespace librbd { +namespace api { namespace { @@ -30,7 +33,7 @@ enum ObjectDiffState { }; struct DiffContext { - DiffIterate::Callback callback; + DiffIterate<>::Callback callback; void *callback_arg; bool whole_object; uint64_t from_snap_id; @@ -38,7 +41,8 @@ struct DiffContext { interval_set parent_diff; OrderedThrottle throttle; - DiffContext(ImageCtx &image_ctx, DiffIterate::Callback callback, + template + DiffContext(I &image_ctx, DiffIterate<>::Callback callback, void *callback_arg, bool _whole_object, uint64_t _from_snap_id, uint64_t _end_snap_id) : callback(callback), callback_arg(callback_arg), @@ -50,10 +54,11 @@ struct DiffContext { class C_DiffObject : public Context { public: - C_DiffObject(ImageCtx &image_ctx, librados::IoCtx &head_ctx, + template + C_DiffObject(I &image_ctx, librados::IoCtx &head_ctx, DiffContext &diff_context, const std::string &oid, uint64_t offset, const std::vector &object_extents) - : m_image_ctx(image_ctx), m_head_ctx(head_ctx), + : m_cct(image_ctx.cct), m_head_ctx(head_ctx), m_diff_context(diff_context), m_oid(oid), m_offset(offset), m_object_extents(object_extents), m_snap_ret(0) { } @@ -76,7 +81,7 @@ protected: typedef std::list Diffs; void finish(int r) override { - CephContext *cct = m_image_ctx.cct; + CephContext *cct = m_cct; if (r == 0 && m_snap_ret < 0) { r = m_snap_ret; } @@ -108,7 +113,7 @@ protected: } private: - ImageCtx &m_image_ctx; + CephContext *m_cct; librados::IoCtx &m_head_ctx; DiffContext &m_diff_context; std::string m_oid; @@ -119,7 +124,7 @@ private: int m_snap_ret; void compute_diffs(Diffs *diffs) { - CephContext *cct = m_image_ctx.cct; + CephContext *cct = m_cct; // calc diff from from_snap_id -> to_snap_id interval_set diff; @@ -158,9 +163,9 @@ private: interval_set overlap; // object extents overlap.insert(opos, r->second); overlap.intersection_of(diff); - ldout(m_image_ctx.cct, 20) << " opos " << opos - << " buf " << r->first << "~" << r->second - << " overlap " << overlap << dendl; + ldout(cct, 20) << " opos " << opos + << " buf " << r->first << "~" << r->second + << " overlap " << overlap << dendl; for (interval_set::iterator s = overlap.begin(); s != overlap.end(); ++s) { uint64_t su_off = s.get_start() - opos; @@ -189,8 +194,7 @@ private: interval_set o; o.insert(m_offset + r->first, r->second); o.intersection_of(m_diff_context.parent_diff); - ldout(m_image_ctx.cct, 20) << " reporting parent overlap " << o - << dendl; + ldout(m_cct, 20) << " reporting parent overlap " << o << dendl; for (interval_set::iterator s = o.begin(); s != o.end(); ++s) { diffs->push_back(boost::make_tuple(s.get_start(), s.get_len(), @@ -202,9 +206,53 @@ private: } }; +int simple_diff_cb(uint64_t off, size_t len, int exists, void *arg) { + // it's possible for a discard to create a hole in the parent image -- ignore + if (exists) { + interval_set *diff = static_cast *>(arg); + diff->insert(off, len); + } + return 0; +} + } // anonymous namespace -int DiffIterate::execute() { +template +int DiffIterate::diff_iterate(I *ictx, const char *fromsnapname, + uint64_t off, uint64_t len, + bool include_parent, bool whole_object, + int (*cb)(uint64_t, size_t, int, void *), + void *arg) +{ + ldout(ictx->cct, 20) << "diff_iterate " << ictx << " off = " << off + << " len = " << len << dendl; + + // ensure previous writes are visible to listsnaps + { + RWLock::RLocker owner_locker(ictx->owner_lock); + ictx->flush(); + } + + int r = ictx->state->refresh_if_required(); + if (r < 0) { + return r; + } + + ictx->snap_lock.get_read(); + r = clip_io(ictx, off, &len); + ictx->snap_lock.put_read(); + if (r < 0) { + return r; + } + + DiffIterate command(*ictx, fromsnapname, off, len, include_parent, + whole_object, cb, arg); + r = command.execute(); + return r; +} + +template +int DiffIterate::execute() { CephContext* cct = m_image_ctx.cct; librados::IoCtx head_ctx; @@ -271,7 +319,7 @@ int DiffIterate::execute() { ldout(cct, 10) << " first getting parent diff" << dendl; DiffIterate diff_parent(*m_image_ctx.parent, NULL, 0, overlap, m_include_parent, m_whole_object, - &DiffIterate::simple_diff_cb, + &simple_diff_cb, &diff_context.parent_diff); r = diff_parent.execute(); } @@ -338,8 +386,9 @@ int DiffIterate::execute() { return 0; } -int DiffIterate::diff_object_map(uint64_t from_snap_id, uint64_t to_snap_id, - BitVector<2>* object_diff_state) { +template +int DiffIterate::diff_object_map(uint64_t from_snap_id, uint64_t to_snap_id, + BitVector<2>* object_diff_state) { assert(m_image_ctx.snap_lock.is_locked()); CephContext* cct = m_image_ctx.cct; @@ -448,14 +497,7 @@ int DiffIterate::diff_object_map(uint64_t from_snap_id, uint64_t to_snap_id, return 0; } -int DiffIterate::simple_diff_cb(uint64_t off, size_t len, int exists, - void *arg) { - // it's possible for a discard to create a hole in the parent image -- ignore - if (exists) { - interval_set *diff = static_cast *>(arg); - diff->insert(off, len); - } - return 0; -} - +} // namespace api } // namespace librbd + +template class librbd::api::DiffIterate; diff --git a/src/librbd/DiffIterate.h b/src/librbd/api/DiffIterate.h similarity index 60% rename from src/librbd/DiffIterate.h rename to src/librbd/api/DiffIterate.h index 6b80af3ad68b6..7790dcd6a87c9 100644 --- a/src/librbd/DiffIterate.h +++ b/src/librbd/api/DiffIterate.h @@ -1,7 +1,8 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab -#ifndef CEPH_LIBRBD_DIFF_ITERATE_H -#define CEPH_LIBRBD_DIFF_ITERATE_H + +#ifndef CEPH_LIBRBD_API_DIFF_ITERATE_H +#define CEPH_LIBRBD_API_DIFF_ITERATE_H #include "include/int_types.h" #include "common/bit_vector.hpp" @@ -10,11 +11,30 @@ namespace librbd { class ImageCtx; +namespace api { + +template class DiffIterate { public: typedef int (*Callback)(uint64_t, size_t, int, void *); - DiffIterate(ImageCtx &image_ctx, const char *from_snap_name, uint64_t off, + static int diff_iterate(ImageCtxT *ictx, const char *fromsnapname, + uint64_t off, uint64_t len, bool include_parent, + bool whole_object, + int (*cb)(uint64_t, size_t, int, void *), + void *arg); + +private: + ImageCtxT &m_image_ctx; + const char* m_from_snap_name; + uint64_t m_offset; + uint64_t m_length; + bool m_include_parent; + bool m_whole_object; + Callback m_callback; + void *m_callback_arg; + + DiffIterate(ImageCtxT &image_ctx, const char *from_snap_name, uint64_t off, uint64_t len, bool include_parent, bool whole_object, Callback callback, void *callback_arg) : m_image_ctx(image_ctx), m_from_snap_name(from_snap_name), m_offset(off), @@ -26,22 +46,14 @@ public: int execute(); -private: - ImageCtx &m_image_ctx; - const char* m_from_snap_name; - uint64_t m_offset; - uint64_t m_length; - bool m_include_parent; - bool m_whole_object; - Callback m_callback; - void *m_callback_arg; - int diff_object_map(uint64_t from_snap_id, uint64_t to_snap_id, BitVector<2>* object_diff_state); - static int simple_diff_cb(uint64_t off, size_t len, int exists, void *arg); }; +} // namespace api } // namespace librbd -#endif // CEPH_LIBRBD_DIFF_ITERATE_H +extern template class librbd::api::DiffIterate; + +#endif // CEPH_LIBRBD_API_DIFF_ITERATE_H diff --git a/src/librbd/Group.cc b/src/librbd/api/Group.cc similarity index 81% rename from src/librbd/Group.cc rename to src/librbd/api/Group.cc index 8e3d82b2e8ccc..7e60fc5202140 100644 --- a/src/librbd/Group.cc +++ b/src/librbd/api/Group.cc @@ -1,16 +1,15 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab +#include "librbd/api/Group.h" #include "common/errno.h" - -#include "librbd/Group.h" #include "librbd/ImageState.h" #include "librbd/Utils.h" #include "librbd/io/AioCompletion.h" #define dout_subsys ceph_subsys_rbd #undef dout_prefix -#define dout_prefix *_dout << "librbd::Group: " +#define dout_prefix *_dout << "librbd::api::Group: " << __func__ << ": " using std::map; using std::pair; @@ -25,10 +24,12 @@ using librados::IoCtx; using librados::Rados; namespace librbd { +namespace api { // Consistency groups functions -int group_create(librados::IoCtx& io_ctx, const char *group_name) +template +int Group::create(librados::IoCtx& io_ctx, const char *group_name) { CephContext *cct = (CephContext *)io_ctx.cct(); @@ -42,7 +43,8 @@ int group_create(librados::IoCtx& io_ctx, const char *group_name) ldout(cct, 2) << "adding consistency group to directory..." << dendl; - int r = cls_client::group_dir_add(&io_ctx, RBD_GROUP_DIRECTORY, group_name, id); + int r = cls_client::group_dir_add(&io_ctx, RBD_GROUP_DIRECTORY, group_name, + id); if (r < 0) { lderr(cct) << "error adding consistency group to directory: " << cpp_strerror(r) @@ -71,13 +73,14 @@ err_remove_from_dir: return r; } -int group_remove(librados::IoCtx& io_ctx, const char *group_name) +template +int Group::remove(librados::IoCtx& io_ctx, const char *group_name) { CephContext *cct((CephContext *)io_ctx.cct()); - ldout(cct, 20) << "group_remove " << &io_ctx << " " << group_name << dendl; + ldout(cct, 20) << "io_ctx=" << &io_ctx << " " << group_name << dendl; std::vector images; - int r = group_image_list(io_ctx, group_name, &images); + int r = image_list(io_ctx, group_name, &images); if (r < 0 && r != -ENOENT) { lderr(cct) << "error listing group images" << dendl; return r; @@ -87,7 +90,7 @@ int group_remove(librados::IoCtx& io_ctx, const char *group_name) librados::Rados rados(io_ctx); IoCtx image_ioctx; rados.ioctx_create2(i.pool, image_ioctx); - r = group_image_remove(io_ctx, group_name, image_ioctx, i.name.c_str()); + r = image_remove(io_ctx, group_name, image_ioctx, i.name.c_str()); if (r < 0 && r != -ENOENT) { lderr(cct) << "error removing image from a group" << dendl; return r; @@ -110,8 +113,8 @@ int group_remove(librados::IoCtx& io_ctx, const char *group_name) return r; } - r = cls_client::group_dir_remove(&io_ctx, RBD_GROUP_DIRECTORY, - group_name, group_id); + r = cls_client::group_dir_remove(&io_ctx, RBD_GROUP_DIRECTORY, group_name, + group_id); if (r < 0 && r != -ENOENT) { lderr(cct) << "error removing group from directory" << dendl; return r; @@ -120,10 +123,11 @@ int group_remove(librados::IoCtx& io_ctx, const char *group_name) return 0; } -int group_list(IoCtx& io_ctx, vector *names) +template +int Group::list(IoCtx& io_ctx, vector *names) { CephContext *cct = (CephContext *)io_ctx.cct(); - ldout(cct, 20) << "group_list " << &io_ctx << dendl; + ldout(cct, 20) << "io_ctx=" << &io_ctx << dendl; int max_read = 1024; string last_read = ""; @@ -149,17 +153,19 @@ int group_list(IoCtx& io_ctx, vector *names) return 0; } -int group_image_add(librados::IoCtx& group_ioctx, const char *group_name, +template +int Group::image_add(librados::IoCtx& group_ioctx, const char *group_name, librados::IoCtx& image_ioctx, const char *image_name) { CephContext *cct = (CephContext *)group_ioctx.cct(); - ldout(cct, 20) << "group_image_add " << &group_ioctx + ldout(cct, 20) << "io_ctx=" << &group_ioctx << " group name " << group_name << " image " << &image_ioctx << " name " << image_name << dendl; string group_id; - int r = cls_client::dir_get_id(&group_ioctx, RBD_GROUP_DIRECTORY, group_name, &group_id); + int r = cls_client::dir_get_id(&group_ioctx, RBD_GROUP_DIRECTORY, group_name, + &group_id); if (r < 0) { lderr(cct) << "error reading consistency group id object: " << cpp_strerror(r) @@ -174,7 +180,8 @@ int group_image_add(librados::IoCtx& group_ioctx, const char *group_name, string image_id; - r = cls_client::dir_get_id(&image_ioctx, RBD_DIRECTORY, image_name, &image_id); + r = cls_client::dir_get_id(&image_ioctx, RBD_DIRECTORY, image_name, + &image_id); if (r < 0) { lderr(cct) << "error reading image id object: " << cpp_strerror(-r) << dendl; @@ -186,10 +193,11 @@ int group_image_add(librados::IoCtx& group_ioctx, const char *group_name, ldout(cct, 20) << "adding image " << image_name << " image id " << image_header_oid << dendl; - cls::rbd::GroupImageStatus incomplete_st(image_id, image_ioctx.get_id(), - cls::rbd::GROUP_IMAGE_LINK_STATE_INCOMPLETE); - cls::rbd::GroupImageStatus attached_st(image_id, image_ioctx.get_id(), - cls::rbd::GROUP_IMAGE_LINK_STATE_ATTACHED); + cls::rbd::GroupImageStatus incomplete_st( + image_id, image_ioctx.get_id(), + cls::rbd::GROUP_IMAGE_LINK_STATE_INCOMPLETE); + cls::rbd::GroupImageStatus attached_st( + image_id, image_ioctx.get_id(), cls::rbd::GROUP_IMAGE_LINK_STATE_ATTACHED); r = cls_client::group_image_set(&group_ioctx, group_header_oid, incomplete_st); @@ -202,8 +210,7 @@ int group_image_add(librados::IoCtx& group_ioctx, const char *group_name, return r; } - r = cls_client::image_add_group(&image_ioctx, image_header_oid, - group_spec); + r = cls_client::image_add_group(&image_ioctx, image_header_oid, group_spec); if (r < 0) { lderr(cct) << "error adding group reference to image: " << cpp_strerror(-r) << dendl; @@ -219,17 +226,19 @@ int group_image_add(librados::IoCtx& group_ioctx, const char *group_name, return r; } -int group_image_remove(librados::IoCtx& group_ioctx, const char *group_name, - librados::IoCtx& image_ioctx, const char *image_name) +template +int Group::image_remove(librados::IoCtx& group_ioctx, const char *group_name, + librados::IoCtx& image_ioctx, const char *image_name) { CephContext *cct = (CephContext *)group_ioctx.cct(); - ldout(cct, 20) << "group_remove_image " << &group_ioctx + ldout(cct, 20) << "io_ctx=" << &group_ioctx << " group name " << group_name << " image " << &image_ioctx << " name " << image_name << dendl; string group_id; - int r = cls_client::dir_get_id(&group_ioctx, RBD_GROUP_DIRECTORY, group_name, &group_id); + int r = cls_client::dir_get_id(&group_ioctx, RBD_GROUP_DIRECTORY, group_name, + &group_id); if (r < 0) { lderr(cct) << "error reading consistency group id object: " << cpp_strerror(r) @@ -242,7 +251,8 @@ int group_image_remove(librados::IoCtx& group_ioctx, const char *group_name, << " group id " << group_header_oid << dendl; string image_id; - r = cls_client::dir_get_id(&image_ioctx, RBD_DIRECTORY, image_name, &image_id); + r = cls_client::dir_get_id(&image_ioctx, RBD_DIRECTORY, image_name, + &image_id); if (r < 0) { lderr(cct) << "error reading image id object: " << cpp_strerror(-r) << dendl; @@ -256,8 +266,9 @@ int group_image_remove(librados::IoCtx& group_ioctx, const char *group_name, cls::rbd::GroupSpec group_spec(group_id, group_ioctx.get_id()); - cls::rbd::GroupImageStatus incomplete_st(image_id, image_ioctx.get_id(), - cls::rbd::GROUP_IMAGE_LINK_STATE_INCOMPLETE); + cls::rbd::GroupImageStatus incomplete_st( + image_id, image_ioctx.get_id(), + cls::rbd::GROUP_IMAGE_LINK_STATE_INCOMPLETE); cls::rbd::GroupImageSpec spec(image_id, image_ioctx.get_id()); @@ -288,12 +299,13 @@ int group_image_remove(librados::IoCtx& group_ioctx, const char *group_name, return 0; } -int group_image_list(librados::IoCtx& group_ioctx, +template +int Group::image_list(librados::IoCtx& group_ioctx, const char *group_name, std::vector *images) { CephContext *cct = (CephContext *)group_ioctx.cct(); - ldout(cct, 20) << "group_image_list " << &group_ioctx + ldout(cct, 20) << "io_ctx=" << &group_ioctx << " group name " << group_name << dendl; string group_id; @@ -319,7 +331,7 @@ int group_image_list(librados::IoCtx& group_ioctx, cls::rbd::GroupImageSpec start_last; r = cls_client::group_image_list(&group_ioctx, group_header_oid, - start_last, max_read, &image_ids_page); + start_last, max_read, &image_ids_page); if (r < 0) { lderr(cct) << "error reading image list from consistency group: " @@ -356,7 +368,8 @@ int group_image_list(librados::IoCtx& group_ioctx, return 0; } -int image_get_group(ImageCtx *ictx, group_spec_t *group_spec) +template +int Group::image_get_group(I *ictx, group_spec_t *group_spec) { int r = ictx->state->refresh_if_required(); if (r < 0) @@ -382,4 +395,7 @@ int image_get_group(ImageCtx *ictx, group_spec_t *group_spec) return 0; } +} // namespace api } // namespace librbd + +template class librbd::api::Group; diff --git a/src/librbd/api/Group.h b/src/librbd/api/Group.h new file mode 100644 index 0000000000000..4773cb5af7497 --- /dev/null +++ b/src/librbd/api/Group.h @@ -0,0 +1,42 @@ +// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- +// vim: ts=8 sw=2 smarttab + +#ifndef CEPH_LIBRBD_API_GROUP_H +#define CEPH_LIBRBD_API_GROUP_H + +#include "include/rbd/librbd.hpp" +#include +#include + +namespace librados { struct IoCtx; } + +namespace librbd { + +struct ImageCtx; + +namespace api { + +template +struct Group { + + static int create(librados::IoCtx& io_ctx, const char *imgname); + static int remove(librados::IoCtx& io_ctx, const char *group_name); + static int list(librados::IoCtx& io_ctx, std::vector *names); + + static int image_add(librados::IoCtx& group_ioctx, const char *group_name, + librados::IoCtx& image_ioctx, const char *image_name); + static int image_remove(librados::IoCtx& group_ioctx, const char *group_name, + librados::IoCtx& image_ioctx, const char *image_name); + static int image_list(librados::IoCtx& group_ioctx, const char *group_name, + std::vector *images); + + static int image_get_group(ImageCtxT *ictx, group_spec_t *group_spec); + +}; + +} // namespace api +} // namespace librbd + +extern template class librbd::api::Group; + +#endif // CEPH_LIBRBD_API_GROUP_H diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index c7b6611aba1f2..3432ae71c4579 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -21,7 +21,6 @@ #include "cls/journal/cls_journal_types.h" #include "cls/journal/cls_journal_client.h" -#include "librbd/DiffIterate.h" #include "librbd/ExclusiveLock.h" #include "librbd/ImageCtx.h" #include "librbd/ImageState.h" @@ -2015,37 +2014,6 @@ int validate_pool(IoCtx &io_ctx, CephContext *cct) { return total_read; } - int diff_iterate(ImageCtx *ictx, const char *fromsnapname, uint64_t off, - uint64_t len, bool include_parent, bool whole_object, - int (*cb)(uint64_t, size_t, int, void *), void *arg) - { - ldout(ictx->cct, 20) << "diff_iterate " << ictx << " off = " << off - << " len = " << len << dendl; - - // ensure previous writes are visible to listsnaps - { - RWLock::RLocker owner_locker(ictx->owner_lock); - ictx->flush(); - } - - int r = ictx->state->refresh_if_required(); - if (r < 0) { - return r; - } - - ictx->snap_lock.get_read(); - r = clip_io(ictx, off, &len); - ictx->snap_lock.put_read(); - if (r < 0) { - return r; - } - - DiffIterate command(*ictx, fromsnapname, off, len, include_parent, - whole_object, cb, arg); - r = command.execute(); - return r; - } - // validate extent against image size; clip to image size if necessary int clip_io(ImageCtx *ictx, uint64_t off, uint64_t *len) { diff --git a/src/librbd/internal.h b/src/librbd/internal.h index 80043f2d5f178..65bb5a40eab10 100644 --- a/src/librbd/internal.h +++ b/src/librbd/internal.h @@ -185,10 +185,6 @@ namespace librbd { int64_t read_iterate(ImageCtx *ictx, uint64_t off, uint64_t len, int (*cb)(uint64_t, size_t, const char *, void *), void *arg); - int diff_iterate(ImageCtx *ictx, const char *fromsnapname, uint64_t off, - uint64_t len, bool include_parent, bool whole_object, - int (*cb)(uint64_t, size_t, int, void *), - void *arg); void readahead(ImageCtx *ictx, const vector >& image_extents); diff --git a/src/librbd/librbd.cc b/src/librbd/librbd.cc index 390af617d50b9..dea4ecb9478e5 100644 --- a/src/librbd/librbd.cc +++ b/src/librbd/librbd.cc @@ -23,11 +23,12 @@ #include "cls/rbd/cls_rbd_client.h" #include "cls/rbd/cls_rbd_types.h" -#include "librbd/Group.h" #include "librbd/ImageCtx.h" #include "librbd/ImageState.h" #include "librbd/internal.h" #include "librbd/Operations.h" +#include "librbd/api/DiffIterate.h" +#include "librbd/api/Group.h" #include "librbd/api/Mirror.h" #include "librbd/io/AioCompletion.h" #include "librbd/io/ImageRequestWQ.h" @@ -477,7 +478,7 @@ namespace librbd { TracepointProvider::initialize(get_cct(io_ctx)); tracepoint(librbd, group_create_enter, io_ctx.get_pool_name().c_str(), io_ctx.get_id(), group_name); - int r = librbd::group_create(io_ctx, group_name); + int r = librbd::api::Group<>::create(io_ctx, group_name); tracepoint(librbd, group_create_exit, r); return r; } @@ -487,7 +488,7 @@ namespace librbd { TracepointProvider::initialize(get_cct(io_ctx)); tracepoint(librbd, group_remove_enter, io_ctx.get_pool_name().c_str(), io_ctx.get_id(), group_name); - int r = librbd::group_remove(io_ctx, group_name); + int r = librbd::api::Group<>::remove(io_ctx, group_name); tracepoint(librbd, group_remove_exit, r); return r; } @@ -498,7 +499,7 @@ namespace librbd { tracepoint(librbd, group_list_enter, io_ctx.get_pool_name().c_str(), io_ctx.get_id()); - int r = librbd::group_list(io_ctx, names); + int r = librbd::api::Group<>::list(io_ctx, names); if (r >= 0) { for (auto itr : *names) { tracepoint(librbd, group_list_entry, itr.c_str()); @@ -515,7 +516,8 @@ namespace librbd { tracepoint(librbd, group_image_add_enter, group_ioctx.get_pool_name().c_str(), group_ioctx.get_id(), group_name, image_ioctx.get_pool_name().c_str(), image_ioctx.get_id(), image_name); - int r = librbd::group_image_add(group_ioctx, group_name, image_ioctx, image_name); + int r = librbd::api::Group<>::image_add(group_ioctx, group_name, + image_ioctx, image_name); tracepoint(librbd, group_image_add_exit, r); return r; } @@ -527,7 +529,8 @@ namespace librbd { tracepoint(librbd, group_image_remove_enter, group_ioctx.get_pool_name().c_str(), group_ioctx.get_id(), group_name, image_ioctx.get_pool_name().c_str(), image_ioctx.get_id(), image_name); - int r = librbd::group_image_remove(group_ioctx, group_name, image_ioctx, image_name); + int r = librbd::api::Group<>::image_remove(group_ioctx, group_name, + image_ioctx, image_name); tracepoint(librbd, group_image_remove_exit, r); return r; } @@ -538,7 +541,7 @@ namespace librbd { TracepointProvider::initialize(get_cct(group_ioctx)); tracepoint(librbd, group_image_list_enter, group_ioctx.get_pool_name().c_str(), group_ioctx.get_id(), group_name); - int r = librbd::group_image_list(group_ioctx, group_name, images); + int r = librbd::api::Group<>::image_list(group_ioctx, group_name, images); tracepoint(librbd, group_image_list_exit, r); return r; } @@ -743,7 +746,7 @@ namespace librbd { { ImageCtx *ictx = (ImageCtx *)ctx; tracepoint(librbd, image_get_group_enter, ictx->name.c_str()); - int r = librbd::image_get_group(ictx, group_spec); + int r = librbd::api::Group<>::image_get_group(ictx, group_spec); tracepoint(librbd, image_get_group_exit, r); return r; } @@ -1277,8 +1280,8 @@ namespace librbd { tracepoint(librbd, diff_iterate_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, fromsnapname, ofs, len, true, false); - int r = librbd::diff_iterate(ictx, fromsnapname, ofs, len, true, false, cb, - arg); + int r = librbd::api::DiffIterate<>::diff_iterate(ictx, fromsnapname, ofs, + len, true, false, cb, arg); tracepoint(librbd, diff_iterate_exit, r); return r; } @@ -1291,8 +1294,9 @@ namespace librbd { tracepoint(librbd, diff_iterate_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, fromsnapname, ofs, len, include_parent, whole_object); - int r = librbd::diff_iterate(ictx, fromsnapname, ofs, len, include_parent, - whole_object, cb, arg); + int r = librbd::api::DiffIterate<>::diff_iterate(ictx, fromsnapname, ofs, + len, include_parent, + whole_object, cb, arg); tracepoint(librbd, diff_iterate_exit, r); return r; } @@ -2890,8 +2894,8 @@ extern "C" int rbd_diff_iterate(rbd_image_t image, tracepoint(librbd, diff_iterate_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, fromsnapname, ofs, len, true, false); - int r = librbd::diff_iterate(ictx, fromsnapname, ofs, len, true, false, cb, - arg); + int r = librbd::api::DiffIterate<>::diff_iterate(ictx, fromsnapname, ofs, len, + true, false, cb, arg); tracepoint(librbd, diff_iterate_exit, r); return r; } @@ -2906,8 +2910,9 @@ extern "C" int rbd_diff_iterate2(rbd_image_t image, const char *fromsnapname, tracepoint(librbd, diff_iterate_enter, ictx, ictx->name.c_str(), ictx->snap_name.c_str(), ictx->read_only, fromsnapname, ofs, len, include_parent != 0, whole_object != 0); - int r = librbd::diff_iterate(ictx, fromsnapname, ofs, len, include_parent, - whole_object, cb, arg); + int r = librbd::api::DiffIterate<>::diff_iterate(ictx, fromsnapname, ofs, len, + include_parent, whole_object, + cb, arg); tracepoint(librbd, diff_iterate_exit, r); return r; } @@ -3395,7 +3400,7 @@ extern "C" int rbd_group_create(rados_ioctx_t p, const char *name) TracepointProvider::initialize(get_cct(io_ctx)); tracepoint(librbd, group_create_enter, io_ctx.get_pool_name().c_str(), io_ctx.get_id(), name); - int r = librbd::group_create(io_ctx, name); + int r = librbd::api::Group<>::create(io_ctx, name); tracepoint(librbd, group_create_exit, r); return r; } @@ -3407,7 +3412,7 @@ extern "C" int rbd_group_remove(rados_ioctx_t p, const char *name) TracepointProvider::initialize(get_cct(io_ctx)); tracepoint(librbd, group_remove_enter, io_ctx.get_pool_name().c_str(), io_ctx.get_id(), name); - int r = librbd::group_remove(io_ctx, name); + int r = librbd::api::Group<>::remove(io_ctx, name); tracepoint(librbd, group_remove_exit, r); return r; } @@ -3475,7 +3480,8 @@ extern "C" int rbd_group_image_add( group_ioctx.get_id(), group_name, image_ioctx.get_pool_name().c_str(), image_ioctx.get_id(), image_name); - int r = librbd::group_image_add(group_ioctx, group_name, image_ioctx, image_name); + int r = librbd::api::Group<>::image_add(group_ioctx, group_name, image_ioctx, + image_name); tracepoint(librbd, group_image_add_exit, r); return r; @@ -3496,7 +3502,8 @@ extern "C" int rbd_group_image_remove( group_ioctx.get_id(), group_name, image_ioctx.get_pool_name().c_str(), image_ioctx.get_id(), image_name); - int r = librbd::group_image_remove(group_ioctx, group_name, image_ioctx, image_name); + int r = librbd::api::Group<>::image_remove(group_ioctx, group_name, + image_ioctx, image_name); tracepoint(librbd, group_image_remove_exit, r); return r; @@ -3515,7 +3522,8 @@ extern "C" int rbd_group_image_list(rados_ioctx_t group_p, group_ioctx.get_id(), group_name); std::vector cpp_images; - int r = librbd::group_image_list(group_ioctx, group_name, &cpp_images); + int r = librbd::api::Group<>::image_list(group_ioctx, group_name, + &cpp_images); if (r == -ENOENT) { tracepoint(librbd, group_image_list_exit, 0); @@ -3556,7 +3564,7 @@ extern "C" int rbd_image_get_group(rados_ioctx_t image_p, tracepoint(librbd, image_get_group_enter, ictx->name.c_str()); librbd::group_spec_t group_spec; - r = librbd::image_get_group(ictx, &group_spec); + r = librbd::api::Group<>::image_get_group(ictx, &group_spec); group_spec_cpp_to_c(group_spec, c_group_spec); tracepoint(librbd, image_get_group_exit, r); ictx->state->close(); diff --git a/src/test/librbd/test_internal.cc b/src/test/librbd/test_internal.cc index db3bbbffaca9d..ed247a3a22591 100644 --- a/src/test/librbd/test_internal.cc +++ b/src/test/librbd/test_internal.cc @@ -1,5 +1,6 @@ // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- // vim: ts=8 sw=2 smarttab + #include "cls/rbd/cls_rbd_types.h" #include "test/librbd/test_fixture.h" #include "test/librbd/test_support.h" @@ -10,6 +11,7 @@ #include "librbd/internal.h" #include "librbd/ObjectMap.h" #include "librbd/Operations.h" +#include "librbd/api/DiffIterate.h" #include "librbd/io/AioCompletion.h" #include "librbd/io/ImageRequest.h" #include "librbd/io/ImageRequestWQ.h" @@ -966,8 +968,8 @@ TEST_F(TestInternal, DiffIterateCloneOverwrite) { interval_set diff; ASSERT_EQ(0, librbd::snap_set(ictx, "one")); - ASSERT_EQ(0, librbd::diff_iterate(ictx, nullptr, 0, size, true, false, - iterate_cb, (void *)&diff)); + ASSERT_EQ(0, librbd::api::DiffIterate<>::diff_iterate( + ictx, nullptr, 0, size, true, false, iterate_cb, (void *)&diff)); ASSERT_EQ(one, diff); } -- 2.39.5