From: Rishabh Dave Date: Tue, 2 Sep 2025 17:37:36 +0000 (+0530) Subject: client: trim path before logging it X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=0cedc4d7b19bca7e0cde0970abdc3c93ddfc1ff5;p=ceph-ci.git client: trim path before logging it Path can be virtually infinitely long and logging a long long path (imagine around 2000 path components) is un-useful as well as lowers readability of the log. Therefore, trim before logging. Fixes: https://tracker.ceph.com/issues/72993 Signed-off-by: Rishabh Dave --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 107419b7d8b..6f2796967b3 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -7689,6 +7689,20 @@ int Client::path_walk(InodeRef dirinode, const filepath& origpath, InodeRef *end return rc; } +/* Trim given path to final 10 components and return it by prefixing it with + * "..." to indicate that the path has been trimmed. */ +std::string Client::get_trimmed_path(std::string path) +{ + std::size_t n = 0; + for (int i = 1; i <= 10; ++i) { + n = path.rfind("/", n - 1); + if (n == std::string::npos) + return path; + } + + return "..." + path.substr(n, -1); +} + int Client::path_walk(InodeRef dirinode, const filepath& origpath, walk_dentry_result* result, const UserPerm& perms, const PathWalk_ExtraOptions& extra_options) { int rc = 0; @@ -7713,7 +7727,9 @@ int Client::path_walk(InodeRef dirinode, const filepath& origpath, walk_dentry_r int symlinks = 0; unsigned i = 0; - ldout(cct, 10) << __func__ << ": cur=" << *diri << " path=" << path << dendl; + std::string trimmed_path = get_trimmed_path(path.get_path()); + + ldout(cct, 10) << __func__ << ": cur=" << *diri << " path=" << trimmed_path << dendl; if (path.depth() == 0) { /* diri/dname can also be used as a filepath; or target */ @@ -7727,7 +7743,7 @@ int Client::path_walk(InodeRef dirinode, const filepath& origpath, walk_dentry_r int caps = 0; dname = path[i]; ldout(cct, 10) << " " << i << " " << *diri << " " << dname << dendl; - ldout(cct, 20) << " (path is " << path << ")" << dendl; + ldout(cct, 20) << " (path is " << trimmed_path << ")" << dendl; InodeRef next; if (!diri.get()->is_dir()) { ldout(cct, 20) << diri.get() << " is not a dir inode, name " << dname.c_str() << dendl; @@ -15420,7 +15436,7 @@ int Client::ll_unlink(Inode *in, const char *name, const UserPerm& perm) int Client::_rmdir(Inode *dir, const char *name, const UserPerm& perms, bool check_perms) { - ldout(cct, 8) << "_rmdir(" << dir->ino << " " << name << " uid " + ldout(cct, 8) << "_rmdir(" << dir->ino << " " << get_trimmed_path(name) << " uid " << perms.uid() << " gid " << perms.gid() << ")" << dendl; walk_dentry_result wdr; diff --git a/src/client/Client.h b/src/client/Client.h index 6b7b4c7dbfa..a1ac690bb05 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -1881,6 +1881,8 @@ private: void update_io_stat_read(utime_t latency); void update_io_stat_write(utime_t latency); + std::string get_trimmed_path(std::string path); + bool should_check_perms() const { return (is_fuse && !fuse_default_permissions) || (!is_fuse && client_permissions); }