X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drivers%2Fblock%2Frd.c;h=485aa87e9bcd6069b7c17a72d2fe946a95100db5;hb=97bf2856c6014879bd04983a3e9dfcdac1e7fe85;hp=b3c7f07c16fd8f1629a15e940efcc14d4f9a5670;hpb=c7b5ebbddf7bcd3651947760f423e3783bbe6573;p=linux-2.6.git diff --git a/drivers/block/rd.c b/drivers/block/rd.c index b3c7f07c1..485aa87e9 100644 --- a/drivers/block/rd.c +++ b/drivers/block/rd.c @@ -42,14 +42,13 @@ * and set blk_size for -ENOSPC, Werner Fink , Apr '99 */ -#include #include #include #include #include #include +#include #include -#include #include #include #include @@ -60,15 +59,12 @@ #include -/* The RAM disk size is now a parameter */ -#define NUM_RAMDISKS 16 /* This cannot be overridden (yet) */ - /* Various static variables go here. Most are used only in the RAM disk code. */ -static struct gendisk *rd_disks[NUM_RAMDISKS]; -static struct block_device *rd_bdev[NUM_RAMDISKS];/* Protected device data */ -static struct request_queue *rd_queue[NUM_RAMDISKS]; +static struct gendisk *rd_disks[CONFIG_BLK_DEV_RAM_COUNT]; +static struct block_device *rd_bdev[CONFIG_BLK_DEV_RAM_COUNT];/* Protected device data */ +static struct request_queue *rd_queue[CONFIG_BLK_DEV_RAM_COUNT]; /* * Parameters for the boot-loading of the RAM disk. These are set by @@ -88,7 +84,7 @@ int rd_size = CONFIG_BLK_DEV_RAM_SIZE; /* Size of the RAM disks */ * behaviour. The default is still BLOCK_SIZE (needed by rd_load_image that * supposes the filesystem in the image uses a BLOCK_SIZE blocksize). */ -int rd_blocksize = BLOCK_SIZE; /* blocksize of the RAM disks */ +static int rd_blocksize = CONFIG_BLK_DEV_RAM_BLOCKSIZE; /* * Copyright (C) 2000 Linus Torvalds. @@ -156,7 +152,7 @@ static int ramdisk_commit_write(struct file *file, struct page *page, /* * ->writepage to the the blockdev's mapping has to redirty the page so that the - * VM doesn't go and steal it. We return WRITEPAGE_ACTIVATE so that the VM + * VM doesn't go and steal it. We return AOP_WRITEPAGE_ACTIVATE so that the VM * won't try to (pointlessly) write the page again for a while. * * Really, these pages should not be on the LRU at all. @@ -167,7 +163,7 @@ static int ramdisk_writepage(struct page *page, struct writeback_control *wbc) make_page_uptodate(page); SetPageDirty(page); if (wbc->for_reclaim) - return WRITEPAGE_ACTIVATE; + return AOP_WRITEPAGE_ACTIVATE; unlock_page(page); return 0; } @@ -188,11 +184,12 @@ static int ramdisk_writepages(struct address_space *mapping, */ static int ramdisk_set_page_dirty(struct page *page) { - SetPageDirty(page); + if (!TestSetPageDirty(page)) + return 1; return 0; } -static struct address_space_operations ramdisk_aops = { +static const struct address_space_operations ramdisk_aops = { .readpage = ramdisk_readpage, .prepare_write = ramdisk_prepare_write, .commit_write = ramdisk_commit_write, @@ -312,12 +309,12 @@ static int rd_ioctl(struct inode *inode, struct file *file, * cache */ error = -EBUSY; - down(&bdev->bd_sem); + mutex_lock(&bdev->bd_mutex); if (bdev->bd_openers <= 2) { truncate_inode_pages(bdev->bd_inode->i_mapping, 0); error = 0; } - up(&bdev->bd_sem); + mutex_unlock(&bdev->bd_mutex); return error; } @@ -327,7 +324,7 @@ static int rd_ioctl(struct inode *inode, struct file *file, */ static struct backing_dev_info rd_backing_dev_info = { .ra_pages = 0, /* No readahead */ - .memory_backed = 1, /* Does not contribute to dirty memory */ + .capabilities = BDI_CAP_NO_ACCT_DIRTY | BDI_CAP_NO_WRITEBACK | BDI_CAP_MAP_COPY, .unplug_io_fn = default_unplug_io_fn, }; @@ -338,7 +335,7 @@ static struct backing_dev_info rd_backing_dev_info = { */ static struct backing_dev_info rd_file_backing_dev_info = { .ra_pages = 0, /* No readahead */ - .memory_backed = 0, /* Does contribute to dirty memory */ + .capabilities = BDI_CAP_MAP_COPY, /* Does contribute to dirty memory */ .unplug_io_fn = default_unplug_io_fn, }; @@ -350,7 +347,7 @@ static int rd_open(struct inode *inode, struct file *filp) struct block_device *bdev = inode->i_bdev; struct address_space *mapping; unsigned bsize; - int gfp_mask; + gfp_t gfp_mask; inode = igrab(bdev->bd_inode); rd_bdev[unit] = bdev; @@ -402,7 +399,7 @@ static void __exit rd_cleanup(void) { int i; - for (i = 0; i < NUM_RAMDISKS; i++) { + for (i = 0; i < CONFIG_BLK_DEV_RAM_COUNT; i++) { struct block_device *bdev = rd_bdev[i]; rd_bdev[i] = NULL; if (bdev) { @@ -413,7 +410,6 @@ static void __exit rd_cleanup(void) put_disk(rd_disks[i]); blk_cleanup_queue(rd_queue[i]); } - devfs_remove("rd"); unregister_blkdev(RAMDISK_MAJOR, "ramdisk"); } @@ -432,10 +428,16 @@ static int __init rd_init(void) rd_blocksize = BLOCK_SIZE; } - for (i = 0; i < NUM_RAMDISKS; i++) { + for (i = 0; i < CONFIG_BLK_DEV_RAM_COUNT; i++) { rd_disks[i] = alloc_disk(1); if (!rd_disks[i]) goto out; + + rd_queue[i] = blk_alloc_queue(GFP_KERNEL); + if (!rd_queue[i]) { + put_disk(rd_disks[i]); + goto out; + } } if (register_blkdev(RAMDISK_MAJOR, "ramdisk")) { @@ -443,15 +445,9 @@ static int __init rd_init(void) goto out; } - devfs_mk_dir("rd"); - - for (i = 0; i < NUM_RAMDISKS; i++) { + for (i = 0; i < CONFIG_BLK_DEV_RAM_COUNT; i++) { struct gendisk *disk = rd_disks[i]; - rd_queue[i] = blk_alloc_queue(GFP_KERNEL); - if (!rd_queue[i]) - goto out_queue; - blk_queue_make_request(rd_queue[i], &rd_make_request); blk_queue_hardsect_size(rd_queue[i], rd_blocksize); @@ -462,7 +458,6 @@ static int __init rd_init(void) disk->queue = rd_queue[i]; disk->flags |= GENHD_FL_SUPPRESS_PARTITION_INFO; sprintf(disk->disk_name, "ram%d", i); - sprintf(disk->devfs_name, "rd/%d", i); set_capacity(disk, rd_size * 2); add_disk(rd_disks[i]); } @@ -470,11 +465,9 @@ static int __init rd_init(void) /* rd_size is given in kB */ printk("RAMDISK driver initialized: " "%d RAM disks of %dK size %d blocksize\n", - NUM_RAMDISKS, rd_size, rd_blocksize); + CONFIG_BLK_DEV_RAM_COUNT, rd_size, rd_blocksize); return 0; -out_queue: - unregister_blkdev(RAMDISK_MAJOR, "ramdisk"); out: while (i--) { put_disk(rd_disks[i]); @@ -508,9 +501,10 @@ __setup("ramdisk_blocksize=", ramdisk_blocksize); #endif /* options - modular */ -MODULE_PARM (rd_size, "1i"); +module_param(rd_size, int, 0); MODULE_PARM_DESC(rd_size, "Size of each RAM disk in kbytes."); -MODULE_PARM (rd_blocksize, "i"); +module_param(rd_blocksize, int, 0); MODULE_PARM_DESC(rd_blocksize, "Blocksize of each RAM disk in bytes."); +MODULE_ALIAS_BLOCKDEV_MAJOR(RAMDISK_MAJOR); MODULE_LICENSE("GPL");