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: [PATCH v5 9/9] scsi_host: switch ida to idr to hold shost ptr
Date: Sun, 19 Jul 2020 22:57:42 -0400 [thread overview]
Message-ID: <20200720025742.349296-10-dgilbert@interlog.com> (raw)
In-Reply-To: <20200720025742.349296-1-dgilbert@interlog.com>
Previously the scsi_host code was using a global static "ida"
array to make sure host numbers where unique and issued in a
predictable ascending integer order. Extend that ida to an
idr array so that it can additionally hold the pointer to
the scsi_host object. This enables scsi_host_lookup() to do
a O(ln(n)) search replacing class_find_device() which is O(n).
This makes all the SCSI exported " lookup" functions O(ln(n)).
iSCSI seems to be the largest user of scsi_host_lookup().
Signed-off-by: Douglas Gilbert <dgilbert@interlog.com>
---
drivers/scsi/hosts.c | 37 +++++++++++--------------------------
1 file changed, 11 insertions(+), 26 deletions(-)
diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
index aebef37684e8..7734dc63606d 100644
--- a/drivers/scsi/hosts.c
+++ b/drivers/scsi/hosts.c
@@ -50,7 +50,7 @@ module_param_named(eh_deadline, shost_eh_deadline, int, S_IRUGO|S_IWUSR);
MODULE_PARM_DESC(eh_deadline,
"SCSI EH timeout in seconds (should be between 0 and 2^31-1)");
-static DEFINE_IDA(host_index_ida);
+static DEFINE_IDR(host_index_idr); /* store index and shost pointer */
static void scsi_host_cls_release(struct device *dev)
@@ -343,7 +343,7 @@ static void scsi_host_dev_release(struct device *dev)
kfree(shost->shost_data);
- ida_simple_remove(&host_index_ida, shost->host_no);
+ idr_remove(&host_index_idr, shost->host_no);
if (parent)
put_device(parent);
@@ -390,8 +390,8 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
init_waitqueue_head(&shost->host_wait);
mutex_init(&shost->scan_mutex);
- index = ida_simple_get(&host_index_ida, 0, 0, GFP_KERNEL);
- if (index < 0)
+ index = idr_alloc(&host_index_idr, shost, 0, 0, GFP_KERNEL);
+ if (unlikely(index < 0))
goto fail_kfree;
shost->host_no = index;
@@ -501,22 +501,13 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
fail_kthread:
kthread_stop(shost->ehandler);
fail_index_remove:
- ida_simple_remove(&host_index_ida, shost->host_no);
+ idr_remove(&host_index_idr, shost->host_no);
fail_kfree:
kfree(shost);
return NULL;
}
EXPORT_SYMBOL(scsi_host_alloc);
-static int __scsi_host_match(struct device *dev, const void *data)
-{
- struct Scsi_Host *p;
- const unsigned short *hostnum = data;
-
- p = class_to_shost(dev);
- return p->host_no == *hostnum;
-}
-
/**
* scsi_host_lookup - get a reference to a Scsi_Host by host no
* @hostnum: host number to locate
@@ -525,20 +516,14 @@ static int __scsi_host_match(struct device *dev, const void *data)
* A pointer to located Scsi_Host or NULL.
*
* The caller must do a scsi_host_put() to drop the reference
- * that scsi_host_get() took. The put_device() below dropped
- * the reference from class_find_device().
+ * that scsi_host_get() took.
**/
struct Scsi_Host *scsi_host_lookup(unsigned short hostnum)
{
- struct device *cdev;
- struct Scsi_Host *shost = NULL;
-
- cdev = class_find_device(&shost_class, NULL, &hostnum,
- __scsi_host_match);
- if (cdev) {
- shost = scsi_host_get(class_to_shost(cdev));
- put_device(cdev);
- }
+ struct Scsi_Host *shost = idr_find(&host_index_idr, hostnum);
+
+ if (shost)
+ shost = scsi_host_get(shost);
return shost;
}
EXPORT_SYMBOL(scsi_host_lookup);
@@ -600,7 +585,7 @@ int scsi_init_hosts(void)
void scsi_exit_hosts(void)
{
class_unregister(&shost_class);
- ida_destroy(&host_index_ida);
+ idr_destroy(&host_index_idr);
}
int scsi_is_host_device(const struct device *dev)
--
2.25.1
prev parent reply other threads:[~2020-07-20 2:58 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-07-20 2:57 [PATCH v5 0/9] scsi: use xarray for devices and targets Douglas Gilbert
2020-07-20 2:57 ` [PATCH v5 1/9] scsi: convert target lookup to xarray Douglas Gilbert
2020-07-20 2:57 ` [PATCH v5 2/9] target_core_pscsi: use __scsi_device_lookup() Douglas Gilbert
2020-07-20 2:57 ` [PATCH v5 3/9] scsi: move target device list to xarray Douglas Gilbert
2020-07-20 2:57 ` [PATCH v5 4/9] scsi: remove direct device lookup per host Douglas Gilbert
2020-07-20 2:57 ` [PATCH v5 5/9] scsi_error: use xarray lookup instead of wrappers Douglas Gilbert
2020-07-20 2:57 ` [PATCH v5 6/9] scsi: avoid pointless memory allocation in scsi_alloc_target() Douglas Gilbert
2020-07-20 2:57 ` [PATCH v5 7/9] scsi: add starget_to_shost() specialization Douglas Gilbert
2020-07-20 2:57 ` [PATCH v5 8/9] scsi: simplify scsi_target() inline Douglas Gilbert
2020-07-20 2:57 ` 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=20200720025742.349296-10-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.