]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
librbd: tweak create non-primary mirror snapshot request
authorJason Dillaman <dillaman@redhat.com>
Fri, 7 Feb 2020 20:06:22 +0000 (15:06 -0500)
committerJason Dillaman <dillaman@redhat.com>
Wed, 19 Feb 2020 15:36:40 +0000 (10:36 -0500)
The replayer will need to pass in the demotion state as well as the
snapshot sequences for the copied snapshots.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/librbd/mirror/snapshot/CreateNonPrimaryRequest.cc
src/librbd/mirror/snapshot/CreateNonPrimaryRequest.h
src/librbd/mirror/snapshot/PromoteRequest.cc
src/test/librbd/mirror/snapshot/test_mock_CreateNonPrimaryRequest.cc
src/test/librbd/mirror/snapshot/test_mock_PromoteRequest.cc

index 18a03964068b9056be7c1b1f672b1e3d56cecab3..c70ae82d5be29b05d511fc218fe6311c538a23b7 100644 (file)
@@ -119,8 +119,11 @@ void CreateNonPrimaryRequest<I>::create_snapshot() {
   ldout(cct, 20) << dendl;
 
   cls::rbd::MirrorSnapshotNamespace ns{
-    cls::rbd::MIRROR_SNAPSHOT_STATE_NON_PRIMARY, {},
+    (m_demoted ? cls::rbd::MIRROR_SNAPSHOT_STATE_NON_PRIMARY_DEMOTED :
+                 cls::rbd::MIRROR_SNAPSHOT_STATE_NON_PRIMARY), {},
     m_primary_mirror_uuid, m_primary_snap_id};
+  ns.snap_seqs = m_snap_seqs;
+
   auto ctx = create_context_callback<
     CreateNonPrimaryRequest<I>,
     &CreateNonPrimaryRequest<I>::handle_create_snapshot>(this);
index 2b0fb68cd27160a200963b592140e88fc9ce4cc9..4a7113439802ff3956aa921c179d4603839259c5 100644 (file)
@@ -6,6 +6,7 @@
 
 #include "include/buffer.h"
 #include "cls/rbd/cls_rbd_types.h"
+#include "librbd/Types.h"
 #include "librbd/mirror/snapshot/Types.h"
 
 #include <string>
@@ -24,24 +25,29 @@ template <typename ImageCtxT = librbd::ImageCtx>
 class CreateNonPrimaryRequest {
 public:
   static CreateNonPrimaryRequest *create(ImageCtxT *image_ctx,
+                                         bool demoted,
                                          const std::string &primary_mirror_uuid,
                                          uint64_t primary_snap_id,
+                                         const SnapSeqs& snap_seqs,
                                          const ImageState &image_state,
                                          uint64_t *snap_id,
                                          Context *on_finish) {
-    return new CreateNonPrimaryRequest(image_ctx, primary_mirror_uuid,
-                                       primary_snap_id, image_state, snap_id,
-                                       on_finish);
+    return new CreateNonPrimaryRequest(image_ctx, demoted, primary_mirror_uuid,
+                                       primary_snap_id, snap_seqs, image_state,
+                                       snap_id, on_finish);
   }
 
   CreateNonPrimaryRequest(ImageCtxT *image_ctx,
+                          bool demoted,
                           const std::string &primary_mirror_uuid,
                           uint64_t primary_snap_id,
+                          const SnapSeqs& snap_seqs,
                           const ImageState &image_state, uint64_t *snap_id,
                           Context *on_finish)
-    : m_image_ctx(image_ctx), m_primary_mirror_uuid(primary_mirror_uuid),
-      m_primary_snap_id(primary_snap_id), m_image_state(image_state),
-      m_snap_id(snap_id), m_on_finish(on_finish) {
+    : m_image_ctx(image_ctx), m_demoted(demoted),
+      m_primary_mirror_uuid(primary_mirror_uuid),
+      m_primary_snap_id(primary_snap_id), m_snap_seqs(snap_seqs),
+      m_image_state(image_state), m_snap_id(snap_id), m_on_finish(on_finish) {
   }
 
   void send();
@@ -71,8 +77,10 @@ private:
    */
 
   ImageCtxT *m_image_ctx;
+  bool m_demoted;
   std::string m_primary_mirror_uuid;
   uint64_t m_primary_snap_id;
+  SnapSeqs m_snap_seqs;
   ImageState m_image_state;
   uint64_t *m_snap_id;
   Context *m_on_finish;
index 347813f6a5ce77b92a34659b545e952ff753b428..418778ce0380f7b883e611b3ab6f10214b15720e 100644 (file)
@@ -59,8 +59,8 @@ void PromoteRequest<I>::create_orphan_snapshot() {
     PromoteRequest<I>,
     &PromoteRequest<I>::handle_create_orphan_snapshot>(this);
 
-  auto req = CreateNonPrimaryRequest<I>::create(m_image_ctx, "", CEPH_NOSNAP,
-                                                {}, nullptr, ctx);
+  auto req = CreateNonPrimaryRequest<I>::create(
+    m_image_ctx, false, "", CEPH_NOSNAP, {}, {}, nullptr, ctx);
   req->send();
 }
 
index 29918c793160c1d8656dcb564b91d305ce2ddf35..25a85ce53193aade6ed1a90d11bfc939fbd59a2a 100644 (file)
@@ -172,8 +172,9 @@ TEST_F(TestMockMirrorSnapshotCreateNonPrimaryRequest, Success) {
   expect_write_image_state(mock_image_ctx, mock_write_image_state_request, 0);
 
   C_SaferCond ctx;
-  auto req = new MockCreateNonPrimaryRequest(&mock_image_ctx, "mirror_uuid",
-                                             123, {}, nullptr, &ctx);
+  auto req = new MockCreateNonPrimaryRequest(&mock_image_ctx, false,
+                                             "mirror_uuid", 123, {{1, 2}}, {},
+                                             nullptr, &ctx);
   req->send();
   ASSERT_EQ(0, ctx.wait());
 }
@@ -191,8 +192,9 @@ TEST_F(TestMockMirrorSnapshotCreateNonPrimaryRequest, RefreshError) {
   expect_refresh_image(mock_image_ctx, true, -EINVAL);
 
   C_SaferCond ctx;
-  auto req = new MockCreateNonPrimaryRequest(&mock_image_ctx, "mirror_uuid",
-                                             123, {}, nullptr, &ctx);
+  auto req = new MockCreateNonPrimaryRequest(&mock_image_ctx, false,
+                                             "mirror_uuid", 123, {{1, 2}}, {},
+                                             nullptr, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
@@ -213,8 +215,9 @@ TEST_F(TestMockMirrorSnapshotCreateNonPrimaryRequest, GetMirrorImageError) {
                      cls::rbd::MIRROR_IMAGE_STATE_ENABLED}, -EINVAL);
 
   C_SaferCond ctx;
-  auto req = new MockCreateNonPrimaryRequest(&mock_image_ctx, "mirror_uuid",
-                                             123, {}, nullptr, &ctx);
+  auto req = new MockCreateNonPrimaryRequest(&mock_image_ctx, false,
+                                             "mirror_uuid", 123, {{1, 2}}, {},
+                                             nullptr, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
@@ -237,8 +240,9 @@ TEST_F(TestMockMirrorSnapshotCreateNonPrimaryRequest, CanNotError) {
   expect_can_create_non_primary_snapshot(mock_utils, false);
 
   C_SaferCond ctx;
-  auto req = new MockCreateNonPrimaryRequest(&mock_image_ctx, "mirror_uuid",
-                                             123, {}, nullptr, &ctx);
+  auto req = new MockCreateNonPrimaryRequest(&mock_image_ctx, false,
+                                             "mirror_uuid", 123, {{1, 2}}, {},
+                                             nullptr, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
@@ -262,8 +266,9 @@ TEST_F(TestMockMirrorSnapshotCreateNonPrimaryRequest, CreateSnapshotError) {
   expect_create_snapshot(mock_image_ctx, -EINVAL);
 
   C_SaferCond ctx;
-  auto req = new MockCreateNonPrimaryRequest(&mock_image_ctx, "mirror_uuid",
-                                             123, {}, nullptr, &ctx);
+  auto req = new MockCreateNonPrimaryRequest(&mock_image_ctx, false,
+                                             "mirror_uuid", 123, {{1, 2}}, {},
+                                             nullptr, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
@@ -290,8 +295,9 @@ TEST_F(TestMockMirrorSnapshotCreateNonPrimaryRequest, WriteImageStateError) {
                            -EINVAL);
 
   C_SaferCond ctx;
-  auto req = new MockCreateNonPrimaryRequest(&mock_image_ctx, "mirror_uuid",
-                                             123, {}, nullptr, &ctx);
+  auto req = new MockCreateNonPrimaryRequest(&mock_image_ctx, false,
+                                             "mirror_uuid", 123, {{1, 2}}, {},
+                                             nullptr, &ctx);
   req->send();
   ASSERT_EQ(-EINVAL, ctx.wait());
 }
index 78954f183a567f694a728ac4c21b58bec365b976..2220d0e64244ec8ec5454cef4e9284124d4358ac 100644 (file)
@@ -89,8 +89,10 @@ struct CreateNonPrimaryRequest<MockTestImageCtx> {
   Context* on_finish = nullptr;
   static CreateNonPrimaryRequest* s_instance;
   static CreateNonPrimaryRequest *create(MockTestImageCtx *image_ctx,
+                                         bool demoted,
                                          const std::string &primary_mirror_uuid,
                                          uint64_t primary_snap_id,
+                                         SnapSeqs snap_seqs,
                                          const ImageState &image_state,
                                          uint64_t *snap_id,
                                          Context *on_finish) {