Commit 8b5f47aa authored by Andrew Morton's avatar Andrew Morton Committed by David S. Miller

[PATCH] ramdisk cleanup

Fairly pointless coding-style cleanups which I've been sitting on for ages.
The ramdisk driver is still buggy: it drops pagecache when unmounted.  I
still need to fix this.

Apparently it also displays data corruption under load even when not
unmounted.
parent 06d1514e
/* /*
* ramdisk.c - Multiple RAM disk driver - gzip-loading version - v. 0.8 beta. * ramdisk.c - Multiple RAM disk driver - gzip-loading version - v. 0.8 beta.
* *
* (C) Chad Page, Theodore Ts'o, et. al, 1995. * (C) Chad Page, Theodore Ts'o, et. al, 1995.
* *
* This RAM disk is designed to have filesystems created on it and mounted * This RAM disk is designed to have filesystems created on it and mounted
* just like a regular floppy disk. * just like a regular floppy disk.
* *
* It also does something suggested by Linus: use the buffer cache as the * It also does something suggested by Linus: use the buffer cache as the
* RAM disk data. This makes it possible to dynamically allocate the RAM disk * RAM disk data. This makes it possible to dynamically allocate the RAM disk
* buffer - with some consequences I have to deal with as I write this. * buffer - with some consequences I have to deal with as I write this.
* *
* This code is based on the original ramdisk.c, written mostly by * This code is based on the original ramdisk.c, written mostly by
* Theodore Ts'o (TYT) in 1991. The code was largely rewritten by * Theodore Ts'o (TYT) in 1991. The code was largely rewritten by
* Chad Page to use the buffer cache to store the RAM disk data in * Chad Page to use the buffer cache to store the RAM disk data in
...@@ -33,7 +33,7 @@ ...@@ -33,7 +33,7 @@
* *
* Added initrd: Werner Almesberger & Hans Lermen, Feb '96 * Added initrd: Werner Almesberger & Hans Lermen, Feb '96
* *
* 4/25/96 : Made RAM disk size a parameter (default is now 4 MB) * 4/25/96 : Made RAM disk size a parameter (default is now 4 MB)
* - Chad Page * - Chad Page
* *
* Add support for fs images split across >1 disk, Paul Gortmaker, Mar '98 * Add support for fs images split across >1 disk, Paul Gortmaker, Mar '98
...@@ -60,7 +60,7 @@ ...@@ -60,7 +60,7 @@
#include <asm/uaccess.h> #include <asm/uaccess.h>
/* The RAM disk size is now a parameter */ /* The RAM disk size is now a parameter */
#define NUM_RAMDISKS 16 /* This cannot be overridden (yet) */ #define NUM_RAMDISKS 16 /* This cannot be overridden (yet) */
/* Various static variables go here. Most are used only in the RAM disk code. /* Various static variables go here. Most are used only in the RAM disk code.
*/ */
...@@ -73,7 +73,7 @@ static struct request_queue *rd_queue[NUM_RAMDISKS]; ...@@ -73,7 +73,7 @@ static struct request_queue *rd_queue[NUM_RAMDISKS];
* Parameters for the boot-loading of the RAM disk. These are set by * Parameters for the boot-loading of the RAM disk. These are set by
* init/main.c (from arguments to the kernel command line) or from the * init/main.c (from arguments to the kernel command line) or from the
* architecture-specific setup routine (from the stored boot sector * architecture-specific setup routine (from the stored boot sector
* information). * information).
*/ */
int rd_size = CONFIG_BLK_DEV_RAM_SIZE; /* Size of the RAM disks */ int rd_size = CONFIG_BLK_DEV_RAM_SIZE; /* Size of the RAM disks */
/* /*
...@@ -94,7 +94,7 @@ int rd_blocksize = BLOCK_SIZE; /* blocksize of the RAM disks */ ...@@ -94,7 +94,7 @@ int rd_blocksize = BLOCK_SIZE; /* blocksize of the RAM disks */
* 2000 Transmeta Corp. * 2000 Transmeta Corp.
* aops copied from ramfs. * aops copied from ramfs.
*/ */
static int ramdisk_readpage(struct file *file, struct page * page) static int ramdisk_readpage(struct file *file, struct page *page)
{ {
if (!PageUptodate(page)) { if (!PageUptodate(page)) {
void *kaddr = kmap_atomic(page, KM_USER0); void *kaddr = kmap_atomic(page, KM_USER0);
...@@ -108,7 +108,8 @@ static int ramdisk_readpage(struct file *file, struct page * page) ...@@ -108,7 +108,8 @@ static int ramdisk_readpage(struct file *file, struct page * page)
return 0; return 0;
} }
static int ramdisk_prepare_write(struct file *file, struct page *page, unsigned offset, unsigned to) static int ramdisk_prepare_write(struct file *file, struct page *page,
unsigned offset, unsigned to)
{ {
if (!PageUptodate(page)) { if (!PageUptodate(page)) {
void *kaddr = kmap_atomic(page, KM_USER0); void *kaddr = kmap_atomic(page, KM_USER0);
...@@ -122,7 +123,8 @@ static int ramdisk_prepare_write(struct file *file, struct page *page, unsigned ...@@ -122,7 +123,8 @@ static int ramdisk_prepare_write(struct file *file, struct page *page, unsigned
return 0; return 0;
} }
static int ramdisk_commit_write(struct file *file, struct page *page, unsigned offset, unsigned to) static int ramdisk_commit_write(struct file *file, struct page *page,
unsigned offset, unsigned to)
{ {
return 0; return 0;
} }
...@@ -212,7 +214,7 @@ static int rd_blkdev_pagecache_IO(int rw, struct bio_vec *vec, sector_t sector, ...@@ -212,7 +214,7 @@ static int rd_blkdev_pagecache_IO(int rw, struct bio_vec *vec, sector_t sector,
* 19-JAN-1998 Richard Gooch <rgooch@atnf.csiro.au> Added devfs support * 19-JAN-1998 Richard Gooch <rgooch@atnf.csiro.au> Added devfs support
* *
*/ */
static int rd_make_request(request_queue_t * q, struct bio *bio) static int rd_make_request(request_queue_t *q, struct bio *bio)
{ {
struct block_device *bdev = bio->bi_bdev; struct block_device *bdev = bio->bi_bdev;
struct address_space * mapping = bdev->bd_inode->i_mapping; struct address_space * mapping = bdev->bd_inode->i_mapping;
...@@ -242,7 +244,8 @@ static int rd_make_request(request_queue_t * q, struct bio *bio) ...@@ -242,7 +244,8 @@ static int rd_make_request(request_queue_t * q, struct bio *bio)
return 0; return 0;
} }
static int rd_ioctl(struct inode *inode, struct file *file, unsigned int cmd, unsigned long arg) static int rd_ioctl(struct inode *inode, struct file *file,
unsigned int cmd, unsigned long arg)
{ {
int error; int error;
struct block_device *bdev = inode->i_bdev; struct block_device *bdev = inode->i_bdev;
...@@ -250,9 +253,11 @@ static int rd_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un ...@@ -250,9 +253,11 @@ static int rd_ioctl(struct inode *inode, struct file *file, unsigned int cmd, un
if (cmd != BLKFLSBUF) if (cmd != BLKFLSBUF)
return -EINVAL; return -EINVAL;
/* special: we want to release the ramdisk memory, /*
it's not like with the other blockdevices where * special: we want to release the ramdisk memory, it's not like with
this ioctl only flushes away the buffer cache. */ * the other blockdevices where this ioctl only flushes away the buffer
* cache
*/
error = -EBUSY; error = -EBUSY;
down(&bdev->bd_sem); down(&bdev->bd_sem);
if (bdev->bd_openers <= 2) { if (bdev->bd_openers <= 2) {
...@@ -268,7 +273,7 @@ static struct backing_dev_info rd_backing_dev_info = { ...@@ -268,7 +273,7 @@ static struct backing_dev_info rd_backing_dev_info = {
.memory_backed = 1, /* Does not contribute to dirty memory */ .memory_backed = 1, /* Does not contribute to dirty memory */
}; };
static int rd_open(struct inode * inode, struct file * filp) static int rd_open(struct inode *inode, struct file *filp)
{ {
unsigned unit = iminor(inode); unsigned unit = iminor(inode);
...@@ -295,12 +300,14 @@ static struct block_device_operations rd_bd_op = { ...@@ -295,12 +300,14 @@ static struct block_device_operations rd_bd_op = {
.ioctl = rd_ioctl, .ioctl = rd_ioctl,
}; };
/* Before freeing the module, invalidate all of the protected buffers! */ /*
static void __exit rd_cleanup (void) * Before freeing the module, invalidate all of the protected buffers!
*/
static void __exit rd_cleanup(void)
{ {
int i; int i;
for (i = 0 ; i < NUM_RAMDISKS; i++) { for (i = 0; i < NUM_RAMDISKS; i++) {
struct block_device *bdev = rd_bdev[i]; struct block_device *bdev = rd_bdev[i];
rd_bdev[i] = NULL; rd_bdev[i] = NULL;
if (bdev) { if (bdev) {
...@@ -311,17 +318,19 @@ static void __exit rd_cleanup (void) ...@@ -311,17 +318,19 @@ static void __exit rd_cleanup (void)
put_disk(rd_disks[i]); put_disk(rd_disks[i]);
} }
devfs_remove("rd"); devfs_remove("rd");
unregister_blkdev(RAMDISK_MAJOR, "ramdisk" ); unregister_blkdev(RAMDISK_MAJOR, "ramdisk");
} }
/* This is the registration and initialization section of the RAM disk driver */ /*
static int __init rd_init (void) * This is the registration and initialization section of the RAM disk driver
*/
static int __init rd_init(void)
{ {
int i; int i;
int err = -ENOMEM; int err = -ENOMEM;
if (rd_blocksize > PAGE_SIZE || rd_blocksize < 512 || if (rd_blocksize > PAGE_SIZE || rd_blocksize < 512 ||
(rd_blocksize & (rd_blocksize-1))) { (rd_blocksize & (rd_blocksize-1))) {
printk("RAMDISK: wrong blocksize %d, reverting to defaults\n", printk("RAMDISK: wrong blocksize %d, reverting to defaults\n",
rd_blocksize); rd_blocksize);
rd_blocksize = BLOCK_SIZE; rd_blocksize = BLOCK_SIZE;
...@@ -363,8 +372,8 @@ static int __init rd_init (void) ...@@ -363,8 +372,8 @@ static int __init rd_init (void)
/* rd_size is given in kB */ /* rd_size is given in kB */
printk("RAMDISK driver initialized: " printk("RAMDISK driver initialized: "
"%d RAM disks of %dK size %d blocksize\n", "%d RAM disks of %dK size %d blocksize\n",
NUM_RAMDISKS, rd_size, rd_blocksize); NUM_RAMDISKS, rd_size, rd_blocksize);
return 0; return 0;
out_queue: out_queue:
......
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