Skip to content

Commit c0da26f

Browse files
damien-lemoalaxboe
authored andcommitted
block: Remove req_bio_endio()
Moving req_bio_endio() code into its only caller, blk_update_request(), allows reducing accesses to and tests of bio and request fields. Also, given that partial completions of zone append operations is not possible and that zone append operations cannot be merged, the update of the BIO sector using the request sector for these operations can be moved directly before the call to bio_endio(). Signed-off-by: Damien Le Moal <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]> Reviewed-by: Bart Van Assche <[email protected]> Reviewed-by: Hannes Reinecke <[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 6f8fd75 commit c0da26f

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

block/blk-mq.c

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -762,31 +762,6 @@ void blk_dump_rq_flags(struct request *rq, char *msg)
762762
}
763763
EXPORT_SYMBOL(blk_dump_rq_flags);
764764

765-
static void req_bio_endio(struct request *rq, struct bio *bio,
766-
unsigned int nbytes, blk_status_t error)
767-
{
768-
if (unlikely(error)) {
769-
bio->bi_status = error;
770-
} else if (req_op(rq) == REQ_OP_ZONE_APPEND) {
771-
/*
772-
* Partial zone append completions cannot be supported as the
773-
* BIO fragments may end up not being written sequentially.
774-
*/
775-
if (bio->bi_iter.bi_size != nbytes)
776-
bio->bi_status = BLK_STS_IOERR;
777-
else
778-
bio->bi_iter.bi_sector = rq->__sector;
779-
}
780-
781-
bio_advance(bio, nbytes);
782-
783-
if (unlikely(rq->rq_flags & RQF_QUIET))
784-
bio_set_flag(bio, BIO_QUIET);
785-
/* don't actually finish bio if it's part of flush sequence */
786-
if (bio->bi_iter.bi_size == 0 && !(rq->rq_flags & RQF_FLUSH_SEQ))
787-
bio_endio(bio);
788-
}
789-
790765
static void blk_account_io_completion(struct request *req, unsigned int bytes)
791766
{
792767
if (req->part && blk_do_io_stat(req)) {
@@ -890,6 +865,8 @@ static void blk_complete_request(struct request *req)
890865
bool blk_update_request(struct request *req, blk_status_t error,
891866
unsigned int nr_bytes)
892867
{
868+
bool is_flush = req->rq_flags & RQF_FLUSH_SEQ;
869+
bool quiet = req->rq_flags & RQF_QUIET;
893870
int total_bytes;
894871

895872
trace_block_rq_complete(req, error, nr_bytes);
@@ -910,9 +887,8 @@ bool blk_update_request(struct request *req, blk_status_t error,
910887
if (blk_crypto_rq_has_keyslot(req) && nr_bytes >= blk_rq_bytes(req))
911888
__blk_crypto_rq_put_keyslot(req);
912889

913-
if (unlikely(error && !blk_rq_is_passthrough(req) &&
914-
!(req->rq_flags & RQF_QUIET)) &&
915-
!test_bit(GD_DEAD, &req->q->disk->state)) {
890+
if (unlikely(error && !blk_rq_is_passthrough(req) && !quiet) &&
891+
!test_bit(GD_DEAD, &req->q->disk->state)) {
916892
blk_print_req_error(req, error);
917893
trace_block_rq_error(req, error, nr_bytes);
918894
}
@@ -924,12 +900,34 @@ bool blk_update_request(struct request *req, blk_status_t error,
924900
struct bio *bio = req->bio;
925901
unsigned bio_bytes = min(bio->bi_iter.bi_size, nr_bytes);
926902

927-
if (bio_bytes == bio->bi_iter.bi_size)
903+
if (unlikely(error))
904+
bio->bi_status = error;
905+
906+
if (bio_bytes == bio->bi_iter.bi_size) {
928907
req->bio = bio->bi_next;
908+
} else if (req_op(req) == REQ_OP_ZONE_APPEND &&
909+
error == BLK_STS_OK) {
910+
/*
911+
* Partial zone append completions cannot be supported
912+
* as the BIO fragments may end up not being written
913+
* sequentially.
914+
*/
915+
bio->bi_status = BLK_STS_IOERR;
916+
}
929917

930918
/* Completion has already been traced */
931919
bio_clear_flag(bio, BIO_TRACE_COMPLETION);
932-
req_bio_endio(req, bio, bio_bytes, error);
920+
if (unlikely(quiet))
921+
bio_set_flag(bio, BIO_QUIET);
922+
923+
bio_advance(bio, bio_bytes);
924+
925+
/* 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);
930+
}
933931

934932
total_bytes += bio_bytes;
935933
nr_bytes -= bio_bytes;

0 commit comments

Comments
 (0)