]> git.apps.os.sepia.ceph.com Git - ceph-ci.git/commitdiff
mds: log trimmed path wherever generating full path is necessary
authorRishabh Dave <ridave@redhat.com>
Tue, 23 Sep 2025 06:03:19 +0000 (11:33 +0530)
committerRishabh Dave <ridave@redhat.com>
Tue, 23 Sep 2025 06:06:00 +0000 (11:36 +0530)
Signed-off-by: Rishabh Dave <ridave@redhat.com>
src/mds/CDentry.cc
src/mds/CDentry.h
src/mds/MDSAuthCaps.cc
src/mds/MDSAuthCaps.h
src/mds/Server.cc
src/mds/SessionMap.cc

index 9a593b60be524cc24d1bc32966605dc362f11519..68d94ef05986f67bfa96f94795ee8fe82f806e05 100644 (file)
@@ -312,6 +312,24 @@ void CDentry::make_path_string(string& s, bool projected,
   s.append(name.data(), name.length());
 }
 
+/* path_comp_count = path component count. default value is 10 which implies
+ * generate entire path.
+ *
+ * XXX Generating more than 10 components of a path for printing in logs will
+ * consume too much time when the path is too long (imagine a path with 2000
+ * components) since the path would've to be generated indidividually for each
+ * log entry.
+ *
+ * Besides consuming too much time, such long paths in logs are not only not
+ * useful but also it makes reading logs harder. Therefore, shorten the path
+ * when used for logging.
+ */
+void CDentry::make_trimmed_path_string(string& s, bool projected,
+                                      int path_comp_count) const
+{
+  make_path_string(s, projected, path_comp_count);
+}
+
 /* path_comp_count = path component count. default value is -1 which implies
  * generate entire path.
  */
index 769ca4bdc75841125ff586ae177456cc651b577a..4c8d5e5edbb7768b4a8ff5f3332a6cc79d9538de 100644 (file)
@@ -252,6 +252,8 @@ public:
   const CDentry& operator= (const CDentry& right);
 
   // misc
+  void make_trimmed_path_string(std::string& s, bool projected,
+                               int path_comp_count=10) const;
   void make_path_string(std::string& s, bool projected=false,
                        int path_comp_count=-1) const;
   void make_path(filepath& fp, bool projected=false,
index f3e6f59d3b8c8c825c223d8d044ad9f86c6fd6e9..47bbebc062e0e9404d960e608a00ebf1a4d8b1b8 100644 (file)
@@ -234,9 +234,11 @@ bool MDSAuthCaps::is_capable(string_view fs_name,
                             const vector<uint64_t> *caller_gid_list,
                             unsigned mask,
                             uid_t new_uid, gid_t new_gid,
-                            const entity_addr_t& addr) const
+                            const entity_addr_t& addr,
+                            string_view trimmed_inode_path) const
 {
-  ldout(g_ceph_context, 10) << __func__ << "fs_name " << fs_name << " inode(path /" << inode_path
+  ldout(g_ceph_context, 10) << __func__ << "fs_name " << fs_name
+                << " inode(path /" << trimmed_inode_path
                 << " owner " << inode_uid << ":" << inode_gid
                 << " mode 0" << std::oct << inode_mode << std::dec
                 << ") by caller " << caller_uid << ":" << caller_gid
index 2f5d71dcd30f014a17ed9d9557378de1fae0a38e..916551143c694be3bb264ab5ad7d4f41e509a30c 100644 (file)
@@ -272,7 +272,7 @@ public:
                  uid_t inode_uid, gid_t inode_gid, unsigned inode_mode,
                  uid_t uid, gid_t gid, const std::vector<uint64_t> *caller_gid_list,
                  unsigned mask, uid_t new_uid, gid_t new_gid,
-                 const entity_addr_t& addr) const;
+                 const entity_addr_t& addr, std::string_view trimmed_inode_path) const;
   bool path_capable(std::string_view inode_path) const;
 
   bool fs_name_capable(std::string_view fs_name, unsigned mask) const {
index fdfd5d3e08ad596ce4eca36183cac4d3a2000eb1..c7b1e0b8e55329666a2b390a8f259e4eda05de4c 100644 (file)
@@ -10190,7 +10190,9 @@ void Server::_rename_prepare(const MDRequestRef& mdr,
       {
         std::string t;
         destdn->make_path_string(t, true);
-        dout(20) << " stray_prior_path = " << t << dendl;
+        std::string trimmed_t;
+        destdn->make_trimmed_path_string(t, true);
+        dout(20) << " stray_prior_path = " << trimmed_t << dendl;
         tpi->stray_prior_path = std::move(t);
       }
       tpi->nlink--;
@@ -10205,7 +10207,9 @@ void Server::_rename_prepare(const MDRequestRef& mdr,
       {
         std::string t;
         destdn->make_path_string(t, true);
-        dout(20) << __func__ << " referent stray_prior_path = " << t << dendl;
+        std::string trimmed_t;
+        destdn->make_trimmed_path_string(t, true);
+        dout(20) << __func__ << " referent stray_prior_path = " << trimmed_t << dendl;
         trpi->stray_prior_path = std::move(t);
       }
     }
index 855c265f4d4f9113f7933d4dde1bfad9922435c2..1cc4ebaf8efaeda02d3592889671e3873b2c8764 100644 (file)
@@ -1122,11 +1122,13 @@ int Session::check_access(std::string_view fs_name, CInode *in, unsigned mask,
     }
   }
 
+  string trimmed_inode_path;
   if (!path.empty()) {
     dout(20) << __func__ << " stray_prior_path " << path << dendl;
   } else {
     in->make_path_string(path, true);
-    dout(20) << __func__ << " path " << path << dendl;
+    in->make_trimmed_path_string(trimmed_inode_path, true);
+    dout(20) << __func__ << " path " << trimmed_inode_path << dendl;
   }
   if (path.length())
     path = path.substr(1);    // drop leading /
@@ -1142,8 +1144,7 @@ int Session::check_access(std::string_view fs_name, CInode *in, unsigned mask,
 
   if (!auth_caps.is_capable(fs_name, path, inode->uid, inode->gid, inode->mode,
                            caller_uid, caller_gid, caller_gid_list, mask,
-                           new_uid, new_gid,
-                           info.inst.addr)) {
+                           new_uid, new_gid, info.inst.addr, trimmed_inode_path)) {
     return -EACCES;
   }
   return 0;