]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/InstanceReplayer.h
update source to Ceph Pacific 16.2.2
[ceph.git] / ceph / src / tools / rbd_mirror / InstanceReplayer.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 RBD_MIRROR_INSTANCE_REPLAYER_H
5 #define RBD_MIRROR_INSTANCE_REPLAYER_H
6
7 #include <map>
8 #include <sstream>
9
10 #include "common/AsyncOpTracker.h"
11 #include "common/Formatter.h"
12 #include "common/ceph_mutex.h"
13 #include "tools/rbd_mirror/Types.h"
14
15 namespace journal { struct CacheManagerHandler; }
16
17 namespace librbd { class ImageCtx; }
18
19 namespace rbd {
20 namespace mirror {
21
22 template <typename> class ImageReplayer;
23 template <typename> class InstanceWatcher;
24 template <typename> class MirrorStatusUpdater;
25 struct PoolMetaCache;
26 template <typename> class ServiceDaemon;
27 template <typename> struct Threads;
28
29 template <typename ImageCtxT = librbd::ImageCtx>
30 class InstanceReplayer {
31 public:
32 static InstanceReplayer* create(
33 librados::IoCtx &local_io_ctx, const std::string &local_mirror_uuid,
34 Threads<ImageCtxT> *threads, ServiceDaemon<ImageCtxT> *service_daemon,
35 MirrorStatusUpdater<ImageCtxT>* local_status_updater,
36 journal::CacheManagerHandler *cache_manager_handler,
37 PoolMetaCache* pool_meta_cache) {
38 return new InstanceReplayer(local_io_ctx, local_mirror_uuid, threads,
39 service_daemon, local_status_updater,
40 cache_manager_handler, pool_meta_cache);
41 }
42 void destroy() {
43 delete this;
44 }
45
46 InstanceReplayer(librados::IoCtx &local_io_ctx,
47 const std::string &local_mirror_uuid,
48 Threads<ImageCtxT> *threads,
49 ServiceDaemon<ImageCtxT> *service_daemon,
50 MirrorStatusUpdater<ImageCtxT>* local_status_updater,
51 journal::CacheManagerHandler *cache_manager_handler,
52 PoolMetaCache* pool_meta_cache);
53 ~InstanceReplayer();
54
55 bool is_blocklisted() const;
56
57 int init();
58 void shut_down();
59
60 void init(Context *on_finish);
61 void shut_down(Context *on_finish);
62
63 void add_peer(const Peer<ImageCtxT>& peer);
64
65 void acquire_image(InstanceWatcher<ImageCtxT> *instance_watcher,
66 const std::string &global_image_id, Context *on_finish);
67 void release_image(const std::string &global_image_id, Context *on_finish);
68 void remove_peer_image(const std::string &global_image_id,
69 const std::string &peer_mirror_uuid,
70 Context *on_finish);
71
72 void release_all(Context *on_finish);
73
74 void print_status(Formatter *f);
75 void start();
76 void stop();
77 void restart();
78 void flush();
79
80 void stop(Context *on_finish);
81
82 private:
83 /**
84 * @verbatim
85 *
86 * <uninitialized> <-------------------\
87 * | (init) | (repeat for each
88 * v STOP_IMAGE_REPLAYER ---\ image replayer)
89 * SCHEDULE_IMAGE_STATE_CHECK_TASK ^ ^ |
90 * | | | |
91 * v (shut_down) | \---------/
92 * <initialized> -----------------> WAIT_FOR_OPS
93 *
94 * @endverbatim
95 */
96
97 typedef std::set<Peer<ImageCtxT>> Peers;
98
99 librados::IoCtx &m_local_io_ctx;
100 std::string m_local_mirror_uuid;
101 Threads<ImageCtxT> *m_threads;
102 ServiceDaemon<ImageCtxT> *m_service_daemon;
103 MirrorStatusUpdater<ImageCtxT>* m_local_status_updater;
104 journal::CacheManagerHandler *m_cache_manager_handler;
105 PoolMetaCache* m_pool_meta_cache;
106
107 mutable ceph::mutex m_lock;
108 AsyncOpTracker m_async_op_tracker;
109 std::map<std::string, ImageReplayer<ImageCtxT> *> m_image_replayers;
110 Peers m_peers;
111 Context *m_image_state_check_task = nullptr;
112 Context *m_on_shut_down = nullptr;
113 bool m_manual_stop = false;
114 bool m_blocklisted = false;
115
116 void wait_for_ops();
117 void handle_wait_for_ops(int r);
118
119 void start_image_replayer(ImageReplayer<ImageCtxT> *image_replayer);
120 void queue_start_image_replayers();
121 void start_image_replayers(int r);
122
123 void stop_image_replayer(ImageReplayer<ImageCtxT> *image_replayer,
124 Context *on_finish);
125
126 void stop_image_replayers();
127 void handle_stop_image_replayers(int r);
128
129 void schedule_image_state_check_task();
130 void cancel_image_state_check_task();
131 };
132
133 } // namespace mirror
134 } // namespace rbd
135
136 extern template class rbd::mirror::InstanceReplayer<librbd::ImageCtx>;
137
138 #endif // RBD_MIRROR_INSTANCE_REPLAYER_H