linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: Jan Kara <jack@suse.cz>
Cc: Christian Brauner <brauner@kernel.org>,
	linux-fsdevel@vger.kernel.org, Al Viro <viro@zeniv.linux.org.uk>,
	David Howells <dhowells@redhat.com>
Subject: Re: [PATCH v2] fs: Provide helpers for manipulating sb->s_readonly_remount
Date: Tue, 20 Jun 2023 09:25:05 +1000	[thread overview]
Message-ID: <ZJDj0XjkeVK7AHIx@dread.disaster.area> (raw)
In-Reply-To: <20230619111832.3886-1-jack@suse.cz>

On Mon, Jun 19, 2023 at 01:18:32PM +0200, Jan Kara wrote:
> Provide helpers to set and clear sb->s_readonly_remount including
> appropriate memory barriers. Also use this opportunity to document what
> the barriers pair with and why they are needed.
> 
> Suggested-by: Dave Chinner <david@fromorbit.com>
> Signed-off-by: Jan Kara <jack@suse.cz>
> ---
>  fs/internal.h      | 34 ++++++++++++++++++++++++++++++++++
>  fs/namespace.c     | 10 ++++------
>  fs/super.c         | 17 ++++++-----------
>  include/linux/fs.h |  2 +-
>  4 files changed, 45 insertions(+), 18 deletions(-)
> 
> diff --git a/fs/internal.h b/fs/internal.h
> index bd3b2810a36b..e206eb58bd3e 100644
> --- a/fs/internal.h
> +++ b/fs/internal.h
> @@ -120,6 +120,40 @@ void put_super(struct super_block *sb);
>  extern bool mount_capable(struct fs_context *);
>  int sb_init_dio_done_wq(struct super_block *sb);
>  
> +/*
> + * Prepare superblock for changing its read-only state (i.e., either remount
> + * read-write superblock read-only or vice versa). After this function returns
> + * mnt_is_readonly() will return true for any mount of the superblock if its
> + * caller is able to observe any changes done by the remount. This holds until
> + * sb_end_ro_state_change() is called.
> + */
> +static inline void sb_start_ro_state_change(struct super_block *sb)
> +{
> +	WRITE_ONCE(sb->s_readonly_remount, 1);
> +	/*
> +	 * For RO->RW transition, the barrier pairs with the barrier in
> +	 * mnt_is_readonly() making sure if mnt_is_readonly() sees SB_RDONLY
> +	 * cleared, it will see s_readonly_remount set.
> +	 * For RW->RO transition, the barrier pairs with the barrier in
> +	 * __mnt_want_write() before the mnt_is_readonly() check. The barrier
> +	 * makes sure if __mnt_want_write() sees MNT_WRITE_HOLD already
> +	 * cleared, it will see s_readonly_remount set.
> +	 */
> +	smp_wmb();
> +}

Can you please also update mnt_is_readonly/__mnt_want_write to
indicate that there is a pairing with this helper from those
functions?

> +
> +/*
> + * Ends section changing read-only state of the superblock. After this function
> + * returns if mnt_is_readonly() returns false, the caller will be able to
> + * observe all the changes remount did to the superblock.
> + */
> +static inline void sb_end_ro_state_change(struct super_block *sb)
> +{
> +	/* The barrier pairs with the barrier in mnt_is_readonly() */
> +	smp_wmb();
> +	WRITE_ONCE(sb->s_readonly_remount, 0);
> +}

	/*
	 * This barrier provides release semantics that pair with
	 * the smp_rmb() acquire semantics in mnt_is_readonly().
	 * This barrier pair ensure that when mnt_is_readonly() sees
	 * 0 for sb->s_readonly_remount, it will also see all the
	 * preceding flag changes that were made during the RO state
	 * change.
	 */

And a comment in mnt_is_readonly() to indicate that it also pairs
with sb_end_ro_state_change() in a different way to the barriers in
sb_start_ro_state_change(), __mnt_want_write(), MNT_WRITE_HOLD, etc.

Memory barriers need clear, concise documentation, otherwise they
are impossible to understand from just reading the code...

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

  parent reply	other threads:[~2023-06-19 23:28 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-19 11:18 [PATCH v2] fs: Provide helpers for manipulating sb->s_readonly_remount Jan Kara
2023-06-19 16:06 ` Christian Brauner
2023-06-19 23:25 ` Dave Chinner [this message]
2023-06-20 11:30   ` Jan Kara

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=ZJDj0XjkeVK7AHIx@dread.disaster.area \
    --to=david@fromorbit.com \
    --cc=brauner@kernel.org \
    --cc=dhowells@redhat.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --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;
as well as URLs for NNTP newsgroup(s).