summaryrefslogtreecommitdiffstats
path: root/fs/super.c
diff options
context:
space:
mode:
authorJan Kara <jack@suse.cz>2023-06-20 13:28:32 +0200
committerChristian Brauner <brauner@kernel.org>2023-06-20 13:48:01 +0200
commitd7439fb1f4338fffd0bc68bb62d78f7712725f26 (patch)
treecfee9d8b47dbf428a1658be8be50b341305e08a7 /fs/super.c
parentfs: Protect reconfiguration of sb read-write from racing writes (diff)
downloadlinux-d7439fb1f4338fffd0bc68bb62d78f7712725f26.tar.xz
linux-d7439fb1f4338fffd0bc68bb62d78f7712725f26.zip
fs: Provide helpers for manipulating sb->s_readonly_remount
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> Reviewed-by: Dave Chinner <dchinner@redhat.com> Message-Id: <20230620112832.5158-1-jack@suse.cz> Signed-off-by: Christian Brauner <brauner@kernel.org>
Diffstat (limited to 'fs/super.c')
-rw-r--r--fs/super.c17
1 files changed, 6 insertions, 11 deletions
diff --git a/fs/super.c b/fs/super.c
index 5bf056087acc..5ee5da1fd498 100644
--- a/fs/super.c
+++ b/fs/super.c
@@ -944,8 +944,7 @@ int reconfigure_super(struct fs_context *fc)
*/
if (remount_ro) {
if (force) {
- sb->s_readonly_remount = 1;
- smp_wmb();
+ sb_start_ro_state_change(sb);
} else {
retval = sb_prepare_remount_readonly(sb);
if (retval)
@@ -953,12 +952,10 @@ int reconfigure_super(struct fs_context *fc)
}
} else if (remount_rw) {
/*
- * We set s_readonly_remount here to protect filesystem's
- * reconfigure code from writes from userspace until
- * reconfigure finishes.
+ * Protect filesystem's reconfigure code from writes from
+ * userspace until reconfigure finishes.
*/
- sb->s_readonly_remount = 1;
- smp_wmb();
+ sb_start_ro_state_change(sb);
}
if (fc->ops->reconfigure) {
@@ -974,9 +971,7 @@ int reconfigure_super(struct fs_context *fc)
WRITE_ONCE(sb->s_flags, ((sb->s_flags & ~fc->sb_flags_mask) |
(fc->sb_flags & fc->sb_flags_mask)));
- /* Needs to be ordered wrt mnt_is_readonly() */
- smp_wmb();
- sb->s_readonly_remount = 0;
+ sb_end_ro_state_change(sb);
/*
* Some filesystems modify their metadata via some other path than the
@@ -991,7 +986,7 @@ int reconfigure_super(struct fs_context *fc)
return 0;
cancel_readonly:
- sb->s_readonly_remount = 0;
+ sb_end_ro_state_change(sb);
return retval;
}