]> git-server-git.apps.pok.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>
Tue, 28 Mar 2017 16:31:34 +0000 (09:31 -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 a5a8a52cee7c806495c54ce733358b4bfd1a7dab..1c29ac7c39ede813f53c69162182720874250b02 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 6c72068c885513fe9f231bb30528a79bcc6dced9..1d7d84af34287e95aeda2cfbb08c9993ac47825e 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;