Skip to content

Commit 6839108

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 70a6e89 commit 6839108

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
@@ -2186,6 +2186,40 @@ static void wait_eb_writebacks(struct btrfs_block_group *block_group)
21862186
rcu_read_unlock();
21872187
}
21882188

2189+
static int call_zone_finish(struct btrfs_block_group *block_group,
2190+
struct btrfs_io_stripe *stripe)
2191+
{
2192+
struct btrfs_device *device = stripe->dev;
2193+
const u64 physical = stripe->physical;
2194+
struct btrfs_zoned_device_info *zinfo = device->zone_info;
2195+
int ret;
2196+
2197+
if (!device->bdev)
2198+
return 0;
2199+
2200+
if (zinfo->max_active_zones == 0)
2201+
return 0;
2202+
2203+
if (btrfs_dev_is_sequential(device, physical)) {
2204+
unsigned int nofs_flags;
2205+
2206+
nofs_flags = memalloc_nofs_save();
2207+
ret = blkdev_zone_mgmt(device->bdev, REQ_OP_ZONE_FINISH,
2208+
physical >> SECTOR_SHIFT,
2209+
zinfo->zone_size >> SECTOR_SHIFT);
2210+
memalloc_nofs_restore(nofs_flags);
2211+
2212+
if (ret)
2213+
return ret;
2214+
}
2215+
2216+
if (!(block_group->flags & BTRFS_BLOCK_GROUP_DATA))
2217+
zinfo->reserved_active_zones++;
2218+
btrfs_dev_clear_active_zone(device, physical);
2219+
2220+
return 0;
2221+
}
2222+
21892223
static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_written)
21902224
{
21912225
struct btrfs_fs_info *fs_info = block_group->fs_info;
@@ -2270,31 +2304,12 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
22702304
down_read(&dev_replace->rwsem);
22712305
map = block_group->physical_map;
22722306
for (i = 0; i < map->num_stripes; i++) {
2273-
struct btrfs_device *device = map->stripes[i].dev;
2274-
const u64 physical = map->stripes[i].physical;
2275-
struct btrfs_zoned_device_info *zinfo = device->zone_info;
2276-
unsigned int nofs_flags;
2277-
2278-
if (!device->bdev)
2279-
continue;
2280-
2281-
if (zinfo->max_active_zones == 0)
2282-
continue;
2283-
2284-
nofs_flags = memalloc_nofs_save();
2285-
ret = blkdev_zone_mgmt(device->bdev, REQ_OP_ZONE_FINISH,
2286-
physical >> SECTOR_SHIFT,
2287-
zinfo->zone_size >> SECTOR_SHIFT);
2288-
memalloc_nofs_restore(nofs_flags);
22892307

2308+
ret = call_zone_finish(block_group, &map->stripes[i]);
22902309
if (ret) {
22912310
up_read(&dev_replace->rwsem);
22922311
return ret;
22932312
}
2294-
2295-
if (!(block_group->flags & BTRFS_BLOCK_GROUP_DATA))
2296-
zinfo->reserved_active_zones++;
2297-
btrfs_dev_clear_active_zone(device, physical);
22982313
}
22992314
up_read(&dev_replace->rwsem);
23002315

0 commit comments

Comments
 (0)