1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef RBD_MIRROR_INSTANCE_REPLAYER_H
5 #define RBD_MIRROR_INSTANCE_REPLAYER_H
10 #include "common/AsyncOpTracker.h"
11 #include "common/Formatter.h"
12 #include "common/Mutex.h"
15 namespace librbd { class ImageCtx; }
20 template <typename> class ImageDeleter;
21 template <typename> class ImageReplayer;
22 template <typename> class InstanceWatcher;
23 template <typename> class ServiceDaemon;
24 template <typename> struct Threads;
26 template <typename ImageCtxT = librbd::ImageCtx>
27 class InstanceReplayer {
29 static InstanceReplayer* create(
30 Threads<ImageCtxT> *threads,
31 ServiceDaemon<ImageCtxT>* service_daemon,
32 ImageDeleter<ImageCtxT>* image_deleter,
33 RadosRef local_rados, const std::string &local_mirror_uuid,
34 int64_t local_pool_id) {
35 return new InstanceReplayer(threads, service_daemon, image_deleter,
36 local_rados, local_mirror_uuid, local_pool_id);
42 InstanceReplayer(Threads<ImageCtxT> *threads,
43 ServiceDaemon<ImageCtxT>* service_daemon,
44 ImageDeleter<ImageCtxT>* image_deleter,
45 RadosRef local_rados, const std::string &local_mirror_uuid,
46 int64_t local_pool_id);
52 void init(Context *on_finish);
53 void shut_down(Context *on_finish);
55 void add_peer(std::string peer_uuid, librados::IoCtx io_ctx);
57 void acquire_image(InstanceWatcher<ImageCtxT> *instance_watcher,
58 const std::string &global_image_id, Context *on_finish);
59 void release_image(const std::string &global_image_id, Context *on_finish);
60 void remove_peer_image(const std::string &global_image_id,
61 const std::string &peer_mirror_uuid,
64 void release_all(Context *on_finish);
66 void print_status(Formatter *f, stringstream *ss);
76 * <uninitialized> <-------------------\
77 * | (init) | (repeat for each
78 * v STOP_IMAGE_REPLAYER ---\ image replayer)
79 * SCHEDULE_IMAGE_STATE_CHECK_TASK ^ ^ |
81 * v (shut_down) | \---------/
82 * <initialized> -----------------> WAIT_FOR_OPS
87 Threads<ImageCtxT> *m_threads;
88 ServiceDaemon<ImageCtxT>* m_service_daemon;
89 ImageDeleter<ImageCtxT>* m_image_deleter;
90 RadosRef m_local_rados;
91 std::string m_local_mirror_uuid;
92 int64_t m_local_pool_id;
95 AsyncOpTracker m_async_op_tracker;
96 std::map<std::string, ImageReplayer<ImageCtxT> *> m_image_replayers;
98 Context *m_image_state_check_task = nullptr;
99 Context *m_on_shut_down = nullptr;
100 bool m_manual_stop = false;
103 void handle_wait_for_ops(int r);
105 void start_image_replayer(ImageReplayer<ImageCtxT> *image_replayer);
106 void queue_start_image_replayers();
107 void start_image_replayers(int r);
109 void stop_image_replayer(ImageReplayer<ImageCtxT> *image_replayer,
112 void stop_image_replayers();
113 void handle_stop_image_replayers(int r);
115 void schedule_image_state_check_task();
116 void cancel_image_state_check_task();
119 } // namespace mirror
122 extern template class rbd::mirror::InstanceReplayer<librbd::ImageCtx>;
124 #endif // RBD_MIRROR_INSTANCE_REPLAYER_H