scsi: core: run queues for all non-SDEV_DEL devices from scsi_run_host_queues
PATCH 1/1 scsi: core: run queues for all non-SDEV_DEL devices from scsi_run_host_queues
While a scsi host is in a recovery state, scsi_mq_requeue_cmd will not set the requeue list for a requeued command to be kicked in the future. The expectation is a call to scsi_run_host_queues will kick all scsi devices once the recovery state is cleared.
However, scsi_run_host_queues uses shost_for_each_device which uses scsi_device_get and so will ignore devices in a partially removed state like SDEV_CANCEL. But these devices may also have requeued requests, leaving their requests stuck from not being kicked and causing the removal process of the device to hang.
scsi_run_host_queues needs to run against more devices than the macro shost_for_each_device allows. Instead of using the too limiting scsi_device_get state checks, only ignore devices in SDEV_DEL state or when unable to acquire a reference. Attempt to run the queues for all other devices when scsi_run_host_queues is called.
--- drivers/scsi/scsi_lib.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-)
drivers/scsi/scsi_lib.c +19 -2
@@ -575,10 +575,27 @@ void scsi_requeue_run_queue(struct work_struct *work)void scsi_run_host_queues (struct Scsi_Host *shost) { -struct scsi_device *sdev; +struct scsi_device *sdev, *prev =NULL ; +unsigned long flags; + +spin_lock_irqsave (shost->host_lock, flags); +__shost_for_each_device (sdev, shost) { +if (sdev->sdev_state ==SDEV_DEL || + !get_device (&sdev->sdev_gendev)) +continue ; +spin_unlock_irqrestore (shost->host_lock, flags); -shost_for_each_device (sdev, shost) +if (prev) +put_device (&prev->sdev_gendev);scsi_run_queue (sdev->request_queue); + + prev = sdev; + +spin_lock_irqsave (shost->host_lock, flags); + } +spin_unlock_irqrestore (shost->host_lock, flags); +if (prev) +put_device (&prev->sdev_gendev); }static void scsi_uninit_cmd (struct scsi_cmnd *cmd)
Signature · 1 line
2.53.0
Quoted 11 lines · David Jeffery
While a scsi host is in a recovery state,
scsi_mq_requeue_cmdwill not set the requeue list for a requeued command to be kicked in the future. The expectation is a call toscsi_run_host_queueswill kick all scsi devices once the recovery state is cleared.However,
scsi_run_host_queuesusesshost_for_each_devicewhich usesscsi_device_getand so will ignore devices in a partially removed state likeSDEV_CANCEL. But these devices may also have requeued requests, leaving their requests stuck from not being kicked and causing the removal process of the device to hang.
Quoted 5 lines
scsi_run_host_queuesneeds to run against more devices than the macroshost_for_each_deviceallows. Instead of using the too limitingscsi_device_getstate checks, only ignore devices inSDEV_DELstate or when unable to acquire a reference. Attempt to run the queues for all other devices whenscsi_run_host_queuesis called.
From scsi_host.h:
static inline int scsi_host_in_recovery(struct Scsi_Host *shost)
{
return shost->shost_state == SHOST_RECOVERY ||
shost->shost_state == SHOST_CANCEL_RECOVERY ||
shost->shost_state == SHOST_DEL_RECOVERY ||
shost->tmf_in_progress;
}This function returns false for the SDEV_CANCEL state. Hence, even with commit 8b566edbdbfb ("scsi: core: Only kick the requeue list if necessary") applied, the requeue list should still be kicked for SCSI hosts in the SDEV_CANCEL state, isn't it?
Thanks,
Bart.
Quoted 28 lines · Bart Van Assche
Quoted 11 lines · David Jeffery
While a scsi host is in a recovery state,
scsi_mq_requeue_cmdwill not set the requeue list for a requeued command to be kicked in the future. The expectation is a call toscsi_run_host_queueswill kick all scsi devices once the recovery state is cleared.However,
scsi_run_host_queuesusesshost_for_each_devicewhich usesscsi_device_getand so will ignore devices in a partially removed state likeSDEV_CANCEL. But these devices may also have requeued requests, leaving their requests stuck from not being kicked and causing the removal process of the device to hang.Quoted 5 lines
scsi_run_host_queuesneeds to run against more devices than the macroshost_for_each_deviceallows. Instead of using the too limitingscsi_device_getstate checks, only ignore devices inSDEV_DELstate or when unable to acquire a reference. Attempt to run the queues for all other devices whenscsi_run_host_queuesis called.From
scsi_host.h:static inline int
scsi_host_in_recovery(struct Scsi_Host *shost){ return shost->shost_state == SHOST_RECOVERY || shost->shost_state == SHOST_CANCEL_RECOVERY || shost->shost_state == SHOST_DEL_RECOVERY || shost->tmf_in_progress; }
Quoted 4 lines
This function returns false for the
SDEV_CANCELstate. Hence, even with commit8b566edbdbfb("scsi: core: Only kick the requeue list if necessary") applied, the requeue list should still be kicked for SCSI hosts in theSDEV_CANCELstate, isn't it?
SDEV_CANCEL is a scsi_device state while the scsi_host_in_recovery macro is looking only at Scsi_Host state. An SDEV_CANCEL scsi_device is unrelated to the scsi_host_in_recovery return value.
I will note that looking at scsi_device state in scsi_mq_requeue_cmd in addition to thescsi_host_in_recovery call does not fix the issue. The scsi_device can be in SDEV_RUNNING state at the time of request requeue with the attempted removal and transition of the scsi_device to SDEV_CANCEL occurring later while error handling is still unfinished.
David Jeffery
Quoted 10 lines · David Jeffery
SDEV_CANCELis ascsi_devicestate while thescsi_host_in_recoverymacro is looking only atScsi_Hoststate. AnSDEV_CANCELscsi_deviceis unrelated to thescsi_host_in_recoveryreturn value.I will note that looking at
scsi_devicestate inscsi_mq_requeue_cmdin addition to thescsi_host_in_recoverycall does not fix the issue. Thescsi_devicecan be inSDEV_RUNNINGstate at the time of request requeue with the attempted removal and transition of thescsi_devicetoSDEV_CANCELoccurring later while error handling is still unfinished.
Oops, I got confused when I wrote my previous reply. Let me take another look at your patch.
Bart.
drivers/scsi/scsi_lib.c void scsi_requeue_run_queue(struct work_struct *work) · line 585
Quoted 3 lines · David Jeffery
drivers/scsi/scsi_lib.c +3
-0+if (sdev->sdev_state ==SDEV_DEL || + !get_device (&sdev->sdev_gendev)) +continue ;
A comment would be welcome above this statement that explains that get_device() is called instead of scsi_device_get() because the latter skips devices that are in the state SDEV_CANCEL state.
Thanks,
Bart.
Quoted 9 lines · Bart Van Assche
drivers/scsi/scsi_lib.c void scsi_requeue_run_queue(struct work_struct *work) · line 585
Quoted 3 lines · David Jeffery
drivers/scsi/scsi_lib.c +3
-0+if (sdev->sdev_state ==SDEV_DEL || + !get_device (&sdev->sdev_gendev)) +continue ;A comment would be welcome above this statement that explains that
get_device()is called instead ofscsi_device_get()because the latter skips devices that are in the stateSDEV_CANCELstate.
Would the wording:
/*
* Only skip devices so deep into removal they will never need
* another kick to their queues. Thus scsi_device_get cannot
* be used as it would skip devices in SDEV_CANCEL state which
* may need a queue kick.
*/
work for you? Thanks for the feedback.
David Jeffery
Quoted 19 lines · David Jeffery
Quoted 9 lines · Bart Van Assche
drivers/scsi/scsi_lib.c void scsi_requeue_run_queue(struct work_struct *work) · line 585
Quoted 3 lines · David Jeffery
drivers/scsi/scsi_lib.c +3
-0+if (sdev->sdev_state ==SDEV_DEL || + !get_device (&sdev->sdev_gendev)) +continue ;A comment would be welcome above this statement that explains that
get_device()is called instead ofscsi_device_get()because the latter skips devices that are in the stateSDEV_CANCELstate.Would the wording:
/*
* Only skip devices so deep into removal they will never need
* another kick to their queues. Thusscsi_device_getcannot
* be used as it would skip devices inSDEV_CANCELstate which
* may need a queue kick.
*/
Quoted 1 line
work for you? Thanks for the feedback.
How about adding that other similar loops use scsi_device_get() and changing "scsi_device_get" into "scsi_device_get()"?
Thanks,
Bart.