]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/image_replayer/StateBuilder.h
import quincy beta 17.1.0
[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_linked() const;
48
49 virtual cls::rbd::MirrorImageMode get_mirror_image_mode() const = 0;
50
51 virtual image_sync::SyncPointHandler* create_sync_point_handler() = 0;
52 void destroy_sync_point_handler();
53
54 virtual bool replay_requires_remote_image() const = 0;
55
56 void close_remote_image(Context* on_finish);
57
58 virtual BaseRequest* create_local_image_request(
59 Threads<ImageCtxT>* threads,
60 librados::IoCtx& local_io_ctx,
61 const std::string& global_image_id,
62 PoolMetaCache* pool_meta_cache,
63 ProgressContext* progress_ctx,
64 Context* on_finish) = 0;
65
66 virtual BaseRequest* create_prepare_replay_request(
67 const std::string& local_mirror_uuid,
68 ProgressContext* progress_ctx,
69 bool* resync_requested,
70 bool* syncing,
71 Context* on_finish) = 0;
72
73 virtual Replayer* create_replayer(
74 Threads<ImageCtxT>* threads,
75 InstanceWatcher<ImageCtxT>* instance_watcher,
76 const std::string& local_mirror_uuid,
77 PoolMetaCache* pool_meta_cache,
78 ReplayerListener* replayer_listener) = 0;
79
80 std::string global_image_id;
81
82 std::string local_image_id;
83 librbd::mirror::PromotionState local_promotion_state =
84 librbd::mirror::PROMOTION_STATE_PRIMARY;
85 ImageCtxT* local_image_ctx = nullptr;
86
87 std::string remote_mirror_uuid;
88 std::string remote_image_id;
89 librbd::mirror::PromotionState remote_promotion_state =
90 librbd::mirror::PROMOTION_STATE_NON_PRIMARY;
91 ImageCtxT* remote_image_ctx = nullptr;
92
93 protected:
94 image_sync::SyncPointHandler* m_sync_point_handler = nullptr;
95
96 StateBuilder(const std::string& global_image_id);
97
98 void close_local_image(Context* on_finish);
99
100 private:
101 virtual bool is_linked_impl() const = 0;
102
103 void handle_close_local_image(int r, Context* on_finish);
104 void handle_close_remote_image(int r, Context* on_finish);
105 };
106
107 } // namespace image_replayer
108 } // namespace mirror
109 } // namespace rbd
110
111 extern template class rbd::mirror::image_replayer::StateBuilder<librbd::ImageCtx>;
112
113 #endif // CEPH_RBD_MIRROR_IMAGE_REPLAYER_STATE_BUILDER_H