Skip to content

Commit e994ff5

Browse files
damien-lemoalaxboe
authored andcommitted
null_blk: Simplify null_zone_write()
In null_zone_write, we do not need to first check if the target zone condition is FULL, READONLY or OFFLINE: for theses conditions, the check of the command sector against the zone write pointer will always result in the command failing. Remove these checks. We still however need to check that the target zone write pointer is not invalid for zone append operations. To do so, add the macro NULL_ZONE_INVALID_WP and use it in null_set_zone_cond() when changing a zone to READONLY or OFFLINE condition. Signed-off-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Link: https://lore.kernel.org/r/20240411085502.728558-4-dlemoal@kernel.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent 3bdde07 commit e994ff5

1 file changed

Lines changed: 16 additions & 20 deletions

File tree

drivers/block/null_blk/zoned.c

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
#undef pr_fmt
1010
#define pr_fmt(fmt) "null_blk: " fmt
1111

12+
#define NULL_ZONE_INVALID_WP ((sector_t)-1)
13+
1214
static inline sector_t mb_to_sects(unsigned long mb)
1315
{
1416
return ((sector_t)mb * SZ_1M) >> SECTOR_SHIFT;
@@ -341,9 +343,6 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
341343

342344
trace_nullb_zone_op(cmd, zno, zone->cond);
343345

344-
if (WARN_ON_ONCE(append && !dev->zone_append_max_sectors))
345-
return BLK_STS_IOERR;
346-
347346
if (zone->type == BLK_ZONE_TYPE_CONVENTIONAL) {
348347
if (append)
349348
return BLK_STS_IOERR;
@@ -352,29 +351,26 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
352351

353352
null_lock_zone(dev, zone);
354353

355-
if (zone->cond == BLK_ZONE_COND_FULL ||
356-
zone->cond == BLK_ZONE_COND_READONLY ||
357-
zone->cond == BLK_ZONE_COND_OFFLINE) {
358-
/* Cannot write to the zone */
359-
ret = BLK_STS_IOERR;
360-
goto unlock_zone;
361-
}
362-
363354
/*
364-
* Regular writes must be at the write pointer position.
365-
* Zone append writes are automatically issued at the write
366-
* pointer and the position returned using the request or BIO
367-
* sector.
355+
* Regular writes must be at the write pointer position. Zone append
356+
* writes are automatically issued at the write pointer and the position
357+
* returned using the request sector. Note that we do not check the zone
358+
* condition because for FULL, READONLY and OFFLINE zones, the sector
359+
* check against the zone write pointer will always result in failing
360+
* the command.
368361
*/
369362
if (append) {
363+
if (WARN_ON_ONCE(!dev->zone_append_max_sectors) ||
364+
zone->wp == NULL_ZONE_INVALID_WP) {
365+
ret = BLK_STS_IOERR;
366+
goto unlock_zone;
367+
}
370368
sector = zone->wp;
371369
blk_mq_rq_from_pdu(cmd)->__sector = sector;
372-
} else if (sector != zone->wp) {
373-
ret = BLK_STS_IOERR;
374-
goto unlock_zone;
375370
}
376371

377-
if (zone->wp + nr_sectors > zone->start + zone->capacity) {
372+
if (sector != zone->wp ||
373+
zone->wp + nr_sectors > zone->start + zone->capacity) {
378374
ret = BLK_STS_IOERR;
379375
goto unlock_zone;
380376
}
@@ -743,7 +739,7 @@ static void null_set_zone_cond(struct nullb_device *dev,
743739
zone->cond != BLK_ZONE_COND_OFFLINE)
744740
null_finish_zone(dev, zone);
745741
zone->cond = cond;
746-
zone->wp = (sector_t)-1;
742+
zone->wp = NULL_ZONE_INVALID_WP;
747743
}
748744

749745
null_unlock_zone(dev, zone);

0 commit comments

Comments
 (0)