]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: new helper method for retrieving a single snapshot info record
authorJason Dillaman <dillaman@redhat.com>
Mon, 23 Jul 2018 18:15:05 +0000 (14:15 -0400)
committerJason Dillaman <dillaman@redhat.com>
Tue, 24 Jul 2018 12:52:33 +0000 (08:52 -0400)
Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/cls/rbd/cls_rbd_client.cc
src/cls/rbd/cls_rbd_client.h
src/librbd/operation/SnapshotRemoveRequest.cc
src/test/librbd/operation/test_mock_SnapshotRemoveRequest.cc

index daad92d561a6d66ce9ba4771f8ebd68af8dd308e..fabf0e2e853739754140a7fff12202b4e7266936 100644 (file)
@@ -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<snapid_t> &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;
           }
index 298fc0a9e83d82f201742ec24097555844f79160..e89c6e90643fdf51d2d54afe05005693b0ea1d07 100644 (file)
@@ -120,6 +120,11 @@ namespace librbd {
     int get_children(librados::IoCtx *ioctx, const std::string &oid,
                       const ParentSpec &pspec, set<string>& 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<snapid_t> &ids);
     int snapshot_get_finish(bufferlist::const_iterator *it,
index 1699d3385740b05cfca787664336702027d84baa..d0c81777b6244db0269adc355fad11e58deb59f5 100644 (file)
@@ -115,7 +115,7 @@ void SnapshotRemoveRequest<I>::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<I>,
@@ -133,14 +133,12 @@ void SnapshotRemoveRequest<I>::handle_get_snap(int r) {
   ldout(cct, 5) << "r=" << r << dendl;
 
   if (r == 0) {
-    std::vector<cls::rbd::SnapshotInfo> snap_infos;
-    std::vector<ParentInfo> parents;
-    std::vector<uint8_t> 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);
     }
   }
 
index 3747e20d86a911b8782726bca0b7d1aaf276bacd..be63561ab4db18c2d7ae973bca5414538745f637 100644 (file)
@@ -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) {