From a1864a759aed0fe75c9d117a3f6500c030f959ed Mon Sep 17 00:00:00 2001 From: Andrew Morton Date: Sun, 18 Jan 2004 18:05:49 -0800 Subject: [PATCH] [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, ...) --- drivers/block/floppy.c | 3 +-- drivers/block/floppy98.c | 3 +-- fs/block_dev.c | 10 +++++----- 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index ea00de8b83edf..7c5085a3d1938 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -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. * Needed so that programs such as fdrawcmd still can work on write * protected disks */ - if ((filp->f_mode & 2) || - (inode->i_sb && (permission(inode,2, NULL) == 0))) + if (filp->f_mode & 2 || permission(filp->f_dentry->d_inode,2,NULL) == 0) filp->private_data = (void*) 8; if (UFDCS->rawcmd == 1) diff --git a/drivers/block/floppy98.c b/drivers/block/floppy98.c index 2e9c5970e18c3..450cf5a588951 100644 --- a/drivers/block/floppy98.c +++ b/drivers/block/floppy98.c @@ -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. * Needed so that programs such as fdrawcmd still can work on write * protected disks */ - if ((filp->f_mode & 2) || - (inode->i_sb && (permission(inode,2) == 0))) + if (filp->f_mode & 2 || permission(filp->f_dentry->d_inode,2,NULL) == 0) filp->private_data = (void*) 8; if (UFDCS->rawcmd == 1) diff --git a/fs/block_dev.c b/fs/block_dev.c index 61108dd1a3fa0..74180b2a2ae8f 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -531,7 +531,7 @@ static void bd_set_size(struct block_device *bdev, loff_t size) 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 gendisk *disk; @@ -554,7 +554,7 @@ static int do_open(struct block_device *bdev, struct inode *inode, struct file * if (!part) { struct backing_dev_info *bdi; if (disk->fops->open) { - ret = disk->fops->open(inode, file); + ret = disk->fops->open(bdev->bd_inode, file); if (ret) goto out_first; } @@ -599,7 +599,7 @@ static int do_open(struct block_device *bdev, struct inode *inode, struct file * module_put(owner); if (bdev->bd_contains == bdev) { 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) goto out; } @@ -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_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); @@ -668,7 +668,7 @@ int blkdev_open(struct inode * inode, struct file * filp) bd_acquire(inode); bdev = inode->i_bdev; - res = do_open(bdev, inode, filp); + res = do_open(bdev, filp); if (res) return res; -- 2.53.0