Skip to content

Commit 0800d97

Browse files
morbidrsagregkh
authored andcommitted
btrfs: zoned: skip ZONE FINISH of conventional zones
[ Upstream commit f0ba0e7 ] Don't call ZONE FINISH for conventional zones as this will result in I/O errors. Instead check if the zone that needs finishing is a conventional zone and if yes skip it. Also factor out the actual handling of finishing a single zone into a helper function, as do_zone_finish() is growing ever bigger and the indentations levels are getting higher. Reviewed-by: Naohiro Aota <naohiro.aota@wdc.com> Reviewed-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Signed-off-by: David Sterba <dsterba@suse.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
1 parent 6edbd02 commit 0800d97

File tree

1 file changed

+35
-20
lines changed

1 file changed

+35
-20
lines changed

fs/btrfs/zoned.c

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2252,6 +2252,40 @@ static void wait_eb_writebacks(struct btrfs_block_group *block_group)
22522252
rcu_read_unlock();
22532253
}
22542254

2255+
static int call_zone_finish(struct btrfs_block_group *block_group,
2256+
struct btrfs_io_stripe *stripe)
2257+
{
2258+
struct btrfs_device *device = stripe->dev;
2259+
const u64 physical = stripe->physical;
2260+
struct btrfs_zoned_device_info *zinfo = device->zone_info;
2261+
int ret;
2262+
2263+
if (!device->bdev)
2264+
return 0;
2265+
2266+
if (zinfo->max_active_zones == 0)
2267+
return 0;
2268+
2269+
if (btrfs_dev_is_sequential(device, physical)) {
2270+
unsigned int nofs_flags;
2271+
2272+
nofs_flags = memalloc_nofs_save();
2273+
ret = blkdev_zone_mgmt(device->bdev, REQ_OP_ZONE_FINISH,
2274+
physical >> SECTOR_SHIFT,
2275+
zinfo->zone_size >> SECTOR_SHIFT);
2276+
memalloc_nofs_restore(nofs_flags);
2277+
2278+
if (ret)
2279+
return ret;
2280+
}
2281+
2282+
if (!(block_group->flags & BTRFS_BLOCK_GROUP_DATA))
2283+
zinfo->reserved_active_zones++;
2284+
btrfs_dev_clear_active_zone(device, physical);
2285+
2286+
return 0;
2287+
}
2288+
22552289
static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_written)
22562290
{
22572291
struct btrfs_fs_info *fs_info = block_group->fs_info;
@@ -2336,31 +2370,12 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
23362370
down_read(&dev_replace->rwsem);
23372371
map = block_group->physical_map;
23382372
for (i = 0; i < map->num_stripes; i++) {
2339-
struct btrfs_device *device = map->stripes[i].dev;
2340-
const u64 physical = map->stripes[i].physical;
2341-
struct btrfs_zoned_device_info *zinfo = device->zone_info;
2342-
unsigned int nofs_flags;
2343-
2344-
if (!device->bdev)
2345-
continue;
2346-
2347-
if (zinfo->max_active_zones == 0)
2348-
continue;
2349-
2350-
nofs_flags = memalloc_nofs_save();
2351-
ret = blkdev_zone_mgmt(device->bdev, REQ_OP_ZONE_FINISH,
2352-
physical >> SECTOR_SHIFT,
2353-
zinfo->zone_size >> SECTOR_SHIFT);
2354-
memalloc_nofs_restore(nofs_flags);
23552373

2374+
ret = call_zone_finish(block_group, &map->stripes[i]);
23562375
if (ret) {
23572376
up_read(&dev_replace->rwsem);
23582377
return ret;
23592378
}
2360-
2361-
if (!(block_group->flags & BTRFS_BLOCK_GROUP_DATA))
2362-
zinfo->reserved_active_zones++;
2363-
btrfs_dev_clear_active_zone(device, physical);
23642379
}
23652380
up_read(&dev_replace->rwsem);
23662381

0 commit comments

Comments
 (0)