From: Douglas Gilbert <dgilbert@interlog.com>
To: linux-scsi@vger.kernel.org
Cc: martin.petersen@oracle.com, jejb@linux.vnet.ibm.com, hare@suse.de
Subject: [RFC v2 6/6] scsi: count number of targets
Date: Sun, 24 May 2020 11:58:14 -0400 [thread overview]
Message-ID: <20200524155814.5895-7-dgilbert@interlog.com> (raw)
In-Reply-To: <20200524155814.5895-1-dgilbert@interlog.com>
If less than 2 used to flatten iteration in __scsi_device_lookup().
The majority of hosts will have 1 target and 1 LU (device).
Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>
---
drivers/scsi/scsi.c | 12 ++++--------
drivers/scsi/scsi_scan.c | 5 ++++-
include/scsi/scsi_host.h | 1 +
3 files changed, 9 insertions(+), 9 deletions(-)
diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 1b1fc8d4e5c2..6acd85ce21dd 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -557,10 +557,6 @@ struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *shost,
unsigned long flags, l_idx;
spin_lock_irqsave(shost->host_lock, flags);
- if (xa_empty(&shost->__devices)) {
- next = NULL;
- goto unlock;
- }
do {
if (!next) { /* get first element iff first iteration */
l_idx = 0;
@@ -578,7 +574,6 @@ struct scsi_device *__scsi_iterate_devices(struct Scsi_Host *shost,
break;
}
} while (next);
-unlock:
spin_unlock_irqrestore(shost->host_lock, flags);
if (prev)
@@ -818,8 +813,9 @@ struct scsi_device *__scsi_device_lookup(struct Scsi_Host *shost,
if (xa_empty(&shost->__devices))
return NULL;
- if (xa_empty(&shost->__targets))
- goto inconsistent;
+ if (shost->num_targets < 2)
+ goto flat_iteration;
+
xa_for_each(&shost->__targets, l_idx, starg) {
if (!(starg->id == id && starg->channel == channel))
continue;
@@ -830,7 +826,7 @@ struct scsi_device *__scsi_device_lookup(struct Scsi_Host *shost,
}
}
return NULL;
-inconsistent:
+flat_iteration:
xa_for_each_marked(&shost->__devices, m_idx, sdev,
SCSI_XA_NON_SDEV_DEL) {
if (sdev->id == id && sdev->channel == channel &&
diff --git a/drivers/scsi/scsi_scan.c b/drivers/scsi/scsi_scan.c
index c055ee083ea9..d665da2b01a4 100644
--- a/drivers/scsi/scsi_scan.c
+++ b/drivers/scsi/scsi_scan.c
@@ -320,7 +320,9 @@ static void scsi_target_destroy(struct scsi_target *starget)
shost->hostt->target_destroy(starget);
/* XARRAY: was list_del_init(); why the _init ? */
e_starg = xa_erase(&shost->__targets, starget->sh_idx);
- if (e_starg != starget)
+ if (e_starg == starget)
+ --shost->num_targets;
+ else
pr_err("%s: bad xa_erase()\n", __func__);
spin_unlock_irqrestore(shost->host_lock, flags);
put_device(dev);
@@ -465,6 +467,7 @@ static struct scsi_target *scsi_alloc_target(struct device *parent,
return NULL;
}
starget->sh_idx = u_idx;
+ ++shost->num_targets;
spin_unlock_irqrestore(shost->host_lock, flags);
/* allocate and add */
transport_setup_device(dev);
diff --git a/include/scsi/scsi_host.h b/include/scsi/scsi_host.h
index 0e94b1feb8e9..f49298a4c452 100644
--- a/include/scsi/scsi_host.h
+++ b/include/scsi/scsi_host.h
@@ -528,6 +528,7 @@ struct Scsi_Host {
*/
struct xarray __devices; /* array of scsi_debug objs */
struct xarray __targets; /* array of scsi_target objs */
+ int num_targets; /* modified under host_lock */
struct list_head starved_list;
--
2.25.1
prev parent reply other threads:[~2020-05-24 15:58 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-05-24 15:58 [RFC v2 0/6] scsi: rework mid-layer with xarrays Douglas Gilbert
2020-05-24 15:58 ` [RFC v2 1/6] scsi: xarray hctl Douglas Gilbert
2020-05-25 6:57 ` Hannes Reinecke
2020-05-25 16:30 ` Douglas Gilbert
2020-05-25 17:40 ` Matthew Wilcox
2020-05-26 2:01 ` Douglas Gilbert
2020-05-26 3:01 ` Matthew Wilcox
2020-05-26 7:24 ` Hannes Reinecke
2020-05-26 6:21 ` Hannes Reinecke
2020-05-26 14:27 ` Matthew Wilcox
2020-05-26 17:53 ` Hannes Reinecke
2020-05-26 18:39 ` Matthew Wilcox
2020-05-26 19:28 ` James Bottomley
2020-05-26 19:10 ` Douglas Gilbert
2020-05-26 20:27 ` Douglas Gilbert
2020-05-27 2:53 ` Douglas Gilbert
2020-05-24 15:58 ` [RFC v2 2/6] scsi: xarray, iterations on scsi_target Douglas Gilbert
2020-05-25 7:06 ` Hannes Reinecke
2020-05-24 15:58 ` [RFC v2 3/6] scsi: xarray mark sdev_del state Douglas Gilbert
2020-05-25 7:00 ` Hannes Reinecke
2020-05-25 16:47 ` Douglas Gilbert
2020-05-24 15:58 ` [RFC v2 4/6] scsi: improve scsi_device_lookup Douglas Gilbert
2020-05-25 7:07 ` Hannes Reinecke
2020-05-24 15:58 ` [RFC v2 5/6] scsi: add __scsi_target_lookup Douglas Gilbert
2020-05-24 15:58 ` Douglas Gilbert [this message]
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=20200524155814.5895-7-dgilbert@interlog.com \
--to=dgilbert@interlog.com \
--cc=hare@suse.de \
--cc=jejb@linux.vnet.ibm.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.