* 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)
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
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);
};
return NULL;
}
-void CInode::get_dirfrags(std::list<CDir*>& ls)
+void CInode::get_dirfrags(std::list<CDir*>& ls) const
{
// all dirfrags
for (const auto &p : dirfrags) {
}
f->close_section();
}
+
+ if (flags & DUMP_DIRFRAGS) {
+ f->open_array_section("dirfrags");
+ list<CDir*> 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 *****/
static const int DUMP_STATE = (1 << 3);
static const int DUMP_CAPS = (1 << 4);
static const int DUMP_PATH = (1 << 5);
+ static const int DUMP_DIRFRAGS = (1 << 6);
static const int DUMP_ALL = (-1);
- static const int DUMP_DEFAULT = DUMP_ALL & (~DUMP_PATH);
+ static const int DUMP_DEFAULT = DUMP_ALL & (~DUMP_PATH) & (~DUMP_DIRFRAGS);
// -- state --
static const int STATE_EXPORTING = (1<<2); // on nonauth bystander.
}
bool get_dirfrags_under(frag_t fg, std::list<CDir*>& ls);
CDir* get_approx_dirfrag(frag_t fg);
- void get_dirfrags(std::list<CDir*>& ls);
+ void get_dirfrags(std::list<CDir*>& ls) const;
void get_nested_dirfrags(std::list<CDir*>& ls);
void get_subtree_dirfrags(std::list<CDir*>& ls);
CDir *get_or_open_dirfrag(MDCache *mdcache, frag_t fg);
}
}
f->open_object_section("inode");
- in->dump(f);
+ in->dump(f, CInode::DUMP_DEFAULT | CInode::DUMP_DIRFRAGS);
f->close_section();
}
* 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;
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<CDir*> dfs;
in->get_dirfrags(dfs);
- if (f) {
- f->open_array_section("dirfrags");
- }
- for (list<CDir*>::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;
};
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);