diff options
Diffstat (limited to '')
-rw-r--r-- | src/librbd/api/Group.cc | 53 |
1 files changed, 19 insertions, 34 deletions
diff --git a/src/librbd/api/Group.cc b/src/librbd/api/Group.cc index bf1c53284f2..97c53abd70f 100644 --- a/src/librbd/api/Group.cc +++ b/src/librbd/api/Group.cc @@ -11,6 +11,7 @@ #include "librbd/ImageWatcher.h" #include "librbd/Operations.h" #include "librbd/Utils.h" +#include "librbd/group/ListSnapshotsRequest.h" #include "librbd/internal.h" #include "librbd/io/AioCompletion.h" @@ -53,36 +54,18 @@ snap_t get_group_snap_id(I* ictx, return CEPH_NOSNAP; } +template <typename I> int group_snap_list(librados::IoCtx& group_ioctx, const std::string& group_id, - std::vector<cls::rbd::GroupSnapshot> *cls_snaps) + bool try_to_sort, bool fail_if_not_sorted, + std::vector<cls::rbd::GroupSnapshot> *cls_snaps) { - CephContext *cct = (CephContext *)group_ioctx.cct(); - - string group_header_oid = util::group_header_name(group_id); - - const int max_read = 1024; - cls::rbd::GroupSnapshot snap_last; - int r; - - for (;;) { - vector<cls::rbd::GroupSnapshot> snaps_page; - - r = cls_client::group_snap_list(&group_ioctx, group_header_oid, - snap_last, max_read, &snaps_page); - - if (r < 0) { - lderr(cct) << "error reading snap list from group: " - << cpp_strerror(-r) << dendl; - return r; - } - cls_snaps->insert(cls_snaps->end(), snaps_page.begin(), snaps_page.end()); - if (snaps_page.size() < max_read) { - break; - } - snap_last = *snaps_page.rbegin(); - } - - return 0; + C_SaferCond cond; + auto req = group::ListSnapshotsRequest<I>::create(group_ioctx, group_id, + try_to_sort, + fail_if_not_sorted, + cls_snaps, &cond); + req->send(); + return cond.wait(); } std::string calc_ind_image_snap_name(uint64_t pool_id, @@ -593,7 +576,7 @@ int Group<I>::remove(librados::IoCtx& io_ctx, const char *group_name) string group_header_oid = util::group_header_name(group_id); std::vector<cls::rbd::GroupSnapshot> snaps; - r = group_snap_list(io_ctx, group_id, &snaps); + r = group_snap_list<I>(io_ctx, group_id, false, false, &snaps); if (r < 0 && r != -ENOENT) { lderr(cct) << "error listing group snapshots" << dendl; return r; @@ -1191,7 +1174,7 @@ int Group<I>::snap_remove(librados::IoCtx& group_ioctx, const char *group_name, } std::vector<cls::rbd::GroupSnapshot> snaps; - r = group_snap_list(group_ioctx, group_id, &snaps); + r = group_snap_list<I>(group_ioctx, group_id, false, false, &snaps); if (r < 0) { return r; } @@ -1232,7 +1215,7 @@ int Group<I>::snap_rename(librados::IoCtx& group_ioctx, const char *group_name, } std::vector<cls::rbd::GroupSnapshot> group_snaps; - r = group_snap_list(group_ioctx, group_id, &group_snaps); + r = group_snap_list<I>(group_ioctx, group_id, false, false, &group_snaps); if (r < 0) { return r; } @@ -1261,6 +1244,7 @@ int Group<I>::snap_rename(librados::IoCtx& group_ioctx, const char *group_name, template <typename I> int Group<I>::snap_list(librados::IoCtx& group_ioctx, const char *group_name, + bool try_to_sort, bool fail_if_not_sorted, std::vector<group_snap_info2_t> *group_snaps) { CephContext *cct = (CephContext *)group_ioctx.cct(); @@ -1275,7 +1259,8 @@ int Group<I>::snap_list(librados::IoCtx& group_ioctx, const char *group_name, } std::vector<cls::rbd::GroupSnapshot> cls_group_snaps; - r = group_snap_list(group_ioctx, group_id, &cls_group_snaps); + r = group_snap_list<I>(group_ioctx, group_id, try_to_sort, fail_if_not_sorted, + &cls_group_snaps); if (r < 0) { return r; } @@ -1311,7 +1296,7 @@ int Group<I>::snap_get_info(librados::IoCtx& group_ioctx, } std::vector<cls::rbd::GroupSnapshot> cls_group_snaps; - r = group_snap_list(group_ioctx, group_id, &cls_group_snaps); + r = group_snap_list<I>(group_ioctx, group_id, false, false, &cls_group_snaps); if (r < 0) { return r; } @@ -1353,7 +1338,7 @@ int Group<I>::snap_rollback(librados::IoCtx& group_ioctx, } std::vector<cls::rbd::GroupSnapshot> snaps; - r = group_snap_list(group_ioctx, group_id, &snaps); + r = group_snap_list<I>(group_ioctx, group_id, false, false, &snaps); if (r < 0) { return r; } |