]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
btrfs: update stripe_extent delete loop assumptions
authorJohannes Thumshirn <johannes.thumshirn@wdc.com>
Tue, 9 Jul 2024 07:40:34 +0000 (09:40 +0200)
committerDavid Sterba <dsterba@suse.com>
Tue, 10 Sep 2024 14:51:12 +0000 (16:51 +0200)
btrfs_delete_raid_extent() was written under the assumption, that it's
call-chain always passes a start, length tuple that matches a single
extent. But btrfs_delete_raid_extent() is called by
do_free_extent_accounting() which in turn is called by
__btrfs_free_extent().

But this call-chain passes in a start address and a length that can
possibly match multiple on-disk extents.

To make this possible, we have to adjust the start and length of each
btree node lookup, to not delete beyond the requested range.

Reviewed-by: Qu Wenruo <wqu@suse.com>
Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Signed-off-by: David Sterba <dsterba@suse.com>
fs/btrfs/raid-stripe-tree.c

index 0c7b928805e5e06ef299dfaae215012da8d4d290..bd06ff7956910f06e7c06b0f35daaf9ca235f23d 100644 (file)
@@ -66,6 +66,11 @@ int btrfs_delete_raid_extent(struct btrfs_trans_handle *trans, u64 start, u64 le
                if (ret)
                        break;
 
+               start += key.offset;
+               length -= key.offset;
+               if (length == 0)
+                       break;
+
                btrfs_release_path(path);
        }