Commit 4ce9191f authored by Christoph Hellwig's avatar Christoph Hellwig Committed by James Bottomley

[PATCH] scsi device template cleanups

Now that .init isn't implement anymore we can get rid of it and
do some more cleanup in the scsi device template:

* remove .blk - unused since 2.5.46
* remove .dev_noticed, only midlayer user is gone together with
  .init.  remaining instance now driver-private
* remove .nr_dev and .dev_max - they're purely driver internal
  and at least in sd and sr they'll be completly gone very soon.
parent c877e091
......@@ -560,13 +560,7 @@ struct Scsi_Device_Template
const char * tag;
struct module * module; /* Used for loadable modules */
unsigned char scsi_type;
unsigned int nr_dev; /* Number currently attached */
unsigned int dev_noticed; /* Number of devices detected. */
unsigned int dev_max; /* Current size of arrays */
unsigned blk:1; /* 0 if character device */
int (*detect)(Scsi_Device *); /* Returns 1 if we can attach this device */
int (*init)(void); /* Sizes arrays based upon number of devices
* detected */
int (*attach)(Scsi_Device *); /* Attach devices to arrays */
void (*detach)(Scsi_Device *);
int (*init_command)(Scsi_Cmnd *); /* Used by new queueing code.
......
......@@ -156,6 +156,10 @@ static int osst_attach(Scsi_Device *);
static int osst_detect(Scsi_Device *);
static void osst_detach(Scsi_Device *);
static int osst_dev_noticed;
static int osst_nr_dev;
static int osst_dev_max;
struct Scsi_Device_Template osst_template =
{
module: THIS_MODULE,
......@@ -4154,7 +4158,7 @@ static int os_scsi_tape_open(struct inode * inode, struct file * filp)
char *name;
int mode = TAPE_MODE(inode->i_rdev);
if (dev >= osst_template.dev_max || (STp = os_scsi_tapes[dev]) == NULL || !STp->device)
if (dev >= osst_dev_max || (STp = os_scsi_tapes[dev]) == NULL || !STp->device)
return (-ENXIO);
filp->private_data = STp;
......@@ -4979,7 +4983,7 @@ static OSST_buffer * new_tape_buffer( int from_initialization, int need_dma )
int i, priority, b_size, order, got = 0, segs = 0;
OSST_buffer *tb;
if (osst_nbr_buffers >= osst_template.dev_max)
if (osst_nbr_buffers >= osst_dev_max)
return NULL; /* Should never happen */
if (from_initialization)
......@@ -5416,15 +5420,15 @@ static int osst_attach(Scsi_Device * SDp)
if (!disk)
return 1;
if (osst_template.nr_dev >= osst_template.dev_max) {
if (osst_nr_dev >= osst_dev_max) {
SDp->attached--;
put_disk(disk);
return 1;
}
/* find a free minor number */
for (i=0; os_scsi_tapes[i] && i<osst_template.dev_max; i++);
if(i >= osst_template.dev_max) panic ("Scsi_devices corrupt (osst)");
for (i=0; os_scsi_tapes[i] && i<osst_dev_max; i++);
if(i >= osst_dev_max) panic ("Scsi_devices corrupt (osst)");
/* allocate a OS_Scsi_Tape for this device */
tpnt = (OS_Scsi_Tape *)kmalloc(sizeof(OS_Scsi_Tape), GFP_ATOMIC);
......@@ -5548,7 +5552,7 @@ static int osst_attach(Scsi_Device * SDp)
tpnt->density_changed = tpnt->compression_changed = tpnt->blksize_changed = FALSE;
init_MUTEX(&tpnt->lock);
osst_template.nr_dev++;
osst_nr_dev++;
printk(KERN_INFO
"osst :I: Attached OnStream %.5s tape at scsi%d, channel %d, id %d, lun %d as %s\n",
......@@ -5562,7 +5566,7 @@ static int osst_detect(Scsi_Device * SDp)
if (SDp->type != TYPE_TAPE) return 0;
if ( ! osst_supports(SDp) ) return 0;
osst_template.dev_noticed++;
osst_dev_noticed++;
return 1;
}
......@@ -5573,7 +5577,7 @@ static int osst_init()
{
int i;
if (osst_template.dev_noticed == 0)
if (osst_dev_noticed == 0)
return 0;
if (!osst_registered) {
......@@ -5586,10 +5590,10 @@ static int osst_init()
if (os_scsi_tapes)
return 0;
osst_template.dev_max = OSST_MAX_TAPES;
if (osst_template.dev_max > 128 / ST_NBR_MODES)
osst_dev_max = OSST_MAX_TAPES;
if (osst_dev_max > 128 / ST_NBR_MODES)
printk(KERN_INFO "osst :I: Only %d tapes accessible.\n", 128 / ST_NBR_MODES);
os_scsi_tapes = kmalloc(osst_template.dev_max * sizeof(OS_Scsi_Tape *),
os_scsi_tapes = kmalloc(osst_dev_max * sizeof(OS_Scsi_Tape *),
GFP_ATOMIC);
if (!os_scsi_tapes) {
printk(KERN_ERR "osst :W: Unable to allocate array for OnStream SCSI tapes.\n");
......@@ -5597,11 +5601,11 @@ static int osst_init()
return 1;
}
for (i=0; i < osst_template.dev_max; ++i)
for (i=0; i < osst_dev_max; ++i)
os_scsi_tapes[i] = NULL;
/* Allocate the buffer pointers */
osst_buffers = kmalloc(osst_template.dev_max * sizeof(OSST_buffer *),
osst_buffers = kmalloc(osst_dev_max * sizeof(OSST_buffer *),
GFP_ATOMIC);
if (!osst_buffers) {
printk(KERN_ERR "osst :W: Unable to allocate tape buffer pointers.\n");
......@@ -5629,7 +5633,7 @@ static void osst_detach(Scsi_Device * SDp)
int mode;
#endif
for(i=0; i<osst_template.dev_max; i++) {
for(i=0; i<osst_dev_max; i++) {
tpnt = os_scsi_tapes[i];
if(tpnt != NULL && tpnt->device == SDp) {
tpnt->device = NULL;
......@@ -5645,8 +5649,8 @@ static void osst_detach(Scsi_Device * SDp)
kfree(tpnt);
os_scsi_tapes[i] = NULL;
SDp->attached--;
osst_template.nr_dev--;
osst_template.dev_noticed--;
osst_nr_dev--;
osst_dev_noticed--;
return;
}
}
......@@ -5668,7 +5672,7 @@ static void __exit exit_osst (void)
unregister_chrdev(MAJOR_NR, "osst");
osst_registered--;
if (os_scsi_tapes) {
for (i=0; i < osst_template.dev_max; ++i) {
for (i=0; i < osst_dev_max; ++i) {
STp = os_scsi_tapes[i];
if (!STp)
continue;
......@@ -5690,7 +5694,7 @@ static void __exit exit_osst (void)
kfree(osst_buffers);
}
}
osst_template.dev_max = 0;
osst_dev_max = 0;
printk(KERN_INFO "osst :I: Unloaded.\n");
}
......
......@@ -1989,9 +1989,6 @@ int scsi_attach_device(struct scsi_device *sdev)
goto fail;
down_read(&scsi_devicelist_mutex);
for (sdt = scsi_devicelist; sdt; sdt = sdt->next)
if (sdt->init && sdt->dev_noticed)
(*sdt->init) ();
for (sdt = scsi_devicelist; sdt; sdt = sdt->next)
if (sdt->attach)
(*sdt->attach) (sdev);
......@@ -2060,14 +2057,6 @@ int scsi_register_device(struct Scsi_Device_Template *tpnt)
}
}
/*
* If any of the devices would match this driver, then perform the
* init function.
*/
if (tpnt->init && tpnt->dev_noticed)
if ((*tpnt->init) ())
return 1;
/*
* Now actually connect the devices to the new driver.
*/
......
......@@ -83,6 +83,7 @@ struct scsi_disk {
unsigned RCD : 1; /* state of disk RCD bit */
};
static int sd_nr_dev; /* XXX(hch) bad hack, we want a bitmap instead */
static LIST_HEAD(sd_devlist);
static spinlock_t sd_devlist_lock = SPIN_LOCK_UNLOCKED;
......@@ -106,7 +107,6 @@ static struct Scsi_Device_Template sd_template = {
.name = "disk",
.tag = "sd",
.scsi_type = TYPE_DISK,
.blk = 1,
.detect = sd_detect,
.attach = sd_attach,
.detach = sd_detach,
......@@ -1179,7 +1179,6 @@ static int sd_detect(struct scsi_device * sdp)
SCSI_LOG_HLQUEUE(3, printk("sd_detect: type=%d\n", sdp->type));
if (sdp->type != TYPE_DISK && sdp->type != TYPE_MOD)
return 0;
sd_template.dev_noticed++;
return 1;
}
......@@ -1228,7 +1227,7 @@ static int sd_attach(struct scsi_device * sdp)
* XXX use find_first_zero_bit on it. This will happen at the
* XXX same time template->nr_* goes away. --hch
*/
dsk_nr = sd_template.nr_dev++;
dsk_nr = sd_nr_dev++;
sdkp->device = sdp;
sdkp->driver = &sd_template;
......@@ -1314,8 +1313,7 @@ static void sd_detach(struct scsi_device * sdp)
sd_devlist_remove(sdkp);
del_gendisk(sdkp->disk);
sdp->attached--;
sd_template.dev_noticed--;
sd_template.nr_dev--;
sd_nr_dev--;
put_disk(sdkp->disk);
kfree(sdkp);
}
......
......@@ -68,7 +68,6 @@ MODULE_PARM(xa_test, "i"); /* see sr_ioctl.c */
static int sr_attach(struct scsi_device *);
static int sr_detect(struct scsi_device *);
static void sr_detach(struct scsi_device *);
static int sr_init_command(struct scsi_cmnd *);
static struct Scsi_Device_Template sr_template = {
......@@ -76,13 +75,13 @@ static struct Scsi_Device_Template sr_template = {
.name = "cdrom",
.tag = "sr",
.scsi_type = TYPE_ROM,
.blk = 1,
.detect = sr_detect,
.attach = sr_attach,
.detach = sr_detach,
.init_command = sr_init_command
};
static int sr_nr_dev; /* XXX(hch) bad hack, we want a bitmap instead */
static LIST_HEAD(sr_devlist);
static spinlock_t sr_devlist_lock = SPIN_LOCK_UNLOCKED;
......@@ -495,7 +494,6 @@ static int sr_detect(struct scsi_device * SDp)
if (SDp->type != TYPE_ROM && SDp->type != TYPE_WORM)
return 0;
sr_template.dev_noticed++;
return 1;
}
......@@ -524,7 +522,7 @@ static int sr_attach(struct scsi_device *sdev)
* XXX use find_first_zero_bit on it. This will happen at the
* XXX same time template->nr_* goes away. --hch
*/
minor = sr_template.nr_dev++;
minor = sr_nr_dev++;
disk->major = MAJOR_NR;
disk->first_minor = minor;
......@@ -810,7 +808,7 @@ static void sr_detach(struct scsi_device * SDp)
unregister_cdrom(&cd->cdi);
SDp->attached--;
sr_template.nr_dev--;
sr_nr_dev--;
kfree(cd);
}
......
......@@ -74,6 +74,9 @@ static int try_direct_io = TRY_DIRECT_IO;
static int try_rdio = TRUE;
static int try_wdio = TRUE;
static int st_dev_max;
static int st_nr_dev;
MODULE_AUTHOR("Kai Makisara");
MODULE_DESCRIPTION("SCSI Tape Driver");
MODULE_LICENSE("GPL");
......@@ -976,7 +979,7 @@ static int st_open(struct inode *inode, struct file *filp)
char *name;
write_lock(&st_dev_arr_lock);
if (dev >= st_template.dev_max || scsi_tapes == NULL ||
if (dev >= st_dev_max || scsi_tapes == NULL ||
((STp = scsi_tapes[dev]) == NULL)) {
write_unlock(&st_dev_arr_lock);
return (-ENXIO);
......@@ -3680,15 +3683,15 @@ static int st_attach(Scsi_Device * SDp)
}
write_lock(&st_dev_arr_lock);
if (st_template.nr_dev >= st_template.dev_max) {
if (st_nr_dev >= st_dev_max) {
Scsi_Tape **tmp_da;
ST_buffer **tmp_ba;
int tmp_dev_max;
tmp_dev_max = st_template.nr_dev + ST_DEV_ARR_LUMP;
tmp_dev_max = st_nr_dev + ST_DEV_ARR_LUMP;
if (tmp_dev_max > ST_MAX_TAPES)
tmp_dev_max = ST_MAX_TAPES;
if (tmp_dev_max <= st_template.nr_dev) {
if (tmp_dev_max <= st_nr_dev) {
SDp->attached--;
write_unlock(&st_dev_arr_lock);
printk(KERN_ERR "st: Too many tape devices (max. %d).\n",
......@@ -3714,18 +3717,18 @@ static int st_attach(Scsi_Device * SDp)
memset(tmp_da, 0, tmp_dev_max * sizeof(Scsi_Tape *));
if (scsi_tapes != NULL) {
memcpy(tmp_da, scsi_tapes,
st_template.dev_max * sizeof(Scsi_Tape *));
st_dev_max * sizeof(Scsi_Tape *));
kfree(scsi_tapes);
}
scsi_tapes = tmp_da;
st_template.dev_max = tmp_dev_max;
st_dev_max = tmp_dev_max;
}
for (i = 0; i < st_template.dev_max; i++)
for (i = 0; i < st_dev_max; i++)
if (scsi_tapes[i] == NULL)
break;
if (i >= st_template.dev_max)
if (i >= st_dev_max)
panic("scsi_devices corrupt (st)");
tpnt = kmalloc(sizeof(Scsi_Tape), GFP_ATOMIC);
......@@ -3821,7 +3824,7 @@ static int st_attach(Scsi_Device * SDp)
tpnt->blksize_changed = FALSE;
init_MUTEX(&tpnt->lock);
st_template.nr_dev++;
st_nr_dev++;
write_unlock(&st_dev_arr_lock);
for (mode = 0; mode < ST_NBR_MODES; ++mode) {
......@@ -3883,7 +3886,6 @@ static int st_detect(Scsi_Device * SDp)
{
if (SDp->type != TYPE_TAPE || st_incompatible(SDp))
return 0;
st_template.dev_noticed++;
return 1;
}
......@@ -3893,7 +3895,7 @@ static void st_detach(Scsi_Device * SDp)
int i, mode;
write_lock(&st_dev_arr_lock);
for (i = 0; i < st_template.dev_max; i++) {
for (i = 0; i < st_dev_max; i++) {
tpnt = scsi_tapes[i];
if (tpnt != NULL && tpnt->device == SDp) {
tpnt->device = NULL;
......@@ -3905,8 +3907,7 @@ static void st_detach(Scsi_Device * SDp)
}
scsi_tapes[i] = 0;
SDp->attached--;
st_template.nr_dev--;
st_template.dev_noticed--;
st_nr_dev--;
write_unlock(&st_dev_arr_lock);
for (mode = 0; mode < ST_NBR_MODES; ++mode) {
......@@ -3962,14 +3963,13 @@ static void __exit exit_st(void)
scsi_unregister_device(&st_template);
unregister_chrdev(SCSI_TAPE_MAJOR, "st");
if (scsi_tapes != NULL) {
for (i=0; i < st_template.dev_max; ++i)
for (i=0; i < st_dev_max; ++i)
if (scsi_tapes[i]) {
put_disk(scsi_tapes[i]->disk);
kfree(scsi_tapes[i]);
}
kfree(scsi_tapes);
}
st_template.dev_max = 0;
printk(KERN_INFO "st: Unloaded.\n");
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment