From: dongdong tao Date: Sat, 17 Feb 2018 03:01:56 +0000 (+0800) Subject: mds: add DUMP_DIRFRAGS to CInode and DUMP_ITEMS to CDir X-Git-Tag: v13.0.2~72^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=ebb285d67b46ef6efc8ae9765d5cd6cc1213d652;p=ceph.git mds: add DUMP_DIRFRAGS to CInode and DUMP_ITEMS to CDir Signed-off-by: dongdong tao --- diff --git a/src/mds/CDir.cc b/src/mds/CDir.cc index 9fb6a323fe8a..08888c325d22 100644 --- a/src/mds/CDir.cc +++ b/src/mds/CDir.cc @@ -3012,45 +3012,64 @@ void CDir::unfreeze_dir() * for identifying a directory and its state rather than for dumping * debug output. */ -void CDir::dump(Formatter *f) const +void CDir::dump(Formatter *f, int flags) const { assert(f != NULL); - - f->dump_stream("path") << get_path(); - - f->dump_stream("dirfrag") << dirfrag(); - f->dump_int("snapid_first", first); - - f->dump_stream("projected_version") << get_projected_version(); - f->dump_stream("version") << get_version(); - f->dump_stream("committing_version") << get_committing_version(); - f->dump_stream("committed_version") << get_committed_version(); - - f->dump_bool("is_rep", is_rep()); - - if (get_dir_auth() != CDIR_AUTH_DEFAULT) { - if (get_dir_auth().second == CDIR_AUTH_UNKNOWN) { - f->dump_stream("dir_auth") << get_dir_auth().first; + if (flags & DUMP_PATH) { + f->dump_stream("path") << get_path(); + } + if (flags & DUMP_DIRFRAG) { + f->dump_stream("dirfrag") << dirfrag(); + } + if (flags & DUMP_SNAPID_FIRST) { + f->dump_int("snapid_first", first); + } + if (flags & DUMP_VERSIONS) { + f->dump_stream("projected_version") << get_projected_version(); + f->dump_stream("version") << get_version(); + f->dump_stream("committing_version") << get_committing_version(); + f->dump_stream("committed_version") << get_committed_version(); + } + if (flags & DUMP_REP) { + f->dump_bool("is_rep", is_rep()); + } + if (flags & DUMP_DIR_AUTH) { + if (get_dir_auth() != CDIR_AUTH_DEFAULT) { + if (get_dir_auth().second == CDIR_AUTH_UNKNOWN) { + f->dump_stream("dir_auth") << get_dir_auth().first; + } else { + f->dump_stream("dir_auth") << get_dir_auth(); + } } else { - f->dump_stream("dir_auth") << get_dir_auth(); + f->dump_string("dir_auth", ""); } - } else { - f->dump_string("dir_auth", ""); - } - - f->open_array_section("states"); - MDSCacheObject::dump_states(f); - if (state_test(CDir::STATE_COMPLETE)) f->dump_string("state", "complete"); - if (state_test(CDir::STATE_FREEZINGTREE)) f->dump_string("state", "freezingtree"); - if (state_test(CDir::STATE_FROZENTREE)) f->dump_string("state", "frozentree"); - if (state_test(CDir::STATE_FROZENDIR)) f->dump_string("state", "frozendir"); - if (state_test(CDir::STATE_FREEZINGDIR)) f->dump_string("state", "freezingdir"); - if (state_test(CDir::STATE_EXPORTBOUND)) f->dump_string("state", "exportbound"); - if (state_test(CDir::STATE_IMPORTBOUND)) f->dump_string("state", "importbound"); - if (state_test(CDir::STATE_BADFRAG)) f->dump_string("state", "badfrag"); - f->close_section(); - - MDSCacheObject::dump(f); + } + if (flags & DUMP_STATES) { + f->open_array_section("states"); + MDSCacheObject::dump_states(f); + if (state_test(CDir::STATE_COMPLETE)) f->dump_string("state", "complete"); + if (state_test(CDir::STATE_FREEZINGTREE)) f->dump_string("state", "freezingtree"); + if (state_test(CDir::STATE_FROZENTREE)) f->dump_string("state", "frozentree"); + if (state_test(CDir::STATE_FROZENDIR)) f->dump_string("state", "frozendir"); + if (state_test(CDir::STATE_FREEZINGDIR)) f->dump_string("state", "freezingdir"); + if (state_test(CDir::STATE_EXPORTBOUND)) f->dump_string("state", "exportbound"); + if (state_test(CDir::STATE_IMPORTBOUND)) f->dump_string("state", "importbound"); + if (state_test(CDir::STATE_BADFRAG)) f->dump_string("state", "badfrag"); + f->close_section(); + } + if (flags & DUMP_MDS_CACHE_OBJECT) { + MDSCacheObject::dump(f); + } + if (flags & DUMP_ITEMS) { + f->open_array_section("dentries"); + for (auto &p : items) { + CDentry *dn = p.second; + f->open_object_section("dentry"); + dn->dump(f); + f->close_section(); + } + f->close_section(); + } } void CDir::dump_load(Formatter *f, utime_t now, const DecayRate& rate) diff --git a/src/mds/CDir.h b/src/mds/CDir.h index 3e6bc0eb2d29..c1e92cf57041 100644 --- a/src/mds/CDir.h +++ b/src/mds/CDir.h @@ -140,8 +140,18 @@ public: static const uint64_t WAIT_ATFREEZEROOT = (WAIT_UNFREEZE); static const uint64_t WAIT_ATSUBTREEROOT = (WAIT_SINGLEAUTH); - - + // -- dump flags -- + static const int DUMP_PATH = (1 << 0); + static const int DUMP_DIRFRAG = (1 << 1); + static const int DUMP_SNAPID_FIRST = (1 << 2); + static const int DUMP_VERSIONS = (1 << 3); + static const int DUMP_REP = (1 << 4); + static const int DUMP_DIR_AUTH = (1 << 5); + static const int DUMP_STATES = (1 << 6); + static const int DUMP_MDS_CACHE_OBJECT = (1 << 7); + static const int DUMP_ITEMS = (1 << 8); + static const int DUMP_ALL = (-1); + static const int DUMP_DEFAULT = DUMP_ALL & (~DUMP_ITEMS); public: // context @@ -746,7 +756,7 @@ public: ostream& print_db_line_prefix(ostream& out) override; void print(ostream& out) override; - void dump(Formatter *f) const; + void dump(Formatter *f, int flags = DUMP_DEFAULT) const; void dump_load(Formatter *f, utime_t now, const DecayRate& rate); }; diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index 8c1719dc32ed..3cdd6b6b19d9 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -601,7 +601,7 @@ CDir *CInode::get_approx_dirfrag(frag_t fg) return NULL; } -void CInode::get_dirfrags(std::list& ls) +void CInode::get_dirfrags(std::list& ls) const { // all dirfrags for (const auto &p : dirfrags) { @@ -4359,6 +4359,19 @@ void CInode::dump(Formatter *f, int flags) const } f->close_section(); } + + if (flags & DUMP_DIRFRAGS) { + f->open_array_section("dirfrags"); + list dfs; + get_dirfrags(dfs); + for(const auto &dir: dfs) { + f->open_object_section("dir"); + dir->dump(f, CDir::DUMP_DEFAULT | CDir::DUMP_ITEMS); + dir->check_rstats(); + f->close_section(); + } + f->close_section(); + } } /****** Scrub Stuff *****/ diff --git a/src/mds/CInode.h b/src/mds/CInode.h index 152456e82526..43287bebcb1a 100644 --- a/src/mds/CInode.h +++ b/src/mds/CInode.h @@ -210,8 +210,9 @@ class CInode : public MDSCacheObject, public InodeStoreBase, public Counter& ls); CDir* get_approx_dirfrag(frag_t fg); - void get_dirfrags(std::list& ls); + void get_dirfrags(std::list& ls) const; void get_nested_dirfrags(std::list& ls); void get_subtree_dirfrags(std::list& ls); CDir *get_or_open_dirfrag(MDCache *mdcache, frag_t fg); diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index fd53f51d6b45..edb1e6bee821 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -11964,7 +11964,7 @@ void MDCache::dump_tree(CInode *in, const int cur_depth, const int max_depth, Fo } } f->open_object_section("inode"); - in->dump(f); + in->dump(f, CInode::DUMP_DEFAULT | CInode::DUMP_DIRFRAGS); f->close_section(); } @@ -11982,7 +11982,7 @@ int MDCache::dump_cache(Formatter *f) * Dump the metadata cache, either to a Formatter, if * provided, else to a plain text file. */ -int MDCache::dump_cache(const char *fn, Formatter *f) +int MDCache::dump_cache(std::string_view fn, Formatter *f) { int r = 0; int fd = -1; @@ -12010,67 +12010,35 @@ int MDCache::dump_cache(const char *fn, Formatter *f) int r; if (f) { f->open_object_section("inode"); - in->dump(f); - } else { - ostringstream ss; - ss << *in << std::endl; - std::string s = ss.str(); - r = safe_write(fd, s.c_str(), s.length()); - if (r < 0) - return r; - } - + in->dump(f, CInode::DUMP_DEFAULT | CInode::DUMP_DIRFRAGS); + f->close_section(); + return 1; + } + ostringstream ss; + ss << *in << std::endl; + std::string s = ss.str(); + r = safe_write(fd, s.c_str(), s.length()); + if (r < 0) + return r; list dfs; in->get_dirfrags(dfs); - if (f) { - f->open_array_section("dirfrags"); - } - for (list::iterator p = dfs.begin(); p != dfs.end(); ++p) { - CDir *dir = *p; - if (f) { - f->open_object_section("dir"); - dir->dump(f); - } else { - ostringstream tt; - tt << " " << *dir << std::endl; - string t = tt.str(); - r = safe_write(fd, t.c_str(), t.length()); - if (r < 0) - return r; - } - - if (f) { - f->open_array_section("dentries"); - } + for (auto &dir : dfs) { + ostringstream tt; + tt << " " << *dir << std::endl; + std::string t = tt.str(); + r = safe_write(fd, t.c_str(), t.length()); + if (r < 0) + return r; for (auto &p : dir->items) { CDentry *dn = p.second; - if (f) { - f->open_object_section("dentry"); - dn->dump(f); - f->close_section(); - } else { - ostringstream uu; - uu << " " << *dn << std::endl; - string u = uu.str(); - r = safe_write(fd, u.c_str(), u.length()); - if (r < 0) - return r; - } - } - if (f) { - f->close_section(); //dentries + ostringstream uu; + uu << " " << *dn << std::endl; + std::string u = uu.str(); + r = safe_write(fd, u.c_str(), u.length()); + if (r < 0) + return r; } dir->check_rstats(); - if (f) { - f->close_section(); //dir - } - } - if (f) { - f->close_section(); // dirfrags - } - - if (f) { - f->close_section(); // inode } return 1; }; diff --git a/src/mds/MDCache.h b/src/mds/MDCache.h index 9a8c1b9456f4..660b0e0f60af 100644 --- a/src/mds/MDCache.h +++ b/src/mds/MDCache.h @@ -1172,7 +1172,7 @@ public: void discard_delayed_expire(CDir *dir); protected: - int dump_cache(const char *fn, Formatter *f); + int dump_cache(std::string_view fn, Formatter *f); public: int dump_cache() { return dump_cache(NULL, NULL); } int dump_cache(std::string_view filename);