From c3968c4f03c22ec10f99aefd751b0915a868a076 Mon Sep 17 00:00:00 2001 From: Igor Fedotov Date: Mon, 8 Apr 2019 13:35:48 +0300 Subject: [PATCH] tools/ceph-objectstore-tool: dump onode internal metadata. Supported for BlueStore only. Signed-off-by: Igor Fedotov --- src/os/ObjectStore.h | 18 +++++++ src/os/bluestore/BlueStore.cc | 81 ++++++++++++++++++++++++++++++ src/os/bluestore/BlueStore.h | 10 ++++ src/tools/ceph_objectstore_tool.cc | 1 + 4 files changed, 110 insertions(+) diff --git a/src/os/ObjectStore.h b/src/os/ObjectStore.h index 1ac2e0746f5..cb84be8faa4 100644 --- a/src/os/ObjectStore.h +++ b/src/os/ObjectStore.h @@ -1705,6 +1705,24 @@ public: virtual int fiemap(CollectionHandle& c, const ghobject_t& oid, uint64_t offset, size_t len, std::map& 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 * diff --git a/src/os/bluestore/BlueStore.cc b/src/os/bluestore/BlueStore.cc index d4a5258b9c8..a558677f682 100644 --- a/src/os/bluestore/BlueStore.cc +++ b/src/os/bluestore/BlueStore.cc @@ -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(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, diff --git a/src/os/bluestore/BlueStore.h b/src/os/bluestore/BlueStore.h index 67fc348a30e..60690973961 100644 --- a/src/os/bluestore/BlueStore.h +++ b/src/os/bluestore/BlueStore.h @@ -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& 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; diff --git a/src/tools/ceph_objectstore_tool.cc b/src/tools/ceph_objectstore_tool.cc index 52de997b42c..1ba6075d157 100644 --- a/src/tools/ceph_objectstore_tool.cc +++ b/src/tools/ceph_objectstore_tool.cc @@ -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); -- 2.39.5