Commit 3480cbc1 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] use bd_claim in the raw driver

Currently if you use the raw driver against /dev/hda1 while it has an
fs mounted, everything gets confused and the kernel locks up or oopses.

Al said to use bd_claim().  This prevents the raw driver from being
able to open the device under these circumstances.

There is value in being able to read the raw device while there's a
filesystem mounted: to poke around at the disk without interacting with
the kernel's caching.  You can still do that, with an O_DIRECT open of
/dev/hda1.
parent d97ec37c
...@@ -56,9 +56,15 @@ static int raw_open(struct inode *inode, struct file *filp) ...@@ -56,9 +56,15 @@ static int raw_open(struct inode *inode, struct file *filp)
bdev = raw_devices[minor].binding; bdev = raw_devices[minor].binding;
err = -ENODEV; err = -ENODEV;
if (bdev) { if (bdev) {
err = bd_claim(bdev, raw_open);
if (err)
goto out;
atomic_inc(&bdev->bd_count); atomic_inc(&bdev->bd_count);
err = blkdev_get(bdev, filp->f_mode, 0, BDEV_RAW); err = blkdev_get(bdev, filp->f_mode, 0, BDEV_RAW);
if (!err) { if (err) {
bd_release(bdev);
goto out;
} else {
err = set_blocksize(bdev, bdev_hardsect_size(bdev)); err = set_blocksize(bdev, bdev_hardsect_size(bdev));
if (err == 0) { if (err == 0) {
raw_devices[minor].inuse++; raw_devices[minor].inuse++;
...@@ -69,6 +75,7 @@ static int raw_open(struct inode *inode, struct file *filp) ...@@ -69,6 +75,7 @@ static int raw_open(struct inode *inode, struct file *filp)
} }
} }
filp->private_data = bdev; filp->private_data = bdev;
out:
up(&raw_mutex); up(&raw_mutex);
return err; return err;
} }
...@@ -82,6 +89,7 @@ static int raw_release(struct inode *inode, struct file *filp) ...@@ -82,6 +89,7 @@ static int raw_release(struct inode *inode, struct file *filp)
bdev = raw_devices[minor].binding; bdev = raw_devices[minor].binding;
raw_devices[minor].inuse--; raw_devices[minor].inuse--;
up(&raw_mutex); up(&raw_mutex);
bd_release(bdev);
blkdev_put(bdev, BDEV_RAW); blkdev_put(bdev, BDEV_RAW);
return 0; return 0;
} }
......
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