Major numbers cleanup
authorvlnb <vlnb@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Fri, 23 Oct 2009 16:52:26 +0000 (16:52 +0000)
committervlnb <vlnb@d57e44dd-8a1f-0410-8b47-8ef2f437770f>
Fri, 23 Oct 2009 16:52:26 +0000 (16:52 +0000)
git-svn-id: https://scst.svn.sourceforge.net/svnroot/scst/trunk@1258 d57e44dd-8a1f-0410-8b47-8ef2f437770f

scst/include/scst.h
scst/src/dev_handlers/scst_user.c
scst/src/scst_main.c
scst/src/scst_priv.h

index 71d881d..7917c8d 100644 (file)
@@ -1719,8 +1719,10 @@ struct scst_device {
        /* Used for storage of dev handler private stuff */
        void *dh_priv;
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
        /* Used to translate SCSI's cmd to SCST's cmd */
        struct gendisk *rq_disk;
+#endif
 
        /* Corresponding real SCSI device, could be NULL for virtual devices */
        struct scsi_device *scsi_dev;
index 75a3903..ec05a31 100644 (file)
@@ -35,7 +35,6 @@
  for details."
 #endif
 
-#define DEV_USER_MAJOR                 237
 #define DEV_USER_CMD_HASH_ORDER                6
 #define DEV_USER_ATTACH_TIMEOUT                (5*HZ)
 
@@ -232,6 +231,8 @@ static struct scst_dev_type dev_user_devtype = {
 #endif
 };
 
+static int dev_user_major;
+
 static struct class *dev_user_sysfs_class;
 
 static DEFINE_SPINLOCK(dev_list_lock);
@@ -3616,23 +3617,23 @@ static int __init init_scst_user(void)
 #endif
        }
 
-       res = register_chrdev(DEV_USER_MAJOR, DEV_USER_NAME, &dev_user_fops);
-       if (res) {
-               PRINT_ERROR("Unable to get major %d for SCSI tapes",
-                           DEV_USER_MAJOR);
+       dev_user_major = register_chrdev(0, DEV_USER_NAME, &dev_user_fops);
+       if (dev_user_major < 0) {
+               PRINT_ERROR("register_chrdev() failed: %d", res);
+               res = dev_user_major;
                goto out_class;
        }
 
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 21)
        class_member = class_device_create(dev_user_sysfs_class, NULL,
-                               MKDEV(DEV_USER_MAJOR, 0), NULL, DEV_USER_NAME);
+                               MKDEV(dev_user_major, 0), NULL, DEV_USER_NAME);
        if (IS_ERR(class_member)) {
                res = PTR_ERR(class_member);
                goto out_chrdev;
        }
 #else
        dev = device_create(dev_user_sysfs_class, NULL,
-                           MKDEV(DEV_USER_MAJOR, 0),
+                           MKDEV(dev_user_major, 0),
 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 27)
                                NULL,
 #endif
@@ -3657,13 +3658,13 @@ out:
 
 out_dev:
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 21)
-       class_device_destroy(dev_user_sysfs_class, MKDEV(DEV_USER_MAJOR, 0));
+       class_device_destroy(dev_user_sysfs_class, MKDEV(dev_user_major, 0));
 #else
-       device_destroy(dev_user_sysfs_class, MKDEV(DEV_USER_MAJOR, 0));
+       device_destroy(dev_user_sysfs_class, MKDEV(dev_user_major, 0));
 #endif
 
 out_chrdev:
-       unregister_chrdev(DEV_USER_MAJOR, DEV_USER_NAME);
+       unregister_chrdev(dev_user_major, DEV_USER_NAME);
 
 out_class:
        class_destroy(dev_user_sysfs_class);
@@ -3694,11 +3695,11 @@ static void __exit exit_scst_user(void)
        if (rc < 0)
                TRACE_MGMT_DBG("kthread_stop() failed: %d", rc);
 
-       unregister_chrdev(DEV_USER_MAJOR, DEV_USER_NAME);
+       unregister_chrdev(dev_user_major, DEV_USER_NAME);
 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 21)
-       class_device_destroy(dev_user_sysfs_class, MKDEV(DEV_USER_MAJOR, 0));
+       class_device_destroy(dev_user_sysfs_class, MKDEV(dev_user_major, 0));
 #else
-       device_destroy(dev_user_sysfs_class, MKDEV(DEV_USER_MAJOR, 0));
+       device_destroy(dev_user_sysfs_class, MKDEV(dev_user_major, 0));
 #endif
        class_destroy(dev_user_sysfs_class);
 
@@ -3719,6 +3720,5 @@ module_exit(exit_scst_user);
 
 MODULE_AUTHOR("Vladislav Bolkhovitin");
 MODULE_LICENSE("GPL");
-MODULE_DESCRIPTION("Virtual user space device handler for SCST");
+MODULE_DESCRIPTION("User space device handler for SCST");
 MODULE_VERSION(SCST_VERSION_STRING);
-MODULE_ALIAS_CHARDEV_MAJOR(DEV_USER_MAJOR);
index 9a6eb7d..515c7a1 100644 (file)
@@ -749,6 +749,7 @@ static int scst_register_device(struct scsi_device *scsidp)
        snprintf(dev->virt_name, 50, "%d:%d:%d:%d", scsidp->host->host_no,
                scsidp->channel, scsidp->id, scsidp->lun);
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
        dev->rq_disk = alloc_disk(1);
        if (dev->rq_disk == NULL) {
                PRINT_ERROR("Unable to alloc disk object for device %s",
@@ -758,6 +759,7 @@ static int scst_register_device(struct scsi_device *scsidp)
                goto out_free_dev;
        }
        dev->rq_disk->major = SCST_MAJOR;
+#endif
 
        dev->scsi_dev = scsidp;
 
@@ -798,7 +800,9 @@ out_err:
 
 out_free:
        list_del(&dev->dev_list_entry);
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
        put_disk(dev->rq_disk);
+#endif
 
 out_free_dev:
        scst_device_sysfs_put(dev);
@@ -836,7 +840,10 @@ static void scst_unregister_device(struct scsi_device *scsidp)
 
        scst_assign_dev_handler(dev, &scst_null_devtype);
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
        put_disk(dev->rq_disk);
+#endif
+
        scst_device_sysfs_put(dev);
 
        PRINT_INFO("Detached from scsi%d, channel %d, id %d, lun %d, type %d",
index 9c92ea4..d2bd953 100644 (file)
@@ -39,7 +39,9 @@
 void sgv_pool_destroy(struct sgv_pool *pool);
 #endif
 
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
 #define SCST_MAJOR              177
+#endif
 
 #define TRACE_RTRY              0x80000000
 #define TRACE_SCSI_SERIALIZING  0x40000000