]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/image_replayer/OpenImageRequest.cc
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / tools / rbd_mirror / image_replayer / OpenImageRequest.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #include "OpenImageRequest.h"
5 #include "common/debug.h"
6 #include "common/errno.h"
7 #include "librbd/ImageCtx.h"
8 #include "librbd/ImageState.h"
9 #include "librbd/Utils.h"
10 #include <type_traits>
11
12 #define dout_context g_ceph_context
13 #define dout_subsys ceph_subsys_rbd_mirror
14 #undef dout_prefix
15 #define dout_prefix *_dout << "rbd::mirror::image_replayer::OpenImageRequest: " \
16 << this << " " << __func__ << " "
17
18 namespace rbd {
19 namespace mirror {
20 namespace image_replayer {
21
22 using librbd::util::create_context_callback;
23
24 template <typename I>
25 OpenImageRequest<I>::OpenImageRequest(librados::IoCtx &io_ctx, I **image_ctx,
26 const std::string &image_id,
27 bool read_only, Context *on_finish)
28 : m_io_ctx(io_ctx), m_image_ctx(image_ctx), m_image_id(image_id),
29 m_read_only(read_only), m_on_finish(on_finish) {
30 }
31
32 template <typename I>
33 void OpenImageRequest<I>::send() {
34 send_open_image();
35 }
36
37 template <typename I>
38 void OpenImageRequest<I>::send_open_image() {
39 dout(20) << dendl;
40
41 *m_image_ctx = I::create("", m_image_id, nullptr, m_io_ctx, m_read_only);
42
43 if (!m_read_only) {
44 // ensure non-primary images can be modified
45 (*m_image_ctx)->read_only_mask = ~librbd::IMAGE_READ_ONLY_FLAG_NON_PRIMARY;
46 }
47
48 Context *ctx = create_context_callback<
49 OpenImageRequest<I>, &OpenImageRequest<I>::handle_open_image>(
50 this);
51 (*m_image_ctx)->state->open(0, ctx);
52 }
53
54 template <typename I>
55 void OpenImageRequest<I>::handle_open_image(int r) {
56 dout(20) << ": r=" << r << dendl;
57
58 if (r < 0) {
59 derr << ": failed to open image '" << m_image_id << "': "
60 << cpp_strerror(r) << dendl;
61 *m_image_ctx = nullptr;
62 }
63
64 finish(r);
65 }
66
67 template <typename I>
68 void OpenImageRequest<I>::finish(int r) {
69 dout(20) << ": r=" << r << dendl;
70
71 m_on_finish->complete(r);
72 delete this;
73 }
74
75 } // namespace image_replayer
76 } // namespace mirror
77 } // namespace rbd
78
79 template class rbd::mirror::image_replayer::OpenImageRequest<librbd::ImageCtx>;