]> 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>
Wed, 1 Oct 2025 19:01:46 +0000 (00:31 +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.

Signed-off-by: Rishabh Dave <ridave@redhat.com>
src/client/Client.cc
src/client/Client.h

index 4d802fa5d60290dc75382bac8abd411d87ffb2c9..25c698cef01101480b48de8a83d3abba4ea5029d 100644 (file)
@@ -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;
index 0847ea5c69e95ee6c966f0a37af8bcc686361326..e19416bb21ab7357bcb90fb304cd6d31c0d73587 100644 (file)
@@ -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);
   }