[RFC 1/2] fuse: add close all in passthrough backing close for crash recovery

Chunsheng Luo posted 2 patches 3 weeks, 4 days ago
There is a newer version of this series
[RFC 1/2] fuse: add close all in passthrough backing close for crash recovery
Posted by Chunsheng Luo 3 weeks, 4 days ago
Simplify FUSE daemon crash recovery by avoiding persistence of
backing_ids, thereby improving availability and reducing performance
overhead.

Non-persistent backing_ids after crash recovery may lead to resource
leaks if backing file resources are not properly cleaned up during
daemon restart.

Add a close_all handler to the backing close operation. This ensures
comprehensive cleanup of all backing file resources when the FUSE
daemon restarts, preventing resource leaks while maintaining the
simplified recovery approach.

Signed-off-by: Chunsheng Luo <luochunsheng@ustc.edu>
---
 fs/fuse/backing.c | 14 ++++++++++++++
 fs/fuse/dev.c     |  5 +++++
 fs/fuse/fuse_i.h  |  1 +
 3 files changed, 20 insertions(+)

diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c
index 4afda419dd14..34d0ea62fb9b 100644
--- a/fs/fuse/backing.c
+++ b/fs/fuse/backing.c
@@ -166,6 +166,20 @@ int fuse_backing_close(struct fuse_conn *fc, int backing_id)
 	return err;
 }
 
+static int fuse_backing_close_one(int id, void *p, void *data)
+{
+	struct fuse_conn *fc = data;
+
+	fuse_backing_close(fc, id);
+
+	return 0;
+}
+
+void fuse_backing_close_all(struct fuse_conn *fc)
+{
+	idr_for_each(&fc->backing_files_map, fuse_backing_close_one, fc);
+}
+
 struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc, int backing_id)
 {
 	struct fuse_backing *fb;
diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
index 6d59cbc877c6..25f6bb58623d 100644
--- a/fs/fuse/dev.c
+++ b/fs/fuse/dev.c
@@ -2651,6 +2651,11 @@ static long fuse_dev_ioctl_backing_close(struct file *file, __u32 __user *argp)
 	if (get_user(backing_id, argp))
 		return -EFAULT;
 
+	if (backing_id == -1) {
+		fuse_backing_close_all(fud->fc);
+		return 0;
+	}
+
 	return fuse_backing_close(fud->fc, backing_id);
 }
 
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 7f16049387d1..6191c02b9ccc 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -1573,6 +1573,7 @@ void fuse_backing_files_init(struct fuse_conn *fc);
 void fuse_backing_files_free(struct fuse_conn *fc);
 int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map);
 int fuse_backing_close(struct fuse_conn *fc, int backing_id);
+void fuse_backing_close_all(struct fuse_conn *fc);
 
 /* passthrough.c */
 static inline struct fuse_backing *fuse_inode_backing(struct fuse_inode *fi)
-- 
2.43.0
Re: [RFC 1/2] fuse: add close all in passthrough backing close for crash recovery
Posted by Amir Goldstein 3 weeks, 3 days ago
On Thu, Jan 15, 2026 at 03:20:30PM +0800, Chunsheng Luo wrote:
> Simplify FUSE daemon crash recovery by avoiding persistence of
> backing_ids, thereby improving availability and reducing performance
> overhead.
> 
> Non-persistent backing_ids after crash recovery may lead to resource
> leaks if backing file resources are not properly cleaned up during
> daemon restart.
> 
> Add a close_all handler to the backing close operation. This ensures
> comprehensive cleanup of all backing file resources when the FUSE
> daemon restarts, preventing resource leaks while maintaining the
> simplified recovery approach.

Am I correct to assume that you are referring to FUSE server restart
where the /dev/fuse fd is stored in an external fd store and reused by
the new FUSE server instance?

> 
> Signed-off-by: Chunsheng Luo <luochunsheng@ustc.edu>
> ---
>  fs/fuse/backing.c | 14 ++++++++++++++
>  fs/fuse/dev.c     |  5 +++++
>  fs/fuse/fuse_i.h  |  1 +
>  3 files changed, 20 insertions(+)
> 
> diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c
> index 4afda419dd14..34d0ea62fb9b 100644
> --- a/fs/fuse/backing.c
> +++ b/fs/fuse/backing.c
> @@ -166,6 +166,20 @@ int fuse_backing_close(struct fuse_conn *fc, int backing_id)
>  	return err;
>  }
>  
> +static int fuse_backing_close_one(int id, void *p, void *data)
> +{
> +	struct fuse_conn *fc = data;
> +
> +	fuse_backing_close(fc, id);
> +
> +	return 0;
> +}
> +
> +void fuse_backing_close_all(struct fuse_conn *fc)
> +{
> +	idr_for_each(&fc->backing_files_map, fuse_backing_close_one, fc);
> +}
> +
>  struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc, int backing_id)
>  {
>  	struct fuse_backing *fb;
> diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
> index 6d59cbc877c6..25f6bb58623d 100644
> --- a/fs/fuse/dev.c
> +++ b/fs/fuse/dev.c
> @@ -2651,6 +2651,11 @@ static long fuse_dev_ioctl_backing_close(struct file *file, __u32 __user *argp)
>  	if (get_user(backing_id, argp))
>  		return -EFAULT;
>  
> +	if (backing_id == -1) {
> +		fuse_backing_close_all(fud->fc);
> +		return 0;
> +	}
> +

I think that an explicit new ioctl FUSE_DEV_IOC_BACKING_CLOSE_ALL
is called for this very intrusive operation.

Sending FUSE_DEV_IOC_BACKING_CLOSE with backing_id -1 could
just as well happen by mistake.

Thanks,
Amir.
Re: [RFC 1/2] fuse: add close all in passthrough backing close for crash recovery
Posted by Chunsheng Luo 3 weeks, 3 days ago

On 1/15/26 8:23 PM, Amir Goldstein wrote:
> On Thu, Jan 15, 2026 at 03:20:30PM +0800, Chunsheng Luo wrote:
>> Simplify FUSE daemon crash recovery by avoiding persistence of
>> backing_ids, thereby improving availability and reducing performance
>> overhead.
>>
>> Non-persistent backing_ids after crash recovery may lead to resource
>> leaks if backing file resources are not properly cleaned up during
>> daemon restart.
>>
>> Add a close_all handler to the backing close operation. This ensures
>> comprehensive cleanup of all backing file resources when the FUSE
>> daemon restarts, preventing resource leaks while maintaining the
>> simplified recovery approach.
> 
> Am I correct to assume that you are referring to FUSE server restart
> where the /dev/fuse fd is stored in an external fd store and reused by
> the new FUSE server instance?
> 

Yes, that's correct.

>>
>> Signed-off-by: Chunsheng Luo <luochunsheng@ustc.edu>
>> ---
>>   fs/fuse/backing.c | 14 ++++++++++++++
>>   fs/fuse/dev.c     |  5 +++++
>>   fs/fuse/fuse_i.h  |  1 +
>>   3 files changed, 20 insertions(+)
>>
>> diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c
>> index 4afda419dd14..34d0ea62fb9b 100644
>> --- a/fs/fuse/backing.c
>> +++ b/fs/fuse/backing.c
>> @@ -166,6 +166,20 @@ int fuse_backing_close(struct fuse_conn *fc, int backing_id)
>>   	return err;
>>   }
>>   
>> +static int fuse_backing_close_one(int id, void *p, void *data)
>> +{
>> +	struct fuse_conn *fc = data;
>> +
>> +	fuse_backing_close(fc, id);
>> +
>> +	return 0;
>> +}
>> +
>> +void fuse_backing_close_all(struct fuse_conn *fc)
>> +{
>> +	idr_for_each(&fc->backing_files_map, fuse_backing_close_one, fc);
>> +}
>> +
>>   struct fuse_backing *fuse_backing_lookup(struct fuse_conn *fc, int backing_id)
>>   {
>>   	struct fuse_backing *fb;
>> diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
>> index 6d59cbc877c6..25f6bb58623d 100644
>> --- a/fs/fuse/dev.c
>> +++ b/fs/fuse/dev.c
>> @@ -2651,6 +2651,11 @@ static long fuse_dev_ioctl_backing_close(struct file *file, __u32 __user *argp)
>>   	if (get_user(backing_id, argp))
>>   		return -EFAULT;
>>   
>> +	if (backing_id == -1) {
>> +		fuse_backing_close_all(fud->fc);
>> +		return 0;
>> +	}
>> +
> 
> I think that an explicit new ioctl FUSE_DEV_IOC_BACKING_CLOSE_ALL
> is called for this very intrusive operation.
> 
> Sending FUSE_DEV_IOC_BACKING_CLOSE with backing_id -1 could
> just as well happen by mistake.
> 
> Thanks,
> Amir.
> 
> 
Okay, thank you for the suggestion.