]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
librbd: look for mirror peers in default namespace 32338/head
authorMykola Golub <mgolub@suse.com>
Wed, 18 Dec 2019 19:36:14 +0000 (19:36 +0000)
committerMykola Golub <mgolub@suse.com>
Fri, 20 Dec 2019 07:29:49 +0000 (07:29 +0000)
(when creating primary mirror snapshot)

Signed-off-by: Mykola Golub <mgolub@suse.com>
src/librbd/mirror/snapshot/CreatePrimaryRequest.cc
src/librbd/mirror/snapshot/CreatePrimaryRequest.h
src/test/librbd/mirror/snapshot/test_mock_CreatePrimaryRequest.cc

index b040c407c179c87420fa0d257d7ca732bfa1cee1..d11df27bc7c938e2cd323b96bd81acc970209297 100644 (file)
@@ -25,6 +25,16 @@ namespace snapshot {
 using librbd::util::create_context_callback;
 using librbd::util::create_rados_callback;
 
+template <typename I>
+CreatePrimaryRequest<I>::CreatePrimaryRequest(I *image_ctx, bool demoted,
+                                              bool force, uint64_t *snap_id,
+                                              Context *on_finish)
+  : m_image_ctx(image_ctx), m_demoted(demoted), m_force(force),
+    m_snap_id(snap_id), m_on_finish(on_finish) {
+  m_default_ns_ctx.dup(m_image_ctx->md_ctx);
+  m_default_ns_ctx.set_namespace("");
+}
+
 template <typename I>
 void CreatePrimaryRequest<I>::send() {
   refresh_image();
@@ -126,7 +136,7 @@ void CreatePrimaryRequest<I>::get_mirror_peers() {
   librados::AioCompletion *comp = create_rados_callback<
     CreatePrimaryRequest<I>, &CreatePrimaryRequest<I>::handle_get_mirror_peers>(this);
   m_out_bl.clear();
-  int r = m_image_ctx->md_ctx.aio_operate(RBD_MIRRORING, comp, &op, &m_out_bl);
+  int r = m_default_ns_ctx.aio_operate(RBD_MIRRORING, comp, &op, &m_out_bl);
   ceph_assert(r == 0);
   comp->release();
 }
index 9291fc45b5d6f37630db2abb6815e5b88613c7aa..fe7d5f90b26d13a30eb7045f97878f896d278276 100644 (file)
@@ -5,6 +5,7 @@
 #define CEPH_LIBRBD_MIRROR_SNAPSHOT_CREATE_PRIMARY_REQUEST_H
 
 #include "include/buffer.h"
+#include "include/rados/librados.hpp"
 #include "cls/rbd/cls_rbd_types.h"
 
 #include <string>
@@ -30,10 +31,7 @@ public:
   }
 
   CreatePrimaryRequest(ImageCtxT *image_ctx, bool demoted, bool force,
-                       uint64_t *snap_id, Context *on_finish)
-    : m_image_ctx(image_ctx), m_demoted(demoted), m_force(force),
-      m_snap_id(snap_id), m_on_finish(on_finish) {
-  }
+                       uint64_t *snap_id, Context *on_finish);
 
   void send();
 
@@ -70,6 +68,7 @@ private:
   uint64_t *m_snap_id;
   Context *m_on_finish;
 
+  librados::IoCtx m_default_ns_ctx;
   std::set<std::string> m_mirror_peer_uuids;
   std::string m_snap_name;
 
index 08e55662ecd659661ee2c941814f3289cf6b1490..9d88a97a7561be61c1f40cac1d87fe7dced9514b 100644 (file)
@@ -115,6 +115,14 @@ public:
                    SnapInfo{snap_name, ns, 0, {}, 0, 0, {}}}).second);
   }
 
+  void expect_clone_md_ctx(MockTestImageCtx &mock_image_ctx) {
+    EXPECT_CALL(get_mock_io_ctx(mock_image_ctx.md_ctx), clone())
+      .WillOnce(Invoke([&mock_image_ctx]() {
+                         get_mock_io_ctx(mock_image_ctx.md_ctx).get();
+                         return &get_mock_io_ctx(mock_image_ctx.md_ctx);
+                       }));
+  }
+
   void expect_refresh_image(MockTestImageCtx &mock_image_ctx,
                             bool refresh_required, int r) {
     EXPECT_CALL(*mock_image_ctx.state, is_refresh_required())
@@ -216,6 +224,7 @@ TEST_F(TestMockMirrorSnapshotCreatePrimaryRequest, Success) {
 
   InSequence seq;
 
+  expect_clone_md_ctx(mock_image_ctx);
   expect_refresh_image(mock_image_ctx, true, 0);
   expect_get_mirror_image(
     mock_image_ctx, {cls::rbd::MIRROR_IMAGE_MODE_SNAPSHOT, "gid",
@@ -244,6 +253,7 @@ TEST_F(TestMockMirrorSnapshotCreatePrimaryRequest, RefreshError) {
 
   InSequence seq;
 
+  expect_clone_md_ctx(mock_image_ctx);
   expect_refresh_image(mock_image_ctx, true, -EINVAL);
 
   C_SaferCond ctx;
@@ -263,6 +273,7 @@ TEST_F(TestMockMirrorSnapshotCreatePrimaryRequest, GetMirrorImageError) {
 
   InSequence seq;
 
+  expect_clone_md_ctx(mock_image_ctx);
   expect_refresh_image(mock_image_ctx, false, 0);
   expect_get_mirror_image(
     mock_image_ctx, {cls::rbd::MIRROR_IMAGE_MODE_SNAPSHOT, "gid",
@@ -285,6 +296,7 @@ TEST_F(TestMockMirrorSnapshotCreatePrimaryRequest, CanNotError) {
 
   InSequence seq;
 
+  expect_clone_md_ctx(mock_image_ctx);
   expect_refresh_image(mock_image_ctx, true, 0);
   expect_get_mirror_image(
     mock_image_ctx, {cls::rbd::MIRROR_IMAGE_MODE_SNAPSHOT, "gid",
@@ -309,6 +321,7 @@ TEST_F(TestMockMirrorSnapshotCreatePrimaryRequest, GetMirrorPeersError) {
 
   InSequence seq;
 
+  expect_clone_md_ctx(mock_image_ctx);
   expect_refresh_image(mock_image_ctx, true, 0);
   expect_get_mirror_image(
     mock_image_ctx, {cls::rbd::MIRROR_IMAGE_MODE_SNAPSHOT, "gid",
@@ -336,6 +349,7 @@ TEST_F(TestMockMirrorSnapshotCreatePrimaryRequest, CreateSnapshotError) {
 
   InSequence seq;
 
+  expect_clone_md_ctx(mock_image_ctx);
   expect_refresh_image(mock_image_ctx, true, 0);
   expect_get_mirror_image(
     mock_image_ctx, {cls::rbd::MIRROR_IMAGE_MODE_SNAPSHOT, "gid",
@@ -369,6 +383,7 @@ TEST_F(TestMockMirrorSnapshotCreatePrimaryRequest, SuccessUnlinkPeer) {
 
   InSequence seq;
 
+  expect_clone_md_ctx(mock_image_ctx);
   expect_refresh_image(mock_image_ctx, true, 0);
   expect_get_mirror_image(
     mock_image_ctx, {cls::rbd::MIRROR_IMAGE_MODE_SNAPSHOT, "gid",