Skip to contentSkip to conversation

fuse: remove FUSE_NOTIFY_CODE_MAX from <uapi/linux/fuse.h>

PATCH In review Miklos Szeredi 6 participants 14 messages Sep 2, 2025 – Oct 1, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/4 fuse: remove FUSE_NOTIFY_CODE_MAX from <uapi/linux/fuse.h>

Constants that change value from version to version have no place in an interface definition.

Hopefully this won't break anything.

---
 include/uapi/linux/fuse.h | 1 -
 1 file changed, 1 deletion(-)
include/uapi/linux/fuse.h +0 -1
index 6b9fb8b08768..30bf0846547f 100644
@@ -680,7 +680,6 @@ enum fuse_notify_code {
 	FUSE_NOTIFY_DELETE = 6,
 	FUSE_NOTIFY_RESEND = 7,
 	FUSE_NOTIFY_INC_EPOCH = 8,
-	FUSE_NOTIFY_CODE_MAX,
 };
 
 /* The read buffer is required to be at least 8k, but may be much larger */
Signature · 1 line
2.49.0
#1 lore raw

PATCH 2/4 fuse: fix possibly missing fuse_copy_finish() call in fuse_notify()

In case of FUSE_NOTIFY_RESEND and FUSE_NOTIFY_INC_EPOCH fuse_copy_finish() isn't called.

Fix by always calling fuse_copy_finish() after fuse_notify(). It's a no-op if called a second time.

Fixes 760eac73f9f6 ("fuse: Introduce a new notification type for resend pending requests")
Fixes 2396356a945b ("fuse: add more control over cache invalidation behaviour")
Cc <[email protected]> # v6.9
---
 fs/fuse/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fuse/dev.c +1 -1
index df793003eb0c..85d05a5e40e9 100644
@@ -2178,7 +2178,7 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
 	 */
 	if (!oh.unique) {
 		err = fuse_notify(fc, oh.error, nbytes - sizeof(oh), cs);
-		goto out;
+		goto copy_finish;
 	}
 
 	err = -EINVAL;
Signature · 1 line
2.49.0
Reviewed-by on v1 2/4
#2 lore raw

Re: [PATCH 2/4] fuse: fix possibly missing fuse_copy_finish() call in fuse_notify()

Quoted 11 lines · Miklos Szeredi

In case of FUSE_NOTIFY_RESEND and FUSE_NOTIFY_INC_EPOCH fuse_copy_finish() isn't called.

Fix by always calling fuse_copy_finish() after fuse_notify(). It's a no-op if called a second time.

Fixes 760eac73f9f6 ("fuse: Introduce a new notification type for resend pending requests")
Fixes 2396356a945b ("fuse: add more control over cache invalidation behaviour")
Cc <[email protected]> # v6.9
Quoted 21 lines
---
 fs/fuse/dev.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
fs/fuse/dev.c +1 -2
index df793003eb0c..85d05a5e40e9 100644
@@ -2178,7 +2178,7 @@ static ssize_t fuse_dev_do_write(struct fuse_dev *fud,
         */
        if (!oh.unique) {
                err = fuse_notify(fc, oh.error, nbytes - sizeof(oh), cs);
-               goto out;
+               goto copy_finish;
        }
 
        err = -EINVAL;
--

2.49.0

#3 lore raw

PATCH 3/4 fuse: remove redundant calls to fuse_copy_finish() in fuse_notify()

In reply to Miklos Szeredi

Remove tail calls of fuse_copy_finish(), since it's now done from fuse_dev_do_write().

No functional change.

---
 fs/fuse/dev.c | 79 +++++++++++++++------------------------------------
 1 file changed, 23 insertions(+), 56 deletions(-)
fs/fuse/dev.c +23 -56
index 85d05a5e40e9..1258acee9704 100644
@@ -1622,35 +1622,31 @@ static int fuse_notify_poll(struct fuse_conn *fc, unsigned int size,
 			    struct fuse_copy_state *cs)
 {
 	struct fuse_notify_poll_wakeup_out outarg;
-	int err = -EINVAL;
+	int err;
 
 	if (size != sizeof(outarg))
-		goto err;
+		return -EINVAL;
 
 	err = fuse_copy_one(cs, &outarg, sizeof(outarg));
 	if (err)
-		goto err;
+		return err;
 
 	fuse_copy_finish(cs);
 	return fuse_notify_poll_wakeup(fc, &outarg);
-
-err:
-	fuse_copy_finish(cs);
-	return err;
 }
 
 static int fuse_notify_inval_inode(struct fuse_conn *fc, unsigned int size,
 				   struct fuse_copy_state *cs)
 {
 	struct fuse_notify_inval_inode_out outarg;
-	int err = -EINVAL;
+	int err;
 
 	if (size != sizeof(outarg))
-		goto err;
+		return -EINVAL;
 
 	err = fuse_copy_one(cs, &outarg, sizeof(outarg));
 	if (err)
-		goto err;
+		return err;
 	fuse_copy_finish(cs);
 
 	down_read(&fc->killsb);
@@ -1658,10 +1654,6 @@ static int fuse_notify_inval_inode(struct fuse_conn *fc, unsigned int size,
 				       outarg.off, outarg.len);
 	up_read(&fc->killsb);
 	return err;
-
-err:
-	fuse_copy_finish(cs);
-	return err;
 }
 
 static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
@@ -1669,29 +1661,26 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
 {
 	struct fuse_notify_inval_entry_out outarg;
 	int err;
-	char *buf = NULL;
+	char *buf;
 	struct qstr name;
 
-	err = -EINVAL;
 	if (size < sizeof(outarg))
-		goto err;
+		return -EINVAL;
 
 	err = fuse_copy_one(cs, &outarg, sizeof(outarg));
 	if (err)
-		goto err;
+		return err;
 
-	err = -ENAMETOOLONG;
 	if (outarg.namelen > fc->name_max)
-		goto err;
+		return -ENAMETOOLONG;
 
 	err = -EINVAL;
 	if (size != sizeof(outarg) + outarg.namelen + 1)
-		goto err;
+		return -EINVAL;
 
-	err = -ENOMEM;
 	buf = kzalloc(outarg.namelen + 1, GFP_KERNEL);
 	if (!buf)
-		goto err;
+		return -ENOMEM;
 
 	name.name = buf;
 	name.len = outarg.namelen;
@@ -1704,12 +1693,8 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
 	down_read(&fc->killsb);
 	err = fuse_reverse_inval_entry(fc, outarg.parent, 0, &name, outarg.flags);
 	up_read(&fc->killsb);
-	kfree(buf);
-	return err;
-
 err:
 	kfree(buf);
-	fuse_copy_finish(cs);
 	return err;
 }
 
@@ -1718,29 +1703,25 @@ static int fuse_notify_delete(struct fuse_conn *fc, unsigned int size,
 {
 	struct fuse_notify_delete_out outarg;
 	int err;
-	char *buf = NULL;
+	char *buf;
 	struct qstr name;
 
-	err = -EINVAL;
 	if (size < sizeof(outarg))
-		goto err;
+		return -EINVAL;
 
 	err = fuse_copy_one(cs, &outarg, sizeof(outarg));
 	if (err)
-		goto err;
+		return err;
 
-	err = -ENAMETOOLONG;
 	if (outarg.namelen > fc->name_max)
-		goto err;
+		return -ENAMETOOLONG;
 
-	err = -EINVAL;
 	if (size != sizeof(outarg) + outarg.namelen + 1)
-		goto err;
+		return -EINVAL;
 
-	err = -ENOMEM;
 	buf = kzalloc(outarg.namelen + 1, GFP_KERNEL);
 	if (!buf)
-		goto err;
+		return -ENOMEM;
 
 	name.name = buf;
 	name.len = outarg.namelen;
@@ -1753,12 +1734,8 @@ static int fuse_notify_delete(struct fuse_conn *fc, unsigned int size,
 	down_read(&fc->killsb);
 	err = fuse_reverse_inval_entry(fc, outarg.parent, outarg.child, &name, 0);
 	up_read(&fc->killsb);
-	kfree(buf);
-	return err;
-
 err:
 	kfree(buf);
-	fuse_copy_finish(cs);
 	return err;
 }
 
@@ -1776,17 +1753,15 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
 	loff_t file_size;
 	loff_t end;
 
-	err = -EINVAL;
 	if (size < sizeof(outarg))
-		goto out_finish;
+		return -EINVAL;
 
 	err = fuse_copy_one(cs, &outarg, sizeof(outarg));
 	if (err)
-		goto out_finish;
+		return err;
 
-	err = -EINVAL;
 	if (size - sizeof(outarg) != outarg.size)
-		goto out_finish;
+		return -EINVAL;
 
 	nodeid = outarg.nodeid;
 
@@ -1846,8 +1821,6 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
 	iput(inode);
 out_up_killsb:
 	up_read(&fc->killsb);
-out_finish:
-	fuse_copy_finish(cs);
 	return err;
 }
 
@@ -1962,13 +1935,12 @@ static int fuse_notify_retrieve(struct fuse_conn *fc, unsigned int size,
 	u64 nodeid;
 	int err;
 
-	err = -EINVAL;
 	if (size != sizeof(outarg))
-		goto copy_finish;
+		return -EINVAL;
 
 	err = fuse_copy_one(cs, &outarg, sizeof(outarg));
 	if (err)
-		goto copy_finish;
+		return err;
 
 	fuse_copy_finish(cs);
 
@@ -1984,10 +1956,6 @@ static int fuse_notify_retrieve(struct fuse_conn *fc, unsigned int size,
 	up_read(&fc->killsb);
 
 	return err;
-
-copy_finish:
-	fuse_copy_finish(cs);
-	return err;
 }
 
 /*
@@ -2098,7 +2066,6 @@ static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code,
 		return fuse_notify_inc_epoch(fc);
 
 	default:
-		fuse_copy_finish(cs);
 		return -EINVAL;
 	}
 }
Signature · 1 line
2.49.0
Reviewed-by on v1 3/4
#4 lore raw

Re: [PATCH 3/4] fuse: remove redundant calls to fuse_copy_finish() in fuse_notify()

Quoted 7 lines · Miklos Szeredi

Remove tail calls of fuse_copy_finish(), since it's now done from fuse_dev_do_write().

No functional change.

Quoted 15 lines
---
 fs/fuse/dev.c | 79 +++++++++++++++------------------------------------
 1 file changed, 23 insertions(+), 56 deletions(-)
fs/fuse/dev.c +1 -1
index 85d05a5e40e9..1258acee9704 100644
@@ -1622,35 +1622,31 @@ static int fuse_notify_poll(struct fuse_conn *fc, unsigned int size,
                            struct fuse_copy_state *cs)
 {
        struct fuse_notify_poll_wakeup_out outarg;
-       int err = -EINVAL;
+       int err;
 

fs/fuse/dev.c static int fuse_notify_poll(struct fuse_conn *fc, unsigned int size, · line 1634

Quoted 10 lines
fs/fuse/dev.c +2 -2
        if (size != sizeof(outarg))
-               goto err;
+               return -EINVAL;
 
        err = fuse_copy_one(cs, &outarg, sizeof(outarg));
        if (err)
-               goto err;
+               return err;
 
        fuse_copy_finish(cs);

Maybe worth also removing fuse_copy_finish() here (and for the other notify handlers) since it's going to get called anyways?

Thanks,
Joanne

Quoted 2 lines
fs/fuse/dev.c +0 -1
        return fuse_notify_poll_wakeup(fc, &outarg);
-
#5 lore raw

Re: [PATCH 3/4] fuse: remove redundant calls to fuse_copy_finish() in fuse_notify()

In reply to Miklos Szeredi
Quoted 44 lines · Miklos Szeredi

Remove tail calls of fuse_copy_finish(), since it's now done from fuse_dev_do_write().

No functional change.

---
 fs/fuse/dev.c | 79 +++++++++++++++------------------------------------
 1 file changed, 23 insertions(+), 56 deletions(-)
fs/fuse/dev.c +4 -8
index 85d05a5e40e9..1258acee9704 100644
@@ -1622,35 +1622,31 @@ static int fuse_notify_poll(struct fuse_conn *fc, unsigned int size,
 			    struct fuse_copy_state *cs)
 {
 	struct fuse_notify_poll_wakeup_out outarg;
-	int err = -EINVAL;
+	int err;
 
 	if (size != sizeof(outarg))
-		goto err;
+		return -EINVAL;
 
 	err = fuse_copy_one(cs, &outarg, sizeof(outarg));
 	if (err)
-		goto err;
+		return err;
 
 	fuse_copy_finish(cs);
 	return fuse_notify_poll_wakeup(fc, &outarg);
-
-err:
-	fuse_copy_finish(cs);
-	return err;
 }
 
 static int fuse_notify_inval_inode(struct fuse_conn *fc, unsigned int size,
 				   struct fuse_copy_state *cs)
 {
 	struct fuse_notify_inval_inode_out outarg;
-	int err = -EINVAL;
+	int err;

fs/fuse/dev.c static int fuse_notify_poll(struct fuse_conn *fc, unsigned int size, · line 1650

Quoted 10 lines
fs/fuse/dev.c +2 -2
 
 	if (size != sizeof(outarg))
-		goto err;
+		return -EINVAL;
 
 	err = fuse_copy_one(cs, &outarg, sizeof(outarg));
 	if (err)
-		goto err;
+		return err;
 	fuse_copy_finish(cs);

I wonder if these extra fuse_copy_finish() calls should also be removed. It doesn't seem to be a problem to call it twice, but maybe it's not needed, or am I missing something? This happens in a few places.

Other than that, and FWIW, the series look good to me.

Cheers,

Signature · 1 line
Luís
Quoted 179 lines
fs/fuse/dev.c +17 -46
 	down_read(&fc->killsb);
@@ -1658,10 +1654,6 @@ static int fuse_notify_inval_inode(struct fuse_conn *fc, unsigned int size,
 				       outarg.off, outarg.len);
 	up_read(&fc->killsb);
 	return err;
-
-err:
-	fuse_copy_finish(cs);
-	return err;
 }
 
 static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
@@ -1669,29 +1661,26 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
 {
 	struct fuse_notify_inval_entry_out outarg;
 	int err;
-	char *buf = NULL;
+	char *buf;
 	struct qstr name;
 
-	err = -EINVAL;
 	if (size < sizeof(outarg))
-		goto err;
+		return -EINVAL;
 
 	err = fuse_copy_one(cs, &outarg, sizeof(outarg));
 	if (err)
-		goto err;
+		return err;
 
-	err = -ENAMETOOLONG;
 	if (outarg.namelen > fc->name_max)
-		goto err;
+		return -ENAMETOOLONG;
 
 	err = -EINVAL;
 	if (size != sizeof(outarg) + outarg.namelen + 1)
-		goto err;
+		return -EINVAL;
 
-	err = -ENOMEM;
 	buf = kzalloc(outarg.namelen + 1, GFP_KERNEL);
 	if (!buf)
-		goto err;
+		return -ENOMEM;
 
 	name.name = buf;
 	name.len = outarg.namelen;
@@ -1704,12 +1693,8 @@ static int fuse_notify_inval_entry(struct fuse_conn *fc, unsigned int size,
 	down_read(&fc->killsb);
 	err = fuse_reverse_inval_entry(fc, outarg.parent, 0, &name, outarg.flags);
 	up_read(&fc->killsb);
-	kfree(buf);
-	return err;
-
 err:
 	kfree(buf);
-	fuse_copy_finish(cs);
 	return err;
 }
 
@@ -1718,29 +1703,25 @@ static int fuse_notify_delete(struct fuse_conn *fc, unsigned int size,
 {
 	struct fuse_notify_delete_out outarg;
 	int err;
-	char *buf = NULL;
+	char *buf;
 	struct qstr name;
 
-	err = -EINVAL;
 	if (size < sizeof(outarg))
-		goto err;
+		return -EINVAL;
 
 	err = fuse_copy_one(cs, &outarg, sizeof(outarg));
 	if (err)
-		goto err;
+		return err;
 
-	err = -ENAMETOOLONG;
 	if (outarg.namelen > fc->name_max)
-		goto err;
+		return -ENAMETOOLONG;
 
-	err = -EINVAL;
 	if (size != sizeof(outarg) + outarg.namelen + 1)
-		goto err;
+		return -EINVAL;
 
-	err = -ENOMEM;
 	buf = kzalloc(outarg.namelen + 1, GFP_KERNEL);
 	if (!buf)
-		goto err;
+		return -ENOMEM;
 
 	name.name = buf;
 	name.len = outarg.namelen;
@@ -1753,12 +1734,8 @@ static int fuse_notify_delete(struct fuse_conn *fc, unsigned int size,
 	down_read(&fc->killsb);
 	err = fuse_reverse_inval_entry(fc, outarg.parent, outarg.child, &name, 0);
 	up_read(&fc->killsb);
-	kfree(buf);
-	return err;
-
 err:
 	kfree(buf);
-	fuse_copy_finish(cs);
 	return err;
 }
 
@@ -1776,17 +1753,15 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
 	loff_t file_size;
 	loff_t end;
 
-	err = -EINVAL;
 	if (size < sizeof(outarg))
-		goto out_finish;
+		return -EINVAL;
 
 	err = fuse_copy_one(cs, &outarg, sizeof(outarg));
 	if (err)
-		goto out_finish;
+		return err;
 
-	err = -EINVAL;
 	if (size - sizeof(outarg) != outarg.size)
-		goto out_finish;
+		return -EINVAL;
 
 	nodeid = outarg.nodeid;
 
@@ -1846,8 +1821,6 @@ static int fuse_notify_store(struct fuse_conn *fc, unsigned int size,
 	iput(inode);
 out_up_killsb:
 	up_read(&fc->killsb);
-out_finish:
-	fuse_copy_finish(cs);
 	return err;
 }
 
@@ -1962,13 +1935,12 @@ static int fuse_notify_retrieve(struct fuse_conn *fc, unsigned int size,
 	u64 nodeid;
 	int err;
 
-	err = -EINVAL;
 	if (size != sizeof(outarg))
-		goto copy_finish;
+		return -EINVAL;
 
 	err = fuse_copy_one(cs, &outarg, sizeof(outarg));
 	if (err)
-		goto copy_finish;
+		return err;
 
 	fuse_copy_finish(cs);
 
@@ -1984,10 +1956,6 @@ static int fuse_notify_retrieve(struct fuse_conn *fc, unsigned int size,
 	up_read(&fc->killsb);
 
 	return err;
-
-copy_finish:
-	fuse_copy_finish(cs);
-	return err;
 }
 
 /*
@@ -2098,7 +2066,6 @@ static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code,
 		return fuse_notify_inc_epoch(fc);
 
 	default:
-		fuse_copy_finish(cs);
 		return -EINVAL;
 	}
 }
Signature · 1 line
2.49.0
maintainer
#6 lore raw

Re: [PATCH 3/4] fuse: remove redundant calls to fuse_copy_finish() in fuse_notify()

Quoted 3 lines · Luis Henriques

I wonder if these extra fuse_copy_finish() calls should also be removed. It doesn't seem to be a problem to call it twice, but maybe it's not needed, or am I missing something? This happens in a few places.

It's not a clear no-op, since the put_page() for the userspace buffer is being moved to after processing the notification.

I don't think this should cause problems, but it's something that I wouldn't like to do without a bit of thought.

Thanks,
Miklos

#7 lore raw

PATCH 4/4 fuse: add prune notification

In reply to Miklos Szeredi

Some fuse servers need to prune their caches, which can only be done if the kernel's own dentry/inode caches are pruned first to avoid dangling references.

Add FUSE_NOTIFY_PRUNE, which takes an array of node ID's to try and get rid of. Inodes with active references are skipped.

A similar functionality is already provided by FUSE_NOTIFY_INVAL_ENTRY with the FUSE_EXPIRE_ONLY flag. Differences in the interface are

FUSE_NOTIFY_INVAL_ENTRY:

- can only prune one dentry

- dentry is determined by parent ID and name

- if inode has multiple aliases (cached hard links), then they would have to be invalidated individually to be able to get rid of the inode

FUSE_NOTIFY_PRUNE:

- can prune multiple inodes

- inodes determined by their node ID

- aliases are taken care of automatically

---
 fs/fuse/dev.c             | 39 +++++++++++++++++++++++++++++++++++++++
 fs/fuse/fuse_i.h          |  6 ++++++
 fs/fuse/inode.c           | 11 +++++++++++
 include/uapi/linux/fuse.h |  8 ++++++++
 4 files changed, 64 insertions(+)
fs/fuse/dev.c +39 -0
index 1258acee9704..4229b38546bb 100644
@@ -2034,6 +2034,42 @@ static int fuse_notify_inc_epoch(struct fuse_conn *fc)
 	return 0;
 }
 
+static int fuse_notify_prune(struct fuse_conn *fc, unsigned int size,
+			     struct fuse_copy_state *cs)
+{
+	struct fuse_notify_prune_out outarg;
+	const unsigned int batch = 512;
+	u64 *nodeids __free(kfree) = kmalloc(sizeof(u64) * batch, GFP_KERNEL);
+	unsigned int num, i;
+	int err;
+
+	if (!nodeids)
+		return -ENOMEM;
+
+	if (size < sizeof(outarg))
+		return -EINVAL;
+
+	err = fuse_copy_one(cs, &outarg, sizeof(outarg));
+	if (err)
+		return err;
+
+	if (size - sizeof(outarg) != outarg.count * sizeof(u64))
+		return -EINVAL;
+
+	for (; outarg.count; outarg.count -= num) {
+		num = min(batch, outarg.count);
+		err = fuse_copy_one(cs, nodeids, num * sizeof(u64));
+		if (err)
+			return err;
+
+		scoped_guard(rwsem_read, &fc->killsb) {
+			for (i = 0; i < num; i++)
+				fuse_try_prune_one_inode(fc, nodeids[i]);
+		}
+	}
+	return 0;
+}
+
 static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code,
 		       unsigned int size, struct fuse_copy_state *cs)
 {
@@ -2065,6 +2101,9 @@ static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code,
 	case FUSE_NOTIFY_INC_EPOCH:
 		return fuse_notify_inc_epoch(fc);
 
+	case FUSE_NOTIFY_PRUNE:
+		return fuse_notify_prune(fc, size, cs);
+
 	default:
 		return -EINVAL;
 	}
fs/fuse/fuse_i.h +6 -0
index 233c6111f768..fb6604120b53 100644
@@ -1413,6 +1413,12 @@ int fuse_reverse_inval_inode(struct fuse_conn *fc, u64 nodeid,
 int fuse_reverse_inval_entry(struct fuse_conn *fc, u64 parent_nodeid,
 			     u64 child_nodeid, struct qstr *name, u32 flags);
 
+/*
+ * Try to prune this inode.  If neither the inode itself nor dentries associated
+ * with this inode have any external reference, then the inode can be freed.
+ */
+void fuse_try_prune_one_inode(struct fuse_conn *fc, u64 nodeid);
+
 int fuse_do_open(struct fuse_mount *fm, u64 nodeid, struct file *file,
 		 bool isdir);
 
fs/fuse/inode.c +11 -0
index 5b7897bf7e45..a4d361b34d06 100644
@@ -585,6 +585,17 @@ int fuse_reverse_inval_inode(struct fuse_conn *fc, u64 nodeid,
 	return 0;
 }
 
+void fuse_try_prune_one_inode(struct fuse_conn *fc, u64 nodeid)
+{
+	struct inode *inode;
+
+	inode = fuse_ilookup(fc, nodeid,  NULL);
+	if (!inode)
+		return;
+	d_prune_aliases(inode);
+	iput(inode);
+}
+
 bool fuse_lock_inode(struct inode *inode)
 {
 	bool locked = false;
include/uapi/linux/fuse.h +8 -0
index 30bf0846547f..c13e1f9a2f12 100644
@@ -239,6 +239,7 @@
  *  7.45
  *  - add FUSE_COPY_FILE_RANGE_64
  *  - add struct fuse_copy_file_range_out
+ *  - add FUSE_NOTIFY_PRUNE
  */
 
 #ifndef _LINUX_FUSE_H
@@ -680,6 +681,7 @@ enum fuse_notify_code {
 	FUSE_NOTIFY_DELETE = 6,
 	FUSE_NOTIFY_RESEND = 7,
 	FUSE_NOTIFY_INC_EPOCH = 8,
+	FUSE_NOTIFY_PRUNE = 9,
 };
 
 /* The read buffer is required to be at least 8k, but may be much larger */
@@ -1118,6 +1120,12 @@ struct fuse_notify_retrieve_in {
 	uint64_t	dummy4;
 };
 
+struct fuse_notify_prune_out {
+	uint32_t	count;
+	uint32_t	padding;
+	uint64_t	spare;
+};
+
 struct fuse_backing_map {
 	int32_t		fd;
 	uint32_t	flags;
Signature · 1 line
2.49.0
Reviewed-by on v1 4/4
#8 lore raw

Re: [PATCH 4/4] fuse: add prune notification

Quoted 22 lines · Miklos Szeredi

Some fuse servers need to prune their caches, which can only be done if the kernel's own dentry/inode caches are pruned first to avoid dangling references.

Add FUSE_NOTIFY_PRUNE, which takes an array of node ID's to try and get rid of. Inodes with active references are skipped.

A similar functionality is already provided by FUSE_NOTIFY_INVAL_ENTRY with the FUSE_EXPIRE_ONLY flag. Differences in the interface are

FUSE_NOTIFY_INVAL_ENTRY:

- can only prune one dentry

- dentry is determined by parent ID and name

- if inode has multiple aliases (cached hard links), then they would have to be invalidated individually to be able to get rid of the inode

FUSE_NOTIFY_PRUNE:

Quoted 7 lines

- can prune multiple inodes

- inodes determined by their node ID

- aliases are taken care of automatically

#9 lore raw

Re: [PATCH 4/4] fuse: add prune notification

In reply to Miklos Szeredi
Quoted 28 lines · Miklos Szeredi

External email: Use caution opening links or attachments

Some fuse servers need to prune their caches, which can only be done if the kernel's own dentry/inode caches are pruned first to avoid dangling references.

Add FUSE_NOTIFY_PRUNE, which takes an array of node ID's to try and get rid of. Inodes with active references are skipped.

A similar functionality is already provided by FUSE_NOTIFY_INVAL_ENTRY with the FUSE_EXPIRE_ONLY flag. Differences in the interface are

FUSE_NOTIFY_INVAL_ENTRY:

- can only prune one dentry

- dentry is determined by parent ID and name

- if inode has multiple aliases (cached hard links), then they would have to be invalidated individually to be able to get rid of the inode

FUSE_NOTIFY_PRUNE:

Quoted 7 lines

- can prune multiple inodes

- inodes determined by their node ID

- aliases are taken care of automatically

Thanks Miklos, this looks great. I’ll give this a spin in our virtio-fs FUSE device.

<snip>

Tested-by
#10 lore raw

Re: [PATCH 4/4] fuse: add prune notification

Quoted 34 lines · Jim Harris
Quoted 31 lines · Miklos Szeredi

External email: Use caution opening links or attachments

Some fuse servers need to prune their caches, which can only be done if the kernel's own dentry/inode caches are pruned first to avoid dangling references.

Add FUSE_NOTIFY_PRUNE, which takes an array of node ID's to try and get rid of. Inodes with active references are skipped.

A similar functionality is already provided by FUSE_NOTIFY_INVAL_ENTRY with the FUSE_EXPIRE_ONLY flag. Differences in the interface are

FUSE_NOTIFY_INVAL_ENTRY:

- can only prune one dentry

- dentry is determined by parent ID and name

- if inode has multiple aliases (cached hard links), then they would have to be invalidated individually to be able to get rid of the inode

FUSE_NOTIFY_PRUNE:

- can prune multiple inodes

Quoted 7 lines
Quoted 5 lines

- inodes determined by their node ID

- aliases are taken care of automatically

Thanks Miklos, this looks great. I’ll give this a spin in our virtio-fs FUSE device.

Hi Miklos,

I was finally was able to give these patches a spin. They work great, a nice simplification compared to FUSE_NOTIFY_INVAL_ENTRY. Feel free to add:

Best regards,

-Jim

#11 lore raw

Re: [PATCH 4/4] fuse: add prune notification

In reply to Miklos Szeredi

Hi Miklos,

I'm sorry for late review.

Quoted 19 lines · Miklos Szeredi

Some fuse servers need to prune their caches, which can only be done if the kernel's own dentry/inode caches are pruned first to avoid dangling references.

Add FUSE_NOTIFY_PRUNE, which takes an array of node ID's to try and get rid of. Inodes with active references are skipped.

A similar functionality is already provided by FUSE_NOTIFY_INVAL_ENTRY with the FUSE_EXPIRE_ONLY flag. Differences in the interface are

FUSE_NOTIFY_INVAL_ENTRY:

- can only prune one dentry

- dentry is determined by parent ID and name

- if inode has multiple aliases (cached hard links), then they would have to be invalidated individually to be able to get rid of the inode

Quoted 7 lines

FUSE_NOTIFY_PRUNE:

- can prune multiple inodes

- inodes determined by their node ID

- aliases are taken care of automatically

It actually solves another issue we had run into. FUSE_NOTIFY_INVAL_ENTRY takes the parent dir lock. Problem with the parent lock is our DLM and lock order. I.e. kernel holds parent lock for some dir operation, calls into fuse-server, which tries to acquires the DLM lock. DLM lock might be taken already and is doing FUSE_NOTIFY_INVAL_ENTRY - deadlock through the parent dir lock. We are running with an additional patch from Yong Ze, which is still for single entries.

Thanks,
Bernd

Quoted 90 lines
---
 fs/fuse/dev.c             | 39 +++++++++++++++++++++++++++++++++++++++
 fs/fuse/fuse_i.h          |  6 ++++++
 fs/fuse/inode.c           | 11 +++++++++++
 include/uapi/linux/fuse.h |  8 ++++++++
 4 files changed, 64 insertions(+)
fs/fuse/dev.c +39 -0
index 1258acee9704..4229b38546bb 100644
@@ -2034,6 +2034,42 @@ static int fuse_notify_inc_epoch(struct fuse_conn *fc)
 	return 0;
 }
 
+static int fuse_notify_prune(struct fuse_conn *fc, unsigned int size,
+			     struct fuse_copy_state *cs)
+{
+	struct fuse_notify_prune_out outarg;
+	const unsigned int batch = 512;
+	u64 *nodeids __free(kfree) = kmalloc(sizeof(u64) * batch, GFP_KERNEL);
+	unsigned int num, i;
+	int err;
+
+	if (!nodeids)
+		return -ENOMEM;
+
+	if (size < sizeof(outarg))
+		return -EINVAL;
+
+	err = fuse_copy_one(cs, &outarg, sizeof(outarg));
+	if (err)
+		return err;
+
+	if (size - sizeof(outarg) != outarg.count * sizeof(u64))
+		return -EINVAL;
+
+	for (; outarg.count; outarg.count -= num) {
+		num = min(batch, outarg.count);
+		err = fuse_copy_one(cs, nodeids, num * sizeof(u64));
+		if (err)
+			return err;
+
+		scoped_guard(rwsem_read, &fc->killsb) {
+			for (i = 0; i < num; i++)
+				fuse_try_prune_one_inode(fc, nodeids[i]);
+		}
+	}
+	return 0;
+}
+
 static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code,
 		       unsigned int size, struct fuse_copy_state *cs)
 {
@@ -2065,6 +2101,9 @@ static int fuse_notify(struct fuse_conn *fc, enum fuse_notify_code code,
 	case FUSE_NOTIFY_INC_EPOCH:
 		return fuse_notify_inc_epoch(fc);
 
+	case FUSE_NOTIFY_PRUNE:
+		return fuse_notify_prune(fc, size, cs);
+
 	default:
 		return -EINVAL;
 	}
fs/fuse/fuse_i.h +6 -0
index 233c6111f768..fb6604120b53 100644
@@ -1413,6 +1413,12 @@ int fuse_reverse_inval_inode(struct fuse_conn *fc, u64 nodeid,
 int fuse_reverse_inval_entry(struct fuse_conn *fc, u64 parent_nodeid,
 			     u64 child_nodeid, struct qstr *name, u32 flags);
 
+/*
+ * Try to prune this inode.  If neither the inode itself nor dentries associated
+ * with this inode have any external reference, then the inode can be freed.
+ */
+void fuse_try_prune_one_inode(struct fuse_conn *fc, u64 nodeid);
+
 int fuse_do_open(struct fuse_mount *fm, u64 nodeid, struct file *file,
 		 bool isdir);
 
fs/fuse/inode.c +0 -0
index 5b7897bf7e45..a4d361b34d06 100644
@@ -585,6 +585,17 @@ int fuse_reverse_inval_inode(struct fuse_conn *fc, u64 nodeid,
 	return 0;
 }

fs/fuse/inode.c int fuse_reverse_inval_inode(struct fuse_conn *fc, u64 nodeid, · line 596

Quoted 10 lines
fs/fuse/inode.c +9 -0
 
+void fuse_try_prune_one_inode(struct fuse_conn *fc, u64 nodeid)
+{
+	struct inode *inode;
+
+	inode = fuse_ilookup(fc, nodeid,  NULL);
+	if (!inode)
+		return;
+	d_prune_aliases(inode);
+	iput(inode);

I also wonder if FUSE_NOTIFY_PRUNE shouldn't handle dir inodes and call d_invalidate() to also prune child entries.

Thanks,
Bernd

maintainer
#12 lore raw

Re: [PATCH 4/4] fuse: add prune notification

Quoted 2 lines · Bernd Schubert

I also wonder if FUSE_NOTIFY_PRUNE shouldn't handle dir inodes and call d_invalidate() to also prune child entries.

d_invalidate unconditionally unhashes the dentry, which this interface should only do if the dentry is unused.

However, it could call shrink_dcache_parent() before trying to prune the dentry.

Thanks,
Miklos

Reviewed-by on v1 1/4
#13 lore raw
In reply to Miklos Szeredi
Quoted 7 lines · Miklos Szeredi

Constants that change value from version to version have no place in an interface definition.

Hopefully this won't break anything.

Quoted 20 lines
---
 include/uapi/linux/fuse.h | 1 -
 1 file changed, 1 deletion(-)
include/uapi/linux/fuse.h +0 -2
index 6b9fb8b08768..30bf0846547f 100644
@@ -680,7 +680,6 @@ enum fuse_notify_code {
        FUSE_NOTIFY_DELETE = 6,
        FUSE_NOTIFY_RESEND = 7,
        FUSE_NOTIFY_INC_EPOCH = 8,
-       FUSE_NOTIFY_CODE_MAX,
 };
 
 /* The read buffer is required to be at least 8k, but may be much larger */
--

2.49.0