Re: IDE driver with CD-RWs (ide-scsi)

Gadi Oxman (gadio@netvision.net.il)
Thu, 17 Dec 1998 08:28:59 +0200 (IST)


Andrew,

This patch implements the original intention of the code, which
was never actually completely implemented (i.e. that echo "driver_name"
> /proc/ide/hdx/driver would really allow us to switch between
ide-cd/ide-tape and ide-scsi in run-time).

The major problem is that while the SCSI subsystem is using the
drive, we must hold DRIVER(drive)->busy, or the IDE subsystem will
be free to just unlink the ide-scsi driver from below the SCSI
subsystem even if it is currently in use.

That's the reason for the DRIVER(drive)->busy++ in idescsi_setup(),
and performing DRIVER(driver)->busy-- only in idescsi_release() in
the original code.

We need to find a way to unlink just a single SCSI drive from the
SCSI subsystem / SCSI host adapter if it's not currently used.

Another option might be to map each ATAPI drive to a different SCSI host
adapter and then try to unlink the host adapter, or perhaps just to try
to unlink the hostadapter with the current mapping and hope that all the
drives on it are unused, but in any case we have to abort the driver change
attempt if the host adapter is currently in use by the SCSI subsystem.

Gadi

On Wed, 16 Dec 1998, Andrew T. Veliath wrote:

> Hello,
>
> A few days ago I picked up one of these cheap ACER CD-RWs. I didn't
> want to use IDE SCSI emulation for my DVD-ROM, and I noticed the
> hdd=ide_scsi option was no longer an option and echo "ide-scsi" >
> /proc/ide/hdd/driver also didn't appear to work. My /dev/hdc is a
> DVD-ROM.
>
> ``echo "ide-scsi" > /proc/ide/hdx/driver'' or ``echo "ide-cdrom" >
> /proc/ide/hdx/driver'' should work, even if the ide-cd and ide-scsi
> modules aren't loaded yet (it doesn't NULL driver_req like it used to
> after writing to /proc). This seems useful if ide-scsi is set to the
> scsi_hostadapter.
>
> With the following changes, I can do the following things, since I
> have ide.c compiled into the kernel, and ide-cd.c and ide-scsi.c as
> modular. Of course, I will leave it to the maintainers to fix the
> deficiencies in this patch :-). I don't think it will change anything
> for a non-modular setup.
>
> 1.
> echo "ide-scsi" > /proc/ide/hdd/driver
> modprobe ide-cd
> modprobe ide-scsi
>
> or 2.
>
> modprobe ide-cd
> modprobe ide-scsi
> echo "ide-scsi" > /proc/ide/hdd/driver
>
> With the same effect in that cat hdd/driver will show ide-cdrom and
> cat hdc/driver will show ide-scsi. Patch is against 2.1.131ac11.
>
> diff -ur /usr/src/orig/linux/drivers/block/ide-proc.c linux/drivers/block/ide-proc.c
> --- /usr/src/orig/linux/drivers/block/ide-proc.c Wed May 6 17:42:53 1998
> +++ linux/drivers/block/ide-proc.c Mon Dec 14 16:33:35 1998
> @@ -551,10 +551,26 @@
> (struct file *file, const char *buffer, unsigned long count, void *data)
> {
> ide_drive_t *drive = (ide_drive_t *) data;
> + char name[MAX_LEN + 1];
> + int n;
>
> if (!capable(CAP_SYS_ADMIN))
> return -EACCES;
> - if (ide_replace_subdriver(drive, buffer))
> + /*
> + * Skip over leading whitespace
> + */
> + while (count && isspace(*buffer)) {
> + --count;
> + ++buffer;
> + }
> + n = IDE_MIN(count, MAX_LEN);
> + strncpy(name, buffer, n);
> + name[n] = 0;
> + n = strlen(name);
> + if (name[n - 1] == '\n')
> + name[n - 1] = 0;
> +
> + if (ide_replace_subdriver(drive, name))
> return -EINVAL;
> return count;
> }
> diff -ur /usr/src/orig/linux/drivers/block/ide.c linux/drivers/block/ide.c
> --- /usr/src/orig/linux/drivers/block/ide.c Mon Dec 14 13:49:20 1998
> +++ linux/drivers/block/ide.c Mon Dec 14 16:38:43 1998
> @@ -1651,9 +1651,8 @@
> goto abort;
> strncpy(drive->driver_req, driver, 9);
> ide_init_module(IDE_DRIVER_MODULE);
> - drive->driver_req[0] = 0;
> - ide_init_module(IDE_DRIVER_MODULE);
> - if (DRIVER(drive) && !strcmp(DRIVER(drive)->name, driver))
> + if (DRIVER(drive) &&
> + !strncmp(DRIVER(drive)->name, drive->driver_req, 9))
> return 0;
> abort:
> return 1;
> diff -ur /usr/src/orig/linux/drivers/scsi/ide-scsi.c linux/drivers/scsi/ide-scsi.c
> --- /usr/src/orig/linux/drivers/scsi/ide-scsi.c Sun Oct 4 16:30:27 1998
> +++ linux/drivers/scsi/ide-scsi.c Mon Dec 14 17:35:40 1998
> @@ -496,7 +496,6 @@
> */
> static void idescsi_setup (ide_drive_t *drive, idescsi_scsi_t *scsi, int id)
> {
> - DRIVER(drive)->busy++;
> idescsi_drives[id] = drive;
> drive->driver_data = scsi;
> drive->ready_stat = 0;
> @@ -556,6 +555,10 @@
>
> static struct proc_dir_entry idescsi_proc_dir = {PROC_SCSI_IDESCSI, 8, "ide-scsi", S_IFDIR | S_IRUGO | S_IXUGO, 2};
>
> +#ifdef MODULE
> +Scsi_Host_Template idescsi_template = IDESCSI;
> +#endif
> +
> /*
> * idescsi_init will register the driver for each scsi.
> */
> @@ -565,10 +568,16 @@
> idescsi_scsi_t *scsi;
> byte media[] = {TYPE_DISK, TYPE_TAPE, TYPE_PROCESSOR, TYPE_WORM, TYPE_ROM, TYPE_SCANNER, TYPE_MOD, 255};
> int i, failed, id;
> -
> - if (idescsi_initialized)
> +
> + if (idescsi_initialized) {
> +#ifdef MODULE
> + scsi_unregister_module (MODULE_SCSI_HA, &idescsi_template);
> +#else
> return 0;
> +#endif
> + }
> idescsi_initialized = 1;
> +
> for (i = 0; i < MAX_HWIFS * MAX_DRIVES; i++)
> idescsi_drives[i] = NULL;
> MOD_INC_USE_COUNT;
> @@ -584,12 +593,17 @@
> kfree (scsi);
> continue;
> }
> + DRIVER(drive)->busy++;
> for (id = 0; id < MAX_HWIFS * MAX_DRIVES && idescsi_drives[id]; id++);
> idescsi_setup (drive, scsi, id);
> + DRIVER(drive)->busy--;
> failed--;
> }
> }
> ide_register_module(&idescsi_module);
> +#ifdef MODULE
> + scsi_register_module (MODULE_SCSI_HA, &idescsi_template);
> +#endif
> MOD_DEC_USE_COUNT;
> return 0;
> }
> @@ -609,14 +623,6 @@
>
> int idescsi_release (struct Scsi_Host *host)
> {
> - ide_drive_t *drive;
> - int id;
> -
> - for (id = 0; id < MAX_HWIFS * MAX_DRIVES; id++) {
> - drive = idescsi_drives[id];
> - if (drive)
> - DRIVER(drive)->busy--;
> - }
> return 0;
> }
>
> @@ -805,8 +811,6 @@
> }
>
> #ifdef MODULE
> -Scsi_Host_Template idescsi_template = IDESCSI;
> -
> int init_module (void)
> {
> idescsi_init ();
>
> -
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.rutgers.edu
> Please read the FAQ at http://www.tux.org/lkml/
>
>

-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.rutgers.edu
Please read the FAQ at http://www.tux.org/lkml/