]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/cephfs_mirror/InstanceWatcher.h
a0740009605e4ae62c9f67cd3bd7c213808b31fc
[ceph.git] / ceph / src / tools / cephfs_mirror / InstanceWatcher.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_INSTANCE_WATCHER_H
5 #define CEPHFS_MIRROR_INSTANCE_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
16 namespace cephfs {
17 namespace mirror {
18
19 // watch directory update notifications via per daemon rados
20 // object and invoke listener callback.
21
22 class InstanceWatcher : public Watcher {
23 public:
24 struct Listener {
25 virtual ~Listener() {
26 }
27
28 virtual void acquire_directory(std::string_view dir_path) = 0;
29 virtual void release_directory(std::string_view dir_path) = 0;
30 };
31
32 static InstanceWatcher *create(librados::IoCtx &ioctx,
33 Listener &listener, ContextWQ *work_queue) {
34 return new InstanceWatcher(ioctx, listener, work_queue);
35 }
36
37 InstanceWatcher(librados::IoCtx &ioctx, Listener &listener, ContextWQ *work_queue);
38 ~InstanceWatcher();
39
40 void init(Context *on_finish);
41 void shutdown(Context *on_finish);
42
43 void handle_notify(uint64_t notify_id, uint64_t handle,
44 uint64_t notifier_id, bufferlist& bl) override;
45 void handle_rewatch_complete(int r) override;
46
47 bool is_blocklisted() {
48 std::scoped_lock locker(m_lock);
49 return m_blocklisted;
50 }
51
52 utime_t get_blocklisted_ts() {
53 std::scoped_lock locker(m_lock);
54 return m_blocklisted_ts;
55 }
56
57 bool is_failed() {
58 std::scoped_lock locker(m_lock);
59 return m_failed;
60 }
61
62 utime_t get_failed_ts() {
63 std::scoped_lock locker(m_lock);
64 return m_failed_ts;
65 }
66
67 private:
68 librados::IoCtx &m_ioctx;
69 Listener &m_listener;
70 ContextWQ *m_work_queue;
71
72 ceph::mutex m_lock;
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 create_instance();
83 void handle_create_instance(int r);
84
85 void register_watcher();
86 void handle_register_watcher(int r);
87
88 void remove_instance();
89 void handle_remove_instance(int r);
90
91 void unregister_watcher();
92 void handle_unregister_watcher(int r);
93 };
94
95 } // namespace mirror
96 } // namespace cephfs
97
98 #endif // CEPHFS_MIRROR_INSTANCE_WATCHER_H