diff mbox series

btrfs: clear force-compress on remount when compress mount option is given

Message ID 4d68f9e1e230dba0dfa70fb664540a962e0ae055.1728920737.git.fdmanana@suse.com (mailing list archive)
State New, archived
Headers show
Series btrfs: clear force-compress on remount when compress mount option is given | expand

Commit Message

Filipe Manana Oct. 14, 2024, 3:46 p.m. UTC
From: Filipe Manana <fdmanana@suse.com>

After the migration to use fs context for processing mount options we had
a slight change in the semantics for remounting a filesystem that was
mounted with compress-force. Before we could clear compress-force by
passing only "-o compress[=algo]" during a remount, but after that change
that does not work anymore, force-compress is still present and one needs
to pass "-o compress-force=no,compress[=algo]" to the mount command.

Example, when running on a kernel 6.8+:

  $ mount -o compress-force=zlib:9 /dev/sdi /mnt/sdi
  $ mount | grep sdi
  /dev/sdi on /mnt/sdi type btrfs (rw,relatime,compress-force=zlib:9,discard=async,space_cache=v2,subvolid=5,subvol=/)

  $ mount -o remount,compress=zlib:5 /mnt/sdi
  $ mount | grep $sdi
  /dev/sdi on /mnt/sdi type btrfs (rw,relatime,compress-force=zlib:5,discard=async,space_cache=v2,subvolid=5,subvol=/)

On a 6.7 kernel (or older):

  $ mount -o compress-force=zlib:9 /dev/sdi /mnt/sdi
  $ mount | grep sdi
  /dev/sdi on /mnt/sdi type btrfs (rw,relatime,compress-force=zlib:9,discard=async,space_cache=v2,subvolid=5,subvol=/)

  $ mount -o remount,compress=zlib:5 /mnt/sdi
  $ mount | grep sdi
  /dev/sdi on /mnt/sdi type btrfs (rw,relatime,compress=zlib:5,discard=async,space_cache=v2,subvolid=5,subvol=/)

So update btrfs_parse_param() to clear "compress-force" when "compress" is
given, providing the same semantics as kernel 6.7 and older.

Reported-by: Roman Mamedov <rm@romanrm.net>
Link: https://lore.kernel.org/linux-btrfs/20241014182416.13d0f8b0@nvm/
CC: stable@vger.kernel.org # 6.8+
Signed-off-by: Filipe Manana <fdmanana@suse.com>
---
 fs/btrfs/super.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

David Sterba Oct. 14, 2024, 4:05 p.m. UTC | #1
On Mon, Oct 14, 2024 at 04:46:30PM +0100, fdmanana@kernel.org wrote:
> From: Filipe Manana <fdmanana@suse.com>
> 
> After the migration to use fs context for processing mount options we had
> a slight change in the semantics for remounting a filesystem that was
> mounted with compress-force. Before we could clear compress-force by
> passing only "-o compress[=algo]" during a remount, but after that change
> that does not work anymore, force-compress is still present and one needs
> to pass "-o compress-force=no,compress[=algo]" to the mount command.
> 
> Example, when running on a kernel 6.8+:
> 
>   $ mount -o compress-force=zlib:9 /dev/sdi /mnt/sdi
>   $ mount | grep sdi
>   /dev/sdi on /mnt/sdi type btrfs (rw,relatime,compress-force=zlib:9,discard=async,space_cache=v2,subvolid=5,subvol=/)
> 
>   $ mount -o remount,compress=zlib:5 /mnt/sdi
>   $ mount | grep $sdi
>   /dev/sdi on /mnt/sdi type btrfs (rw,relatime,compress-force=zlib:5,discard=async,space_cache=v2,subvolid=5,subvol=/)
> 
> On a 6.7 kernel (or older):
> 
>   $ mount -o compress-force=zlib:9 /dev/sdi /mnt/sdi
>   $ mount | grep sdi
>   /dev/sdi on /mnt/sdi type btrfs (rw,relatime,compress-force=zlib:9,discard=async,space_cache=v2,subvolid=5,subvol=/)
> 
>   $ mount -o remount,compress=zlib:5 /mnt/sdi
>   $ mount | grep sdi
>   /dev/sdi on /mnt/sdi type btrfs (rw,relatime,compress=zlib:5,discard=async,space_cache=v2,subvolid=5,subvol=/)
> 
> So update btrfs_parse_param() to clear "compress-force" when "compress" is
> given, providing the same semantics as kernel 6.7 and older.
> 
> Reported-by: Roman Mamedov <rm@romanrm.net>
> Link: https://lore.kernel.org/linux-btrfs/20241014182416.13d0f8b0@nvm/
> CC: stable@vger.kernel.org # 6.8+
> Signed-off-by: Filipe Manana <fdmanana@suse.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 e8a5bf4af918..a4711640c0b4 100644
--- a/fs/btrfs/super.c
+++ b/fs/btrfs/super.c
@@ -340,6 +340,15 @@  static int btrfs_parse_param(struct fs_context *fc, struct fs_parameter *param)
 		fallthrough;
 	case Opt_compress:
 	case Opt_compress_type:
+		/*
+		 * Provide the same semantics as older kernels that don't use fs
+		 * context, specifying the "compress" option clears
+		 * "force-compress" without the need to pass
+		 * "compress-force=[no|none]" before specifying "compress".
+		 */
+		if (opt != Opt_compress_force && opt != Opt_compress_force_type)
+			btrfs_clear_opt(ctx->mount_opt, FORCE_COMPRESS);
+
 		if (opt == Opt_compress || opt == Opt_compress_force) {
 			ctx->compress_type = BTRFS_COMPRESS_ZLIB;
 			ctx->compress_level = BTRFS_ZLIB_DEFAULT_LEVEL;