Commit 20d346ec authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] per-drive IDE deregistration

loops in ide_cdrom_init()/ide_cdrom_exit(), etc. are pulled into
ide_register_module()/ide_unregister_module() resp.
parent 47a1397b
...@@ -3150,28 +3150,12 @@ int ide_cdrom_reinit (ide_drive_t *drive) ...@@ -3150,28 +3150,12 @@ int ide_cdrom_reinit (ide_drive_t *drive)
static void __exit ide_cdrom_exit(void) static void __exit ide_cdrom_exit(void)
{ {
ide_drive_t *drive;
int failed = 0;
while ((drive = ide_scan_devices (&ide_cdrom_driver, failed)) != NULL)
if (ide_cdrom_cleanup (drive)) {
printk ("%s: cleanup_module() called while still busy\n", drive->name);
failed++;
}
ide_unregister_module (&ide_cdrom_module); ide_unregister_module (&ide_cdrom_module);
} }
static int ide_cdrom_init(void) static int ide_cdrom_init(void)
{ {
ide_drive_t *drive;
int failed = 0;
MOD_INC_USE_COUNT; MOD_INC_USE_COUNT;
while ((drive = ide_scan_devices (NULL, failed++)) != NULL) {
if (ide_cdrom_reinit(drive))
continue;
failed--;
}
ide_register_module(&ide_cdrom_module); ide_register_module(&ide_cdrom_module);
MOD_DEC_USE_COUNT; MOD_DEC_USE_COUNT;
return 0; return 0;
......
...@@ -1717,35 +1717,12 @@ int idedisk_reinit(ide_drive_t *drive) ...@@ -1717,35 +1717,12 @@ int idedisk_reinit(ide_drive_t *drive)
static void __exit idedisk_exit (void) static void __exit idedisk_exit (void)
{ {
ide_drive_t *drive;
int failed = 0;
while ((drive = ide_scan_devices(&idedisk_driver, failed)) != NULL) {
if (idedisk_cleanup (drive)) {
printk (KERN_ERR "%s: cleanup_module() called while still busy\n", drive->name);
failed++;
}
/* We must remove proc entries defined in this module.
Otherwise we oops while accessing these entries */
#ifdef CONFIG_PROC_FS
if (drive->proc)
ide_remove_proc_entries(drive->proc, idedisk_proc);
#endif
}
ide_unregister_module(&idedisk_module); ide_unregister_module(&idedisk_module);
} }
static int idedisk_init (void) static int idedisk_init (void)
{ {
ide_drive_t *drive;
int failed = 0;
MOD_INC_USE_COUNT; MOD_INC_USE_COUNT;
while ((drive = ide_scan_devices(NULL, failed++)) != NULL) {
if (idedisk_reinit(drive))
continue;
failed--;
}
ide_register_module(&idedisk_module); ide_register_module(&idedisk_module);
MOD_DEC_USE_COUNT; MOD_DEC_USE_COUNT;
return 0; return 0;
......
...@@ -2233,21 +2233,6 @@ MODULE_DESCRIPTION("ATAPI FLOPPY Driver"); ...@@ -2233,21 +2233,6 @@ MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
static void __exit idefloppy_exit (void) static void __exit idefloppy_exit (void)
{ {
ide_drive_t *drive;
int failed = 0;
while ((drive = ide_scan_devices(&idefloppy_driver, failed)) != NULL) {
if (idefloppy_cleanup (drive)) {
printk ("%s: cleanup_module() called while still busy\n", drive->name);
failed++;
}
/* We must remove proc entries defined in this module.
Otherwise we oops while accessing these entries */
#ifdef CONFIG_PROC_FS
if (drive->proc)
ide_remove_proc_entries(drive->proc, idefloppy_proc);
#endif
}
ide_unregister_module(&idefloppy_module); ide_unregister_module(&idefloppy_module);
} }
...@@ -2256,16 +2241,8 @@ static void __exit idefloppy_exit (void) ...@@ -2256,16 +2241,8 @@ static void __exit idefloppy_exit (void)
*/ */
static int idefloppy_init (void) static int idefloppy_init (void)
{ {
ide_drive_t *drive;
int failed = 0;
printk("ide-floppy driver " IDEFLOPPY_VERSION "\n"); printk("ide-floppy driver " IDEFLOPPY_VERSION "\n");
MOD_INC_USE_COUNT; MOD_INC_USE_COUNT;
while ((drive = ide_scan_devices(NULL, failed++)) != NULL) {
if (idefloppy_reinit(drive))
continue;
failed--;
}
ide_register_module(&idefloppy_module); ide_register_module(&idefloppy_module);
MOD_DEC_USE_COUNT; MOD_DEC_USE_COUNT;
return 0; return 0;
......
...@@ -6272,11 +6272,6 @@ static int idetape_cleanup (ide_drive_t *drive) ...@@ -6272,11 +6272,6 @@ static int idetape_cleanup (ide_drive_t *drive)
devfs_unregister(tape->de_r); devfs_unregister(tape->de_r);
devfs_unregister(tape->de_n); devfs_unregister(tape->de_n);
kfree (tape); kfree (tape);
for (minor = 0; minor < MAX_HWIFS * MAX_DRIVES; minor++)
if (idetape_chrdevs[minor].drive != NULL)
return 0;
unregister_chrdev(IDETAPE_MAJOR, "ht");
idetape_chrdev_present = 0;
return 0; return 0;
} }
...@@ -6427,15 +6422,9 @@ MODULE_LICENSE("GPL"); ...@@ -6427,15 +6422,9 @@ MODULE_LICENSE("GPL");
static void __exit idetape_exit (void) static void __exit idetape_exit (void)
{ {
ide_drive_t *drive;
int minor;
for (minor = 0; minor < MAX_HWIFS * MAX_DRIVES; minor++) {
drive = idetape_chrdevs[minor].drive;
if (drive != NULL && idetape_cleanup (drive))
printk(KERN_ERR "ide-tape: %s: cleanup_module() called while still busy\n", drive->name);
}
ide_unregister_module(&idetape_module); ide_unregister_module(&idetape_module);
unregister_chrdev(IDETAPE_MAJOR, "ht");
idetape_chrdev_present = 0;
} }
/* /*
...@@ -6443,30 +6432,15 @@ static void __exit idetape_exit (void) ...@@ -6443,30 +6432,15 @@ static void __exit idetape_exit (void)
*/ */
static int idetape_init (void) static int idetape_init (void)
{ {
ide_drive_t *drive;
int minor, failed = 0, supported = 0;
/* DRIVER(drive)->busy++; */
MOD_INC_USE_COUNT; MOD_INC_USE_COUNT;
if (!idetape_chrdev_present) { if (!idetape_chrdev_present) {
idetape_chrdev_present = 1;
if (register_chrdev(IDETAPE_MAJOR, "ht", &idetape_fops)) { if (register_chrdev(IDETAPE_MAJOR, "ht", &idetape_fops)) {
printk(KERN_ERR "ide-tape: Failed to register character device interface\n"); printk(KERN_ERR "ide-tape: Failed to register character device interface\n");
MOD_DEC_USE_COUNT; MOD_DEC_USE_COUNT;
return -EBUSY; return -EBUSY;
} }
for (minor = 0; minor < MAX_HWIFS * MAX_DRIVES; minor++)
idetape_chrdevs[minor].drive = NULL;
} }
while ((drive = ide_scan_devices(NULL, failed++))) {
if (idetape_reinit(drive))
continue;
supported++;
failed--;
}
if (!idetape_chrdev_present && !supported) {
unregister_chrdev(IDETAPE_MAJOR, "ht");
} else
idetape_chrdev_present = 1;
ide_register_module(&idetape_module); ide_register_module(&idetape_module);
MOD_DEC_USE_COUNT; MOD_DEC_USE_COUNT;
return 0; return 0;
......
...@@ -3511,7 +3511,7 @@ static void setup_driver_defaults (ide_drive_t *drive) ...@@ -3511,7 +3511,7 @@ static void setup_driver_defaults (ide_drive_t *drive)
if (d->reinit == NULL) d->reinit = default_reinit; if (d->reinit == NULL) d->reinit = default_reinit;
} }
ide_drive_t *ide_scan_devices(ide_driver_t *driver, int n) static ide_drive_t *ide_scan_devices(ide_driver_t *driver, int n)
{ {
unsigned int unit, index, i; unsigned int unit, index, i;
...@@ -3594,12 +3594,20 @@ int ide_unregister_subdriver (ide_drive_t *drive) ...@@ -3594,12 +3594,20 @@ int ide_unregister_subdriver (ide_drive_t *drive)
int ide_register_module (ide_module_t *module) int ide_register_module (ide_module_t *module)
{ {
ide_module_t *p = ide_modules; ide_driver_t *driver = module->info;
ide_module_t *p;
ide_drive_t *drive;
int failed = 0;
while (p) { while ((drive = ide_scan_devices (NULL, failed++)) != NULL) {
if (driver->reinit(drive))
continue;
failed--;
}
for (p = ide_modules; p; p = p->next) {
if (p == module) if (p == module)
return 1; return 1;
p = p->next;
} }
module->next = ide_modules; module->next = ide_modules;
ide_modules = module; ide_modules = module;
...@@ -3609,7 +3617,23 @@ int ide_register_module (ide_module_t *module) ...@@ -3609,7 +3617,23 @@ int ide_register_module (ide_module_t *module)
void ide_unregister_module (ide_module_t *module) void ide_unregister_module (ide_module_t *module)
{ {
ide_driver_t *driver = module->info;
ide_module_t **p; ide_module_t **p;
ide_drive_t *drive;
int failed = 0;
while ((drive = ide_scan_devices(driver, failed)) != NULL) {
if (driver->cleanup(drive)) {
printk ("%s: cleanup_module() called while still busy\n", drive->name);
failed++;
}
/* We must remove proc entries defined in this module.
Otherwise we oops while accessing these entries */
#ifdef CONFIG_PROC_FS
if (drive->proc)
ide_remove_proc_entries(drive->proc, driver->proc);
#endif
}
for (p = &ide_modules; (*p) && (*p) != module; p = &((*p)->next)); for (p = &ide_modules; (*p) && (*p) != module; p = &((*p)->next));
if (*p) if (*p)
...@@ -3648,7 +3672,6 @@ EXPORT_SYMBOL(do_ide_request); ...@@ -3648,7 +3672,6 @@ EXPORT_SYMBOL(do_ide_request);
/* /*
* Driver module * Driver module
*/ */
EXPORT_SYMBOL(ide_scan_devices);
EXPORT_SYMBOL(ide_register_subdriver); EXPORT_SYMBOL(ide_register_subdriver);
EXPORT_SYMBOL(ide_unregister_subdriver); EXPORT_SYMBOL(ide_unregister_subdriver);
EXPORT_SYMBOL(ide_replace_subdriver); EXPORT_SYMBOL(ide_replace_subdriver);
......
...@@ -614,8 +614,7 @@ static int idescsi_reinit(ide_drive_t *drive) ...@@ -614,8 +614,7 @@ static int idescsi_reinit(ide_drive_t *drive)
*/ */
static int idescsi_init (void) static int idescsi_init (void)
{ {
ide_drive_t *drive; int i;
int i, failed;
if (idescsi_initialized) if (idescsi_initialized)
return 0; return 0;
...@@ -623,12 +622,6 @@ static int idescsi_init (void) ...@@ -623,12 +622,6 @@ static int idescsi_init (void)
for (i = 0; i < MAX_HWIFS * MAX_DRIVES; i++) for (i = 0; i < MAX_HWIFS * MAX_DRIVES; i++)
idescsi_drives[i] = NULL; idescsi_drives[i] = NULL;
MOD_INC_USE_COUNT; MOD_INC_USE_COUNT;
failed = 0;
while ((drive = ide_scan_devices(NULL, failed++)) != NULL) {
if (idescsi_reinit(drive))
continue;
failed--;
}
ide_register_module(&idescsi_module); ide_register_module(&idescsi_module);
MOD_DEC_USE_COUNT; MOD_DEC_USE_COUNT;
return 0; return 0;
...@@ -886,16 +879,7 @@ static int __init init_idescsi_module(void) ...@@ -886,16 +879,7 @@ static int __init init_idescsi_module(void)
static void __exit exit_idescsi_module(void) static void __exit exit_idescsi_module(void)
{ {
ide_drive_t *drive;
int failed;
scsi_unregister_host(&idescsi_template); scsi_unregister_host(&idescsi_template);
failed = 0;
while ((drive = ide_scan_devices(&idescsi_driver, failed)) != NULL)
if (idescsi_cleanup (drive)) {
printk ("%s: exit_idescsi_module() called while still busy\n", drive->name);
failed++;
}
ide_unregister_module(&idescsi_module); ide_unregister_module(&idescsi_module);
} }
......
...@@ -1237,7 +1237,6 @@ int idescsi_reinit (ide_drive_t *drive); ...@@ -1237,7 +1237,6 @@ int idescsi_reinit (ide_drive_t *drive);
int ide_register_module (ide_module_t *module); int ide_register_module (ide_module_t *module);
void ide_unregister_module (ide_module_t *module); void ide_unregister_module (ide_module_t *module);
ide_drive_t *ide_scan_devices(ide_driver_t *driver, int n);
int ide_register_subdriver (ide_drive_t *drive, ide_driver_t *driver, int version); int ide_register_subdriver (ide_drive_t *drive, ide_driver_t *driver, int version);
int ide_unregister_subdriver (ide_drive_t *drive); int ide_unregister_subdriver (ide_drive_t *drive);
int ide_replace_subdriver(ide_drive_t *drive, const char *driver); int ide_replace_subdriver(ide_drive_t *drive, const char *driver);
......
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