From f3d484b8dff0e522fc056cf71b29422bbb647fc4 Mon Sep 17 00:00:00 2001 From: taodd Date: Thu, 14 Jun 2018 21:13:46 +0800 Subject: [PATCH] mds: add dump inode command dump inode with an specific inode number this is useful when we only known the inode number. Signed-off-by: dongdong tao --- src/mds/MDCache.cc | 10 ++++++++++ src/mds/MDCache.h | 1 + src/mds/MDSDaemon.cc | 6 ++++++ src/mds/MDSRank.cc | 18 ++++++++++++++++++ src/mds/MDSRank.h | 1 + 5 files changed, 36 insertions(+) diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 43628c36655ee..26d76c52a098b 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -12829,3 +12829,13 @@ void MDCache::clear_dirty_bits_for_stray(CInode* diri) { } } +bool MDCache::dump_inode(Formatter *f, uint64_t number) { + CInode *in = get_inode(number); + if (!in) { + return false; + } + f->open_object_section("inode"); + in->dump(f, CInode::DUMP_DEFAULT | CInode::DUMP_PATH); + f->close_section(); + return true; +} diff --git a/src/mds/MDCache.h b/src/mds/MDCache.h index 1b2379d7816b5..cfe656a803b12 100644 --- a/src/mds/MDCache.h +++ b/src/mds/MDCache.h @@ -543,6 +543,7 @@ public: void clean_open_file_lists(); void dump_openfiles(Formatter *f); + bool dump_inode(Formatter *f, uint64_t number); protected: // [rejoin] bool rejoins_pending; diff --git a/src/mds/MDSDaemon.cc b/src/mds/MDSDaemon.cc index 0bc7cf68d9113..c40a3cb00683e 100644 --- a/src/mds/MDSDaemon.cc +++ b/src/mds/MDSDaemon.cc @@ -323,6 +323,12 @@ void MDSDaemon::set_up_admin_socket() asok_hook, "List the opening files and their caps"); assert(r == 0); + r = admin_socket->register_command("dump inode", + "dump inode " + "name=number,type=CephInt,req=true", + asok_hook, + "dump inode by inode number"); + assert(r == 0); } void MDSDaemon::clean_up_admin_socket() diff --git a/src/mds/MDSRank.cc b/src/mds/MDSRank.cc index 10cfc04a2143e..22112143def01 100644 --- a/src/mds/MDSRank.cc +++ b/src/mds/MDSRank.cc @@ -2127,6 +2127,8 @@ bool MDSRankDispatcher::handle_asok_command(std::string_view command, command_dirfrag_ls(cmdmap, ss, f); } else if (command == "openfiles ls") { command_openfiles_ls(f); + } else if (command == "dump inode") { + command_dump_inode(f, cmdmap, ss); } else { return false; } @@ -2657,6 +2659,22 @@ void MDSRank::command_openfiles_ls(Formatter *f) mdcache->dump_openfiles(f); } +void MDSRank::command_dump_inode(Formatter *f, const cmdmap_t &cmdmap, std::ostream &ss) +{ + Mutex::Locker l(mds_lock); + int64_t number; + bool got = cmd_getval(g_ceph_context, cmdmap, "number", number); + if (!got) { + ss << "missing inode number"; + return; + } + + bool success = mdcache->dump_inode(f, number); + if (!success) { + ss << "dump inode failed, wrong inode number or the inode is not cached"; + } +} + void MDSRank::dump_status(Formatter *f) const { if (state == MDSMap::STATE_REPLAY || diff --git a/src/mds/MDSRank.h b/src/mds/MDSRank.h index 60a624bebf86e..69a40ce3fda22 100644 --- a/src/mds/MDSRank.h +++ b/src/mds/MDSRank.h @@ -464,6 +464,7 @@ class MDSRank { std::ostream &ss); void command_openfiles_ls(Formatter *f); void command_dump_tree(const cmdmap_t &cmdmap, std::ostream &ss, Formatter *f); + void command_dump_inode(Formatter *f, const cmdmap_t &cmdmap, std::ostream &ss); protected: Messenger *messenger; -- 2.39.5