get rid of global array and ->init in sd.c and sr.c
RFC PATCH 1/1 get rid of global array and ->init in sd.c and sr.c
Okay, here's a rather big patch doing major surgery to sd.c and sr.c, the patch is again 2.5.44 + my last patch.
(1) Move register_blockdev out of ->init to the module_init routine. This is symetric to where we unregister it, and the most logical place for it. Note that we can't open a block device before it's gendisk is registered anyway (i.e. in ->attach).
(2) Allocate the Scsi_CD/Scsi_Disk structures one at a time in
->attach instead of the ugly global arrays
(3) To still find the devices in ->detach add a global linked list of those structures - sd.c also uses it for it's reboot notifier
(4) Get rid of ->init
Note that I could only actually test the sd.c portion, sr.c stuff will hopefully be tested soon.
Known issues: We don't have a hotplug aware allocation of minors yet, we really need some kind of bitmap for this. I hope we'll get one for free when Al has finished his CIDR for device :) The other problem is that sd's rebott notifer walks the devlist without taking the lock. The problem is that it would have to wait under the lock, so we'd have to make it a semaphore. But as it's in the reboot notifier we can't have contention anyway..
drivers/scsi/Config.help +0 -26
@@ -34,19 +34,6 @@ CONFIG_BLK_DEV_SD is located on a SCSI disk. In this case, do not compile the driver for your SCSI host adapter (below) as a module either. -CONFIG_SD_EXTRA_DEVS - This controls the amount of additional space allocated in tables for - drivers that are loaded as modules after the kernel is booted. In - the event that the SCSI core itself was loaded as a module, this - value is the number of additional disks that can be loaded after the - first host driver is loaded. - - Admittedly this isn't pretty, but there are tons of race conditions - involved with resizing the internal arrays on the fly. Someday this - flag will go away, and everything will work automatically. - - If you don't understand what's going on, go with the default. - CONFIG_CHR_DEV_ST If you want to use a SCSI tape drive under Linux, say Y and read the SCSI-HOWTO, available from
@@ -93,19 +80,6 @@ CONFIG_BLK_DEV_SR The module will be called sr_mod.o. If you want to compile it as a module, say M here and read <file:Documentation/modules.txt> and <file:Documentation/scsi.txt>. - -CONFIG_SR_EXTRA_DEVS - This controls the amount of additional space allocated in tables for - drivers that are loaded as modules after the kernel is booted. In - the event that the SCSI core itself was loaded as a module, this - value is the number of additional CD-ROMs that can be loaded after - the first host driver is loaded. - - Admittedly this isn't pretty, but there are tons of race conditions - involved with resizing the internal arrays on the fly. Someday this - flag will go away, and everything will work automatically. - - If you don't understand what's going on, go with the default. CONFIG_BLK_DEV_SR_VENDOR This enables the usage of vendor specific SCSI commands. This is
drivers/scsi/Config.in +1 -12
@@ -1,21 +1,10 @@ comment 'SCSI support type (disk, tape, CD-ROM)' dep_tristate ' SCSI disk support' CONFIG_BLK_DEV_SD $CONFIG_SCSI - -if [ "$CONFIG_BLK_DEV_SD" != "n" ]; then - int 'Maximum number of SCSI disks that can be loaded as modules' CONFIG_SD_EXTRA_DEVS 40 -fi - dep_tristate ' SCSI tape support' CONFIG_CHR_DEV_ST $CONFIG_SCSI - dep_tristate ' SCSI OnStream SC-x0 tape support' CONFIG_CHR_DEV_OSST $CONFIG_SCSI - dep_tristate ' SCSI CDROM support' CONFIG_BLK_DEV_SR $CONFIG_SCSI - -if [ "$CONFIG_BLK_DEV_SR" != "n" ]; then - bool ' Enable vendor-specific extensions (for SCSI CDROM)' CONFIG_BLK_DEV_SR_VENDOR - int 'Maximum number of CDROM devices that can be loaded as modules' CONFIG_SR_EXTRA_DEVS 2 -fi +dep_mbool' Enable vendor-specific extensions (for SCSI CDROM)' CONFIG_BLK_DEV_SR_VENDOR $CONFIG_BLK_DEV_SR dep_tristate ' SCSI generic support' CONFIG_CHR_DEV_SG $CONFIG_SCSI comment 'Some SCSI devices (e.g. CD jukebox) support multiple LUNs'
drivers/scsi/hosts.h +0 -26
@@ -614,32 +614,6 @@ extern void scsi_host_busy_inc(struct Scextern void scsi_host_busy_dec_and_test (struct Scsi_Host *,Scsi_Device *);extern void scsi_host_failed_inc_and_test (struct Scsi_Host *); -/* -* This is an ugly hack. If we expect to be able to load devices at run time, -* we need to leave extra room in some of the data structures. Doing a -* realloc to enlarge the structures would be riddled with race conditions, -* so until a better solution is discovered, we use this crude approach -* -* Even bigger hack for SparcSTORAGE arrays. Those are at least 6 disks, but -* usually up to 30 disks, so everyone would need to change this. -jj -* -* Note: These things are all evil and all need to go away. My plan is to -* tackle the character devices first, as there aren't any locking implications -* in the block device layer. The block devices will require more work. -* -* The generics driver has been updated to resize as required. So as the tape -* driver. Two down, two more to go. -*/ -#ifndef CONFIG_SD_EXTRA_DEVS -#define CONFIG_SD_EXTRA_DEVS 2 -#endif -#ifndef CONFIG_SR_EXTRA_DEVS -#define CONFIG_SR_EXTRA_DEVS 2 -#endif -#define SD_EXTRA_DEVS CONFIG_SD_EXTRA_DEVS -#define SR_EXTRA_DEVS CONFIG_SR_EXTRA_DEVS - -/** * scsi_find_device - find a device given the host * @shost: SCSI host pointer
drivers/scsi/sd.c +139 -270
602 lines not on this page · raw message
drivers/scsi/sd.h +2 -14
@@ -12,32 +12,20 @@#ifndef _SD_H#define _SD_H -#ifndef _SCSI_H -#include "scsi.h" -#endif - -#ifndef _GENDISK_H -#include <linux/genhd.h> -#endif -typedef struct scsi_disk { +struct list_head list;sector_t capacity;/* size in 512-byte sectors */ Scsi_Device *device; +struct gendisk *gd;unsigned char media_present;unsigned char write_prot;unsigned WCE:1 ;/* state of disk WCE bit */ unsigned RCD:1 ;/* state of disk RCD bit */ }Scsi_Disk ; -extern int revalidate_scsidisk (kdev_t dev,int maxusage); -/* * Used by pmac to find the device associated with a target. */ extern kdev_t sd_find_target (void *host,int tgt); - -#define N_SD_MAJORS 8 - -#define SD_MAJOR_MASK (N_SD_MAJORS - 1)#endif
drivers/scsi/sr.c +145 -169
422 lines not on this page · raw message
drivers/scsi/sr.h +1 -0
@@ -25,6 +25,7 @@#define IOCTL_TIMEOUT 30*HZ typedef struct { + struct list_head list; unsigned capacity; /* size in blocks */ Scsi_Device *device; unsigned int vendor; /* vendor code, see sr_vendor.c */
Looks good. I ran it on a system with ips, aic, scsi_debug and qla2x00 as a module.
When I applied the patch I got a quite a few rejects on sd.c and sr.c. I fixed up sd.c, but did not run sr.c. My view is based off James scsi-misc-2.5.
I noticed the patch seems to include some of your driver_register removals (preiously posted) in init_sd and exit_sd, but there are no adds to scsi_register_device or scsi_unregister_device.
drivers/scsi/sd.c sd_find_target(void *hp, int scsi_id) · line 169
Quoted 6 lines · Christoph Hellwig [[email protected]] wrote:
drivers/scsi/sd.c +2
-0+list_for_each (p, &sd_devlist) { + sdkp = list_entry(p, struct scsi_disk, list); sdp = sdkp->device;if (sdp && (sdp->host == shp) && (sdp->id == scsi_id)) { retval =MKDEV_SD (dsk_nr);break ;
Might consider using list_for_each_entry since you always do both.
Quoted 14 lines
drivers/scsi/sd.h +0
-8@@ -12,32 +12,20 @@#ifndef _SD_H#define _SD_H -#ifndef _SCSI_H -#include "scsi.h" -#endif - -#ifndef _GENDISK_H -#include <linux/genhd.h> -#endif -
drivers/scsi/sd.h line 24
Quoted 10 lines
drivers/scsi/sd.h +2
-0typedef struct scsi_disk { +struct list_head list;sector_t capacity;/* size in 512-byte sectors */ Scsi_Device *device; +struct gendisk *gd;unsigned char media_present;unsigned char write_prot;unsigned WCE:1 ;/* state of disk WCE bit */ unsigned RCD:1 ;/* state of disk RCD bit */ }Scsi_Disk ;
I received a compile failures on sector_t until I put back the scsi.h include.
-andmike
--
Michael Anderson
[email protected]
Quoted 10 lines · Mike Anderson
Looks good. I ran it on a system with ips, aic,
scsi_debugand qla2x00 as a module.When I applied the patch I got a quite a few rejects on
sd.candsr.c. I fixed upsd.c, but did not runsr.c. My view is based off James scsi-misc-2.5.I noticed the patch seems to include some of your
driver_registerremovals (preiously posted) ininit_sdandexit_sd, but there are no adds toscsi_register_deviceorscsi_unregister_device.
The patch is again 2.5.44 + my previous two patch (devicefs stuff and ->finish removal).
Quoted 10 lines
drivers/scsi/sd.c sd_find_target(void *hp, int scsi_id) · line 169
Quoted 6 lines · Christoph Hellwig [[email protected]] wrote:
drivers/scsi/sd.c +2
-0+list_for_each (p, &sd_devlist) { + sdkp = list_entry(p, struct scsi_disk, list); sdp = sdkp->device;if (sdp && (sdp->host == shp) && (sdp->id == scsi_id)) { retval =MKDEV_SD (dsk_nr);break ;Might consider using
list_for_each_entrysince you always do both.
Yupp.
Quoted 2 lines
I received a compile failures on
sector_tuntil I put back thescsi.hinclude.
Umm, rhigh. There are far to many users of sd.h to do such a change. I'll submt a patch to get rid of all those sd.h users in some time.
Quoted 8 lines · Christoph Hellwig [[email protected]] wrote:
Quoted 7 lines · Mike Anderson
Looks good. I ran it on a system with ips, aic,
scsi_debugand qla2x00 as a module.When I applied the patch I got a quite a few rejects on
sd.candsr.c. I fixed upsd.c, but did not runsr.c. My view is based off James scsi-misc-2.5.
Quoted 6 lines
Quoted 3 lines
I noticed the patch seems to include some of your
driver_registerremovals (preiously posted) ininit_sdandexit_sd, but there are no adds toscsi_register_deviceorscsi_unregister_device.The patch is again 2.5.44 + my previous two patch (devicefs stuff and ->finish removal).
ok. Sorry I did not comment on that previous device model cleanup. I do have a couple comments now though.
In scsi_register_device (which we should probably rename to scsi_bus_register_driver) we could just call driver_register(&tpnt->scsi_driverfs_driver).
In the upper levels just do something like this:
.
.
.
.init_command = sd_init_command,
.scsi_driverfs_driver {
.name = "sd",
.bus = &scsi_driverfs_bus_type,
.probe = sd_probe,
.remove = sd_remove, },We can also remove .tag from the template.
This gives more flexibility to the upper levels in-case they need to add to there driver template.
-andmike
--
Michael Anderson
[email protected]
Quoted 19 lines · Mike Anderson
ok. Sorry I did not comment on that previous device model cleanup. I do have a couple comments now though.
In
scsi_register_device(which we should probably rename toscsi_bus_register_driver) we could just calldriver_register(&tpnt->scsi_driverfs_driver).In the upper levels just do something like this:
.
.
..init_command = sd_init_command, .scsi_driverfs_driver { .name = "sd", .bus = &scsi_driverfs_bus_type, .probe = sd_probe, .remove = sd_remove, },
Quoted 5 lines
We can also remove .tag from the template.
This gives more flexibility to the upper levels in-case they need to add to there driver template.
Looks fine to me. I'll do that once the driverfs/sysfs changes settle down a bit.