]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/image_replayer/StateBuilder.h
import ceph quincy 17.2.4
[ceph.git] / ceph / src / tools / rbd_mirror / image_replayer / StateBuilder.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_RBD_MIRROR_IMAGE_REPLAYER_STATE_BUILDER_H
5 #define CEPH_RBD_MIRROR_IMAGE_REPLAYER_STATE_BUILDER_H
6
7 #include "include/rados/librados_fwd.hpp"
8 #include "cls/rbd/cls_rbd_types.h"
9 #include "librbd/mirror/Types.h"
10
11 struct Context;
12 namespace librbd { struct ImageCtx; }
13
14 namespace rbd {
15 namespace mirror {
16
17 struct BaseRequest;
18 template <typename> class InstanceWatcher;
19 struct PoolMetaCache;
20 struct ProgressContext;
21 template <typename> class Threads;
22
23 namespace image_sync { struct SyncPointHandler; }
24
25 namespace image_replayer {
26
27 struct Replayer;
28 struct ReplayerListener;
29
30 template <typename ImageCtxT>
31 class StateBuilder {
32 public:
33 StateBuilder(const StateBuilder&) = delete;
34 StateBuilder& operator=(const StateBuilder&) = delete;
35
36 virtual ~StateBuilder();
37
38 virtual void destroy() {
39 delete this;
40 }
41
42 virtual void close(Context* on_finish) = 0;
43
44 virtual bool is_disconnected() const = 0;
45
46 bool is_local_primary() const;
47 bool is_remote_primary() const;
48 bool is_linked() const;
49
50 virtual cls::rbd::MirrorImageMode get_mirror_image_mode() const = 0;
51
52 virtual image_sync::SyncPointHandler* create_sync_point_handler() = 0;
53 void destroy_sync_point_handler();
54
55 virtual bool replay_requires_remote_image() const = 0;
56
57 void close_remote_image(Context* on_finish);
58
59 virtual BaseRequest* create_local_image_request(
60 Threads<ImageCtxT>* threads,
61 librados::IoCtx& local_io_ctx,
62 const std::string& global_image_id,
63 PoolMetaCache* pool_meta_cache,
64 ProgressContext* progress_ctx,
65 Context* on_finish) = 0;
66
67 virtual BaseRequest* create_prepare_replay_request(
68 const std::string& local_mirror_uuid,
69 ProgressContext* progress_ctx,
70 bool* resync_requested,
71 bool* syncing,
72 Context* on_finish) = 0;
73
74 virtual Replayer* create_replayer(
75 Threads<ImageCtxT>* threads,
76 InstanceWatcher<ImageCtxT>* instance_watcher,
77 const std::string& local_mirror_uuid,
78 PoolMetaCache* pool_meta_cache,
79 ReplayerListener* replayer_listener) = 0;
80
81 std::string global_image_id;
82
83 std::string local_image_id;
84 librbd::mirror::PromotionState local_promotion_state =
85 librbd::mirror::PROMOTION_STATE_UNKNOWN;
86 ImageCtxT* local_image_ctx = nullptr;
87
88 std::string remote_mirror_uuid;
89 std::string remote_image_id;
90 librbd::mirror::PromotionState remote_promotion_state =
91 librbd::mirror::PROMOTION_STATE_UNKNOWN;
92 ImageCtxT* remote_image_ctx = nullptr;
93
94 protected:
95 image_sync::SyncPointHandler* m_sync_point_handler = nullptr;
96
97 StateBuilder(const std::string& global_image_id);
98
99 void close_local_image(Context* on_finish);
100
101 private:
102 virtual bool is_linked_impl() const = 0;
103
104 void handle_close_local_image(int r, Context* on_finish);
105 void handle_close_remote_image(int r, Context* on_finish);
106 };
107
108 } // namespace image_replayer
109 } // namespace mirror
110 } // namespace rbd
111
112 extern template class rbd::mirror::image_replayer::StateBuilder<librbd::ImageCtx>;
113
114 #endif // CEPH_RBD_MIRROR_IMAGE_REPLAYER_STATE_BUILDER_H