]>
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 "tools/rbd/ArgumentTypes.h" | |
5 | #include "tools/rbd/Shell.h" | |
6 | #include "tools/rbd/Utils.h" | |
7 | #include "common/errno.h" | |
8 | #include <iostream> | |
9 | #include <boost/program_options.hpp> | |
10 | ||
11 | namespace rbd { | |
12 | namespace action { | |
13 | namespace object_map { | |
14 | ||
15 | namespace at = argument_types; | |
16 | namespace po = boost::program_options; | |
17 | ||
18 | static int do_object_map_rebuild(librbd::Image &image, bool no_progress) | |
19 | { | |
20 | utils::ProgressContext pc("Object Map Rebuild", no_progress); | |
21 | int r = image.rebuild_object_map(pc); | |
22 | if (r < 0) { | |
23 | pc.fail(); | |
24 | return r; | |
25 | } | |
26 | pc.finish(); | |
27 | return 0; | |
28 | } | |
29 | ||
30 | void get_rebuild_arguments(po::options_description *positional, | |
31 | po::options_description *options) { | |
32 | at::add_image_or_snap_spec_options(positional, options, | |
33 | at::ARGUMENT_MODIFIER_NONE); | |
34 | at::add_no_progress_option(options); | |
35 | } | |
36 | ||
11fdf7f2 TL |
37 | int execute_rebuild(const po::variables_map &vm, |
38 | const std::vector<std::string> &ceph_global_init_args) { | |
7c673cae FG |
39 | size_t arg_index = 0; |
40 | std::string pool_name; | |
11fdf7f2 | 41 | std::string namespace_name; |
7c673cae FG |
42 | std::string image_name; |
43 | std::string snap_name; | |
44 | int r = utils::get_pool_image_snapshot_names( | |
11fdf7f2 TL |
45 | vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &namespace_name, |
46 | &image_name, &snap_name, true, utils::SNAPSHOT_PRESENCE_PERMITTED, | |
7c673cae FG |
47 | utils::SPEC_VALIDATION_NONE); |
48 | if (r < 0) { | |
49 | return r; | |
50 | } | |
51 | ||
52 | librados::Rados rados; | |
53 | librados::IoCtx io_ctx; | |
54 | librbd::Image image; | |
11fdf7f2 TL |
55 | r = utils::init_and_open_image(pool_name, namespace_name, image_name, "", |
56 | snap_name, false, &rados, &io_ctx, &image); | |
7c673cae FG |
57 | if (r < 0) { |
58 | return r; | |
59 | } | |
60 | ||
61 | r = do_object_map_rebuild(image, vm[at::NO_PROGRESS].as<bool>()); | |
62 | if (r < 0) { | |
63 | std::cerr << "rbd: rebuilding object map failed: " << cpp_strerror(r) | |
64 | << std::endl; | |
65 | return r; | |
66 | } | |
67 | return 0; | |
68 | } | |
69 | ||
70 | static int do_object_map_check(librbd::Image &image, bool no_progress) | |
71 | { | |
72 | utils::ProgressContext pc("Object Map Check", no_progress); | |
73 | int r = image.check_object_map(pc); | |
74 | if (r < 0) { | |
75 | pc.fail(); | |
76 | return r; | |
77 | } | |
78 | pc.finish(); | |
79 | return 0; | |
80 | } | |
81 | ||
82 | void get_check_arguments(po::options_description *positional, | |
83 | po::options_description *options) { | |
84 | at::add_image_or_snap_spec_options(positional, options, | |
85 | at::ARGUMENT_MODIFIER_NONE); | |
86 | at::add_no_progress_option(options); | |
87 | } | |
88 | ||
11fdf7f2 TL |
89 | int execute_check(const po::variables_map &vm, |
90 | const std::vector<std::string> &ceph_global_init_args) { | |
7c673cae FG |
91 | size_t arg_index = 0; |
92 | std::string pool_name; | |
11fdf7f2 | 93 | std::string namespace_name; |
7c673cae FG |
94 | std::string image_name; |
95 | std::string snap_name; | |
96 | int r = utils::get_pool_image_snapshot_names( | |
11fdf7f2 TL |
97 | vm, at::ARGUMENT_MODIFIER_NONE, &arg_index, &pool_name, &namespace_name, |
98 | &image_name, &snap_name, true, utils::SNAPSHOT_PRESENCE_PERMITTED, | |
7c673cae FG |
99 | utils::SPEC_VALIDATION_NONE); |
100 | if (r < 0) { | |
101 | return r; | |
102 | } | |
103 | ||
104 | librados::Rados rados; | |
105 | librados::IoCtx io_ctx; | |
106 | librbd::Image image; | |
11fdf7f2 TL |
107 | r = utils::init_and_open_image(pool_name, namespace_name, image_name, "", |
108 | snap_name, false, &rados, &io_ctx, &image); | |
7c673cae FG |
109 | if (r < 0) { |
110 | return r; | |
111 | } | |
112 | ||
113 | r = do_object_map_check(image, vm[at::NO_PROGRESS].as<bool>()); | |
114 | if (r < 0) { | |
115 | std::cerr << "rbd: checking object map failed: " << cpp_strerror(r) | |
116 | << std::endl; | |
117 | return r; | |
118 | } | |
119 | return 0; | |
120 | } | |
121 | ||
122 | Shell::Action action_rebuild( | |
123 | {"object-map", "rebuild"}, {}, "Rebuild an invalid object map.", "", | |
124 | &get_rebuild_arguments, &execute_rebuild); | |
125 | Shell::Action action_check( | |
126 | {"object-map", "check"}, {}, "Verify the object map is correct.", "", | |
127 | &get_check_arguments, &execute_check); | |
128 | ||
129 | } // namespace object_map | |
130 | } // namespace action | |
131 | } // namespace rbd |