]> git.proxmox.com Git - ceph.git/blob - ceph/src/rbd_replay/rbd-replay.cc
bump version to 18.2.4-pve3
[ceph.git] / ceph / src / rbd_replay / rbd-replay.cc
1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
3 /*
4 * Ceph - scalable distributed file system
5 *
6 * Copyright (C) 2014 Adam Crume <adamcrume@gmail.com>
7 *
8 * This is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License version 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
12 *
13 */
14
15 #include <vector>
16 #include <boost/thread.hpp>
17 #include "common/ceph_argparse.h"
18 #include "global/global_init.h"
19 #include "Replayer.hpp"
20 #include "rbd_replay_debug.hpp"
21 #include "ImageNameMap.hpp"
22
23 using namespace std;
24 using namespace rbd_replay;
25
26
27 static const char* get_remainder(const char *string, const char *prefix) {
28 while (*prefix) {
29 if (*prefix++ != *string++) {
30 return NULL;
31 }
32 }
33 return string;
34 }
35
36 static void usage(const char* program) {
37 cout << "Usage: " << program << " --conf=<config_file> <replay_file>" << std::endl;
38 cout << "Options:" << std::endl;
39 cout << " -p, --pool-name <pool> Name of the pool to use. Default: rbd" << std::endl;
40 cout << " --latency-multiplier <float> Multiplies inter-request latencies. Default: 1" << std::endl;
41 cout << " --read-only Only perform non-destructive operations." << std::endl;
42 cout << " --map-image <rule> Add a rule to map image names in the trace to" << std::endl;
43 cout << " image names in the replay cluster." << std::endl;
44 cout << " --dump-perf-counters *Experimental*" << std::endl;
45 cout << " Dump performance counters to standard out before" << std::endl;
46 cout << " an image is closed. Performance counters may be dumped" << std::endl;
47 cout << " multiple times if multiple images are closed, or if" << std::endl;
48 cout << " the same image is opened and closed multiple times." << std::endl;
49 cout << " Performance counters and their meaning may change between" << std::endl;
50 cout << " versions." << std::endl;
51 cout << std::endl;
52 cout << "Image mapping rules:" << std::endl;
53 cout << "A rule of image1@snap1=image2@snap2 would map snap1 of image1 to snap2 of" << std::endl;
54 cout << "image2." << std::endl;
55 }
56
57 int main(int argc, const char **argv) {
58 auto args = argv_to_vec(argc, argv);
59 if (args.empty()) {
60 cerr << argv[0] << ": -h or --help for usage" << std::endl;
61 exit(1);
62 }
63 if (ceph_argparse_need_usage(args)) {
64 usage(argv[0]);
65 exit(0);
66 }
67 auto cct = global_init(NULL, args, CEPH_ENTITY_TYPE_CLIENT,
68 CODE_ENVIRONMENT_UTILITY, 0);
69
70 std::vector<const char*>::iterator i;
71 string pool_name;
72 float latency_multiplier = 1;
73 bool readonly = false;
74 ImageNameMap image_name_map;
75 std::string val;
76 std::ostringstream err;
77 bool dump_perf_counters = false;
78 for (i = args.begin(); i != args.end(); ) {
79 if (ceph_argparse_double_dash(args, i)) {
80 break;
81 } else if (ceph_argparse_witharg(args, i, &val, "-p", "--pool", (char*)NULL)) {
82 pool_name = val;
83 } else if (ceph_argparse_witharg(args, i, &latency_multiplier, err, "--latency-multiplier",
84 (char*)NULL)) {
85 if (!err.str().empty()) {
86 cerr << err.str() << std::endl;
87 return 1;
88 }
89 } else if (ceph_argparse_flag(args, i, "--read-only", (char*)NULL)) {
90 readonly = true;
91 } else if (ceph_argparse_witharg(args, i, &val, "--map-image", (char*)NULL)) {
92 ImageNameMap::Mapping mapping;
93 if (image_name_map.parse_mapping(val, &mapping)) {
94 image_name_map.add_mapping(mapping);
95 } else {
96 cerr << "Unable to parse mapping string: '" << val << "'" << std::endl;
97 return 1;
98 }
99 } else if (ceph_argparse_flag(args, i, "--dump-perf-counters", (char*)NULL)) {
100 dump_perf_counters = true;
101 } else if (get_remainder(*i, "-")) {
102 cerr << "Unrecognized argument: " << *i << std::endl;
103 return 1;
104 } else {
105 ++i;
106 }
107 }
108
109 common_init_finish(g_ceph_context);
110
111 string replay_file;
112 if (!args.empty()) {
113 replay_file = args[0];
114 }
115
116 if (replay_file.empty()) {
117 cerr << "No replay file specified." << std::endl;
118 return 1;
119 }
120
121 unsigned int nthreads = boost::thread::hardware_concurrency();
122 Replayer replayer(2 * nthreads + 1);
123 replayer.set_latency_multiplier(latency_multiplier);
124 replayer.set_pool_name(pool_name);
125 replayer.set_readonly(readonly);
126 replayer.set_image_name_map(image_name_map);
127 replayer.set_dump_perf_counters(dump_perf_counters);
128 replayer.run(replay_file);
129 }