diff mbox series

[2/2] blk-mq: Move more error handling into blk_mq_submit_bio()

Message ID 20241216201901.2670237-3-bvanassche@acm.org (mailing list archive)
State New
Headers show
Series Move blk_mq_submit_bio() error handling | expand

Commit Message

Bart Van Assche Dec. 16, 2024, 8:19 p.m. UTC
The error handling code in blk_mq_get_new_requests() cannot be understood
without knowing that this function is only called by blk_mq_submit_bio().
Hence move the code for handling blk_mq_get_new_requests() failures into
blk_mq_submit_bio().

Cc: Damien Le Moal <dlemoal@kernel.org>
Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Bart Van Assche <bvanassche@acm.org>
---
 block/blk-mq.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

Comments

Christoph Hellwig Dec. 17, 2024, 4:18 a.m. UTC | #1
On Mon, Dec 16, 2024 at 12:19:01PM -0800, Bart Van Assche wrote:
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index 8d2aab4d9ba9..80eb91296142 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -2971,8 +2971,6 @@ static struct request *blk_mq_get_new_requests(struct request_queue *q,
>  	if (rq)
>  		return rq;
>  	rq_qos_cleanup(q, bio);
> -	if (bio->bi_opf & REQ_NOWAIT)
> -		bio_wouldblock_error(bio);
>  	return NULL;

Please turn this into:

	if (rq)
		rq_qos_cleanup(q, bio);
	return rq;

Otherwise this looks like a nice cleanup.
Bart Van Assche Dec. 17, 2024, 9:06 p.m. UTC | #2
On 12/16/24 8:18 PM, Christoph Hellwig wrote:
> On Mon, Dec 16, 2024 at 12:19:01PM -0800, Bart Van Assche wrote:
>> diff --git a/block/blk-mq.c b/block/blk-mq.c
>> index 8d2aab4d9ba9..80eb91296142 100644
>> --- a/block/blk-mq.c
>> +++ b/block/blk-mq.c
>> @@ -2971,8 +2971,6 @@ static struct request *blk_mq_get_new_requests(struct request_queue *q,
>>   	if (rq)
>>   		return rq;
>>   	rq_qos_cleanup(q, bio);
>> -	if (bio->bi_opf & REQ_NOWAIT)
>> -		bio_wouldblock_error(bio);
>>   	return NULL;
> 
> Please turn this into:
> 
> 	if (rq)
> 		rq_qos_cleanup(q, bio);
> 	return rq;
> 
> Otherwise this looks like a nice cleanup.

It seems to me that there is a typo in the above code? Unless if you 
tell me otherwise, I will assume that this is what you meant:

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 8d2aab4d9ba9..f4300e608ed8 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2968,12 +2968,9 @@ static struct request 
*blk_mq_get_new_requests(struct request_queue *q,
  	}

  	rq = __blk_mq_alloc_requests(&data);
-	if (rq)
-		return rq;
-	rq_qos_cleanup(q, bio);
-	if (bio->bi_opf & REQ_NOWAIT)
-		bio_wouldblock_error(bio);
-	return NULL;
+	if (!rq)
+		rq_qos_cleanup(q, bio);
+	return rq;
  }

  /*
@@ -3106,8 +3103,11 @@ void blk_mq_submit_bio(struct bio *bio)
  		blk_mq_use_cached_rq(rq, plug, bio);
  	} else {
  		rq = blk_mq_get_new_requests(q, plug, bio, nr_segs);
-		if (unlikely(!rq))
+		if (unlikely(!rq)) {
+			if (bio->bi_opf & REQ_NOWAIT)
+				bio_wouldblock_error(bio);
  			goto queue_exit;
+		}
  	}

  	trace_block_getrq(bio);



Thanks,

Bart.
Christoph Hellwig Dec. 18, 2024, 7 a.m. UTC | #3
On Tue, Dec 17, 2024 at 01:06:12PM -0800, Bart Van Assche wrote:
> It seems to me that there is a typo in the above code? Unless if you tell 
> me otherwise, I will assume that this is what you meant:

Yes.
diff mbox series

Patch

diff --git a/block/blk-mq.c b/block/blk-mq.c
index 8d2aab4d9ba9..80eb91296142 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -2971,8 +2971,6 @@  static struct request *blk_mq_get_new_requests(struct request_queue *q,
 	if (rq)
 		return rq;
 	rq_qos_cleanup(q, bio);
-	if (bio->bi_opf & REQ_NOWAIT)
-		bio_wouldblock_error(bio);
 	return NULL;
 }
 
@@ -3106,8 +3104,11 @@  void blk_mq_submit_bio(struct bio *bio)
 		blk_mq_use_cached_rq(rq, plug, bio);
 	} else {
 		rq = blk_mq_get_new_requests(q, plug, bio, nr_segs);
-		if (unlikely(!rq))
+		if (unlikely(!rq)) {
+			if (bio->bi_opf & REQ_NOWAIT)
+				bio_wouldblock_error(bio);
 			goto queue_exit;
+		}
 	}
 
 	trace_block_getrq(bio);