diff options
author | Samuel Just <sam.just@inktank.com> | 2013-04-30 09:31:26 -0700 |
---|---|---|
committer | Samuel Just <sam.just@inktank.com> | 2013-05-01 15:43:22 -0700 |
commit | d0d93a743e3af77bb3784b318b1a1f7a5c1c293a (patch) | |
tree | 9c66ff543aae411fdfc094e5ecd4a49809f5769a | |
parent | dfacd1bd805ebb730b5206c9830b28f47cc7f9cf (diff) | |
download | ceph-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>
-rw-r--r-- | src/.gitignore | 1 | ||||
-rw-r--r-- | src/Makefile.am | 7 | ||||
-rw-r--r-- | src/os/DBObjectMap.cc | 13 | ||||
-rw-r--r-- | src/os/DBObjectMap.h | 4 | ||||
-rw-r--r-- | src/tools/ceph-osdomap-tool.cc | 154 |
5 files changed, 179 insertions, 0 deletions
diff --git a/src/.gitignore b/src/.gitignore index 473af888080..7914240f2f9 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -41,6 +41,7 @@ Makefile /ceph_smalliobenchfs /ceph_smalliobenchrbd /ceph_monstore_tool +/ceph-osdomap-tool /ceph_ver.h /dev /init-ceph diff --git a/src/Makefile.am b/src/Makefile.am index 476c80e8027..4e259568eea 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -128,6 +128,13 @@ ceph_filestore_dump_LDADD += -ldl endif bin_PROGRAMS += ceph ceph-conf ceph-authtool ceph_filestore_dump +ceph_osdomap_tool_SOURCES = tools/ceph-osdomap-tool.cc \ + os/LevelDBStore.cc +ceph_osdomap_tool_LDFLAGS = ${AM_LDFLAGS} +ceph_osdomap_tool_LDADD = $(LIBOS_LDA) $(LIBGLOBAL_LDA) -lboost_program_options +ceph_osdomap_tool_CXXFLAGS = ${AM_CXXFLAGS} ${UNITTEST_CXXFLAGS} +bin_DEBUGPROGRAMS += ceph-osdomap-tool + ceph_monstore_tool_SOURCES = tools/ceph-monstore-tool.cc \ os/LevelDBStore.cc ceph_monstore_tool_LDFLAGS = ${AM_LDFLAGS} diff --git a/src/os/DBObjectMap.cc b/src/os/DBObjectMap.cc index c3a4c3b9869..29cf8360991 100644 --- a/src/os/DBObjectMap.cc +++ b/src/os/DBObjectMap.cc @@ -1213,3 +1213,16 @@ bool DBObjectMap::check_spos(const hobject_t &hoid, return true; } } + +int DBObjectMap::list_objects(vector<hobject_t> *out) +{ + KeyValueDB::Iterator iter = db->get_iterator(HOBJECT_TO_SEQ); + for (iter->seek_to_first(); iter->valid(); iter->next()) { + bufferlist bl = iter->value(); + bufferlist::iterator bliter = bl.begin(); + _Header header; + header.decode(bliter); + out->push_back(header.hoid); + } + return 0; +} diff --git a/src/os/DBObjectMap.h b/src/os/DBObjectMap.h index 18c6ce402ff..ba05dff6c6f 100644 --- a/src/os/DBObjectMap.h +++ b/src/os/DBObjectMap.h @@ -164,6 +164,10 @@ public: /// Ensure that all previous operations are durable int sync(const hobject_t *hoid=0, const SequencerPosition *spos=0); + /// Util, list all objects, there must be no other concurrent access + int list_objects(vector<hobject_t> *objs ///< [out] objects + ); + ObjectMapIterator get_iterator(const hobject_t &hoid); static const string USER_PREFIX; 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; +} |