public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
From: Christoph Hellwig <hch@lst.de>
To: James.Bottomley@steeleye.com
Cc: linux-scsi@vger.kernel.org
Subject: [PATCH] LDM-based scsi host lookup
Date: Tue, 27 May 2003 13:25:50 +0200	[thread overview]
Message-ID: <20030527112550.GB13798@lst.de> (raw)

Replace scsi_host_hn_get with scsi_host_lookup that walks
through the shost class and gets a proper reference to the
host.  This should fix the OOPS that Douglas saw last week.


--- 1.67/drivers/scsi/hosts.c	Mon May 26 14:17:48 2003
+++ edited/drivers/scsi/hosts.c	Mon May 26 15:06:44 2003
@@ -522,16 +522,33 @@
 }
 
 /**
- * scsi_host_hn_get - get a Scsi_Host by host no and inc ref count
- * @host_no:	host number to locate
- *
- * Return value:
- * 	A pointer to located Scsi_Host or NULL.
- **/
-struct Scsi_Host *scsi_host_hn_get(unsigned short host_no)
+ * scsi_host_lookup - get a reference to a Scsi_Host by host no
+ *
+ * @hostnum:	host number to locate
+ *
+ * Return value:
+ *	A pointer to located Scsi_Host or NULL.
+ **/
+struct Scsi_Host *scsi_host_lookup(unsigned short hostnum)
 {
-	/* XXX Inc ref count */
-	return scsi_find_host_by_num(host_no);
+	struct class *class = class_get(&shost_class);
+	struct class_device *cdev;
+	struct Scsi_Host *shost = NULL, *p;
+
+	if (class) {
+		down_read(&class->subsys.rwsem);
+		list_for_each_entry(cdev, &class->children, node) {
+			p = class_to_shost(cdev);
+			if (p->host_no == hostnum) {
+				scsi_host_get(p);
+				shost = p;
+				break;
+			}
+		}
+		up_read(&class->subsys.rwsem);
+	}
+
+	return shost;
 }
 
 /**
@@ -540,10 +557,8 @@
  **/
 void scsi_host_get(struct Scsi_Host *shost)
 {
-
 	get_device(&shost->host_gendev);
 	class_device_get(&shost->class_dev);
-	return;
 }
 
 /**
@@ -555,7 +570,6 @@
 
 	class_device_put(&shost->class_dev);
 	put_device(&shost->host_gendev);
-	return;
 }
 
 /**
===== drivers/scsi/scsi_priv.h 1.9 vs edited =====
--- 1.9/drivers/scsi/scsi_priv.h	Mon May 26 14:17:48 2003
+++ edited/drivers/scsi/scsi_priv.h	Mon May 26 15:06:30 2003
@@ -56,7 +56,7 @@
 extern void scsi_host_busy_inc(struct Scsi_Host *, Scsi_Device *);
 extern void scsi_host_busy_dec_and_test(struct Scsi_Host *, Scsi_Device *);
 extern struct Scsi_Host *scsi_host_get_next(struct Scsi_Host *);
-extern struct Scsi_Host *scsi_host_hn_get(unsigned short);
+extern struct Scsi_Host *scsi_host_lookup(unsigned short);
 extern void scsi_host_put(struct Scsi_Host *);
 extern void scsi_host_init(void);
 
@@ -128,5 +128,7 @@
  * class and device attributes */
 extern struct class_device_attribute *scsi_sysfs_shost_attrs[];
 extern struct device_attribute *scsi_sysfs_sdev_attrs[];
+
+extern struct class shost_class;
 
 #endif /* _SCSI_PRIV_H */
--- 1.23/drivers/scsi/scsi_proc.c	Mon May 12 16:26:15 2003
+++ edited/drivers/scsi/scsi_proc.c	Mon May 26 15:07:09 2003
@@ -250,7 +214,7 @@
 	struct scsi_device *sdev;
 	int error = -ENODEV;
 
-	shost = scsi_host_hn_get(host);
+	shost = scsi_host_lookup(host);
 	if (!shost)
 		return -ENODEV;
 
@@ -272,7 +236,7 @@
 	struct Scsi_Host *shost;
 	int error = -ENODEV;
 
-	shost = scsi_host_hn_get(host);
+	shost = scsi_host_lookup(host);
 	if (!shost)
 		return -ENODEV;
 	sdev = scsi_find_device(shost, channel, id, lun);
--- 1.19/drivers/scsi/scsi_sysfs.c	Mon May 26 14:17:48 2003
+++ edited/drivers/scsi/scsi_sysfs.c	Mon May 26 15:06:07 2003
@@ -54,7 +54,7 @@
 	NULL
 };
 
-static struct class shost_class = {
+struct class shost_class = {
 	.name		= "scsi_host",
 };
 

             reply	other threads:[~2003-05-27 11:12 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-05-27 11:25 Christoph Hellwig [this message]
2003-05-28  7:44 ` [PATCH] LDM-based scsi host lookup Mike Anderson
2003-05-28  9:06   ` 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=20030527112550.GB13798@lst.de \
    --to=hch@lst.de \
    --cc=James.Bottomley@steeleye.com \
    --cc=linux-scsi@vger.kernel.org \
    /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