Commit f53197de authored by Alexander Viro's avatar Alexander Viro Committed by Linus Torvalds

[PATCH] stram/z2ram switched to alloc_disk()

parent 2b6df45e
...@@ -1046,13 +1046,7 @@ static struct block_device_operations stram_fops = { ...@@ -1046,13 +1046,7 @@ static struct block_device_operations stram_fops = {
.release = stram_release, .release = stram_release,
}; };
static struct gendisk stram_disk = { static struct gendisk *stram_disk;
.major = STRAM_MAJOR,
.first_minor = STRAM_MINOR,
.minor_shift = 0,
.fops = &stram_fops,
.disk_name = "stram"
};
int __init stram_device_init(void) int __init stram_device_init(void)
{ {
...@@ -1063,15 +1057,24 @@ int __init stram_device_init(void) ...@@ -1063,15 +1057,24 @@ int __init stram_device_init(void)
if (!max_swap_size) if (!max_swap_size)
/* swapping not enabled */ /* swapping not enabled */
return -ENXIO; return -ENXIO;
stram_disk = alloc_disk();
if (!stram_disk)
return -ENOMEM;
if (register_blkdev( STRAM_MAJOR, "stram", &stram_fops)) { if (register_blkdev( STRAM_MAJOR, "stram", &stram_fops)) {
printk(KERN_ERR "stram: Unable to get major %d\n", STRAM_MAJOR); printk(KERN_ERR "stram: Unable to get major %d\n", STRAM_MAJOR);
put_disk(stram_disk);
return -ENXIO; return -ENXIO;
} }
blk_init_queue(BLK_DEFAULT_QUEUE(STRAM_MAJOR), do_stram_request); blk_init_queue(BLK_DEFAULT_QUEUE(STRAM_MAJOR), do_stram_request);
set_capacity(&stram_disk, (swap_end - swap_start)/512); stram_disk->major = STRAM_MAJOR;
add_disk(&stram_disk); stram_disk->first_minor = STRAM_MINOR;
stram_disk->minor_shift = 0;
stram_disk->fops = &stram_fops;
sprintf(stram_disk->disk_name, "stram");
set_capacity(stram_disk, (swap_end - swap_start)/512);
add_disk(stram_disk);
return 0; return 0;
} }
......
...@@ -71,13 +71,7 @@ static int current_device = -1; ...@@ -71,13 +71,7 @@ static int current_device = -1;
static spinlock_t z2ram_lock = SPIN_LOCK_UNLOCKED; static spinlock_t z2ram_lock = SPIN_LOCK_UNLOCKED;
static struct block_device_operations z2_fops; static struct block_device_operations z2_fops;
static struct gendisk z2ram_gendisk = { static struct gendisk *z2ram_gendisk;
.major = MAJOR_NR,
.first_minor = 0,
.minor_shift = 0,
.fops = &z2_fops,
.disk_name = "z2ram"
};
static void static void
do_z2_request( request_queue_t * q ) do_z2_request( request_queue_t * q )
...@@ -320,7 +314,7 @@ z2_open( struct inode *inode, struct file *filp ) ...@@ -320,7 +314,7 @@ z2_open( struct inode *inode, struct file *filp )
current_device = device; current_device = device;
z2ram_size <<= Z2RAM_CHUNKSHIFT; z2ram_size <<= Z2RAM_CHUNKSHIFT;
set_capacity(&z2ram_gendisk, z2ram_size >> 9; set_capacity(z2ram_gendisk, z2ram_size >> 9;
} }
return 0; return 0;
...@@ -355,7 +349,7 @@ static struct gendisk *z2_find(int minor) ...@@ -355,7 +349,7 @@ static struct gendisk *z2_find(int minor)
{ {
if (minor > Z2MINOR_COUNT) if (minor > Z2MINOR_COUNT)
return NULL; return NULL;
return &z2ram_gendisk; return z2ram_gendisk;
} }
int __init int __init
...@@ -371,9 +365,19 @@ z2_init( void ) ...@@ -371,9 +365,19 @@ z2_init( void )
MAJOR_NR ); MAJOR_NR );
return -EBUSY; return -EBUSY;
} }
z2ram_gendisk = alloc_disk();
if (!z2ram_gendisk) {
unregister_blkdev( MAJOR_NR, DEVICE_NAME );
return -ENOMEM;
}
z2ram_gendisk->major = MAJOR_NR;
z2ram_gendisk->first_minor = 0;
z2ram_gendisk->minor_shift = 0;
z2ram_gendisk->fops = &z2_fops;
sprintf(z2ram_gendisk->disk_name, "z2ram");
blk_init_queue(BLK_DEFAULT_QUEUE(MAJOR_NR), do_z2_request, &z2ram_lock); blk_init_queue(BLK_DEFAULT_QUEUE(MAJOR_NR), do_z2_request, &z2ram_lock);
add_disk(&z2ram_gendisk); add_disk(z2ram_gendisk);
blk_set_probe(MAJOR_NR, z2_find); blk_set_probe(MAJOR_NR, z2_find);
return 0; return 0;
...@@ -406,7 +410,8 @@ cleanup_module( void ) ...@@ -406,7 +410,8 @@ cleanup_module( void )
if ( unregister_blkdev( MAJOR_NR, DEVICE_NAME ) != 0 ) if ( unregister_blkdev( MAJOR_NR, DEVICE_NAME ) != 0 )
printk( KERN_ERR DEVICE_NAME ": unregister of device failed\n"); printk( KERN_ERR DEVICE_NAME ": unregister of device failed\n");
del_gendisk(&z2ram_gendisk); del_gendisk(z2ram_gendisk);
put_disk(z2ram_gendisk);
blk_cleanup_queue(BLK_DEFAULT_QUEUE(MAJOR_NR)); blk_cleanup_queue(BLK_DEFAULT_QUEUE(MAJOR_NR));
if ( current_device != -1 ) if ( current_device != -1 )
......
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