]>
Commit | Line | Data |
---|---|---|
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 | ||
16 | rbd::mirror::Mirror *mirror = nullptr; | |
dc7c3f34 TL |
17 | PerfCounters *g_journal_perf_counters = nullptr; |
18 | PerfCounters *g_snapshot_perf_counters = nullptr; | |
7c673cae FG |
19 | |
20 | void 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 | ||
30 | static void handle_signal(int signum) | |
31 | { | |
32 | if (mirror) | |
33 | mirror->handle_signal(signum); | |
34 | } | |
35 | ||
36 | int main(int argc, const char **argv) | |
37 | { | |
38 | std::vector<const char*> args; | |
7c673cae | 39 | argv_to_vec(argc, argv, args); |
11fdf7f2 TL |
40 | if (args.empty()) { |
41 | cerr << argv[0] << ": -h or --help for usage" << std::endl; | |
42 | exit(1); | |
43 | } | |
44 | if (ceph_argparse_need_usage(args)) { | |
45 | usage(); | |
46 | exit(0); | |
47 | } | |
7c673cae FG |
48 | |
49 | auto cct = global_init(nullptr, args, CEPH_ENTITY_TYPE_CLIENT, | |
50 | CODE_ENVIRONMENT_DAEMON, | |
51 | CINIT_FLAG_UNPRIVILEGED_DAEMON_DEFAULTS); | |
52 | ||
11fdf7f2 | 53 | if (g_conf()->daemonize) { |
7c673cae FG |
54 | global_init_daemonize(g_ceph_context); |
55 | } | |
7c673cae FG |
56 | |
57 | common_init_finish(g_ceph_context); | |
58 | ||
59 | init_async_signal_handler(); | |
92f5a8d4 | 60 | register_async_signal_handler(SIGHUP, handle_signal); |
7c673cae FG |
61 | register_async_signal_handler_oneshot(SIGINT, handle_signal); |
62 | register_async_signal_handler_oneshot(SIGTERM, handle_signal); | |
63 | ||
64 | std::vector<const char*> cmd_args; | |
65 | argv_to_vec(argc, argv, cmd_args); | |
66 | ||
67 | // disable unnecessary librbd cache | |
11fdf7f2 TL |
68 | g_ceph_context->_conf.set_val_or_die("rbd_cache", "false"); |
69 | ||
70 | auto prio = | |
71 | g_ceph_context->_conf.get_val<int64_t>("rbd_mirror_perf_stats_prio"); | |
dc7c3f34 TL |
72 | { |
73 | PerfCountersBuilder plb(g_ceph_context, "rbd_mirror", | |
74 | rbd::mirror::l_rbd_mirror_journal_first, | |
75 | rbd::mirror::l_rbd_mirror_journal_last); | |
76 | plb.add_u64_counter(rbd::mirror::l_rbd_mirror_replay, "replay", "Replays", | |
77 | "r", prio); | |
78 | plb.add_u64_counter(rbd::mirror::l_rbd_mirror_replay_bytes, "replay_bytes", | |
79 | "Replayed data", "rb", prio, unit_t(UNIT_BYTES)); | |
80 | plb.add_time_avg(rbd::mirror::l_rbd_mirror_replay_latency, "replay_latency", | |
81 | "Replay latency", "rl", prio); | |
82 | g_journal_perf_counters = plb.create_perf_counters(); | |
83 | } | |
84 | { | |
85 | PerfCountersBuilder plb(g_ceph_context, "rbd_mirror_snapshot", | |
86 | rbd::mirror::l_rbd_mirror_snapshot_first, | |
87 | rbd::mirror::l_rbd_mirror_snapshot_last); | |
88 | plb.add_u64_counter(rbd::mirror::l_rbd_mirror_snapshot_replay_snapshots, | |
89 | "snapshots", "Snapshots", "r", prio); | |
90 | plb.add_time_avg(rbd::mirror::l_rbd_mirror_snapshot_replay_snapshots_time, | |
91 | "snapshots_time", "Snapshots time", "rl", prio); | |
92 | plb.add_u64_counter(rbd::mirror::l_rbd_mirror_snapshot_replay_bytes, | |
93 | "replay_bytes", "Replayed data", "rb", prio, | |
94 | unit_t(UNIT_BYTES)); | |
95 | g_snapshot_perf_counters = plb.create_perf_counters(); | |
96 | } | |
97 | g_ceph_context->get_perfcounters_collection()->add(g_journal_perf_counters); | |
98 | g_ceph_context->get_perfcounters_collection()->add(g_snapshot_perf_counters); | |
7c673cae FG |
99 | |
100 | mirror = new rbd::mirror::Mirror(g_ceph_context, cmd_args); | |
101 | int r = mirror->init(); | |
102 | if (r < 0) { | |
103 | std::cerr << "failed to initialize: " << cpp_strerror(r) << std::endl; | |
104 | goto cleanup; | |
105 | } | |
106 | ||
107 | mirror->run(); | |
108 | ||
109 | cleanup: | |
92f5a8d4 | 110 | unregister_async_signal_handler(SIGHUP, handle_signal); |
7c673cae FG |
111 | unregister_async_signal_handler(SIGINT, handle_signal); |
112 | unregister_async_signal_handler(SIGTERM, handle_signal); | |
113 | shutdown_async_signal_handler(); | |
114 | ||
dc7c3f34 TL |
115 | g_ceph_context->get_perfcounters_collection()->remove(g_journal_perf_counters); |
116 | g_ceph_context->get_perfcounters_collection()->remove(g_snapshot_perf_counters); | |
11fdf7f2 | 117 | |
7c673cae | 118 | delete mirror; |
dc7c3f34 TL |
119 | delete g_journal_perf_counters; |
120 | delete g_snapshot_perf_counters; | |
7c673cae FG |
121 | |
122 | return r < 0 ? EXIT_SUCCESS : EXIT_FAILURE; | |
123 | } |