From: Rishabh Dave Date: Tue, 23 Sep 2025 06:03:19 +0000 (+0530) Subject: mds: log trimmed path wherever generating full path is necessary X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=c863e7caf1d6345fda1f1477e15e90c7396184dc;p=ceph-ci.git mds: log trimmed path wherever generating full path is necessary Signed-off-by: Rishabh Dave --- diff --git a/src/mds/CDentry.cc b/src/mds/CDentry.cc index 9a593b60be5..68d94ef0598 100644 --- a/src/mds/CDentry.cc +++ b/src/mds/CDentry.cc @@ -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. */ diff --git a/src/mds/CDentry.h b/src/mds/CDentry.h index 769ca4bdc75..4c8d5e5edbb 100644 --- a/src/mds/CDentry.h +++ b/src/mds/CDentry.h @@ -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, diff --git a/src/mds/MDSAuthCaps.cc b/src/mds/MDSAuthCaps.cc index f3e6f59d3b8..47bbebc062e 100644 --- a/src/mds/MDSAuthCaps.cc +++ b/src/mds/MDSAuthCaps.cc @@ -234,9 +234,11 @@ bool MDSAuthCaps::is_capable(string_view fs_name, const vector *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 diff --git a/src/mds/MDSAuthCaps.h b/src/mds/MDSAuthCaps.h index 2f5d71dcd30..916551143c6 100644 --- a/src/mds/MDSAuthCaps.h +++ b/src/mds/MDSAuthCaps.h @@ -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 *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 { diff --git a/src/mds/Server.cc b/src/mds/Server.cc index fdfd5d3e08a..c7b1e0b8e55 100644 --- a/src/mds/Server.cc +++ b/src/mds/Server.cc @@ -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); } } diff --git a/src/mds/SessionMap.cc b/src/mds/SessionMap.cc index 855c265f4d4..1cc4ebaf8ef 100644 --- a/src/mds/SessionMap.cc +++ b/src/mds/SessionMap.cc @@ -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;