From 6ca8e479925067bc374483f754e88eabaf79a872 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 (cherry picked from commit f3d484b8dff0e522fc056cf71b29422bbb647fc4) --- 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 d28a98185e3b2..40bf2f4b8a2a8 100644 --- a/src/mds/MDCache.cc +++ b/src/mds/MDCache.cc @@ -13078,3 +13078,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 c8e4f34c6f19e..536e8e7acc582 100644 --- a/src/mds/MDCache.h +++ b/src/mds/MDCache.h @@ -545,6 +545,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 de118eebd337c..b0a605957e41d 100644 --- a/src/mds/MDSDaemon.cc +++ b/src/mds/MDSDaemon.cc @@ -328,6 +328,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 bd376ebb43cc4..0964f5d57ab21 100644 --- a/src/mds/MDSRank.cc +++ b/src/mds/MDSRank.cc @@ -2578,6 +2578,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; } @@ -3000,6 +3002,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 3837536ddfafd..1124d405c830f 100644 --- a/src/mds/MDSRank.h +++ b/src/mds/MDSRank.h @@ -485,6 +485,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); void cache_drop_send_reply(Formatter *f, C_MDS_Send_Command_Reply *reply, int r); void command_cache_drop(uint64_t timeout, Formatter *f, Context *on_finish); -- 2.39.5