Iterating over all devices in scsi_eh_bus_device_reset() is inefficient as not all devices may be affected during SCSI EH. There also is no reason to open-code scsi_eh_test_devices() as for FAST_IO_FAIL we really should just return the commands without further ado. So rewrite the loop in scsi_eh_bus_device_reset() to match the loop in scsi_eh_target_reset() and scsi_eh_bus_reset(). Signed-off-by: Hannes Reinecke <hare@xxxxxxx> Reviewed-by: Christoph Hellwig <hch@xxxxxx> --- drivers/scsi/scsi_error.c | 58 ++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 31 deletions(-) diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c index 63b762d5d66f..7c655d08a305 100644 --- a/drivers/scsi/scsi_error.c +++ b/drivers/scsi/scsi_error.c @@ -1570,54 +1570,50 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost, struct list_head *work_q, struct list_head *done_q) { - struct scsi_cmnd *scmd, *bdr_scmd, *next; - struct scsi_device *sdev; - enum scsi_disposition rtn; + struct scsi_cmnd *scmd, *next; + LIST_HEAD(tmp_list); + LIST_HEAD(check_list); + + list_splice_init(work_q, &tmp_list); + + while (!list_empty(&tmp_list)) { + struct scsi_device *sdev; + enum scsi_disposition rtn; + + scmd = list_entry(tmp_list.next, struct scsi_cmnd, eh_entry); + sdev = scmd->device; - shost_for_each_device(sdev, shost) { if (scsi_host_eh_past_deadline(shost)) { + /* push back on work queue for further processing */ + list_splice_init(&check_list, work_q); + list_splice_init(&tmp_list, work_q); SCSI_LOG_ERROR_RECOVERY(3, sdev_printk(KERN_INFO, sdev, "%s: skip BDR, past eh deadline\n", current->comm)); - scsi_device_put(sdev); - break; + return list_empty(work_q); } - bdr_scmd = NULL; - list_for_each_entry(scmd, work_q, eh_entry) - if (scmd->device == sdev) { - bdr_scmd = scmd; - break; - } - - if (!bdr_scmd) - continue; - SCSI_LOG_ERROR_RECOVERY(3, sdev_printk(KERN_INFO, sdev, "%s: Sending BDR\n", current->comm)); rtn = scsi_try_bus_device_reset(sdev); - if (rtn == SUCCESS || rtn == FAST_IO_FAIL) { - if (!scsi_device_online(sdev) || - rtn == FAST_IO_FAIL || - !scsi_eh_tur(bdr_scmd)) { - list_for_each_entry_safe(scmd, next, - work_q, eh_entry) { - if (scmd->device == sdev && - scsi_eh_action(scmd, rtn) != FAILED) { - set_host_byte(scmd, DID_RESET); - scsi_eh_finish_cmd(scmd, done_q); - } - } - } - } else { + if (rtn != SUCCESS && rtn != FAST_IO_FAIL) SCSI_LOG_ERROR_RECOVERY(3, sdev_printk(KERN_INFO, sdev, "%s: BDR failed\n", current->comm)); + list_for_each_entry_safe(scmd, next, work_q, eh_entry) { + if (scmd->device != sdev) + continue; + if (rtn == SUCCESS) + list_move_tail(&scmd->eh_entry, &check_list); + else if (rtn == FAST_IO_FAIL) { + set_host_byte(scmd, DID_TRANSPORT_FAILFAST); + scsi_eh_finish_cmd(scmd, done_q); + } } } - return list_empty(work_q); + return scsi_eh_test_devices(&check_list, work_q, done_q, 0); } /** -- 2.35.3