Skip to contentSkip to conversation

fuse: share lookup state between submount and its parent

PATCH RESEND Applied Krister Johansen 2 participants 2 messages Nov 3, 2023 – Nov 6, 2023

Subsystems (2)

v4 of 5 Applied Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH RESEND v4 1/1 fuse: share lookup state between submount and its parent

Fuse submounts do not perform a lookup for the nodeid that they inherit from their parent. Instead, the code decrements the nlookup on the submount's fuse_inode when it is instantiated, and no forget is performed when a submount root is evicted.

Trouble arises when the submount's parent is evicted despite the submount itself being in use. In this author's case, the submount was in a container and deatched from the initial mount namespace via a MNT_DEATCH operation. When memory pressure triggered the shrinker, the inode from the parent was evicted, which triggered enough forgets to render the submount's nodeid invalid.

Since submounts should still function, even if their parent goes away, solve this problem by sharing refcounted state between the parent and its submount. When all of the references on this shared state reach zero, it's safe to forget the final lookup of the fuse nodeid.

Fixes 1866d779d5d2 ("fuse: Allow fuse_fill_super_common() for submounts")

---
Changes since v3:

- Remove rcu head from lookup tracking struct along with unnecessary kfree_rcu call. (Feedback from Miklos Szeredi)
- Make nlookup one implicitly. Remove from struct and simplify places where it was being used. (Feedback from Miklos Szeredi)
- Remove unnecessary spinlock acquisition. (Feedback from Miklos Szeredi)
- Add a WARN_ON if the lookup tracking cookie cannot be found during fuse_fill_super_submount. (Feedback from Miklos Szeredi)

Changes since v2:

- Move to an approach where the lookup is shared between the submount's parent and children. Use a reference counted lookup cookie to decide when it is safe to perform the forget of the final reference. (Feedback from Miklos Szeredi)

Changes since v1:

- Cleanups to pacify test robot

Changes since RFC:

- Modified fuse_fill_super_submount to always fail if dentry cannot be revalidated. (Feedback from Bernd Schubert)
- Fixed up an edge case where looked up but subsequently declared invalid dentries were not correctly tracking nlookup. (Error was introduced in my RFC).

---
 fs/fuse/fuse_i.h | 15 ++++++++++
 fs/fuse/inode.c  | 74 ++++++++++++++++++++++++++++++++++++++++++++++--
 2 files changed, 86 insertions(+), 3 deletions(-)
fs/fuse/fuse_i.h +15 -0
index 405252bb51f2..9377c46f14c4 100644
@@ -63,6 +63,19 @@ struct fuse_forget_link {
 	struct fuse_forget_link *next;
 };
 
+/* Submount lookup tracking */
+struct fuse_submount_lookup {
+	/** Refcount */
+	refcount_t count;
+
+	/** Unique ID, which identifies the inode between userspace
+	 * and kernel */
+	u64 nodeid;
+
+	/** The request used for sending the FORGET message */
+	struct fuse_forget_link *forget;
+};
+
 /** FUSE inode */
 struct fuse_inode {
 	/** Inode data */
@@ -158,6 +171,8 @@ struct fuse_inode {
 	 */
 	struct fuse_inode_dax *dax;
 #endif
+	/** Submount specific lookup tracking */
+	struct fuse_submount_lookup *submount_lookup;
 };
 
 /** FUSE inode state bits */
fs/fuse/inode.c +71 -3

136 lines not on this page · raw message

Signature · 1 line
2.25.1
#1 lore raw
Quoted 5 lines · Krister Johansen

Fuse submounts do not perform a lookup for the nodeid that they inherit from their parent. Instead, the code decrements the nlookup on the submount's fuse_inode when it is instantiated, and no forget is performed when a submount root is evicted.

Applied, thanks.

Miklos