1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPH_RBD_MIRROR_POOL_WATCHER_H
5 #define CEPH_RBD_MIRROR_POOL_WATCHER_H
12 #include "common/AsyncOpTracker.h"
13 #include "common/ceph_context.h"
14 #include "common/Mutex.h"
15 #include "include/rados/librados.hpp"
17 #include <boost/functional/hash.hpp>
18 #include <boost/optional.hpp>
19 #include "include/assert.h"
21 namespace librbd
{ struct ImageCtx
; }
26 template <typename
> struct Threads
;
29 * Keeps track of images that have mirroring enabled within all
32 template <typename ImageCtxT
= librbd::ImageCtx
>
39 virtual void handle_update(const std::string
&mirror_uuid
,
40 ImageIds
&&added_image_ids
,
41 ImageIds
&&removed_image_ids
) = 0;
44 PoolWatcher(Threads
<ImageCtxT
> *threads
, librados::IoCtx
&remote_io_ctx
,
47 PoolWatcher(const PoolWatcher
&) = delete;
48 PoolWatcher
& operator=(const PoolWatcher
&) = delete;
50 bool is_blacklisted() const;
52 void init(Context
*on_finish
= nullptr);
53 void shut_down(Context
*on_finish
);
67 * |/--------------------------------\
72 * |/----------------------------\ |
83 * | |\---> IMAGE_UPDATED | |
86 * | | GET_IMAGE_NAME --/ |
88 * | \----> WATCH_ERROR ---------/
100 class MirroringWatcher
;
102 Threads
<ImageCtxT
> *m_threads
;
103 librados::IoCtx m_remote_io_ctx
;
104 Listener
&m_listener
;
106 ImageIds m_refresh_image_ids
;
109 mutable Mutex m_lock
;
111 Context
*m_on_init_finish
= nullptr;
113 ImageIds m_image_ids
;
114 std::string m_mirror_uuid
;
116 bool m_pending_updates
= false;
117 bool m_notify_listener_in_progress
= false;
118 ImageIds m_pending_image_ids
;
119 ImageIds m_pending_added_image_ids
;
120 ImageIds m_pending_removed_image_ids
;
122 std::string m_pending_mirror_uuid
;
124 MirroringWatcher
*m_mirroring_watcher
;
126 Context
*m_timer_ctx
= nullptr;
128 AsyncOpTracker m_async_op_tracker
;
129 bool m_blacklisted
= false;
130 bool m_shutting_down
= false;
131 bool m_image_ids_invalid
= true;
132 bool m_refresh_in_progress
= false;
133 bool m_deferred_refresh
= false;
135 void register_watcher();
136 void handle_register_watcher(int r
);
137 void unregister_watcher();
139 void refresh_images();
140 void handle_refresh_images(int r
);
142 void schedule_refresh_images(double interval
);
143 void process_refresh_images();
145 void get_mirror_uuid();
146 void handle_get_mirror_uuid(int r
);
148 void handle_rewatch_complete(int r
);
149 void handle_image_updated(const std::string
&remote_image_id
,
150 const std::string
&global_image_id
,
153 void schedule_listener();
154 void notify_listener();
158 } // namespace mirror
161 extern template class rbd::mirror::PoolWatcher
<librbd::ImageCtx
>;
163 #endif // CEPH_RBD_MIRROR_POOL_WATCHER_H