]> git.hungrycats.org Git - linux/commitdiff
btrfs: stripe_alloc: warn when raid56 metadata is not covered
authorZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sat, 19 Sep 2026 17:17:47 +0000 (13:17 -0400)
committerZygo Blaxell <ce3g8jdj@umail.furryterror.org>
Sun, 8 Nov 2026 23:37:46 +0000 (18:37 -0500)
stripe_alloc closes the write hole for raid56 data.  It does nothing for
raid56 metadata, which keeps read-modify-write and keeps the hole, and
on a mixed-block-group filesystem it now does nothing at all.  A user
who enables stripe_alloc on -d raid5 -m raid5 has every reason to
believe the filesystem is covered, and finds out otherwise only after a
crash on a degraded array -- with metadata damage, which is worse than
the data damage they were protecting against.

Say it once at mount, after the block groups are read, so the message
reflects what is actually on disk rather than what was asked for.  A
warning, not an error: the data guarantee is real and worth having on
its own, and a filesystem can be converted to raid1c3/raid1c4 metadata
without unmounting.

Assisted-by: Claude:claude-fable-5
Assisted-by: Claude:claude-opus-5-5
fs/btrfs/block-group.c

index 0b420806e298600a42ef81c6d655bfe3dcfea102..c3ceb8ef87ebdb2ea66cc4651d2b7383aa771fcb 100644 (file)
@@ -1077,6 +1077,28 @@ static void stripe_alloc_sweep_groups(struct btrfs_fs_info *fs_info, bool arm)
        }
 }
 
+/*
+ * stripe_alloc covers raid56 *data* block groups only.  A filesystem whose
+ * metadata is also raid56 keeps the write hole there.  The data guarantee is
+ * easy to read as a filesystem-wide one, so say once, when the policy turns
+ * on, what is not covered.  That is btrfs_enable_stripe_alloc(): at mount the
+ * property applies after the block groups are read, so a report from
+ * btrfs_read_block_groups() would find the flag still clear.  (Mixed block
+ * groups cannot get here: the property refuses them.)
+ */
+static void warn_stripe_alloc_uncovered(struct btrfs_fs_info *info)
+{
+       const u64 meta_bits = info->avail_metadata_alloc_bits |
+                             info->avail_system_alloc_bits;
+
+       if (!btrfs_test_opt(info, STRIPE_ALLOC))
+               return;
+
+       if (meta_bits & BTRFS_BLOCK_GROUP_RAID56_MASK)
+               btrfs_warn(info,
+"stripe_alloc does not cover raid56 metadata: the write hole remains for metadata, consider converting it to raid1c3/raid1c4");
+}
+
 int btrfs_enable_stripe_alloc(struct btrfs_fs_info *fs_info)
 {
        int ret;
@@ -1087,6 +1109,7 @@ int btrfs_enable_stripe_alloc(struct btrfs_fs_info *fs_info)
        if (ret)
                return ret;
        btrfs_set_opt(fs_info->mount_opt, STRIPE_ALLOC);
+       warn_stripe_alloc_uncovered(fs_info);
        /*
         * Arm stripe_unusable accounting for raid56 data groups whose caches
         * loaded before the policy was enabled: block groups are read before