return 0;
}
+void MDCache::dump_tree(CInode *in, const int cur_depth, const int max_depth, Formatter *f)
+{
+ assert(in);
+ if ((max_depth >= 0) && (cur_depth > max_depth)) {
+ return;
+ }
+ list<CDir*> ls;
+ in->get_dirfrags(ls);
+ for (const auto &subdir : ls) {
+ for (const auto &p : subdir->items) {
+ CDentry *dn = p.second;
+ CInode *in = dn->get_linkage()->get_inode();
+ if (in) {
+ dump_tree(in, cur_depth + 1, max_depth, f);
+ }
+ }
+ }
+ f->open_object_section("inode");
+ in->dump(f);
+ f->close_section();
+}
+
int MDCache::dump_cache(std::string_view file_name)
{
return dump_cache(file_name, NULL);
return dump_cache(std::string_view(""), f);
}
-int MDCache::dump_cache(std::string_view dump_root, int depth, Formatter *f)
-{
- return dump_cache(std::string_view(""), f, dump_root, depth);
-}
-
/**
* Dump the metadata cache, either to a Formatter, if
* provided, else to a plain text file.
*/
-int MDCache::dump_cache(std::string_view fn, Formatter *f,
- std::string_view dump_root, int depth)
+int MDCache::dump_cache(const char *fn, Formatter *f)
{
int r = 0;
int fd = -1;
}
}
- auto dump_func = [fd, f, depth, &dump_root](CInode *in) {
+ auto dump_func = [fd, f](CInode *in) {
int r;
- if (!dump_root.empty()) {
- string ipath;
- if (in->is_root())
- ipath = "/";
- else
- in->make_path_string(ipath);
-
- if (dump_root.length() > ipath.length() ||
- !equal(dump_root.begin(), dump_root.end(), ipath.begin()))
- return 0;
-
- if (depth >= 0 &&
- count(ipath.begin() + dump_root.length(), ipath.end(), '/') > depth)
- return 0;
- }
-
if (f) {
f->open_object_section("inode");
in->dump(f);
void discard_delayed_expire(CDir *dir);
protected:
- int dump_cache(std::string_view fn, Formatter *f,
- std::string_view dump_root = "",
- int depth = -1);
+ int dump_cache(const char *fn, Formatter *f);
public:
int dump_cache() { return dump_cache(NULL, NULL); }
int dump_cache(std::string_view filename);
int dump_cache(Formatter *f);
- int dump_cache(std::string_view dump_root, int depth, Formatter *f);
+ void dump_tree(CInode *in, const int cur_depth, const int max_depth, Formatter *f);
int cache_status(Formatter *f);
ss << "Failed to get cache status: " << cpp_strerror(r);
}
} else if (command == "dump tree") {
- string root;
- int64_t depth;
- cmd_getval(g_ceph_context, cmdmap, "root", root);
- if (!cmd_getval(g_ceph_context, cmdmap, "depth", depth))
- depth = -1;
- {
- Mutex::Locker l(mds_lock);
- int r = mdcache->dump_cache(root, depth, f);
- if (r != 0) {
- ss << "Failed to dump tree: " << cpp_strerror(r);
- f->reset();
- }
- }
+ command_dump_tree(cmdmap, ss, f);
} else if (command == "dump loads") {
Mutex::Locker l(mds_lock);
int r = balancer->dump_loads(f);
return 0;
}
+void MDSRank::command_dump_tree(const cmdmap_t &cmdmap, std::ostream &ss, Formatter *f)
+{
+ std::string root;
+ int64_t depth;
+ cmd_getval(g_ceph_context, cmdmap, "root", root);
+ if (!cmd_getval(g_ceph_context, cmdmap, "depth", depth))
+ depth = -1;
+ Mutex::Locker l(mds_lock);
+ CInode *in = mdcache->cache_traverse(filepath(root.c_str()));
+ if (!in) {
+ ss << "root inode is not in cache";
+ return;
+ }
+ f->open_array_section("inodes");
+ mdcache->dump_tree(in, 0, depth, f);
+ f->close_section();
+}
+
CDir *MDSRank::_command_dirfrag_get(
const cmdmap_t &cmdmap,
std::ostream &ss)
const cmdmap_t &cmdmap,
std::ostream &ss);
void command_openfiles_ls(Formatter *f);
+ void command_dump_tree(const cmdmap_t &cmdmap, std::ostream &ss, Formatter *f);
protected:
Messenger *messenger;