Skip to content

Commit 8f69746

Browse files
morbidrsakdave
authored andcommitted
btrfs: zoned: skip ZONE FINISH of conventional zones
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 <[email protected]> Reviewed-by: Anand Jain <[email protected]> Signed-off-by: Johannes Thumshirn <[email protected]>
1 parent 011f085 commit 8f69746

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
@@ -2245,6 +2245,40 @@ static void wait_eb_writebacks(struct btrfs_block_group *block_group)
22452245
rcu_read_unlock();
22462246
}
22472247

2248+
static int call_zone_finish(struct btrfs_block_group *block_group,
2249+
struct btrfs_io_stripe *stripe)
2250+
{
2251+
struct btrfs_device *device = stripe->dev;
2252+
const u64 physical = stripe->physical;
2253+
struct btrfs_zoned_device_info *zinfo = device->zone_info;
2254+
int ret;
2255+
2256+
if (!device->bdev)
2257+
return 0;
2258+
2259+
if (zinfo->max_active_zones == 0)
2260+
return 0;
2261+
2262+
if (btrfs_dev_is_sequential(device, physical)) {
2263+
unsigned int nofs_flags;
2264+
2265+
nofs_flags = memalloc_nofs_save();
2266+
ret = blkdev_zone_mgmt(device->bdev, REQ_OP_ZONE_FINISH,
2267+
physical >> SECTOR_SHIFT,
2268+
zinfo->zone_size >> SECTOR_SHIFT);
2269+
memalloc_nofs_restore(nofs_flags);
2270+
2271+
if (ret)
2272+
return ret;
2273+
}
2274+
2275+
if (!(block_group->flags & BTRFS_BLOCK_GROUP_DATA))
2276+
zinfo->reserved_active_zones++;
2277+
btrfs_dev_clear_active_zone(device, physical);
2278+
2279+
return 0;
2280+
}
2281+
22482282
static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_written)
22492283
{
22502284
struct btrfs_fs_info *fs_info = block_group->fs_info;
@@ -2329,31 +2363,12 @@ static int do_zone_finish(struct btrfs_block_group *block_group, bool fully_writ
23292363
down_read(&dev_replace->rwsem);
23302364
map = block_group->physical_map;
23312365
for (i = 0; i < map->num_stripes; i++) {
2332-
struct btrfs_device *device = map->stripes[i].dev;
2333-
const u64 physical = map->stripes[i].physical;
2334-
struct btrfs_zoned_device_info *zinfo = device->zone_info;
2335-
unsigned int nofs_flags;
2336-
2337-
if (!device->bdev)
2338-
continue;
2339-
2340-
if (zinfo->max_active_zones == 0)
2341-
continue;
2342-
2343-
nofs_flags = memalloc_nofs_save();
2344-
ret = blkdev_zone_mgmt(device->bdev, REQ_OP_ZONE_FINISH,
2345-
physical >> SECTOR_SHIFT,
2346-
zinfo->zone_size >> SECTOR_SHIFT);
2347-
memalloc_nofs_restore(nofs_flags);
23482366

2367+
ret = call_zone_finish(block_group, &map->stripes[i]);
23492368
if (ret) {
23502369
up_read(&dev_replace->rwsem);
23512370
return ret;
23522371
}
2353-
2354-
if (!(block_group->flags & BTRFS_BLOCK_GROUP_DATA))
2355-
zinfo->reserved_active_zones++;
2356-
btrfs_dev_clear_active_zone(device, physical);
23572372
}
23582373
up_read(&dev_replace->rwsem);
23592374

0 commit comments

Comments
 (0)