diff mbox series

btrfs: use the original mount's mount options for the legacy reconfigure

Message ID 18faaced53d356f66b4b1f0f118d15e37e3c8a2c.1704909267.git.josef@toxicpanda.com (mailing list archive)
State New, archived
Headers show
Series btrfs: use the original mount's mount options for the legacy reconfigure | expand

Commit Message

Josef Bacik Jan. 10, 2024, 5:54 p.m. UTC
btrfs/330, which tests our old trick to allow

mount -o ro,subvol=/x /dev/sda1 /foo
mount -o rw,subvol=/y /dev/sda1 /bar

fails on the block group tree.  This is because we aren't preserving the
mount options for what is essentially a remount, and thus we're ending
up without the FREE_SPACE_TREE mount option, which triggers our free
space tree delete codepath.  This isn't possible with the block group
tree and thus it falls over.

Fix this by making sure we copy the existing mount options for the
existing fs mount over in this case.

Signed-off-by: Josef Bacik <josef@toxicpanda.com>
---
 fs/btrfs/super.c | 8 ++++++++
 1 file changed, 8 insertions(+)

Comments

Neal Gompa Jan. 11, 2024, 11:34 a.m. UTC | #1
On Wed, Jan 10, 2024 at 12:57 PM Josef Bacik <josef@toxicpanda.com> wrote:
>
> btrfs/330, which tests our old trick to allow
>
> mount -o ro,subvol=/x /dev/sda1 /foo
> mount -o rw,subvol=/y /dev/sda1 /bar
>
> fails on the block group tree.  This is because we aren't preserving the
> mount options for what is essentially a remount, and thus we're ending
> up without the FREE_SPACE_TREE mount option, which triggers our free
> space tree delete codepath.  This isn't possible with the block group
> tree and thus it falls over.
>
> Fix this by making sure we copy the existing mount options for the
> existing fs mount over in this case.
>
> Signed-off-by: Josef Bacik <josef@toxicpanda.com>
> ---
>  fs/btrfs/super.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
> index 3a677b808f0f..f192f8fe0ce6 100644
> --- a/fs/btrfs/super.c
> +++ b/fs/btrfs/super.c
> @@ -1451,6 +1451,14 @@ static int btrfs_reconfigure(struct fs_context *fc)
>
>         btrfs_info_to_ctx(fs_info, &old_ctx);
>
> +       /*
> +        * This is our "bind mount" trick, we don't want to allow the user to do
> +        * anything other than mount a different ro/rw and a different subvol,
> +        * all of the mount options should be maintained.
> +        */
> +       if (mount_reconfigure)
> +               ctx->mount_opt = old_ctx.mount_opt;
> +
>         sync_filesystem(sb);
>         set_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state);
>
> --
> 2.43.0
>
>

This makes sense, though I don't think this is a particularly intuitive feature.

Reviewed-by: Neal Gompa <neal@gompa.dev>
David Sterba Jan. 11, 2024, 4:43 p.m. UTC | #2
On Wed, Jan 10, 2024 at 12:54:41PM -0500, Josef Bacik wrote:
> btrfs/330, which tests our old trick to allow
> 
> mount -o ro,subvol=/x /dev/sda1 /foo
> mount -o rw,subvol=/y /dev/sda1 /bar
> 
> fails on the block group tree.  This is because we aren't preserving the
> mount options for what is essentially a remount, and thus we're ending
> up without the FREE_SPACE_TREE mount option, which triggers our free
> space tree delete codepath.  This isn't possible with the block group
> tree and thus it falls over.
> 
> Fix this by making sure we copy the existing mount options for the
> existing fs mount over in this case.

Fixes: f044b318675f ("btrfs: handle the ro->rw transition for mounting different subvolumes")

> Signed-off-by: Josef Bacik <josef@toxicpanda.com>

Reviewed-by: David Sterba <dsterba@suse.com>
diff mbox series

Patch

diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
index 3a677b808f0f..f192f8fe0ce6 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -1451,6 +1451,14 @@  static int btrfs_reconfigure(struct fs_context *fc)
 
 	btrfs_info_to_ctx(fs_info, &old_ctx);
 
+	/*
+	 * This is our "bind mount" trick, we don't want to allow the user to do
+	 * anything other than mount a different ro/rw and a different subvol,
+	 * all of the mount options should be maintained.
+	 */
+	if (mount_reconfigure)
+		ctx->mount_opt = old_ctx.mount_opt;
+
 	sync_filesystem(sb);
 	set_bit(BTRFS_FS_STATE_REMOUNTING, &fs_info->fs_state);