block: fix partial zone append completion handling in req_bio_endio()
PATCH 1/1 block: fix partial zone append completion handling in req_bio_endio()
Partial completions of zone append request is not allowed but if a zone append completion indicates a number of completed bytes different from the original BIO size, only the BIO status is set to error. This leads to bio_advance() not setting the BIO size to 0 and thus to not call bio_endio() at the end of req_bio_endio().
Make sure a partially completed zone append is failed and completed immediately by forcing the completed number of bytes (nbytes) to be equal to the BIO sizei, thus ensuring that bio_endio() is called.
--- block/blk-mq.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-)
block/blk-mq.c +7 -2
@@ -772,11 +772,16 @@ static void req_bio_endio(struct request *rq, struct bio *bio,/* * Partial zone append completions cannot be supported as the * BIO fragments may end up not being written sequentially. +* For such case, force the completed nbytes to be equal to +* the BIO size so that bio_advance() sets the BIO remaining +* size to 0 and we end up calling bio_endio() before returning. */ -if (bio->bi_iter.bi_size != nbytes) +if (bio->bi_iter.bi_size != nbytes) { bio->bi_status =BLK_STS_IOERR ; -else + nbytes = bio->bi_iter.bi_size; + }else { bio->bi_iter.bi_sector = rq->__sector; + } }bio_advance (bio, nbytes);
Signature · 1 line
2.43.0
Quoted 9 lines · Damien Le Moal
Partial completions of zone append request is not allowed but if a zone append completion indicates a number of completed bytes different from the original BIO size, only the BIO status is set to error. This leads to
bio_advance()not setting the BIO size to 0 and thus to not callbio_endio()at the end ofreq_bio_endio().Make sure a partially completed zone append is failed and completed immediately by forcing the completed number of bytes (nbytes) to be equal to the BIO sizei, thus ensuring that
bio_endio()is called.
This really is a should not ever happen case. But if it does happen anyway for some reason, this is the right way to deal with it, so:
Quoted 7 lines · Christoph Hellwig
Quoted 6 lines · Damien Le Moal
Partial completions of zone append request is not allowed but if a zone append completion indicates a number of completed bytes different from the original BIO size, only the BIO status is set to error. This leads to
bio_advance()not setting the BIO size to 0 and thus to not callbio_endio()at the end ofreq_bio_endio().
Quoted 6 lines
Quoted 3 lines
Make sure a partially completed zone append is failed and completed immediately by forcing the completed number of bytes (nbytes) to be equal to the BIO sizei, thus ensuring that
bio_endio()is called.This really is a should not ever happen case. But if it does happen anyway for some reason, this is the right way to deal with it, so:
Yes, that is likely impossible for NVMe ZNS. But that is definitely in the realm of the possible for SMR drives with zone append emulation using regular writes. ATA drives will never partially complete, but SAS drives may do so.
Quoted 2 lines
Reviewed-by Christoph Hellwig <[email protected]>
Thanks.
Signature · 2 lines
Damien Le Moal Western Digital Research
Quoted 1 line · Damien Le Moal
equal to the BIO sizei, thus ensuring that
bio_endio()is called.
typo: size ~^
Quoted 3 lines · Johannes Thumshirn
Quoted 1 line · Damien Le Moal
equal to the BIO sizei, thus ensuring that
bio_endio()is called.typo: size ~^
Oops... Sent a fix. Thanks.
Quoted 2 lines
Reviewed-by Johannes Thumshirn <[email protected]>
Signature · 2 lines
Damien Le Moal Western Digital Research