]> git.proxmox.com Git - ceph.git/blame - ceph/src/tools/rbd_mirror/image_replayer/snapshot/StateBuilder.cc
import ceph quincy 17.2.4
[ceph.git] / ceph / src / tools / rbd_mirror / image_replayer / snapshot / StateBuilder.cc
CommitLineData
9f95a23c
TL
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#include "StateBuilder.h"
5#include "include/ceph_assert.h"
6#include "include/Context.h"
7#include "common/debug.h"
8#include "common/errno.h"
9#include "librbd/ImageCtx.h"
10#include "librbd/mirror/snapshot/ImageMeta.h"
11#include "tools/rbd_mirror/image_replayer/snapshot/CreateLocalImageRequest.h"
12#include "tools/rbd_mirror/image_replayer/snapshot/PrepareReplayRequest.h"
13#include "tools/rbd_mirror/image_replayer/snapshot/Replayer.h"
14
15#define dout_context g_ceph_context
16#define dout_subsys ceph_subsys_rbd_mirror
17#undef dout_prefix
18#define dout_prefix *_dout << "rbd::mirror::image_replayer::snapshot::" \
19 << "StateBuilder: " << this << " " \
20 << __func__ << ": "
21
22namespace rbd {
23namespace mirror {
24namespace image_replayer {
25namespace snapshot {
26
27template <typename I>
28StateBuilder<I>::StateBuilder(const std::string& global_image_id)
29 : image_replayer::StateBuilder<I>(global_image_id) {
30}
31
32template <typename I>
33StateBuilder<I>::~StateBuilder() {
34 ceph_assert(local_image_meta == nullptr);
35}
36
37template <typename I>
38void StateBuilder<I>::close(Context* on_finish) {
39 dout(10) << dendl;
40
41 delete local_image_meta;
42 local_image_meta = nullptr;
43
44 // close the remote image after closing the local
45 // image in case the remote cluster is unreachable and
46 // we cannot close it.
47 on_finish = new LambdaContext([this, on_finish](int) {
48 this->close_remote_image(on_finish);
49 });
50 this->close_local_image(on_finish);
51}
52
53template <typename I>
54bool StateBuilder<I>::is_disconnected() const {
55 return false;
56}
57
58template <typename I>
20effc67 59bool StateBuilder<I>::is_linked_impl() const {
9f95a23c 60 // the remote has to have us registered as a peer
20effc67 61 return !remote_mirror_peer_uuid.empty();
9f95a23c
TL
62}
63
64template <typename I>
65cls::rbd::MirrorImageMode StateBuilder<I>::get_mirror_image_mode() const {
66 return cls::rbd::MIRROR_IMAGE_MODE_SNAPSHOT;
67}
68
69template <typename I>
70image_sync::SyncPointHandler* StateBuilder<I>::create_sync_point_handler() {
71 dout(10) << dendl;
72
73 // TODO
74 ceph_assert(false);
75 return nullptr;
76}
77
78template <typename I>
79BaseRequest* StateBuilder<I>::create_local_image_request(
80 Threads<I>* threads,
81 librados::IoCtx& local_io_ctx,
82 const std::string& global_image_id,
83 PoolMetaCache* pool_meta_cache,
84 ProgressContext* progress_ctx,
85 Context* on_finish) {
86 return CreateLocalImageRequest<I>::create(
87 threads, local_io_ctx, this->remote_image_ctx, global_image_id,
88 pool_meta_cache, progress_ctx, this, on_finish);
89}
90
91template <typename I>
92BaseRequest* StateBuilder<I>::create_prepare_replay_request(
93 const std::string& local_mirror_uuid,
94 ProgressContext* progress_ctx,
95 bool* resync_requested,
96 bool* syncing,
97 Context* on_finish) {
98 return PrepareReplayRequest<I>::create(
2a845540
TL
99 local_mirror_uuid, progress_ctx, this, resync_requested, syncing,
100 on_finish);
9f95a23c
TL
101}
102
103template <typename I>
104image_replayer::Replayer* StateBuilder<I>::create_replayer(
105 Threads<I>* threads,
106 InstanceWatcher<I>* instance_watcher,
107 const std::string& local_mirror_uuid,
108 PoolMetaCache* pool_meta_cache,
109 ReplayerListener* replayer_listener) {
110 return Replayer<I>::create(
111 threads, instance_watcher, local_mirror_uuid, pool_meta_cache, this,
112 replayer_listener);
113}
114
115} // namespace snapshot
116} // namespace image_replayer
117} // namespace mirror
118} // namespace rbd
119
120template class rbd::mirror::image_replayer::snapshot::StateBuilder<librbd::ImageCtx>;