1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2012 Inktank, Inc.
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 kkjversion 2.1, as published by the Free Software
11 * Foundation. See file COPYING.
13 #include <boost/program_options/variables_map.hpp>
14 #include <boost/program_options/parsers.hpp>
19 #include "common/errno.h"
20 #include "global/global_init.h"
22 #include "os/filestore/DBObjectMap.h"
23 #include "kv/KeyValueDB.h"
25 namespace po
= boost::program_options
;
28 int main(int argc
, char **argv
) {
29 po::options_description
desc("Allowed options");
30 string store_path
, cmd
, oid
, backend
;
33 ("help", "produce help message")
34 ("omap-path", po::value
<string
>(&store_path
),
35 "path to mon directory, mandatory (current/omap usually)")
36 ("paranoid", "use paranoid checking")
37 ("debug", "Additional debug output from DBObjectMap")
38 ("oid", po::value
<string
>(&oid
), "Restrict to this object id when dumping objects")
39 ("command", po::value
<string
>(&cmd
),
40 "command arg is one of [dump-raw-keys, dump-raw-key-vals, dump-objects, dump-objects-with-keys, check, dump-headers, repair, compact], mandatory")
41 ("backend", po::value
<string
>(&backend
),
42 "DB backend (default rocksdb)")
44 po::positional_options_description p
;
47 vector
<string
> ceph_option_strings
;
50 po::parsed_options parsed
=
51 po::command_line_parser(argc
, argv
).options(desc
).positional(p
).allow_unregistered().run();
57 ceph_option_strings
= po::collect_unrecognized(parsed
.options
,
58 po::include_positional
);
59 } catch(po::error
&e
) {
60 std::cerr
<< e
.what() << std::endl
;
64 vector
<const char *> ceph_options
, def_args
;
65 ceph_options
.reserve(ceph_option_strings
.size());
66 for (vector
<string
>::iterator i
= ceph_option_strings
.begin();
67 i
!= ceph_option_strings
.end();
69 ceph_options
.push_back(i
->c_str());
72 if (vm
.count("debug")) debug
= true;
74 auto cct
= global_init(
75 &def_args
, ceph_options
, CEPH_ENTITY_TYPE_OSD
,
76 CODE_ENVIRONMENT_UTILITY_NODOUT
, 0);
77 common_init_finish(g_ceph_context
);
78 g_ceph_context
->_conf
->apply_changes(NULL
);
79 g_conf
= g_ceph_context
->_conf
;
81 g_conf
->set_val_or_die("log_to_stderr", "true");
82 g_conf
->set_val_or_die("err_to_stderr", "true");
84 g_conf
->apply_changes(NULL
);
86 if (vm
.count("help")) {
87 std::cerr
<< desc
<< std::endl
;
91 if (vm
.count("omap-path") == 0) {
92 std::cerr
<< "Required argument --omap-path" << std::endl
;
96 if (vm
.count("command") == 0) {
97 std::cerr
<< "Required argument --command" << std::endl
;
101 if (vm
.count("backend") == 0) {
105 KeyValueDB
* store(KeyValueDB::create(g_ceph_context
, backend
, store_path
));
107 std::cerr
<< "Invalid backend '" << backend
<< "' specified" << std::endl
;
110 /*if (vm.count("paranoid")) {
111 std::cerr << "Enabling paranoid checks" << std::endl;
112 store->options.paranoid_checks = true;
114 DBObjectMap
omap(cct
.get(), store
);
116 int r
= store
->open(out
);
118 std::cerr
<< "Store open got: " << cpp_strerror(r
) << std::endl
;
119 std::cerr
<< "Output: " << out
.str() << std::endl
;
122 // We don't call omap.init() here because it will repair
123 // the DBObjectMap which we might want to examine for diagnostic
124 // reasons. Instead use --command repair.
127 std::cout
<< "Version: " << (int)omap
.state
.v
<< std::endl
;
128 std::cout
<< "Seq: " << omap
.state
.seq
<< std::endl
;
129 std::cout
<< "legacy: " << (omap
.state
.legacy
? "true" : "false") << std::endl
;
131 if (cmd
== "dump-raw-keys") {
132 KeyValueDB::WholeSpaceIterator i
= store
->get_iterator();
133 for (i
->seek_to_first(); i
->valid(); i
->next()) {
134 std::cout
<< i
->raw_key() << std::endl
;
137 } else if (cmd
== "dump-raw-key-vals") {
138 KeyValueDB::WholeSpaceIterator i
= store
->get_iterator();
139 for (i
->seek_to_first(); i
->valid(); i
->next()) {
140 std::cout
<< i
->raw_key() << std::endl
;
141 i
->value().hexdump(std::cout
);
144 } else if (cmd
== "dump-objects") {
145 vector
<ghobject_t
> objects
;
146 r
= omap
.list_objects(&objects
);
148 std::cerr
<< "list_objects got: " << cpp_strerror(r
) << std::endl
;
151 for (vector
<ghobject_t
>::iterator i
= objects
.begin();
154 if (vm
.count("oid") != 0 && i
->hobj
.oid
.name
!= oid
)
156 std::cout
<< *i
<< std::endl
;
159 } else if (cmd
== "dump-objects-with-keys") {
160 vector
<ghobject_t
> objects
;
161 r
= omap
.list_objects(&objects
);
163 std::cerr
<< "list_objects got: " << cpp_strerror(r
) << std::endl
;
166 for (vector
<ghobject_t
>::iterator i
= objects
.begin();
169 if (vm
.count("oid") != 0 && i
->hobj
.oid
.name
!= oid
)
171 std::cout
<< "Object: " << *i
<< std::endl
;
172 ObjectMap::ObjectMapIterator j
= omap
.get_iterator(ghobject_t(i
->hobj
));
173 for (j
->seek_to_first(); j
->valid(); j
->next()) {
174 std::cout
<< j
->key() << std::endl
;
175 j
->value().hexdump(std::cout
);
179 } else if (cmd
== "check" || cmd
== "repair") {
181 bool repair
= (cmd
== "repair");
182 r
= omap
.check(ss
, repair
, true);
184 std::cerr
<< ss
.str() << std::endl
;
186 std::cerr
<< "check got " << r
<< " error(s)" << std::endl
;
190 std::cout
<< (repair
? "repair" : "check") << " succeeded" << std::endl
;
192 } else if (cmd
== "dump-headers") {
193 vector
<DBObjectMap::_Header
> headers
;
194 r
= omap
.list_object_headers(&headers
);
196 std::cerr
<< "list_object_headers got: " << cpp_strerror(r
) << std::endl
;
199 for (auto i
: headers
)
200 std::cout
<< i
<< std::endl
;
202 } else if (cmd
== "resetv2") {
204 omap
.state
.legacy
= false;
206 } else if (cmd
== "compact") {
210 std::cerr
<< "Did not recognize command " << cmd
<< std::endl
;