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

[PATCH] ftl.c

	* switched to private queue
	* set ->queue and ->private_data
	* switched to new methods
	* switched ->open() and friends to use of ->bd_disk
	* switched request handling to use of ->rq_disk
	* cleaned up
parent 53780b94
...@@ -175,16 +175,16 @@ static int ftl_ioctl(struct inode *inode, struct file *file, ...@@ -175,16 +175,16 @@ static int ftl_ioctl(struct inode *inode, struct file *file,
u_int cmd, u_long arg); u_int cmd, u_long arg);
static int ftl_open(struct inode *inode, struct file *file); static int ftl_open(struct inode *inode, struct file *file);
static release_t ftl_close(struct inode *inode, struct file *file); static release_t ftl_close(struct inode *inode, struct file *file);
static int ftl_revalidate(kdev_t dev); static int ftl_revalidate(struct gendisk *disk);
static void ftl_erase_callback(struct erase_info *done); static void ftl_erase_callback(struct erase_info *done);
static struct block_device_operations ftl_blk_fops = { static struct block_device_operations ftl_blk_fops = {
owner: THIS_MODULE, .owner = THIS_MODULE,
open: ftl_open, .open = ftl_open,
release: ftl_close, .release = ftl_close,
ioctl: ftl_ioctl, .ioctl = ftl_ioctl,
revalidate: ftl_revalidate, .revalidate_disk= ftl_revalidate,
}; };
/*====================================================================== /*======================================================================
...@@ -823,14 +823,7 @@ static u_int32_t find_free(partition_t *part) ...@@ -823,14 +823,7 @@ static u_int32_t find_free(partition_t *part)
static int ftl_open(struct inode *inode, struct file *file) static int ftl_open(struct inode *inode, struct file *file)
{ {
int minor = minor(inode->i_rdev); partition_t *partition = inode->i_bdev->bd_disk->private_data;
partition_t *partition;
if (minor>>4 >= MAX_MTD_DEVICES)
return -ENODEV;
partition = myparts[minor>>4];
if (!partition) if (!partition)
return -ENODEV; return -ENODEV;
...@@ -848,7 +841,7 @@ static int ftl_open(struct inode *inode, struct file *file) ...@@ -848,7 +841,7 @@ static int ftl_open(struct inode *inode, struct file *file)
return -EROFS; return -EROFS;
} }
DEBUG(0, "ftl_cs: ftl_open(%d)\n", minor); DEBUG(0, "ftl_cs: ftl_open(%s)\n", inode->i_bdev->b_disk->disk_name);
atomic_inc(&partition->open); atomic_inc(&partition->open);
...@@ -859,11 +852,10 @@ static int ftl_open(struct inode *inode, struct file *file) ...@@ -859,11 +852,10 @@ static int ftl_open(struct inode *inode, struct file *file)
static release_t ftl_close(struct inode *inode, struct file *file) static release_t ftl_close(struct inode *inode, struct file *file)
{ {
int minor = minor(inode->i_rdev); partition_t *part = inode->i_bdev->bd_disk->private_data;
partition_t *part = myparts[minor >> 4];
int i; int i;
DEBUG(0, "ftl_cs: ftl_close(%d)\n", minor); DEBUG(0, "ftl_cs: ftl_close(%s)\n", inode->i_bdev->b_disk->disk_name);
/* Wait for any pending erase operations to complete */ /* Wait for any pending erase operations to complete */
if (part->mtd->sync) if (part->mtd->sync)
...@@ -1091,9 +1083,9 @@ static int ftl_write(partition_t *part, caddr_t buffer, ...@@ -1091,9 +1083,9 @@ static int ftl_write(partition_t *part, caddr_t buffer,
static int ftl_ioctl(struct inode *inode, struct file *file, static int ftl_ioctl(struct inode *inode, struct file *file,
u_int cmd, u_long arg) u_int cmd, u_long arg)
{ {
partition_t *part = inode->i_bdev->bd_disk->private_data;
struct hd_geometry *geo = (struct hd_geometry *)arg; struct hd_geometry *geo = (struct hd_geometry *)arg;
int ret = 0, minor = minor(inode->i_rdev); int ret = 0;
partition_t *part= myparts[minor >> 4];
u_long sect; u_long sect;
if (!part) if (!part)
...@@ -1102,7 +1094,8 @@ static int ftl_ioctl(struct inode *inode, struct file *file, ...@@ -1102,7 +1094,8 @@ static int ftl_ioctl(struct inode *inode, struct file *file,
if (cmd != HDIO_GETGEO) if (cmd != HDIO_GETGEO)
return -EINVAL; return -EINVAL;
ret = verify_area(VERIFY_WRITE, (long *)arg, sizeof(*geo)); ret = verify_area(VERIFY_WRITE, (long *)arg, sizeof(*geo));
if (ret) return ret; if (ret)
return ret;
/* Sort of arbitrary: round size down to 4K boundary */ /* Sort of arbitrary: round size down to 4K boundary */
sect = le32_to_cpu(part->header.FormattedSize)/SECTOR_SIZE; sect = le32_to_cpu(part->header.FormattedSize)/SECTOR_SIZE;
put_user(1, (char *)&geo->heads); put_user(1, (char *)&geo->heads);
...@@ -1118,13 +1111,11 @@ static int ftl_ioctl(struct inode *inode, struct file *file, ...@@ -1118,13 +1111,11 @@ static int ftl_ioctl(struct inode *inode, struct file *file,
======================================================================*/ ======================================================================*/
static int ftl_revalidate(kdev_t dev) static int ftl_revalidate(struct gendisk *disk)
{ {
int unit = minor(dev) >> 4; partition_t *part = disk->private_data;
partition_t *part = myparts[unit];
scan_header(part); scan_header(part);
set_capacity(part->disk, set_capacity(disk, le32_to_cpu(part->header.FormattedSize)/SECTOR_SIZE);
le32_to_cpu(part->header.FormattedSize)/SECTOR_SIZE);
return 0; return 0;
} }
...@@ -1134,49 +1125,47 @@ static int ftl_revalidate(kdev_t dev) ...@@ -1134,49 +1125,47 @@ static int ftl_revalidate(kdev_t dev)
======================================================================*/ ======================================================================*/
static void do_ftl_request(request_arg_t) static struct request_queue ftl_queue;
static void do_ftl_request(struct request_queue *q)
{ {
int ret, minor; struct request *req;
partition_t *part; partition_t *part;
int ret;
do { do {
// sti(); // sti();
if (blk_queue_empty(QUEUE)) if (blk_queue_empty(q))
return; return;
req = elv_next_request(q);
minor = minor(CURRENT->rq_dev); part = req->rq_disk->private_data;
part = myparts[minor >> 4];
if (part) { if (part) {
ret = 0; ret = 0;
switch (rq_data_dir(CURRENT)) { switch (rq_data_dir(CURRENT)) {
case READ: case READ:
ret = ftl_read(part, CURRENT->buffer, CURRENT->sector, ret = ftl_read(part, req->buffer, req->sector,
CURRENT->current_nr_sectors); req->current_nr_sectors);
if (ret) printk("ftl_read returned %d\n", ret); if (ret)
printk("ftl_read returned %d\n", ret);
break; break;
case WRITE: case WRITE:
ret = ftl_write(part, CURRENT->buffer, CURRENT->sector, ret = ftl_write(part, req->buffer, req->sector,
CURRENT->current_nr_sectors); req->current_nr_sectors);
if (ret) printk("ftl_write returned %d\n", ret); if (ret)
printk("ftl_write returned %d\n", ret);
break; break;
default: default:
panic("ftl_cs: unknown block command!\n"); panic("ftl_cs: unknown block command!\n");
} }
} else { } else {
ret = 1; ret = 1;
printk("NULL part in ftl_request\n"); printk("NULL part in ftl_request\n");
} }
if (!ret) { if (!ret)
CURRENT->sector += CURRENT->current_nr_sectors; req->sector += req->current_nr_sectors;
}
end_request(CURRENT, (ret == 0) ? 1 : 0); end_request(req, (ret == 0) ? 1 : 0);
} while (1); } while (1);
} /* do_ftl_request */ } /* do_ftl_request */
...@@ -1246,6 +1235,8 @@ static void ftl_notify_add(struct mtd_info *mtd) ...@@ -1246,6 +1235,8 @@ static void ftl_notify_add(struct mtd_info *mtd)
atomic_set(&partition->open, 0); atomic_set(&partition->open, 0);
myparts[device] = partition; myparts[device] = partition;
set_capacity(disk, le32_to_cpu(partition->header.FormattedSize)/SECTOR_SIZE); set_capacity(disk, le32_to_cpu(partition->header.FormattedSize)/SECTOR_SIZE);
disk->private_data = partition;
disk->queue = &ftl_queue;
add_disk(disk); add_disk(disk);
#ifdef PCMCIA_DEBUG #ifdef PCMCIA_DEBUG
printk(KERN_INFO "ftl_cs: opening %d kb FTL partition\n", printk(KERN_INFO "ftl_cs: opening %d kb FTL partition\n",
...@@ -1295,9 +1286,8 @@ int init_ftl(void) ...@@ -1295,9 +1286,8 @@ int init_ftl(void)
"device number!\n"); "device number!\n");
return -EAGAIN; return -EAGAIN;
} }
blk_init_queue(BLK_DEFAULT_QUEUE(FTL_MAJOR), &do_ftl_request, &lock); blk_init_queue(&ftl_queue, &do_ftl_request, &lock);
register_mtd_user(&ftl_notifier); register_mtd_user(&ftl_notifier);
return 0; return 0;
} }
...@@ -1305,13 +1295,12 @@ static void __exit cleanup_ftl(void) ...@@ -1305,13 +1295,12 @@ static void __exit cleanup_ftl(void)
{ {
unregister_mtd_user(&ftl_notifier); unregister_mtd_user(&ftl_notifier);
unregister_blkdev(FTL_MAJOR, "ftl"); unregister_blkdev(FTL_MAJOR, "ftl");
blk_cleanup_queue(BLK_DEFAULT_QUEUE(FTL_MAJOR)); blk_cleanup_queue(&ftl_queue);
} }
module_init(init_ftl); module_init(init_ftl);
module_exit(cleanup_ftl); module_exit(cleanup_ftl);
MODULE_LICENSE("Dual MPL/GPL"); MODULE_LICENSE("Dual MPL/GPL");
MODULE_AUTHOR("David Hinds <dhinds@sonic.net>"); MODULE_AUTHOR("David Hinds <dhinds@sonic.net>");
MODULE_DESCRIPTION("Support code for Flash Translation Layer, used on PCMCIA devices and M-Systems DiskOnChip 1000"); MODULE_DESCRIPTION("Support code for Flash Translation Layer, used on PCMCIA devices and M-Systems DiskOnChip 1000");
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