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/ceph_mutex.h"
15 #include "include/rados/librados.hpp"
16 #include "tools/rbd_mirror/Types.h"
17 #include <boost/functional/hash.hpp>
18 #include <boost/optional.hpp>
19 #include "include/ceph_assert.h"
20 #include "tools/rbd_mirror/pool_watcher/Types.h"
22 namespace librbd
{ struct ImageCtx
; }
27 template <typename
> struct Threads
;
30 * Keeps track of images that have mirroring enabled within all
33 template <typename ImageCtxT
= librbd::ImageCtx
>
36 static PoolWatcher
* create(Threads
<ImageCtxT
> *threads
,
37 librados::IoCtx
&io_ctx
,
38 const std::string
& mirror_uuid
,
39 pool_watcher::Listener
&listener
) {
40 return new PoolWatcher(threads
, io_ctx
, mirror_uuid
, listener
);
43 PoolWatcher(Threads
<ImageCtxT
> *threads
,
44 librados::IoCtx
&io_ctx
,
45 const std::string
& mirror_uuid
,
46 pool_watcher::Listener
&listener
);
48 PoolWatcher(const PoolWatcher
&) = delete;
49 PoolWatcher
& operator=(const PoolWatcher
&) = delete;
51 bool is_blocklisted() const;
53 void init(Context
*on_finish
= nullptr);
54 void shut_down(Context
*on_finish
);
56 inline uint64_t get_image_count() const {
57 std::lock_guard locker
{m_lock
};
58 return m_image_ids
.size();
73 * |/--------------------------------\
78 * |/----------------------------\ |
86 * | |\---> IMAGE_UPDATED | |
89 * | | GET_IMAGE_NAME --/ |
91 * | \----> WATCH_ERROR ---------/
103 class MirroringWatcher
;
105 Threads
<ImageCtxT
> *m_threads
;
106 librados::IoCtx m_io_ctx
;
107 std::string m_mirror_uuid
;
108 pool_watcher::Listener
&m_listener
;
110 ImageIds m_refresh_image_ids
;
113 mutable ceph::mutex m_lock
;
115 Context
*m_on_init_finish
= nullptr;
117 ImageIds m_image_ids
;
119 bool m_pending_updates
= false;
120 bool m_notify_listener_in_progress
= false;
121 ImageIds m_pending_image_ids
;
122 ImageIds m_pending_added_image_ids
;
123 ImageIds m_pending_removed_image_ids
;
125 MirroringWatcher
*m_mirroring_watcher
;
127 Context
*m_timer_ctx
= nullptr;
129 AsyncOpTracker m_async_op_tracker
;
130 bool m_blocklisted
= false;
131 bool m_shutting_down
= false;
132 bool m_image_ids_invalid
= true;
133 bool m_refresh_in_progress
= false;
134 bool m_deferred_refresh
= false;
136 void register_watcher();
137 void handle_register_watcher(int r
);
138 void unregister_watcher();
140 void refresh_images();
141 void handle_refresh_images(int r
);
143 void schedule_refresh_images(double interval
);
144 void process_refresh_images();
146 void handle_rewatch_complete(int r
);
147 void handle_image_updated(const std::string
&image_id
,
148 const std::string
&global_image_id
,
151 void schedule_listener();
152 void notify_listener();
156 } // namespace mirror
159 extern template class rbd::mirror::PoolWatcher
<librbd::ImageCtx
>;
161 #endif // CEPH_RBD_MIRROR_POOL_WATCHER_H