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/scoped_ptr.hpp>
14
#include <boost/lexical_cast.hpp>
15
#include <boost/program_options/option.hpp>
16
#include <boost/program_options/options_description.hpp>
17
#include <boost/program_options/variables_map.hpp>
18
#include <boost/program_options/cmdline.hpp>
19
#include <boost/program_options/parsers.hpp>
29
#include <boost/scoped_ptr.hpp>
31
#include "global/global_init.h"
32
#include "os/LevelDBStore.h"
33
#include "mon/MonitorDBStore.h"
34
#include "os/DBObjectMap.h"
36
namespace po = boost::program_options;
39
int main(int argc, char **argv) {
40
po::options_description desc("Allowed options");
41
string store_path, cmd, out_path;
42
bool paranoid = false;
44
("help", "produce help message")
45
("omap-path", po::value<string>(&store_path),
46
"path to mon directory, mandatory (current/omap usually)")
47
("paranoid", po::value<bool>(¶noid),
48
"use paranoid checking")
49
("command", po::value<string>(&cmd),
52
po::positional_options_description p;
56
po::parsed_options parsed =
57
po::command_line_parser(argc, argv).options(desc).positional(p).run();
64
cout << desc << std::endl;
68
vector<const char *> ceph_options, def_args;
69
vector<string> ceph_option_strings = po::collect_unrecognized(
70
parsed.options, po::include_positional);
71
ceph_options.reserve(ceph_option_strings.size());
72
for (vector<string>::iterator i = ceph_option_strings.begin();
73
i != ceph_option_strings.end();
75
ceph_options.push_back(i->c_str());
79
&def_args, ceph_options, CEPH_ENTITY_TYPE_OSD,
80
CODE_ENVIRONMENT_UTILITY, 0);
81
common_init_finish(g_ceph_context);
82
g_ceph_context->_conf->apply_changes(NULL);
83
g_conf = g_ceph_context->_conf;
85
if (vm.count("help")) {
86
std::cerr << desc << std::endl;
90
LevelDBStore* store(new LevelDBStore(g_ceph_context, store_path));
92
std::cerr << "Enabling paranoid checks" << std::endl;
93
store->options.paranoid_checks = paranoid;
95
DBObjectMap omap(store);
97
int r = store->open(out);
99
std::cerr << "Store open got: " << cpp_strerror(r) << std::endl;
100
std::cerr << "Output: " << out.str() << std::endl;
106
if (cmd == "dump-raw-keys") {
107
KeyValueDB::WholeSpaceIterator i = store->get_iterator();
108
for (i->seek_to_first(); i->valid(); i->next()) {
109
std::cout << i->raw_key() << std::endl;
111
} else if (cmd == "dump-raw-key-vals") {
112
KeyValueDB::WholeSpaceIterator i = store->get_iterator();
113
for (i->seek_to_first(); i->valid(); i->next()) {
114
std::cout << i->raw_key() << std::endl;
115
i->value().hexdump(std::cout);
117
} else if (cmd == "dump-objects") {
118
vector<ghobject_t> objects;
119
r = omap.list_objects(&objects);
121
std::cerr << "list_objects got: " << cpp_strerror(r) << std::endl;
124
for (vector<ghobject_t>::iterator i = objects.begin();
127
std::cout << *i << std::endl;
130
} else if (cmd == "dump-objects-with-keys") {
131
vector<ghobject_t> objects;
132
r = omap.list_objects(&objects);
134
std::cerr << "list_objects got: " << cpp_strerror(r) << std::endl;
137
for (vector<ghobject_t>::iterator i = objects.begin();
140
std::cout << "Object: " << *i << std::endl;
141
ObjectMap::ObjectMapIterator j = omap.get_iterator(i->hobj);
142
for (j->seek_to_first(); j->valid(); j->next()) {
143
std::cout << j->key() << std::endl;
144
j->value().hexdump(std::cout);
147
} else if (cmd == "check") {
148
r = omap.check(std::cout);
150
std::cerr << "check got: " << cpp_strerror(r) << std::endl;
153
std::cout << "check succeeded" << std::endl;
155
std::cerr << "Did not recognize command " << cmd << std::endl;