X-Git-Url: https://gerrit.opnfv.org/gerrit/gitweb?a=blobdiff_plain;f=src%2Fceph%2Fsrc%2Ftools%2Frbd_mirror%2Fimage_replayer%2FIsPrimaryRequest.cc;fp=src%2Fceph%2Fsrc%2Ftools%2Frbd_mirror%2Fimage_replayer%2FIsPrimaryRequest.cc;h=0000000000000000000000000000000000000000;hb=7da45d65be36d36b880cc55c5036e96c24b53f00;hp=f2faa9f20f21f16112a8eefa029396d788b2199c;hpb=691462d09d0987b47e112d6ee8740375df3c51b2;p=stor4nfv.git diff --git a/src/ceph/src/tools/rbd_mirror/image_replayer/IsPrimaryRequest.cc b/src/ceph/src/tools/rbd_mirror/image_replayer/IsPrimaryRequest.cc deleted file mode 100644 index f2faa9f..0000000 --- a/src/ceph/src/tools/rbd_mirror/image_replayer/IsPrimaryRequest.cc +++ /dev/null @@ -1,122 +0,0 @@ -// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- -// vim: ts=8 sw=2 smarttab - -#include "IsPrimaryRequest.h" -#include "common/errno.h" -#include "common/WorkQueue.h" -#include "cls/rbd/cls_rbd_client.h" -#include "librbd/ImageCtx.h" -#include "librbd/Journal.h" -#include "librbd/Utils.h" -#include - -#define dout_context g_ceph_context -#define dout_subsys ceph_subsys_rbd_mirror -#undef dout_prefix -#define dout_prefix *_dout << "rbd::mirror::image_replayer::IsPrimaryRequest: " \ - << this << " " << __func__ << " " - -namespace rbd { -namespace mirror { -namespace image_replayer { - -using librbd::util::create_context_callback; -using librbd::util::create_rados_callback; - -template -IsPrimaryRequest::IsPrimaryRequest(I *image_ctx, bool *primary, - Context *on_finish) - : m_image_ctx(image_ctx), m_primary(primary), m_on_finish(on_finish) { -} - -template -void IsPrimaryRequest::send() { - send_get_mirror_state(); -} - -template -void IsPrimaryRequest::send_get_mirror_state() { - dout(20) << dendl; - - librados::ObjectReadOperation op; - librbd::cls_client::mirror_image_get_start(&op, m_image_ctx->id); - - librados::AioCompletion *aio_comp = create_rados_callback< - IsPrimaryRequest, &IsPrimaryRequest::handle_get_mirror_state>(this); - int r = m_image_ctx->md_ctx.aio_operate(RBD_MIRRORING, aio_comp, &op, - &m_out_bl); - assert(r == 0); - aio_comp->release(); -} - -template -void IsPrimaryRequest::handle_get_mirror_state(int r) { - dout(20) << ": r=" << r << dendl; - - cls::rbd::MirrorImage mirror_image; - if (r == 0) { - bufferlist::iterator iter = m_out_bl.begin(); - r = librbd::cls_client::mirror_image_get_finish(&iter, &mirror_image); - if (r == 0) { - if (mirror_image.state == cls::rbd::MIRROR_IMAGE_STATE_ENABLED) { - send_is_tag_owner(); - return; - } else if (mirror_image.state == cls::rbd::MIRROR_IMAGE_STATE_DISABLING) { - dout(5) << ": image mirroring is being disabled" << dendl; - *m_primary = false; - } else { - derr << ": image mirroring is disabled" << dendl; - r = -EINVAL; - } - } else { - derr << ": failed to decode image mirror state: " << cpp_strerror(r) - << dendl; - } - } else { - derr << ": failed to retrieve image mirror state: " << cpp_strerror(r) - << dendl; - } - - finish(r); -} - -template -void IsPrimaryRequest::send_is_tag_owner() { - // deduce the class type for the journal to support unit tests - using Journal = typename std::decay< - typename std::remove_pointer().journal)> - ::type>::type; - - dout(20) << dendl; - - Context *ctx = create_context_callback< - IsPrimaryRequest, &IsPrimaryRequest::handle_is_tag_owner>(this); - - Journal::is_tag_owner(m_image_ctx, m_primary, ctx); -} - -template -void IsPrimaryRequest::handle_is_tag_owner(int r) { - dout(20) << ": r=" << r << dendl; - - if (r < 0) { - derr << ": failed to query remote image tag owner: " << cpp_strerror(r) - << dendl; - } - - finish(r); -} - -template -void IsPrimaryRequest::finish(int r) { - dout(20) << ": r=" << r << dendl; - - m_on_finish->complete(r); - delete this; -} - -} // namespace image_replayer -} // namespace mirror -} // namespace rbd - -template class rbd::mirror::image_replayer::IsPrimaryRequest;