From: Xiubo Li Date: Tue, 25 Apr 2023 09:31:25 +0000 (+0800) Subject: client: add make_path_string() helpers support X-Git-Tag: v18.2.4~114^2~16 X-Git-Url: http://git.apps.os.sepia.ceph.com/?a=commitdiff_plain;h=f5bdac14e4fcd616a617e6e63b0fed47e934732b;p=ceph.git client: add make_path_string() helpers support Will use this to get the path string to do the mds auth check. It may fail when the there is no any dentry in local cache, which could be caused by just unlinking the last dentry while the inode keeps opening and then try to change the mode. Fixes: https://tracker.ceph.com/issues/57154 Signed-off-by: Xiubo Li (cherry picked from commit fd7aaab290728e47ff699063fa26ad63f848bbf1) --- diff --git a/src/client/Dentry.h b/src/client/Dentry.h index 8003dfed34be5..c66aca6f1e04e 100644 --- a/src/client/Dentry.h +++ b/src/client/Dentry.h @@ -77,6 +77,21 @@ public: dir = nullptr; } + bool make_path_string(std::string& s) + { + bool ret = false; + + if (dir) { + ret = dir->parent_inode->make_path_string(s); + } else { + s = "???"; + } + s += "/"; + s.append(name.data(), name.length()); + + return ret; + } + void dump(Formatter *f) const; friend std::ostream &operator<<(std::ostream &oss, const Dentry &Dentry); diff --git a/src/client/Inode.cc b/src/client/Inode.cc index 0c19bef5e1814..cb30d4940e0bf 100644 --- a/src/client/Inode.cc +++ b/src/client/Inode.cc @@ -119,6 +119,22 @@ void Inode::make_short_path(filepath& p) p = filepath(ino); } +/* + * make a filepath suitable for mds auth access check: + */ +bool Inode::make_path_string(std::string& s) +{ + if (client->_get_root_ino(false) == ino) { + return true; + } else if (!dentries.empty()) { + Dentry *dn = get_first_parent(); + ceph_assert(dn->dir && dn->dir->parent_inode); + return dn->make_path_string(s); + } + + return false; +} + /* * make a filepath suitable for an mds request: * - if we are non-snapped/live, the ino is sufficient, e.g. #1234 diff --git a/src/client/Inode.h b/src/client/Inode.h index d28ff2e081b29..f330824116530 100644 --- a/src/client/Inode.h +++ b/src/client/Inode.h @@ -252,6 +252,7 @@ struct Inode : RefCountedObject { void make_long_path(filepath& p); void make_short_path(filepath& p); + bool make_path_string(std::string& s); void make_nosnap_relative_path(filepath& p); // The ref count. 1 for each dentry, fh, inode_map,