]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/cephfs_mirror/MirrorWatcher.h
update ceph source to reef 18.2.1
[ceph.git] / ceph / src / tools / cephfs_mirror / MirrorWatcher.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 CEPHFS_MIRROR_MIRROR_WATCHER_H
5 #define CEPHFS_MIRROR_MIRROR_WATCHER_H
6
7 #include <string_view>
8
9 #include "common/ceph_mutex.h"
10 #include "include/Context.h"
11 #include "include/rados/librados.hpp"
12 #include "Watcher.h"
13
14 class ContextWQ;
15 class Messenger;
16
17 namespace cephfs {
18 namespace mirror {
19
20 class FSMirror;
21
22 // watch for notifications via cephfs_mirror object (in metadata
23 // pool). this is used sending keepalived with keepalive payload
24 // being the rados instance address (used by the manager module
25 // to blocklist when needed).
26
27 class MirrorWatcher : public Watcher {
28 public:
29 static MirrorWatcher *create(librados::IoCtx &ioctx, FSMirror *fs_mirror,
30 ContextWQ *work_queue) {
31 return new MirrorWatcher(ioctx, fs_mirror, work_queue);
32 }
33
34 MirrorWatcher(librados::IoCtx &ioctx, FSMirror *fs_mirror,
35 ContextWQ *work_queue);
36 ~MirrorWatcher();
37
38 void init(Context *on_finish);
39 void shutdown(Context *on_finish);
40
41 void handle_notify(uint64_t notify_id, uint64_t handle,
42 uint64_t notifier_id, bufferlist& bl) override;
43 void handle_rewatch_complete(int r) override;
44
45 bool is_blocklisted() {
46 std::scoped_lock locker(m_lock);
47 return m_blocklisted;
48 }
49
50 utime_t get_blocklisted_ts() {
51 std::scoped_lock locker(m_lock);
52 return m_blocklisted_ts;
53 }
54
55 bool is_failed() {
56 std::scoped_lock locker(m_lock);
57 return m_failed;
58 }
59
60 utime_t get_failed_ts() {
61 std::scoped_lock locker(m_lock);
62 return m_failed_ts;
63 }
64
65 private:
66 librados::IoCtx &m_ioctx;
67 FSMirror *m_fs_mirror;
68 ContextWQ *m_work_queue;
69
70 ceph::mutex m_lock;
71 std::string m_instance_id;
72
73 Context *m_on_init_finish = nullptr;
74 Context *m_on_shutdown_finish = nullptr;
75
76 bool m_blocklisted = false;
77 bool m_failed = false;
78
79 utime_t m_blocklisted_ts;
80 utime_t m_failed_ts;
81
82 void register_watcher();
83 void handle_register_watcher(int r);
84
85 void unregister_watcher();
86 void handle_unregister_watcher(int r);
87 };
88
89 } // namespace mirror
90 } // namespace cephfs
91
92 #endif // CEPHFS_MIRROR_MIRROR_WATCHER_H