Skip to content

Commit

Permalink
rbd-mirror: check mirroring is enabled for remote image when bootstra…
Browse files Browse the repository at this point in the history
…pping

Fixes: http://tracker.ceph.com/issues/18447
Signed-off-by: Mykola Golub <mgolub@mirantis.com>
  • Loading branch information
Mykola Golub committed Jan 8, 2017
1 parent a159f3d commit 55ebc25
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 0 deletions.
35 changes: 35 additions & 0 deletions src/test/rbd_mirror/image_replayer/test_mock_BootstrapRequest.cc
Expand Up @@ -288,6 +288,26 @@ class TestMockImageReplayerBootstrapRequest : public TestMockFixture {
Return(r)));
}

void expect_mirror_image_get(librados::IoCtx &io_ctx,
const std::string &image_id,
const std::string &global_image_id,
cls::rbd::MirrorImageState state, int r) {
bufferlist in_bl;
::encode(image_id, in_bl);

bufferlist bl;
::encode(cls::rbd::MirrorImage(global_image_id, state), bl);

EXPECT_CALL(get_mock_io_ctx(io_ctx),
exec(RBD_MIRRORING, _, StrEq("rbd"),
StrEq("mirror_image_get"), ContentsEqual(in_bl),
_, _))
.WillOnce(DoAll(WithArg<5>(Invoke([bl](bufferlist *out_bl) {
*out_bl = bl;
})),
Return(r)));
}

void expect_journaler_get_client(::journal::MockJournaler &mock_journaler,
const std::string &client_id,
cls::journal::Client &client, int r) {
Expand Down Expand Up @@ -455,6 +475,9 @@ TEST_F(TestMockImageReplayerBootstrapRequest, NonPrimaryRemoteSyncingState) {
MockOpenImageRequest mock_open_image_request;
expect_open_image(mock_open_image_request, m_remote_io_ctx,
mock_remote_image_ctx.id, mock_remote_image_ctx, 0);
expect_mirror_image_get(m_remote_io_ctx, mock_remote_image_ctx.id,
"global image id",
cls::rbd::MIRROR_IMAGE_STATE_ENABLED, 0);
expect_journal_is_tag_owner(mock_journal, false, 0);

// switch the state to replaying
Expand Down Expand Up @@ -512,6 +535,9 @@ TEST_F(TestMockImageReplayerBootstrapRequest, RemoteDemotePromote) {
MockOpenImageRequest mock_open_image_request;
expect_open_image(mock_open_image_request, m_remote_io_ctx,
mock_remote_image_ctx.id, mock_remote_image_ctx, 0);
expect_mirror_image_get(m_remote_io_ctx, mock_remote_image_ctx.id,
"global image id",
cls::rbd::MIRROR_IMAGE_STATE_ENABLED, 0);
expect_journal_is_tag_owner(mock_journal, true, 0);

// open the local image
Expand Down Expand Up @@ -590,6 +616,9 @@ TEST_F(TestMockImageReplayerBootstrapRequest, MultipleRemoteDemotePromotes) {
MockOpenImageRequest mock_open_image_request;
expect_open_image(mock_open_image_request, m_remote_io_ctx,
mock_remote_image_ctx.id, mock_remote_image_ctx, 0);
expect_mirror_image_get(m_remote_io_ctx, mock_remote_image_ctx.id,
"global image id",
cls::rbd::MIRROR_IMAGE_STATE_ENABLED, 0);
expect_journal_is_tag_owner(mock_journal, true, 0);

// open the local image
Expand Down Expand Up @@ -678,6 +707,9 @@ TEST_F(TestMockImageReplayerBootstrapRequest, LocalDemoteRemotePromote) {
MockOpenImageRequest mock_open_image_request;
expect_open_image(mock_open_image_request, m_remote_io_ctx,
mock_remote_image_ctx.id, mock_remote_image_ctx, 0);
expect_mirror_image_get(m_remote_io_ctx, mock_remote_image_ctx.id,
"global image id",
cls::rbd::MIRROR_IMAGE_STATE_ENABLED, 0);
expect_journal_is_tag_owner(mock_journal, true, 0);

// open the local image
Expand Down Expand Up @@ -754,6 +786,9 @@ TEST_F(TestMockImageReplayerBootstrapRequest, SplitBrainForcePromote) {
MockOpenImageRequest mock_open_image_request;
expect_open_image(mock_open_image_request, m_remote_io_ctx,
mock_remote_image_ctx.id, mock_remote_image_ctx, 0);
expect_mirror_image_get(m_remote_io_ctx, mock_remote_image_ctx.id,
"global image id",
cls::rbd::MIRROR_IMAGE_STATE_ENABLED, 0);
expect_journal_is_tag_owner(mock_journal, true, 0);

// open the local image
Expand Down
1 change: 1 addition & 0 deletions src/test/rbd_mirror/test_ImageReplayer.cc
Expand Up @@ -99,6 +99,7 @@ class TestImageReplayer : public ::rbd::mirror::TestFixture {

EXPECT_EQ(0, m_remote_cluster.ioctx_create(m_remote_pool_name.c_str(),
m_remote_ioctx));
EXPECT_EQ(0, librbd::mirror_mode_set(m_remote_ioctx, RBD_MIRROR_MODE_POOL));

m_image_name = get_temp_image_name();
uint64_t features = librbd::util::get_rbd_default_features(g_ceph_context);
Expand Down
16 changes: 16 additions & 0 deletions src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc
Expand Up @@ -273,6 +273,22 @@ void BootstrapRequest<I>::handle_open_remote_image(int r) {
}

// TODO: make async

cls::rbd::MirrorImage mirror_image;
r = librbd::cls_client::mirror_image_get(&m_remote_io_ctx, m_remote_image_ctx->id,
&mirror_image);
if (r < 0) {
derr << ": failed to get remote image state: " << cpp_strerror(r) << dendl;
} else if (mirror_image.state != cls::rbd::MIRROR_IMAGE_STATE_ENABLED) {
dout(5) << ": mirroring is not enabled" << dendl;
r = -EAGAIN;
}
if (r < 0) {
m_ret_val = r;
close_remote_image();
return;
}

bool tag_owner;
r = Journal::is_tag_owner(m_remote_image_ctx, &tag_owner);
if (r < 0) {
Expand Down

0 comments on commit 55ebc25

Please sign in to comment.