]> git.proxmox.com Git - ceph.git/blob - ceph/src/tools/cephfs_mirror/InstanceWatcher.h
add stop-gap to fix compat with CPUs not supporting SSE 4.1
[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 bool is_failed() {
53 std::scoped_lock locker(m_lock);
54 return m_failed;
55 }
56
57 private:
58 librados::IoCtx &m_ioctx;
59 Listener &m_listener;
60 ContextWQ *m_work_queue;
61
62 ceph::mutex m_lock;
63 Context *m_on_init_finish = nullptr;
64 Context *m_on_shutdown_finish = nullptr;
65
66 bool m_blocklisted = false;
67 bool m_failed = false;
68
69 void create_instance();
70 void handle_create_instance(int r);
71
72 void register_watcher();
73 void handle_register_watcher(int r);
74
75 void remove_instance();
76 void handle_remove_instance(int r);
77
78 void unregister_watcher();
79 void handle_unregister_watcher(int r);
80 };
81
82 } // namespace mirror
83 } // namespace cephfs
84
85 #endif // CEPHFS_MIRROR_INSTANCE_WATCHER_H