From 9baa65c3bd33ee91138018fc9ce6ed0da0fcc8f1 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Mon, 23 Jul 2018 14:15:05 -0400 Subject: [PATCH] librbd: new helper method for retrieving a single snapshot info record Signed-off-by: Jason Dillaman --- src/cls/rbd/cls_rbd_client.cc | 36 ++++++++++++++----- src/cls/rbd/cls_rbd_client.h | 5 +++ src/librbd/operation/SnapshotRemoveRequest.cc | 12 +++---- .../test_mock_SnapshotRemoveRequest.cc | 10 ------ 4 files changed, 38 insertions(+), 25 deletions(-) diff --git a/src/cls/rbd/cls_rbd_client.cc b/src/cls/rbd/cls_rbd_client.cc index daad92d561a6d..fabf0e2e85373 100644 --- a/src/cls/rbd/cls_rbd_client.cc +++ b/src/cls/rbd/cls_rbd_client.cc @@ -549,14 +549,30 @@ namespace librbd { return get_children_finish(&it, &children); } + void snapshot_info_get_start(librados::ObjectReadOperation *op, + snapid_t snap_id) + { + bufferlist bl; + encode(snap_id, bl); + op->exec("rbd", "snapshot_get", bl); + } + + int snapshot_info_get_finish(bufferlist::const_iterator* it, + cls::rbd::SnapshotInfo* snap_info) + { + try { + decode(*snap_info, *it); + } catch (const buffer::error &err) { + return -EBADMSG; + } + return 0; + } + void snapshot_get_start(librados::ObjectReadOperation *op, const std::vector &ids) { for (auto snap_id : ids) { - bufferlist bl; - encode(snap_id, bl); - op->exec("rbd", "snapshot_get", bl); - + snapshot_info_get_start(op, snap_id); get_parent_start(op, snap_id); get_protection_status_start(op, snap_id); } @@ -573,11 +589,15 @@ namespace librbd { protection_statuses->resize(ids.size()); try { for (size_t i = 0; i < snaps->size(); ++i) { - decode((*snaps)[i], *it); + // snapshot_get + int r = snapshot_info_get_finish(it, &(*snaps)[i]); + if (r < 0) { + return r; + } - // get_parent - int r = get_parent_finish(it, &(*parents)[i].spec, - &(*parents)[i].overlap); + // get_parent + r = get_parent_finish(it, &(*parents)[i].spec, + &(*parents)[i].overlap); if (r < 0) { return r; } diff --git a/src/cls/rbd/cls_rbd_client.h b/src/cls/rbd/cls_rbd_client.h index 298fc0a9e83d8..e89c6e90643fd 100644 --- a/src/cls/rbd/cls_rbd_client.h +++ b/src/cls/rbd/cls_rbd_client.h @@ -120,6 +120,11 @@ namespace librbd { int get_children(librados::IoCtx *ioctx, const std::string &oid, const ParentSpec &pspec, set& children); + void snapshot_info_get_start(librados::ObjectReadOperation* op, + snapid_t snap_id); + int snapshot_info_get_finish(bufferlist::const_iterator* it, + cls::rbd::SnapshotInfo* snap_info); + void snapshot_get_start(librados::ObjectReadOperation *op, const std::vector &ids); int snapshot_get_finish(bufferlist::const_iterator *it, diff --git a/src/librbd/operation/SnapshotRemoveRequest.cc b/src/librbd/operation/SnapshotRemoveRequest.cc index 1699d3385740b..d0c81777b6244 100644 --- a/src/librbd/operation/SnapshotRemoveRequest.cc +++ b/src/librbd/operation/SnapshotRemoveRequest.cc @@ -115,7 +115,7 @@ void SnapshotRemoveRequest::get_snap() { ldout(cct, 5) << dendl; librados::ObjectReadOperation op; - cls_client::snapshot_get_start(&op, {m_snap_id}); + cls_client::snapshot_info_get_start(&op, m_snap_id); auto aio_comp = create_rados_callback< SnapshotRemoveRequest, @@ -133,14 +133,12 @@ void SnapshotRemoveRequest::handle_get_snap(int r) { ldout(cct, 5) << "r=" << r << dendl; if (r == 0) { - std::vector snap_infos; - std::vector parents; - std::vector protections; + cls::rbd::SnapshotInfo snap_info; + auto it = m_out_bl.cbegin(); - r = cls_client::snapshot_get_finish(&it, {m_snap_id}, &snap_infos, - &parents, &protections); + r = cls_client::snapshot_info_get_finish(&it, &snap_info); if (r == 0) { - m_child_attached = (snap_infos[0].child_count > 0); + m_child_attached = (snap_info.child_count > 0); } } diff --git a/src/test/librbd/operation/test_mock_SnapshotRemoveRequest.cc b/src/test/librbd/operation/test_mock_SnapshotRemoveRequest.cc index 3747e20d86a91..be63561ab4db1 100644 --- a/src/test/librbd/operation/test_mock_SnapshotRemoveRequest.cc +++ b/src/test/librbd/operation/test_mock_SnapshotRemoveRequest.cc @@ -110,16 +110,6 @@ public: encode(snap_info, *bl); return r; }))); - if (r >= 0) { - EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx), - exec(mock_image_ctx.header_oid, _, StrEq("rbd"), - StrEq("get_parent"), _, _, _)) - .WillOnce(DoDefault()); - EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx), - exec(mock_image_ctx.header_oid, _, StrEq("rbd"), - StrEq("get_protection_status"), _, _, _)) - .WillOnce(DoDefault()); - } } void expect_object_map_snap_remove(MockImageCtx &mock_image_ctx, int r) { -- 2.39.5