summaryrefslogtreecommitdiff
path: root/src/tools
diff options
context:
space:
mode:
authorSamuel Just <sam.just@inktank.com>2013-04-30 09:31:26 -0700
committerSamuel Just <sam.just@inktank.com>2013-05-01 15:43:22 -0700
commitd0d93a743e3af77bb3784b318b1a1f7a5c1c293a (patch)
tree9c66ff543aae411fdfc094e5ecd4a49809f5769a /src/tools
parentdfacd1bd805ebb730b5206c9830b28f47cc7f9cf (diff)
downloadceph-d0d93a743e3af77bb3784b318b1a1f7a5c1c293a.tar.gz
tools: ceph-osdomap-tool.cc
Add tool for dumping info from osd omap. Signed-off-by: Samuel Just <sam.just@inktank.com>
Diffstat (limited to 'src/tools')
-rw-r--r--src/tools/ceph-osdomap-tool.cc154
1 files changed, 154 insertions, 0 deletions
diff --git a/src/tools/ceph-osdomap-tool.cc b/src/tools/ceph-osdomap-tool.cc
new file mode 100644
index 00000000000..28a407ca151
--- /dev/null
+++ b/src/tools/ceph-osdomap-tool.cc
@@ -0,0 +1,154 @@
+// -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
+// vim: ts=8 sw=2 smarttab
+/*
+* Ceph - scalable distributed file system
+*
+* Copyright (C) 2012 Inktank, Inc.
+*
+* This is free software; you can redistribute it and/or
+* modify it under the terms of the GNU Lesser General Public
+* License kkjversion 2.1, as published by the Free Software
+* Foundation. See file COPYING.
+*/
+#include <boost/scoped_ptr.hpp>
+#include <boost/lexical_cast.hpp>
+#include <boost/program_options/option.hpp>
+#include <boost/program_options/options_description.hpp>
+#include <boost/program_options/variables_map.hpp>
+#include <boost/program_options/cmdline.hpp>
+#include <boost/program_options/parsers.hpp>
+#include <iostream>
+#include <set>
+#include <sstream>
+#include <stdlib.h>
+#include <fstream>
+#include <string>
+#include <sstream>
+#include <map>
+#include <set>
+#include <boost/scoped_ptr.hpp>
+
+#include "global/global_init.h"
+#include "os/LevelDBStore.h"
+#include "mon/MonitorDBStore.h"
+#include "os/DBObjectMap.h"
+
+namespace po = boost::program_options;
+using namespace std;
+
+int main(int argc, char **argv) {
+ po::options_description desc("Allowed options");
+ string store_path, cmd, out_path;
+ desc.add_options()
+ ("help", "produce help message")
+ ("omap-path", po::value<string>(&store_path),
+ "path to mon directory, mandatory (current/omap usually)")
+ ("command", po::value<string>(&cmd),
+ "command")
+ ;
+ po::positional_options_description p;
+ p.add("command", 1);
+
+ po::variables_map vm;
+ po::parsed_options parsed =
+ po::command_line_parser(argc, argv).options(desc).positional(p).run();
+ po::store(
+ parsed,
+ vm);
+ try {
+ po::notify(vm);
+ } catch (...) {
+ cout << desc << std::endl;
+ return 1;
+ }
+
+ vector<const char *> ceph_options, def_args;
+ vector<string> ceph_option_strings = po::collect_unrecognized(
+ parsed.options, po::include_positional);
+ ceph_options.reserve(ceph_option_strings.size());
+ for (vector<string>::iterator i = ceph_option_strings.begin();
+ i != ceph_option_strings.end();
+ ++i) {
+ ceph_options.push_back(i->c_str());
+ }
+
+ global_init(
+ &def_args, ceph_options, CEPH_ENTITY_TYPE_OSD,
+ CODE_ENVIRONMENT_UTILITY, 0);
+ common_init_finish(g_ceph_context);
+ g_ceph_context->_conf->apply_changes(NULL);
+ g_conf = g_ceph_context->_conf;
+
+ if (vm.count("help")) {
+ std::cerr << desc << std::endl;
+ return 1;
+ }
+
+ LevelDBStore* store(new LevelDBStore(store_path));
+ DBObjectMap omap(store);
+ stringstream out;
+ int r = store->open(out);
+ if (r < 0) {
+ std::cerr << "Store open got: " << cpp_strerror(r) << std::endl;
+ std::cerr << "Output: " << out.str() << std::endl;
+ goto done;
+ }
+ r = 0;
+
+
+ if (cmd == "dump-raw-keys") {
+ KeyValueDB::WholeSpaceIterator i = store->get_iterator();
+ for (i->seek_to_first(); i->valid(); i->next()) {
+ std::cout << i->raw_key() << std::endl;
+ }
+ } else if (cmd == "dump-raw-key-vals") {
+ KeyValueDB::WholeSpaceIterator i = store->get_iterator();
+ for (i->seek_to_first(); i->valid(); i->next()) {
+ std::cout << i->raw_key() << std::endl;
+ i->value().hexdump(std::cout);
+ }
+ } else if (cmd == "dump-objects") {
+ vector<hobject_t> objects;
+ r = omap.list_objects(&objects);
+ if (r < 0) {
+ std::cerr << "list_objects got: " << cpp_strerror(r) << std::endl;
+ goto done;
+ }
+ for (vector<hobject_t>::iterator i = objects.begin();
+ i != objects.end();
+ ++i) {
+ std::cout << *i << std::endl;
+ }
+ r = 0;
+ } else if (cmd == "dump-objects-with-keys") {
+ vector<hobject_t> objects;
+ r = omap.list_objects(&objects);
+ if (r < 0) {
+ std::cerr << "list_objects got: " << cpp_strerror(r) << std::endl;
+ goto done;
+ }
+ for (vector<hobject_t>::iterator i = objects.begin();
+ i != objects.end();
+ ++i) {
+ std::cout << "Object: " << *i << std::endl;
+ ObjectMap::ObjectMapIterator j = omap.get_iterator(*i);
+ for (j->seek_to_first(); j->valid(); j->next()) {
+ std::cout << j->key() << std::endl;
+ j->value().hexdump(std::cout);
+ }
+ }
+ } else if (cmd == "check") {
+ r = omap.check(std::cout);
+ if (!r) {
+ std::cerr << "check got: " << cpp_strerror(r) << std::endl;
+ goto done;
+ }
+ std::cout << "check succeeded" << std::endl;
+ } else {
+ std::cerr << "Did not recognize command " << cmd << std::endl;
+ goto done;
+ }
+
+ done:
+ return r;
+}