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 Sep 23, 2016
1 parent e578a55 commit 4ab1798
Show file tree
Hide file tree
Showing 14 changed files with 94 additions and 25 deletions.
Expand Up @@ -218,7 +218,9 @@ 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::SnapshotNamespaceEntry(
cls::rbd::UserSnapshotNamespace())));
EXPECT_EQ(0, ictx->operations->snap_protect(snap_name.c_str()));
ictx->state->close();
}
Expand Down
16 changes: 12 additions & 4 deletions src/test/rbd_mirror/image_replayer/test_mock_EventPreprocessor.cc
Expand Up @@ -120,7 +120,9 @@ 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::SnapshotNamespaceEntry(
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 +148,9 @@ 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::SnapshotNamespaceEntry(
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 +201,9 @@ 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::SnapshotNamespaceEntry(
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 +252,9 @@ 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::SnapshotNamespaceEntry(
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::SnapshotNamespaceEntry &snap_namespace,
uint64_t size,
const librbd::parent_spec &parent_spec,
uint64_t parent_overlap,
Expand Down Expand Up @@ -176,7 +177,9 @@ 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::SnapshotNamespaceEntry(
cls::rbd::UserSnapshotNamespace()));
if (r < 0) {
return r;
}
Expand Down
37 changes: 32 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::SnapshotNamespaceEntry &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,10 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, Resize) {

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

C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1", 123, {}, 0,
"snap1",
cls::rbd::SnapshotNamespaceEntry(
cls::rbd::UserSnapshotNamespace()),
123, {}, 0,
&ctx);
request->send();
ASSERT_EQ(-EINVAL, ctx.wait());
Expand All @@ -158,6 +165,8 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, RemoveParent) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::SnapshotNamespaceEntry(
cls::rbd::UserSnapshotNamespace()),
m_local_image_ctx->size,
{}, 0, &ctx);
request->send();
Expand All @@ -174,6 +183,8 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, RemoveParentError) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::SnapshotNamespaceEntry(
cls::rbd::UserSnapshotNamespace()),
m_local_image_ctx->size,
{}, 0, &ctx);
request->send();
Expand All @@ -193,6 +204,8 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, RemoveSetParent) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::SnapshotNamespaceEntry(
cls::rbd::UserSnapshotNamespace()),
m_local_image_ctx->size,
{123, "test", 0}, 0,
&ctx);
Expand All @@ -211,6 +224,8 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, SetParentSpec) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::SnapshotNamespaceEntry(
cls::rbd::UserSnapshotNamespace()),
m_local_image_ctx->size,
{123, "test", 0}, 0,
&ctx);
Expand All @@ -230,6 +245,8 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, SetParentOverlap) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::SnapshotNamespaceEntry(
cls::rbd::UserSnapshotNamespace()),
m_local_image_ctx->size,
mock_local_image_ctx.parent_md.spec,
123, &ctx);
Expand All @@ -246,6 +263,8 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, SetParentError) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::SnapshotNamespaceEntry(
cls::rbd::UserSnapshotNamespace()),
m_local_image_ctx->size,
{123, "test", 0}, 0,
&ctx);
Expand All @@ -263,6 +282,8 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, SnapCreate) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::SnapshotNamespaceEntry(
cls::rbd::UserSnapshotNamespace()),
m_local_image_ctx->size,
{}, 0, &ctx);
request->send();
Expand All @@ -278,6 +299,8 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, SnapCreateError) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::SnapshotNamespaceEntry(
cls::rbd::UserSnapshotNamespace()),
m_local_image_ctx->size,
{}, 0, &ctx);
request->send();
Expand All @@ -295,6 +318,8 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, ResizeObjectMap) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::SnapshotNamespaceEntry(
cls::rbd::UserSnapshotNamespace()),
m_local_image_ctx->size,
{}, 0, &ctx);
request->send();
Expand All @@ -312,6 +337,8 @@ TEST_F(TestMockImageSyncSnapshotCreateRequest, ResizeObjectMapError) {
C_SaferCond ctx;
MockSnapshotCreateRequest *request = create_request(mock_local_image_ctx,
"snap1",
cls::rbd::SnapshotNamespaceEntry(
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
9 changes: 7 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,9 @@ 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::SnapshotNamespaceEntry(
cls::rbd::UserSnapshotNamespace())));

if (protect) {
EXPECT_EQ(0, ictx->operations->snap_protect(snap_name.c_str()));
Expand All @@ -166,7 +169,9 @@ 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::SnapshotNamespaceEntry(
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
9 changes: 7 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 @@ -735,7 +736,9 @@ 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::SnapshotNamespaceEntry(
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 @@ -782,7 +785,9 @@ 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::SnapshotNamespaceEntry(
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
5 changes: 4 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,9 @@ 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::SnapshotNamespaceEntry(
cls::rbd::UserSnapshotNamespace())));
EXPECT_EQ(0, ictx->operations->snap_protect(snap_name.c_str()));
ictx->state->close();
}
Expand Down
5 changes: 4 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,9 @@ 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::SnapshotNamespaceEntry(
cls::rbd::UserSnapshotNamespace()));
if (r < 0) {
return r;
}
Expand Down
3 changes: 2 additions & 1 deletion src/tools/rbd_mirror/image_sync/SnapshotCopyRequest.cc
Expand Up @@ -288,6 +288,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 +312,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
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::SnapshotNamespaceEntry m_snap_namespace;

librbd::parent_spec m_local_parent_spec;

Expand Down
9 changes: 7 additions & 2 deletions src/tools/rbd_mirror/image_sync/SnapshotCreateRequest.cc
Expand Up @@ -4,6 +4,7 @@
#include "SnapshotCreateRequest.h"
#include "common/errno.h"
#include "cls/rbd/cls_rbd_client.h"
#include "cls/rbd/cls_rbd_types.h"
#include "librbd/ObjectMap.h"
#include "librbd/Operations.h"
#include "librbd/Utils.h"
Expand All @@ -24,11 +25,13 @@ using librbd::util::create_rados_safe_callback;
template <typename I>
SnapshotCreateRequest<I>::SnapshotCreateRequest(I *local_image_ctx,
const std::string &snap_name,
const cls::rbd::SnapshotNamespaceEntry &snap_namespace,
uint64_t size,
const librbd::parent_spec &spec,
uint64_t parent_overlap,
Context *on_finish)
: m_local_image_ctx(local_image_ctx), m_snap_name(snap_name), m_size(size),
: m_local_image_ctx(local_image_ctx), m_snap_name(snap_name),
m_snap_namespace(snap_namespace), m_size(size),
m_parent_spec(spec), m_parent_overlap(parent_overlap),
m_on_finish(on_finish) {
}
Expand Down Expand Up @@ -186,7 +189,9 @@ void SnapshotCreateRequest<I>::send_snap_create() {
SnapshotCreateRequest<I>, &SnapshotCreateRequest<I>::handle_snap_create>(
this);
RWLock::RLocker owner_locker(m_local_image_ctx->owner_lock);
m_local_image_ctx->operations->execute_snap_create(m_snap_name.c_str(), ctx,
m_local_image_ctx->operations->execute_snap_create(m_snap_name.c_str(),
m_snap_namespace,
ctx,
0U, true);
}

Expand Down

0 comments on commit 4ab1798

Please sign in to comment.