[PATCH] fuse: set ff->flock only on success

Zhang Tianci posted 1 patch 1 month, 1 week ago
fs/fuse/file.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
[PATCH] fuse: set ff->flock only on success
Posted by Zhang Tianci 1 month, 1 week ago
If FUSE_SETLK fails (e.g., due to EWOULDBLOCK), we shall not set
FUSE_RELEASE_FLOCK_UNLOCK in fuse_file_release().

Reported-by: Li Yichao <liyichao.1@bytedance.com>
Signed-off-by: Zhang Tianci <zhangtianci.1997@bytedance.com>
---
 fs/fuse/file.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index 01bc894e9c2ba..d83ef81e3b9b3 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -2563,8 +2563,9 @@ static int fuse_file_flock(struct file *file, int cmd, struct file_lock *fl)
 		struct fuse_file *ff = file->private_data;
 
 		/* emulate flock with POSIX locks */
-		ff->flock = true;
 		err = fuse_setlk(file, fl, 1);
+		if (!err)
+			ff->flock = true;
 	}
 
 	return err;
-- 
2.39.5
Re: [PATCH] fuse: set ff->flock only on success
Posted by Miklos Szeredi 1 week, 3 days ago
On Thu, 25 Dec 2025 at 12:12, Zhang Tianci
<zhangtianci.1997@bytedance.com> wrote:
>
> If FUSE_SETLK fails (e.g., due to EWOULDBLOCK), we shall not set
> FUSE_RELEASE_FLOCK_UNLOCK in fuse_file_release().

It's not clear if this is an optimization, a correctness fix or neither?

Thanks,
Miklos
Re: [External] Re: [PATCH] fuse: set ff->flock only on success
Posted by Zhang Tianci 1 week, 3 days ago
Hi Miklos,

On Tue, Jan 27, 2026 at 5:58 PM Miklos Szeredi <miklos@szeredi.hu> wrote:
>
> On Thu, 25 Dec 2025 at 12:12, Zhang Tianci
> <zhangtianci.1997@bytedance.com> wrote:
> >
> > If FUSE_SETLK fails (e.g., due to EWOULDBLOCK), we shall not set
> > FUSE_RELEASE_FLOCK_UNLOCK in fuse_file_release().
>
> It's not clear if this is an optimization, a correctness fix or neither?

I think it's an optimization, If FUSE_SETLK failed, FUSEdaemon  will
not record this lock, so in
FUSE_RELEASE operation, FUSEdaemon will perform an unnecessary lock
owner lookup.

Thanks,
Tianci
Re: [PATCH] fuse: set ff->flock only on success
Posted by Zhang Tianci 1 month ago
gently ping...
Re: [PATCH] fuse: set ff->flock only on success
Posted by Zhang Tianci 1 week, 3 days ago
gently ping...