mtd/drivers/mtd mtd_blkdevs.c,1.3,1.4
David Woodhouse
dwmw2 at infradead.org
Sun May 18 13:30:13 EDT 2003
Update of /home/cvs/mtd/drivers/mtd
In directory phoenix.infradead.org:/tmp/cvs-serv4045
Modified Files:
mtd_blkdevs.c
Log Message:
Wheee. Actually bloody works, at least without partitions.
Index: mtd_blkdevs.c
===================================================================
RCS file: /home/cvs/mtd/drivers/mtd/mtd_blkdevs.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- mtd_blkdevs.c 18 May 2003 14:40:54 -0000 1.3
+++ mtd_blkdevs.c 18 May 2003 17:30:09 -0000 1.4
@@ -125,12 +125,13 @@
at the head of the queue */
spin_unlock_irq(&io_request_lock);
- /* Hmmm. Where can we store the dev, on which
- we already have a refcount anyway? This locking
- sucks */
- down(&mtd_table_mutex);
+ /* FIXME: Where can we store the dev, on which
+ we already have a refcount anyway? This deadlocks
+ with grok_partitions called from the registration
+ callbacks. */
+// down(&mtd_table_mutex);
dev = tr_get_dev(tr, devnum);
- up(&mtd_table_mutex);
+// up(&mtd_table_mutex);
if (!dev) {
/* We'd BUG() but it's rude to do so when we know
@@ -147,11 +148,10 @@
relock:
spin_lock_irq(&io_request_lock);
- if (end_that_request_first(req, res, tr->name))
- return;
-
- blkdev_dequeue_request(req);
- end_that_request_last(req);
+ if (!end_that_request_first(req, res, tr->name)) {
+ blkdev_dequeue_request(req);
+ end_that_request_last(req);
+ }
}
}
@@ -188,8 +188,7 @@
dev->usecount++;
tr->usecount++;
- f->private_data = dev;
-
+ ret = 0;
if (tr->open && (ret = tr->open(dev, i, f))) {
tr->usecount--;
dev->usecount--;
@@ -205,12 +204,27 @@
int blktrans_release(struct inode *i, struct file *f)
{
- struct mtd_blktrans_dev *dev = f->private_data;
- struct mtd_blktrans_ops *tr = dev->tr;
+ struct mtd_blktrans_dev *dev;
+ struct mtd_blktrans_ops *tr;
int ret = 0;
+ int devnum;
down(&mtd_table_mutex);
+ tr = get_tr(MAJOR(i->i_rdev));
+ if (!tr) {
+ up(&mtd_table_mutex);
+ return -ENODEV;
+ }
+
+ devnum = MINOR(i->i_rdev) >> tr->part_bits;
+ dev = tr_get_dev(tr, devnum);
+
+ if (!dev) {
+ up(&mtd_table_mutex);
+ return -ENODEV;
+ }
+
if (tr->release)
ret = tr->release(dev, i, f);
@@ -234,7 +248,7 @@
int i;
int minor = MINOR(rdev);
- if (minor & ((1<<tr->part_bits)-1)) {
+ if (minor & ((1<<tr->part_bits)-1) || !tr->part_bits) {
/* BLKRRPART on a partition. Go away. */
return -ENOTTY;
}
@@ -260,8 +274,8 @@
grok_partitions(gd, minor, 1 << tr->part_bits,
tr->blkcore_priv->sizes[minor]);
-
up(&mtd_table_mutex);
+
return 0;
}
@@ -270,6 +284,7 @@
{
struct mtd_blktrans_dev *dev;
struct mtd_blktrans_ops *tr;
+ int devnum;
switch(cmd) {
case BLKGETSIZE:
@@ -286,29 +301,22 @@
return blk_ioctl(inode->i_rdev, cmd, arg);
}
- if (file) {
- dev = file->private_data;
- tr = dev->tr;
- } else {
- /* Urgh. ioctl_by_bdev() calls us without a file pointer. */
- int devnum;
-
- down(&mtd_table_mutex);
-
- tr = get_tr(MAJOR(inode->i_rdev));
- if (!tr) {
- up(&mtd_table_mutex);
- return -ENODEV;
- }
-
- devnum = MINOR(inode->i_rdev) >> tr->part_bits;
- dev = tr_get_dev(tr, devnum);
+ down(&mtd_table_mutex);
+ tr = get_tr(MAJOR(inode->i_rdev));
+ if (!tr) {
up(&mtd_table_mutex);
+ return -ENODEV;
+ }
+
+ devnum = MINOR(inode->i_rdev) >> tr->part_bits;
+ dev = tr_get_dev(tr, devnum);
+
+ up(&mtd_table_mutex);
+
+ if (!dev)
+ return -ENODEV;
- if (!dev)
- return -ENODEV;
- }
switch(cmd) {
case BLKRRPART:
return mtd_blktrans_rrpart(inode->i_rdev, tr, dev);
@@ -383,8 +391,10 @@
tr->blkcore_priv->gd.nr_real++;
tr->blkcore_priv->part_table[new->devnum << tr->part_bits].nr_sects = new->size;
- grok_partitions(&tr->blkcore_priv->gd, new->devnum,
- 1 << tr->part_bits, new->size);
+ if (tr->part_bits) {
+ grok_partitions(&tr->blkcore_priv->gd, new->devnum,
+ 1 << tr->part_bits, new->size);
+ }
return 0;
}
@@ -414,7 +424,7 @@
return 0;
}
-void blktrans_notify_add(struct mtd_info *mtd)
+void blktrans_notify_remove(struct mtd_info *mtd)
{
struct list_head *this, *this2, *next;
@@ -430,7 +440,7 @@
}
}
-void blktrans_notify_remove(struct mtd_info *mtd)
+void blktrans_notify_add(struct mtd_info *mtd)
{
struct list_head *this;
@@ -505,7 +515,6 @@
int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr)
{
struct list_head *this, *next;
-
down(&mtd_table_mutex);
if (tr->usecount) {
up(&mtd_table_mutex);
More information about the linux-mtd-cvs
mailing list