diff mbox series

blk-mq: Use helpers to access rq->state

Message ID 20210512095017.235295-1-nborisov@suse.com (mailing list archive)
State New, archived
Headers show
Series blk-mq: Use helpers to access rq->state | expand

Commit Message

Nikolay Borisov May 12, 2021, 9:50 a.m. UTC
Instead of having a mixed bag of opencoded usage and helper usage,
simply replace opencoded sites with the appropriate helper. No
functional changes.

Signed-off-by: Nikolay Borisov <nborisov@suse.com>
---
 block/blk-mq.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

Comments

Hannes Reinecke May 12, 2021, 3:24 p.m. UTC | #1
On 5/12/21 11:50 AM, Nikolay Borisov wrote:
> Instead of having a mixed bag of opencoded usage and helper usage,
> simply replace opencoded sites with the appropriate helper. No
> functional changes.
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> ---
>   block/blk-mq.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
Reviewed-by: Hannes Reinecke <hare@suse.de>

Cheers,

Hannes
Chaitanya Kulkarni May 12, 2021, 8:01 p.m. UTC | #2
On 5/12/21 02:50, Nikolay Borisov wrote:
> Instead of having a mixed bag of opencoded usage and helper usage,
> simply replace opencoded sites with the appropriate helper. No
> functional changes.
>
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Not sure if that is kept open coded to make code easy to read.

In either case looks good.

Reviewed-by: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Nikolay Borisov Aug. 30, 2021, 2:24 p.m. UTC | #3
On 12.05.21 г. 12:50, Nikolay Borisov wrote:
> Instead of having a mixed bag of opencoded usage and helper usage,
> simply replace opencoded sites with the appropriate helper. No
> functional changes.
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>

Ping
Bart Van Assche Aug. 30, 2021, 5:29 p.m. UTC | #4
On 5/12/21 2:50 AM, Nikolay Borisov wrote:
> Instead of having a mixed bag of opencoded usage and helper usage,
> simply replace opencoded sites with the appropriate helper. No
> functional changes.
> 
> Signed-off-by: Nikolay Borisov <nborisov@suse.com>
> ---
>   block/blk-mq.c | 6 +++---
>   1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/block/blk-mq.c b/block/blk-mq.c
> index d4d7c1caa439..d1cfacf2734c 100644
> --- a/block/blk-mq.c
> +++ b/block/blk-mq.c
> @@ -644,7 +644,7 @@ static void blk_mq_raise_softirq(struct request *rq)
>   
>   bool blk_mq_complete_request_remote(struct request *rq)
>   {
> -	WRITE_ONCE(rq->state, MQ_RQ_COMPLETE);
> +	blk_mq_set_request_complete(rq);
>   
>   	/*
>   	 * For a polled request, always complete locallly, it's pointless
> @@ -721,7 +721,7 @@ void blk_mq_start_request(struct request *rq)
>   		rq_qos_issue(q, rq);
>   	}
>   
> -	WARN_ON_ONCE(blk_mq_rq_state(rq) != MQ_RQ_IDLE);
> +	WARN_ON_ONCE(blk_mq_request_started(rq));
>   
>   	blk_add_timer(rq);
>   	WRITE_ONCE(rq->state, MQ_RQ_IN_FLIGHT);
> @@ -3812,7 +3812,7 @@ static bool blk_mq_poll_hybrid_sleep(struct request_queue *q,
>   	hrtimer_set_expires(&hs.timer, kt);
>   
>   	do {
> -		if (blk_mq_rq_state(rq) == MQ_RQ_COMPLETE)
> +		if (blk_mq_request_completed(rq))
>   			break;
>   		set_current_state(TASK_UNINTERRUPTIBLE);
>   		hrtimer_sleeper_start_expires(&hs, mode);

Is the above patch complete? I think even with the above patch applied
there are still two functions in the block layer that use WRITE_ONCE() to
modify rq->state directly:

$ git grep -nH 'WRITE_ONCE(rq->state,'
block/blk-mq.c:532:	WRITE_ONCE(rq->state, MQ_RQ_IDLE);
block/blk-mq.c:648:	WRITE_ONCE(rq->state, MQ_RQ_COMPLETE);
block/blk-mq.c:728:	WRITE_ONCE(rq->state, MQ_RQ_IN_FLIGHT);
block/blk-mq.c:747:		WRITE_ONCE(rq->state, MQ_RQ_IDLE);
block/blk-mq.c:2416:	WRITE_ONCE(rq->state, MQ_RQ_IDLE);
include/linux/blk-mq.h:521:	WRITE_ONCE(rq->state, MQ_RQ_COMPLETE);

Thanks,

Bart.
Nikolay Borisov Aug. 31, 2021, 6:42 a.m. UTC | #5
On 30.08.21 г. 20:29, Bart Van Assche wrote:
<snip>

> Is the above patch complete? I think even with the above patch applied
> there are still two functions in the block layer that use WRITE_ONCE() to
> modify rq->state directly:
> 
> $ git grep -nH 'WRITE_ONCE(rq->state,'
> block/blk-mq.c:532:    WRITE_ONCE(rq->state, MQ_RQ_IDLE);
> block/blk-mq.c:648:    WRITE_ONCE(rq->state, MQ_RQ_COMPLETE);
> block/blk-mq.c:728:    WRITE_ONCE(rq->state, MQ_RQ_IN_FLIGHT);
> block/blk-mq.c:747:        WRITE_ONCE(rq->state, MQ_RQ_IDLE);
> block/blk-mq.c:2416:    WRITE_ONCE(rq->state, MQ_RQ_IDLE);
> include/linux/blk-mq.h:521:    WRITE_ONCE(rq->state, MQ_RQ_COMPLETE);

On just-updated master I get:

$ git grep 'WRITE_ONCE(rq->state,'
block/blk-mq.c: WRITE_ONCE(rq->state, MQ_RQ_IDLE);
block/blk-mq.c: WRITE_ONCE(rq->state, MQ_RQ_IN_FLIGHT);
block/blk-mq.c:         WRITE_ONCE(rq->state, MQ_RQ_IDLE);
block/blk-mq.c: WRITE_ONCE(rq->state, MQ_RQ_IDLE);
include/linux/blk-mq.h: WRITE_ONCE(rq->state, MQ_RQ_COMPLETE);


> 
> Thanks,
> 
> Bart.
>
diff mbox series

Patch

diff --git a/block/blk-mq.c b/block/blk-mq.c
index d4d7c1caa439..d1cfacf2734c 100644
--- a/block/blk-mq.c
+++ b/block/blk-mq.c
@@ -644,7 +644,7 @@  static void blk_mq_raise_softirq(struct request *rq)
 
 bool blk_mq_complete_request_remote(struct request *rq)
 {
-	WRITE_ONCE(rq->state, MQ_RQ_COMPLETE);
+	blk_mq_set_request_complete(rq);
 
 	/*
 	 * For a polled request, always complete locallly, it's pointless
@@ -721,7 +721,7 @@  void blk_mq_start_request(struct request *rq)
 		rq_qos_issue(q, rq);
 	}
 
-	WARN_ON_ONCE(blk_mq_rq_state(rq) != MQ_RQ_IDLE);
+	WARN_ON_ONCE(blk_mq_request_started(rq));
 
 	blk_add_timer(rq);
 	WRITE_ONCE(rq->state, MQ_RQ_IN_FLIGHT);
@@ -3812,7 +3812,7 @@  static bool blk_mq_poll_hybrid_sleep(struct request_queue *q,
 	hrtimer_set_expires(&hs.timer, kt);
 
 	do {
-		if (blk_mq_rq_state(rq) == MQ_RQ_COMPLETE)
+		if (blk_mq_request_completed(rq))
 			break;
 		set_current_state(TASK_UNINTERRUPTIBLE);
 		hrtimer_sleeper_start_expires(&hs, mode);