Commit a1864a75 authored by Andrew Morton's avatar Andrew Morton Committed by Linus Torvalds

[PATCH] bdev: open() changes

The first of a series which move us toward blockdev hotplug support.  After
these we have achieved the following:

a) For "normal" (not bdevfs) inodes of block devices we never look at
   ->i_mapping.

b) For the same inodes we only look at ->i_bdev in bd_acquire() where it's
   used only as "here's what we'd found the last time" sort of cached value.
   If it's NULL, we just recalculate it.

c) Lots of messy expressions had been trimmed down, while we are at it.

(a) and (b) allow us to start doing proper block hotplug - we can destroy the
association between inode and bdev at any time, unhash bdev in question and
have new open() do everything from scratch, without waiting for old opened
files to close.  The goal is to be able to say "revoke everything over that
gendisk"/"revoke that partition" and have it do the right thing.


This patch:

Where the old code called (block device) ->open(inode, file), use
->open(inode->i_bdev->bd_inode, file).  Changes in drivers:

* none to those that only used inode->i_bdev and inode->i_rdev in their
  ->open() (bdev->bd_inode->i_bdev == bdev, so we are OK)

* floppy.c and floppy98.c used to call permission(inode, ...) in
  floppy_open().  Switched to permission(file->f_dentry->d_inode, ...)
parent 26dd5cfe
...@@ -3784,8 +3784,7 @@ static int floppy_open(struct inode * inode, struct file * filp) ...@@ -3784,8 +3784,7 @@ static int floppy_open(struct inode * inode, struct file * filp)
/* Allow ioctls if we have write-permissions even if read-only open. /* Allow ioctls if we have write-permissions even if read-only open.
* Needed so that programs such as fdrawcmd still can work on write * Needed so that programs such as fdrawcmd still can work on write
* protected disks */ * protected disks */
if ((filp->f_mode & 2) || if (filp->f_mode & 2 || permission(filp->f_dentry->d_inode,2,NULL) == 0)
(inode->i_sb && (permission(inode,2, NULL) == 0)))
filp->private_data = (void*) 8; filp->private_data = (void*) 8;
if (UFDCS->rawcmd == 1) if (UFDCS->rawcmd == 1)
......
...@@ -3859,8 +3859,7 @@ static int floppy_open(struct inode * inode, struct file * filp) ...@@ -3859,8 +3859,7 @@ static int floppy_open(struct inode * inode, struct file * filp)
/* Allow ioctls if we have write-permissions even if read-only open. /* Allow ioctls if we have write-permissions even if read-only open.
* Needed so that programs such as fdrawcmd still can work on write * Needed so that programs such as fdrawcmd still can work on write
* protected disks */ * protected disks */
if ((filp->f_mode & 2) || if (filp->f_mode & 2 || permission(filp->f_dentry->d_inode,2,NULL) == 0)
(inode->i_sb && (permission(inode,2) == 0)))
filp->private_data = (void*) 8; filp->private_data = (void*) 8;
if (UFDCS->rawcmd == 1) if (UFDCS->rawcmd == 1)
......
...@@ -531,7 +531,7 @@ static void bd_set_size(struct block_device *bdev, loff_t size) ...@@ -531,7 +531,7 @@ static void bd_set_size(struct block_device *bdev, loff_t size)
bdev->bd_inode->i_blkbits = blksize_bits(bsize); bdev->bd_inode->i_blkbits = blksize_bits(bsize);
} }
static int do_open(struct block_device *bdev, struct inode *inode, struct file *file) static int do_open(struct block_device *bdev, struct file *file)
{ {
struct module *owner = NULL; struct module *owner = NULL;
struct gendisk *disk; struct gendisk *disk;
...@@ -554,7 +554,7 @@ static int do_open(struct block_device *bdev, struct inode *inode, struct file * ...@@ -554,7 +554,7 @@ static int do_open(struct block_device *bdev, struct inode *inode, struct file *
if (!part) { if (!part) {
struct backing_dev_info *bdi; struct backing_dev_info *bdi;
if (disk->fops->open) { if (disk->fops->open) {
ret = disk->fops->open(inode, file); ret = disk->fops->open(bdev->bd_inode, file);
if (ret) if (ret)
goto out_first; goto out_first;
} }
...@@ -599,7 +599,7 @@ static int do_open(struct block_device *bdev, struct inode *inode, struct file * ...@@ -599,7 +599,7 @@ static int do_open(struct block_device *bdev, struct inode *inode, struct file *
module_put(owner); module_put(owner);
if (bdev->bd_contains == bdev) { if (bdev->bd_contains == bdev) {
if (bdev->bd_disk->fops->open) { if (bdev->bd_disk->fops->open) {
ret = bdev->bd_disk->fops->open(inode, file); ret = bdev->bd_disk->fops->open(bdev->bd_inode, file);
if (ret) if (ret)
goto out; goto out;
} }
...@@ -647,7 +647,7 @@ int blkdev_get(struct block_device *bdev, mode_t mode, unsigned flags, int kind) ...@@ -647,7 +647,7 @@ int blkdev_get(struct block_device *bdev, mode_t mode, unsigned flags, int kind)
fake_file.f_dentry = &fake_dentry; fake_file.f_dentry = &fake_dentry;
fake_dentry.d_inode = bdev->bd_inode; fake_dentry.d_inode = bdev->bd_inode;
return do_open(bdev, bdev->bd_inode, &fake_file); return do_open(bdev, &fake_file);
} }
EXPORT_SYMBOL(blkdev_get); EXPORT_SYMBOL(blkdev_get);
...@@ -668,7 +668,7 @@ int blkdev_open(struct inode * inode, struct file * filp) ...@@ -668,7 +668,7 @@ int blkdev_open(struct inode * inode, struct file * filp)
bd_acquire(inode); bd_acquire(inode);
bdev = inode->i_bdev; bdev = inode->i_bdev;
res = do_open(bdev, inode, filp); res = do_open(bdev, filp);
if (res) if (res)
return res; return res;
......
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