]> git.proxmox.com Git - ceph.git/blame - ceph/src/tools/cephfs_mirror/MirrorWatcher.h
import quincy beta 17.1.0
[ceph.git] / ceph / src / tools / cephfs_mirror / MirrorWatcher.h
CommitLineData
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_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
14class ContextWQ;
15class Messenger;
16
17namespace cephfs {
18namespace mirror {
19
20class 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
27class MirrorWatcher : public Watcher {
28public:
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 bool is_failed() {
51 std::scoped_lock locker(m_lock);
52 return m_failed;
53 }
54
55private:
56 librados::IoCtx &m_ioctx;
57 FSMirror *m_fs_mirror;
58 ContextWQ *m_work_queue;
59
60 ceph::mutex m_lock;
61 std::string m_instance_id;
62
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 register_watcher();
70 void handle_register_watcher(int r);
71
72 void unregister_watcher();
73 void handle_unregister_watcher(int r);
74};
75
76} // namespace mirror
77} // namespace cephfs
78
79#endif // CEPHFS_MIRROR_MIRROR_WATCHER_H