1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #include "tools/rbd_mirror/image_replayer/PrepareRemoteImageRequest.h"
5 #include "include/rados/librados.hpp"
6 #include "cls/rbd/cls_rbd_client.h"
7 #include "common/errno.h"
8 #include "librbd/ImageCtx.h"
9 #include "librbd/Utils.h"
10 #include "tools/rbd_mirror/image_replayer/GetMirrorImageIdRequest.h"
12 #define dout_context g_ceph_context
13 #define dout_subsys ceph_subsys_rbd_mirror
15 #define dout_prefix *_dout << "rbd::mirror::image_replayer::" \
16 << "PrepareRemoteImageRequest: " << this << " " \
21 namespace image_replayer
{
23 using librbd::util::create_context_callback
;
24 using librbd::util::create_rados_callback
;
27 void PrepareRemoteImageRequest
<I
>::send() {
28 get_remote_mirror_uuid();
32 void PrepareRemoteImageRequest
<I
>::get_remote_mirror_uuid() {
35 librados::ObjectReadOperation op
;
36 librbd::cls_client::mirror_uuid_get_start(&op
);
38 librados::AioCompletion
*aio_comp
= create_rados_callback
<
39 PrepareRemoteImageRequest
<I
>,
40 &PrepareRemoteImageRequest
<I
>::handle_get_remote_mirror_uuid
>(this);
41 int r
= m_io_ctx
.aio_operate(RBD_MIRRORING
, aio_comp
, &op
, &m_out_bl
);
47 void PrepareRemoteImageRequest
<I
>::handle_get_remote_mirror_uuid(int r
) {
49 bufferlist::iterator it
= m_out_bl
.begin();
50 r
= librbd::cls_client::mirror_uuid_get_finish(&it
, m_remote_mirror_uuid
);
51 if (r
>= 0 && m_remote_mirror_uuid
->empty()) {
56 dout(20) << "r=" << r
<< dendl
;
59 dout(5) << "remote mirror uuid missing" << dendl
;
61 derr
<< "failed to retrieve remote mirror uuid: " << cpp_strerror(r
)
68 get_remote_image_id();
72 void PrepareRemoteImageRequest
<I
>::get_remote_image_id() {
75 Context
*ctx
= create_context_callback
<
76 PrepareRemoteImageRequest
<I
>,
77 &PrepareRemoteImageRequest
<I
>::handle_get_remote_image_id
>(this);
78 auto req
= GetMirrorImageIdRequest
<I
>::create(m_io_ctx
, m_global_image_id
,
79 m_remote_image_id
, ctx
);
84 void PrepareRemoteImageRequest
<I
>::handle_get_remote_image_id(int r
) {
85 dout(20) << "r=" << r
<< ", "
86 << "remote_image_id=" << *m_remote_image_id
<< dendl
;
97 void PrepareRemoteImageRequest
<I
>::finish(int r
) {
98 dout(20) << "r=" << r
<< dendl
;
100 m_on_finish
->complete(r
);
104 } // namespace image_replayer
105 } // namespace mirror
108 template class rbd::mirror::image_replayer::PrepareRemoteImageRequest
<librbd::ImageCtx
>;