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_REMOTE_POOL_POLLER_H
5 #define CEPH_RBD_MIRROR_REMOTE_POOL_POLLER_H
7 #include "include/rados/librados.hpp"
8 #include "tools/rbd_mirror/Types.h"
12 namespace librbd
{ struct ImageCtx
; }
17 template <typename
> struct Threads
;
19 namespace remote_pool_poller
{
22 virtual ~Listener() {}
24 virtual void handle_updated(const RemotePoolMeta
& remote_pool_meta
) = 0;
27 }; // namespace remote_pool_poller
29 template <typename ImageCtxT
>
30 class RemotePoolPoller
{
32 static RemotePoolPoller
* create(
33 Threads
<ImageCtxT
>* threads
,
34 librados::IoCtx
& remote_io_ctx
,
35 const std::string
& site_name
,
36 const std::string
& local_mirror_uuid
,
37 remote_pool_poller::Listener
& listener
) {
38 return new RemotePoolPoller(threads
, remote_io_ctx
, site_name
,
39 local_mirror_uuid
, listener
);
43 Threads
<ImageCtxT
>* threads
,
44 librados::IoCtx
& remote_io_ctx
,
45 const std::string
& site_name
,
46 const std::string
& local_mirror_uuid
,
47 remote_pool_poller::Listener
& listener
)
49 m_remote_io_ctx(remote_io_ctx
),
50 m_site_name(site_name
),
51 m_local_mirror_uuid(local_mirror_uuid
),
52 m_listener(listener
) {
56 void init(Context
* on_finish
);
57 void shut_down(Context
* on_finish
);
65 * |/----------------------------\
79 * v (skip if no changes) |
82 * | (repeat periodically) |
83 * |\----------------------------/
97 Threads
<ImageCtxT
>* m_threads
;
98 librados::IoCtx
& m_remote_io_ctx
;
99 std::string m_site_name
;
100 std::string m_local_mirror_uuid
;
101 remote_pool_poller::Listener
& m_listener
;
105 RemotePoolMeta m_remote_pool_meta
;
106 bool m_updated
= false;
108 State m_state
= STATE_INITIALIZING
;
109 Context
* m_timer_task
= nullptr;
110 Context
* m_on_finish
= nullptr;
112 void get_mirror_uuid();
113 void handle_get_mirror_uuid(int r
);
115 void mirror_peer_ping();
116 void handle_mirror_peer_ping(int r
);
118 void mirror_peer_list();
119 void handle_mirror_peer_list(int r
);
121 void notify_listener();
123 void schedule_task(int r
);
128 } // namespace mirror
131 extern template class rbd::mirror::RemotePoolPoller
<librbd::ImageCtx
>;
133 #endif // CEPH_RBD_MIRROR_REMOTE_POOL_POLLER_H