@@ -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 &&
@@ -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);
@@ -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;
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(-)