From: Hannes Reinecke <hare@suse.de>
To: Christoph Hellwig <hch@lst.de>
Cc: "Martin K. Petersen" <martin.petersen@oracle.com>,
James Bottomley <james.bottomley@hansenpartnership.com>,
linux-scsi@vger.kernel.org, Hannes Reinecke <hare@suse.de>,
Johannes Thumshirn <johannes.thumshirn@wdc.com>
Subject: [PATCH 13/17] snic: Use scsi_host_busy_iter() to traverse commands
Date: Mon, 16 Oct 2023 11:24:26 +0200 [thread overview]
Message-ID: <20231016092430.55557-14-hare@suse.de> (raw)
In-Reply-To: <20231016092430.55557-1-hare@suse.de>
Use scsi_host_busy_iter() to traverse commands instead of hand-crafted
routines walking the command list.
Signed-off-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Johannes Thumshirn <johannes.thumshirn@wdc.com>
---
drivers/scsi/snic/snic_scsi.c | 177 ++++++++++++++++------------------
1 file changed, 84 insertions(+), 93 deletions(-)
diff --git a/drivers/scsi/snic/snic_scsi.c b/drivers/scsi/snic/snic_scsi.c
index 06615619b84c..48261a37d4a6 100644
--- a/drivers/scsi/snic/snic_scsi.c
+++ b/drivers/scsi/snic/snic_scsi.c
@@ -63,7 +63,7 @@ static const char * const snic_io_status_str[] = {
[SNIC_STAT_FATAL_ERROR] = "SNIC_STAT_FATAL_ERROR",
};
-static void snic_scsi_cleanup(struct snic *, int);
+static void snic_scsi_cleanup(struct snic *);
const char *
snic_state_to_str(unsigned int state)
@@ -958,7 +958,7 @@ snic_hba_reset_scsi_cleanup(struct snic *snic)
long act_ios = 0, act_fwreqs = 0;
SNIC_SCSI_DBG(snic->shost, "HBA Reset scsi cleanup.\n");
- snic_scsi_cleanup(snic, snic->max_tag_id);
+ snic_scsi_cleanup(snic);
/* Update stats on pending IOs */
act_ios = atomic64_read(&st->io.active);
@@ -2357,53 +2357,36 @@ snic_cmpl_pending_tmreq(struct snic *snic, struct scsi_cmnd *sc)
complete(rqi->abts_done);
}
-/*
- * snic_scsi_cleanup: Walks through tag map and releases the reqs
- */
-static void
-snic_scsi_cleanup(struct snic *snic, int ex_tag)
+static bool
+snic_scsi_cleanup_iter(struct scsi_cmnd *sc, void *data, bool reserved)
{
+ struct snic *snic = data;
struct snic_req_info *rqi = NULL;
- struct scsi_cmnd *sc = NULL;
spinlock_t *io_lock = NULL;
unsigned long flags;
- int tag;
+ int tag = scsi_cmd_to_rq(sc)->tag;
u64 st_time = 0;
SNIC_SCSI_DBG(snic->shost, "sc_clean: scsi cleanup.\n");
- for (tag = 0; tag < snic->max_tag_id; tag++) {
- /* Skip ex_tag */
- if (tag == ex_tag)
- continue;
-
- io_lock = snic_io_lock_tag(snic, tag);
- spin_lock_irqsave(io_lock, flags);
- sc = scsi_host_find_tag(snic->shost, tag);
- if (!sc) {
- spin_unlock_irqrestore(io_lock, flags);
-
- continue;
- }
-
- if (unlikely(snic_tmreq_pending(sc))) {
- /*
- * When FW Completes reset w/o sending completions
- * for outstanding ios.
- */
- snic_cmpl_pending_tmreq(snic, sc);
- spin_unlock_irqrestore(io_lock, flags);
-
- continue;
- }
+ io_lock = snic_io_lock_tag(snic, tag);
+ spin_lock_irqsave(io_lock, flags);
- rqi = (struct snic_req_info *) CMD_SP(sc);
- if (!rqi) {
- spin_unlock_irqrestore(io_lock, flags);
+ if (unlikely(snic_tmreq_pending(sc))) {
+ /*
+ * When FW Completes reset w/o sending completions
+ * for outstanding ios.
+ */
+ snic_cmpl_pending_tmreq(snic, sc);
+ spin_unlock_irqrestore(io_lock, flags);
- goto cleanup;
- }
+ return true;
+ }
+ rqi = (struct snic_req_info *) CMD_SP(sc);
+ if (!rqi)
+ spin_unlock_irqrestore(io_lock, flags);
+ else {
SNIC_SCSI_DBG(snic->shost,
"sc_clean: sc %p, rqi %p, tag %d flags 0x%llx\n",
sc, rqi, tag, CMD_FLAGS(sc));
@@ -2418,24 +2401,34 @@ snic_scsi_cleanup(struct snic *snic, int ex_tag)
rqi, CMD_FLAGS(sc));
snic_release_req_buf(snic, rqi, sc);
+ }
+ sc->result = DID_TRANSPORT_DISRUPTED << 16;
+ SNIC_HOST_INFO(snic->shost,
+ "sc_clean: DID_TRANSPORT_DISRUPTED for sc %p, Tag %d flags 0x%llx rqi %p duration %u msecs\n",
+ sc, tag, CMD_FLAGS(sc), rqi,
+ jiffies_to_msecs(jiffies - st_time));
-cleanup:
- sc->result = DID_TRANSPORT_DISRUPTED << 16;
- SNIC_HOST_INFO(snic->shost,
- "sc_clean: DID_TRANSPORT_DISRUPTED for sc %p, Tag %d flags 0x%llx rqi %p duration %u msecs\n",
- sc, scsi_cmd_to_rq(sc)->tag, CMD_FLAGS(sc), rqi,
- jiffies_to_msecs(jiffies - st_time));
+ /* Update IO stats */
+ snic_stats_update_io_cmpl(&snic->s_stats);
- /* Update IO stats */
- snic_stats_update_io_cmpl(&snic->s_stats);
+ SNIC_TRC(snic->shost->host_no, tag, (ulong) sc,
+ jiffies_to_msecs(jiffies - st_time), 0,
+ SNIC_TRC_CMD(sc),
+ SNIC_TRC_CMD_STATE_FLAGS(sc));
- SNIC_TRC(snic->shost->host_no, tag, (ulong) sc,
- jiffies_to_msecs(jiffies - st_time), 0,
- SNIC_TRC_CMD(sc),
- SNIC_TRC_CMD_STATE_FLAGS(sc));
+ scsi_done(sc);
+ return true;
+}
- scsi_done(sc);
- }
+/*
+ * snic_scsi_cleanup: Walks through tag map and releases the reqs
+ */
+static void
+snic_scsi_cleanup(struct snic *snic)
+{
+ SNIC_SCSI_DBG(snic->shost, "sc_clean: scsi cleanup\n");
+
+ scsi_host_busy_iter(snic->shost, snic_scsi_cleanup_iter, snic);
} /* end of snic_scsi_cleanup */
void
@@ -2443,7 +2436,7 @@ snic_shutdown_scsi_cleanup(struct snic *snic)
{
SNIC_HOST_INFO(snic->shost, "Shutdown time SCSI Cleanup.\n");
- snic_scsi_cleanup(snic, SCSI_NO_TAG);
+ snic_scsi_cleanup(snic);
} /* end of snic_shutdown_scsi_cleanup */
/*
@@ -2457,7 +2450,7 @@ snic_internal_abort_io(struct snic *snic, struct scsi_cmnd *sc, int tmf)
spinlock_t *io_lock = NULL;
unsigned long flags;
u32 sv_state = 0;
- int ret = 0;
+ int ret = FAILED;
io_lock = snic_io_lock_hash(snic, sc);
spin_lock_irqsave(io_lock, flags);
@@ -2532,6 +2525,35 @@ snic_internal_abort_io(struct snic *snic, struct scsi_cmnd *sc, int tmf)
return ret;
} /* end of snic_internal_abort_io */
+struct snic_tgt_scsi_abort_io_data {
+ struct snic *snic;
+ struct snic_tgt *tgt;
+ int tmf;
+ int abt_cnt;
+};
+
+static bool snic_tgt_scsi_abort_io_iter(struct scsi_cmnd *sc, void *data,
+ bool reserved)
+{
+ struct snic_tgt_scsi_abort_io_data *iter_data = data;
+ struct snic *snic = iter_data->snic;
+ struct snic_tgt *sc_tgt;
+ int ret;
+
+ sc_tgt = starget_to_tgt(scsi_target(sc->device));
+ if (sc_tgt != iter_data->tgt)
+ return true;
+
+ ret = snic_internal_abort_io(snic, sc, iter_data->tmf);
+ if (ret == SUCCESS)
+ iter_data->abt_cnt++;
+ else
+ SNIC_HOST_ERR(snic->shost,
+ "tgt_abt_io: Tag %x, Failed w err = %d\n",
+ scsi_cmd_to_rq(sc)->tag, ret);
+ return true;
+}
+
/*
* snic_tgt_scsi_abort_io : called by snic_tgt_del
*/
@@ -2539,11 +2561,9 @@ int
snic_tgt_scsi_abort_io(struct snic_tgt *tgt)
{
struct snic *snic = NULL;
- struct scsi_cmnd *sc = NULL;
- struct snic_tgt *sc_tgt = NULL;
- spinlock_t *io_lock = NULL;
- unsigned long flags;
- int ret = 0, tag, abt_cnt = 0, tmf = 0;
+ struct snic_tgt_scsi_abort_io_data data = {
+ .abt_cnt = 0,
+ };
if (!tgt)
return -1;
@@ -2551,44 +2571,15 @@ snic_tgt_scsi_abort_io(struct snic_tgt *tgt)
snic = shost_priv(snic_tgt_to_shost(tgt));
SNIC_SCSI_DBG(snic->shost, "tgt_abt_io: Cleaning Pending IOs.\n");
+ data.snic = snic;
if (tgt->tdata.typ == SNIC_TGT_DAS)
- tmf = SNIC_ITMF_ABTS_TASK;
+ data.tmf = SNIC_ITMF_ABTS_TASK;
else
- tmf = SNIC_ITMF_ABTS_TASK_TERM;
-
- for (tag = 0; tag < snic->max_tag_id; tag++) {
- io_lock = snic_io_lock_tag(snic, tag);
-
- spin_lock_irqsave(io_lock, flags);
- sc = scsi_host_find_tag(snic->shost, tag);
- if (!sc) {
- spin_unlock_irqrestore(io_lock, flags);
-
- continue;
- }
+ data.tmf = SNIC_ITMF_ABTS_TASK_TERM;
- sc_tgt = starget_to_tgt(scsi_target(sc->device));
- if (sc_tgt != tgt) {
- spin_unlock_irqrestore(io_lock, flags);
-
- continue;
- }
- spin_unlock_irqrestore(io_lock, flags);
-
- ret = snic_internal_abort_io(snic, sc, tmf);
- if (ret < 0) {
- SNIC_HOST_ERR(snic->shost,
- "tgt_abt_io: Tag %x, Failed w err = %d\n",
- tag, ret);
-
- continue;
- }
-
- if (ret == SUCCESS)
- abt_cnt++;
- }
+ scsi_host_busy_iter(snic->shost, snic_tgt_scsi_abort_io_iter, &data);
- SNIC_SCSI_DBG(snic->shost, "tgt_abt_io: abt_cnt = %d\n", abt_cnt);
+ SNIC_SCSI_DBG(snic->shost, "tgt_abt_io: abt_cnt = %d\n", data.abt_cnt);
return 0;
} /* end of snic_tgt_scsi_abort_io */
--
2.35.3
next prev parent reply other threads:[~2023-10-16 9:25 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-10-16 9:24 [PATCHv6 00/17] scsi: EH rework prep patches, part 2 Hannes Reinecke
2023-10-16 9:24 ` [PATCH 01/17] pmcraid: add missing scsi_device_put() in pmcraid_eh_target_reset_handler() Hannes Reinecke
2023-10-16 13:29 ` Christoph Hellwig
2023-10-16 13:37 ` Hannes Reinecke
2023-10-16 9:24 ` [PATCH 02/17] zfcp: do not wait for rports to become unblocked after host reset Hannes Reinecke
2023-10-16 9:24 ` [PATCH 03/17] bfa: Do not use scsi command to signal TMF status Hannes Reinecke
2023-10-16 13:35 ` Christoph Hellwig
2023-10-16 9:24 ` [PATCH 04/17] aha152x: look for stuck command when resetting device Hannes Reinecke
2023-10-16 13:35 ` Christoph Hellwig
2023-10-16 9:24 ` [PATCH 05/17] a1000u2w: do not rely on the command for inia100_device_reset() Hannes Reinecke
2023-10-16 13:36 ` Christoph Hellwig
2023-10-16 9:24 ` [PATCH 06/17] fas216: Rework device reset to not rely on SCSI command pointer Hannes Reinecke
2023-10-16 9:24 ` [PATCH 07/17] xen-scsifront: add scsi device as argument to scsifront_do_request() Hannes Reinecke
2023-10-16 9:24 ` [PATCH 08/17] xen-scsifront: rework scsifront_action_handler() Hannes Reinecke
2023-10-16 13:36 ` Christoph Hellwig
2023-10-16 9:24 ` [PATCH 09/17] libiscsi: use cls_session as argument for target and session reset Hannes Reinecke
2023-10-19 20:02 ` Mike Christie
2023-10-20 5:53 ` Hannes Reinecke
2023-10-20 16:55 ` michael.christie
2023-10-16 9:24 ` [PATCH 10/17] scsi_transport_iscsi: use session as argument for iscsi_block_scsi_eh() Hannes Reinecke
2023-10-16 9:24 ` [PATCH 11/17] snic: reserve tag for TMF Hannes Reinecke
2023-10-16 13:37 ` Christoph Hellwig
2023-10-16 9:24 ` [PATCH 12/17] snic: allocate device reset command Hannes Reinecke
2023-10-16 13:38 ` Christoph Hellwig
2023-10-16 14:58 ` Hannes Reinecke
2023-10-16 9:24 ` Hannes Reinecke [this message]
2023-10-16 9:24 ` [PATCH 14/17] fnic: allocate device reset command on the fly Hannes Reinecke
2023-10-17 6:37 ` Christoph Hellwig
2023-10-16 9:24 ` [PATCH 15/17] fnic: use fc_block_rport() correctly Hannes Reinecke
2023-10-16 9:24 ` [PATCH 16/17] csiostor: use separate TMF command Hannes Reinecke
2023-10-17 6:37 ` Christoph Hellwig
2023-10-16 9:24 ` [PATCH 17/17] dc395x: Remove 'scmd' parameter from doing_srb_done() Hannes Reinecke
2023-10-17 6:38 ` 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=20231016092430.55557-14-hare@suse.de \
--to=hare@suse.de \
--cc=hch@lst.de \
--cc=james.bottomley@hansenpartnership.com \
--cc=johannes.thumshirn@wdc.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