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);
55 inline uint64_t get_image_count() const {
56 Mutex::Locker locker(m_lock);
57 return m_image_ids.size();
72 * |/--------------------------------\
77 * |/----------------------------\ |
88 * | |\---> IMAGE_UPDATED | |
91 * | | GET_IMAGE_NAME --/ |
93 * | \----> WATCH_ERROR ---------/
105 class MirroringWatcher;
107 Threads<ImageCtxT> *m_threads;
108 librados::IoCtx m_remote_io_ctx;
109 Listener &m_listener;
111 ImageIds m_refresh_image_ids;
114 mutable Mutex m_lock;
116 Context *m_on_init_finish = nullptr;
118 ImageIds m_image_ids;
119 std::string m_mirror_uuid;
121 bool m_pending_updates = false;
122 bool m_notify_listener_in_progress = false;
123 ImageIds m_pending_image_ids;
124 ImageIds m_pending_added_image_ids;
125 ImageIds m_pending_removed_image_ids;
127 std::string m_pending_mirror_uuid;
129 MirroringWatcher *m_mirroring_watcher;
131 Context *m_timer_ctx = nullptr;
133 AsyncOpTracker m_async_op_tracker;
134 bool m_blacklisted = false;
135 bool m_shutting_down = false;
136 bool m_image_ids_invalid = true;
137 bool m_refresh_in_progress = false;
138 bool m_deferred_refresh = false;
140 void register_watcher();
141 void handle_register_watcher(int r);
142 void unregister_watcher();
144 void refresh_images();
145 void handle_refresh_images(int r);
147 void schedule_refresh_images(double interval);
148 void process_refresh_images();
150 void get_mirror_uuid();
151 void handle_get_mirror_uuid(int r);
153 void handle_rewatch_complete(int r);
154 void handle_image_updated(const std::string &remote_image_id,
155 const std::string &global_image_id,
158 void schedule_listener();
159 void notify_listener();
163 } // namespace mirror
166 extern template class rbd::mirror::PoolWatcher<librbd::ImageCtx>;
168 #endif // CEPH_RBD_MIRROR_POOL_WATCHER_H