Merge git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb-2.6
[safe/jmp/linux-2.6] / drivers / block / z2ram.c
index 82ddbdd..9114654 100644 (file)
@@ -33,6 +33,7 @@
 #include <linux/module.h>
 #include <linux/blkdev.h>
 #include <linux/bitops.h>
+#include <linux/slab.h>
 
 #include <asm/setup.h>
 #include <asm/amigahw.h>
@@ -44,9 +45,6 @@
 extern int m68k_realnum_memory;
 extern struct mem_info m68k_memory[NUM_MEMINFO];
 
-#define TRUE                  (1)
-#define FALSE                 (0)
-
 #define Z2MINOR_COMBINED      (0)
 #define Z2MINOR_Z2ONLY        (1)
 #define Z2MINOR_CHIPONLY      (2)
@@ -67,21 +65,23 @@ static int current_device   = -1;
 
 static DEFINE_SPINLOCK(z2ram_lock);
 
-static struct block_device_operations z2_fops;
 static struct gendisk *z2ram_gendisk;
 
-static void do_z2_request(request_queue_t *q)
+static void do_z2_request(struct request_queue *q)
 {
        struct request *req;
-       while ((req = elv_next_request(q)) != NULL) {
-               unsigned long start = req->sector << 9;
-               unsigned long len  = req->current_nr_sectors << 9;
+
+       req = blk_fetch_request(q);
+       while (req) {
+               unsigned long start = blk_rq_pos(req) << 9;
+               unsigned long len  = blk_rq_cur_bytes(req);
+               int err = 0;
 
                if (start + len > z2ram_size) {
                        printk( KERN_ERR DEVICE_NAME ": bad access: block=%lu, count=%u\n",
-                               req->sector, req->current_nr_sectors);
-                       end_request(req, 0);
-                       continue;
+                               blk_rq_pos(req), blk_rq_cur_sectors(req));
+                       err = -EIO;
+                       goto done;
                }
                while (len) {
                        unsigned long addr = start & Z2RAM_CHUNKMASK;
@@ -96,7 +96,9 @@ static void do_z2_request(request_queue_t *q)
                        start += size;
                        len -= size;
                }
-               end_request(req, 1);
+       done:
+               if (!__blk_end_request_cur(req, err))
+                       req = blk_fetch_request(q);
        }
 }
 
@@ -140,8 +142,7 @@ get_chipram( void )
     return;
 }
 
-static int
-z2_open( struct inode *inode, struct file *filp )
+static int z2_open(struct block_device *bdev, fmode_t mode)
 {
     int device;
     int max_z2_map = ( Z2RAM_SIZE / Z2RAM_CHUNKSIZE ) *
@@ -150,7 +151,7 @@ z2_open( struct inode *inode, struct file *filp )
        sizeof( z2ram_map[0] );
     int rc = -ENOMEM;
 
-    device = iminor(inode);
+    device = MINOR(bdev->bd_dev);
 
     if ( current_device != -1 && current_device != device )
     {
@@ -302,7 +303,7 @@ err_out:
 }
 
 static int
-z2_release( struct inode *inode, struct file *filp )
+z2_release(struct gendisk *disk, fmode_t mode)
 {
     if ( current_device == -1 )
        return 0;     
@@ -314,7 +315,7 @@ z2_release( struct inode *inode, struct file *filp )
     return 0;
 }
 
-static struct block_device_operations z2_fops =
+static const struct block_device_operations z2_fops =
 {
        .owner          = THIS_MODULE,
        .open           = z2_open,
@@ -329,13 +330,13 @@ static struct kobject *z2_find(dev_t dev, int *part, void *data)
 
 static struct request_queue *z2_queue;
 
-int __init 
+static int __init 
 z2_init(void)
 {
     int ret;
 
     if (!MACH_IS_AMIGA)
-       return -ENXIO;
+       return -ENODEV;
 
     ret = -EBUSY;
     if (register_blkdev(Z2RAM_MAJOR, DEVICE_NAME))
@@ -370,32 +371,11 @@ err:
     return ret;
 }
 
-#if defined(MODULE)
-
-MODULE_LICENSE("GPL");
-
-int
-init_module( void )
-{
-    int error;
-    
-    error = z2_init();
-    if ( error == 0 )
-    {
-       printk( KERN_INFO DEVICE_NAME ": loaded as module\n" );
-    }
-    
-    return error;
-}
-
-void
-cleanup_module( void )
+static void __exit z2_exit(void)
 {
     int i, j;
-    blk_unregister_region(MKDEV(Z2RAM_MAJOR, 0), 256);
-    if ( unregister_blkdev( Z2RAM_MAJOR, DEVICE_NAME ) != 0 )
-       printk( KERN_ERR DEVICE_NAME ": unregister of device failed\n");
-
+    blk_unregister_region(MKDEV(Z2RAM_MAJOR, 0), Z2MINOR_COUNT);
+    unregister_blkdev(Z2RAM_MAJOR, DEVICE_NAME);
     del_gendisk(z2ram_gendisk);
     put_disk(z2ram_gendisk);
     blk_cleanup_queue(z2_queue);
@@ -425,4 +405,7 @@ cleanup_module( void )
 
     return;
 } 
-#endif
+
+module_init(z2_init);
+module_exit(z2_exit);
+MODULE_LICENSE("GPL");