]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
client: add make_path_string() helpers support
authorXiubo Li <xiubli@redhat.com>
Tue, 25 Apr 2023 09:31:25 +0000 (17:31 +0800)
committerXiubo Li <xiubli@redhat.com>
Wed, 27 Mar 2024 00:42:41 +0000 (08:42 +0800)
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 <xiubli@redhat.com>
(cherry picked from commit fd7aaab290728e47ff699063fa26ad63f848bbf1)

src/client/Dentry.h
src/client/Inode.cc
src/client/Inode.h

index 8003dfed34be5d43427b8a04ecf3ab1d1c2089f5..c66aca6f1e04ef878051e02a9b37b64bdfe8baf6 100644 (file)
@@ -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);
 
index 0c19bef5e181468a72472b7760321533dbce0b98..cb30d4940e0bf2569ef1cdb65242af53db9b219d 100644 (file)
@@ -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
index d28ff2e081b29dc3bd272e0b94e9a0f9818aa710..f330824116530a3011d2a30832e3a167fdc0ca0c 100644 (file)
@@ -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,