From: Ricardo Dias Date: Tue, 10 Jan 2017 15:11:19 +0000 (+0000) Subject: librbd: allow to open an image without opening parent image X-Git-Tag: v10.2.6~31^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F13130%2Fhead;p=ceph.git librbd: allow to open an image without opening parent image Fixes: http://tracker.ceph.com/issues/18325 Signed-off-by: Ricardo Dias (cherry picked from commit 61af1c25015de087a2423811548d975dd7d430b4) Conflicts: src/librbd/ImageState.cc - added missing arg to RefreshRequest::create src/librbd/exclusive_lock/PostAcquireRequest.cc - deleted, does not exist in jewel src/librbd/image/OpenRequest.cc - added missing arg to RefreshRequest::create src/librbd/internal.cc - added missing arg to ImageState::open src/librbd/librbd.cc - added missing arg to ImageState::open src/test/librbd/exclusive_lock/test_mock_PostAcquireRequest.cc - deleted, does not exist in jewel src/test/rbd_mirror/image_replayer/test_mock_CreateImageRequest.cc - added missing arg to ImageState::open src/test/rbd_mirror/test_PoolWatcher.cc - added missing arg to ImageState::open --- diff --git a/src/librbd/ImageState.cc b/src/librbd/ImageState.cc index 320430727692..28cf4274ef9e 100644 --- a/src/librbd/ImageState.cc +++ b/src/librbd/ImageState.cc @@ -234,7 +234,8 @@ ImageState::ImageState(I *image_ctx) : m_image_ctx(image_ctx), m_state(STATE_UNINITIALIZED), m_lock(util::unique_lock_name("librbd::ImageState::m_lock", this)), m_last_refresh(0), m_refresh_seq(0), - m_update_watchers(new ImageUpdateWatchers(image_ctx->cct)) { + m_update_watchers(new ImageUpdateWatchers(image_ctx->cct)), + m_skip_open_parent_image(false) { } template @@ -244,19 +245,20 @@ ImageState::~ImageState() { } template -int ImageState::open() { +int ImageState::open(bool skip_open_parent) { C_SaferCond ctx; - open(&ctx); + open(skip_open_parent, &ctx); return ctx.wait(); } template -void ImageState::open(Context *on_finish) { +void ImageState::open(bool skip_open_parent, Context *on_finish) { CephContext *cct = m_image_ctx->cct; ldout(cct, 20) << __func__ << dendl; m_lock.Lock(); assert(m_state == STATE_UNINITIALIZED); + m_skip_open_parent_image = skip_open_parent; Action action(ACTION_TYPE_OPEN); action.refresh_seq = m_refresh_seq; @@ -555,7 +557,7 @@ void ImageState::send_open_unlock() { *m_image_ctx, create_context_callback< ImageState, &ImageState::handle_open>(this)); image::OpenRequest *req = image::OpenRequest::create( - m_image_ctx, ctx); + m_image_ctx, m_skip_open_parent_image, ctx); m_lock.Unlock(); req->send(); @@ -620,7 +622,7 @@ void ImageState::send_refresh_unlock() { *m_image_ctx, create_context_callback< ImageState, &ImageState::handle_refresh>(this)); image::RefreshRequest *req = image::RefreshRequest::create( - *m_image_ctx, false, ctx); + *m_image_ctx, false, false, ctx); m_lock.Unlock(); req->send(); diff --git a/src/librbd/ImageState.h b/src/librbd/ImageState.h index 412730e71168..b6e7ce63b442 100644 --- a/src/librbd/ImageState.h +++ b/src/librbd/ImageState.h @@ -25,8 +25,8 @@ public: ImageState(ImageCtxT *image_ctx); ~ImageState(); - int open(); - void open(Context *on_finish); + int open(bool skip_open_parent); + void open(bool skip_open_parent, Context *on_finish); int close(); void close(Context *on_finish); @@ -109,6 +109,8 @@ private: ImageUpdateWatchers *m_update_watchers; + bool m_skip_open_parent_image; + bool is_transition_state() const; bool is_closed() const; diff --git a/src/librbd/exclusive_lock/AcquireRequest.cc b/src/librbd/exclusive_lock/AcquireRequest.cc index 5a495805debd..344a267db8f9 100644 --- a/src/librbd/exclusive_lock/AcquireRequest.cc +++ b/src/librbd/exclusive_lock/AcquireRequest.cc @@ -189,7 +189,7 @@ Context *AcquireRequest::send_refresh() { // ImageState is blocked waiting for lock to complete -- safe to directly // refresh image::RefreshRequest *req = image::RefreshRequest::create( - m_image_ctx, true, ctx); + m_image_ctx, true, false, ctx); req->send(); return nullptr; } diff --git a/src/librbd/image/OpenRequest.cc b/src/librbd/image/OpenRequest.cc index 36d740da76f4..9fbd8bcb485e 100644 --- a/src/librbd/image/OpenRequest.cc +++ b/src/librbd/image/OpenRequest.cc @@ -30,8 +30,10 @@ using util::create_context_callback; using util::create_rados_ack_callback; template -OpenRequest::OpenRequest(I *image_ctx, Context *on_finish) - : m_image_ctx(image_ctx), m_on_finish(on_finish), m_error_result(0), +OpenRequest::OpenRequest(I *image_ctx, bool skip_open_parent, + Context *on_finish) + : m_image_ctx(image_ctx), m_skip_open_parent_image(skip_open_parent), + m_on_finish(on_finish), m_error_result(0), m_last_metadata_key(ImageCtx::METADATA_CONF_PREFIX) { } @@ -373,7 +375,7 @@ void OpenRequest::send_refresh() { using klass = OpenRequest; RefreshRequest *ctx = RefreshRequest::create( - *m_image_ctx, false, + *m_image_ctx, false, m_skip_open_parent_image, create_context_callback(this)); ctx->send(); } diff --git a/src/librbd/image/OpenRequest.h b/src/librbd/image/OpenRequest.h index 627285b40ffd..04c255d9c796 100644 --- a/src/librbd/image/OpenRequest.h +++ b/src/librbd/image/OpenRequest.h @@ -19,8 +19,9 @@ namespace image { template class OpenRequest { public: - static OpenRequest *create(ImageCtxT *image_ctx, Context *on_finish) { - return new OpenRequest(image_ctx, on_finish); + static OpenRequest *create(ImageCtxT *image_ctx, bool skip_open_parent, + Context *on_finish) { + return new OpenRequest(image_ctx, skip_open_parent, on_finish); } void send(); @@ -65,9 +66,10 @@ private: * @endverbatim */ - OpenRequest(ImageCtxT *image_ctx, Context *on_finish); + OpenRequest(ImageCtxT *image_ctx, bool skip_open_parent, Context *on_finish); ImageCtxT *m_image_ctx; + bool m_skip_open_parent_image; Context *m_on_finish; bufferlist m_out_bl; diff --git a/src/librbd/image/RefreshParentRequest.cc b/src/librbd/image/RefreshParentRequest.cc index a44124f39136..28058abe7b55 100644 --- a/src/librbd/image/RefreshParentRequest.cc +++ b/src/librbd/image/RefreshParentRequest.cc @@ -120,7 +120,7 @@ void RefreshParentRequest::send_open_parent() { Context *ctx = create_async_context_callback( m_child_image_ctx, create_context_callback< klass, &klass::handle_open_parent, false>(this)); - OpenRequest *req = OpenRequest::create(m_parent_image_ctx, ctx); + OpenRequest *req = OpenRequest::create(m_parent_image_ctx, false, ctx); req->send(); } diff --git a/src/librbd/image/RefreshRequest.cc b/src/librbd/image/RefreshRequest.cc index 04b05fa55d3d..70c43b97aacc 100644 --- a/src/librbd/image/RefreshRequest.cc +++ b/src/librbd/image/RefreshRequest.cc @@ -28,8 +28,9 @@ using util::create_context_callback; template RefreshRequest::RefreshRequest(I &image_ctx, bool acquiring_lock, - Context *on_finish) + bool skip_open_parent, Context *on_finish) : m_image_ctx(image_ctx), m_acquiring_lock(acquiring_lock), + m_skip_open_parent_image(skip_open_parent), m_on_finish(create_async_context_callback(m_image_ctx, on_finish)), m_error_result(0), m_flush_aio(false), m_exclusive_lock(nullptr), m_object_map(nullptr), m_journal(nullptr), m_refresh_parent(nullptr) { @@ -397,8 +398,8 @@ void RefreshRequest::send_v2_refresh_parent() { parent_info parent_md; int r = get_parent_info(m_image_ctx.snap_id, &parent_md); - if (r < 0 || - RefreshParentRequest::is_refresh_required(m_image_ctx, parent_md)) { + if (!m_skip_open_parent_image && (r < 0 || + RefreshParentRequest::is_refresh_required(m_image_ctx, parent_md))) { CephContext *cct = m_image_ctx.cct; ldout(cct, 10) << this << " " << __func__ << dendl; diff --git a/src/librbd/image/RefreshRequest.h b/src/librbd/image/RefreshRequest.h index 79b5d9e816d2..43275d705f7d 100644 --- a/src/librbd/image/RefreshRequest.h +++ b/src/librbd/image/RefreshRequest.h @@ -27,11 +27,13 @@ template class RefreshRequest { public: static RefreshRequest *create(ImageCtxT &image_ctx, bool acquiring_lock, - Context *on_finish) { - return new RefreshRequest(image_ctx, acquiring_lock, on_finish); + bool skip_open_parent, Context *on_finish) { + return new RefreshRequest(image_ctx, acquiring_lock, skip_open_parent, + on_finish); } - RefreshRequest(ImageCtxT &image_ctx, bool acquiring_lock, Context *on_finish); + RefreshRequest(ImageCtxT &image_ctx, bool acquiring_lock, + bool skip_open_parent, Context *on_finish); ~RefreshRequest(); void send(); @@ -98,6 +100,7 @@ private: ImageCtxT &m_image_ctx; bool m_acquiring_lock; + bool m_skip_open_parent_image; Context *m_on_finish; int m_error_result; diff --git a/src/librbd/internal.cc b/src/librbd/internal.cc index b7f7df633af0..d5875d8dde21 100644 --- a/src/librbd/internal.cc +++ b/src/librbd/internal.cc @@ -1422,7 +1422,7 @@ int mirror_image_disable_internal(ImageCtx *ictx, bool force, // make sure parent snapshot exists ImageCtx *p_imctx = new ImageCtx(p_name, "", p_snap_name, p_ioctx, true); - int r = p_imctx->state->open(); + int r = p_imctx->state->open(false); if (r < 0) { lderr(cct) << "error opening parent image: " << cpp_strerror(-r) << dendl; @@ -1558,7 +1558,7 @@ int mirror_image_disable_internal(ImageCtx *ictx, bool force, } c_imctx = new ImageCtx(c_name, "", NULL, c_ioctx, false); - r = c_imctx->state->open(); + r = c_imctx->state->open(false); if (r < 0) { lderr(cct) << "Error opening new image: " << cpp_strerror(r) << dendl; delete c_imctx; @@ -1631,7 +1631,7 @@ int mirror_image_disable_internal(ImageCtx *ictx, bool force, << dstname << dendl; ImageCtx *ictx = new ImageCtx(srcname, "", "", io_ctx, false); - int r = ictx->state->open(); + int r = ictx->state->open(false); if (r < 0) { lderr(ictx->cct) << "error opening source image: " << cpp_strerror(r) << dendl; @@ -1971,7 +1971,7 @@ int mirror_image_disable_internal(ImageCtx *ictx, bool force, if (enable_mirroring) { ImageCtx *img_ctx = new ImageCtx("", ictx->id, nullptr, ictx->md_ctx, false); - r = img_ctx->state->open(); + r = img_ctx->state->open(false); if (r < 0) { lderr(cct) << "error opening image: " << cpp_strerror(r) << dendl; delete img_ctx; @@ -2268,7 +2268,7 @@ int mirror_image_disable_internal(ImageCtx *ictx, bool force, bool unknown_format = true; ImageCtx *ictx = new ImageCtx( (id.empty() ? name : std::string()), id, nullptr, io_ctx, false); - int r = ictx->state->open(); + int r = ictx->state->open(true); if (r < 0) { ldout(cct, 2) << "error opening image: " << cpp_strerror(-r) << dendl; delete ictx; @@ -2538,7 +2538,7 @@ int mirror_image_disable_internal(ImageCtx *ictx, bool force, ImageCtx *dest = new librbd::ImageCtx(destname, "", NULL, dest_md_ctx, false); - r = dest->state->open(); + r = dest->state->open(false); if (r < 0) { delete dest; lderr(cct) << "failed to read newly created header" << dendl; @@ -3603,7 +3603,7 @@ int mirror_image_disable_internal(ImageCtx *ictx, bool force, if ((features & RBD_FEATURE_JOURNALING) != 0) { ImageCtx *img_ctx = new ImageCtx("", img_pair.second, nullptr, io_ctx, false); - r = img_ctx->state->open(); + r = img_ctx->state->open(false); if (r < 0) { lderr(cct) << "error opening image "<< img_pair.first << ": " << cpp_strerror(r) << dendl; @@ -3650,7 +3650,7 @@ int mirror_image_disable_internal(ImageCtx *ictx, bool force, } } else { ImageCtx *img_ctx = new ImageCtx("", img_id, nullptr, io_ctx, false); - r = img_ctx->state->open(); + r = img_ctx->state->open(false); if (r < 0) { lderr(cct) << "error opening image id "<< img_id << ": " << cpp_strerror(r) << dendl; diff --git a/src/librbd/librbd.cc b/src/librbd/librbd.cc index f560b22d40a6..04bdb06aef2b 100644 --- a/src/librbd/librbd.cc +++ b/src/librbd/librbd.cc @@ -103,7 +103,7 @@ struct C_OpenAfterCloseComplete : public Context { virtual void finish(int r) { ldout(ictx->cct, 20) << "C_OpenAfterCloseComplete::finish: r=" << r << dendl; - ictx->state->open(new C_OpenComplete(ictx, comp, ictxp, true)); + ictx->state->open(false, new C_OpenComplete(ictx, comp, ictxp, true)); } }; @@ -213,7 +213,7 @@ namespace librbd { image.ctx = NULL; } - int r = ictx->state->open(); + int r = ictx->state->open(false); if (r < 0) { delete ictx; tracepoint(librbd, open_image_exit, r); @@ -236,7 +236,7 @@ namespace librbd { reinterpret_cast(image.ctx)->state->close( new C_OpenAfterCloseComplete(ictx, get_aio_completion(c), &image.ctx)); } else { - ictx->state->open(new C_OpenComplete(ictx, get_aio_completion(c), + ictx->state->open(false, new C_OpenComplete(ictx, get_aio_completion(c), &image.ctx)); } tracepoint(librbd, aio_open_image_exit, 0); @@ -255,7 +255,7 @@ namespace librbd { image.ctx = NULL; } - int r = ictx->state->open(); + int r = ictx->state->open(false); if (r < 0) { delete ictx; tracepoint(librbd, open_image_exit, r); @@ -278,7 +278,7 @@ namespace librbd { reinterpret_cast(image.ctx)->state->close( new C_OpenAfterCloseComplete(ictx, get_aio_completion(c), &image.ctx)); } else { - ictx->state->open(new C_OpenComplete(ictx, get_aio_completion(c), + ictx->state->open(false, new C_OpenComplete(ictx, get_aio_completion(c), &image.ctx)); } tracepoint(librbd, aio_open_image_exit, 0); @@ -1904,7 +1904,7 @@ extern "C" int rbd_open(rados_ioctx_t p, const char *name, rbd_image_t *image, false); tracepoint(librbd, open_image_enter, ictx, ictx->name.c_str(), ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only); - int r = ictx->state->open(); + int r = ictx->state->open(false); if (r < 0) { delete ictx; } else { @@ -1925,7 +1925,7 @@ extern "C" int rbd_aio_open(rados_ioctx_t p, const char *name, false); librbd::RBD::AioCompletion *comp = (librbd::RBD::AioCompletion *)c; tracepoint(librbd, aio_open_image_enter, ictx, ictx->name.c_str(), ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only, comp->pc); - ictx->state->open(new C_OpenComplete(ictx, get_aio_completion(comp), image)); + ictx->state->open(false, new C_OpenComplete(ictx, get_aio_completion(comp), image)); tracepoint(librbd, aio_open_image_exit, 0); return 0; } @@ -1940,7 +1940,7 @@ extern "C" int rbd_open_read_only(rados_ioctx_t p, const char *name, true); tracepoint(librbd, open_image_enter, ictx, ictx->name.c_str(), ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only); - int r = ictx->state->open(); + int r = ictx->state->open(false); if (r < 0) { delete ictx; } else { @@ -1961,7 +1961,8 @@ extern "C" int rbd_aio_open_read_only(rados_ioctx_t p, const char *name, true); librbd::RBD::AioCompletion *comp = (librbd::RBD::AioCompletion *)c; tracepoint(librbd, aio_open_image_enter, ictx, ictx->name.c_str(), ictx->id.c_str(), ictx->snap_name.c_str(), ictx->read_only, comp->pc); - ictx->state->open(new C_OpenComplete(ictx, get_aio_completion(comp), image)); + ictx->state->open(false, new C_OpenComplete(ictx, get_aio_completion(comp), + image)); tracepoint(librbd, aio_open_image_exit, 0); return 0; } diff --git a/src/test/librbd/exclusive_lock/test_mock_AcquireRequest.cc b/src/test/librbd/exclusive_lock/test_mock_AcquireRequest.cc index 00f03cf96c0b..1c96cdba983b 100644 --- a/src/test/librbd/exclusive_lock/test_mock_AcquireRequest.cc +++ b/src/test/librbd/exclusive_lock/test_mock_AcquireRequest.cc @@ -89,7 +89,7 @@ struct RefreshRequest { static RefreshRequest *create(librbd::MockTestImageCtx &image_ctx, bool acquire_lock_refresh, - Context *on_finish) { + bool skip_open_parent, Context *on_finish) { EXPECT_TRUE(acquire_lock_refresh); assert(s_instance != nullptr); s_instance->on_finish = on_finish; diff --git a/src/test/librbd/image/test_mock_RefreshRequest.cc b/src/test/librbd/image/test_mock_RefreshRequest.cc index 4076e253bba5..6b0ff52ab534 100644 --- a/src/test/librbd/image/test_mock_RefreshRequest.cc +++ b/src/test/librbd/image/test_mock_RefreshRequest.cc @@ -321,7 +321,7 @@ TEST_F(TestMockImageRefreshRequest, SuccessV1) { expect_init_layout(mock_image_ctx); C_SaferCond ctx; - MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, &ctx); + MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, false, &ctx); req->send(); ASSERT_EQ(0, ctx.wait()); @@ -347,7 +347,7 @@ TEST_F(TestMockImageRefreshRequest, SuccessSnapshotV1) { expect_add_snap(mock_image_ctx, "snap", ictx->snap_ids.begin()->second); C_SaferCond ctx; - MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, &ctx); + MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, false, &ctx); req->send(); ASSERT_EQ(0, ctx.wait()); @@ -374,7 +374,7 @@ TEST_F(TestMockImageRefreshRequest, SuccessV2) { } C_SaferCond ctx; - MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, &ctx); + MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, false, &ctx); req->send(); ASSERT_EQ(0, ctx.wait()); @@ -405,7 +405,7 @@ TEST_F(TestMockImageRefreshRequest, SuccessSnapshotV2) { expect_add_snap(mock_image_ctx, "snap", ictx->snap_ids.begin()->second); C_SaferCond ctx; - MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, &ctx); + MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, false, &ctx); req->send(); ASSERT_EQ(0, ctx.wait()); @@ -438,7 +438,7 @@ TEST_F(TestMockImageRefreshRequest, SuccessSetSnapshotV2) { expect_get_snap_id(mock_image_ctx, "snap", ictx->snap_ids.begin()->second); C_SaferCond ctx; - MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, &ctx); + MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, false, &ctx); req->send(); ASSERT_EQ(0, ctx.wait()); @@ -488,7 +488,52 @@ TEST_F(TestMockImageRefreshRequest, SuccessChild) { expect_refresh_parent_finalize(mock_image_ctx, *mock_refresh_parent_request, 0); C_SaferCond ctx; - MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, &ctx); + MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, false, &ctx); + req->send(); + + ASSERT_EQ(0, ctx.wait()); +} + +TEST_F(TestMockImageRefreshRequest, SuccessChildDontOpenParent) { + REQUIRE_FEATURE(RBD_FEATURE_LAYERING); + + librbd::ImageCtx *ictx; + librbd::ImageCtx *ictx2 = nullptr; + std::string clone_name = get_temp_image_name(); + + ASSERT_EQ(0, open_image(m_image_name, &ictx)); + ASSERT_EQ(0, snap_create(*ictx, "snap")); + ASSERT_EQ(0, snap_protect(*ictx, "snap")); + BOOST_SCOPE_EXIT_ALL((&)) { + if (ictx2 != nullptr) { + close_image(ictx2); + } + + librbd::NoOpProgressContext no_op; + ASSERT_EQ(0, librbd::remove(m_ioctx, clone_name, "", no_op)); + ASSERT_EQ(0, ictx->operations->snap_unprotect("snap")); + }; + + int order = ictx->order; + ASSERT_EQ(0, librbd::clone(m_ioctx, m_image_name.c_str(), "snap", m_ioctx, + clone_name.c_str(), ictx->features, &order, 0, 0)); + + ASSERT_EQ(0, open_image(clone_name, &ictx2)); + + MockRefreshImageCtx mock_image_ctx(*ictx2); + MockExclusiveLock mock_exclusive_lock; + expect_op_work_queue(mock_image_ctx); + expect_test_features(mock_image_ctx); + + InSequence seq; + expect_get_mutable_metadata(mock_image_ctx, 0); + expect_get_flags(mock_image_ctx, 0); + if (ictx->test_features(RBD_FEATURE_EXCLUSIVE_LOCK)) { + expect_init_exclusive_lock(mock_image_ctx, mock_exclusive_lock, 0); + } + + C_SaferCond ctx; + MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, true, &ctx); req->send(); ASSERT_EQ(0, ctx.wait()); @@ -544,7 +589,7 @@ TEST_F(TestMockImageRefreshRequest, DisableExclusiveLock) { expect_shut_down_exclusive_lock(mock_image_ctx, *mock_exclusive_lock, 0); C_SaferCond ctx; - MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, &ctx); + MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, false, &ctx); req->send(); ASSERT_EQ(0, ctx.wait()); @@ -589,7 +634,7 @@ TEST_F(TestMockImageRefreshRequest, DisableExclusiveLockWhileAcquiringLock) { expect_refresh_parent_is_required(mock_refresh_parent_request, false); C_SaferCond ctx; - MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, true, &ctx); + MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, true, false, &ctx); req->send(); ASSERT_EQ(-ERESTART, ctx.wait()); @@ -631,7 +676,7 @@ TEST_F(TestMockImageRefreshRequest, JournalDisabledByPolicy) { expect_journal_disabled(mock_journal_policy, true); C_SaferCond ctx; - MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, &ctx); + MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, false, &ctx); req->send(); ASSERT_EQ(0, ctx.wait()); @@ -675,7 +720,7 @@ TEST_F(TestMockImageRefreshRequest, EnableJournalWithExclusiveLock) { expect_open_journal(mock_image_ctx, mock_journal, 0); C_SaferCond ctx; - MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, &ctx); + MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, false, &ctx); req->send(); ASSERT_EQ(0, ctx.wait()); @@ -713,7 +758,7 @@ TEST_F(TestMockImageRefreshRequest, EnableJournalWithoutExclusiveLock) { expect_set_require_lock_on_read(mock_image_ctx); C_SaferCond ctx; - MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, &ctx); + MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, false, &ctx); req->send(); ASSERT_EQ(0, ctx.wait()); @@ -757,7 +802,7 @@ TEST_F(TestMockImageRefreshRequest, DisableJournal) { expect_unblock_writes(mock_image_ctx); C_SaferCond ctx; - MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, &ctx); + MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, false, &ctx); req->send(); ASSERT_EQ(0, ctx.wait()); @@ -793,7 +838,7 @@ TEST_F(TestMockImageRefreshRequest, EnableObjectMapWithExclusiveLock) { expect_open_object_map(mock_image_ctx, &mock_object_map, 0); C_SaferCond ctx; - MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, &ctx); + MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, false, &ctx); req->send(); ASSERT_EQ(0, ctx.wait()); @@ -826,7 +871,7 @@ TEST_F(TestMockImageRefreshRequest, EnableObjectMapWithoutExclusiveLock) { expect_refresh_parent_is_required(mock_refresh_parent_request, false); C_SaferCond ctx; - MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, &ctx); + MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, false, &ctx); req->send(); ASSERT_EQ(0, ctx.wait()); @@ -871,7 +916,7 @@ TEST_F(TestMockImageRefreshRequest, DisableObjectMap) { expect_close_object_map(mock_image_ctx, *mock_object_map, 0); C_SaferCond ctx; - MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, &ctx); + MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, false, &ctx); req->send(); ASSERT_EQ(0, ctx.wait()); @@ -907,7 +952,7 @@ TEST_F(TestMockImageRefreshRequest, OpenObjectMapError) { expect_open_object_map(mock_image_ctx, mock_object_map, -EFBIG); C_SaferCond ctx; - MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, &ctx); + MockRefreshRequest *req = new MockRefreshRequest(mock_image_ctx, false, false, &ctx); req->send(); ASSERT_EQ(0, ctx.wait()); diff --git a/src/test/librbd/test_fixture.cc b/src/test/librbd/test_fixture.cc index a521a79deee8..d3283c5cee2d 100644 --- a/src/test/librbd/test_fixture.cc +++ b/src/test/librbd/test_fixture.cc @@ -60,7 +60,7 @@ int TestFixture::open_image(const std::string &image_name, *ictx = new librbd::ImageCtx(image_name.c_str(), "", NULL, m_ioctx, false); m_ictxs.insert(*ictx); - return (*ictx)->state->open(); + return (*ictx)->state->open(false); } int TestFixture::snap_create(librbd::ImageCtx &ictx, diff --git a/src/test/librbd/test_internal.cc b/src/test/librbd/test_internal.cc index 97c2dadf253c..cd7f56ba3b91 100644 --- a/src/test/librbd/test_internal.cc +++ b/src/test/librbd/test_internal.cc @@ -81,7 +81,7 @@ TEST_F(TestInternal, OpenByID) { close_image(ictx); ictx = new librbd::ImageCtx("", id, nullptr, m_ioctx, true); - ASSERT_EQ(0, ictx->state->open()); + ASSERT_EQ(0, ictx->state->open(false)); ASSERT_EQ(ictx->name, m_image_name); close_image(ictx); } diff --git a/src/test/rbd_mirror/image_replayer/test_mock_CreateImageRequest.cc b/src/test/rbd_mirror/image_replayer/test_mock_CreateImageRequest.cc index 81916522c187..798dc1d42951 100644 --- a/src/test/rbd_mirror/image_replayer/test_mock_CreateImageRequest.cc +++ b/src/test/rbd_mirror/image_replayer/test_mock_CreateImageRequest.cc @@ -198,7 +198,7 @@ public: librbd::ImageCtx *ictx = new librbd::ImageCtx(parent_image_ctx->name, "", "", m_remote_io_ctx, false); - ictx->state->open(); + ictx->state->open(false); EXPECT_EQ(0, ictx->operations->snap_create(snap_name.c_str())); EXPECT_EQ(0, ictx->operations->snap_protect(snap_name.c_str())); ictx->state->close(); diff --git a/src/test/rbd_mirror/test_ImageDeleter.cc b/src/test/rbd_mirror/test_ImageDeleter.cc index 5480316e338f..d3739eb43d11 100644 --- a/src/test/rbd_mirror/test_ImageDeleter.cc +++ b/src/test/rbd_mirror/test_ImageDeleter.cc @@ -69,7 +69,7 @@ public: EXPECT_EQ(0, create_image(rbd, m_local_io_ctx, m_image_name, 1 << 20)); ImageCtx *ictx = new ImageCtx(m_image_name, "", "", m_local_io_ctx, false); - EXPECT_EQ(0, ictx->state->open()); + EXPECT_EQ(0, ictx->state->open(false)); m_local_image_id = ictx->id; cls::rbd::MirrorImage mirror_image(GLOBAL_IMAGE_ID, @@ -112,7 +112,7 @@ public: if (!ictx) { ictx = new ImageCtx("", m_local_image_id, "", m_local_io_ctx, false); - r = ictx->state->open(); + r = ictx->state->open(false); close = (r == 0); } @@ -133,7 +133,7 @@ public: if (!ictx) { ictx = new ImageCtx("", m_local_image_id, "", m_local_io_ctx, false); - EXPECT_EQ(0, ictx->state->open()); + EXPECT_EQ(0, ictx->state->open(false)); close = true; } @@ -147,7 +147,7 @@ public: void create_snapshot(std::string snap_name="snap1", bool protect=false) { ImageCtx *ictx = new ImageCtx("", m_local_image_id, "", m_local_io_ctx, false); - EXPECT_EQ(0, ictx->state->open()); + EXPECT_EQ(0, ictx->state->open(false)); promote_image(ictx); EXPECT_EQ(0, ictx->operations->snap_create(snap_name.c_str())); @@ -163,7 +163,7 @@ public: std::string create_clone() { ImageCtx *ictx = new ImageCtx("", m_local_image_id, "", m_local_io_ctx, false); - EXPECT_EQ(0, ictx->state->open()); + EXPECT_EQ(0, ictx->state->open(false)); promote_image(ictx); EXPECT_EQ(0, ictx->operations->snap_create("snap1")); @@ -175,7 +175,7 @@ public: std::string clone_id; ImageCtx *ictx_clone = new ImageCtx("clone1", "", "", m_local_io_ctx, false); - EXPECT_EQ(0, ictx_clone->state->open()); + EXPECT_EQ(0, ictx_clone->state->open(false)); clone_id = ictx_clone->id; cls::rbd::MirrorImage mirror_image(GLOBAL_CLONE_IMAGE_ID, MirrorImageState::MIRROR_IMAGE_STATE_ENABLED); @@ -193,7 +193,7 @@ public: void check_image_deleted() { ImageCtx *ictx = new ImageCtx("", m_local_image_id, "", m_local_io_ctx, false); - EXPECT_EQ(-ENOENT, ictx->state->open()); + EXPECT_EQ(-ENOENT, ictx->state->open(false)); delete ictx; cls::rbd::MirrorImage mirror_image; @@ -417,7 +417,7 @@ TEST_F(TestImageDeleter, Delete_NonExistent_Image_Without_MirroringState) { TEST_F(TestImageDeleter, Fail_Delete_NonPrimary_Image) { ImageCtx *ictx = new ImageCtx("", m_local_image_id, "", m_local_io_ctx, false); - EXPECT_EQ(0, ictx->state->open()); + EXPECT_EQ(0, ictx->state->open(false)); m_deleter->schedule_image_delete(_rados, m_local_pool_id, m_local_image_id, m_image_name, GLOBAL_IMAGE_ID); @@ -436,7 +436,7 @@ TEST_F(TestImageDeleter, Fail_Delete_NonPrimary_Image) { TEST_F(TestImageDeleter, Retry_Failed_Deletes) { ImageCtx *ictx = new ImageCtx("", m_local_image_id, "", m_local_io_ctx, false); - EXPECT_EQ(0, ictx->state->open()); + EXPECT_EQ(0, ictx->state->open(false)); m_deleter->set_failed_timer_interval(2); @@ -464,7 +464,7 @@ TEST_F(TestImageDeleter, Retry_Failed_Deletes) { TEST_F(TestImageDeleter, Delete_Is_Idempotent) { ImageCtx *ictx = new ImageCtx("", m_local_image_id, "", m_local_io_ctx, false); - EXPECT_EQ(0, ictx->state->open()); + EXPECT_EQ(0, ictx->state->open(false)); m_deleter->schedule_image_delete(_rados, m_local_pool_id, m_local_image_id, m_image_name, GLOBAL_IMAGE_ID); diff --git a/src/test/rbd_mirror/test_ImageReplayer.cc b/src/test/rbd_mirror/test_ImageReplayer.cc index 38b0b41aee78..28682eecd26a 100644 --- a/src/test/rbd_mirror/test_ImageReplayer.cc +++ b/src/test/rbd_mirror/test_ImageReplayer.cc @@ -192,7 +192,7 @@ public: { librbd::ImageCtx *ictx = new librbd::ImageCtx(image_name.c_str(), "", "", ioctx, readonly); - EXPECT_EQ(0, ictx->state->open()); + EXPECT_EQ(0, ictx->state->open(false)); *ictxp = ictx; } diff --git a/src/test/rbd_mirror/test_PoolWatcher.cc b/src/test/rbd_mirror/test_PoolWatcher.cc index 2a2708ed686c..96e1b3d31817 100644 --- a/src/test/rbd_mirror/test_PoolWatcher.cc +++ b/src/test/rbd_mirror/test_PoolWatcher.cc @@ -126,7 +126,7 @@ TestPoolWatcher() : m_lock("TestPoolWatcherLock"), { librbd::ImageCtx *ictx = new librbd::ImageCtx(parent_image_name.c_str(), "", "", pioctx, false); - ictx->state->open(); + ictx->state->open(false); EXPECT_EQ(0, ictx->operations->snap_create(snap_name.c_str())); EXPECT_EQ(0, ictx->operations->snap_protect(snap_name.c_str())); ictx->state->close(); diff --git a/src/test/rbd_mirror/test_fixture.cc b/src/test/rbd_mirror/test_fixture.cc index b1eb489d97aa..361e553cf63b 100644 --- a/src/test/rbd_mirror/test_fixture.cc +++ b/src/test/rbd_mirror/test_fixture.cc @@ -79,7 +79,7 @@ int TestFixture::open_image(librados::IoCtx &io_ctx, *image_ctx = new librbd::ImageCtx(image_name.c_str(), "", NULL, io_ctx, false); m_image_ctxs.insert(*image_ctx); - return (*image_ctx)->state->open(); + return (*image_ctx)->state->open(false); } int TestFixture::create_snap(librbd::ImageCtx *image_ctx, const char* snap_name, diff --git a/src/tools/rbd_mirror/ImageDeleter.cc b/src/tools/rbd_mirror/ImageDeleter.cc index 0b0c775dba0d..d089768c60b5 100644 --- a/src/tools/rbd_mirror/ImageDeleter.cc +++ b/src/tools/rbd_mirror/ImageDeleter.cc @@ -330,7 +330,7 @@ bool ImageDeleter::process_image_delete() { ImageCtx *imgctx = new ImageCtx("", m_active_delete->local_image_id, nullptr, ioctx, false); - r = imgctx->state->open(); + r = imgctx->state->open(false); if (r < 0) { derr << "error opening image id " << m_active_delete->local_image_id << ": " << cpp_strerror(r) << dendl; diff --git a/src/tools/rbd_mirror/image_replayer/OpenImageRequest.cc b/src/tools/rbd_mirror/image_replayer/OpenImageRequest.cc index 9cf6af2b3219..32c0724ab619 100644 --- a/src/tools/rbd_mirror/image_replayer/OpenImageRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/OpenImageRequest.cc @@ -44,7 +44,7 @@ void OpenImageRequest::send_open_image() { Context *ctx = create_context_callback< OpenImageRequest, &OpenImageRequest::handle_open_image>( this); - (*m_image_ctx)->state->open(ctx); + (*m_image_ctx)->state->open(false, ctx); } template diff --git a/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc b/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc index 1d331f906a84..b1ec3c74ec3b 100644 --- a/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/OpenLocalImageRequest.cc @@ -99,7 +99,7 @@ void OpenLocalImageRequest::send_open_image() { Context *ctx = create_context_callback< OpenLocalImageRequest, &OpenLocalImageRequest::handle_open_image>( this); - (*m_local_image_ctx)->state->open(ctx); + (*m_local_image_ctx)->state->open(false, ctx); } template