diff mbox series

[v2] block: fix partial zone append completion handling in req_bio_endio()

Message ID 20240110092942.442334-1-dlemoal@kernel.org (mailing list archive)
State New, archived
Headers show
Series [v2] block: fix partial zone append completion handling in req_bio_endio() | expand

Commit Message

Damien Le Moal Jan. 10, 2024, 9:29 a.m. UTC
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 size, thus ensuring that bio_endio() is called.

Fixes: 297db731847e ("block: fix req_bio_endio append error handling")
Cc: stable@kernel.vger.org
Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
Changes from v1:
 - Fixed typo in commit message
 - Added review tags

 block/blk-mq.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

Comments

Hannes Reinecke Jan. 10, 2024, 9:38 a.m. UTC | #1
On 1/10/24 10:29, Damien Le Moal wrote:
> 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 size, thus ensuring that bio_endio() is called.
> 
> Fixes: 297db731847e ("block: fix req_bio_endio append error handling")
> Cc: stable@kernel.vger.org
> Signed-off-by: Damien Le Moal <dlemoal@kernel.org>
> Reviewed-by: Christoph Hellwig <hch@lst.de>
> Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
> ---
> Changes from v1:
>   - Fixed typo in commit message
>   - Added review tags
> 
>   block/blk-mq.c | 9 +++++++--
>   1 file changed, 7 insertions(+), 2 deletions(-)
> 
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index c11c97afa0bc..cd59b172c8fc 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -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);

Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
Jens Axboe Jan. 10, 2024, 4:01 p.m. UTC | #2
On Wed, 10 Jan 2024 18:29:42 +0900, Damien Le Moal wrote:
> 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 size, thus ensuring that bio_endio() is called.
> 
> [...]

Applied, thanks!

[1/1] block: fix partial zone append completion handling in req_bio_endio()
      commit: 748dc0b65ec2b4b7b3dbd7befcc4a54fdcac7988

Best regards,
diff mbox series

Patch

diff --git a/block/blk-mq.c b/block/blk-mq.c
index c11c97afa0bc..cd59b172c8fc 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -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);