]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: zoned: fixup last alloc pointer after extent removal for RAID1
authorNaohiro Aota <naohiro.aota@wdc.com>
Wed, 17 Dec 2025 11:14:04 +0000 (20:14 +0900)
committerSasha Levin <sashal@kernel.org>
Wed, 4 Mar 2026 12:21:21 +0000 (07:21 -0500)
[ Upstream commit dda3ec9ee6b3e120603bff1b798f25b51e54ac5d ]

When a block group is composed of a sequential write zone and a
conventional zone, we recover the (pseudo) write pointer of the
conventional zone using the end of the last allocated position.

However, if the last extent in a block group is removed, the last extent
position will be smaller than the other real write pointer position.
Then, that will cause an error due to mismatch of the write pointers.

We can fixup this case by moving the alloc_offset to the corresponding
write pointer position.

Fixes: 568220fa9657 ("btrfs: zoned: support RAID0/1/10 on top of raid stripe tree")
CC: stable@vger.kernel.org # 6.12+
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: Naohiro Aota <naohiro.aota@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
Signed-off-by: Sasha Levin <sashal@kernel.org>
fs/btrfs/zoned.c

index 3afc9c0c2228789420f81334ac4da2422e17336b..8e6e96660fa66d95022daa7476c34a0f63be4853 100644 (file)
@@ -1483,6 +1483,21 @@ static int btrfs_load_block_group_raid1(struct btrfs_block_group *bg,
        /* In case a device is missing we have a cap of 0, so don't use it. */
        bg->zone_capacity = min_not_zero(zone_info[0].capacity, zone_info[1].capacity);
 
+       /*
+        * When the last extent is removed, last_alloc can be smaller than the other write
+        * pointer. In that case, last_alloc should be moved to the corresponding write
+        * pointer position.
+        */
+       for (i = 0; i < map->num_stripes; i++) {
+               if (zone_info[i].alloc_offset == WP_MISSING_DEV ||
+                   zone_info[i].alloc_offset == WP_CONVENTIONAL)
+                       continue;
+               if (last_alloc <= zone_info[i].alloc_offset) {
+                       last_alloc = zone_info[i].alloc_offset;
+                       break;
+               }
+       }
+
        for (i = 0; i < map->num_stripes; i++) {
                if (zone_info[i].alloc_offset == WP_MISSING_DEV)
                        continue;