public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: James Bottomley <james.bottomley@hansenpartnership.com>,
	linux-scsi@vger.kernel.org, Christoph Hellwig <hch@lst.de>,
	Hannes Reinecke <hare@suse.de>
Subject: [PATCH 16/18] pmcraid: Select device in pmcraid_eh_bus_reset_handler()
Date: Mon,  2 Oct 2023 17:43:26 +0200	[thread overview]
Message-ID: <20231002154328.43718-17-hare@suse.de> (raw)
In-Reply-To: <20231002154328.43718-1-hare@suse.de>

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 bus when sending down a bus reset.

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

diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
index 50dc30051f22..d7a331255e71 100644
--- a/drivers/scsi/pmcraid.c
+++ b/drivers/scsi/pmcraid.c
@@ -2691,7 +2691,7 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
  *	SUCCESS / FAILED
  */
 static int pmcraid_reset_device(
-	struct scsi_cmnd *scsi_cmd,
+	struct scsi_device *scsi_dev,
 	unsigned long timeout,
 	u8 modifier)
 {
@@ -2703,11 +2703,11 @@ static int pmcraid_reset_device(
 	u32 ioasc;
 
 	pinstance =
-		(struct pmcraid_instance *)scsi_cmd->device->host->hostdata;
-	res = scsi_cmd->device->hostdata;
+		(struct pmcraid_instance *)scsi_dev->host->hostdata;
+	res = scsi_dev->hostdata;
 
 	if (!res) {
-		sdev_printk(KERN_ERR, scsi_cmd->device,
+		sdev_printk(KERN_ERR, scsi_dev,
 			    "reset_device: NULL resource pointer\n");
 		return FAILED;
 	}
@@ -3018,16 +3018,46 @@ static int pmcraid_eh_device_reset_handler(struct scsi_cmnd *scmd)
 {
 	scmd_printk(KERN_INFO, scmd,
 		    "resetting device due to an I/O command timeout.\n");
-	return pmcraid_reset_device(scmd,
+	return pmcraid_reset_device(scmd->device,
 				    PMCRAID_INTERNAL_TIMEOUT,
 				    RESET_DEVICE_LUN);
 }
 
 static int pmcraid_eh_bus_reset_handler(struct scsi_cmnd *scmd)
 {
-	scmd_printk(KERN_INFO, scmd,
+	struct Scsi_Host *host = scmd->device->host;
+	struct pmcraid_instance *pinstance =
+		(struct pmcraid_instance *)host->hostdata;
+	struct pmcraid_resource_entry *res = NULL;
+	struct pmcraid_resource_entry *temp;
+	struct scsi_device *sdev = NULL;
+	unsigned long lock_flags;
+
+	/*
+	 * The reset device code insists on us passing down
+	 * a device, so grab the first device on the bus.
+	 */
+	spin_lock_irqsave(&pinstance->resource_lock, lock_flags);
+	list_for_each_entry(temp, &pinstance->used_res_q, queue) {
+		if (scmd->device->channel == PMCRAID_VSET_BUS_ID &&
+		    RES_IS_VSET(temp->cfg_entry)) {
+			res = temp;
+			break;
+		} else if (scmd->device->channel == PMCRAID_PHYS_BUS_ID &&
+			   RES_IS_GSCSI(temp->cfg_entry)) {
+			res = temp;
+			break;
+		}
+	}
+	if (res)
+		sdev = res->scsi_dev;
+	spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
+	if (!sdev)
+		return FAILED;
+
+	sdev_printk(KERN_INFO, sdev,
 		    "Doing bus reset due to an I/O command timeout.\n");
-	return pmcraid_reset_device(scmd,
+	return pmcraid_reset_device(sdev,
 				    PMCRAID_RESET_BUS_TIMEOUT,
 				    RESET_DEVICE_BUS);
 }
@@ -3036,7 +3066,7 @@ static int pmcraid_eh_target_reset_handler(struct scsi_cmnd *scmd)
 {
 	scmd_printk(KERN_INFO, scmd,
 		    "Doing target reset due to an I/O command timeout.\n");
-	return pmcraid_reset_device(scmd,
+	return pmcraid_reset_device(scmd->device,
 				    PMCRAID_INTERNAL_TIMEOUT,
 				    RESET_DEVICE_TARGET);
 }
-- 
2.35.3


  parent reply	other threads:[~2023-10-02 15:44 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-02 15:43 [PATCHv5 00/18] scsi: EH rework prep patches, part 1 Hannes Reinecke
2023-10-02 15:43 ` [PATCH 01/18] mptfc: simplify mptfc_block_error_handler() Hannes Reinecke
2023-10-02 15:43 ` [PATCH 02/18] mptfusion: correct definitions for mptscsih_dev_reset() Hannes Reinecke
2023-10-02 15:43 ` [PATCH 03/18] mptfc: open-code mptfc_block_error_handler() for bus reset Hannes Reinecke
2023-10-02 15:43 ` [PATCH 04/18] qedf: use fc rport as argument for qedf_initiate_tmf() Hannes Reinecke
2023-10-02 15:43 ` [PATCH 05/18] bnx2fc: Do not rely on a scsi command for lun or target reset Hannes Reinecke
2023-10-02 15:43 ` [PATCH 06/18] aic7xxx: make BUILD_SCSIID() a function Hannes Reinecke
2023-10-12  8:26   ` Christoph Hellwig
2023-10-13 17:59     ` Martin K. Petersen
2023-10-02 15:43 ` [PATCH 07/18] aic7xxx: do not reference scsi command when resetting device Hannes Reinecke
2023-10-02 15:43 ` [PATCH 08/18] aic79xx: make BUILD_SCSIID() a function Hannes Reinecke
2023-10-12  8:26   ` Christoph Hellwig
2023-10-13 17:59     ` Martin K. Petersen
2023-10-02 15:43 ` [PATCH 09/18] aic79xx: do not reference scsi command when resetting device Hannes Reinecke
2023-10-02 15:43 ` [PATCH 10/18] ibmvfc: open-code reset loop for target reset Hannes Reinecke
2023-10-02 15:43 ` [PATCH 11/18] megaraid: pass in NULL scb for host reset Hannes Reinecke
2023-10-02 15:43 ` [PATCH 12/18] ips: Do not try to abort command from " Hannes Reinecke
2023-10-02 15:43 ` [PATCH 13/18] sym53c8xx_2: split off bus reset " Hannes Reinecke
2023-10-02 15:43 ` [PATCH 14/18] sym53c8xx_2: rework reset handling Hannes Reinecke
2023-10-02 15:43 ` [PATCH 15/18] qla1280: separate out host reset function from qla1280_error_action() Hannes Reinecke
2023-10-02 15:43 ` Hannes Reinecke [this message]
2023-10-02 15:43 ` [PATCH 17/18] pmcraid: select device in pmcraid_eh_target_reset_handler() Hannes Reinecke
2023-10-05 12:26   ` John Garry
2023-10-09  7:52     ` Hannes Reinecke
2023-10-02 15:43 ` [PATCH 18/18] mpi3mr: split off bus_reset function from host_reset Hannes Reinecke
2023-10-13 18:26 ` [PATCHv5 00/18] scsi: EH rework prep patches, part 1 Martin K. Petersen
2023-10-17  1:11 ` Martin K. Petersen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231002154328.43718-17-hare@suse.de \
    --to=hare@suse.de \
    --cc=hch@lst.de \
    --cc=james.bottomley@hansenpartnership.com \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox