Skip to content

Commit a0508c3

Browse files
damien-lemoalaxboe
authored andcommitted
block: Introduce blk_zone_update_request_bio()
On completion of a zone append request, the request sector indicates the location of the written data. This value must be returned to the user through the BIO iter sector. This is done in 2 places: in blk_complete_request() and in blk_update_request(). Introduce the inline helper function blk_zone_update_request_bio() to avoid duplicating this BIO update for zone append requests, and to compile out this helper call when CONFIG_BLK_DEV_ZONED is not enabled. Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Hannes Reinecke <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Tested-by: Hans Holmberg <[email protected]> Tested-by: Dennis Maisenbacher <[email protected]> Reviewed-by: Martin K. Petersen <[email protected]> Reviewed-by: Johannes Thumshirn <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent c0da26f commit a0508c3

File tree

2 files changed

+23
-7
lines changed

2 files changed

+23
-7
lines changed

block/blk-mq.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -821,8 +821,7 @@ static void blk_complete_request(struct request *req)
821821
/* Completion has already been traced */
822822
bio_clear_flag(bio, BIO_TRACE_COMPLETION);
823823

824-
if (req_op(req) == REQ_OP_ZONE_APPEND)
825-
bio->bi_iter.bi_sector = req->__sector;
824+
blk_zone_update_request_bio(req, bio);
826825

827826
if (!is_flush)
828827
bio_endio(bio);
@@ -923,10 +922,10 @@ bool blk_update_request(struct request *req, blk_status_t error,
923922
bio_advance(bio, bio_bytes);
924923

925924
/* Don't actually finish bio if it's part of flush sequence */
926-
if (!bio->bi_iter.bi_size && !is_flush) {
927-
if (req_op(req) == REQ_OP_ZONE_APPEND)
928-
bio->bi_iter.bi_sector = req->__sector;
929-
bio_endio(bio);
925+
if (!bio->bi_iter.bi_size) {
926+
blk_zone_update_request_bio(req, bio);
927+
if (!is_flush)
928+
bio_endio(bio);
930929
}
931930

932931
total_bytes += bio_bytes;

block/blk.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -408,12 +408,29 @@ static inline struct bio *blk_queue_bounce(struct bio *bio,
408408

409409
#ifdef CONFIG_BLK_DEV_ZONED
410410
void disk_free_zone_bitmaps(struct gendisk *disk);
411+
static inline void blk_zone_update_request_bio(struct request *rq,
412+
struct bio *bio)
413+
{
414+
/*
415+
* For zone append requests, the request sector indicates the location
416+
* at which the BIO data was written. Return this value to the BIO
417+
* issuer through the BIO iter sector.
418+
*/
419+
if (req_op(rq) == REQ_OP_ZONE_APPEND)
420+
bio->bi_iter.bi_sector = rq->__sector;
421+
}
411422
int blkdev_report_zones_ioctl(struct block_device *bdev, unsigned int cmd,
412423
unsigned long arg);
413424
int blkdev_zone_mgmt_ioctl(struct block_device *bdev, blk_mode_t mode,
414425
unsigned int cmd, unsigned long arg);
415426
#else /* CONFIG_BLK_DEV_ZONED */
416-
static inline void disk_free_zone_bitmaps(struct gendisk *disk) {}
427+
static inline void disk_free_zone_bitmaps(struct gendisk *disk)
428+
{
429+
}
430+
static inline void blk_zone_update_request_bio(struct request *rq,
431+
struct bio *bio)
432+
{
433+
}
417434
static inline int blkdev_report_zones_ioctl(struct block_device *bdev,
418435
unsigned int cmd, unsigned long arg)
419436
{

0 commit comments

Comments
 (0)