Commit 5a22d00c authored by Dave Jones's avatar Dave Jones Committed by Linus Torvalds

[PATCH] MTD update.

Numerous bugfixes brought forward from 2.4. I added some quick bio fixes
to mtdblock.c, which seemed to work for me whilst testing JFFS2 changes.
parent 34a7eea9
This diff is collapsed.
...@@ -16,11 +16,8 @@ ...@@ -16,11 +16,8 @@
#define MAJOR_NR MTD_BLOCK_MAJOR #define MAJOR_NR MTD_BLOCK_MAJOR
#define DEVICE_NAME "mtdblock" #define DEVICE_NAME "mtdblock"
#define DEVICE_REQUEST mtdblock_request
#define DEVICE_NR(device) (device) #define DEVICE_NR(device) (device)
#define DEVICE_ON(device) #define LOCAL_END_REQUEST
#define DEVICE_OFF(device)
#define DEVICE_NO_RANDOM
#include <linux/blk.h> #include <linux/blk.h>
/* for old kernels... */ /* for old kernels... */
#ifndef QUEUE_EMPTY #ifndef QUEUE_EMPTY
...@@ -283,7 +280,7 @@ static int mtdblock_open(struct inode *inode, struct file *file) ...@@ -283,7 +280,7 @@ static int mtdblock_open(struct inode *inode, struct file *file)
if (!inode) if (!inode)
return -EINVAL; return -EINVAL;
dev = MINOR(inode->i_rdev); dev = minor(inode->i_rdev);
if (dev >= MAX_MTD_DEVICES) if (dev >= MAX_MTD_DEVICES)
return -EINVAL; return -EINVAL;
...@@ -373,7 +370,7 @@ static release_t mtdblock_release(struct inode *inode, struct file *file) ...@@ -373,7 +370,7 @@ static release_t mtdblock_release(struct inode *inode, struct file *file)
invalidate_device(inode->i_rdev, 1); invalidate_device(inode->i_rdev, 1);
dev = MINOR(inode->i_rdev); dev = minor(inode->i_rdev);
mtdblk = mtdblks[dev]; mtdblk = mtdblks[dev];
down(&mtdblk->cache_sem); down(&mtdblk->cache_sem);
...@@ -417,18 +414,20 @@ static void handle_mtdblock_request(void) ...@@ -417,18 +414,20 @@ static void handle_mtdblock_request(void)
INIT_REQUEST; INIT_REQUEST;
req = CURRENT; req = CURRENT;
spin_unlock_irq(&QUEUE->queue_lock); spin_unlock_irq(&QUEUE->queue_lock);
mtdblk = mtdblks[MINOR(req->rq_dev)]; mtdblk = mtdblks[minor(req->rq_dev)];
res = 0; res = 0;
if (MINOR(req->rq_dev) >= MAX_MTD_DEVICES) if (minor(req->rq_dev) >= MAX_MTD_DEVICES)
panic(__FUNCTION__": minor out of bound"); panic(__FUNCTION__": minor out of bound");
if (req->flags & REQ_CMD)
goto end_req;
if ((req->sector + req->current_nr_sectors) > (mtdblk->mtd->size >> 9)) if ((req->sector + req->current_nr_sectors) > (mtdblk->mtd->size >> 9))
goto end_req; goto end_req;
// Handle the request // Handle the request
switch (req->cmd) switch (rq_data_dir(CURRENT)) {
{
int err; int err;
case READ: case READ:
...@@ -459,7 +458,11 @@ static void handle_mtdblock_request(void) ...@@ -459,7 +458,11 @@ static void handle_mtdblock_request(void)
end_req: end_req:
spin_lock_irq(&QUEUE->queue_lock); spin_lock_irq(&QUEUE->queue_lock);
end_request(res); if (!end_that_request_first(req, res, req->hard_cur_sectors)) {
blkdev_dequeue_request(req);
end_that_request_last(req);
}
} }
} }
...@@ -519,7 +522,7 @@ static int mtdblock_ioctl(struct inode * inode, struct file * file, ...@@ -519,7 +522,7 @@ static int mtdblock_ioctl(struct inode * inode, struct file * file,
{ {
struct mtdblk_dev *mtdblk; struct mtdblk_dev *mtdblk;
mtdblk = mtdblks[MINOR(inode->i_rdev)]; mtdblk = mtdblks[minor(inode->i_rdev)];
#ifdef PARANOIA #ifdef PARANOIA
if (!mtdblk) if (!mtdblk)
...@@ -597,6 +600,8 @@ static void mtd_notify_remove(struct mtd_info* mtd) ...@@ -597,6 +600,8 @@ static void mtd_notify_remove(struct mtd_info* mtd)
} }
#endif #endif
static spinlock_t mtddev_lock = SPIN_LOCK_UNLOCKED;
int __init init_mtdblock(void) int __init init_mtdblock(void)
{ {
int i; int i;
...@@ -630,7 +635,7 @@ int __init init_mtdblock(void) ...@@ -630,7 +635,7 @@ int __init init_mtdblock(void)
blksize_size[MAJOR_NR] = mtd_blksizes; blksize_size[MAJOR_NR] = mtd_blksizes;
blk_size[MAJOR_NR] = mtd_sizes; blk_size[MAJOR_NR] = mtd_sizes;
blk_init_queue(BLK_DEFAULT_QUEUE(MAJOR_NR), &mtdblock_request); blk_init_queue(BLK_DEFAULT_QUEUE(MAJOR_NR), &mtdblock_request, &mtddev_lock);
kernel_thread (mtdblock_thread, NULL, CLONE_FS|CLONE_FILES|CLONE_SIGHAND); kernel_thread (mtdblock_thread, NULL, CLONE_FS|CLONE_FILES|CLONE_SIGHAND);
return 0; return 0;
} }
......
...@@ -16,13 +16,10 @@ ...@@ -16,13 +16,10 @@
#include <linux/mtd/mtd.h> #include <linux/mtd/mtd.h>
#include <linux/mtd/compatmac.h> #include <linux/mtd/compatmac.h>
#define LOCAL_END_REQUEST
#define MAJOR_NR MTD_BLOCK_MAJOR #define MAJOR_NR MTD_BLOCK_MAJOR
#define DEVICE_NAME "mtdblock" #define DEVICE_NAME "mtdblock"
#define DEVICE_REQUEST mtdblock_request
#define DEVICE_NR(device) (device) #define DEVICE_NR(device) (device)
#define DEVICE_ON(device)
#define DEVICE_OFF(device)
#define DEVICE_NO_RANDOM
#include <linux/blk.h> #include <linux/blk.h>
#if LINUX_VERSION_CODE < 0x20300 #if LINUX_VERSION_CODE < 0x20300
...@@ -52,7 +49,7 @@ static int mtdblock_open(struct inode *inode, struct file *file) ...@@ -52,7 +49,7 @@ static int mtdblock_open(struct inode *inode, struct file *file)
if (inode == 0) if (inode == 0)
return -EINVAL; return -EINVAL;
dev = MINOR(inode->i_rdev); dev = minor(inode->i_rdev);
mtd = get_mtd_device(NULL, dev); mtd = get_mtd_device(NULL, dev);
if (!mtd) if (!mtd)
...@@ -81,7 +78,7 @@ static release_t mtdblock_release(struct inode *inode, struct file *file) ...@@ -81,7 +78,7 @@ static release_t mtdblock_release(struct inode *inode, struct file *file)
invalidate_device(inode->i_rdev, 1); invalidate_device(inode->i_rdev, 1);
dev = MINOR(inode->i_rdev); dev = minor(inode->i_rdev);
mtd = __get_mtd_device(NULL, dev); mtd = __get_mtd_device(NULL, dev);
if (!mtd) { if (!mtd) {
...@@ -97,8 +94,15 @@ static release_t mtdblock_release(struct inode *inode, struct file *file) ...@@ -97,8 +94,15 @@ static release_t mtdblock_release(struct inode *inode, struct file *file)
DEBUG(1, "ok\n"); DEBUG(1, "ok\n");
release_return(0); release_return(0);
} }
static inline void mtdblock_end_request(struct request *req, int uptodate)
{
if (end_that_request_first(req, uptodate, req->hard_cur_sectors))
return;
blkdev_dequeue_request(req);
end_that_request_last(req);
}
static void mtdblock_request(RQFUNC_ARG) static void mtdblock_request(RQFUNC_ARG)
{ {
...@@ -113,19 +117,19 @@ static void mtdblock_request(RQFUNC_ARG) ...@@ -113,19 +117,19 @@ static void mtdblock_request(RQFUNC_ARG)
INIT_REQUEST; INIT_REQUEST;
current_request = CURRENT; current_request = CURRENT;
if (MINOR(current_request->rq_dev) >= MAX_MTD_DEVICES) if (minor(current_request->rq_dev) >= MAX_MTD_DEVICES)
{ {
printk("mtd: Unsupported device!\n"); printk("mtd: Unsupported device!\n");
end_request(0); mtdblock_end_request(current_request, 0);
continue; continue;
} }
// Grab our MTD structure // Grab our MTD structure
mtd = __get_mtd_device(NULL, MINOR(current_request->rq_dev)); mtd = __get_mtd_device(NULL, minor(current_request->rq_dev));
if (!mtd) { if (!mtd) {
printk("MTD device %d doesn't appear to exist any more\n", CURRENT_DEV); printk("MTD device %d doesn't appear to exist any more\n", CURRENT_DEV);
end_request(0); mtdblock_end_request(current_request, 0);
} }
if (current_request->sector << 9 > mtd->size || if (current_request->sector << 9 > mtd->size ||
...@@ -133,7 +137,7 @@ static void mtdblock_request(RQFUNC_ARG) ...@@ -133,7 +137,7 @@ static void mtdblock_request(RQFUNC_ARG)
{ {
printk("mtd: Attempt to read past end of device!\n"); printk("mtd: Attempt to read past end of device!\n");
printk("size: %x, sector: %lx, nr_sectors %lx\n", mtd->size, current_request->sector, current_request->nr_sectors); printk("size: %x, sector: %lx, nr_sectors %lx\n", mtd->size, current_request->sector, current_request->nr_sectors);
end_request(0); mtdblock_end_request(current_request, 0);
continue; continue;
} }
...@@ -192,7 +196,7 @@ static void mtdblock_request(RQFUNC_ARG) ...@@ -192,7 +196,7 @@ static void mtdblock_request(RQFUNC_ARG)
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0) #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,2,0)
spin_lock_irq(&io_request_lock); spin_lock_irq(&io_request_lock);
#endif #endif
end_request(res); mtdblock_end_request(current_request, res);
} }
} }
...@@ -203,7 +207,7 @@ static int mtdblock_ioctl(struct inode * inode, struct file * file, ...@@ -203,7 +207,7 @@ static int mtdblock_ioctl(struct inode * inode, struct file * file,
{ {
struct mtd_info *mtd; struct mtd_info *mtd;
mtd = __get_mtd_device(NULL, MINOR(inode->i_rdev)); mtd = __get_mtd_device(NULL, minor(inode->i_rdev));
if (!mtd) return -EINVAL; if (!mtd) return -EINVAL;
......
...@@ -64,7 +64,7 @@ static loff_t mtd_lseek (struct file *file, loff_t offset, int orig) ...@@ -64,7 +64,7 @@ static loff_t mtd_lseek (struct file *file, loff_t offset, int orig)
static int mtd_open(struct inode *inode, struct file *file) static int mtd_open(struct inode *inode, struct file *file)
{ {
int minor = MINOR(inode->i_rdev); int minor = minor(inode->i_rdev);
int devnum = minor >> 1; int devnum = minor >> 1;
struct mtd_info *mtd; struct mtd_info *mtd;
......
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