1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 #ifndef CEPHFS_MIRROR_H
5 #define CEPHFS_MIRROR_H
11 #include "common/ceph_mutex.h"
12 #include "common/WorkQueue.h"
13 #include "mds/FSMap.h"
14 #include "ClusterWatcher.h"
16 #include "ServiceDaemon.h"
26 // this wraps up ClusterWatcher and FSMirrors to implement mirroring
27 // for ceph filesystems.
31 Mirror(CephContext
*cct
, const std::vector
<const char*> &args
,
32 MonClient
*monc
, Messenger
*msgr
);
35 int init(std::string
&reason
);
39 void handle_signal(int signum
);
42 static constexpr std::string_view MIRRORING_MODULE
= "mirroring";
44 struct C_EnableMirroring
;
45 struct C_DisableMirroring
;
47 struct C_RestartMirroring
;
49 struct ClusterListener
: ClusterWatcher::Listener
{
52 ClusterListener(Mirror
*mirror
)
56 void handle_mirroring_enabled(const FilesystemSpec
&spec
) override
{
57 mirror
->mirroring_enabled(spec
.filesystem
, spec
.pool_id
);
60 void handle_mirroring_disabled(const Filesystem
&filesystem
) override
{
61 mirror
->mirroring_disabled(filesystem
);
64 void handle_peers_added(const Filesystem
&filesystem
, const Peer
&peer
) override
{
65 mirror
->peer_added(filesystem
, peer
);
68 void handle_peers_removed(const Filesystem
&filesystem
, const Peer
&peer
) override
{
69 mirror
->peer_removed(filesystem
, peer
);
74 MirrorAction(uint64_t pool_id
) :
78 uint64_t pool_id
; // for restarting blocklisted mirror instance
79 bool action_in_progress
= false;
80 bool restarting
= false;
81 std::list
<Context
*> action_ctxs
;
82 std::unique_ptr
<FSMirror
> fs_mirror
;
85 ceph::mutex m_lock
= ceph::make_mutex("cephfs::mirror::Mirror");
86 ceph::condition_variable m_cond
;
89 std::vector
<const char *> m_args
;
92 ClusterListener m_listener
;
94 ThreadPool
*m_thread_pool
= nullptr;
95 ContextWQ
*m_work_queue
= nullptr;
96 SafeTimer
*m_timer
= nullptr;
97 ceph::mutex
*m_timer_lock
= nullptr;
98 Context
*m_timer_task
= nullptr;
100 bool m_stopping
= false;
101 std::unique_ptr
<ClusterWatcher
> m_cluster_watcher
;
102 std::map
<Filesystem
, MirrorAction
> m_mirror_actions
;
105 std::unique_ptr
<ServiceDaemon
> m_service_daemon
;
107 int init_mon_client();
109 // called via listener
110 void mirroring_enabled(const Filesystem
&filesystem
, uint64_t local_pool_id
);
111 void mirroring_disabled(const Filesystem
&filesystem
);
112 void peer_added(const Filesystem
&filesystem
, const Peer
&peer
);
113 void peer_removed(const Filesystem
&filesystem
, const Peer
&peer
);
115 // mirror enable callback
116 void enable_mirroring(const Filesystem
&filesystem
, uint64_t local_pool_id
,
117 Context
*on_finish
, bool is_restart
=false);
118 void handle_enable_mirroring(const Filesystem
&filesystem
, int r
);
119 void handle_enable_mirroring(const Filesystem
&filesystem
, const Peers
&peers
, int r
);
121 // mirror disable callback
122 void disable_mirroring(const Filesystem
&filesystem
, Context
*on_finish
);
123 void handle_disable_mirroring(const Filesystem
&filesystem
, int r
);
125 // peer update callback
126 void add_peer(const Filesystem
&filesystem
, const Peer
&peer
);
127 void remove_peer(const Filesystem
&filesystem
, const Peer
&peer
);
129 void schedule_mirror_update_task();
130 void update_fs_mirrors();
134 void _set_restarting(const Filesystem
&filesystem
) {
135 auto &mirror_action
= m_mirror_actions
.at(filesystem
);
136 mirror_action
.restarting
= true;
139 void _unset_restarting(const Filesystem
&filesystem
) {
140 auto &mirror_action
= m_mirror_actions
.at(filesystem
);
141 mirror_action
.restarting
= false;
144 bool _is_restarting(const Filesystem
&filesystem
) {
145 auto &mirror_action
= m_mirror_actions
.at(filesystem
);
146 return mirror_action
.restarting
;
150 } // namespace mirror
151 } // namespace cephfs
153 #endif // CEPHFS_MIRROR_H