From: Mykola Golub Date: Wed, 18 Dec 2019 19:36:14 +0000 (+0000) Subject: librbd: look for mirror peers in default namespace X-Git-Tag: v15.1.0~393^2 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=a5c2bdcd53acb1f9e425afb2a15b0a47cf66361d;p=ceph.git librbd: look for mirror peers in default namespace (when creating primary mirror snapshot) Signed-off-by: Mykola Golub --- diff --git a/src/librbd/mirror/snapshot/CreatePrimaryRequest.cc b/src/librbd/mirror/snapshot/CreatePrimaryRequest.cc index b040c407c179c..d11df27bc7c93 100644 --- a/src/librbd/mirror/snapshot/CreatePrimaryRequest.cc +++ b/src/librbd/mirror/snapshot/CreatePrimaryRequest.cc @@ -25,6 +25,16 @@ namespace snapshot { using librbd::util::create_context_callback; using librbd::util::create_rados_callback; +template +CreatePrimaryRequest::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 void CreatePrimaryRequest::send() { refresh_image(); @@ -126,7 +136,7 @@ void CreatePrimaryRequest::get_mirror_peers() { librados::AioCompletion *comp = create_rados_callback< CreatePrimaryRequest, &CreatePrimaryRequest::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(); } diff --git a/src/librbd/mirror/snapshot/CreatePrimaryRequest.h b/src/librbd/mirror/snapshot/CreatePrimaryRequest.h index 9291fc45b5d6f..fe7d5f90b26d1 100644 --- a/src/librbd/mirror/snapshot/CreatePrimaryRequest.h +++ b/src/librbd/mirror/snapshot/CreatePrimaryRequest.h @@ -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 @@ -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 m_mirror_peer_uuids; std::string m_snap_name; diff --git a/src/test/librbd/mirror/snapshot/test_mock_CreatePrimaryRequest.cc b/src/test/librbd/mirror/snapshot/test_mock_CreatePrimaryRequest.cc index 08e55662ecd65..9d88a97a7561b 100644 --- a/src/test/librbd/mirror/snapshot/test_mock_CreatePrimaryRequest.cc +++ b/src/test/librbd/mirror/snapshot/test_mock_CreatePrimaryRequest.cc @@ -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",