Skip to content

Commit 096bc7e

Browse files
damien-lemoalaxboe
authored andcommitted
block: Fix handling of non-empty flush write requests to zones
Zone write plugging ignores empty (no data) flush operations but handles flush BIOs that have data to ensure that the flush machinery generated write is processed in order. However, the call to blk_zone_write_plug_attempt_merge() which sets a request RQF_ZONE_WRITE_PLUGGING flag is called after blk_insert_flush(), thus missing indicating that a non empty flush request completion needs handling by zone write plugging. Fix this by moving the call to blk_zone_write_plug_attempt_merge() before blk_insert_flush(). And while at it, rename that function as blk_zone_write_plug_init_request() to be clear that it is not just about merging plugged BIOs in the request. While at it, also add a WARN_ONCE() check that the zone write plug for the request is not NULL. Fixes: dd291d7 ("block: Introduce zone write plugging") Signed-off-by: Damien Le Moal <dlemoal@kernel.org> Reviewed-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com> Link: https://lore.kernel.org/r/20240501110907.96950-10-dlemoal@kernel.org Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent af147b7 commit 096bc7e

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

block/blk-mq.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3001,12 +3001,12 @@ void blk_mq_submit_bio(struct bio *bio)
30013001
return;
30023002
}
30033003

3004+
if (bio_zone_write_plugging(bio))
3005+
blk_zone_write_plug_init_request(rq);
3006+
30043007
if (op_is_flush(bio->bi_opf) && blk_insert_flush(rq))
30053008
return;
30063009

3007-
if (bio_zone_write_plugging(bio))
3008-
blk_zone_write_plug_attempt_merge(rq);
3009-
30103010
if (plug) {
30113011
blk_add_rq_to_plug(plug, rq);
30123012
return;

block/blk-zoned.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -874,8 +874,9 @@ void blk_zone_write_plug_bio_merged(struct bio *bio)
874874

875875
/*
876876
* If the BIO was already plugged, then we were called through
877-
* blk_zone_write_plug_attempt_merge() -> blk_attempt_bio_merge().
878-
* For this case, blk_zone_write_plug_attempt_merge() will handle the
877+
* blk_zone_write_plug_init_request() -> blk_attempt_bio_merge().
878+
* For this case, we already hold a reference on the zone write plug for
879+
* the BIO and blk_zone_write_plug_init_request() will handle the
879880
* zone write pointer offset update.
880881
*/
881882
if (bio_flagged(bio, BIO_ZONE_WRITE_PLUGGING))
@@ -899,7 +900,7 @@ void blk_zone_write_plug_bio_merged(struct bio *bio)
899900
* already went through zone write plugging (either a new BIO or one that was
900901
* unplugged).
901902
*/
902-
void blk_zone_write_plug_attempt_merge(struct request *req)
903+
void blk_zone_write_plug_init_request(struct request *req)
903904
{
904905
sector_t req_back_sector = blk_rq_pos(req) + blk_rq_sectors(req);
905906
struct request_queue *q = req->q;
@@ -910,6 +911,9 @@ void blk_zone_write_plug_attempt_merge(struct request *req)
910911
unsigned long flags;
911912
struct bio *bio;
912913

914+
if (WARN_ON_ONCE(!zwplug))
915+
return;
916+
913917
/*
914918
* Indicate that completion of this request needs to be handled with
915919
* blk_zone_write_plug_complete_request(), which will drop the reference
@@ -1269,7 +1273,7 @@ void blk_zone_write_plug_complete_request(struct request *req)
12691273

12701274
/*
12711275
* Drop the reference we took when the request was initialized in
1272-
* blk_zone_write_plug_attempt_merge().
1276+
* blk_zone_write_plug_init_request().
12731277
*/
12741278
disk_put_zone_wplug(zwplug);
12751279

block/blk.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ static inline bool bio_is_zone_append(struct bio *bio)
427427
bio_flagged(bio, BIO_EMULATES_ZONE_APPEND);
428428
}
429429
void blk_zone_write_plug_bio_merged(struct bio *bio);
430-
void blk_zone_write_plug_attempt_merge(struct request *rq);
430+
void blk_zone_write_plug_init_request(struct request *rq);
431431
static inline void blk_zone_update_request_bio(struct request *rq,
432432
struct bio *bio)
433433
{
@@ -481,7 +481,7 @@ static inline bool bio_is_zone_append(struct bio *bio)
481481
static inline void blk_zone_write_plug_bio_merged(struct bio *bio)
482482
{
483483
}
484-
static inline void blk_zone_write_plug_attempt_merge(struct request *rq)
484+
static inline void blk_zone_write_plug_init_request(struct request *rq)
485485
{
486486
}
487487
static inline void blk_zone_update_request_bio(struct request *rq,

0 commit comments

Comments
 (0)