From: taodd Date: Thu, 14 Jun 2018 13:13:46 +0000 (+0800) Subject: mds: add dump inode command X-Git-Tag: v14.0.1~1081^2~1 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=f3d484b8dff0e522fc056cf71b29422bbb647fc4;p=ceph.git 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 --- diff --git a/src/mds/MDCache.cc b/src/mds/MDCache.cc index 43628c36655e..26d76c52a098 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 1b2379d7816b..cfe656a803b1 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 0bc7cf68d911..c40a3cb00683 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 10cfc04a2143..22112143def0 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 60a624bebf86..69a40ce3fda2 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;