From 476da1011cc772f1fc2acec4f50204801175e906 Mon Sep 17 00:00:00 2001 From: Jason Dillaman Date: Thu, 24 Mar 2016 10:56:35 -0400 Subject: [PATCH] rbd-mirror: cross-reference local image via global image id Signed-off-by: Jason Dillaman --- .../image_replayer/BootstrapRequest.cc | 45 +++++++++++++++++-- .../image_replayer/BootstrapRequest.h | 8 ++++ 2 files changed, 50 insertions(+), 3 deletions(-) diff --git a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc index acb39f00cd5c..4aaf5a29fd1d 100644 --- a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc +++ b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.cc @@ -8,6 +8,7 @@ #include "common/dout.h" #include "common/errno.h" #include "common/WorkQueue.h" +#include "cls/rbd/cls_rbd_client.h" #include "journal/Journaler.h" #include "librbd/ImageCtx.h" #include "librbd/ImageState.h" @@ -26,6 +27,7 @@ namespace mirror { namespace image_replayer { using librbd::util::create_context_callback; +using librbd::util::create_rados_ack_callback; namespace { @@ -100,6 +102,43 @@ BootstrapRequest::~BootstrapRequest() { template void BootstrapRequest::send() { + get_local_image_id(); +} + +template +void BootstrapRequest::get_local_image_id() { + dout(20) << dendl; + + // attempt to cross-reference a local image by the global image id + librados::ObjectReadOperation op; + librbd::cls_client::mirror_image_get_image_id_start(&op, m_global_image_id); + + librados::AioCompletion *aio_comp = create_rados_ack_callback< + BootstrapRequest, &BootstrapRequest::handle_get_local_image_id>( + this); + int r = m_local_io_ctx.aio_operate(RBD_MIRRORING, aio_comp, &op, &m_out_bl); + assert(r == 0); + aio_comp->release(); +} + +template +void BootstrapRequest::handle_get_local_image_id(int r) { + dout(20) << ": r=" << r << dendl; + + if (r == 0) { + bufferlist::iterator iter = m_out_bl.begin(); + r = librbd::cls_client::mirror_image_get_image_id_finish( + &iter, &m_local_image_id); + } + + if (r == -ENOENT) { + dout(10) << ": image not registered locally" << dendl; + } else if (r < 0) { + derr << ": failed to retreive local image id: " << cpp_strerror(r) << dendl; + finish(r); + return; + } + get_client(); } @@ -136,9 +175,9 @@ template void BootstrapRequest::register_client() { dout(20) << dendl; - // record an empty place-holder record + // record an place-holder record librbd::journal::ClientData client_data{ - librbd::journal::MirrorPeerClientMeta{}}; + librbd::journal::MirrorPeerClientMeta{m_local_image_id}}; bufferlist client_data_bl; ::encode(client_data, client_data_bl); @@ -159,7 +198,7 @@ void BootstrapRequest::handle_register_client(int r) { return; } - *m_client_meta = librbd::journal::MirrorPeerClientMeta(); + *m_client_meta = librbd::journal::MirrorPeerClientMeta(m_local_image_id); open_remote_image(); } diff --git a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h index b0822be1e758..faa8694f96ef 100644 --- a/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h +++ b/src/tools/rbd_mirror/image_replayer/BootstrapRequest.h @@ -67,6 +67,9 @@ private: * * | * v + * GET_LOCAL_IMAGE_ID * * * * * * * * * * * * + * | * + * v * * GET_CLIENT * * * * * * * * * * * * * * * * * | * * v (skip if not needed) * (error) @@ -125,6 +128,11 @@ private: ImageCtxT *m_remote_image_ctx = nullptr; int m_ret_val = 0; + bufferlist m_out_bl; + + void get_local_image_id(); + void handle_get_local_image_id(int r); + void get_client(); void handle_get_client(int r); -- 2.47.3