From: Jiachen Zhang <zhangjiachen.jaycee@bytedance.com>
To: Miklos Szeredi <miklos@szeredi.hu>,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Andrew Morton <akpm@osdl.org>,
me@jcix.top, Jiachen Zhang <zhangjiachen.jaycee@bytedance.com>
Subject: [PATCH 1/2] fuse: support unlock remote OFD locks on file release
Date: Thu, 8 Jun 2023 16:46:08 +0800 [thread overview]
Message-ID: <20230608084609.14245-2-zhangjiachen.jaycee@bytedance.com> (raw)
In-Reply-To: <20230608084609.14245-1-zhangjiachen.jaycee@bytedance.com>
Like flock(2), the fcntl(2) OFD locks also use struct file addresses as
the lock owner ID, and also should be unlocked on file release.
The commit 37fb3a30b462 ("fuse: fix flock") fixed the flock unlocking
issue on file release. This commit aims to fix the OFD lock by reusing
the release_flag 'FUSE_RELEASE_FLOCK_UNLOCK'. The FUSE daemons should
unlock both OFD locks and flocks in the FUSE_RELEASE handler.
To make it more clear, rename 'ff->flock' to 'ff->unlock_on_release', as
it would be used for both flock and OFD lock. It will be set true if the
value of fl->fl_owner equals to the struct file address.
Fixes: 37fb3a30b462 ("fuse: fix flock")
Signed-off-by: Jiachen Zhang <zhangjiachen.jaycee@bytedance.com>
---
fs/fuse/file.c | 17 ++++++++++++++---
fs/fuse/fuse_i.h | 2 +-
2 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/fs/fuse/file.c b/fs/fuse/file.c
index de37a3a06a71..7fe9d405969e 100644
--- a/fs/fuse/file.c
+++ b/fs/fuse/file.c
@@ -312,7 +312,7 @@ void fuse_file_release(struct inode *inode, struct fuse_file *ff,
fuse_prepare_release(fi, ff, open_flags, opcode);
- if (ff->flock) {
+ if (ff->unlock_on_release) {
ra->inarg.release_flags |= FUSE_RELEASE_FLOCK_UNLOCK;
ra->inarg.lock_owner = fuse_lock_owner_id(ff->fm->fc, id);
}
@@ -2650,8 +2650,19 @@ static int fuse_file_lock(struct file *file, int cmd, struct file_lock *fl)
} else {
if (fc->no_lock)
err = posix_lock_file(file, fl, NULL);
- else
+ else {
+ /*
+ * Like flock, the OFD lock also uses the struct
+ * file address as the fl_owner, and should be
+ * unlocked on file release.
+ */
+ if (file == fl->fl_owner) {
+ struct fuse_file *ff = file->private_data;
+
+ ff->unlock_on_release = true;
+ }
err = fuse_setlk(file, fl, 0);
+ }
}
return err;
}
@@ -2668,7 +2679,7 @@ 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;
+ ff->unlock_on_release = true;
err = fuse_setlk(file, fl, 1);
}
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 9b7fc7d3c7f1..574f67bd5684 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -225,7 +225,7 @@ struct fuse_file {
wait_queue_head_t poll_wait;
/** Has flock been performed on this file? */
- bool flock:1;
+ bool unlock_on_release:1;
};
/** One input argument of a request */
--
2.20.1
next prev parent reply other threads:[~2023-06-08 8:47 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-08 8:46 [PATCH 0/2] fuse: fixes for remote locking Jiachen Zhang
2023-06-08 8:46 ` Jiachen Zhang [this message]
2023-06-18 15:04 ` [PATCH 1/2] fuse: support unlock remote OFD locks on file release Jochen Friedrich
2023-06-08 8:46 ` [PATCH 2/2] fuse: remove an unnecessary if statement Jiachen Zhang
2024-03-06 9:13 ` Miklos Szeredi
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230608084609.14245-2-zhangjiachen.jaycee@bytedance.com \
--to=zhangjiachen.jaycee@bytedance.com \
--cc=akpm@osdl.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=me@jcix.top \
--cc=miklos@szeredi.hu \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).