]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/rbd_mirror/RemotePoolPoller.h
import ceph quincy 17.2.4
[ceph.git] / ceph / src / tools / rbd_mirror / RemotePoolPoller.h
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3
4 #ifndef CEPH_RBD_MIRROR_REMOTE_POOL_POLLER_H
5 #define CEPH_RBD_MIRROR_REMOTE_POOL_POLLER_H
6
7 #include "include/rados/librados.hpp"
8 #include "tools/rbd_mirror/Types.h"
9 #include <string>
10
11 struct Context;
12 namespace librbd { struct ImageCtx; }
13
14 namespace rbd {
15 namespace mirror {
16
17 template <typename> struct Threads;
18
19 namespace remote_pool_poller {
20
21 struct Listener {
22 virtual ~Listener() {}
23
24 virtual void handle_updated(const RemotePoolMeta& remote_pool_meta) = 0;
25 };
26
27 }; // namespace remote_pool_poller
28
29 template <typename ImageCtxT>
30 class RemotePoolPoller {
31 public:
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);
40 }
41
42 RemotePoolPoller(
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)
48 : m_threads(threads),
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) {
53 }
54 ~RemotePoolPoller();
55
56 void init(Context* on_finish);
57 void shut_down(Context* on_finish);
58
59 private:
60 /**
61 * @verbatim
62 *
63 * <start>
64 * |
65 * |/----------------------------\
66 * | |
67 * v |
68 * MIRROR_UUID_GET |
69 * | |
70 * v |
71 * MIRROR_PEER_PING |
72 * | |
73 * v |
74 * MIRROR_PEER_LIST |
75 * | |
76 * v |
77 * MIRROR_UUID_GET |
78 * | |
79 * v (skip if no changes) |
80 * NOTIFY_LISTENER |
81 * | |
82 * | (repeat periodically) |
83 * |\----------------------------/
84 * |
85 * v
86 * <finish>
87 *
88 * @endverbatim
89 */
90
91 enum State {
92 STATE_INITIALIZING,
93 STATE_POLLING,
94 STATE_SHUTTING_DOWN
95 };
96
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;
102
103 bufferlist m_out_bl;
104
105 RemotePoolMeta m_remote_pool_meta;
106 bool m_updated = false;
107
108 State m_state = STATE_INITIALIZING;
109 Context* m_timer_task = nullptr;
110 Context* m_on_finish = nullptr;
111
112 void get_mirror_uuid();
113 void handle_get_mirror_uuid(int r);
114
115 void mirror_peer_ping();
116 void handle_mirror_peer_ping(int r);
117
118 void mirror_peer_list();
119 void handle_mirror_peer_list(int r);
120
121 void notify_listener();
122
123 void schedule_task(int r);
124 void handle_task();
125
126 };
127
128 } // namespace mirror
129 } // namespace rbd
130
131 extern template class rbd::mirror::RemotePoolPoller<librbd::ImageCtx>;
132
133 #endif // CEPH_RBD_MIRROR_REMOTE_POOL_POLLER_H