]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
client: trim path before logging it
authorRishabh Dave <ridave@redhat.com>
Tue, 2 Sep 2025 17:37:36 +0000 (23:07 +0530)
committerRishabh Dave <ridave@redhat.com>
Mon, 22 Sep 2025 10:10:59 +0000 (15:40 +0530)
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 <ridave@redhat.com>
src/client/Client.cc
src/client/Client.h

index 107419b7d8bd99da79579c5ac6e811c088796544..6f2796967b3b960930704d0fcfbb9bf1b6020aa7 100644 (file)
@@ -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;
index 6b7b4c7dbfabae8b164fe8dd7a7f0b3a0e7df3c4..a1ac690bb05dd1d568e10ac403448789104ff8f9 100644 (file)
@@ -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);
   }