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=16e955f49f6c14ac70aa3208e0c93a30aab70661;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. Signed-off-by: Rishabh Dave --- diff --git a/src/client/Client.cc b/src/client/Client.cc index 4d802fa5d60..25c698cef01 100644 --- a/src/client/Client.cc +++ b/src/client/Client.cc @@ -7729,6 +7729,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; @@ -7753,7 +7767,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 */ @@ -7767,7 +7783,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; @@ -15471,7 +15487,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 0847ea5c69e..e19416bb21a 100644 --- a/src/client/Client.h +++ b/src/client/Client.h @@ -1920,6 +1920,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); }