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 std::list
<Context
*> action_ctxs
;
81 std::unique_ptr
<FSMirror
> fs_mirror
;
84 ceph::mutex m_lock
= ceph::make_mutex("cephfs::mirror::Mirror");
85 ceph::condition_variable m_cond
;
88 std::vector
<const char *> m_args
;
91 ClusterListener m_listener
;
93 ThreadPool
*m_thread_pool
= nullptr;
94 ContextWQ
*m_work_queue
= nullptr;
95 SafeTimer
*m_timer
= nullptr;
96 ceph::mutex
*m_timer_lock
= nullptr;
97 Context
*m_timer_task
= nullptr;
99 bool m_stopping
= false;
100 std::unique_ptr
<ClusterWatcher
> m_cluster_watcher
;
101 std::map
<Filesystem
, MirrorAction
> m_mirror_actions
;
103 utime_t m_last_blocklist_check
;
104 utime_t m_last_failure_check
;
107 std::unique_ptr
<ServiceDaemon
> m_service_daemon
;
109 int init_mon_client();
111 // called via listener
112 void mirroring_enabled(const Filesystem
&filesystem
, uint64_t local_pool_id
);
113 void mirroring_disabled(const Filesystem
&filesystem
);
114 void peer_added(const Filesystem
&filesystem
, const Peer
&peer
);
115 void peer_removed(const Filesystem
&filesystem
, const Peer
&peer
);
117 // mirror enable callback
118 void enable_mirroring(const Filesystem
&filesystem
, uint64_t local_pool_id
,
119 Context
*on_finish
, bool is_restart
=false);
120 void handle_enable_mirroring(const Filesystem
&filesystem
, int r
);
121 void handle_enable_mirroring(const Filesystem
&filesystem
, const Peers
&peers
, int r
);
123 // mirror disable callback
124 void disable_mirroring(const Filesystem
&filesystem
, Context
*on_finish
);
125 void handle_disable_mirroring(const Filesystem
&filesystem
, int r
);
127 // peer update callback
128 void add_peer(const Filesystem
&filesystem
, const Peer
&peer
);
129 void remove_peer(const Filesystem
&filesystem
, const Peer
&peer
);
131 void schedule_mirror_update_task();
132 void update_fs_mirrors();
137 } // namespace mirror
138 } // namespace cephfs
140 #endif // CEPHFS_MIRROR_H