]> git.proxmox.com Git - ceph.git/blame - 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
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#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
11struct Context;
12namespace librbd { struct ImageCtx; }
13
14namespace rbd {
15namespace mirror {
16
17struct BaseRequest;
18template <typename> class InstanceWatcher;
19struct PoolMetaCache;
20struct ProgressContext;
21template <typename> class Threads;
22
23namespace image_sync { struct SyncPointHandler; }
24
25namespace image_replayer {
26
27struct Replayer;
28struct ReplayerListener;
29
30template <typename ImageCtxT>
31class StateBuilder {
32public:
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;
20effc67 47 bool is_linked() const;
9f95a23c
TL
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
20effc67 54 virtual bool replay_requires_remote_image() const = 0;
9f95a23c
TL
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
20effc67 82 std::string local_image_id;
9f95a23c
TL
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;
20effc67 88 std::string remote_image_id;
9f95a23c
TL
89 librbd::mirror::PromotionState remote_promotion_state =
90 librbd::mirror::PROMOTION_STATE_NON_PRIMARY;
91 ImageCtxT* remote_image_ctx = nullptr;
92
93protected:
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
100private:
20effc67
TL
101 virtual bool is_linked_impl() const = 0;
102
9f95a23c
TL
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
111extern template class rbd::mirror::image_replayer::StateBuilder<librbd::ImageCtx>;
112
113#endif // CEPH_RBD_MIRROR_IMAGE_REPLAYER_STATE_BUILDER_H