Merge tag 'for-linus' of git://github.com/openrisc/linux
[linux-2.6-microblaze.git] / drivers / scsi / st.c
index c6f1454..9d04929 100644 (file)
@@ -309,13 +309,8 @@ static char * st_incompatible(struct scsi_device* SDp)
 }
 \f
 
-static inline char *tape_name(struct scsi_tape *tape)
-{
-       return tape->disk->disk_name;
-}
-
 #define st_printk(prefix, t, fmt, a...) \
-       sdev_prefix_printk(prefix, (t)->device, tape_name(t), fmt, ##a)
+       sdev_prefix_printk(prefix, (t)->device, (t)->name, fmt, ##a)
 #ifdef DEBUG
 #define DEBC_printk(t, fmt, a...) \
        if (debugging) { st_printk(ST_DEB_MSG, t, fmt, ##a ); }
@@ -363,7 +358,7 @@ static int st_chk_result(struct scsi_tape *STp, struct st_request * SRpnt)
        int result = SRpnt->result;
        u8 scode;
        DEB(const char *stp;)
-       char *name = tape_name(STp);
+       char *name = STp->name;
        struct st_cmdstatus *cmdstatp;
 
        if (!result)
@@ -3499,8 +3494,9 @@ out:
 
 
 /* The ioctl command */
-static long st_ioctl_common(struct file *file, unsigned int cmd_in, void __user *p)
+static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)
 {
+       void __user *p = (void __user *)arg;
        int i, cmd_nr, cmd_type, bt;
        int retval = 0;
        unsigned int blk;
@@ -3820,73 +3816,44 @@ static long st_ioctl_common(struct file *file, unsigned int cmd_in, void __user
                goto out;
        }
        mutex_unlock(&STp->lock);
-       switch (cmd_in) {
-               case SCSI_IOCTL_STOP_UNIT:
-                       /* unload */
-                       retval = scsi_ioctl(STp->device, cmd_in, p);
-                       if (!retval) {
-                               STp->rew_at_close = 0;
-                               STp->ready = ST_NO_TAPE;
-                       }
-                       return retval;
 
-               case SCSI_IOCTL_GET_IDLUN:
-               case SCSI_IOCTL_GET_BUS_NUMBER:
-                       break;
+       switch (cmd_in) {
+       case SG_IO:
+       case SCSI_IOCTL_SEND_COMMAND:
+       case CDROM_SEND_PACKET:
+               if (!capable(CAP_SYS_RAWIO))
+                       return -EPERM;
+       default:
+               break;
+       }
 
-               default:
-                       if ((cmd_in == SG_IO ||
-                            cmd_in == SCSI_IOCTL_SEND_COMMAND ||
-                            cmd_in == CDROM_SEND_PACKET) &&
-                           !capable(CAP_SYS_RAWIO))
-                               i = -EPERM;
-                       else
-                               i = scsi_cmd_ioctl(STp->disk->queue, STp->disk,
-                                                  file->f_mode, cmd_in, p);
-                       if (i != -ENOTTY)
-                               return i;
-                       break;
+       retval = scsi_ioctl(STp->device, NULL, file->f_mode, cmd_in, p);
+       if (!retval && cmd_in == SCSI_IOCTL_STOP_UNIT) {
+               /* unload */
+               STp->rew_at_close = 0;
+               STp->ready = ST_NO_TAPE;
        }
-       return -ENOTTY;
+       return retval;
 
  out:
        mutex_unlock(&STp->lock);
        return retval;
 }
 
-static long st_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)
-{
-       void __user *p = (void __user *)arg;
-       struct scsi_tape *STp = file->private_data;
-       int ret;
-
-       ret = st_ioctl_common(file, cmd_in, p);
-       if (ret != -ENOTTY)
-               return ret;
-
-       return scsi_ioctl(STp->device, cmd_in, p);
-}
-
 #ifdef CONFIG_COMPAT
 static long st_compat_ioctl(struct file *file, unsigned int cmd_in, unsigned long arg)
 {
-       void __user *p = compat_ptr(arg);
-       struct scsi_tape *STp = file->private_data;
-       int ret;
-
        /* argument conversion is handled using put_user_mtpos/put_user_mtget */
        switch (cmd_in) {
        case MTIOCPOS32:
-               return st_ioctl_common(file, MTIOCPOS, p);
+               cmd_in = MTIOCPOS;
+               break;
        case MTIOCGET32:
-               return st_ioctl_common(file, MTIOCGET, p);
+               cmd_in = MTIOCGET;
+               break;
        }
 
-       ret = st_ioctl_common(file, cmd_in, p);
-       if (ret != -ENOTTY)
-               return ret;
-
-       return scsi_compat_ioctl(STp->device, cmd_in, p);
+       return st_ioctl(file, cmd_in, arg);
 }
 #endif
 
@@ -4216,7 +4183,7 @@ static int create_one_cdev(struct scsi_tape *tape, int mode, int rew)
 
        i = mode << (4 - ST_NBR_MODE_BITS);
        snprintf(name, 10, "%s%s%s", rew ? "n" : "",
-                tape->disk->disk_name, st_formats[i]);
+                tape->name, st_formats[i]);
 
        dev = device_create(&st_sysfs_class, &tape->device->sdev_gendev,
                            cdev_devno, &tape->modes[mode], "%s", name);
@@ -4271,7 +4238,6 @@ static void remove_cdevs(struct scsi_tape *tape)
 static int st_probe(struct device *dev)
 {
        struct scsi_device *SDp = to_scsi_device(dev);
-       struct gendisk *disk = NULL;
        struct scsi_tape *tpnt = NULL;
        struct st_modedef *STm;
        struct st_partstat *STps;
@@ -4301,27 +4267,13 @@ static int st_probe(struct device *dev)
                goto out;
        }
 
-       disk = alloc_disk(1);
-       if (!disk) {
-               sdev_printk(KERN_ERR, SDp,
-                           "st: out of memory. Device not attached.\n");
-               goto out_buffer_free;
-       }
-
        tpnt = kzalloc(sizeof(struct scsi_tape), GFP_KERNEL);
        if (tpnt == NULL) {
                sdev_printk(KERN_ERR, SDp,
                            "st: Can't allocate device descriptor.\n");
-               goto out_put_disk;
+               goto out_buffer_free;
        }
        kref_init(&tpnt->kref);
-       tpnt->disk = disk;
-       disk->private_data = &tpnt->driver;
-       /* SCSI tape doesn't register this gendisk via add_disk().  Manually
-        * take queue reference that release_disk() expects. */
-       if (!blk_get_queue(SDp->request_queue))
-               goto out_put_disk;
-       disk->queue = SDp->request_queue;
        tpnt->driver = &st_template;
 
        tpnt->device = SDp;
@@ -4394,10 +4346,10 @@ static int st_probe(struct device *dev)
        idr_preload_end();
        if (error < 0) {
                pr_warn("st: idr allocation failed: %d\n", error);
-               goto out_put_queue;
+               goto out_free_tape;
        }
        tpnt->index = error;
-       sprintf(disk->disk_name, "st%d", tpnt->index);
+       sprintf(tpnt->name, "st%d", tpnt->index);
        tpnt->stats = kzalloc(sizeof(struct scsi_tape_stats), GFP_KERNEL);
        if (tpnt->stats == NULL) {
                sdev_printk(KERN_ERR, SDp,
@@ -4414,9 +4366,9 @@ static int st_probe(struct device *dev)
        scsi_autopm_put_device(SDp);
 
        sdev_printk(KERN_NOTICE, SDp,
-                   "Attached scsi tape %s\n", tape_name(tpnt));
+                   "Attached scsi tape %s\n", tpnt->name);
        sdev_printk(KERN_INFO, SDp, "%s: try direct i/o: %s (alignment %d B)\n",
-                   tape_name(tpnt), tpnt->try_dio ? "yes" : "no",
+                   tpnt->name, tpnt->try_dio ? "yes" : "no",
                    queue_dma_alignment(SDp->request_queue) + 1);
 
        return 0;
@@ -4428,10 +4380,7 @@ out_idr_remove:
        spin_lock(&st_index_lock);
        idr_remove(&st_index_idr, tpnt->index);
        spin_unlock(&st_index_lock);
-out_put_queue:
-       blk_put_queue(disk->queue);
-out_put_disk:
-       put_disk(disk);
+out_free_tape:
        kfree(tpnt);
 out_buffer_free:
        kfree(buffer);
@@ -4470,7 +4419,6 @@ static int st_remove(struct device *dev)
 static void scsi_tape_release(struct kref *kref)
 {
        struct scsi_tape *tpnt = to_scsi_tape(kref);
-       struct gendisk *disk = tpnt->disk;
 
        tpnt->device = NULL;
 
@@ -4480,8 +4428,6 @@ static void scsi_tape_release(struct kref *kref)
                kfree(tpnt->buffer);
        }
 
-       disk->private_data = NULL;
-       put_disk(disk);
        kfree(tpnt->stats);
        kfree(tpnt);
        return;