Skip to content

Commit e0489ed

Browse files
damien-lemoalaxboe
authored andcommitted
null_blk: Support REQ_OP_ZONE_APPEND
Support REQ_OP_ZONE_APPEND requests for null_blk devices with zoned mode enabled. Use the internally tracked zone write pointer position as the actual write position and return it using the command request __sector field in the case of an mq device and using the command BIO sector in the case of a BIO device. Signed-off-by: Damien Le Moal <[email protected]> Signed-off-by: Johannes Thumshirn <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Signed-off-by: Jens Axboe <[email protected]>
1 parent 5795eb4 commit e0489ed

File tree

1 file changed

+29
-8
lines changed

1 file changed

+29
-8
lines changed

drivers/block/null_blk_zoned.c

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,13 +70,20 @@ int null_init_zoned_dev(struct nullb_device *dev, struct request_queue *q)
7070

7171
int null_register_zoned_dev(struct nullb *nullb)
7272
{
73+
struct nullb_device *dev = nullb->dev;
7374
struct request_queue *q = nullb->q;
7475

75-
if (queue_is_mq(q))
76-
return blk_revalidate_disk_zones(nullb->disk, NULL);
76+
if (queue_is_mq(q)) {
77+
int ret = blk_revalidate_disk_zones(nullb->disk, NULL);
78+
79+
if (ret)
80+
return ret;
81+
} else {
82+
blk_queue_chunk_sectors(q, dev->zone_size_sects);
83+
q->nr_zones = blkdev_nr_zones(nullb->disk);
84+
}
7785

78-
blk_queue_chunk_sectors(q, nullb->dev->zone_size_sects);
79-
q->nr_zones = blkdev_nr_zones(nullb->disk);
86+
blk_queue_max_zone_append_sectors(q, dev->zone_size_sects);
8087

8188
return 0;
8289
}
@@ -138,7 +145,7 @@ size_t null_zone_valid_read_len(struct nullb *nullb,
138145
}
139146

140147
static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
141-
unsigned int nr_sectors)
148+
unsigned int nr_sectors, bool append)
142149
{
143150
struct nullb_device *dev = cmd->nq->dev;
144151
unsigned int zno = null_zone_no(dev, sector);
@@ -158,9 +165,21 @@ static blk_status_t null_zone_write(struct nullb_cmd *cmd, sector_t sector,
158165
case BLK_ZONE_COND_IMP_OPEN:
159166
case BLK_ZONE_COND_EXP_OPEN:
160167
case BLK_ZONE_COND_CLOSED:
161-
/* Writes must be at the write pointer position */
162-
if (sector != zone->wp)
168+
/*
169+
* Regular writes must be at the write pointer position.
170+
* Zone append writes are automatically issued at the write
171+
* pointer and the position returned using the request or BIO
172+
* sector.
173+
*/
174+
if (append) {
175+
sector = zone->wp;
176+
if (cmd->bio)
177+
cmd->bio->bi_iter.bi_sector = sector;
178+
else
179+
cmd->rq->__sector = sector;
180+
} else if (sector != zone->wp) {
163181
return BLK_STS_IOERR;
182+
}
164183

165184
if (zone->cond != BLK_ZONE_COND_EXP_OPEN)
166185
zone->cond = BLK_ZONE_COND_IMP_OPEN;
@@ -242,7 +261,9 @@ blk_status_t null_process_zoned_cmd(struct nullb_cmd *cmd, enum req_opf op,
242261
{
243262
switch (op) {
244263
case REQ_OP_WRITE:
245-
return null_zone_write(cmd, sector, nr_sectors);
264+
return null_zone_write(cmd, sector, nr_sectors, false);
265+
case REQ_OP_ZONE_APPEND:
266+
return null_zone_write(cmd, sector, nr_sectors, true);
246267
case REQ_OP_ZONE_RESET:
247268
case REQ_OP_ZONE_RESET_ALL:
248269
case REQ_OP_ZONE_OPEN:

0 commit comments

Comments
 (0)