public inbox for linux-scsi@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] declare and export scsi_bus_type
@ 2002-12-12  1:46 Matt Domsch
  2002-12-12  9:12 ` Christoph Hellwig
  0 siblings, 1 reply; 5+ messages in thread
From: Matt Domsch @ 2002-12-12  1:46 UTC (permalink / raw)
  To: linux-scsi; +Cc: mochel

Below please find a patch, written by Pat Mochel, to declare and export
scsi_bus_type.  My EDD code requires this to be exported in order to walk
the list of SCSI devices to match what BIOS discovered.

Please apply.

Thanks,
Matt

-- 
Matt Domsch
Sr. Software Engineer, Lead Engineer, Architect
Dell Linux Solutions www.dell.com/linux
Linux on Dell mailing lists @ http://lists.us.dell.com

===== drivers/scsi/scsi.h 1.50 vs edited =====
--- 1.50/drivers/scsi/scsi.h	Thu Nov 28 08:09:53 2002
+++ edited/drivers/scsi/scsi.h	Thu Dec  5 19:05:27 2002
@@ -994,4 +994,6 @@
 extern int scsi_sysfs_register(void);
 extern void scsi_sysfs_unregister(void);
 
+extern struct bus_type scsi_bus_type;
+
 #endif
===== drivers/scsi/scsi_sysfs.c 1.1 vs edited =====
--- 1.1/drivers/scsi/scsi_sysfs.c	Thu Nov 28 12:54:06 2002
+++ edited/drivers/scsi/scsi_sysfs.c	Thu Dec  5 19:06:55 2002
@@ -84,7 +84,7 @@
 }
 
 
-static struct bus_type scsi_bus_type = {
+struct bus_type scsi_bus_type = {
         .name		= "scsi",
         .match		= scsi_bus_match,
 };
@@ -202,3 +202,5 @@
 	device_remove_file(&sdev->sdev_driverfs_dev, &dev_attr_type);
 	device_unregister(&sdev->sdev_driverfs_dev);
 }
+
+EXPORT_SYMBOL(scsi_bus_type);



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] declare and export scsi_bus_type
  2002-12-12  1:46 [PATCH] declare and export scsi_bus_type Matt Domsch
@ 2002-12-12  9:12 ` Christoph Hellwig
  2002-12-12 13:58   ` James Bottomley
  2002-12-12 16:00   ` Patrick Mochel
  0 siblings, 2 replies; 5+ messages in thread
From: Christoph Hellwig @ 2002-12-12  9:12 UTC (permalink / raw)
  To: Matt Domsch; +Cc: linux-scsi, mochel

On Wed, Dec 11, 2002 at 07:46:22PM -0600, Matt Domsch wrote:
> Below please find a patch, written by Pat Mochel, to declare and export
> scsi_bus_type.  My EDD code requires this to be exported in order to walk
> the list of SCSI devices to match what BIOS discovered.

I'm very unhappy with exporting random parts of the scsi midlayer.  In
what way do you need it?  How does your code work with modular scsi?


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] declare and export scsi_bus_type
  2002-12-12  9:12 ` Christoph Hellwig
@ 2002-12-12 13:58   ` James Bottomley
  2002-12-12 16:16     ` Patrick Mochel
  2002-12-12 16:00   ` Patrick Mochel
  1 sibling, 1 reply; 5+ messages in thread
From: James Bottomley @ 2002-12-12 13:58 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Matt Domsch, linux-scsi, mochel

hch@infradead.org said:
> I'm very unhappy with exporting random parts of the scsi midlayer.  In
> what way do you need it?  How does your code work with modular scsi? 

Convention tends to be that these bus types are exported.  That's certainly 
true for pci and mca.

However, perhaps we should have a better way of finding them than by direct 
export of the symbol.  Since each bus is required to have a unique name, and 
the sysfs system has an internal list of bus_types, we could have a function 
which takes the name and returns a pointer to the bus_type if it exists?

James



^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] declare and export scsi_bus_type
  2002-12-12  9:12 ` Christoph Hellwig
  2002-12-12 13:58   ` James Bottomley
@ 2002-12-12 16:00   ` Patrick Mochel
  1 sibling, 0 replies; 5+ messages in thread
From: Patrick Mochel @ 2002-12-12 16:00 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Matt Domsch, linux-scsi


> On Wed, Dec 11, 2002 at 07:46:22PM -0600, Matt Domsch wrote:
> > Below please find a patch, written by Pat Mochel, to declare and export
> > scsi_bus_type.  My EDD code requires this to be exported in order to walk
> > the list of SCSI devices to match what BIOS discovered.
> 
> I'm very unhappy with exporting random parts of the scsi midlayer.  In
> what way do you need it?  How does your code work with modular scsi?

It's a not a random piece. It's a symbolic representation of the scsi bus 
type. It is designed to be exported for modular and optional components to 
use. 

EDD is a perfect example of this. It parses the firmware and obtains data
about the installed hard disks. It needs to associate the physical
hardware with the firmware data. So, it iterates over the SCSI (and soon 
IDE, I believe) drives, searching for a match. It uses scsi_bus_type 
because it uses the helper

int bus_for_each_dev(struct bus_type * bus, struct device * start, void * data,
                     int (*fn)(struct device *, void *));

Exporting the bus type keeps EDD at a good level of abstraction: it is 
ia32-specific, so it can remain in arch/i386/ in a single source file, and 
out of drivers/scsi/ and drivers/ide/. Instead of splitting the 
functionality between those three places. 

The bus type is accessible anyway, via the driver mdoel core. A piece of
code can iterate over the registered bus types and find the one named
'scsi', so it's by no means inaccessible. On the other hand, I can export
a call 'find_bus()' to search the bus-space for a bus with a certain name, 
but that is much less efficient that dereferencing an explicit pointer. 

	-pat


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] declare and export scsi_bus_type
  2002-12-12 13:58   ` James Bottomley
@ 2002-12-12 16:16     ` Patrick Mochel
  0 siblings, 0 replies; 5+ messages in thread
From: Patrick Mochel @ 2002-12-12 16:16 UTC (permalink / raw)
  To: James Bottomley; +Cc: Christoph Hellwig, Matt Domsch, linux-scsi


Didn't see this before I replied.. 

On Thu, 12 Dec 2002, James Bottomley wrote:

> hch@infradead.org said:
> > I'm very unhappy with exporting random parts of the scsi midlayer.  In
> > what way do you need it?  How does your code work with modular scsi? 
> 
> Convention tends to be that these bus types are exported.  That's certainly 
> true for pci and mca.
> 
> However, perhaps we should have a better way of finding them than by direct 
> export of the symbol.  Since each bus is required to have a unique name, and 
> the sysfs system has an internal list of bus_types, we could have a function 
> which takes the name and returns a pointer to the bus_type if it exists?

Yes, the following patch should work. There are two caveats, AFAICT

- Making sure that we have a consistent name. This could resolved by adding 
  something like

  #define SCSI_BUS_NAME "scsi"

  to include/scsi.h/scsi.h..

- Accessing a bus type is O(n) rather that O(1). OTOH, it's not peformance 
  critical code, and there can't be very many bus types registered at once, 
  so it shouldn't be noticable. 


	-pat

===== drivers/base/bus.c 1.27 vs edited =====
--- 1.27/drivers/base/bus.c	Thu Dec  5 22:33:28 2002
+++ edited/drivers/base/bus.c	Thu Dec 12 10:09:32 2002
@@ -466,6 +466,29 @@
 	}
 }
 
+
+/**
+ *	find_bus - search for a bus type by name.
+ *	@name:	name of the bus.
+ */
+
+struct bus_type * find_bus(const char * name)
+{
+	struct list_head * entry;
+	struct bus_type * ret = NULL;
+
+	down_read(&bus_subsys.rwsem);
+	list_for_each(entry,&bus_subsys.list) {
+		struct bus_type * b = list_entry(entry,struct bus_type,subsys.kobj.entry);
+		if (!strncmp(b->subsys.kobj.name,name,KOBJ_NAME_LEN)) {
+			ret = b;
+			break;
+		}
+	}
+	up_read(&bus_subsys.rwsem);
+	return ret;
+}
+
 struct bus_type * get_bus(struct bus_type * bus)
 {
 	return bus ? container_of(subsys_get(&bus->subsys),struct bus_type,subsys) : NULL;
@@ -537,6 +560,7 @@
 EXPORT_SYMBOL(bus_remove_device);
 EXPORT_SYMBOL(bus_register);
 EXPORT_SYMBOL(bus_unregister);
+EXPORT_SYMBOL(find_bus);
 EXPORT_SYMBOL(get_bus);
 EXPORT_SYMBOL(put_bus);
 
===== include/linux/device.h 1.68 vs edited =====
--- 1.68/include/linux/device.h	Tue Dec  3 12:40:21 2002
+++ edited/include/linux/device.h	Thu Dec 12 10:09:23 2002
@@ -81,6 +81,8 @@
 extern int bus_register(struct bus_type * bus);
 extern void bus_unregister(struct bus_type * bus);
 
+extern struct bus_type * find_bus(const char * name);
+
 extern struct bus_type * get_bus(struct bus_type * bus);
 extern void put_bus(struct bus_type * bus);
 


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2002-12-12 16:16 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-12-12  1:46 [PATCH] declare and export scsi_bus_type Matt Domsch
2002-12-12  9:12 ` Christoph Hellwig
2002-12-12 13:58   ` James Bottomley
2002-12-12 16:16     ` Patrick Mochel
2002-12-12 16:00   ` Patrick Mochel

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox