]> git.hungrycats.org Git - btrfs-progs/commitdiff
btrfs-progs: mkfs: make -O mixed-bg behave identically to --mixed
authorAndrus Suvalau <andrus.suvalau@n-able.com>
Mon, 28 Sep 2026 15:10:04 +0000 (17:10 +0200)
committerQu Wenruo <wqu@suse.com>
Wed, 30 Sep 2026 09:43:48 +0000 (19:13 +0930)
Mixed block groups can be requested either with the -M/--mixed flag or
with the -O mixed-bg filesystem feature.

However using "mkfs.btrfs -O mixed-bg" results non-mixed block groups:

 Label:              (null)
 UUID:               8b6b2eaf-d399-4190-8b64-fcbed24f20fe
 Node size:          4096
 Sector size:        4096        (CPU page size: 4096)
 Filesystem size:    2.00GiB
 Block group profiles:
   Data:             single            8.00MiB <<<
   Metadata:         DUP             102.38MiB <<<
   Data+Metadata:    single            8.00MiB
   System:           DUP               8.00MiB

As "-O mixed-bg" option didn't properly set @mixed variable, thus
regular non-mixed block groups are still created.

Fix it by setting @mixed if BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS feature
is also set.

Signed-off-by: Andrus Suvalau <andrus.suvalau@n-able.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
[ Update the commit message to show the problem more clearly ]
Signed-off-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Andrus Suvalau <andrus.suvalau@n-able.com>
mkfs/main.c
tests/mkfs-tests/045-mixed-flag-vs-option/test.sh [new file with mode: 0755]

index 71c7968310928648e6d768a769085ed81ba3b309..f09f712627edc7ba5338b3298617468812206e3b 100644 (file)
@@ -1918,6 +1918,9 @@ int BOX_MAIN(mkfs)(int argc, char **argv)
                features.incompat_flags |= BTRFS_FEATURE_INCOMPAT_ZONED;
        }
 
+       if (features.incompat_flags & BTRFS_FEATURE_INCOMPAT_MIXED_GROUPS)
+               mixed = true;
+
        /*
        * Set default profiles according to number of added devices.
        * For mixed groups defaults are single/single.
diff --git a/tests/mkfs-tests/045-mixed-flag-vs-option/test.sh b/tests/mkfs-tests/045-mixed-flag-vs-option/test.sh
new file mode 100755 (executable)
index 0000000..7bd4369
--- /dev/null
@@ -0,0 +1,22 @@
+#!/bin/bash
+# Test that both -M and the FS feature mixed-bg create a FS with the same
+# data and metadata profiles.
+
+source "$TEST_TOP/common" || exit
+
+check_prereq mkfs.btrfs
+
+setup_root_helper
+prepare_test_dev
+
+check_mixed() {
+       local output
+       output=$(run_check_stdout "$TOP/mkfs.btrfs" "$@" -f "$TEST_DEV" | grep -E 'Data|Metadata')
+
+       if echo "$output" | grep -q -v 'Data+Metadata:'; then
+               _fail "created a mixed-bg filesystem with differing profiles using '$*' options"
+       fi
+}
+
+check_mixed -M
+check_mixed -O mixed-bg