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/ceph_mutex.h"
13 #include "tools/rbd_mirror/Types.h"
15 namespace journal
{ struct CacheManagerHandler
; }
17 namespace librbd
{ class ImageCtx
; }
22 template <typename
> class ImageReplayer
;
23 template <typename
> class InstanceWatcher
;
24 template <typename
> class MirrorStatusUpdater
;
26 template <typename
> class ServiceDaemon
;
27 template <typename
> struct Threads
;
29 template <typename ImageCtxT
= librbd::ImageCtx
>
30 class InstanceReplayer
{
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
);
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
);
55 bool is_blocklisted() const;
60 void init(Context
*on_finish
);
61 void shut_down(Context
*on_finish
);
63 void add_peer(const Peer
<ImageCtxT
>& peer
);
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
,
72 void release_all(Context
*on_finish
);
74 void print_status(Formatter
*f
);
80 void stop(Context
*on_finish
);
86 * <uninitialized> <-------------------\
87 * | (init) | (repeat for each
88 * v STOP_IMAGE_REPLAYER ---\ image replayer)
89 * SCHEDULE_IMAGE_STATE_CHECK_TASK ^ ^ |
91 * v (shut_down) | \---------/
92 * <initialized> -----------------> WAIT_FOR_OPS
97 typedef std::set
<Peer
<ImageCtxT
>> Peers
;
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
;
107 mutable ceph::mutex m_lock
;
108 AsyncOpTracker m_async_op_tracker
;
109 std::map
<std::string
, ImageReplayer
<ImageCtxT
> *> m_image_replayers
;
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;
117 void handle_wait_for_ops(int r
);
119 void start_image_replayer(ImageReplayer
<ImageCtxT
> *image_replayer
);
120 void queue_start_image_replayers();
121 void start_image_replayers(int r
);
123 void stop_image_replayer(ImageReplayer
<ImageCtxT
> *image_replayer
,
126 void stop_image_replayers();
127 void handle_stop_image_replayers(int r
);
129 void schedule_image_state_check_task();
130 void cancel_image_state_check_task();
133 } // namespace mirror
136 extern template class rbd::mirror::InstanceReplayer
<librbd::ImageCtx
>;
138 #endif // RBD_MIRROR_INSTANCE_REPLAYER_H