From 145c98148b34aa2a5dd11a50d2370e937feda27e Mon Sep 17 00:00:00 2001 From: Rishabh Dave Date: Sun, 17 Aug 2025 23:43:40 +0530 Subject: [PATCH] mds: for logging generate only 10 final components of inode path Generating full absolute path for inodes for printing in MDS logs slows down the FS to a great extent especially when the path is very long (imagine a path with 2000 components). Also printing such long paths in MDS logs is not only pointless but also greatly reduces the readability of the MDS logs. Therefore, generate only 10 final components of inode paths for logging. Fixes: https://tracker.ceph.com/issues/72779 Signed-off-by: Rishabh Dave --- src/mds/CDentry.cc | 5 +++-- src/mds/CDentry.h | 3 ++- src/mds/CInode.cc | 32 ++++++++++++++++++++++++++++---- src/mds/CInode.h | 4 +++- 4 files changed, 36 insertions(+), 8 deletions(-) diff --git a/src/mds/CDentry.cc b/src/mds/CDentry.cc index d373f82aa22..d2796d4c709 100644 --- a/src/mds/CDentry.cc +++ b/src/mds/CDentry.cc @@ -300,10 +300,11 @@ void CDentry::clear_auth() } } -void CDentry::make_path_string(string& s, bool projected) const +void CDentry::make_path_string(string& s, bool projected, + int path_comp_count) const { if (dir) { - dir->inode->make_path_string(s, projected); + dir->inode->make_path_string(s, projected, NULL, path_comp_count); } else { s = "???"; } diff --git a/src/mds/CDentry.h b/src/mds/CDentry.h index 26c56fc2d3b..67cf9323666 100644 --- a/src/mds/CDentry.h +++ b/src/mds/CDentry.h @@ -252,7 +252,8 @@ public: const CDentry& operator= (const CDentry& right); // misc - void make_path_string(std::string& s, bool projected=false) const; + void make_path_string(std::string& s, bool projected=false, + int path_comp_count=-1) const; void make_path(filepath& fp, bool projected=false) const; // -- version -- diff --git a/src/mds/CInode.cc b/src/mds/CInode.cc index 244f348b253..6d99ccd7a65 100644 --- a/src/mds/CInode.cc +++ b/src/mds/CInode.cc @@ -177,7 +177,7 @@ int num_cinode_locks = sizeof(cinode_lock_info) / sizeof(cinode_lock_info[0]); ostream& operator<<(ostream& out, const CInode& in) { string path; - in.make_path_string(path, true); + in.make_path_string(path, false, NULL, 10); out << "[inode " << in.ino(); out << " [" @@ -1096,14 +1096,38 @@ bool CInode::is_projected_ancestor_of(const CInode *other) const * inode is used all the way up the path chain. Otherwise the primary parent * stable inode is used. */ -void CInode::make_path_string(string& s, bool projected, const CDentry *use_parent) const -{ +void CInode::make_path_string(string& s, bool projected, + const CDentry *use_parent, + int path_comp_count) const +{ + /* path_comp_count = path components count. default value is -1, which implies + * generate full path. + * + * XXX Generating more than 10 components of a path for printing in logs will + * consume too much time when the path is too long (imagine a path with 2000 + * components) since the path would've to be generated indidividually for each + * log entry. + * + * Besides consuming too much time, such long paths in logs are not only not + * useful but also it makes reading logs harder. Therefore, shorten the path + * when used for logging. + */ + if (!use_parent) { use_parent = projected ? get_projected_parent_dn() : parent; } if (use_parent) { - use_parent->make_path_string(s, projected); + if (path_comp_count == -1) { + use_parent->make_path_string(s, projected, path_comp_count); + } else if (path_comp_count >= 1) { + --path_comp_count; + use_parent->make_path_string(s, projected, path_comp_count); + } else if (path_comp_count == 0) { + // this indicates that path has been shortened. + s = "..."; + return; + } } else if (is_root()) { s = ""; } else if (is_mdsdir()) { diff --git a/src/mds/CInode.h b/src/mds/CInode.h index f87fd408104..b00a2a22cd0 100644 --- a/src/mds/CInode.h +++ b/src/mds/CInode.h @@ -742,7 +742,9 @@ class CInode : public MDSCacheObject, public InodeStoreBase, public Counter* visited=nullptr) const; bool is_projected_ancestor_of(const CInode *other) const; - void make_path_string(std::string& s, bool projected=false, const CDentry *use_parent=NULL) const; + void make_path_string(std::string& s, bool projected=false, + const CDentry *use_parent=NULL, + int path_comp_count=-1) const; void make_path(filepath& s, bool projected=false) const; void name_stray_dentry(std::string& dname); -- 2.39.5