]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
btrfs: zoned: finish block group when there are no more allocatable bytes left
authorNaohiro Aota <naohiro.aota@wdc.com>
Wed, 4 May 2022 00:48:52 +0000 (17:48 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Jun 2022 08:29:31 +0000 (10:29 +0200)
commit 8b8a53998caefebfe5c8da7a74c2b601caf5dd48 upstream.

Currently, btrfs_zone_finish_endio() finishes a block group only when the
written region reaches the end of the block group. We can also finish the
block group when no more allocation is possible.

Fixes: be1a1d7a5d24 ("btrfs: zoned: finish fully written block group")
CC: stable@vger.kernel.org # 5.16+
Reviewed-by: Pankaj Raghav <p.raghav@samsung.com>
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: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
fs/btrfs/zoned.c

index 3f932198ae316b2db9a36e63e8c759e56fb51aa0..a6417ec093f3358aeed416ad41d2bb1e2dffd727 100644 (file)
@@ -2000,6 +2000,7 @@ void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 len
        struct btrfs_block_group *block_group;
        struct map_lookup *map;
        struct btrfs_device *device;
+       u64 min_alloc_bytes;
        u64 physical;
 
        if (!btrfs_is_zoned(fs_info))
@@ -2008,7 +2009,15 @@ void btrfs_zone_finish_endio(struct btrfs_fs_info *fs_info, u64 logical, u64 len
        block_group = btrfs_lookup_block_group(fs_info, logical);
        ASSERT(block_group);
 
-       if (logical + length < block_group->start + block_group->zone_capacity)
+       /* No MIXED_BG on zoned btrfs. */
+       if (block_group->flags & BTRFS_BLOCK_GROUP_DATA)
+               min_alloc_bytes = fs_info->sectorsize;
+       else
+               min_alloc_bytes = fs_info->nodesize;
+
+       /* Bail out if we can allocate more data from this block group. */
+       if (logical + length + min_alloc_bytes <=
+           block_group->start + block_group->zone_capacity)
                goto out;
 
        spin_lock(&block_group->lock);