linux-scsi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
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 4/6] scsi: improve scsi_device_lookup
Date: Sun, 24 May 2020 11:58:12 -0400	[thread overview]
Message-ID: <20200524155814.5895-5-dgilbert@interlog.com> (raw)
In-Reply-To: <20200524155814.5895-1-dgilbert@interlog.com>

When the __scsi_device_lookup() function is given a "ctl" (i.e. the
latter part of "hctl" tuple), improve the loop to find a matching
device (LU) in the given host. Rather than loop over all LUs in the
host, first loop over all targets to find a match on "ct" then, if
found, loop over all LUs in that target for a match on "l". These
nested loops are better since they don't visit LUs belonging to
non-matching targets. This improvement flows through to the locked
version of this function, namely scsi_device_lookup().

Remove a 21 year old comment by the author that no longer seem
relevant.

Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>
---
 drivers/scsi/scsi.c | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)

diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
index 0fb650aebcfb..9e7658aebdb7 100644
--- a/drivers/scsi/scsi.c
+++ b/drivers/scsi/scsi.c
@@ -35,7 +35,6 @@
  *
  *  Jiffies wrap fixes (host->resetting), 3 Dec 1998 Andrea Arcangeli
  *
- *  out_of_space hacks, D. Gilbert (dpg) 990608
  */
 
 #include <linux/module.h>
@@ -789,16 +788,31 @@ EXPORT_SYMBOL(scsi_device_lookup_by_target);
 struct scsi_device *__scsi_device_lookup(struct Scsi_Host *shost,
 		uint channel, uint id, u64 lun)
 {
-	unsigned long l_idx;
+	unsigned long l_idx, m_idx;
+	struct scsi_target *starg;
 	struct scsi_device *sdev;
 
-	xa_for_each_marked(&shost->__devices, l_idx, sdev,
+	if (xa_empty(&shost->__devices))
+		return NULL;
+	if (xa_empty(&shost->__targets))
+		goto inconsistent;
+	xa_for_each(&shost->__targets, l_idx, starg) {
+		if (!(starg->id == id && starg->channel == channel))
+			continue;
+		xa_for_each_marked(&starg->devices, m_idx, sdev,
+				   SCSI_XA_NON_SDEV_DEL) {
+			if (sdev->lun == lun)
+				return sdev;
+		}
+	}
+	return NULL;
+inconsistent:
+	xa_for_each_marked(&shost->__devices, m_idx, sdev,
 			   SCSI_XA_NON_SDEV_DEL) {
-		if (sdev->channel == channel && sdev->id == id &&
-				sdev->lun ==lun)
+		if (sdev->id == id && sdev->channel == channel &&
+		    sdev->lun == lun)
 			return sdev;
 	}
-
 	return NULL;
 }
 EXPORT_SYMBOL(__scsi_device_lookup);
-- 
2.25.1


  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 ` Douglas Gilbert [this message]
2020-05-25  7:07   ` [RFC v2 4/6] scsi: improve scsi_device_lookup Hannes Reinecke
2020-05-24 15:58 ` [RFC v2 5/6] scsi: add __scsi_target_lookup Douglas Gilbert
2020-05-24 15:58 ` [RFC v2 6/6] scsi: count number of targets Douglas Gilbert

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-5-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).