Skip to content

Commit

Permalink
Merge pull request #9925 from fullerdj/wip-djf-11171
Browse files Browse the repository at this point in the history
mds: Add path filtering for dump cache

Reviewed-by: John Spray <john.spray@redhat.com>
  • Loading branch information
John Spray committed Jul 28, 2016
2 parents f742113 + d3c591a commit ec6dab7
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 4 deletions.
29 changes: 26 additions & 3 deletions src/mds/MDCache.cc
Expand Up @@ -11673,11 +11673,17 @@ void MDCache::dump_cache(Formatter *f)
dump_cache(NULL, f);
}

void MDCache::dump_cache(const string& dump_root, int depth, Formatter *f)
{
dump_cache(NULL, f, dump_root, depth);
}

/**
* Dump the metadata cache, either to a Formatter, if
* provided, else to a plain text file.
*/
void MDCache::dump_cache(const char *fn, Formatter *f)
void MDCache::dump_cache(const char *fn, Formatter *f,
const string& dump_root, int depth)
{
int r = 0;
int fd = -1;
Expand All @@ -11699,11 +11705,28 @@ void MDCache::dump_cache(const char *fn, Formatter *f)
return;
}
}

for (ceph::unordered_map<vinodeno_t,CInode*>::iterator it = inode_map.begin();
it != inode_map.end();
++it) {
CInode *in = it->second;

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()))
continue;

if (depth >= 0 &&
count(ipath.begin() + dump_root.length(), ipath.end(), '/') > depth)
continue;
}

if (f) {
f->open_object_section("inode");
in->dump(f);
Expand All @@ -11713,7 +11736,7 @@ void MDCache::dump_cache(const char *fn, Formatter *f)
std::string s = ss.str();
r = safe_write(fd, s.c_str(), s.length());
if (r < 0) {
goto out;
goto out;
}
}

Expand Down
5 changes: 4 additions & 1 deletion src/mds/MDCache.h
Expand Up @@ -1121,11 +1121,14 @@ class MDCache {
void notify_osdmap_changed();

protected:
void dump_cache(const char *fn, Formatter *f);
void dump_cache(const char *fn, Formatter *f,
const std::string& dump_root = "",
int depth = -1);
public:
void dump_cache() {dump_cache(NULL, NULL);}
void dump_cache(const std::string &filename);
void dump_cache(Formatter *f);
void dump_cache(const std::string& dump_root, int depth, Formatter *f);

void dump_resolve_status(Formatter *f) const;
void dump_rejoin_status(Formatter *f) const;
Expand Down
8 changes: 8 additions & 0 deletions src/mds/MDSDaemon.cc
Expand Up @@ -259,6 +259,13 @@ void MDSDaemon::set_up_admin_socket()
asok_hook,
"dump metadata cache (optionally to a file)");
assert(r == 0);
r = admin_socket->register_command("dump tree",
"dump tree "
"name=root,type=CephString,req=true "
"name=depth,type=CephInt,req=false ",
asok_hook,
"dump metadata cache for subtree");
assert(r == 0);
r = admin_socket->register_command("session evict",
"session evict name=client_id,type=CephString",
asok_hook,
Expand Down Expand Up @@ -325,6 +332,7 @@ void MDSDaemon::clean_up_admin_socket()
admin_socket->unregister_command("flush_path");
admin_socket->unregister_command("export dir");
admin_socket->unregister_command("dump cache");
admin_socket->unregister_command("dump tree");
admin_socket->unregister_command("session evict");
admin_socket->unregister_command("osdmap barrier");
admin_socket->unregister_command("session ls");
Expand Down
10 changes: 10 additions & 0 deletions src/mds/MDSRank.cc
Expand Up @@ -1776,6 +1776,16 @@ bool MDSRankDispatcher::handle_asok_command(
} else {
mdcache->dump_cache(path);
}
} 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);
mdcache->dump_cache(root, depth, f);
}
} else if (command == "force_readonly") {
Mutex::Locker l(mds_lock);
mdcache->force_readonly();
Expand Down

0 comments on commit ec6dab7

Please sign in to comment.