diff mbox series

[17/18] pmcraid: select device in pmcraid_eh_target_reset_handler()

Message ID 20231002154328.43718-18-hare@suse.de
State New
Headers show
Series scsi: EH rework prep patches, part 1 | expand

Commit Message

Hannes Reinecke Oct. 2, 2023, 3:43 p.m. UTC
The reset code requires a device to be selected, but we shouldn't
rely on the command to provide a device for us. So select the first
device on the target when sending down a target reset.

Signed-off-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
---
 drivers/scsi/pmcraid.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

Comments

John Garry Oct. 5, 2023, 12:26 p.m. UTC | #1
On 02/10/2023 16:43, Hannes Reinecke wrote:
>   static int pmcraid_eh_target_reset_handler(struct scsi_cmnd *scmd)
>   {
> -	scmd_printk(KERN_INFO, scmd,
> +	struct Scsi_Host *shost = scmd->device->host;
> +	struct scsi_device *scsi_dev = NULL, *tmp;
> +
> +	shost_for_each_device(tmp, shost) {
> +		if ((tmp->channel == scmd->device->channel) &&
> +		    (tmp->id == scmd->device->id)) {
> +			scsi_dev = tmp;
> +			break;

If you break out of the loop, you must call scsi_device_put(sdev) - is 
that missing?

> +		}
> +	}
> +	if (!scsi_dev)
> +		return FAILED;
> +	sdev_printk(KERN_INFO, scsi_dev,
>   		    "Doing target reset due to an I/O command timeout.\n");
> -	return pmcraid_reset_device(scmd->device,
Hannes Reinecke Oct. 9, 2023, 7:52 a.m. UTC | #2
On 10/5/23 14:26, John Garry wrote:
> On 02/10/2023 16:43, Hannes Reinecke wrote:
>>   static int pmcraid_eh_target_reset_handler(struct scsi_cmnd *scmd)
>>   {
>> -    scmd_printk(KERN_INFO, scmd,
>> +    struct Scsi_Host *shost = scmd->device->host;
>> +    struct scsi_device *scsi_dev = NULL, *tmp;
>> +
>> +    shost_for_each_device(tmp, shost) {
>> +        if ((tmp->channel == scmd->device->channel) &&
>> +            (tmp->id == scmd->device->id)) {
>> +            scsi_dev = tmp;
>> +            break;
> 
> If you break out of the loop, you must call scsi_device_put(sdev) - is 
> that missing?
> 
No, you are correct. Will be fixing it up.

Cheers,

Hannes
diff mbox series

Patch

diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index d7a331255e71..a831b34c08a4 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -3064,9 +3064,21 @@  static int pmcraid_eh_bus_reset_handler(struct scsi_cmnd *scmd)
 
 static int pmcraid_eh_target_reset_handler(struct scsi_cmnd *scmd)
 {
-	scmd_printk(KERN_INFO, scmd,
+	struct Scsi_Host *shost = scmd->device->host;
+	struct scsi_device *scsi_dev = NULL, *tmp;
+
+	shost_for_each_device(tmp, shost) {
+		if ((tmp->channel == scmd->device->channel) &&
+		    (tmp->id == scmd->device->id)) {
+			scsi_dev = tmp;
+			break;
+		}
+	}
+	if (!scsi_dev)
+		return FAILED;
+	sdev_printk(KERN_INFO, scsi_dev,
 		    "Doing target reset due to an I/O command timeout.\n");
-	return pmcraid_reset_device(scmd->device,
+	return pmcraid_reset_device(scsi_dev,
 				    PMCRAID_INTERNAL_TIMEOUT,
 				    RESET_DEVICE_TARGET);
 }