From: Jan Kara <jack@suse.cz>
To: I Hsin Cheng <richard120310@gmail.com>
Cc: viro@zeniv.linux.org.uk, brauner@kernel.org, jack@suse.cz,
linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [RFC PATCH] file: Wrap locking mechanism for f_pos_lock
Date: Wed, 4 Dec 2024 11:26:44 +0100 [thread overview]
Message-ID: <20241204102644.hvutdftkueiiyss7@quack3> (raw)
In-Reply-To: <20241204092325.170349-1-richard120310@gmail.com>
On Wed 04-12-24 17:23:25, I Hsin Cheng wrote:
> As the implementation of "f->f_pos_lock" may change in the future,
> wrapping the actual implementation of locking and unlocking of it can
> provide better decoupling semantics.
>
> "__f_unlock_pos()" already exist and does that, adding "__f_lock_pos()"
> can provide full decoupling.
>
> Signed-off-by: I Hsin Cheng <richard120310@gmail.com>
I guess this would make sense for consistence. But Al, what was the
motivation of introducing __f_unlock_pos() in the first place? It has one
caller and was silently introduced in 63b6df14134d ("give
readdir(2)/getdents(2)/etc. uniform exclusion with lseek()") about 8 years
ago.
Honza
> ---
> fs/file.c | 7 ++++++-
> include/linux/file.h | 1 +
> 2 files changed, 7 insertions(+), 1 deletion(-)
>
> diff --git a/fs/file.c b/fs/file.c
> index fb1011cf6b4a..b93ac67d276d 100644
> --- a/fs/file.c
> +++ b/fs/file.c
> @@ -1181,6 +1181,11 @@ static inline bool file_needs_f_pos_lock(struct file *file)
> (file_count(file) > 1 || file->f_op->iterate_shared);
> }
>
> +void __f_lock_pos(struct file *f)
> +{
> + mutex_lock(&f->f_pos_lock);
> +}
> +
> struct fd fdget_pos(unsigned int fd)
> {
> struct fd f = fdget(fd);
> @@ -1188,7 +1193,7 @@ struct fd fdget_pos(unsigned int fd)
>
> if (file && file_needs_f_pos_lock(file)) {
> f.word |= FDPUT_POS_UNLOCK;
> - mutex_lock(&file->f_pos_lock);
> + __f_lock_pos(file);
> }
> return f;
> }
> diff --git a/include/linux/file.h b/include/linux/file.h
> index 302f11355b10..16292bd95499 100644
> --- a/include/linux/file.h
> +++ b/include/linux/file.h
> @@ -67,6 +67,7 @@ extern struct file *fget(unsigned int fd);
> extern struct file *fget_raw(unsigned int fd);
> extern struct file *fget_task(struct task_struct *task, unsigned int fd);
> extern struct file *fget_task_next(struct task_struct *task, unsigned int *fd);
> +extern void __f_lock_pos(struct file *file);
> extern void __f_unlock_pos(struct file *);
>
> struct fd fdget(unsigned int fd);
> --
> 2.43.0
>
--
Jan Kara <jack@suse.com>
SUSE Labs, CR
next prev parent reply other threads:[~2024-12-04 10:26 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-12-04 9:23 I Hsin Cheng
2024-12-04 10:26 ` Jan Kara [this message]
2024-12-04 11:11 ` Christian Brauner
2024-12-04 12:48 ` Jan Kara
2024-12-04 15:33 ` I Hsin Cheng
2024-12-04 16:07 ` Christian Brauner
2024-12-04 16:34 ` Al Viro
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=20241204102644.hvutdftkueiiyss7@quack3 \
--to=jack@suse.cz \
--cc=brauner@kernel.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=richard120310@gmail.com \
--cc=viro@zeniv.linux.org.uk \
/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
all inboxes | Powered by JetHome®