]> git.proxmox.com Git - ceph.git/blame - ceph/src/tools/rbd_mirror/main.cc
bump version to 18.2.2-pve1
[ceph.git] / ceph / src / tools / rbd_mirror / main.cc
CommitLineData
7c673cae
FG
1// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2// vim: ts=8 sw=2 smarttab
3
4#include "common/ceph_argparse.h"
5#include "common/config.h"
6#include "common/debug.h"
7#include "common/errno.h"
11fdf7f2 8#include "common/perf_counters.h"
7c673cae
FG
9#include "global/global_init.h"
10#include "global/signal_handler.h"
11#include "Mirror.h"
11fdf7f2 12#include "Types.h"
7c673cae
FG
13
14#include <vector>
15
16rbd::mirror::Mirror *mirror = nullptr;
522d829b
TL
17PerfCounters *g_journal_perf_counters = nullptr;
18PerfCounters *g_snapshot_perf_counters = nullptr;
7c673cae
FG
19
20void usage() {
21 std::cout << "usage: rbd-mirror [options...]" << std::endl;
22 std::cout << "options:\n";
23 std::cout << " -m monaddress[:port] connect to specified monitor\n";
24 std::cout << " --keyring=<path> path to keyring for local cluster\n";
25 std::cout << " --log-file=<logfile> file to log debug output\n";
26 std::cout << " --debug-rbd-mirror=<log-level>/<memory-level> set rbd-mirror debug level\n";
27 generic_server_usage();
28}
29
30static void handle_signal(int signum)
31{
32 if (mirror)
33 mirror->handle_signal(signum);
34}
35
36int main(int argc, const char **argv)
37{
20effc67 38 auto args = argv_to_vec(argc, argv);
11fdf7f2 39 if (args.empty()) {
20effc67 40 std::cerr << argv[0] << ": -h or --help for usage" << std::endl;
11fdf7f2
TL
41 exit(1);
42 }
43 if (ceph_argparse_need_usage(args)) {
44 usage();
45 exit(0);
46 }
7c673cae
FG
47
48 auto cct = global_init(nullptr, args, CEPH_ENTITY_TYPE_CLIENT,
49 CODE_ENVIRONMENT_DAEMON,
50 CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS);
51
11fdf7f2 52 if (g_conf()->daemonize) {
7c673cae
FG
53 global_init_daemonize(g_ceph_context);
54 }
7c673cae
FG
55
56 common_init_finish(g_ceph_context);
57
58 init_async_signal_handler();
92f5a8d4 59 register_async_signal_handler(SIGHUP, handle_signal);
7c673cae
FG
60 register_async_signal_handler_oneshot(SIGINT, handle_signal);
61 register_async_signal_handler_oneshot(SIGTERM, handle_signal);
62
20effc67 63 auto cmd_args = argv_to_vec(argc, argv);
7c673cae
FG
64
65 // disable unnecessary librbd cache
11fdf7f2
TL
66 g_ceph_context->_conf.set_val_or_die("rbd_cache", "false");
67
68 auto prio =
69 g_ceph_context->_conf.get_val<int64_t>("rbd_mirror_perf_stats_prio");
522d829b 70 {
1e59de90 71 PerfCountersBuilder plb(g_ceph_context, "rbd_mirror_journal",
522d829b
TL
72 rbd::mirror::l_rbd_mirror_journal_first,
73 rbd::mirror::l_rbd_mirror_journal_last);
1e59de90
TL
74 plb.add_u64_counter(rbd::mirror::l_rbd_mirror_journal_entries, "entries",
75 "Number of entries replayed", nullptr, prio);
76 plb.add_u64_counter(rbd::mirror::l_rbd_mirror_journal_replay_bytes,
77 "replay_bytes", "Total bytes replayed", nullptr, prio,
78 unit_t(UNIT_BYTES));
79 plb.add_time_avg(rbd::mirror::l_rbd_mirror_journal_replay_latency,
80 "replay_latency", "Replay latency", nullptr, prio);
522d829b
TL
81 g_journal_perf_counters = plb.create_perf_counters();
82 }
83 {
1e59de90
TL
84 PerfCountersBuilder plb(
85 g_ceph_context, "rbd_mirror_snapshot",
86 rbd::mirror::l_rbd_mirror_snapshot_first,
87 rbd::mirror::l_rbd_mirror_snapshot_remote_timestamp);
88 plb.add_u64_counter(rbd::mirror::l_rbd_mirror_snapshot_snapshots,
89 "snapshots", "Number of snapshots synced", nullptr,
90 prio);
91 plb.add_time_avg(rbd::mirror::l_rbd_mirror_snapshot_sync_time, "sync_time",
92 "Average sync time", nullptr, prio);
93 plb.add_u64_counter(rbd::mirror::l_rbd_mirror_snapshot_sync_bytes,
94 "sync_bytes", "Total bytes synced", nullptr, prio,
522d829b
TL
95 unit_t(UNIT_BYTES));
96 g_snapshot_perf_counters = plb.create_perf_counters();
97 }
98 g_ceph_context->get_perfcounters_collection()->add(g_journal_perf_counters);
99 g_ceph_context->get_perfcounters_collection()->add(g_snapshot_perf_counters);
7c673cae
FG
100
101 mirror = new rbd::mirror::Mirror(g_ceph_context, cmd_args);
102 int r = mirror->init();
103 if (r < 0) {
104 std::cerr << "failed to initialize: " << cpp_strerror(r) << std::endl;
105 goto cleanup;
106 }
107
108 mirror->run();
109
110 cleanup:
92f5a8d4 111 unregister_async_signal_handler(SIGHUP, handle_signal);
7c673cae
FG
112 unregister_async_signal_handler(SIGINT, handle_signal);
113 unregister_async_signal_handler(SIGTERM, handle_signal);
114 shutdown_async_signal_handler();
115
522d829b
TL
116 g_ceph_context->get_perfcounters_collection()->remove(g_journal_perf_counters);
117 g_ceph_context->get_perfcounters_collection()->remove(g_snapshot_perf_counters);
11fdf7f2 118
7c673cae 119 delete mirror;
522d829b
TL
120 delete g_journal_perf_counters;
121 delete g_snapshot_perf_counters;
7c673cae 122
1e59de90 123 return r < 0 ? EXIT_FAILURE : EXIT_SUCCESS;
7c673cae 124}