Commit ce3058ec authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] Add ->owner to ide_driver_t

->owner added to ide_driver_t.  MOD_INC_USE_COUNT/MOD_DEC_USE_COUNT
taken out of ->reinit().  ide_reinit_drive() turned into "call
->reinit() for all high-level drivers that are registered until somebody
claims the drive" (instead of open-coded variant in 2.5.32; cleaner and
works correctly for modular drivers).
parent 20d346ec
......@@ -3048,9 +3048,10 @@ int ide_cdrom_cleanup(ide_drive_t *drive)
}
static int ide_cdrom_init(void);
int ide_cdrom_reinit (ide_drive_t *drive);
static int ide_cdrom_reinit (ide_drive_t *drive);
static ide_driver_t ide_cdrom_driver = {
owner: THIS_MODULE,
name: "ide-cdrom",
version: IDECD_VERSION,
media: ide_cdrom,
......@@ -3099,11 +3100,10 @@ char *ignore = NULL;
MODULE_PARM(ignore, "s");
MODULE_DESCRIPTION("ATAPI CD-ROM Driver");
int ide_cdrom_reinit (ide_drive_t *drive)
static int ide_cdrom_reinit (ide_drive_t *drive)
{
struct cdrom_info *info;
MOD_INC_USE_COUNT;
if (!strstr("ide-cdrom", drive->driver_req))
goto failed;
if (!drive->present)
......@@ -3141,10 +3141,8 @@ int ide_cdrom_reinit (ide_drive_t *drive)
goto failed;
}
DRIVER(drive)->busy--;
MOD_DEC_USE_COUNT;
return 0;
failed:
MOD_DEC_USE_COUNT;
return 1;
}
......
......@@ -1637,12 +1637,13 @@ static int idedisk_cleanup (ide_drive_t *drive)
}
static int idedisk_init (void);
int idedisk_reinit(ide_drive_t *drive);
static int idedisk_reinit(ide_drive_t *drive);
/*
* IDE subdriver functions, registered with ide.c
*/
static ide_driver_t idedisk_driver = {
owner: THIS_MODULE,
name: "ide-disk",
version: IDEDISK_VERSION,
media: ide_disk,
......@@ -1683,9 +1684,8 @@ static ide_module_t idedisk_module = {
MODULE_DESCRIPTION("ATA DISK Driver");
int idedisk_reinit(ide_drive_t *drive)
static int idedisk_reinit(ide_drive_t *drive)
{
MOD_INC_USE_COUNT;
/* strstr("foo", "") is non-NULL */
if (!strstr("ide-disk", drive->driver_req))
goto failed;
......@@ -1708,10 +1708,8 @@ int idedisk_reinit(ide_drive_t *drive)
goto failed;
}
DRIVER(drive)->busy--;
MOD_DEC_USE_COUNT;
return 0;
failed:
MOD_DEC_USE_COUNT;
return 1;
}
......
......@@ -2144,12 +2144,13 @@ static ide_proc_entry_t idefloppy_proc[] = {
#endif /* CONFIG_PROC_FS */
static int idefloppy_init (void);
int idefloppy_reinit(ide_drive_t *drive);
static int idefloppy_reinit(ide_drive_t *drive);
/*
* IDE subdriver functions, registered with ide.c
*/
static ide_driver_t idefloppy_driver = {
owner: THIS_MODULE,
name: "ide-floppy",
version: IDEFLOPPY_VERSION,
media: ide_floppy,
......@@ -2192,10 +2193,9 @@ static ide_module_t idefloppy_module = {
NULL
};
int idefloppy_reinit (ide_drive_t *drive)
static int idefloppy_reinit (ide_drive_t *drive)
{
idefloppy_floppy_t *floppy;
MOD_INC_USE_COUNT;
if (!strstr("ide-floppy", drive->driver_req))
goto failed;
if (!drive->present)
......@@ -2222,10 +2222,8 @@ int idefloppy_reinit (ide_drive_t *drive)
DRIVER(drive)->busy++;
idefloppy_setup (drive, floppy);
DRIVER(drive)->busy--;
MOD_DEC_USE_COUNT;
return 0;
failed:
MOD_DEC_USE_COUNT;
return 1;
}
......
......@@ -6301,12 +6301,13 @@ static ide_proc_entry_t idetape_proc[] = {
#endif
static int idetape_init (void);
int idetape_reinit(ide_drive_t *drive);
static int idetape_reinit(ide_drive_t *drive);
/*
* IDE subdriver functions, registered with ide.c
*/
static ide_driver_t idetape_driver = {
owner: THIS_MODULE,
name: "ide-tape",
version: IDETAPE_VERSION,
media: ide_tape,
......@@ -6361,12 +6362,11 @@ static struct file_operations idetape_fops = {
release: idetape_chrdev_release,
};
int idetape_reinit (ide_drive_t *drive)
static int idetape_reinit (ide_drive_t *drive)
{
idetape_tape_t *tape;
int minor;
MOD_INC_USE_COUNT;
if (!strstr("ide-tape", drive->driver_req))
goto failed;
if (!drive->present)
......@@ -6410,10 +6410,8 @@ int idetape_reinit (ide_drive_t *drive)
S_IFCHR | S_IRUGO | S_IWUGO,
&idetape_fops, NULL);
devfs_register_tape(tape->de_r);
MOD_DEC_USE_COUNT;
return 0;
failed:
MOD_DEC_USE_COUNT;
return 1;
}
......
......@@ -2515,59 +2515,28 @@ int system_bus_clock (void)
return((int) ((!system_bus_speed) ? ide_system_bus_speed() : system_bus_speed ));
}
static spinlock_t drivers_lock = SPIN_LOCK_UNLOCKED;
int ide_reinit_drive (ide_drive_t *drive)
{
switch (drive->media) {
#ifdef CONFIG_BLK_DEV_IDECD
case ide_cdrom:
{
extern int ide_cdrom_reinit(ide_drive_t *drive);
if (ide_cdrom_reinit(drive))
return 1;
break;
}
#endif /* CONFIG_BLK_DEV_IDECD */
#ifdef CONFIG_BLK_DEV_IDEDISK
case ide_disk:
{
extern int idedisk_reinit(ide_drive_t *drive);
if (idedisk_reinit(drive))
return 1;
break;
}
#endif /* CONFIG_BLK_DEV_IDEDISK */
#ifdef CONFIG_BLK_DEV_IDEFLOPPY
case ide_floppy:
{
extern int idefloppy_reinit(ide_drive_t *drive);
if (idefloppy_reinit(drive))
return 1;
break;
ide_module_t *module;
spin_lock(&drivers_lock);
for (module = ide_modules; module; module = module->next) {
ide_driver_t *driver = module->info;
if (!try_inc_mod_count(driver->owner))
continue;
spin_unlock(&drivers_lock);
if (driver->reinit(drive) == 0) {
if (driver->owner)
__MOD_DEC_USE_COUNT(driver->owner);
return 0;
}
#endif /* CONFIG_BLK_DEV_IDEFLOPPY */
#ifdef CONFIG_BLK_DEV_IDETAPE
case ide_tape:
{
extern int idetape_reinit(ide_drive_t *drive);
if (idetape_reinit(drive))
return 1;
break;
spin_lock(&drivers_lock);
if (driver->owner)
__MOD_DEC_USE_COUNT(driver->owner);
}
#endif /* CONFIG_BLK_DEV_IDETAPE */
#ifdef CONFIG_BLK_DEV_IDESCSI
/*
* {
* extern int idescsi_reinit(ide_drive_t *drive);
* if (idescsi_reinit(drive))
* return 1;
* break;
* }
*/
#endif /* CONFIG_BLK_DEV_IDESCSI */
default:
spin_unlock(&drivers_lock);
return 1;
}
return 0;
}
static int ide_ioctl (struct inode *inode, struct file *file,
......@@ -3605,12 +3574,16 @@ int ide_register_module (ide_module_t *module)
failed--;
}
spin_lock(&drivers_lock);
for (p = ide_modules; p; p = p->next) {
if (p == module)
if (p == module) {
spin_unlock(&drivers_lock);
return 1;
}
}
module->next = ide_modules;
ide_modules = module;
spin_unlock(&drivers_lock);
revalidate_drives();
return 0;
}
......@@ -3635,9 +3608,11 @@ void ide_unregister_module (ide_module_t *module)
#endif
}
spin_lock(&drivers_lock);
for (p = &ide_modules; (*p) && (*p) != module; p = &((*p)->next));
if (*p)
*p = (*p)->next;
spin_unlock(&drivers_lock);
}
struct block_device_operations ide_fops[] = {{
......
......@@ -545,6 +545,7 @@ static int idescsi_reinit(ide_drive_t *drive);
* IDE subdriver functions, registered with ide.c
*/
static ide_driver_t idescsi_driver = {
owner: THIS_MODULE,
name: "ide-scsi",
version: IDESCSI_VERSION,
media: ide_scsi,
......@@ -582,7 +583,6 @@ static int idescsi_reinit(ide_drive_t *drive)
idescsi_scsi_t *scsi;
int id;
MOD_INC_USE_COUNT;
if (!strstr("ide-scsi", drive->driver_req))
goto failed;
if (!drive->present)
......@@ -602,10 +602,8 @@ static int idescsi_reinit(ide_drive_t *drive)
for (id = 0; id < MAX_HWIFS * MAX_DRIVES && idescsi_drives[id]; id++)
;
idescsi_setup (drive, scsi, id);
MOD_DEC_USE_COUNT;
return 0;
failed:
MOD_DEC_USE_COUNT;
return 1;
}
......
......@@ -890,6 +890,7 @@ read_proc_t proc_ide_read_geometry;
#define IDE_SUBDRIVER_VERSION 1
typedef struct ide_driver_s {
struct module *owner;
const char *name;
const char *version;
byte media;
......@@ -1218,21 +1219,6 @@ int ide_reinit_drive (ide_drive_t *drive);
#ifdef CONFIG_BLK_DEV_IDE
int ideprobe_init (void);
#endif /* CONFIG_BLK_DEV_IDE */
#ifdef CONFIG_BLK_DEV_IDEDISK
int idedisk_reinit (ide_drive_t *drive);
#endif /* CONFIG_BLK_DEV_IDEDISK */
#ifdef CONFIG_BLK_DEV_IDECD
int ide_cdrom_reinit (ide_drive_t *drive);
#endif /* CONFIG_BLK_DEV_IDECD */
#ifdef CONFIG_BLK_DEV_IDETAPE
int idetape_reinit (ide_drive_t *drive);
#endif /* CONFIG_BLK_DEV_IDETAPE */
#ifdef CONFIG_BLK_DEV_IDEFLOPPY
int idefloppy_reinit (ide_drive_t *drive);
#endif /* CONFIG_BLK_DEV_IDEFLOPPY */
#ifdef CONFIG_BLK_DEV_IDESCSI
int idescsi_reinit (ide_drive_t *drive);
#endif /* CONFIG_BLK_DEV_IDESCSI */
#endif /* _IDE_C */
int ide_register_module (ide_module_t *module);
......
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