Skip to contentSkip to conversation

LDM-based scsi host lookup

PATCH In review Christoph Hellwig 2 participants 3 messages May 27, 2003 – May 28, 2003 SCSI

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 LDM-based scsi host lookup

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.

drivers/scsi/hosts.c +26 -12
@@ -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 =====

drivers/scsi/scsi_priv.h +3 -1
@@ -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 */
drivers/scsi/scsi_proc.c +2 -2
@@ -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);
drivers/scsi/scsi_sysfs.c +1 -1
@@ -54,7 +54,7 @@
 	NULL
 };
 
-static struct class shost_class = {
+struct class shost_class = {
 	.name		= "scsi_host",
 };
 
#1 lore raw

Looks good. One code comment below.

I have a core class for each child interator patch. Do you think we should use that instead. It would protect the SCSI code in case the core changed on how class children are protected. It does have a little more overhead then your loop though.

Quoted 29 lines · Christoph Hellwig [[email protected]] wrote:
drivers/scsi/hosts.c +15 -9
@@ -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) {

drivers/scsi/hosts.c line 550

Quoted 10 lines
drivers/scsi/hosts.c +10 -0
+			p = class_to_shost(cdev);
+			if (p->host_no == hostnum) {
+				scsi_host_get(p);
+				shost = p;
+				break;
+			}
+		}
+		up_read(&class->subsys.rwsem);
+	}
+

Need class_put(&shost_class); here ?

drivers/scsi/hosts.c line 552

Quoted 2 lines
drivers/scsi/hosts.c +1 -0
+	return shost;
 }

-andmike
--
Michael Anderson
[email protected]

#2 lore raw
Quoted 6 lines · Mike Anderson

Looks good. One code comment below.

I have a core class for each child interator patch. Do you think we should use that instead. It would protect the SCSI code in case the core changed on how class children are protected. It does have a little more overhead then your loop though.

Sounds like a good idea. I'd suggest just taking my patch for now and switching over to use your function once it's in.