Skip to content

Commit

Permalink
rbd: Use user snapshot namespace in rbd_mirror for now
Browse files Browse the repository at this point in the history
Signed-off-by: Victor Denisov <denisovenator@gmail.com>
  • Loading branch information
VictorDenisov committed Oct 13, 2016
1 parent 2157f35 commit db1b6c0
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 26 deletions.
Expand Up @@ -216,7 +216,8 @@ class TestMockImageReplayerCreateImageRequest : public TestMockFixture {
"", "", m_remote_io_ctx,
false);
ictx->state->open();
EXPECT_EQ(0, ictx->operations->snap_create(snap_name.c_str()));
EXPECT_EQ(0, ictx->operations->snap_create(snap_name.c_str(),
cls::rbd::UserSnapshotNamespace()));
EXPECT_EQ(0, ictx->operations->snap_protect(snap_name.c_str()));
ictx->state->close();
}
Expand Down
Expand Up @@ -120,7 +120,7 @@ TEST_F(TestMockImageReplayerEventPreprocessor, PreprocessSnapMapPrune) {
expect_update_client(mock_remote_journaler, 0);

mock_local_image_ctx.snap_info = {
{6, librbd::SnapInfo{"snap", 0U, {}, 0U, 0U}}};
{6, librbd::SnapInfo{"snap", cls::rbd::UserSnapshotNamespace(), 0U, {}, 0U, 0U}}};
m_client_meta.snap_seqs = {{1, 2}, {3, 4}, {5, 6}};
MockEventPreprocessor event_preprocessor(mock_local_image_ctx,
mock_remote_journaler,
Expand All @@ -146,7 +146,7 @@ TEST_F(TestMockImageReplayerEventPreprocessor, PreprocessSnapRename) {

mock_local_image_ctx.snap_ids = {{"snap", 6}};
mock_local_image_ctx.snap_info = {
{6, librbd::SnapInfo{"snap", 0U, {}, 0U, 0U}}};
{6, librbd::SnapInfo{"snap", cls::rbd::UserSnapshotNamespace(), 0U, {}, 0U, 0U}}};
MockEventPreprocessor event_preprocessor(mock_local_image_ctx,
mock_remote_journaler,
"local mirror uuid",
Expand Down Expand Up @@ -197,7 +197,7 @@ TEST_F(TestMockImageReplayerEventPreprocessor, PreprocessSnapRenameKnown) {
expect_image_refresh(mock_local_image_ctx, 0);

mock_local_image_ctx.snap_info = {
{6, librbd::SnapInfo{"snap", 0U, {}, 0U, 0U}}};
{6, librbd::SnapInfo{"snap", cls::rbd::UserSnapshotNamespace(), 0U, {}, 0U, 0U}}};
m_client_meta.snap_seqs = {{5, 6}};
MockEventPreprocessor event_preprocessor(mock_local_image_ctx,
mock_remote_journaler,
Expand Down Expand Up @@ -246,7 +246,7 @@ TEST_F(TestMockImageReplayerEventPreprocessor, PreprocessClientUpdateError) {

mock_local_image_ctx.snap_ids = {{"snap", 6}};
mock_local_image_ctx.snap_info = {
{6, librbd::SnapInfo{"snap", 0U, {}, 0U, 0U}}};
{6, librbd::SnapInfo{"snap", cls::rbd::UserSnapshotNamespace(), 0U, {}, 0U, 0U}}};
MockEventPreprocessor event_preprocessor(mock_local_image_ctx,
mock_remote_journaler,
"local mirror uuid",
Expand Down
Expand Up @@ -45,6 +45,7 @@ struct SnapshotCreateRequest<librbd::MockTestImageCtx> {
static SnapshotCreateRequest* s_instance;
static SnapshotCreateRequest* create(librbd::MockTestImageCtx* image_ctx,
const std::string &snap_name,
const cls::rbd::SnapshotNamespace &snap_namespace,
uint64_t size,
const librbd::parent_spec &parent_spec,
uint64_t parent_overlap,
Expand Down Expand Up @@ -176,7 +177,8 @@ class TestMockImageSyncSnapshotCopyRequest : public TestMockFixture {

int create_snap(librbd::ImageCtx *image_ctx, const std::string &snap_name,
bool protect = false) {
int r = image_ctx->operations->snap_create(snap_name.c_str());
int r = image_ctx->operations->snap_create(snap_name.c_str(),
cls::rbd::UserSnapshotNamespace());
if (r < 0) {
return r;
}
Expand Down
25 changes: 20 additions & 5 deletions src/test/rbd_mirror/image_sync/test_mock_SnapshotCreateRequest.cc
Expand Up @@ -80,11 +80,11 @@ class TestMockImageSyncSnapshotCreateRequest : public TestMockFixture {

void expect_snap_create(librbd::MockTestImageCtx &mock_image_ctx,
const std::string &snap_name, uint64_t snap_id, int r) {
EXPECT_CALL(*mock_image_ctx.operations, execute_snap_create(StrEq(snap_name), _, 0, true))
EXPECT_CALL(*mock_image_ctx.operations, execute_snap_create(StrEq(snap_name), _, _, 0, true))
.WillOnce(DoAll(InvokeWithoutArgs([&mock_image_ctx, snap_id, snap_name]() {
inject_snap(mock_image_ctx, snap_id, snap_name);
}),
WithArg<1>(Invoke([this, r](Context *ctx) {
WithArg<2>(Invoke([this, r](Context *ctx) {
m_threads->work_queue->queue(ctx, r);
}))));
}
Expand All @@ -105,11 +105,12 @@ class TestMockImageSyncSnapshotCreateRequest : public TestMockFixture {

MockSnapshotCreateRequest *create_request(librbd::MockTestImageCtx &mock_local_image_ctx,
const std::string &snap_name,
const cls::rbd::SnapshotNamespace &snap_namespace,
uint64_t size,
const librbd::parent_spec &spec,
uint64_t parent_overlap,
Context *on_finish) {
return new MockSnapshotCreateRequest(&mock_local_image_ctx, snap_name, size,
return new MockSnapshotCreateRequest(&mock_local_image_ctx, snap_name, snap_namespace, size,
spec, parent_overlap, on_finish);
}

Expand All @@ -126,7 +127,9 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, Resize) {

C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1", 123, {}, 0,
"snap1",
cls::rbd::UserSnapshotNamespace(),
123, {}, 0,
&ctx);
request->send();
ASSERT_EQ(0, ctx.wait());
Expand All @@ -140,7 +143,9 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, ResizeError) {

C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1", 123, {}, 0,
"snap1",
cls::rbd::UserSnapshotNamespace(),
123, {}, 0,
&ctx);
request->send();
ASSERT_EQ(-EINVAL, ctx.wait());
Expand All @@ -158,6 +163,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, RemoveParent) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::UserSnapshotNamespace(),
m_local_image_ctx->size,
{}, 0, &ctx);
request->send();
Expand All @@ -174,6 +180,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, RemoveParentError) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::UserSnapshotNamespace(),
m_local_image_ctx->size,
{}, 0, &ctx);
request->send();
Expand All @@ -193,6 +200,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, RemoveSetParent) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::UserSnapshotNamespace(),
m_local_image_ctx->size,
{123, "test", 0}, 0,
&ctx);
Expand All @@ -211,6 +219,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, SetParentSpec) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::UserSnapshotNamespace(),
m_local_image_ctx->size,
{123, "test", 0}, 0,
&ctx);
Expand All @@ -230,6 +239,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, SetParentOverlap) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::UserSnapshotNamespace(),
m_local_image_ctx->size,
mock_local_image_ctx.parent_md.spec,
123, &ctx);
Expand All @@ -246,6 +256,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, SetParentError) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::UserSnapshotNamespace(),
m_local_image_ctx->size,
{123, "test", 0}, 0,
&ctx);
Expand All @@ -263,6 +274,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, SnapCreate) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::UserSnapshotNamespace(),
m_local_image_ctx->size,
{}, 0, &ctx);
request->send();
Expand All @@ -278,6 +290,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, SnapCreateError) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::UserSnapshotNamespace(),
m_local_image_ctx->size,
{}, 0, &ctx);
request->send();
Expand All @@ -295,6 +308,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, ResizeObjectMap) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::UserSnapshotNamespace(),
m_local_image_ctx->size,
{}, 0, &ctx);
request->send();
Expand All @@ -312,6 +326,7 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, ResizeObjectMapError) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::UserSnapshotNamespace(),
m_local_image_ctx->size,
{}, 0, &ctx);
request->send();
Expand Down
Expand Up @@ -67,8 +67,8 @@ class TestMockImageSyncSyncPointCreateRequest : public TestMockFixture {
}

void expect_snap_create(librbd::MockTestImageCtx &mock_remote_image_ctx, int r) {
EXPECT_CALL(*mock_remote_image_ctx.operations, snap_create(_, _))
.WillOnce(WithArg<1>(CompleteContext(r)));
EXPECT_CALL(*mock_remote_image_ctx.operations, snap_create(_, _, _))
.WillOnce(WithArg<2>(CompleteContext(r)));
}

MockSyncPointCreateRequest *create_request(librbd::MockTestImageCtx &mock_remote_image_ctx,
Expand Down
7 changes: 5 additions & 2 deletions src/test/rbd_mirror/test_ImageDeleter.cc
Expand Up @@ -14,6 +14,7 @@
#include "include/rados/librados.hpp"
#include "include/rbd/librbd.hpp"
#include "include/stringify.h"
#include "cls/rbd/cls_rbd_types.h"
#include "cls/rbd/cls_rbd_client.h"
#include "tools/rbd_mirror/ImageDeleter.h"
#include "tools/rbd_mirror/ImageReplayer.h"
Expand Down Expand Up @@ -150,7 +151,8 @@ class TestImageDeleter : public TestFixture {
EXPECT_EQ(0, ictx->state->open());
promote_image(ictx);

EXPECT_EQ(0, ictx->operations->snap_create(snap_name.c_str()));
EXPECT_EQ(0, ictx->operations->snap_create(snap_name.c_str(),
cls::rbd::UserSnapshotNamespace()));

if (protect) {
EXPECT_EQ(0, ictx->operations->snap_protect(snap_name.c_str()));
Expand All @@ -166,7 +168,8 @@ class TestImageDeleter : public TestFixture {
EXPECT_EQ(0, ictx->state->open());
promote_image(ictx);

EXPECT_EQ(0, ictx->operations->snap_create("snap1"));
EXPECT_EQ(0, ictx->operations->snap_create("snap1",
cls::rbd::UserSnapshotNamespace()));
EXPECT_EQ(0, ictx->operations->snap_protect("snap1"));
int order = 20;
EXPECT_EQ(0, librbd::clone(m_local_io_ctx, ictx->name.c_str(), "snap1",
Expand Down
7 changes: 5 additions & 2 deletions src/test/rbd_mirror/test_ImageReplayer.cc
Expand Up @@ -19,6 +19,7 @@
#include "include/stringify.h"
#include "cls/journal/cls_journal_types.h"
#include "cls/journal/cls_journal_client.h"
#include "cls/rbd/cls_rbd_types.h"
#include "cls/rbd/cls_rbd_client.h"
#include "journal/Journaler.h"
#include "librbd/AioCompletion.h"
Expand Down Expand Up @@ -737,7 +738,8 @@ TEST_F(TestImageReplayer, MultipleReplayFailures_SingleEpoch) {
librbd::ImageCtx *ictx;
open_image(m_local_ioctx, m_image_name, false, &ictx);
ictx->features &= ~RBD_FEATURE_JOURNALING;
ASSERT_EQ(0, ictx->operations->snap_create("foo"));
ASSERT_EQ(0, ictx->operations->snap_create("foo",
cls::rbd::UserSnapshotNamespace()));
ASSERT_EQ(0, ictx->operations->snap_protect("foo"));
ASSERT_EQ(0, librbd::cls_client::add_child(&ictx->md_ctx, RBD_CHILDREN,
{ictx->md_ctx.get_id(),
Expand Down Expand Up @@ -784,7 +786,8 @@ TEST_F(TestImageReplayer, MultipleReplayFailures_MultiEpoch) {
librbd::ImageCtx *ictx;
open_image(m_local_ioctx, m_image_name, false, &ictx);
ictx->features &= ~RBD_FEATURE_JOURNALING;
ASSERT_EQ(0, ictx->operations->snap_create("foo"));
ASSERT_EQ(0, ictx->operations->snap_create("foo",
cls::rbd::UserSnapshotNamespace()));
ASSERT_EQ(0, ictx->operations->snap_protect("foo"));
ASSERT_EQ(0, librbd::cls_client::add_child(&ictx->md_ctx, RBD_CHILDREN,
{ictx->md_ctx.get_id(),
Expand Down
4 changes: 3 additions & 1 deletion src/test/rbd_mirror/test_PoolWatcher.cc
Expand Up @@ -3,6 +3,7 @@
#include "include/rados/librados.hpp"
#include "include/rbd/librbd.hpp"
#include "include/stringify.h"
#include "cls/rbd/cls_rbd_types.h"
#include "cls/rbd/cls_rbd_client.h"
#include "include/rbd_types.h"
#include "librbd/internal.h"
Expand Down Expand Up @@ -127,7 +128,8 @@ TestPoolWatcher() : m_lock("TestPoolWatcherLock"),
librbd::ImageCtx *ictx = new librbd::ImageCtx(parent_image_name.c_str(),
"", "", pioctx, false);
ictx->state->open();
EXPECT_EQ(0, ictx->operations->snap_create(snap_name.c_str()));
EXPECT_EQ(0, ictx->operations->snap_create(snap_name.c_str(),
cls::rbd::UserSnapshotNamespace()));
EXPECT_EQ(0, ictx->operations->snap_protect(snap_name.c_str()));
ictx->state->close();
}
Expand Down
4 changes: 3 additions & 1 deletion src/test/rbd_mirror/test_fixture.cc
@@ -1,6 +1,7 @@
// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
// vim: ts=8 sw=2 smarttab

#include "cls/rbd/cls_rbd_types.h"
#include "test/rbd_mirror/test_fixture.h"
#include "include/stringify.h"
#include "include/rbd/librbd.hpp"
Expand Down Expand Up @@ -84,7 +85,8 @@ int TestFixture::open_image(librados::IoCtx &io_ctx,

int TestFixture::create_snap(librbd::ImageCtx *image_ctx, const char* snap_name,
librados::snap_t *snap_id) {
int r = image_ctx->operations->snap_create(snap_name);
int r = image_ctx->operations->snap_create(snap_name,
cls::rbd::UserSnapshotNamespace());
if (r < 0) {
return r;
}
Expand Down
34 changes: 32 additions & 2 deletions src/tools/rbd_mirror/image_sync/SnapshotCopyRequest.cc
Expand Up @@ -101,6 +101,7 @@ void SnapshotCopyRequest<I>::send_snap_unprotect() {
librados::snap_t local_snap_id = *snap_id_it;

m_local_image_ctx->snap_lock.get_read();

bool local_unprotected;
int r = m_local_image_ctx->is_snap_unprotected(local_snap_id,
&local_unprotected);
Expand Down Expand Up @@ -200,6 +201,21 @@ void SnapshotCopyRequest<I>::send_snap_remove() {
for (; snap_id_it != m_local_snap_ids.end(); ++snap_id_it) {
librados::snap_t local_snap_id = *snap_id_it;

cls::rbd::SnapshotNamespace snap_namespace;
m_local_image_ctx->snap_lock.get_read();
int r = m_local_image_ctx->get_snap_namespace(local_snap_id, &snap_namespace);
m_local_image_ctx->snap_lock.put_read();
if (r < 0) {
derr << ": failed to retrieve local snap namespace: " << m_snap_name
<< dendl;
finish(r);
return;
}

if (boost::get<cls::rbd::UserSnapshotNamespace>(&snap_namespace) == nullptr) {
continue;
}

// if the local snapshot isn't in our mapping table, remove it
auto snap_seq_it = std::find_if(
m_snap_seqs.begin(), m_snap_seqs.end(),
Expand Down Expand Up @@ -261,8 +277,20 @@ void SnapshotCopyRequest<I>::send_snap_create() {
for (; snap_id_it != m_remote_snap_ids.end(); ++snap_id_it) {
librados::snap_t remote_snap_id = *snap_id_it;

cls::rbd::SnapshotNamespace snap_namespace;
m_remote_image_ctx->snap_lock.get_read();
int r = m_remote_image_ctx->get_snap_namespace(remote_snap_id, &snap_namespace);
m_remote_image_ctx->snap_lock.put_read();
if (r < 0) {
derr << ": failed to retrieve remote snap namespace: " << m_snap_name
<< dendl;
finish(r);
return;
}

// if the remote snapshot isn't in our mapping table, create it
if (m_snap_seqs.find(remote_snap_id) == m_snap_seqs.end()) {
if (m_snap_seqs.find(remote_snap_id) == m_snap_seqs.end() &&
boost::get<cls::rbd::UserSnapshotNamespace>(&snap_namespace) != nullptr) {
break;
}
}
Expand All @@ -288,6 +316,7 @@ void SnapshotCopyRequest<I>::send_snap_create() {
}

uint64_t size = snap_info_it->second.size;
m_snap_namespace = snap_info_it->second.snap_namespace;
librbd::parent_spec parent_spec;
uint64_t parent_overlap = 0;
if (snap_info_it->second.parent.spec.pool_id != -1) {
Expand All @@ -311,7 +340,7 @@ void SnapshotCopyRequest<I>::send_snap_create() {
SnapshotCopyRequest<I>, &SnapshotCopyRequest<I>::handle_snap_create>(
this);
SnapshotCreateRequest<I> *req = SnapshotCreateRequest<I>::create(
m_local_image_ctx, m_snap_name, size, parent_spec, parent_overlap, ctx);
m_local_image_ctx, m_snap_name, m_snap_namespace, size, parent_spec, parent_overlap, ctx);
req->send();
}

Expand Down Expand Up @@ -354,6 +383,7 @@ void SnapshotCopyRequest<I>::send_snap_protect() {
librados::snap_t remote_snap_id = *snap_id_it;

m_remote_image_ctx->snap_lock.get_read();

bool remote_protected;
int r = m_remote_image_ctx->is_snap_protected(remote_snap_id,
&remote_protected);
Expand Down
1 change: 1 addition & 0 deletions src/tools/rbd_mirror/image_sync/SnapshotCopyRequest.h
Expand Up @@ -104,6 +104,7 @@ class SnapshotCopyRequest : public BaseRequest {
librados::snap_t m_prev_snap_id = CEPH_NOSNAP;

std::string m_snap_name;
cls::rbd::SnapshotNamespace m_snap_namespace;

librbd::parent_spec m_local_parent_spec;

Expand Down

0 comments on commit db1b6c0

Please sign in to comment.