]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools: Add dump-headers command to ceph-osdomap-tool
authorDavid Zafman <dzafman@redhat.com>
Wed, 8 Feb 2017 17:40:49 +0000 (09:40 -0800)
committerDavid Zafman <dzafman@redhat.com>
Wed, 26 Apr 2017 21:03:18 +0000 (14:03 -0700)
Signed-off-by: David Zafman <dzafman@redhat.com>
(cherry picked from commit f4101591ad701a62fe027c4744ca8ea505f44bdc)

Conflicts:
src/os/filestore/DBObjectMap.h (trivial)

src/os/filestore/DBObjectMap.cc
src/os/filestore/DBObjectMap.h
src/tools/ceph_osdomap_tool.cc

index e9d572ca9dd7b866af80d7df9457455ed4dcf6ac..ccc6bbf52260783d3d6077e1ea4e41c3d162ef6f 100644 (file)
@@ -1260,3 +1260,41 @@ int DBObjectMap::list_objects(vector<ghobject_t> *out)
   }
   return 0;
 }
+
+int DBObjectMap::list_object_headers(vector<_Header> *out)
+{
+  int error = 0;
+  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);
+    while (header.parent) {
+      set<string> to_get;
+      map<string, bufferlist> got;
+      to_get.insert(HEADER_KEY);
+      db->get(sys_parent_prefix(header), to_get, &got);
+      if (got.empty()) {
+       dout(0) << "Missing: seq " << header.parent << dendl;
+       error = -ENOENT;
+       break;
+      } else {
+       bl = got.begin()->second;
+        bufferlist::iterator bliter = bl.begin();
+        header.decode(bliter);
+        out->push_back(header);
+      }
+    }
+  }
+  return error;
+}
+
+ostream& operator<<(ostream& out, const DBObjectMap::_Header& h)
+{
+  out << "seq=" << h.seq << " parent=" << h.parent 
+      << " num_children=" << h.num_children
+      << " ghobject=" << h.oid;
+  return out;
+}
index e0860327a6905f47ffb0d9808a72c9c65aaba3b6..26d435320f5396d6e240b964d82f75b219cacc83 100644 (file)
@@ -221,6 +221,11 @@ public:
   int list_objects(vector<ghobject_t> *objs ///< [out] objects
     );
 
+  struct _Header;
+  // Util, get all object headers, there must be no other concurrent access
+  int list_object_headers(vector<_Header> *out ///< [out] headers
+    );
+
   ObjectMapIterator get_iterator(const ghobject_t &oid);
 
   static const string USER_PREFIX;
@@ -531,4 +536,6 @@ private:
 WRITE_CLASS_ENCODER(DBObjectMap::_Header)
 WRITE_CLASS_ENCODER(DBObjectMap::State)
 
+ostream& operator<<(ostream& out, const DBObjectMap::_Header& h);
+
 #endif
index 9eb7a8c939a33a550b1a3021a1b26038c245a954..269ff44643da6497c61fd572946c28d5087f103e 100644 (file)
@@ -35,7 +35,7 @@ int main(int argc, char **argv) {
     ("paranoid", "use paranoid checking")
     ("oid", po::value<string>(&oid), "Restrict to this object id when dumping objects")
     ("command", po::value<string>(&cmd),
-     "command arg is one of [dump-raw-keys, dump-raw-key-vals, dump-objects, dump-objects-with-keys, check], mandatory")
+     "command arg is one of [dump-raw-keys, dump-raw-key-vals, dump-objects, dump-objects-with-keys, check, dump-headers], mandatory")
     ;
   po::positional_options_description p;
   p.add("command", 1);
@@ -155,6 +155,16 @@ int main(int argc, char **argv) {
       goto done;
     }
     std::cout << "check succeeded" << std::endl;
+  } else if (cmd == "dump-headers") {
+    vector<DBObjectMap::_Header> headers;
+    r = omap.list_object_headers(&headers);
+    if (r < 0) {
+      std::cerr << "list_object_headers got: " << cpp_strerror(r) << std::endl;
+      r = 1;
+      goto done;
+    }
+    for (auto i : headers)
+      std::cout << i << std::endl;
   } else {
     std::cerr << "Did not recognize command " << cmd << std::endl;
     goto done;