]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools: ceph-osdomap-tool.cc
authorSamuel Just <sam.just@inktank.com>
Tue, 30 Apr 2013 16:31:26 +0000 (09:31 -0700)
committerSamuel Just <sam.just@inktank.com>
Wed, 1 May 2013 22:43:22 +0000 (15:43 -0700)
Add tool for dumping info from osd omap.

Signed-off-by: Samuel Just <sam.just@inktank.com>
src/.gitignore
src/Makefile.am
src/os/DBObjectMap.cc
src/os/DBObjectMap.h
src/tools/ceph-osdomap-tool.cc [new file with mode: 0644]

index 473af888080a3420c4cde2aa47693896a59bc06e..7914240f2f998093fc015da836c262966d17c47e 100644 (file)
@@ -41,6 +41,7 @@ Makefile
 /ceph_smalliobenchfs
 /ceph_smalliobenchrbd
 /ceph_monstore_tool
+/ceph-osdomap-tool
 /ceph_ver.h
 /dev
 /init-ceph
index 476c80e802754355012efaccec4a7587ccf1f1b2..4e259568eea512ad036d5f81db4e8729555a0bab 100644 (file)
@@ -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}
index c3a4c3b9869a299976f1c4ee5f9e3ea110247b32..29cf8360991a9ae8572472961cf741d56a612aa6 100644 (file)
@@ -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;
+}
index 18c6ce402ff396c38983170edd6d3845fdc03aac..ba05dff6c6ff0bab34b99ae7e75092a44e9a17ae 100644 (file)
@@ -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 (file)
index 0000000..28a407c
--- /dev/null
@@ -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;
+}