]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
tools/ceph-objectstore-tool: dump onode internal metadata. 27869/head
authorIgor Fedotov <ifedotov@suse.com>
Mon, 8 Apr 2019 10:35:48 +0000 (13:35 +0300)
committerIgor Fedotov <ifedotov@suse.com>
Mon, 29 Apr 2019 16:43:56 +0000 (19:43 +0300)
Supported for BlueStore only.

Signed-off-by: Igor Fedotov <ifedotov@suse.com>
src/os/ObjectStore.h
src/os/bluestore/BlueStore.cc
src/os/bluestore/BlueStore.h
src/tools/ceph_objectstore_tool.cc

index 1ac2e0746f572235e9b041212d0aa65b867d441c..cb84be8faa4fb16dfae5d44436809f2f06113a6c 100644 (file)
@@ -1705,6 +1705,24 @@ public:
    virtual int fiemap(CollectionHandle& c, const ghobject_t& oid,
                      uint64_t offset, size_t len, std::map<uint64_t, uint64_t>& destmap) = 0;
 
+  /**
+   * dump_onode -- dumps onode metadata in human readable form,
+     intended primiarily for debugging
+   *
+   * @param cid collection for object
+   * @param oid oid of object
+   * @param section_name section name to create and print under
+   * @param f Formatter class instance to print to
+   * @returns 0 on success, negative error code on failure.
+   */
+  virtual int dump_onode(
+    CollectionHandle &c,
+    const ghobject_t& oid,
+    const string& section_name,
+    Formatter *f) {
+    return -ENOTSUP;
+  }
+
   /**
    * getattr -- get an xattr of an object
    *
index d4a5258b9c8a9ce95782590ce38f2a295598acfa..a558677f682c608e881a0e81c016b9865f8f6eff 100644 (file)
@@ -1628,6 +1628,16 @@ void BlueStore::OnodeSpace::dump(CephContext *cct)
 #undef dout_prefix
 #define dout_prefix *_dout << "bluestore.sharedblob(" << this << ") "
 
+void BlueStore::SharedBlob::dump(Formatter* f) const
+{
+  f->dump_bool("loaded", loaded);
+  if (loaded) {
+    persistent->dump(f);
+  } else {
+    f->dump_unsigned("sbid_unloaded", sbid_unloaded);
+  }
+}
+
 ostream& operator<<(ostream& out, const BlueStore::SharedBlob& sb)
 {
   out << "SharedBlob(" << &sb;
@@ -1731,6 +1741,17 @@ void BlueStore::SharedBlobSet::dump(CephContext *cct)
 #undef dout_prefix
 #define dout_prefix *_dout << "bluestore.blob(" << this << ") "
 
+void BlueStore::Blob::dump(Formatter* f) const
+{
+  if (is_spanning()) {
+    f->dump_unsigned("spanning_id ", id);
+  }
+  blob.dump(f);
+  if (shared_blob) {
+    f->dump_object("shared", *shared_blob);
+  }
+}
+
 ostream& operator<<(ostream& out, const BlueStore::Blob& b)
 {
   out << "Blob(" << &b;
@@ -1970,6 +1991,14 @@ void BlueStore::Blob::decode(
 
 // Extent
 
+void BlueStore::Extent::dump(Formatter* f) const
+{
+  f->dump_unsigned("logical_offset", logical_offset);
+  f->dump_unsigned("length", length);
+  f->dump_unsigned("blob_offset", blob_offset);
+  f->dump_object("blob", *blob);
+}
+
 ostream& operator<<(ostream& out, const BlueStore::Extent& e)
 {
   return out << std::hex << "0x" << e.logical_offset << "~" << e.length
@@ -2000,6 +2029,16 @@ BlueStore::ExtentMap::ExtentMap(Onode *o)
       o->c->store->cct->_conf->bluestore_extent_map_inline_shard_prealloc_size) {
 }
 
+void BlueStore::ExtentMap::dump(Formatter* f) const
+{
+  f->open_array_section("extents");
+
+  for (auto& e : extent_map) {
+      f->dump_object("extent", e);
+  }
+  f->close_section();
+}
+
 void BlueStore::ExtentMap::dup(BlueStore* b, TransContext* txc,
   CollectionRef& c, OnodeRef& oldo, OnodeRef& newo, uint64_t& srcoff,
   uint64_t& length, uint64_t& dstoff) {
@@ -3095,6 +3134,12 @@ void BlueStore::Onode::flush()
   ldout(c->store->cct, 20) << __func__ << " done" << dendl;
 }
 
+void BlueStore::Onode::dump(Formatter* f) const
+{
+  onode.dump(f);
+  extent_map.dump(f);
+}
+
 // =======================================================
 // WriteContext
  
@@ -8873,6 +8918,42 @@ int BlueStore::fiemap(
   return r;
 }
 
+int BlueStore::dump_onode(CollectionHandle &c_,
+  const ghobject_t& oid,
+  const string& section_name,
+  Formatter *f)
+{
+  Collection *c = static_cast<Collection *>(c_.get());
+  dout(15) << __func__ << " " << c->cid << " " << oid << dendl;
+  if (!c->exists)
+    return -ENOENT;
+
+  int r;
+  {
+    RWLock::RLocker l(c->lock);
+
+    OnodeRef o = c->get_onode(oid, false);
+    if (!o || !o->exists) {
+      r = -ENOENT;
+      goto out;
+    }
+    // FIXME minor: actually the next line isn't enough to
+    // load shared blobs. Leaving as is for now..
+    //
+    o->extent_map.fault_range(db, 0, OBJECT_MAX_SIZE);
+
+    _dump_onode<0>(o);
+    f->open_object_section(section_name.c_str());
+    o->dump(f);
+    f->close_section();
+    r = 0;
+  }
+ out:
+  dout(10) << __func__ << " " << c->cid << " " << oid
+          << " = " << r << dendl;
+  return r;
+}
+
 int BlueStore::getattr(
   CollectionHandle &c_,
   const ghobject_t& oid,
index 67fc348a30e792ffe5f8e31b9ad1e881d0184b88..60690973961bbc51c09ebf4d97621a84a3741596 100644 (file)
@@ -411,6 +411,7 @@ public:
     friend void intrusive_ptr_add_ref(SharedBlob *b) { b->get(); }
     friend void intrusive_ptr_release(SharedBlob *b) { b->put(); }
 
+    void dump(Formatter* f) const;
     friend ostream& operator<<(ostream& out, const SharedBlob& sb);
 
     void get() {
@@ -516,6 +517,7 @@ public:
     friend void intrusive_ptr_add_ref(Blob *b) { b->get(); }
     friend void intrusive_ptr_release(Blob *b) { b->put(); }
 
+    void dump(Formatter* f) const;
     friend ostream& operator<<(ostream& out, const Blob &b);
 
     const bluestore_blob_use_tracker_t& get_blob_use_tracker() const {
@@ -693,6 +695,8 @@ public:
       }
     }
 
+    void dump(Formatter* f) const;
+
     void assign_blob(const BlobRef& b) {
       ceph_assert(!blob);
       blob = b;
@@ -811,6 +815,8 @@ public:
       clear_needs_reshard();
     }
 
+    void dump(Formatter* f) const;
+
     bool encode_some(uint32_t offset, uint32_t length, bufferlist& bl,
                     unsigned *pn);
     unsigned decode_some(bufferlist& bl);
@@ -1065,6 +1071,8 @@ public:
        extent_map(this) {
     }
 
+    void dump(Formatter* f) const;
+
     void flush();
     void get() {
       ++nref;
@@ -2523,6 +2531,8 @@ public:
   int fiemap(CollectionHandle &c, const ghobject_t& oid,
             uint64_t offset, size_t len, map<uint64_t, uint64_t>& destmap) override;
 
+  int dump_onode(CollectionHandle &c, const ghobject_t& oid,
+    const string& section_name, Formatter *f) override;
 
   int getattr(CollectionHandle &c, const ghobject_t& oid, const char *name,
              bufferptr& value) override;
index 52de997b42ce38874ddb26cc769f16860626b585..1ba6075d157ecef6e6d767a69956cc1188be3f17 100644 (file)
@@ -2438,6 +2438,7 @@ int print_obj_info(ObjectStore *store, coll_t coll, ghobject_t &ghobj, Formatter
            << cpp_strerror(r) << std::endl;
     }
   }
+  gr = store->dump_onode(ch, ghobj, "onode", formatter);
 
   formatter->close_section();
   formatter->flush(cout);