]> 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>
Thu, 16 Oct 2025 06:09:26 +0000 (11:39 +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>
(cherry picked from commit bdc8aae400fbbdd61df811455d49176deab1f331)

Conflicts:
src/include/filepath.cc
src/include/filepath.h
- Unlink main branch, filepath.cc is absent in this branch. Therefore,
  the changes must be moved to filepath.h.

src/client/Client.cc
src/client/Client.h
src/include/filepath.h

index e76cd9abc508584476900aa0bcb40917a7e15ccd..4e7e5ad2865ba7c4678194df9e2bef7f66b6a455 100644 (file)
@@ -7663,7 +7663,10 @@ int Client::path_walk(InodeRef dirinode, const filepath& origpath, InodeRef *end
   return rc;
 }
 
-int Client::path_walk(InodeRef dirinode, const filepath& origpath, walk_dentry_result* result, const UserPerm& perms, const PathWalk_ExtraOptions& extra_options)
+int Client::path_walk(InodeRef dirinode, const filepath& origpath,
+                     walk_dentry_result* result, const UserPerm& perms,
+                     const PathWalk_ExtraOptions& extra_options,
+                     std::string trimmed_path)
 {
   int rc = 0;
   filepath path = origpath;
@@ -7687,7 +7690,11 @@ 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;
+  if (trimmed_path == "") {
+    std::string trimmed_path = path.get_trimmed_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 */
@@ -7701,7 +7708,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 (should_check_perms()) {
       int r = may_lookup(diri.get(), perms);
@@ -15305,11 +15312,12 @@ 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 "
+  std::string trimmed_path = filepath(name).get_trimmed_path();
+  ldout(cct, 8) << "_rmdir(" << dir->ino << " " << trimmed_path << " uid "
                << perms.uid() << " gid " << perms.gid() << ")" << dendl;
 
   walk_dentry_result wdr;
-  if (int rc = path_walk(dir, filepath(name), &wdr, perms, {.followsym = false}); rc < 0) {
+  if (int rc = path_walk(dir, filepath(name), &wdr, perms, {.followsym = false}, trimmed_path); rc < 0) {
     return rc;
   }
 
index 1569fed6be5d23a2092ce498237bb9dfea0fd618..a5f6c56d2a3e0af90ee69c92fc88da3509f76f7b 100644 (file)
@@ -1062,7 +1062,7 @@ protected:
     bool is_rename = false;
     bool require_target = true;
   };
-  int path_walk(InodeRef dirinode, const filepath& fp, struct walk_dentry_result* result, const UserPerm& perms, const PathWalk_ExtraOptions& extra_options);
+  int path_walk(InodeRef dirinode, const filepath& fp, struct walk_dentry_result* result, const UserPerm& perms, const PathWalk_ExtraOptions& extra_options, std::string trimmed_path=std::string());
   int path_walk(InodeRef dirinode, const filepath& fp, InodeRef *end, const UserPerm& perms, const PathWalk_ExtraOptions& extra_options);
 
   // fake inode number for 32-bits ino_t
index 92d4b06b2b0eb71519f67bd7f4e4fb94db4743f5..be13ad427fa2b92d83a5f333e9b5a7d656df07f6 100644 (file)
@@ -104,6 +104,21 @@ class filepath {
     trimmed = true;
   }
 
+  /* Trim given path to final 10 components and return it by prefixing it with
+   * "..."  to indicate that the path has been trimmed. */
+  std::string get_trimmed_path() const
+  {
+    std::size_t n = 0;
+    for (int i = 1; i <= 10; ++i) {
+      n = path.rfind("/", n - 1);
+      if (n == std::string::npos) {
+       return std::string(path);
+      }
+    }
+
+    return std::string("..." + path.substr(n, -1));
+  }
+
   void set_path(std::string_view s, inodeno_t b) {
     path = s;
     ino = b;