diff mbox

scsi: core: use blk_mq_requeue_request in __scsi_queue_insert

Message ID 1519631932-1730-1-git-send-email-jianchao.w.wang@oracle.com (mailing list archive)
State Changes Requested
Headers show

Commit Message

jianchao.wang Feb. 26, 2018, 7:58 a.m. UTC
In scsi core, __scsi_queue_insert should just put request back on
the queue and retry using the same command as before. However, for
blk-mq, scsi_mq_requeue_cmd is employed here which will unprepare
the request. To align with the semantics of __scsi_queue_insert,
just use blk_mq_requeue_request with kick_requeue_list == true.

Cc: Christoph Hellwig <hch@lst.de>
Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
---
 drivers/scsi/scsi_lib.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Bart Van Assche Feb. 27, 2018, 3:08 a.m. UTC | #1
On Mon, 2018-02-26 at 15:58 +0800, Jianchao Wang wrote:
> In scsi core, __scsi_queue_insert should just put request back on

> the queue and retry using the same command as before. However, for

> blk-mq, scsi_mq_requeue_cmd is employed here which will unprepare

> the request. To align with the semantics of __scsi_queue_insert,

> just use blk_mq_requeue_request with kick_requeue_list == true.

> 

> Cc: Christoph Hellwig <hch@lst.de>

> Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>

> ---

>  drivers/scsi/scsi_lib.c | 2 +-

>  1 file changed, 1 insertion(+), 1 deletion(-)

> 

> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c

> index a86df9c..06d8110 100644

> --- a/drivers/scsi/scsi_lib.c

> +++ b/drivers/scsi/scsi_lib.c

> @@ -191,7 +191,7 @@ static void __scsi_queue_insert(struct scsi_cmnd *cmd, int reason, bool unbusy)

>  	 */

>  	cmd->result = 0;

>  	if (q->mq_ops) {

> -		scsi_mq_requeue_cmd(cmd);

> +		blk_mq_requeue_request(cmd->request, true);

>  		return;

>  	}

>  	spin_lock_irqsave(q->queue_lock, flags);


I think this patch will break the code in the aacraid driver that iterates
over sdev->cmd_list because commands are added to and removed from that
list in the prep / unprep code.

Bart.
jianchao.wang Feb. 27, 2018, 3:28 a.m. UTC | #2
Hi Bart

Thanks for your kindly response.

On 02/27/2018 11:08 AM, Bart Van Assche wrote:
> On Mon, 2018-02-26 at 15:58 +0800, Jianchao Wang wrote:
>> In scsi core, __scsi_queue_insert should just put request back on
>> the queue and retry using the same command as before. However, for
>> blk-mq, scsi_mq_requeue_cmd is employed here which will unprepare
>> the request. To align with the semantics of __scsi_queue_insert,
>> just use blk_mq_requeue_request with kick_requeue_list == true.
>>
>> Cc: Christoph Hellwig <hch@lst.de>
>> Signed-off-by: Jianchao Wang <jianchao.w.wang@oracle.com>
>> ---
>>  drivers/scsi/scsi_lib.c | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
>> index a86df9c..06d8110 100644
>> --- a/drivers/scsi/scsi_lib.c
>> +++ b/drivers/scsi/scsi_lib.c
>> @@ -191,7 +191,7 @@ static void __scsi_queue_insert(struct scsi_cmnd *cmd, int reason, bool unbusy)
>>  	 */
>>  	cmd->result = 0;
>>  	if (q->mq_ops) {
>> -		scsi_mq_requeue_cmd(cmd);
>> +		blk_mq_requeue_request(cmd->request, true);
>>  		return;
>>  	}
>>  	spin_lock_irqsave(q->queue_lock, flags);
> 
> I think this patch will break the code in the aacraid driver that iterates
> over sdev->cmd_list because commands are added to and removed from that
> list in the prep / unprep code.

If that is true, what if aacraid driver uses block legacy instead of blk-mq ?
w/ blk-mq disabled, __scsi_queue_insert just requeue the request with blk_requeue_request.

__scsi_queue_insert
...
	if (q->mq_ops) {
		scsi_mq_requeue_cmd(cmd);
		return;
	}
	spin_lock_irqsave(q->queue_lock, flags);
	blk_requeue_request(q, cmd->request);
	kblockd_schedule_work(&device->requeue_work);
	spin_unlock_irqrestore(q->queue_lock, flags);
...

no prep/unprep code there for block legacy code.

Thanks
Jianchao

> 
> Bart.
>
Bart Van Assche Feb. 27, 2018, 3:41 a.m. UTC | #3
On Tue, 2018-02-27 at 11:28 +0800, jianchao.wang wrote:
> If that is true, what if aacraid driver uses block legacy instead of blk-mq ?

> w/ blk-mq disabled, __scsi_queue_insert just requeue the request with blk_requeue_request.

> 

> __scsi_queue_insert

> ...

> 	if (q->mq_ops) {

> 		scsi_mq_requeue_cmd(cmd);

> 		return;

> 	}

> 	spin_lock_irqsave(q->queue_lock, flags);

> 	blk_requeue_request(q, cmd->request);

> 	kblockd_schedule_work(&device->requeue_work);

> 	spin_unlock_irqrestore(q->queue_lock, flags);

> ...

> 

> no prep/unprep code there for block legacy code.


Hello Jianchao,

For the legacy block layer preparing and unpreparing a request happens from
inside the block layer core. Please have a look at block/blk-core.c and the
code in that file that handles the request flag RQF_DONTPREP.

Thanks,

Bart.
jianchao.wang Feb. 27, 2018, 4 a.m. UTC | #4
Hi Bart

Thanks for your kindly response.

On 02/27/2018 11:41 AM, Bart Van Assche wrote:
> On Tue, 2018-02-27 at 11:28 +0800, jianchao.wang wrote:
>> If that is true, what if aacraid driver uses block legacy instead of blk-mq ?
>> w/ blk-mq disabled, __scsi_queue_insert just requeue the request with blk_requeue_request.
>>
>> __scsi_queue_insert
>> ...
>> 	if (q->mq_ops) {
>> 		scsi_mq_requeue_cmd(cmd);
>> 		return;
>> 	}
>> 	spin_lock_irqsave(q->queue_lock, flags);
>> 	blk_requeue_request(q, cmd->request);
>> 	kblockd_schedule_work(&device->requeue_work);
>> 	spin_unlock_irqrestore(q->queue_lock, flags);
>> ...
>>
>> no prep/unprep code there for block legacy code.
> 
> Hello Jianchao,
> 
> For the legacy block layer preparing and unpreparing a request happens from
> inside the block layer core. Please have a look at block/blk-core.c and the
> code in that file that handles the request flag RQF_DONTPREP.
Yes, thanks for your directive.

On the other hand, this patch is to align the actions between blk-mq and block legacy code in __scsi_queue_insert.
As we know, __scsi_queue_insert is just to requeue the request back to queue, as the block legacy code segment above:
for block legacy, it just blk_requeue_request for the request and kick the queue run.
However, for the blk-mq, scsi_mq_requeue_cmd will be invoked, it not only requeue the request, but also unprep request.
This is not what __scsi_queue_insert should do, but scsi_io_completion.
When the request is not finished completely, and scsi_io_completion finds it need a ACTION_REPREP, at the moment,
we need requeue and unprep there.

If I missed something, please feel free to point out. :)

Thanks
Jianchao

 

> 
> Thanks,
> 
> Bart.
> 
> 
>
Bart Van Assche Feb. 27, 2018, 5:12 a.m. UTC | #5
On Tue, 2018-02-27 at 12:00 +0800, jianchao.wang wrote:
> On the other hand, this patch is to align the actions between blk-mq and block

> legacy code in __scsi_queue_insert.


Hello Jianchao,

Since the legacy SCSI core unpreps an reprepares a request when requeuing it I
think your patch does not align the blk-mq and legacy block layer actions but
instead makes the behavior of the two code paths different.

Thanks,

Bart.
jianchao.wang Feb. 27, 2018, 5:15 a.m. UTC | #6
Hi Bart

Thanks for your kindly response.

On 02/27/2018 01:12 PM, Bart Van Assche wrote:
> On Tue, 2018-02-27 at 12:00 +0800, jianchao.wang wrote:
>> On the other hand, this patch is to align the actions between blk-mq and block
>> legacy code in __scsi_queue_insert.
> 
> Hello Jianchao,
> 
> Since the legacy SCSI core unpreps an reprepares a request when requeuing it I
> think your patch does not align the blk-mq and legacy block layer actions but
> instead makes the behavior of the two code paths different.
> 

Can you share more details about this ? 

Thanks 
Jianchao
Bart Van Assche Feb. 27, 2018, 5:06 p.m. UTC | #7
On Tue, 2018-02-27 at 13:15 +0800, jianchao.wang wrote:
> Can you share more details about this ? 


After having had another look, I think your patch is fine. So if you want you
can add:

Reviewed-by: Bart Van Assche <bart.vanassche@wdc.com>
Bart Van Assche Feb. 27, 2018, 5:18 p.m. UTC | #8
On Tue, 2018-02-27 at 17:06 +0000, Bart Van Assche wrote:
> On Tue, 2018-02-27 at 13:15 +0800, jianchao.wang wrote:

> > Can you share more details about this ? 

> 

> After having had another look, I think your patch is fine.


(replying to my own e-mail)

What I think is fine in your patch is that it skips the unprep and reprep
when requeueing. However, there is a put_device(&sdev->sdev_gendev) call
in scsi_mq_requeue_cmd() and your patch causes that put_device() call to
be skipped when requeueing. An explanation is needed in the commit message
why you think that removing that put_device() call is fine.

Bart.
jianchao.wang Feb. 28, 2018, 2:25 a.m. UTC | #9
Hi Bart

Thanks for your kindly response and precious time to review this.

On 02/28/2018 01:18 AM, Bart Van Assche wrote:
> On Tue, 2018-02-27 at 17:06 +0000, Bart Van Assche wrote:
>> On Tue, 2018-02-27 at 13:15 +0800, jianchao.wang wrote:
>>> Can you share more details about this ? 
>>
>> After having had another look, I think your patch is fine.
> 
> (replying to my own e-mail)
> 
> What I think is fine in your patch is that it skips the unprep and reprep
> when requeueing. However, there is a put_device(&sdev->sdev_gendev) call
> in scsi_mq_requeue_cmd() and your patch causes that put_device() call to
> be skipped when requeueing. An explanation is needed in the commit message
> why you think that removing that put_device() call is fine.

Your concern is right.
For the block legacy path in scsi core, the get_device(&sdev->sdev_gendev) is in prep.
So when it requeue the request w/ RQF_DONTPREP, the reference will not be got again.
However, for blk-mq patch in scsi core, the get_device(&sdev->sdev_gendev) in .get_budget,
so put_device is still needed here.

Thanks for your directive.
Jianchao
diff mbox

Patch

diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
index a86df9c..06d8110 100644
--- a/drivers/scsi/scsi_lib.c
+++ b/drivers/scsi/scsi_lib.c
@@ -191,7 +191,7 @@  static void __scsi_queue_insert(struct scsi_cmnd *cmd, int reason, bool unbusy)
 	 */
 	cmd->result = 0;
 	if (q->mq_ops) {
-		scsi_mq_requeue_cmd(cmd);
+		blk_mq_requeue_request(cmd->request, true);
 		return;
 	}
 	spin_lock_irqsave(q->queue_lock, flags);