]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
rbd-mirror: permit R/W operations against non-primary image
authorJason Dillaman <dillaman@redhat.com>
Mon, 9 Mar 2020 20:49:07 +0000 (16:49 -0400)
committerJason Dillaman <dillaman@redhat.com>
Tue, 10 Mar 2020 23:23:02 +0000 (19:23 -0400)
With the non-primary feature bit is enabled, mask-out the read-only
feature bit that will be set in the refresh image state machine if
the image has that feature bit set. This will ensure that only the
rbd-mirror daemon will be able to modify a non-primary image.

Signed-off-by: Jason Dillaman <dillaman@redhat.com>
src/test/rbd_mirror/image_deleter/test_mock_SnapshotPurgeRequest.cc
src/test/rbd_mirror/image_deleter/test_mock_TrashMoveRequest.cc
src/tools/rbd_mirror/image_deleter/SnapshotPurgeRequest.cc
src/tools/rbd_mirror/image_deleter/TrashMoveRequest.cc
src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc

index 0084181200a90b9e0a2f95f5f2d719c12602efb3..627082e285c6763c5f8365ef6c555c9a4aa1f1ba 100644 (file)
@@ -71,7 +71,9 @@ public:
 
   void expect_open(librbd::MockTestImageCtx &mock_image_ctx, int r) {
     EXPECT_CALL(*mock_image_ctx.state, open(true, _))
-      .WillOnce(WithArg<1>(Invoke([this, r](Context* ctx) {
+      .WillOnce(WithArg<1>(Invoke([this, &mock_image_ctx, r](Context* ctx) {
+                             EXPECT_EQ(0U, mock_image_ctx.read_only_mask &
+                                             librbd::IMAGE_READ_ONLY_FLAG_NON_PRIMARY);
                              m_threads->work_queue->queue(ctx, r);
                            })));
   }
index 7a712999cdd4a5568d079ed540984688cdacbcd9..2630915115d0366fe9a9bdce59c0595516b44a98 100644 (file)
@@ -233,7 +233,9 @@ public:
 
   void expect_open(librbd::MockTestImageCtx &mock_image_ctx, int r) {
     EXPECT_CALL(*mock_image_ctx.state, open(true, _))
-      .WillOnce(WithArg<1>(Invoke([this, r](Context* ctx) {
+      .WillOnce(WithArg<1>(Invoke([this, &mock_image_ctx, r](Context* ctx) {
+                             EXPECT_EQ(0U, mock_image_ctx.read_only_mask &
+                                             librbd::IMAGE_READ_ONLY_FLAG_NON_PRIMARY);
                              m_threads->work_queue->queue(ctx, r);
                            })));
   }
index 58ebd5e58dc78ac0e5e412018b1443089c3cb212..8280e38ba1833f340c3455fe02c1d1b7039febc4 100644 (file)
@@ -34,6 +34,9 @@ void SnapshotPurgeRequest<I>::open_image() {
   dout(10) << dendl;
   m_image_ctx = I::create("", m_image_id, nullptr, m_io_ctx, false);
 
+  // ensure non-primary images can be modified
+  m_image_ctx->read_only_mask &= ~librbd::IMAGE_READ_ONLY_FLAG_NON_PRIMARY;
+
   {
     std::unique_lock image_locker{m_image_ctx->image_lock};
     m_image_ctx->set_journal_policy(new JournalPolicy());
index 87b48fdc828366ce2e1843598116a404200bf1de..0eadca7bf2a86eda3f5a03971a3fac1a2ba113a2 100644 (file)
@@ -161,6 +161,9 @@ void TrashMoveRequest<I>::open_image() {
 
   m_image_ctx = I::create("", m_image_id, nullptr, m_io_ctx, false);
 
+  // ensure non-primary images can be modified
+  m_image_ctx->read_only_mask &= ~librbd::IMAGE_READ_ONLY_FLAG_NON_PRIMARY;
+
   {
     // don't attempt to open the journal
     std::unique_lock image_locker{m_image_ctx->image_lock};
index 70e935fd72d2213a18c57269342fa3122aaa8db4..2418cf3a9c7502358f01bf732eeec227e6e02294 100644 (file)
@@ -116,6 +116,11 @@ void OpenLocalImageRequest<I>::send_open_image() {
 
   *m_local_image_ctx = I::create("", m_local_image_id, nullptr,
                                  m_local_io_ctx, false);
+
+  // ensure non-primary images can be modified
+  (*m_local_image_ctx)->read_only_mask =
+    ~librbd::IMAGE_READ_ONLY_FLAG_NON_PRIMARY;
+
   {
     std::scoped_lock locker{(*m_local_image_ctx)->owner_lock,
                            (*m_local_image_ctx)->image_lock};