All of lore.kernel.org
 help / color / mirror / Atom feed
From: Hannes Reinecke <hare@suse.de>
To: "Martin K. Petersen" <martin.petersen@oracle.com>
Cc: Christoph Hellwig <hch@lst.de>,
	James Bottomley <james.bottomley@hansenpartnership.com>,
	linux-scsi@vger.kernel.org, Hannes Reinecke <hare@suse.de>,
	Hannes Reinecke <hare@suse.com>
Subject: [PATCH 50/51] scsi: Do not allocate scsi command in scsi_ioctl_reset()
Date: Tue, 17 Aug 2021 11:14:55 +0200	[thread overview]
Message-ID: <20210817091456.73342-51-hare@suse.de> (raw)
In-Reply-To: <20210817091456.73342-1-hare@suse.de>

As we now have moved the error handler functions to not rely on
a scsi command we can drop the out-of-band scsi command allocation
from scsi_ioctl_reset().

Signed-off-by: Hannes Reinecke <hare@suse.com>
---
 drivers/scsi/scsi_error.c | 104 +++++++++++++++++---------------------
 1 file changed, 46 insertions(+), 58 deletions(-)

diff --git a/drivers/scsi/scsi_error.c b/drivers/scsi/scsi_error.c
index 44e29558b068..5cfff3fa306c 100644
--- a/drivers/scsi/scsi_error.c
+++ b/drivers/scsi/scsi_error.c
@@ -796,14 +796,14 @@ static void scsi_eh_done(struct scsi_cmnd *scmd)
 
 /**
  * scsi_try_host_reset - ask host adapter to reset itself
- * @scmd:	SCSI cmd to send host reset.
+ * @host:	SCSI host to be reset.
  */
-static enum scsi_disposition scsi_try_host_reset(struct scsi_cmnd *scmd)
+static enum scsi_disposition scsi_try_host_reset(struct Scsi_Host *host)
 {
 	unsigned long flags;
 	enum scsi_disposition rtn;
-	struct Scsi_Host *host = scmd->device->host;
 	struct scsi_host_template *hostt = host->hostt;
+	struct scsi_device *sdev;
 
 	SCSI_LOG_ERROR_RECOVERY(3,
 		shost_printk(KERN_INFO, host, "Snd Host RST\n"));
@@ -817,7 +817,8 @@ static enum scsi_disposition scsi_try_host_reset(struct scsi_cmnd *scmd)
 		if (!hostt->skip_settle_delay)
 			ssleep(HOST_RESET_SETTLE_TIME);
 		spin_lock_irqsave(host->host_lock, flags);
-		scsi_report_bus_reset(host, scmd_channel(scmd));
+		__shost_for_each_device(sdev, host)
+			__scsi_report_device_reset(sdev);
 		spin_unlock_irqrestore(host->host_lock, flags);
 	}
 
@@ -826,28 +827,29 @@ static enum scsi_disposition scsi_try_host_reset(struct scsi_cmnd *scmd)
 
 /**
  * scsi_try_bus_reset - ask host to perform a bus reset
- * @scmd:	SCSI cmd to send bus reset.
+ * @host:	SCSI host to send bus reset.
+ * @channel:	Number of the bus to be reset
  */
-static enum scsi_disposition scsi_try_bus_reset(struct scsi_cmnd *scmd)
+static enum scsi_disposition scsi_try_bus_reset(struct Scsi_Host *host,
+						int channel)
 {
 	unsigned long flags;
 	enum scsi_disposition rtn;
-	struct Scsi_Host *host = scmd->device->host;
 	struct scsi_host_template *hostt = host->hostt;
 
-	SCSI_LOG_ERROR_RECOVERY(3, scmd_printk(KERN_INFO, scmd,
-		"%s: Snd Bus RST\n", __func__));
+	SCSI_LOG_ERROR_RECOVERY(3, shost_printk(KERN_INFO, host,
+		"%s: Snd Bus RST to bus %d\n", __func__, channel));
 
 	if (!hostt->eh_bus_reset_handler)
 		return FAILED;
 
-	rtn = hostt->eh_bus_reset_handler(host, scmd_channel(scmd));
+	rtn = hostt->eh_bus_reset_handler(host, channel);
 
 	if (rtn == SUCCESS) {
 		if (!hostt->skip_settle_delay)
 			ssleep(BUS_RESET_SETTLE_TIME);
 		spin_lock_irqsave(host->host_lock, flags);
-		scsi_report_bus_reset(host, scmd_channel(scmd));
+		scsi_report_bus_reset(host, channel);
 		spin_unlock_irqrestore(host->host_lock, flags);
 	}
 
@@ -862,7 +864,8 @@ static void __scsi_report_device_reset(struct scsi_device *sdev, void *data)
 
 /**
  * scsi_try_target_reset - Ask host to perform a target reset
- * @scmd:	SCSI cmd used to send a target reset
+ * @host:	SCSI Host
+ * @starget:	SCSI target to be reset
  *
  * Notes:
  *    There is no timeout for this operation.  if this operation is
@@ -870,13 +873,13 @@ static void __scsi_report_device_reset(struct scsi_device *sdev, void *data)
  *    timer on it, and set the host back to a consistent state prior to
  *    returning.
  */
-static enum scsi_disposition scsi_try_target_reset(struct scsi_cmnd *scmd)
+static enum scsi_disposition scsi_try_target_reset(struct Scsi_Host *host,
+						   struct scsi_target *starget)
 {
 	unsigned long flags;
 	enum scsi_disposition rtn;
-	struct Scsi_Host *host = scmd->device->host;
+	struct scsi_device *sdev;
 	struct scsi_host_template *hostt = host->hostt;
-	struct scsi_target *starget = scsi_target(scmd->device);
 
 	if (!hostt->eh_target_reset_handler)
 		return FAILED;
@@ -884,8 +887,11 @@ static enum scsi_disposition scsi_try_target_reset(struct scsi_cmnd *scmd)
 	rtn = hostt->eh_target_reset_handler(starget);
 	if (rtn == SUCCESS) {
 		spin_lock_irqsave(host->host_lock, flags);
-		__starget_for_each_device(starget, NULL,
-					  __scsi_report_device_reset);
+		__shost_for_each_device(sdev, host) {
+			if ((sdev->channel == starget->channel) &&
+			    (sdev->id == starget->id))
+				__scsi_report_device_reset(sdev);
+		}
 		spin_unlock_irqrestore(host->host_lock, flags);
 	}
 
@@ -894,7 +900,7 @@ static enum scsi_disposition scsi_try_target_reset(struct scsi_cmnd *scmd)
 
 /**
  * scsi_try_bus_device_reset - Ask host to perform a BDR on a dev
- * @scmd:	SCSI cmd used to send BDR
+ * @sdev:	SCSI device to perform the BDR on
  *
  * Notes:
  *    There is no timeout for this operation.  if this operation is
@@ -902,17 +908,17 @@ static enum scsi_disposition scsi_try_target_reset(struct scsi_cmnd *scmd)
  *    timer on it, and set the host back to a consistent state prior to
  *    returning.
  */
-static enum scsi_disposition scsi_try_bus_device_reset(struct scsi_cmnd *scmd)
+static enum scsi_disposition scsi_try_bus_device_reset(struct scsi_device *sdev)
 {
 	enum scsi_disposition rtn;
-	struct scsi_host_template *hostt = scmd->device->host->hostt;
+	struct scsi_host_template *hostt = sdev->host->hostt;
 
 	if (!hostt->eh_device_reset_handler)
 		return FAILED;
 
-	rtn = hostt->eh_device_reset_handler(scmd->device);
+	rtn = hostt->eh_device_reset_handler(sdev);
 	if (rtn == SUCCESS)
-		__scsi_report_device_reset(scmd->device, NULL);
+		__scsi_report_device_reset(sdev, NULL);
 	return rtn;
 }
 
@@ -944,11 +950,15 @@ scsi_try_to_abort_cmd(struct scsi_host_template *hostt, struct scsi_cmnd *scmd)
 
 static void scsi_abort_eh_cmnd(struct scsi_cmnd *scmd)
 {
-	if (scsi_try_to_abort_cmd(scmd->device->host->hostt, scmd) != SUCCESS)
-		if (scsi_try_bus_device_reset(scmd) != SUCCESS)
-			if (scsi_try_target_reset(scmd) != SUCCESS)
-				if (scsi_try_bus_reset(scmd) != SUCCESS)
-					scsi_try_host_reset(scmd);
+	struct Scsi_Host *host = scmd->device->host;
+	struct scsi_target *starget = scsi_target(scmd->device);
+	int channel = scmd->device->channel;
+
+	if (scsi_try_to_abort_cmd(host->hostt, scmd) != SUCCESS)
+		if (scsi_try_bus_device_reset(scmd->device) != SUCCESS)
+			if (scsi_try_target_reset(host, starget) != SUCCESS)
+				if (scsi_try_bus_reset(host, channel) != SUCCESS)
+					scsi_try_host_reset(host);
 }
 
 /**
@@ -1530,7 +1540,7 @@ static int scsi_eh_bus_device_reset(struct Scsi_Host *shost,
 		SCSI_LOG_ERROR_RECOVERY(3,
 			sdev_printk(KERN_INFO, sdev,
 				     "%s: Sending BDR\n", current->comm));
-		rtn = scsi_try_bus_device_reset(bdr_scmd);
+		rtn = scsi_try_bus_device_reset(sdev);
 		if (rtn == SUCCESS || rtn == FAST_IO_FAIL) {
 			if (!scsi_device_online(sdev) ||
 			    rtn == FAST_IO_FAIL ||
@@ -1595,7 +1605,7 @@ static int scsi_eh_target_reset(struct Scsi_Host *shost,
 			shost_printk(KERN_INFO, shost,
 				     "%s: Sending target reset to target %d\n",
 				     current->comm, id));
-		rtn = scsi_try_target_reset(scmd);
+		rtn = scsi_try_target_reset(shost, scsi_target(scmd->device));
 		if (rtn != SUCCESS && rtn != FAST_IO_FAIL)
 			SCSI_LOG_ERROR_RECOVERY(3,
 				shost_printk(KERN_INFO, shost,
@@ -1670,7 +1680,7 @@ static int scsi_eh_bus_reset(struct Scsi_Host *shost,
 			shost_printk(KERN_INFO, shost,
 				     "%s: Sending BRST chan: %d\n",
 				     current->comm, channel));
-		rtn = scsi_try_bus_reset(chan_scmd);
+		rtn = scsi_try_bus_reset(shost, channel);
 		if (rtn == SUCCESS || rtn == FAST_IO_FAIL) {
 			list_for_each_entry_safe(scmd, next, work_q, eh_entry) {
 				if (channel == scmd_channel(scmd)) {
@@ -1716,7 +1726,7 @@ static int scsi_eh_host_reset(struct Scsi_Host *shost,
 				     "%s: Sending HRST\n",
 				     current->comm));
 
-		rtn = scsi_try_host_reset(scmd);
+		rtn = scsi_try_host_reset(shost);
 		if (rtn == SUCCESS) {
 			list_splice_init(work_q, &check_list);
 		} else if (rtn == FAST_IO_FAIL) {
@@ -2364,9 +2374,8 @@ scsi_reset_provider_done_command(struct scsi_cmnd *scmd)
 int
 scsi_ioctl_reset(struct scsi_device *dev, int __user *arg)
 {
-	struct scsi_cmnd *scmd;
 	struct Scsi_Host *shost = dev->host;
-	struct request *rq;
+	struct scsi_target *starget = scsi_target(dev);
 	unsigned long flags;
 	int error = 0, val;
 	enum scsi_disposition rtn;
@@ -2381,25 +2390,6 @@ scsi_ioctl_reset(struct scsi_device *dev, int __user *arg)
 	if (scsi_autopm_get_host(shost) < 0)
 		return -EIO;
 
-	error = -EIO;
-	rq = kzalloc(sizeof(struct request) + sizeof(struct scsi_cmnd) +
-			shost->hostt->cmd_size, GFP_KERNEL);
-	if (!rq)
-		goto out_put_autopm_host;
-	blk_rq_init(NULL, rq);
-
-	scmd = (struct scsi_cmnd *)(rq + 1);
-	scsi_init_command(dev, scmd);
-	scmd->request = rq;
-	scmd->cmnd = scsi_req(rq)->cmd;
-
-	scmd->scsi_done		= scsi_reset_provider_done_command;
-	memset(&scmd->sdb, 0, sizeof(scmd->sdb));
-
-	scmd->cmd_len			= 0;
-
-	scmd->sc_data_direction		= DMA_BIDIRECTIONAL;
-
 	spin_lock_irqsave(shost->host_lock, flags);
 	shost->tmf_in_progress = 1;
 	spin_unlock_irqrestore(shost->host_lock, flags);
@@ -2409,22 +2399,22 @@ scsi_ioctl_reset(struct scsi_device *dev, int __user *arg)
 		rtn = SUCCESS;
 		break;
 	case SG_SCSI_RESET_DEVICE:
-		rtn = scsi_try_bus_device_reset(scmd);
+		rtn = scsi_try_bus_device_reset(dev);
 		if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
 			break;
 		fallthrough;
 	case SG_SCSI_RESET_TARGET:
-		rtn = scsi_try_target_reset(scmd);
+		rtn = scsi_try_target_reset(shost, starget);
 		if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
 			break;
 		fallthrough;
 	case SG_SCSI_RESET_BUS:
-		rtn = scsi_try_bus_reset(scmd);
+		rtn = scsi_try_bus_reset(shost, dev->channel);
 		if (rtn == SUCCESS || (val & SG_SCSI_RESET_NO_ESCALATE))
 			break;
 		fallthrough;
 	case SG_SCSI_RESET_HOST:
-		rtn = scsi_try_host_reset(scmd);
+		rtn = scsi_try_host_reset(shost);
 		if (rtn == SUCCESS)
 			break;
 		fallthrough;
@@ -2450,8 +2440,6 @@ scsi_ioctl_reset(struct scsi_device *dev, int __user *arg)
 	wake_up(&shost->host_wait);
 	scsi_run_host_queues(shost);
 
-	kfree(rq);
-
 out_put_autopm_host:
 	scsi_autopm_put_host(shost);
 	return error;
-- 
2.29.2


  parent reply	other threads:[~2021-08-17  9:17 UTC|newest]

Thread overview: 83+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-17  9:14 [PATCHv2 00/51] SCSI EH argument reshuffle part II Hannes Reinecke
2021-08-17  9:14 ` [PATCH 01/51] lpfc: kill lpfc_bus_reset_handler Hannes Reinecke
2021-08-17 17:37   ` James Smart
2021-08-17  9:14 ` [PATCH 02/51] lpfc: drop lpfc_no_handler() Hannes Reinecke
2021-08-17 12:13   ` Christoph Hellwig
2021-08-17 17:36   ` James Smart
2021-08-17  9:14 ` [PATCH 03/51] sym53c8xx_2: split off bus reset from host reset Hannes Reinecke
2021-08-17 12:18   ` Christoph Hellwig
2021-08-17  9:14 ` [PATCH 04/51] ips: Do not try to abort command " Hannes Reinecke
2021-08-17  9:14 ` [PATCH 05/51] snic: reserve tag for TMF Hannes Reinecke
2021-08-17 12:21   ` Christoph Hellwig
2021-08-17  9:14 ` [PATCH 06/51] qla1280: separate out host reset function from qla1280_error_action() Hannes Reinecke
2021-08-17 12:22   ` Christoph Hellwig
2021-08-17 14:05     ` Hannes Reinecke
2021-08-17  9:14 ` [PATCH 07/51] megaraid: pass in NULL scb for host reset Hannes Reinecke
2021-08-17 12:26   ` Christoph Hellwig
2021-08-17 13:46     ` Hannes Reinecke
2021-08-17  9:14 ` [PATCH 08/51] zfcp: open-code fc_block_scsi_eh() " Hannes Reinecke
2021-08-17 11:53   ` Benjamin Block
2021-08-17 12:54     ` Hannes Reinecke
2021-08-17 14:03       ` Steffen Maier
2021-08-17 14:10         ` Hannes Reinecke
2021-08-18 11:00           ` Steffen Maier
2021-08-18 11:58             ` Hannes Reinecke
2021-08-17  9:14 ` [PATCH 09/51] mpi3mr: split off bus_reset function from host_reset Hannes Reinecke
2021-08-17  9:14 ` [PATCH 10/51] scsi: Use Scsi_Host as argument for eh_host_reset_handler Hannes Reinecke
2021-08-17 14:55   ` Steffen Maier
2021-08-19 18:34   ` Bart Van Assche
2021-08-17  9:14 ` [PATCH 11/51] mptfc: simplify mpt_fc_block_error_handler() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 12/51] mptfusion: correct definitions for mptscsih_dev_reset() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 13/51] mptfc: open-code mptfc_block_error_handler() for bus reset Hannes Reinecke
2021-08-17  9:14 ` [PATCH 14/51] pmcraid: Select device in pmcraid_eh_bus_reset_handler() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 15/51] qla2xxx: open-code qla2xxx_generic_reset() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 16/51] qla2xxx: Do not call fc_block_scsi_eh() during bus reset Hannes Reinecke
2021-08-17  9:14 ` [PATCH 17/51] visorhba: select first device on the bus for bus_reset() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 18/51] ncr53c8xx: remove 'sync_reset' argument from ncr_reset_bus() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 19/51] ncr53c8xx: Complete all commands during bus reset Hannes Reinecke
2021-08-17  9:14 ` [PATCH 20/51] ncr53c8xx: Remove unused code Hannes Reinecke
2021-08-17  9:14 ` [PATCH 21/51] scsi: Use Scsi_Host and channel number as argument for eh_bus_reset_handler() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 22/51] libiscsi: use cls_session as argument for target and session reset Hannes Reinecke
2021-08-17  9:14 ` [PATCH 23/51] bnx2fc: Do not rely on a scsi command when issueing lun or target reset Hannes Reinecke
2021-08-17  9:14 ` [PATCH 24/51] ibmvfc: open-code reset loop for " Hannes Reinecke
2021-08-17  9:14 ` [PATCH 25/51] lpfc: use fc_block_rport() Hannes Reinecke
2021-08-18 16:35   ` James Smart
2021-08-17  9:14 ` [PATCH 26/51] lpfc: use rport as argument for lpfc_send_taskmgmt() Hannes Reinecke
2021-08-18 16:35   ` James Smart
2021-08-17  9:14 ` [PATCH 27/51] lpfc: use rport as argument for lpfc_chk_tgt_mapped() Hannes Reinecke
2021-08-18 16:36   ` James Smart
2021-08-17  9:14 ` [PATCH 28/51] csiostor: use fc_block_rport() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 29/51] qla2xxx: " Hannes Reinecke
2021-08-17  9:14 ` [PATCH 30/51] fc_fcp: " Hannes Reinecke
2021-08-17  9:14 ` [PATCH 31/51] qedf: use fc rport as argument for qedf_initiate_tmf() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 32/51] sym53c8xx_2: rework reset handling Hannes Reinecke
2021-08-17  9:14 ` [PATCH 33/51] bfa: Do not use scsi command to signal TMF status Hannes Reinecke
2021-08-17  9:14 ` [PATCH 34/51] scsi_transport_iscsi: use session as argument for iscsi_block_scsi_eh() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 35/51] pmcraid: select first available device for target reset Hannes Reinecke
2021-08-17  9:14 ` [PATCH 36/51] scsi: Use scsi_target as argument for eh_target_reset_handler() Hannes Reinecke
2021-08-17 15:53   ` Steffen Maier
2021-08-18 16:37   ` James Smart
2021-08-19 18:37   ` Bart Van Assche
2021-08-17  9:14 ` [PATCH 37/51] aha152x: look for stuck command when resetting device Hannes Reinecke
2021-08-18  0:43   ` Finn Thain
2021-08-17  9:14 ` [PATCH 38/51] fnic: use dedicated device reset command Hannes Reinecke
2021-08-17  9:14 ` [PATCH 39/51] a1000u2w: do not rely on the command for inia100_device_reset() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 40/51] aic7xxx: use scsi device as argument for BUILD_SCSIID() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 41/51] aic79xx: " Hannes Reinecke
2021-08-17  9:14 ` [PATCH 42/51] aic7xxx: do not reference scsi command when resetting device Hannes Reinecke
2021-08-17  9:14 ` [PATCH 43/51] aic79xx: " Hannes Reinecke
2021-08-17  9:14 ` [PATCH 44/51] xen-scsifront: add scsi device as argument to scsifront_do_request() Hannes Reinecke
2021-08-17  9:14 ` [PATCH 45/51] fas216: Rework device reset to not rely on SCSI command pointer Hannes Reinecke
2021-08-17  9:14 ` [PATCH 46/51] csiostor: use separate TMF command Hannes Reinecke
2021-08-17  9:14 ` [PATCH 47/51] snic: use dedicated device reset command Hannes Reinecke
2021-08-17  9:14 ` [PATCH 48/51] snic: Use scsi_host_busy_iter() to traverse commands Hannes Reinecke
2021-08-17  9:14 ` [PATCH 49/51] scsi: Move eh_device_reset_handler() to use scsi_device as argument Hannes Reinecke
2021-08-17 16:13   ` Steffen Maier
2021-08-17 18:09     ` Hannes Reinecke
2021-08-17  9:14 ` Hannes Reinecke [this message]
2021-08-17  9:14 ` [PATCH 51/51] scsi_error: streamline scsi_eh_bus_device_reset() Hannes Reinecke
2021-08-17 12:13 ` [PATCHv2 00/51] SCSI EH argument reshuffle part II Christoph Hellwig
2021-08-17 12:55   ` Hannes Reinecke
2022-02-23 12:49     ` Christoph Hellwig
2022-02-23 13:03       ` Hannes Reinecke
2022-02-23 13:05         ` Christoph Hellwig

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=20210817091456.73342-51-hare@suse.de \
    --to=hare@suse.de \
    --cc=hare@suse.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.