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 mirror_uuid
, librados::IoCtx io_ctx
);
56 void remove_peer(std::string mirror_uuid
);
58 void acquire_image(InstanceWatcher
<ImageCtxT
> *instance_watcher
,
59 const std::string
&global_image_id
,
60 const std::string
&peer_mirror_uuid
,
61 const std::string
&peer_image_id
,
63 void release_image(const std::string
&global_image_id
,
64 const std::string
&peer_mirror_uuid
,
65 const std::string
&peer_image_id
,
66 bool schedule_delete
, Context
*on_finish
);
67 void release_all(Context
*on_finish
);
69 void print_status(Formatter
*f
, stringstream
*ss
);
79 * <uninitialized> <-------------------\
80 * | (init) | (repeat for each
81 * v STOP_IMAGE_REPLAYER ---\ image replayer)
82 * SCHEDULE_IMAGE_STATE_CHECK_TASK ^ ^ |
84 * v (shut_down) | \---------/
85 * <initialized> -----------------> WAIT_FOR_OPS
91 std::string mirror_uuid
;
92 librados::IoCtx io_ctx
;
97 Peer(const std::string
&mirror_uuid
) : mirror_uuid(mirror_uuid
) {
100 Peer(const std::string
&mirror_uuid
, librados::IoCtx
&io_ctx
)
101 : mirror_uuid(mirror_uuid
), io_ctx(io_ctx
) {
104 inline bool operator<(const Peer
&rhs
) const {
105 return mirror_uuid
< rhs
.mirror_uuid
;
107 inline bool operator==(const Peer
&rhs
) const {
108 return mirror_uuid
== rhs
.mirror_uuid
;
112 typedef std::set
<Peer
> Peers
;
114 Threads
<ImageCtxT
> *m_threads
;
115 ServiceDaemon
<ImageCtxT
>* m_service_daemon
;
116 ImageDeleter
<ImageCtxT
>* m_image_deleter
;
117 RadosRef m_local_rados
;
118 std::string m_local_mirror_uuid
;
119 int64_t m_local_pool_id
;
122 AsyncOpTracker m_async_op_tracker
;
123 std::map
<std::string
, ImageReplayer
<ImageCtxT
> *> m_image_replayers
;
125 Context
*m_image_state_check_task
= nullptr;
126 Context
*m_on_shut_down
= nullptr;
127 bool m_manual_stop
= false;
130 void handle_wait_for_ops(int r
);
132 void start_image_replayer(ImageReplayer
<ImageCtxT
> *image_replayer
);
133 void queue_start_image_replayers();
134 void start_image_replayers(int r
);
136 void stop_image_replayer(ImageReplayer
<ImageCtxT
> *image_replayer
,
139 void stop_image_replayers();
140 void handle_stop_image_replayers(int r
);
142 void schedule_image_state_check_task();
143 void cancel_image_state_check_task();
146 } // namespace mirror
149 extern template class rbd::mirror::InstanceReplayer
<librbd::ImageCtx
>;
151 #endif // RBD_MIRROR_INSTANCE_REPLAYER_H