Commit 2923c262 authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] move media_type checks from ide_scan_devices() to ->reinit

Checks for media type, ->driver_req, etc.  are moved from the
ide_scan_devices() to ->reinit().  ide_scan_devices() had lost first two
arguments (it will completely disappear later).
parent 06330ca4
...@@ -3104,17 +3104,32 @@ int ide_cdrom_reinit (ide_drive_t *drive) ...@@ -3104,17 +3104,32 @@ int ide_cdrom_reinit (ide_drive_t *drive)
struct cdrom_info *info; struct cdrom_info *info;
MOD_INC_USE_COUNT; MOD_INC_USE_COUNT;
if (!strstr("ide-cdrom", drive->driver_req))
goto failed;
if (!drive->present)
goto failed;
if (drive->media != ide_cdrom)
goto failed;
/* skip drives that we were told to ignore */
if (ignore != NULL) {
if (strstr(ignore, drive->name)) {
printk("ide-cd: ignoring drive %s\n", drive->name);
goto failed;
}
}
if (drive->scsi) {
printk("ide-cd: passing drive %s to ide-scsi emulation.\n", drive->name);
goto failed;
}
info = (struct cdrom_info *) kmalloc (sizeof (struct cdrom_info), GFP_KERNEL); info = (struct cdrom_info *) kmalloc (sizeof (struct cdrom_info), GFP_KERNEL);
if (info == NULL) { if (info == NULL) {
printk ("%s: Can't allocate a cdrom structure\n", drive->name); printk ("%s: Can't allocate a cdrom structure\n", drive->name);
MOD_DEC_USE_COUNT; goto failed;
return 1;
} }
if (ide_register_subdriver (drive, &ide_cdrom_driver, IDE_SUBDRIVER_VERSION)) { if (ide_register_subdriver (drive, &ide_cdrom_driver, IDE_SUBDRIVER_VERSION)) {
printk ("%s: Failed to register the driver with ide.c\n", drive->name); printk ("%s: Failed to register the driver with ide.c\n", drive->name);
kfree (info); kfree (info);
MOD_DEC_USE_COUNT; goto failed;
return 1;
} }
memset (info, 0, sizeof (struct cdrom_info)); memset (info, 0, sizeof (struct cdrom_info));
drive->driver_data = info; drive->driver_data = info;
...@@ -3123,12 +3138,14 @@ int ide_cdrom_reinit (ide_drive_t *drive) ...@@ -3123,12 +3138,14 @@ int ide_cdrom_reinit (ide_drive_t *drive)
DRIVER(drive)->busy--; DRIVER(drive)->busy--;
if (ide_cdrom_cleanup (drive)) if (ide_cdrom_cleanup (drive))
printk ("%s: ide_cdrom_cleanup failed in ide_cdrom_init\n", drive->name); printk ("%s: ide_cdrom_cleanup failed in ide_cdrom_init\n", drive->name);
MOD_DEC_USE_COUNT; goto failed;
return 1;
} }
DRIVER(drive)->busy--; DRIVER(drive)->busy--;
MOD_DEC_USE_COUNT; MOD_DEC_USE_COUNT;
return 0; return 0;
failed:
MOD_DEC_USE_COUNT;
return 1;
} }
static void __exit ide_cdrom_exit(void) static void __exit ide_cdrom_exit(void)
...@@ -3136,7 +3153,7 @@ static void __exit ide_cdrom_exit(void) ...@@ -3136,7 +3153,7 @@ static void __exit ide_cdrom_exit(void)
ide_drive_t *drive; ide_drive_t *drive;
int failed = 0; int failed = 0;
while ((drive = ide_scan_devices (ide_cdrom, ide_cdrom_driver.name, &ide_cdrom_driver, failed)) != NULL) while ((drive = ide_scan_devices (&ide_cdrom_driver, failed)) != NULL)
if (ide_cdrom_cleanup (drive)) { if (ide_cdrom_cleanup (drive)) {
printk ("%s: cleanup_module() called while still busy\n", drive->name); printk ("%s: cleanup_module() called while still busy\n", drive->name);
failed++; failed++;
...@@ -3150,18 +3167,7 @@ int ide_cdrom_init(void) ...@@ -3150,18 +3167,7 @@ int ide_cdrom_init(void)
int failed = 0; int failed = 0;
MOD_INC_USE_COUNT; MOD_INC_USE_COUNT;
while ((drive = ide_scan_devices (ide_cdrom, ide_cdrom_driver.name, NULL, failed++)) != NULL) { while ((drive = ide_scan_devices (NULL, failed++)) != NULL) {
/* skip drives that we were told to ignore */
if (ignore != NULL) {
if (strstr(ignore, drive->name)) {
printk("ide-cd: ignoring drive %s\n", drive->name);
continue;
}
}
if (drive->scsi) {
printk("ide-cd: passing drive %s to ide-scsi emulation.\n", drive->name);
continue;
}
if (ide_cdrom_reinit(drive)) if (ide_cdrom_reinit(drive))
continue; continue;
failed--; failed--;
......
...@@ -1686,11 +1686,17 @@ MODULE_DESCRIPTION("ATA DISK Driver"); ...@@ -1686,11 +1686,17 @@ MODULE_DESCRIPTION("ATA DISK Driver");
int idedisk_reinit(ide_drive_t *drive) int idedisk_reinit(ide_drive_t *drive)
{ {
MOD_INC_USE_COUNT; MOD_INC_USE_COUNT;
/* strstr("foo", "") is non-NULL */
if (!strstr("ide-disk", drive->driver_req))
goto failed;
if (!drive->present)
goto failed;
if (drive->media != ide_disk)
goto failed;
if (ide_register_subdriver (drive, &idedisk_driver, IDE_SUBDRIVER_VERSION)) { if (ide_register_subdriver (drive, &idedisk_driver, IDE_SUBDRIVER_VERSION)) {
printk (KERN_ERR "ide-disk: %s: Failed to register the driver with ide.c\n", drive->name); printk (KERN_ERR "ide-disk: %s: Failed to register the driver with ide.c\n", drive->name);
MOD_DEC_USE_COUNT; goto failed;
return 1;
} }
DRIVER(drive)->busy++; DRIVER(drive)->busy++;
idedisk_setup(drive); idedisk_setup(drive);
...@@ -1699,12 +1705,14 @@ int idedisk_reinit(ide_drive_t *drive) ...@@ -1699,12 +1705,14 @@ int idedisk_reinit(ide_drive_t *drive)
drive->name, drive->head); drive->name, drive->head);
(void) idedisk_cleanup(drive); (void) idedisk_cleanup(drive);
DRIVER(drive)->busy--; DRIVER(drive)->busy--;
MOD_DEC_USE_COUNT; goto failed;
return 1;
} }
DRIVER(drive)->busy--; DRIVER(drive)->busy--;
MOD_DEC_USE_COUNT; MOD_DEC_USE_COUNT;
return 0; return 0;
failed:
MOD_DEC_USE_COUNT;
return 1;
} }
static void __exit idedisk_exit (void) static void __exit idedisk_exit (void)
...@@ -1712,7 +1720,7 @@ static void __exit idedisk_exit (void) ...@@ -1712,7 +1720,7 @@ static void __exit idedisk_exit (void)
ide_drive_t *drive; ide_drive_t *drive;
int failed = 0; int failed = 0;
while ((drive = ide_scan_devices (ide_disk, idedisk_driver.name, &idedisk_driver, failed)) != NULL) { while ((drive = ide_scan_devices(&idedisk_driver, failed)) != NULL) {
if (idedisk_cleanup (drive)) { if (idedisk_cleanup (drive)) {
printk (KERN_ERR "%s: cleanup_module() called while still busy\n", drive->name); printk (KERN_ERR "%s: cleanup_module() called while still busy\n", drive->name);
failed++; failed++;
...@@ -1733,7 +1741,7 @@ int idedisk_init (void) ...@@ -1733,7 +1741,7 @@ int idedisk_init (void)
int failed = 0; int failed = 0;
MOD_INC_USE_COUNT; MOD_INC_USE_COUNT;
while ((drive = ide_scan_devices (ide_disk, idedisk_driver.name, NULL, failed++)) != NULL) { while ((drive = ide_scan_devices(NULL, failed++)) != NULL) {
if (idedisk_reinit(drive)) if (idedisk_reinit(drive))
continue; continue;
failed--; failed--;
......
...@@ -2196,32 +2196,37 @@ int idefloppy_reinit (ide_drive_t *drive) ...@@ -2196,32 +2196,37 @@ int idefloppy_reinit (ide_drive_t *drive)
{ {
idefloppy_floppy_t *floppy; idefloppy_floppy_t *floppy;
MOD_INC_USE_COUNT; MOD_INC_USE_COUNT;
if (!strstr("ide-floppy", drive->driver_req))
goto failed;
if (!drive->present)
goto failed;
if (drive->media != ide_floppy)
goto failed;
if (!idefloppy_identify_device (drive, drive->id)) { if (!idefloppy_identify_device (drive, drive->id)) {
printk (KERN_ERR "ide-floppy: %s: not supported by this version of ide-floppy\n", drive->name); printk (KERN_ERR "ide-floppy: %s: not supported by this version of ide-floppy\n", drive->name);
MOD_DEC_USE_COUNT; goto failed;
return 1;
} }
if (drive->scsi) { if (drive->scsi) {
printk("ide-floppy: passing drive %s to ide-scsi emulation.\n", drive->name); printk("ide-floppy: passing drive %s to ide-scsi emulation.\n", drive->name);
MOD_DEC_USE_COUNT; goto failed;
return 1;
} }
if ((floppy = (idefloppy_floppy_t *) kmalloc (sizeof (idefloppy_floppy_t), GFP_KERNEL)) == NULL) { if ((floppy = (idefloppy_floppy_t *) kmalloc (sizeof (idefloppy_floppy_t), GFP_KERNEL)) == NULL) {
printk (KERN_ERR "ide-floppy: %s: Can't allocate a floppy structure\n", drive->name); printk (KERN_ERR "ide-floppy: %s: Can't allocate a floppy structure\n", drive->name);
MOD_DEC_USE_COUNT; goto failed;
return 1;
} }
if (ide_register_subdriver (drive, &idefloppy_driver, IDE_SUBDRIVER_VERSION)) { if (ide_register_subdriver (drive, &idefloppy_driver, IDE_SUBDRIVER_VERSION)) {
printk (KERN_ERR "ide-floppy: %s: Failed to register the driver with ide.c\n", drive->name); printk (KERN_ERR "ide-floppy: %s: Failed to register the driver with ide.c\n", drive->name);
kfree (floppy); kfree (floppy);
MOD_DEC_USE_COUNT; goto failed;
return 1;
} }
DRIVER(drive)->busy++; DRIVER(drive)->busy++;
idefloppy_setup (drive, floppy); idefloppy_setup (drive, floppy);
DRIVER(drive)->busy--; DRIVER(drive)->busy--;
MOD_DEC_USE_COUNT; MOD_DEC_USE_COUNT;
return 0; return 0;
failed:
MOD_DEC_USE_COUNT;
return 1;
} }
MODULE_DESCRIPTION("ATAPI FLOPPY Driver"); MODULE_DESCRIPTION("ATAPI FLOPPY Driver");
...@@ -2231,7 +2236,7 @@ static void __exit idefloppy_exit (void) ...@@ -2231,7 +2236,7 @@ static void __exit idefloppy_exit (void)
ide_drive_t *drive; ide_drive_t *drive;
int failed = 0; int failed = 0;
while ((drive = ide_scan_devices (ide_floppy, idefloppy_driver.name, &idefloppy_driver, failed)) != NULL) { while ((drive = ide_scan_devices(&idefloppy_driver, failed)) != NULL) {
if (idefloppy_cleanup (drive)) { if (idefloppy_cleanup (drive)) {
printk ("%s: cleanup_module() called while still busy\n", drive->name); printk ("%s: cleanup_module() called while still busy\n", drive->name);
failed++; failed++;
...@@ -2256,7 +2261,7 @@ int idefloppy_init (void) ...@@ -2256,7 +2261,7 @@ int idefloppy_init (void)
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 (ide_floppy, idefloppy_driver.name, NULL, failed++)) != NULL) { while ((drive = ide_scan_devices(NULL, failed++)) != NULL) {
if (idefloppy_reinit(drive)) if (idefloppy_reinit(drive))
continue; continue;
failed--; failed--;
......
...@@ -6372,31 +6372,33 @@ int idetape_reinit (ide_drive_t *drive) ...@@ -6372,31 +6372,33 @@ int idetape_reinit (ide_drive_t *drive)
int minor; int minor;
MOD_INC_USE_COUNT; MOD_INC_USE_COUNT;
if (!strstr("ide-tape", drive->driver_req))
goto failed;
if (!drive->present)
goto failed;
if (drive->media != ide_tape)
goto failed;
if (!idetape_identify_device (drive, drive->id)) { if (!idetape_identify_device (drive, drive->id)) {
printk(KERN_ERR "ide-tape: %s: not supported by this version of ide-tape\n", drive->name); printk(KERN_ERR "ide-tape: %s: not supported by this version of ide-tape\n", drive->name);
MOD_DEC_USE_COUNT; goto failed;
return 1;
} }
if (drive->scsi) { if (drive->scsi) {
if (strstr(drive->id->model, "OnStream DI-")) { if (strstr(drive->id->model, "OnStream DI-")) {
printk("ide-tape: ide-scsi emulation is not supported for %s.\n", drive->id->model); printk("ide-tape: ide-scsi emulation is not supported for %s.\n", drive->id->model);
} else { } else {
printk("ide-tape: passing drive %s to ide-scsi emulation.\n", drive->name); printk("ide-tape: passing drive %s to ide-scsi emulation.\n", drive->name);
MOD_DEC_USE_COUNT; goto failed;
return 1;
} }
} }
tape = (idetape_tape_t *) kmalloc (sizeof (idetape_tape_t), GFP_KERNEL); tape = (idetape_tape_t *) kmalloc (sizeof (idetape_tape_t), GFP_KERNEL);
if (tape == NULL) { if (tape == NULL) {
printk(KERN_ERR "ide-tape: %s: Can't allocate a tape structure\n", drive->name); printk(KERN_ERR "ide-tape: %s: Can't allocate a tape structure\n", drive->name);
MOD_DEC_USE_COUNT; goto failed;
return 1;
} }
if (ide_register_subdriver (drive, &idetape_driver, IDE_SUBDRIVER_VERSION)) { if (ide_register_subdriver (drive, &idetape_driver, IDE_SUBDRIVER_VERSION)) {
printk(KERN_ERR "ide-tape: %s: Failed to register the driver with ide.c\n", drive->name); printk(KERN_ERR "ide-tape: %s: Failed to register the driver with ide.c\n", drive->name);
kfree(tape); kfree(tape);
MOD_DEC_USE_COUNT; goto failed;
return 1;
} }
for (minor = 0; idetape_chrdevs[minor].drive != NULL; minor++) for (minor = 0; idetape_chrdevs[minor].drive != NULL; minor++)
; ;
...@@ -6415,6 +6417,9 @@ int idetape_reinit (ide_drive_t *drive) ...@@ -6415,6 +6417,9 @@ int idetape_reinit (ide_drive_t *drive)
devfs_register_tape(tape->de_r); devfs_register_tape(tape->de_r);
MOD_DEC_USE_COUNT; MOD_DEC_USE_COUNT;
return 0; return 0;
failed:
MOD_DEC_USE_COUNT;
return 1;
} }
MODULE_DESCRIPTION("ATAPI Streaming TAPE Driver"); MODULE_DESCRIPTION("ATAPI Streaming TAPE Driver");
...@@ -6452,7 +6457,7 @@ int idetape_init (void) ...@@ -6452,7 +6457,7 @@ int idetape_init (void)
idetape_chrdevs[minor].drive = NULL; idetape_chrdevs[minor].drive = NULL;
} }
while ((drive = ide_scan_devices(ide_tape, idetape_driver.name, NULL, failed++))) { while ((drive = ide_scan_devices(NULL, failed++))) {
if (idetape_reinit(drive)) if (idetape_reinit(drive))
continue; continue;
supported++; supported++;
......
...@@ -3535,7 +3535,7 @@ static void setup_driver_defaults (ide_drive_t *drive) ...@@ -3535,7 +3535,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 (byte media, const char *name, ide_driver_t *driver, int n) ide_drive_t *ide_scan_devices(ide_driver_t *driver, int n)
{ {
unsigned int unit, index, i; unsigned int unit, index, i;
...@@ -3545,10 +3545,7 @@ ide_drive_t *ide_scan_devices (byte media, const char *name, ide_driver_t *drive ...@@ -3545,10 +3545,7 @@ ide_drive_t *ide_scan_devices (byte media, const char *name, ide_driver_t *drive
continue; continue;
for (unit = 0; unit < MAX_DRIVES; ++unit) { for (unit = 0; unit < MAX_DRIVES; ++unit) {
ide_drive_t *drive = &hwif->drives[unit]; ide_drive_t *drive = &hwif->drives[unit];
char *req = drive->driver_req; if (drive->driver == driver && ++i > n)
if (*req && !strstr(name, req))
continue;
if (drive->present && drive->media == media && drive->driver == driver && ++i > n)
return drive; return drive;
} }
} }
......
...@@ -583,23 +583,30 @@ static int idescsi_reinit(ide_drive_t *drive) ...@@ -583,23 +583,30 @@ static int idescsi_reinit(ide_drive_t *drive)
int id; int id;
MOD_INC_USE_COUNT; MOD_INC_USE_COUNT;
if (!strstr("ide-scsi", drive->driver_req))
goto failed;
if (!drive->present)
goto failed;
/* we accept everything except ide-disk */
if (drive->media == ide_disk)
goto failed;
if ((scsi = (idescsi_scsi_t *) kmalloc (sizeof (idescsi_scsi_t), GFP_KERNEL)) == NULL) { if ((scsi = (idescsi_scsi_t *) kmalloc (sizeof (idescsi_scsi_t), GFP_KERNEL)) == NULL) {
printk (KERN_ERR "ide-scsi: %s: Can't allocate a scsi structure\n", drive->name); printk (KERN_ERR "ide-scsi: %s: Can't allocate a scsi structure\n", drive->name);
MOD_DEC_USE_COUNT; goto failed;
return 1;
} }
if (ide_register_subdriver (drive, &idescsi_driver, IDE_SUBDRIVER_VERSION)) { if (ide_register_subdriver (drive, &idescsi_driver, IDE_SUBDRIVER_VERSION)) {
printk (KERN_ERR "ide-scsi: %s: Failed to register the driver with ide.c\n", drive->name); printk (KERN_ERR "ide-scsi: %s: Failed to register the driver with ide.c\n", drive->name);
kfree (scsi); kfree (scsi);
MOD_DEC_USE_COUNT; goto failed;
return 1;
} }
for (id = 0; id < MAX_HWIFS * MAX_DRIVES && idescsi_drives[id]; id++) for (id = 0; id < MAX_HWIFS * MAX_DRIVES && idescsi_drives[id]; id++)
; ;
idescsi_setup (drive, scsi, id); idescsi_setup (drive, scsi, id);
MOD_DEC_USE_COUNT; MOD_DEC_USE_COUNT;
return 0; return 0;
failed:
MOD_DEC_USE_COUNT;
return 1;
} }
/* /*
...@@ -608,7 +615,6 @@ static int idescsi_reinit(ide_drive_t *drive) ...@@ -608,7 +615,6 @@ static int idescsi_reinit(ide_drive_t *drive)
int idescsi_init (void) int idescsi_init (void)
{ {
ide_drive_t *drive; ide_drive_t *drive;
byte media[] = {TYPE_DISK, TYPE_TAPE, TYPE_PROCESSOR, TYPE_WORM, TYPE_ROM, TYPE_SCANNER, TYPE_MOD, 255};
int i, failed; int i, failed;
if (idescsi_initialized) if (idescsi_initialized)
...@@ -617,13 +623,11 @@ int idescsi_init (void) ...@@ -617,13 +623,11 @@ 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;
for (i = 0; media[i] != 255; i++) { failed = 0;
failed = 0; while ((drive = ide_scan_devices(NULL, failed++)) != NULL) {
while ((drive = ide_scan_devices (media[i], idescsi_driver.name, NULL, failed++)) != NULL) { if (idescsi_reinit(drive))
if (idescsi_reinit(drive)) continue;
continue; failed--;
failed--;
}
} }
ide_register_module(&idescsi_module); ide_register_module(&idescsi_module);
MOD_DEC_USE_COUNT; MOD_DEC_USE_COUNT;
...@@ -883,18 +887,15 @@ static int __init init_idescsi_module(void) ...@@ -883,18 +887,15 @@ 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; ide_drive_t *drive;
byte media[] = {TYPE_DISK, TYPE_TAPE, TYPE_PROCESSOR, TYPE_WORM, TYPE_ROM, TYPE_SCANNER, TYPE_MOD, 255}; int failed;
int i, failed;
scsi_unregister_host(&idescsi_template); scsi_unregister_host(&idescsi_template);
for (i = 0; media[i] != 255; i++) { failed = 0;
failed = 0; while ((drive = ide_scan_devices(&idescsi_driver, failed)) != NULL)
while ((drive = ide_scan_devices (media[i], idescsi_driver.name, &idescsi_driver, failed)) != NULL) if (idescsi_cleanup (drive)) {
if (idescsi_cleanup (drive)) { printk ("%s: exit_idescsi_module() called while still busy\n", drive->name);
printk ("%s: exit_idescsi_module() called while still busy\n", drive->name); failed++;
failed++; }
}
}
ide_unregister_module(&idescsi_module); ide_unregister_module(&idescsi_module);
} }
......
...@@ -1242,7 +1242,7 @@ int idescsi_init (void); ...@@ -1242,7 +1242,7 @@ int idescsi_init (void);
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 (byte media, const char *name, ide_driver_t *driver, int n); 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