]>
Commit | Line | Data |
---|---|---|
f67539c2 TL |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | ||
4 | #ifndef CEPHFS_MIRROR_FS_MIRROR_H | |
5 | #define CEPHFS_MIRROR_FS_MIRROR_H | |
6 | ||
7 | #include "common/Formatter.h" | |
8 | #include "common/Thread.h" | |
9 | #include "mds/FSMap.h" | |
10 | #include "Types.h" | |
11 | #include "InstanceWatcher.h" | |
12 | #include "MirrorWatcher.h" | |
13 | ||
14 | class ContextWQ; | |
15 | ||
16 | namespace cephfs { | |
17 | namespace mirror { | |
18 | ||
19 | class MirrorAdminSocketHook; | |
20 | class PeerReplayer; | |
21 | class ServiceDaemon; | |
22 | ||
23 | // handle mirroring for a filesystem to a set of peers | |
24 | ||
25 | class FSMirror { | |
26 | public: | |
27 | FSMirror(CephContext *cct, const Filesystem &filesystem, uint64_t pool_id, | |
28 | ServiceDaemon *service_daemon, std::vector<const char*> args, | |
29 | ContextWQ *work_queue); | |
30 | ~FSMirror(); | |
31 | ||
32 | void init(Context *on_finish); | |
33 | void shutdown(Context *on_finish); | |
34 | ||
35 | void add_peer(const Peer &peer); | |
36 | void remove_peer(const Peer &peer); | |
37 | ||
38 | bool is_stopping() { | |
39 | std::scoped_lock locker(m_lock); | |
40 | return m_stopping; | |
41 | } | |
42 | ||
43 | bool is_init_failed() { | |
44 | std::scoped_lock locker(m_lock); | |
45 | return m_init_failed; | |
46 | } | |
47 | ||
48 | bool is_failed() { | |
49 | std::scoped_lock locker(m_lock); | |
50 | return m_init_failed || | |
51 | m_instance_watcher->is_failed() || | |
52 | m_mirror_watcher->is_failed(); | |
53 | } | |
54 | ||
55 | bool is_blocklisted() { | |
56 | std::scoped_lock locker(m_lock); | |
57 | return is_blocklisted(locker); | |
58 | } | |
59 | ||
60 | Peers get_peers() { | |
61 | std::scoped_lock locker(m_lock); | |
62 | return m_all_peers; | |
63 | } | |
64 | ||
65 | std::string get_instance_addr() { | |
66 | std::scoped_lock locker(m_lock); | |
67 | return m_addrs; | |
68 | } | |
69 | ||
70 | // admin socket helpers | |
71 | void mirror_status(Formatter *f); | |
72 | ||
b3b6e05e TL |
73 | void reopen_logs(); |
74 | ||
f67539c2 TL |
75 | private: |
76 | bool is_blocklisted(const std::scoped_lock<ceph::mutex> &locker) const { | |
77 | bool blocklisted = false; | |
78 | if (m_instance_watcher) { | |
79 | blocklisted = m_instance_watcher->is_blocklisted(); | |
80 | } | |
81 | if (m_mirror_watcher) { | |
82 | blocklisted |= m_mirror_watcher->is_blocklisted(); | |
83 | } | |
84 | ||
85 | return blocklisted; | |
86 | } | |
87 | ||
88 | struct SnapListener : public InstanceWatcher::Listener { | |
89 | FSMirror *fs_mirror; | |
90 | ||
91 | SnapListener(FSMirror *fs_mirror) | |
92 | : fs_mirror(fs_mirror) { | |
93 | } | |
94 | ||
20effc67 | 95 | void acquire_directory(std::string_view dir_path) override { |
f67539c2 TL |
96 | fs_mirror->handle_acquire_directory(dir_path); |
97 | } | |
98 | ||
20effc67 | 99 | void release_directory(std::string_view dir_path) override { |
f67539c2 TL |
100 | fs_mirror->handle_release_directory(dir_path); |
101 | } | |
102 | }; | |
103 | ||
104 | CephContext *m_cct; | |
105 | Filesystem m_filesystem; | |
106 | uint64_t m_pool_id; | |
107 | ServiceDaemon *m_service_daemon; | |
108 | std::vector<const char *> m_args; | |
109 | ContextWQ *m_work_queue; | |
110 | ||
111 | ceph::mutex m_lock = ceph::make_mutex("cephfs::mirror::fs_mirror"); | |
112 | SnapListener m_snap_listener; | |
113 | std::set<std::string, std::less<>> m_directories; | |
114 | Peers m_all_peers; | |
115 | std::map<Peer, std::unique_ptr<PeerReplayer>> m_peer_replayers; | |
116 | ||
117 | RadosRef m_cluster; | |
118 | std::string m_addrs; | |
119 | librados::IoCtx m_ioctx; | |
120 | InstanceWatcher *m_instance_watcher = nullptr; | |
121 | MirrorWatcher *m_mirror_watcher = nullptr; | |
122 | ||
123 | int m_retval = 0; | |
124 | bool m_stopping = false; | |
125 | bool m_init_failed = false; | |
126 | Context *m_on_init_finish = nullptr; | |
127 | Context *m_on_shutdown_finish = nullptr; | |
128 | ||
129 | MirrorAdminSocketHook *m_asok_hook = nullptr; | |
130 | ||
131 | MountRef m_mount; | |
132 | ||
133 | int init_replayer(PeerReplayer *peer_replayer); | |
134 | void shutdown_replayer(PeerReplayer *peer_replayer); | |
135 | void cleanup(); | |
136 | ||
137 | void init_instance_watcher(Context *on_finish); | |
138 | void handle_init_instance_watcher(int r); | |
139 | ||
140 | void init_mirror_watcher(); | |
141 | void handle_init_mirror_watcher(int r); | |
142 | ||
143 | void shutdown_peer_replayers(); | |
144 | ||
145 | void shutdown_mirror_watcher(); | |
146 | void handle_shutdown_mirror_watcher(int r); | |
147 | ||
148 | void shutdown_instance_watcher(); | |
149 | void handle_shutdown_instance_watcher(int r); | |
150 | ||
20effc67 TL |
151 | void handle_acquire_directory(std::string_view dir_path); |
152 | void handle_release_directory(std::string_view dir_path); | |
f67539c2 TL |
153 | }; |
154 | ||
155 | } // namespace mirror | |
156 | } // namespace cephfs | |
157 | ||
158 | #endif // CEPHFS_MIRROR_FS_MIRROR_H |