From aeb5d727062a0238a2f96c9c380fbd2be4640c6f Mon Sep 17 00:00:00 2001 From: Al Viro Date: Tue, 2 Sep 2008 15:28:45 -0400 Subject: [PATCH] introduce fmode_t, do annotations Signed-off-by: Al Viro --- fs/block_dev.c | 10 +++++----- fs/fifo.c | 6 +++--- fs/file_table.c | 4 ++-- fs/hostfs/hostfs_kern.c | 5 +++-- fs/locks.c | 3 ++- fs/open.c | 2 +- fs/proc/base.c | 4 ++-- fs/reiserfs/journal.c | 2 +- 8 files changed, 19 insertions(+), 17 deletions(-) (limited to 'fs') diff --git a/fs/block_dev.c b/fs/block_dev.c index 218408eed1b..8897f3b02e9 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -840,7 +840,7 @@ EXPORT_SYMBOL_GPL(bd_release_from_disk); * to be used for internal purposes. If you ever need it - reconsider * your API. */ -struct block_device *open_by_devnum(dev_t dev, unsigned mode) +struct block_device *open_by_devnum(dev_t dev, fmode_t mode) { struct block_device *bdev = bdget(dev); int err = -ENOMEM; @@ -975,7 +975,7 @@ void bd_set_size(struct block_device *bdev, loff_t size) } EXPORT_SYMBOL(bd_set_size); -static int __blkdev_get(struct block_device *bdev, mode_t mode, unsigned flags, +static int __blkdev_get(struct block_device *bdev, fmode_t mode, unsigned flags, int for_part); static int __blkdev_put(struct block_device *bdev, int for_part); @@ -1104,7 +1104,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part) return ret; } -static int __blkdev_get(struct block_device *bdev, mode_t mode, unsigned flags, +static int __blkdev_get(struct block_device *bdev, fmode_t mode, unsigned flags, int for_part) { /* @@ -1123,7 +1123,7 @@ static int __blkdev_get(struct block_device *bdev, mode_t mode, unsigned flags, return do_open(bdev, &fake_file, for_part); } -int blkdev_get(struct block_device *bdev, mode_t mode, unsigned flags) +int blkdev_get(struct block_device *bdev, fmode_t mode, unsigned flags) { return __blkdev_get(bdev, mode, flags, 0); } @@ -1315,7 +1315,7 @@ EXPORT_SYMBOL(lookup_bdev); struct block_device *open_bdev_excl(const char *path, int flags, void *holder) { struct block_device *bdev; - mode_t mode = FMODE_READ; + fmode_t mode = FMODE_READ; int error = 0; bdev = lookup_bdev(path); diff --git a/fs/fifo.c b/fs/fifo.c index 987bf941149..f8f97b8b6d4 100644 --- a/fs/fifo.c +++ b/fs/fifo.c @@ -51,7 +51,7 @@ static int fifo_open(struct inode *inode, struct file *filp) filp->f_mode &= (FMODE_READ | FMODE_WRITE); switch (filp->f_mode) { - case 1: + case FMODE_READ: /* * O_RDONLY * POSIX.1 says that O_NONBLOCK means return with the FIFO @@ -76,7 +76,7 @@ static int fifo_open(struct inode *inode, struct file *filp) } break; - case 2: + case FMODE_WRITE: /* * O_WRONLY * POSIX.1 says that O_NONBLOCK means return -1 with @@ -98,7 +98,7 @@ static int fifo_open(struct inode *inode, struct file *filp) } break; - case 3: + case FMODE_READ | FMODE_WRITE: /* * O_RDWR * POSIX.1 leaves this case "undefined" when O_NONBLOCK is set. diff --git a/fs/file_table.c b/fs/file_table.c index f45a4493f9e..efc06faede6 100644 --- a/fs/file_table.c +++ b/fs/file_table.c @@ -161,7 +161,7 @@ EXPORT_SYMBOL(get_empty_filp); * code should be moved into this function. */ struct file *alloc_file(struct vfsmount *mnt, struct dentry *dentry, - mode_t mode, const struct file_operations *fop) + fmode_t mode, const struct file_operations *fop) { struct file *file; struct path; @@ -193,7 +193,7 @@ EXPORT_SYMBOL(alloc_file); * of this should be moving to alloc_file(). */ int init_file(struct file *file, struct vfsmount *mnt, struct dentry *dentry, - mode_t mode, const struct file_operations *fop) + fmode_t mode, const struct file_operations *fop) { int error = 0; file->f_path.dentry = dentry; diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c index d6ecabf4d23..7f34f4385de 100644 --- a/fs/hostfs/hostfs_kern.c +++ b/fs/hostfs/hostfs_kern.c @@ -20,7 +20,7 @@ struct hostfs_inode_info { char *host_filename; int fd; - int mode; + fmode_t mode; struct inode vfs_inode; }; @@ -373,7 +373,8 @@ int hostfs_readdir(struct file *file, void *ent, filldir_t filldir) int hostfs_file_open(struct inode *ino, struct file *file) { char *name; - int mode = 0, r = 0, w = 0, fd; + fmode_t mode = 0; + int r = 0, w = 0, fd; mode = file->f_mode & (FMODE_READ | FMODE_WRITE); if ((mode & HOSTFS_I(ino)->mode) == mode) diff --git a/fs/locks.c b/fs/locks.c index 5eb259e3cd3..20457486d6b 100644 --- a/fs/locks.c +++ b/fs/locks.c @@ -1580,7 +1580,8 @@ asmlinkage long sys_flock(unsigned int fd, unsigned int cmd) cmd &= ~LOCK_NB; unlock = (cmd == LOCK_UN); - if (!unlock && !(cmd & LOCK_MAND) && !(filp->f_mode & 3)) + if (!unlock && !(cmd & LOCK_MAND) && + !(filp->f_mode & (FMODE_READ|FMODE_WRITE))) goto out_putf; error = flock_make_lock(filp, &lock, cmd); diff --git a/fs/open.c b/fs/open.c index 5596049863b..83cdb9dee0c 100644 --- a/fs/open.c +++ b/fs/open.c @@ -798,7 +798,7 @@ static struct file *__dentry_open(struct dentry *dentry, struct vfsmount *mnt, int error; f->f_flags = flags; - f->f_mode = ((flags+1) & O_ACCMODE) | FMODE_LSEEK | + f->f_mode = (__force fmode_t)((flags+1) & O_ACCMODE) | FMODE_LSEEK | FMODE_PREAD | FMODE_PWRITE; inode = dentry->d_inode; if (f->f_mode & FMODE_WRITE) { diff --git a/fs/proc/base.c b/fs/proc/base.c index b5918ae8ca7..486cf3fe713 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1712,9 +1712,9 @@ static struct dentry *proc_fd_instantiate(struct inode *dir, file = fcheck_files(files, fd); if (!file) goto out_unlock; - if (file->f_mode & 1) + if (file->f_mode & FMODE_READ) inode->i_mode |= S_IRUSR | S_IXUSR; - if (file->f_mode & 2) + if (file->f_mode & FMODE_WRITE) inode->i_mode |= S_IWUSR | S_IXUSR; spin_unlock(&files->file_lock); put_files_struct(files); diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c index c21df71943a..b89d193a00d 100644 --- a/fs/reiserfs/journal.c +++ b/fs/reiserfs/journal.c @@ -2593,7 +2593,7 @@ static int journal_init_dev(struct super_block *super, { int result; dev_t jdev; - int blkdev_mode = FMODE_READ | FMODE_WRITE; + fmode_t blkdev_mode = FMODE_READ | FMODE_WRITE; char b[BDEVNAME_SIZE]; result = 0; -- cgit v1.2.3-70-g09d2 From 86d434dede14108dd917b25af0f29c0cb28b8d18 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sun, 26 Aug 2007 19:50:05 -0400 Subject: [PATCH] eliminate use of ->f_flags in block methods store needed information in f_mode Signed-off-by: Al Viro --- drivers/block/ataflop.c | 6 +++--- drivers/block/floppy.c | 15 ++++----------- drivers/block/swim3.c | 6 +++--- drivers/block/ub.c | 2 +- drivers/cdrom/cdrom.c | 4 ++-- drivers/ide/ide-gd.c | 2 +- drivers/scsi/sd.c | 2 +- fs/block_dev.c | 7 +++++++ include/linux/fs.h | 4 ++++ 9 files changed, 26 insertions(+), 22 deletions(-) (limited to 'fs') diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c index e1db285b72c..85d56a26f7c 100644 --- a/drivers/block/ataflop.c +++ b/drivers/block/ataflop.c @@ -1813,17 +1813,17 @@ static int floppy_open( struct inode *inode, struct file *filp ) if (p->ref && p->type != type) return -EBUSY; - if (p->ref == -1 || (p->ref && filp->f_flags & O_EXCL)) + if (p->ref == -1 || (p->ref && filp->f_mode & FMODE_EXCL)) return -EBUSY; - if (filp->f_flags & O_EXCL) + if (filp->f_mode & FMODE_EXCL) p->ref = -1; else p->ref++; p->type = type; - if (filp->f_flags & O_NDELAY) + if (filp->f_mode & FMODE_NDELAY) return 0; if (filp->f_mode & (FMODE_READ|FMODE_WRITE)) { diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index ae3ef8945f3..5d60c05a736 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -3453,7 +3453,7 @@ static int fd_getgeo(struct block_device *bdev, struct hd_geometry *geo) static int fd_ioctl(struct inode *inode, struct file *filp, unsigned int cmd, unsigned long param) { -#define FD_IOCTL_ALLOWED ((filp) && (filp)->private_data) +#define FD_IOCTL_ALLOWED ((filp) && (filp)->f_mode & (FMODE_WRITE|FMODE_WRITE_IOCTL)) #define OUT(c,x) case c: outparam = (const char *) (x); break #define IN(c,x,tag) case c: *(x) = inparam. tag ; return 0 @@ -3690,7 +3690,6 @@ static int floppy_open(struct inode *inode, struct file *filp) int res = -EBUSY; char *tmp; - filp->private_data = (void *)0; mutex_lock(&open_lock); old_dev = UDRS->fd_device; if (opened_bdev[drive] && opened_bdev[drive] != inode->i_bdev) @@ -3701,10 +3700,10 @@ static int floppy_open(struct inode *inode, struct file *filp) USETF(FD_VERIFY); } - if (UDRS->fd_ref == -1 || (UDRS->fd_ref && (filp->f_flags & O_EXCL))) + if (UDRS->fd_ref == -1 || (UDRS->fd_ref && (filp->f_mode & FMODE_EXCL))) goto out2; - if (filp->f_flags & O_EXCL) + if (filp->f_mode & FMODE_EXCL) UDRS->fd_ref = -1; else UDRS->fd_ref++; @@ -3751,16 +3750,10 @@ static int floppy_open(struct inode *inode, struct file *filp) buffer_track = -1; } - /* 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 & FMODE_WRITE) || !file_permission(filp, MAY_WRITE)) - filp->private_data = (void *)8; - if (UFDCS->rawcmd == 1) UFDCS->rawcmd = 2; - if (!(filp->f_flags & O_NDELAY)) { + if (!(filp->f_mode & FMODE_NDELAY)) { if (filp->f_mode & (FMODE_READ|FMODE_WRITE)) { UDRS->last_checked = 0; check_disk_change(inode->i_bdev); diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c index a53ca54bee1..5c45d5556ae 100644 --- a/drivers/block/swim3.c +++ b/drivers/block/swim3.c @@ -904,10 +904,10 @@ static int floppy_open(struct inode *inode, struct file *filp) swim3_action(fs, SETMFM); swim3_select(fs, RELAX); - } else if (fs->ref_count == -1 || filp->f_flags & O_EXCL) + } else if (fs->ref_count == -1 || filp->f_mode & FMODE_EXCL) return -EBUSY; - if (err == 0 && (filp->f_flags & O_NDELAY) == 0 + if (err == 0 && (filp->f_mode & FMODE_NDELAY) == 0 && (filp->f_mode & (FMODE_READ|FMODE_WRITE))) { check_disk_change(inode->i_bdev); if (fs->ejected) @@ -930,7 +930,7 @@ static int floppy_open(struct inode *inode, struct file *filp) return err; } - if (filp->f_flags & O_EXCL) + if (filp->f_mode & FMODE_EXCL) fs->ref_count = -1; else ++fs->ref_count; diff --git a/drivers/block/ub.c b/drivers/block/ub.c index f60e41833f6..85d41eb67c0 100644 --- a/drivers/block/ub.c +++ b/drivers/block/ub.c @@ -1691,7 +1691,7 @@ static int ub_bd_open(struct inode *inode, struct file *filp) * under some pretty murky conditions (a failure of READ CAPACITY). * We may need it one day. */ - if (lun->removable && lun->changed && !(filp->f_flags & O_NDELAY)) { + if (lun->removable && lun->changed && !(filp->f_mode & FMODE_NDELAY)) { rc = -ENOMEDIUM; goto err_open; } diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c index d47f2f80acc..4feefa622ae 100644 --- a/drivers/cdrom/cdrom.c +++ b/drivers/cdrom/cdrom.c @@ -982,7 +982,7 @@ int cdrom_open(struct cdrom_device_info *cdi, struct inode *ip, struct file *fp) /* if this was a O_NONBLOCK open and we should honor the flags, * do a quick open without drive/disc integrity checks. */ cdi->use_count++; - if ((fp->f_flags & O_NONBLOCK) && (cdi->options & CDO_USE_FFLAGS)) { + if ((fp->f_mode & FMODE_NDELAY) && (cdi->options & CDO_USE_FFLAGS)) { ret = cdi->ops->open(cdi, 1); } else { ret = open_for_data(cdi); @@ -1205,7 +1205,7 @@ int cdrom_release(struct cdrom_device_info *cdi, struct file *fp) } opened_for_data = !(cdi->options & CDO_USE_FFLAGS) || - !(fp && fp->f_flags & O_NONBLOCK); + !(fp && fp->f_mode & FMODE_NDELAY); /* * flush cache on last write release diff --git a/drivers/ide/ide-gd.c b/drivers/ide/ide-gd.c index d367473098f..66bbb0a22f5 100644 --- a/drivers/ide/ide-gd.c +++ b/drivers/ide/ide-gd.c @@ -197,7 +197,7 @@ static int ide_gd_open(struct inode *inode, struct file *filp) * unreadable disk, so that we can get the format capacity * of the drive or begin the format - Sam */ - if (ret && (filp->f_flags & O_NDELAY) == 0) { + if (ret && (filp->f_mode & FMODE_NDELAY) == 0) { ret = -EIO; goto out_put_idkp; } diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 7c4d2e68df1..202c1ed9abd 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -640,7 +640,7 @@ static int sd_open(struct inode *inode, struct file *filp) */ retval = -ENOMEDIUM; if (sdev->removable && !sdkp->media_present && - !(filp->f_flags & O_NDELAY)) + !(filp->f_mode & FMODE_NDELAY)) goto error_out; /* diff --git a/fs/block_dev.c b/fs/block_dev.c index 8897f3b02e9..b9022694e9f 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1007,6 +1007,13 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part) return ret; } + if (file->f_flags & O_NDELAY) + file->f_mode |= FMODE_NDELAY; + if (file->f_flags & O_EXCL) + file->f_mode |= FMODE_EXCL; + if ((file->f_flags & O_ACCMODE) == 3) + file->f_mode |= FMODE_WRITE_IOCTL; + ret = -ENXIO; file->f_mapping = bdev->bd_inode->i_mapping; diff --git a/include/linux/fs.h b/include/linux/fs.h index 60a7a581ba9..5ab5579a516 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -76,6 +76,10 @@ extern int dir_notify_enable; behavior for cross-node execution/opening_for_writing of files */ #define FMODE_EXEC ((__force fmode_t)16) +#define FMODE_NDELAY ((__force fmode_t)32) +#define FMODE_EXCL ((__force fmode_t)64) +#define FMODE_WRITE_IOCTL ((__force fmode_t)128) + #define RW_MASK 1 #define RWA_MASK 2 #define READ 0 -- cgit v1.2.3-70-g09d2 From 08f85851215100d0eebf026810955ee6ad456c38 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Mon, 8 Oct 2007 13:26:20 -0400 Subject: [PATCH] move block_device_operations to blkdev.h Signed-off-by: Al Viro --- fs/ext2/xip.c | 1 + include/linux/blkdev.h | 17 +++++++++++++++++ include/linux/fs.h | 15 +-------------- 3 files changed, 19 insertions(+), 14 deletions(-) (limited to 'fs') diff --git a/fs/ext2/xip.c b/fs/ext2/xip.c index 4fb94c20041..b72b8588422 100644 --- a/fs/ext2/xip.c +++ b/fs/ext2/xip.c @@ -11,6 +11,7 @@ #include #include #include +#include #include "ext2.h" #include "xip.h" diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 48f41b991ad..48ec8862a11 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1057,6 +1057,23 @@ static inline int blk_integrity_rq(struct request *rq) #endif /* CONFIG_BLK_DEV_INTEGRITY */ +struct file; +struct inode; + +struct block_device_operations { + int (*open) (struct inode *, struct file *); + int (*release) (struct inode *, struct file *); + int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long); + long (*unlocked_ioctl) (struct file *, unsigned, unsigned long); + long (*compat_ioctl) (struct file *, unsigned, unsigned long); + int (*direct_access) (struct block_device *, sector_t, + void **, unsigned long *); + int (*media_changed) (struct gendisk *); + int (*revalidate_disk) (struct gendisk *); + int (*getgeo)(struct block_device *, struct hd_geometry *); + struct module *owner; +}; + #else /* CONFIG_BLOCK */ /* * stubs for when the block layer is configured out diff --git a/include/linux/fs.h b/include/linux/fs.h index 5ab5579a516..58bbf689fef 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1270,20 +1270,7 @@ int generic_osync_inode(struct inode *, struct address_space *, int); * to have different dirent layouts depending on the binary type. */ typedef int (*filldir_t)(void *, const char *, int, loff_t, u64, unsigned); - -struct block_device_operations { - int (*open) (struct inode *, struct file *); - int (*release) (struct inode *, struct file *); - int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long); - long (*unlocked_ioctl) (struct file *, unsigned, unsigned long); - long (*compat_ioctl) (struct file *, unsigned, unsigned long); - int (*direct_access) (struct block_device *, sector_t, - void **, unsigned long *); - int (*media_changed) (struct gendisk *); - int (*revalidate_disk) (struct gendisk *); - int (*getgeo)(struct block_device *, struct hd_geometry *); - struct module *owner; -}; +struct block_device_operations; /* These macros are for out of kernel modules to test that * the kernel supports the unlocked_ioctl and compat_ioctl -- cgit v1.2.3-70-g09d2 From d4430d62fa77208824a37fe6f85ab2831d274769 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sun, 2 Mar 2008 09:09:22 -0500 Subject: [PATCH] beginning of methods conversion To keep the size of changesets sane we split the switch by drivers; to keep the damn thing bisectable we do the following: 1) rename the affected methods, add ones with correct prototypes, make (few) callers handle both. That's this changeset. 2) for each driver convert to new methods. *ALL* drivers are converted in this series. 3) kill the old (renamed) methods. Note that it _is_ a flagday; all in-tree drivers are converted and by the end of this series no trace of old methods remain. The only reason why we do that this way is to keep the damn thing bisectable and allow per-driver debugging if anything goes wrong. New methods: open(bdev, mode) release(disk, mode) ioctl(bdev, mode, cmd, arg) /* Called without BKL */ compat_ioctl(bdev, mode, cmd, arg) locked_ioctl(bdev, mode, cmd, arg) /* Called with BKL, legacy */ Signed-off-by: Al Viro --- arch/um/drivers/ubd_kern.c | 6 +++--- block/compat_ioctl.c | 17 +++++++++-------- block/ioctl.c | 35 ++++++++++++++++++++++++++--------- drivers/block/DAC960.c | 2 +- drivers/block/amiflop.c | 6 +++--- drivers/block/aoe/aoeblk.c | 4 ++-- drivers/block/ataflop.c | 6 +++--- drivers/block/brd.c | 2 +- drivers/block/cciss.c | 8 ++++---- drivers/block/cpqarray.c | 6 +++--- drivers/block/floppy.c | 6 +++--- drivers/block/loop.c | 8 ++++---- drivers/block/nbd.c | 2 +- drivers/block/paride/pcd.c | 6 +++--- drivers/block/paride/pd.c | 6 +++--- drivers/block/paride/pf.c | 6 +++--- drivers/block/pktcdvd.c | 6 +++--- drivers/block/swim3.c | 6 +++--- drivers/block/ub.c | 6 +++--- drivers/block/viodasd.c | 4 ++-- drivers/block/virtio_blk.c | 2 +- drivers/block/xd.c | 2 +- drivers/block/xen-blkfront.c | 4 ++-- drivers/block/xsysace.c | 4 ++-- drivers/block/z2ram.c | 4 ++-- drivers/cdrom/gdrom.c | 6 +++--- drivers/cdrom/viocd.c | 6 +++--- drivers/ide/ide-cd.c | 6 +++--- drivers/ide/ide-gd.c | 6 +++--- drivers/ide/ide-tape.c | 6 +++--- drivers/md/dm.c | 6 +++--- drivers/md/md.c | 6 +++--- drivers/memstick/core/mspro_block.c | 4 ++-- drivers/message/i2o/i2o_block.c | 6 +++--- drivers/mmc/card/block.c | 4 ++-- drivers/mtd/mtd_blkdevs.c | 6 +++--- drivers/s390/block/dasd.c | 8 ++++---- drivers/s390/block/dcssblk.c | 4 ++-- drivers/s390/char/tape_block.c | 6 +++--- drivers/scsi/ide-scsi.c | 6 +++--- drivers/scsi/sd.c | 8 ++++---- drivers/scsi/sr.c | 6 +++--- fs/block_dev.c | 18 +++++++++++++++--- include/linux/blkdev.h | 15 ++++++++++----- include/linux/fs.h | 1 + 45 files changed, 167 insertions(+), 131 deletions(-) (limited to 'fs') diff --git a/arch/um/drivers/ubd_kern.c b/arch/um/drivers/ubd_kern.c index b58fb8941d8..72569cc3cbb 100644 --- a/arch/um/drivers/ubd_kern.c +++ b/arch/um/drivers/ubd_kern.c @@ -108,9 +108,9 @@ static int ubd_getgeo(struct block_device *bdev, struct hd_geometry *geo); static struct block_device_operations ubd_blops = { .owner = THIS_MODULE, - .open = ubd_open, - .release = ubd_release, - .ioctl = ubd_ioctl, + .__open = ubd_open, + .__release = ubd_release, + .__ioctl = ubd_ioctl, .getgeo = ubd_getgeo, }; diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index 1e559fba7bd..576c4fd1546 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -708,17 +708,17 @@ static int compat_blkdev_driver_ioctl(struct inode *inode, struct file *file, return -ENOIOCTLCMD; } - if (disk->fops->unlocked_ioctl) - return disk->fops->unlocked_ioctl(file, cmd, arg); + if (disk->fops->__unlocked_ioctl) + return disk->fops->__unlocked_ioctl(file, cmd, arg); - if (disk->fops->ioctl) { + if (disk->fops->__ioctl) { lock_kernel(); - ret = disk->fops->ioctl(inode, file, cmd, arg); + ret = disk->fops->__ioctl(inode, file, cmd, arg); unlock_kernel(); return ret; } - return -ENOTTY; + return __blkdev_driver_ioctl(inode->i_bdev, file->f_mode, cmd, arg); } static int compat_blkdev_locked_ioctl(struct inode *inode, struct file *file, @@ -805,10 +805,11 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) lock_kernel(); ret = compat_blkdev_locked_ioctl(inode, file, bdev, cmd, arg); - /* FIXME: why do we assume -> compat_ioctl needs the BKL? */ - if (ret == -ENOIOCTLCMD && disk->fops->compat_ioctl) - ret = disk->fops->compat_ioctl(file, cmd, arg); + if (ret == -ENOIOCTLCMD && disk->fops->__compat_ioctl) + ret = disk->fops->__compat_ioctl(file, cmd, arg); unlock_kernel(); + if (ret == -ENOIOCTLCMD && disk->fops->compat_ioctl) + ret = disk->fops->compat_ioctl(bdev, file->f_mode, cmd, arg); if (ret != -ENOIOCTLCMD) return ret; diff --git a/block/ioctl.c b/block/ioctl.c index 9a26ace6d04..01ff463bc80 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -269,17 +269,24 @@ int blkdev_driver_ioctl(struct inode *inode, struct file *file, struct gendisk *disk, unsigned cmd, unsigned long arg) { int ret; - if (disk->fops->unlocked_ioctl) - return disk->fops->unlocked_ioctl(file, cmd, arg); + fmode_t mode = 0; + if (file) { + mode = file->f_mode; + if (file->f_flags & O_NDELAY) + mode |= FMODE_NDELAY_NOW; + } + + if (disk->fops->__unlocked_ioctl) + return disk->fops->__unlocked_ioctl(file, cmd, arg); - if (disk->fops->ioctl) { + if (disk->fops->__ioctl) { lock_kernel(); - ret = disk->fops->ioctl(inode, file, cmd, arg); + ret = disk->fops->__ioctl(inode, file, cmd, arg); unlock_kernel(); return ret; } - return -ENOTTY; + return __blkdev_driver_ioctl(inode->i_bdev, mode, cmd, arg); } EXPORT_SYMBOL_GPL(blkdev_driver_ioctl); @@ -295,12 +302,22 @@ int __blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, fake_file.f_path.dentry = &fake_dentry; fake_dentry.d_inode = bdev->bd_inode; - if (disk->fops->unlocked_ioctl) - return disk->fops->unlocked_ioctl(&fake_file, cmd, arg); + if (disk->fops->__unlocked_ioctl) + return disk->fops->__unlocked_ioctl(&fake_file, cmd, arg); + + if (disk->fops->__ioctl) { + lock_kernel(); + ret = disk->fops->__ioctl(bdev->bd_inode, &fake_file, cmd, arg); + unlock_kernel(); + return ret; + } + + if (disk->fops->ioctl) + return disk->fops->ioctl(bdev, mode, cmd, arg); - if (disk->fops->ioctl) { + if (disk->fops->locked_ioctl) { lock_kernel(); - ret = disk->fops->ioctl(bdev->bd_inode, &fake_file, cmd, arg); + ret = disk->fops->locked_ioctl(bdev, mode, cmd, arg); unlock_kernel(); return ret; } diff --git a/drivers/block/DAC960.c b/drivers/block/DAC960.c index a002a381df9..4b90ebfa667 100644 --- a/drivers/block/DAC960.c +++ b/drivers/block/DAC960.c @@ -153,7 +153,7 @@ static int DAC960_revalidate_disk(struct gendisk *disk) static struct block_device_operations DAC960_BlockDeviceOperations = { .owner = THIS_MODULE, - .open = DAC960_open, + .__open = DAC960_open, .getgeo = DAC960_getgeo, .media_changed = DAC960_media_changed, .revalidate_disk = DAC960_revalidate_disk, diff --git a/drivers/block/amiflop.c b/drivers/block/amiflop.c index d19c5a939fe..d5da4e3cb2a 100644 --- a/drivers/block/amiflop.c +++ b/drivers/block/amiflop.c @@ -1648,9 +1648,9 @@ static int amiga_floppy_change(struct gendisk *disk) static struct block_device_operations floppy_fops = { .owner = THIS_MODULE, - .open = floppy_open, - .release = floppy_release, - .ioctl = fd_ioctl, + .__open = floppy_open, + .__release = floppy_release, + .__ioctl = fd_ioctl, .getgeo = fd_getgeo, .media_changed = amiga_floppy_change, }; diff --git a/drivers/block/aoe/aoeblk.c b/drivers/block/aoe/aoeblk.c index d876ad86123..d4d9796d5dd 100644 --- a/drivers/block/aoe/aoeblk.c +++ b/drivers/block/aoe/aoeblk.c @@ -239,8 +239,8 @@ aoeblk_getgeo(struct block_device *bdev, struct hd_geometry *geo) } static struct block_device_operations aoe_bdops = { - .open = aoeblk_open, - .release = aoeblk_release, + .__open = aoeblk_open, + .__release = aoeblk_release, .getgeo = aoeblk_getgeo, .owner = THIS_MODULE, }; diff --git a/drivers/block/ataflop.c b/drivers/block/ataflop.c index 85d56a26f7c..30166774327 100644 --- a/drivers/block/ataflop.c +++ b/drivers/block/ataflop.c @@ -1857,9 +1857,9 @@ static int floppy_release( struct inode * inode, struct file * filp ) static struct block_device_operations floppy_fops = { .owner = THIS_MODULE, - .open = floppy_open, - .release = floppy_release, - .ioctl = fd_ioctl, + .__open = floppy_open, + .__release = floppy_release, + .__ioctl = fd_ioctl, .media_changed = check_floppy_change, .revalidate_disk= floppy_revalidate, }; diff --git a/drivers/block/brd.c b/drivers/block/brd.c index d070d492e38..2ea99f94766 100644 --- a/drivers/block/brd.c +++ b/drivers/block/brd.c @@ -376,7 +376,7 @@ static int brd_ioctl(struct inode *inode, struct file *file, static struct block_device_operations brd_fops = { .owner = THIS_MODULE, - .ioctl = brd_ioctl, + .__ioctl = brd_ioctl, #ifdef CONFIG_BLK_DEV_XIP .direct_access = brd_direct_access, #endif diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c index d9b1c15b811..781b745181d 100644 --- a/drivers/block/cciss.c +++ b/drivers/block/cciss.c @@ -197,12 +197,12 @@ static long cciss_compat_ioctl(struct file *f, unsigned cmd, unsigned long arg); static struct block_device_operations cciss_fops = { .owner = THIS_MODULE, - .open = cciss_open, - .release = cciss_release, - .ioctl = cciss_ioctl, + .__open = cciss_open, + .__release = cciss_release, + .__ioctl = cciss_ioctl, .getgeo = cciss_getgeo, #ifdef CONFIG_COMPAT - .compat_ioctl = cciss_compat_ioctl, + .__compat_ioctl = cciss_compat_ioctl, #endif .revalidate_disk = cciss_revalidate, }; diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c index 3d967525e9a..b71334b968b 100644 --- a/drivers/block/cpqarray.c +++ b/drivers/block/cpqarray.c @@ -195,9 +195,9 @@ static inline ctlr_info_t *get_host(struct gendisk *disk) static struct block_device_operations ida_fops = { .owner = THIS_MODULE, - .open = ida_open, - .release = ida_release, - .ioctl = ida_ioctl, + .__open = ida_open, + .__release = ida_release, + .__ioctl = ida_ioctl, .getgeo = ida_getgeo, .revalidate_disk= ida_revalidate, }; diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c index 5d60c05a736..72363df5895 100644 --- a/drivers/block/floppy.c +++ b/drivers/block/floppy.c @@ -3902,9 +3902,9 @@ static int floppy_revalidate(struct gendisk *disk) static struct block_device_operations floppy_fops = { .owner = THIS_MODULE, - .open = floppy_open, - .release = floppy_release, - .ioctl = fd_ioctl, + .__open = floppy_open, + .__release = floppy_release, + .__ioctl = fd_ioctl, .getgeo = fd_getgeo, .media_changed = check_floppy_change, .revalidate_disk = floppy_revalidate, diff --git a/drivers/block/loop.c b/drivers/block/loop.c index d3a25b027ff..6faca2b7ae3 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -1355,11 +1355,11 @@ static int lo_release(struct inode *inode, struct file *file) static struct block_device_operations lo_fops = { .owner = THIS_MODULE, - .open = lo_open, - .release = lo_release, - .ioctl = lo_ioctl, + .__open = lo_open, + .__release = lo_release, + .__ioctl = lo_ioctl, #ifdef CONFIG_COMPAT - .compat_ioctl = lo_compat_ioctl, + .__compat_ioctl = lo_compat_ioctl, #endif }; diff --git a/drivers/block/nbd.c b/drivers/block/nbd.c index 9034ca585af..36015e0945b 100644 --- a/drivers/block/nbd.c +++ b/drivers/block/nbd.c @@ -691,7 +691,7 @@ static int nbd_ioctl(struct inode *inode, struct file *file, static struct block_device_operations nbd_fops = { .owner = THIS_MODULE, - .ioctl = nbd_ioctl, + .__ioctl = nbd_ioctl, }; /* diff --git a/drivers/block/paride/pcd.c b/drivers/block/paride/pcd.c index 8bd557e2a65..6e6dcc1d432 100644 --- a/drivers/block/paride/pcd.c +++ b/drivers/block/paride/pcd.c @@ -252,9 +252,9 @@ static int pcd_block_media_changed(struct gendisk *disk) static struct block_device_operations pcd_bdops = { .owner = THIS_MODULE, - .open = pcd_block_open, - .release = pcd_block_release, - .ioctl = pcd_block_ioctl, + .__open = pcd_block_open, + .__release = pcd_block_release, + .__ioctl = pcd_block_ioctl, .media_changed = pcd_block_media_changed, }; diff --git a/drivers/block/paride/pd.c b/drivers/block/paride/pd.c index 5fdfa7c888c..b3023844947 100644 --- a/drivers/block/paride/pd.c +++ b/drivers/block/paride/pd.c @@ -807,9 +807,9 @@ static int pd_revalidate(struct gendisk *p) static struct block_device_operations pd_fops = { .owner = THIS_MODULE, - .open = pd_open, - .release = pd_release, - .ioctl = pd_ioctl, + .__open = pd_open, + .__release = pd_release, + .__ioctl = pd_ioctl, .getgeo = pd_getgeo, .media_changed = pd_check_media, .revalidate_disk= pd_revalidate diff --git a/drivers/block/paride/pf.c b/drivers/block/paride/pf.c index a902d84fd33..e08ca5161ad 100644 --- a/drivers/block/paride/pf.c +++ b/drivers/block/paride/pf.c @@ -264,9 +264,9 @@ static char *pf_buf; /* buffer for request in progress */ static struct block_device_operations pf_fops = { .owner = THIS_MODULE, - .open = pf_open, - .release = pf_release, - .ioctl = pf_ioctl, + .__open = pf_open, + .__release = pf_release, + .__ioctl = pf_ioctl, .getgeo = pf_getgeo, .media_changed = pf_check_media, }; diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index a0ba4023953..33ac8ddf491 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -2847,9 +2847,9 @@ static int pkt_media_changed(struct gendisk *disk) static struct block_device_operations pktcdvd_ops = { .owner = THIS_MODULE, - .open = pkt_open, - .release = pkt_close, - .ioctl = pkt_ioctl, + .__open = pkt_open, + .__release = pkt_close, + .__ioctl = pkt_ioctl, .media_changed = pkt_media_changed, }; diff --git a/drivers/block/swim3.c b/drivers/block/swim3.c index 5c45d5556ae..9398af86a7a 100644 --- a/drivers/block/swim3.c +++ b/drivers/block/swim3.c @@ -998,9 +998,9 @@ static int floppy_revalidate(struct gendisk *disk) } static struct block_device_operations floppy_fops = { - .open = floppy_open, - .release = floppy_release, - .ioctl = floppy_ioctl, + .__open = floppy_open, + .__release = floppy_release, + .__ioctl = floppy_ioctl, .media_changed = floppy_check_change, .revalidate_disk= floppy_revalidate, }; diff --git a/drivers/block/ub.c b/drivers/block/ub.c index bc04330f368..5261773407d 100644 --- a/drivers/block/ub.c +++ b/drivers/block/ub.c @@ -1791,9 +1791,9 @@ static int ub_bd_media_changed(struct gendisk *disk) static struct block_device_operations ub_bd_fops = { .owner = THIS_MODULE, - .open = ub_bd_open, - .release = ub_bd_release, - .ioctl = ub_bd_ioctl, + .__open = ub_bd_open, + .__release = ub_bd_release, + .__ioctl = ub_bd_ioctl, .media_changed = ub_bd_media_changed, .revalidate_disk = ub_bd_revalidate, }; diff --git a/drivers/block/viodasd.c b/drivers/block/viodasd.c index 1730d29e604..7f7beec29eb 100644 --- a/drivers/block/viodasd.c +++ b/drivers/block/viodasd.c @@ -221,8 +221,8 @@ static int viodasd_getgeo(struct block_device *bdev, struct hd_geometry *geo) */ static struct block_device_operations viodasd_fops = { .owner = THIS_MODULE, - .open = viodasd_open, - .release = viodasd_release, + .__open = viodasd_open, + .__release = viodasd_release, .getgeo = viodasd_getgeo, }; diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 7643cd16fd6..10f157ea7b0 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -180,7 +180,7 @@ static int virtblk_getgeo(struct block_device *bd, struct hd_geometry *geo) } static struct block_device_operations virtblk_fops = { - .ioctl = virtblk_ioctl, + .__ioctl = virtblk_ioctl, .owner = THIS_MODULE, .getgeo = virtblk_getgeo, }; diff --git a/drivers/block/xd.c b/drivers/block/xd.c index 624d30f7da3..316fa1da4b9 100644 --- a/drivers/block/xd.c +++ b/drivers/block/xd.c @@ -132,7 +132,7 @@ static int xd_getgeo(struct block_device *bdev, struct hd_geometry *geo); static struct block_device_operations xd_fops = { .owner = THIS_MODULE, - .ioctl = xd_ioctl, + .__ioctl = xd_ioctl, .getgeo = xd_getgeo, }; static DECLARE_WAIT_QUEUE_HEAD(xd_wait_int); diff --git a/drivers/block/xen-blkfront.c b/drivers/block/xen-blkfront.c index 1a50ae70f71..7efac80c8dd 100644 --- a/drivers/block/xen-blkfront.c +++ b/drivers/block/xen-blkfront.c @@ -1041,8 +1041,8 @@ static int blkif_release(struct inode *inode, struct file *filep) static struct block_device_operations xlvbd_block_fops = { .owner = THIS_MODULE, - .open = blkif_open, - .release = blkif_release, + .__open = blkif_open, + .__release = blkif_release, .getgeo = blkif_getgeo, .ioctl = blkif_ioctl, }; diff --git a/drivers/block/xsysace.c b/drivers/block/xsysace.c index 4a7a059ebaf..e4efe5b7ec2 100644 --- a/drivers/block/xsysace.c +++ b/drivers/block/xsysace.c @@ -919,8 +919,8 @@ static int ace_getgeo(struct block_device *bdev, struct hd_geometry *geo) static struct block_device_operations ace_fops = { .owner = THIS_MODULE, - .open = ace_open, - .release = ace_release, + .__open = ace_open, + .__release = ace_release, .media_changed = ace_media_changed, .revalidate_disk = ace_revalidate_disk, .getgeo = ace_getgeo, diff --git a/drivers/block/z2ram.c b/drivers/block/z2ram.c index be20a67f1fa..4860d0f3687 100644 --- a/drivers/block/z2ram.c +++ b/drivers/block/z2ram.c @@ -314,8 +314,8 @@ z2_release( struct inode *inode, struct file *filp ) static struct block_device_operations z2_fops = { .owner = THIS_MODULE, - .open = z2_open, - .release = z2_release, + .__open = z2_open, + .__release = z2_release, }; static struct kobject *z2_find(dev_t dev, int *part, void *data) diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c index 0959edf2afd..ab0c637f58b 100644 --- a/drivers/cdrom/gdrom.c +++ b/drivers/cdrom/gdrom.c @@ -514,10 +514,10 @@ static int gdrom_bdops_ioctl(struct inode *inode, struct file *file, static struct block_device_operations gdrom_bdops = { .owner = THIS_MODULE, - .open = gdrom_bdops_open, - .release = gdrom_bdops_release, + .__open = gdrom_bdops_open, + .__release = gdrom_bdops_release, .media_changed = gdrom_bdops_mediachanged, - .ioctl = gdrom_bdops_ioctl, + .__ioctl = gdrom_bdops_ioctl, }; static irqreturn_t gdrom_command_interrupt(int irq, void *dev_id) diff --git a/drivers/cdrom/viocd.c b/drivers/cdrom/viocd.c index abc4079c3f4..57c2dced3e9 100644 --- a/drivers/cdrom/viocd.c +++ b/drivers/cdrom/viocd.c @@ -180,9 +180,9 @@ static int viocd_blk_media_changed(struct gendisk *disk) struct block_device_operations viocd_fops = { .owner = THIS_MODULE, - .open = viocd_blk_open, - .release = viocd_blk_release, - .ioctl = viocd_blk_ioctl, + .__open = viocd_blk_open, + .__release = viocd_blk_release, + .__ioctl = viocd_blk_ioctl, .media_changed = viocd_blk_media_changed, }; diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c index 87d90200b16..3533984355a 100644 --- a/drivers/ide/ide-cd.c +++ b/drivers/ide/ide-cd.c @@ -2200,9 +2200,9 @@ static int idecd_revalidate_disk(struct gendisk *disk) static struct block_device_operations idecd_ops = { .owner = THIS_MODULE, - .open = idecd_open, - .release = idecd_release, - .ioctl = idecd_ioctl, + .__open = idecd_open, + .__release = idecd_release, + .__ioctl = idecd_ioctl, .media_changed = idecd_media_changed, .revalidate_disk = idecd_revalidate_disk }; diff --git a/drivers/ide/ide-gd.c b/drivers/ide/ide-gd.c index 948af08abe2..d118bbed7cd 100644 --- a/drivers/ide/ide-gd.c +++ b/drivers/ide/ide-gd.c @@ -298,9 +298,9 @@ static int ide_gd_ioctl(struct inode *inode, struct file *file, static struct block_device_operations ide_gd_ops = { .owner = THIS_MODULE, - .open = ide_gd_open, - .release = ide_gd_release, - .ioctl = ide_gd_ioctl, + .__open = ide_gd_open, + .__release = ide_gd_release, + .__ioctl = ide_gd_ioctl, .getgeo = ide_gd_getgeo, .media_changed = ide_gd_media_changed, .revalidate_disk = ide_gd_revalidate_disk diff --git a/drivers/ide/ide-tape.c b/drivers/ide/ide-tape.c index 2b263281ffe..c5df53c4838 100644 --- a/drivers/ide/ide-tape.c +++ b/drivers/ide/ide-tape.c @@ -2376,9 +2376,9 @@ static int idetape_ioctl(struct inode *inode, struct file *file, static struct block_device_operations idetape_block_ops = { .owner = THIS_MODULE, - .open = idetape_open, - .release = idetape_release, - .ioctl = idetape_ioctl, + .__open = idetape_open, + .__release = idetape_release, + .__ioctl = idetape_ioctl, }; static int ide_tape_probe(ide_drive_t *drive) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index 5f0f4c8bcd3..8b4c92b1b6d 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1698,9 +1698,9 @@ int dm_noflush_suspending(struct dm_target *ti) EXPORT_SYMBOL_GPL(dm_noflush_suspending); static struct block_device_operations dm_blk_dops = { - .open = dm_blk_open, - .release = dm_blk_close, - .ioctl = dm_blk_ioctl, + .__open = dm_blk_open, + .__release = dm_blk_close, + .__ioctl = dm_blk_ioctl, .getgeo = dm_blk_getgeo, .owner = THIS_MODULE }; diff --git a/drivers/md/md.c b/drivers/md/md.c index aaa3d465de4..21b04d39ba3 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -5046,9 +5046,9 @@ static int md_revalidate(struct gendisk *disk) static struct block_device_operations md_fops = { .owner = THIS_MODULE, - .open = md_open, - .release = md_release, - .ioctl = md_ioctl, + .__open = md_open, + .__release = md_release, + .__ioctl = md_ioctl, .getgeo = md_getgeo, .media_changed = md_media_changed, .revalidate_disk= md_revalidate, diff --git a/drivers/memstick/core/mspro_block.c b/drivers/memstick/core/mspro_block.c index 5263913e0c6..fbe5919789d 100644 --- a/drivers/memstick/core/mspro_block.c +++ b/drivers/memstick/core/mspro_block.c @@ -237,8 +237,8 @@ static int mspro_block_bd_getgeo(struct block_device *bdev, } static struct block_device_operations ms_block_bdops = { - .open = mspro_block_bd_open, - .release = mspro_block_bd_release, + .__open = mspro_block_bd_open, + .__release = mspro_block_bd_release, .getgeo = mspro_block_bd_getgeo, .owner = THIS_MODULE }; diff --git a/drivers/message/i2o/i2o_block.c b/drivers/message/i2o/i2o_block.c index 81483de8c0f..71500dda8eb 100644 --- a/drivers/message/i2o/i2o_block.c +++ b/drivers/message/i2o/i2o_block.c @@ -931,9 +931,9 @@ static void i2o_block_request_fn(struct request_queue *q) /* I2O Block device operations definition */ static struct block_device_operations i2o_block_fops = { .owner = THIS_MODULE, - .open = i2o_block_open, - .release = i2o_block_release, - .ioctl = i2o_block_ioctl, + .__open = i2o_block_open, + .__release = i2o_block_release, + .__ioctl = i2o_block_ioctl, .getgeo = i2o_block_getgeo, .media_changed = i2o_block_media_changed }; diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c index 24c97d3d16b..8cba06f5e11 100644 --- a/drivers/mmc/card/block.c +++ b/drivers/mmc/card/block.c @@ -130,8 +130,8 @@ mmc_blk_getgeo(struct block_device *bdev, struct hd_geometry *geo) } static struct block_device_operations mmc_bdops = { - .open = mmc_blk_open, - .release = mmc_blk_release, + .__open = mmc_blk_open, + .__release = mmc_blk_release, .getgeo = mmc_blk_getgeo, .owner = THIS_MODULE, }; diff --git a/drivers/mtd/mtd_blkdevs.c b/drivers/mtd/mtd_blkdevs.c index 681d5aca2af..b00d07c5375 100644 --- a/drivers/mtd/mtd_blkdevs.c +++ b/drivers/mtd/mtd_blkdevs.c @@ -213,9 +213,9 @@ static int blktrans_ioctl(struct inode *inode, struct file *file, static struct block_device_operations mtd_blktrans_ops = { .owner = THIS_MODULE, - .open = blktrans_open, - .release = blktrans_release, - .ioctl = blktrans_ioctl, + .__open = blktrans_open, + .__release = blktrans_release, + .__ioctl = blktrans_ioctl, .getgeo = blktrans_getgeo, }; diff --git a/drivers/s390/block/dasd.c b/drivers/s390/block/dasd.c index 0a225ccda02..6bf68e5fe89 100644 --- a/drivers/s390/block/dasd.c +++ b/drivers/s390/block/dasd.c @@ -2087,10 +2087,10 @@ static int dasd_getgeo(struct block_device *bdev, struct hd_geometry *geo) struct block_device_operations dasd_device_operations = { .owner = THIS_MODULE, - .open = dasd_open, - .release = dasd_release, - .ioctl = dasd_ioctl, - .compat_ioctl = dasd_compat_ioctl, + .__open = dasd_open, + .__release = dasd_release, + .__ioctl = dasd_ioctl, + .__compat_ioctl = dasd_compat_ioctl, .getgeo = dasd_getgeo, }; diff --git a/drivers/s390/block/dcssblk.c b/drivers/s390/block/dcssblk.c index a7ff167d5b8..413460cc3dd 100644 --- a/drivers/s390/block/dcssblk.c +++ b/drivers/s390/block/dcssblk.c @@ -42,8 +42,8 @@ static char dcssblk_segments[DCSSBLK_PARM_LEN] = "\0"; static int dcssblk_major; static struct block_device_operations dcssblk_devops = { .owner = THIS_MODULE, - .open = dcssblk_open, - .release = dcssblk_release, + .__open = dcssblk_open, + .__release = dcssblk_release, .direct_access = dcssblk_direct_access, }; diff --git a/drivers/s390/char/tape_block.c b/drivers/s390/char/tape_block.c index a25b8bf54f4..f1a741c9a6f 100644 --- a/drivers/s390/char/tape_block.c +++ b/drivers/s390/char/tape_block.c @@ -52,9 +52,9 @@ static int tapeblock_revalidate_disk(struct gendisk *); static struct block_device_operations tapeblock_fops = { .owner = THIS_MODULE, - .open = tapeblock_open, - .release = tapeblock_release, - .ioctl = tapeblock_ioctl, + .__open = tapeblock_open, + .__release = tapeblock_release, + .__ioctl = tapeblock_ioctl, .media_changed = tapeblock_medium_changed, .revalidate_disk = tapeblock_revalidate_disk, }; diff --git a/drivers/scsi/ide-scsi.c b/drivers/scsi/ide-scsi.c index 5bcc04e82c2..9069afbad9d 100644 --- a/drivers/scsi/ide-scsi.c +++ b/drivers/scsi/ide-scsi.c @@ -483,9 +483,9 @@ static int idescsi_ide_ioctl(struct inode *inode, struct file *file, static struct block_device_operations idescsi_ops = { .owner = THIS_MODULE, - .open = idescsi_ide_open, - .release = idescsi_ide_release, - .ioctl = idescsi_ide_ioctl, + .__open = idescsi_ide_open, + .__release = idescsi_ide_release, + .__ioctl = idescsi_ide_ioctl, }; static int idescsi_slave_configure(struct scsi_device * sdp) diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 5a18528a69d..c8b95e8d285 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -962,12 +962,12 @@ static long sd_compat_ioctl(struct file *file, unsigned int cmd, unsigned long a static struct block_device_operations sd_fops = { .owner = THIS_MODULE, - .open = sd_open, - .release = sd_release, - .ioctl = sd_ioctl, + .__open = sd_open, + .__release = sd_release, + .__ioctl = sd_ioctl, .getgeo = sd_getgeo, #ifdef CONFIG_COMPAT - .compat_ioctl = sd_compat_ioctl, + .__compat_ioctl = sd_compat_ioctl, #endif .media_changed = sd_media_changed, .revalidate_disk = sd_revalidate_disk, diff --git a/drivers/scsi/sr.c b/drivers/scsi/sr.c index 2fb8d4d2d6f..9446cbf4de8 100644 --- a/drivers/scsi/sr.c +++ b/drivers/scsi/sr.c @@ -540,9 +540,9 @@ static int sr_block_media_changed(struct gendisk *disk) static struct block_device_operations sr_bdops = { .owner = THIS_MODULE, - .open = sr_block_open, - .release = sr_block_release, - .ioctl = sr_block_ioctl, + .__open = sr_block_open, + .__release = sr_block_release, + .__ioctl = sr_block_ioctl, .media_changed = sr_block_media_changed, /* * No compat_ioctl for now because sr_block_ioctl never diff --git a/fs/block_dev.c b/fs/block_dev.c index b9022694e9f..73b6ce47c86 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1033,8 +1033,13 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part) bdev->bd_contains = bdev; if (!partno) { struct backing_dev_info *bdi; + if (disk->fops->__open) { + ret = disk->fops->__open(bdev->bd_inode, file); + if (ret) + goto out_first; + } if (disk->fops->open) { - ret = disk->fops->open(bdev->bd_inode, file); + ret = disk->fops->open(bdev, file->f_mode); if (ret) goto out_clear; } @@ -1074,8 +1079,13 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part) part = NULL; disk = NULL; if (bdev->bd_contains == bdev) { + if (bdev->bd_disk->fops->__open) { + ret = bdev->bd_disk->fops->__open(bdev->bd_inode, file); + if (ret) + goto out; + } if (bdev->bd_disk->fops->open) { - ret = bdev->bd_disk->fops->open(bdev->bd_inode, file); + ret = bdev->bd_disk->fops->open(bdev, file->f_mode); if (ret) goto out_unlock_bdev; } @@ -1184,8 +1194,10 @@ static int __blkdev_put(struct block_device *bdev, int for_part) kill_bdev(bdev); } if (bdev->bd_contains == bdev) { + if (disk->fops->__release) + ret = disk->fops->__release(bd_inode, NULL); if (disk->fops->release) - ret = disk->fops->release(bd_inode, NULL); + ret = disk->fops->release(disk, 0); } if (!bdev->bd_openers) { struct module *owner = disk->fops->owner; diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 2bad616b994..b573186ff1a 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1061,11 +1061,16 @@ struct file; struct inode; struct block_device_operations { - int (*open) (struct inode *, struct file *); - int (*release) (struct inode *, struct file *); - int (*ioctl) (struct inode *, struct file *, unsigned, unsigned long); - long (*unlocked_ioctl) (struct file *, unsigned, unsigned long); - long (*compat_ioctl) (struct file *, unsigned, unsigned long); + int (*__open) (struct inode *, struct file *); + int (*__release) (struct inode *, struct file *); + int (*__ioctl) (struct inode *, struct file *, unsigned, unsigned long); + long (*__unlocked_ioctl) (struct file *, unsigned, unsigned long); + long (*__compat_ioctl) (struct file *, unsigned, unsigned long); + int (*open) (struct block_device *, fmode_t); + int (*release) (struct gendisk *, fmode_t); + int (*locked_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long); + int (*ioctl) (struct block_device *, fmode_t, unsigned, unsigned long); + int (*compat_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long); int (*direct_access) (struct block_device *, sector_t, void **, unsigned long *); int (*media_changed) (struct gendisk *); diff --git a/include/linux/fs.h b/include/linux/fs.h index 58bbf689fef..b5894604ba5 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -79,6 +79,7 @@ extern int dir_notify_enable; #define FMODE_NDELAY ((__force fmode_t)32) #define FMODE_EXCL ((__force fmode_t)64) #define FMODE_WRITE_IOCTL ((__force fmode_t)128) +#define FMODE_NDELAY_NOW ((__force fmode_t)256) #define RW_MASK 1 #define RWA_MASK 2 -- cgit v1.2.3-70-g09d2 From 90b8f2824ce68dd87d304641a1d5a048dfff39f5 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Sun, 2 Mar 2008 10:43:36 -0500 Subject: [PATCH] end of methods switch: remove the old ones Signed-off-by: Al Viro --- block/compat_ioctl.c | 12 ------------ block/ioctl.c | 26 -------------------------- fs/block_dev.c | 13 ------------- include/linux/blkdev.h | 8 -------- 4 files changed, 59 deletions(-) (limited to 'fs') diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index 576c4fd1546..fd537fdb25a 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -708,16 +708,6 @@ static int compat_blkdev_driver_ioctl(struct inode *inode, struct file *file, return -ENOIOCTLCMD; } - if (disk->fops->__unlocked_ioctl) - return disk->fops->__unlocked_ioctl(file, cmd, arg); - - if (disk->fops->__ioctl) { - lock_kernel(); - ret = disk->fops->__ioctl(inode, file, cmd, arg); - unlock_kernel(); - return ret; - } - return __blkdev_driver_ioctl(inode->i_bdev, file->f_mode, cmd, arg); } @@ -805,8 +795,6 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) lock_kernel(); ret = compat_blkdev_locked_ioctl(inode, file, bdev, cmd, arg); - if (ret == -ENOIOCTLCMD && disk->fops->__compat_ioctl) - ret = disk->fops->__compat_ioctl(file, cmd, arg); unlock_kernel(); if (ret == -ENOIOCTLCMD && disk->fops->compat_ioctl) ret = disk->fops->compat_ioctl(bdev, file->f_mode, cmd, arg); diff --git a/block/ioctl.c b/block/ioctl.c index 01ff463bc80..0db89f95b15 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -276,16 +276,6 @@ int blkdev_driver_ioctl(struct inode *inode, struct file *file, mode |= FMODE_NDELAY_NOW; } - if (disk->fops->__unlocked_ioctl) - return disk->fops->__unlocked_ioctl(file, cmd, arg); - - if (disk->fops->__ioctl) { - lock_kernel(); - ret = disk->fops->__ioctl(inode, file, cmd, arg); - unlock_kernel(); - return ret; - } - return __blkdev_driver_ioctl(inode->i_bdev, mode, cmd, arg); } EXPORT_SYMBOL_GPL(blkdev_driver_ioctl); @@ -295,22 +285,6 @@ int __blkdev_driver_ioctl(struct block_device *bdev, fmode_t mode, { struct gendisk *disk = bdev->bd_disk; int ret; - /* you bet it'll go away by the end of patch series */ - struct file fake_file = {}; - struct dentry fake_dentry = {}; - fake_file.f_mode = mode; - fake_file.f_path.dentry = &fake_dentry; - fake_dentry.d_inode = bdev->bd_inode; - - if (disk->fops->__unlocked_ioctl) - return disk->fops->__unlocked_ioctl(&fake_file, cmd, arg); - - if (disk->fops->__ioctl) { - lock_kernel(); - ret = disk->fops->__ioctl(bdev->bd_inode, &fake_file, cmd, arg); - unlock_kernel(); - return ret; - } if (disk->fops->ioctl) return disk->fops->ioctl(bdev, mode, cmd, arg); diff --git a/fs/block_dev.c b/fs/block_dev.c index 73b6ce47c86..55124ac8c7a 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1033,11 +1033,6 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part) bdev->bd_contains = bdev; if (!partno) { struct backing_dev_info *bdi; - if (disk->fops->__open) { - ret = disk->fops->__open(bdev->bd_inode, file); - if (ret) - goto out_first; - } if (disk->fops->open) { ret = disk->fops->open(bdev, file->f_mode); if (ret) @@ -1079,11 +1074,6 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part) part = NULL; disk = NULL; if (bdev->bd_contains == bdev) { - if (bdev->bd_disk->fops->__open) { - ret = bdev->bd_disk->fops->__open(bdev->bd_inode, file); - if (ret) - goto out; - } if (bdev->bd_disk->fops->open) { ret = bdev->bd_disk->fops->open(bdev, file->f_mode); if (ret) @@ -1180,7 +1170,6 @@ static int blkdev_open(struct inode * inode, struct file * filp) static int __blkdev_put(struct block_device *bdev, int for_part) { int ret = 0; - struct inode *bd_inode = bdev->bd_inode; struct gendisk *disk = bdev->bd_disk; struct block_device *victim = NULL; @@ -1194,8 +1183,6 @@ static int __blkdev_put(struct block_device *bdev, int for_part) kill_bdev(bdev); } if (bdev->bd_contains == bdev) { - if (disk->fops->__release) - ret = disk->fops->__release(bd_inode, NULL); if (disk->fops->release) ret = disk->fops->release(disk, 0); } diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index b573186ff1a..a135256b272 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1057,15 +1057,7 @@ static inline int blk_integrity_rq(struct request *rq) #endif /* CONFIG_BLK_DEV_INTEGRITY */ -struct file; -struct inode; - struct block_device_operations { - int (*__open) (struct inode *, struct file *); - int (*__release) (struct inode *, struct file *); - int (*__ioctl) (struct inode *, struct file *, unsigned, unsigned long); - long (*__unlocked_ioctl) (struct file *, unsigned, unsigned long); - long (*__compat_ioctl) (struct file *, unsigned, unsigned long); int (*open) (struct block_device *, fmode_t); int (*release) (struct gendisk *, fmode_t); int (*locked_ioctl) (struct block_device *, fmode_t, unsigned, unsigned long); -- cgit v1.2.3-70-g09d2 From 9a1c3542768b5a58e45a9216921cd10a3bae1205 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Fri, 22 Feb 2008 20:40:24 -0500 Subject: [PATCH] pass fmode_t to blkdev_put() Signed-off-by: Al Viro --- drivers/block/pktcdvd.c | 8 ++++---- drivers/char/raw.c | 4 ++-- drivers/md/dm-table.c | 4 ++-- drivers/md/md.c | 4 ++-- drivers/s390/block/dasd_genhd.c | 2 +- fs/block_dev.c | 22 +++++++++++----------- fs/ext3/super.c | 4 ++-- fs/ext4/super.c | 4 ++-- fs/jfs/jfs_logmgr.c | 4 ++-- fs/ocfs2/cluster/heartbeat.c | 4 ++-- fs/partitions/check.c | 2 +- fs/reiserfs/journal.c | 4 ++-- include/linux/fs.h | 2 +- kernel/power/swap.c | 8 ++++---- 14 files changed, 38 insertions(+), 38 deletions(-) (limited to 'fs') diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index 90548da9c1c..ce8c7190192 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -2381,7 +2381,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, fmode_t write) out_unclaim: bd_release(pd->bdev); out_putdev: - blkdev_put(pd->bdev); + blkdev_put(pd->bdev, FMODE_READ); out: return ret; } @@ -2399,7 +2399,7 @@ static void pkt_release_dev(struct pktcdvd_device *pd, int flush) pkt_set_speed(pd, MAX_SPEED, MAX_SPEED); bd_release(pd->bdev); - blkdev_put(pd->bdev); + blkdev_put(pd->bdev, FMODE_READ); pkt_shrink_pktlist(pd); } @@ -2790,7 +2790,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) return 0; out_mem: - blkdev_put(bdev); + blkdev_put(bdev, FMODE_READ|FMODE_WRITE); /* This is safe: open() is still holding a reference. */ module_put(THIS_MODULE); return ret; @@ -2975,7 +2975,7 @@ static int pkt_remove_dev(dev_t pkt_dev) pkt_debugfs_dev_remove(pd); pkt_sysfs_dev_remove(pd); - blkdev_put(pd->bdev); + blkdev_put(pd->bdev, FMODE_READ|FMODE_WRITE); remove_proc_entry(pd->name, pkt_proc); DPRINTK(DRIVER_NAME": writer %s unmapped\n", pd->name); diff --git a/drivers/char/raw.c b/drivers/char/raw.c index e139372d0e6..bfd59e6bf54 100644 --- a/drivers/char/raw.c +++ b/drivers/char/raw.c @@ -87,7 +87,7 @@ static int raw_open(struct inode *inode, struct file *filp) out2: bd_release(bdev); out1: - blkdev_put(bdev); + blkdev_put(bdev, filp->f_mode); out: mutex_unlock(&raw_mutex); return err; @@ -112,7 +112,7 @@ static int raw_release(struct inode *inode, struct file *filp) mutex_unlock(&raw_mutex); bd_release(bdev); - blkdev_put(bdev); + blkdev_put(bdev, filp->f_mode); return 0; } diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c index 7c8671b06fe..dd8bd2e867c 100644 --- a/drivers/md/dm-table.c +++ b/drivers/md/dm-table.c @@ -357,7 +357,7 @@ static int open_dev(struct dm_dev_internal *d, dev_t dev, return PTR_ERR(bdev); r = bd_claim_by_disk(bdev, _claim_ptr, dm_disk(md)); if (r) - blkdev_put(bdev); + blkdev_put(bdev, d->dm_dev.mode); else d->dm_dev.bdev = bdev; return r; @@ -372,7 +372,7 @@ static void close_dev(struct dm_dev_internal *d, struct mapped_device *md) return; bd_release_from_disk(d->dm_dev.bdev, dm_disk(md)); - blkdev_put(d->dm_dev.bdev); + blkdev_put(d->dm_dev.bdev, d->dm_dev.mode); d->dm_dev.bdev = NULL; } diff --git a/drivers/md/md.c b/drivers/md/md.c index 06ea991c7a4..c1a837ca193 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -1520,7 +1520,7 @@ static int lock_rdev(mdk_rdev_t *rdev, dev_t dev, int shared) if (err) { printk(KERN_ERR "md: could not bd_claim %s.\n", bdevname(bdev, b)); - blkdev_put(bdev); + blkdev_put(bdev, FMODE_READ|FMODE_WRITE); return err; } if (!shared) @@ -1536,7 +1536,7 @@ static void unlock_rdev(mdk_rdev_t *rdev) if (!bdev) MD_BUG(); bd_release(bdev); - blkdev_put(bdev); + blkdev_put(bdev, FMODE_READ|FMODE_WRITE); } void md_autodetect_dev(dev_t dev); diff --git a/drivers/s390/block/dasd_genhd.c b/drivers/s390/block/dasd_genhd.c index aee6565aaf9..3c1b6915c9a 100644 --- a/drivers/s390/block/dasd_genhd.c +++ b/drivers/s390/block/dasd_genhd.c @@ -152,7 +152,7 @@ void dasd_destroy_partitions(struct dasd_block *block) invalidate_partition(block->gdp, 0); /* Matching blkdev_put to the blkdev_get in dasd_scan_partitions. */ - blkdev_put(bdev); + blkdev_put(bdev, FMODE_READ); set_capacity(block->gdp, 0); } diff --git a/fs/block_dev.c b/fs/block_dev.c index 55124ac8c7a..05131baf3cf 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -977,7 +977,7 @@ EXPORT_SYMBOL(bd_set_size); static int __blkdev_get(struct block_device *bdev, fmode_t mode, unsigned flags, int for_part); -static int __blkdev_put(struct block_device *bdev, int for_part); +static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part); /* * bd_mutex locking: @@ -1095,7 +1095,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part) bdev->bd_part = NULL; bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; if (bdev != bdev->bd_contains) - __blkdev_put(bdev->bd_contains, 1); + __blkdev_put(bdev->bd_contains, file->f_mode, 1); bdev->bd_contains = NULL; out_unlock_bdev: mutex_unlock(&bdev->bd_mutex); @@ -1163,11 +1163,11 @@ static int blkdev_open(struct inode * inode, struct file * filp) if (!(res = bd_claim(bdev, filp))) return 0; - blkdev_put(bdev); + blkdev_put(bdev, filp->f_mode); return res; } -static int __blkdev_put(struct block_device *bdev, int for_part) +static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part) { int ret = 0; struct gendisk *disk = bdev->bd_disk; @@ -1184,7 +1184,7 @@ static int __blkdev_put(struct block_device *bdev, int for_part) } if (bdev->bd_contains == bdev) { if (disk->fops->release) - ret = disk->fops->release(disk, 0); + ret = disk->fops->release(disk, mode); } if (!bdev->bd_openers) { struct module *owner = disk->fops->owner; @@ -1203,13 +1203,13 @@ static int __blkdev_put(struct block_device *bdev, int for_part) mutex_unlock(&bdev->bd_mutex); bdput(bdev); if (victim) - __blkdev_put(victim, 1); + __blkdev_put(victim, mode, 1); return ret; } -int blkdev_put(struct block_device *bdev) +int blkdev_put(struct block_device *bdev, fmode_t mode) { - return __blkdev_put(bdev, 0); + return __blkdev_put(bdev, mode, 0); } EXPORT_SYMBOL(blkdev_put); @@ -1218,7 +1218,7 @@ static int blkdev_close(struct inode * inode, struct file * filp) struct block_device *bdev = I_BDEV(filp->f_mapping->host); if (bdev->bd_holder == filp) bd_release(bdev); - return blkdev_put(bdev); + return blkdev_put(bdev, filp->f_mode); } static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg) @@ -1343,7 +1343,7 @@ struct block_device *open_bdev_excl(const char *path, int flags, void *holder) return bdev; blkdev_put: - blkdev_put(bdev); + blkdev_put(bdev, mode); return ERR_PTR(error); } @@ -1359,7 +1359,7 @@ EXPORT_SYMBOL(open_bdev_excl); void close_bdev_excl(struct block_device *bdev) { bd_release(bdev); - blkdev_put(bdev); + blkdev_put(bdev, 0); /* move up in the next patches */ } EXPORT_SYMBOL(close_bdev_excl); diff --git a/fs/ext3/super.c b/fs/ext3/super.c index 3a260af5544..15c38e69b69 100644 --- a/fs/ext3/super.c +++ b/fs/ext3/super.c @@ -347,7 +347,7 @@ fail: static int ext3_blkdev_put(struct block_device *bdev) { bd_release(bdev); - return blkdev_put(bdev); + return blkdev_put(bdev, FMODE_READ|FMODE_WRITE); } static int ext3_blkdev_remove(struct ext3_sb_info *sbi) @@ -2066,7 +2066,7 @@ static journal_t *ext3_get_dev_journal(struct super_block *sb, if (bd_claim(bdev, sb)) { printk(KERN_ERR "EXT3: failed to claim external journal device.\n"); - blkdev_put(bdev); + blkdev_put(bdev, FMODE_READ|FMODE_WRITE); return NULL; } diff --git a/fs/ext4/super.c b/fs/ext4/super.c index 9b2b2bc4ec1..c12cf7a657a 100644 --- a/fs/ext4/super.c +++ b/fs/ext4/super.c @@ -399,7 +399,7 @@ fail: static int ext4_blkdev_put(struct block_device *bdev) { bd_release(bdev); - return blkdev_put(bdev); + return blkdev_put(bdev, FMODE_READ|FMODE_WRITE); } static int ext4_blkdev_remove(struct ext4_sb_info *sbi) @@ -2553,7 +2553,7 @@ static journal_t *ext4_get_dev_journal(struct super_block *sb, if (bd_claim(bdev, sb)) { printk(KERN_ERR "EXT4: failed to claim external journal device.\n"); - blkdev_put(bdev); + blkdev_put(bdev, FMODE_READ|FMODE_WRITE); return NULL; } diff --git a/fs/jfs/jfs_logmgr.c b/fs/jfs/jfs_logmgr.c index cd2ec2988b5..335c4de6552 100644 --- a/fs/jfs/jfs_logmgr.c +++ b/fs/jfs/jfs_logmgr.c @@ -1168,7 +1168,7 @@ journal_found: bd_release(bdev); close: /* close external log device */ - blkdev_put(bdev); + blkdev_put(bdev, FMODE_READ|FMODE_WRITE); free: /* free log descriptor */ mutex_unlock(&jfs_log_mutex); @@ -1514,7 +1514,7 @@ int lmLogClose(struct super_block *sb) rc = lmLogShutdown(log); bd_release(bdev); - blkdev_put(bdev); + blkdev_put(bdev, FMODE_READ|FMODE_WRITE); kfree(log); diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c index 7dce1612553..4b6fdf591ee 100644 --- a/fs/ocfs2/cluster/heartbeat.c +++ b/fs/ocfs2/cluster/heartbeat.c @@ -976,7 +976,7 @@ static void o2hb_region_release(struct config_item *item) } if (reg->hr_bdev) - blkdev_put(reg->hr_bdev); + blkdev_put(reg->hr_bdev, FMODE_READ|FMODE_WRITE); if (reg->hr_slots) kfree(reg->hr_slots); @@ -1358,7 +1358,7 @@ out: iput(inode); if (ret < 0) { if (reg->hr_bdev) { - blkdev_put(reg->hr_bdev); + blkdev_put(reg->hr_bdev, FMODE_READ|FMODE_WRITE); reg->hr_bdev = NULL; } } diff --git a/fs/partitions/check.c b/fs/partitions/check.c index cfb0c80690a..5a35ff2e1a9 100644 --- a/fs/partitions/check.c +++ b/fs/partitions/check.c @@ -488,7 +488,7 @@ void register_disk(struct gendisk *disk) err = blkdev_get(bdev, FMODE_READ, 0); if (err < 0) goto exit; - blkdev_put(bdev); + blkdev_put(bdev, FMODE_READ); exit: /* announce disk after possible partitions are created */ diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c index b89d193a00d..3261518478f 100644 --- a/fs/reiserfs/journal.c +++ b/fs/reiserfs/journal.c @@ -2575,7 +2575,7 @@ static int release_journal_dev(struct super_block *super, if (journal->j_dev_bd != NULL) { if (journal->j_dev_bd->bd_dev != super->s_dev) bd_release(journal->j_dev_bd); - result = blkdev_put(journal->j_dev_bd); + result = blkdev_put(journal->j_dev_bd, 0); /* move up */ journal->j_dev_bd = NULL; } @@ -2618,7 +2618,7 @@ static int journal_init_dev(struct super_block *super, } else if (jdev != super->s_dev) { result = bd_claim(journal->j_dev_bd, journal); if (result) { - blkdev_put(journal->j_dev_bd); + blkdev_put(journal->j_dev_bd, blkdev_mode); return result; } diff --git a/include/linux/fs.h b/include/linux/fs.h index b5894604ba5..04c8dc41f45 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1722,7 +1722,7 @@ extern int blkdev_driver_ioctl(struct inode *inode, struct file *file, unsigned long arg); extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long); extern int blkdev_get(struct block_device *, fmode_t, unsigned); -extern int blkdev_put(struct block_device *); +extern int blkdev_put(struct block_device *, fmode_t); extern int bd_claim(struct block_device *, void *); extern void bd_release(struct block_device *); #ifdef CONFIG_SYSFS diff --git a/kernel/power/swap.c b/kernel/power/swap.c index 80ccac849e4..7b9d611c110 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c @@ -178,7 +178,7 @@ static int swsusp_swap_check(void) /* This is called before saving image */ res = set_blocksize(resume_bdev, PAGE_SIZE); if (res < 0) - blkdev_put(resume_bdev); + blkdev_put(resume_bdev, FMODE_WRITE); return res; } @@ -574,7 +574,7 @@ int swsusp_read(unsigned int *flags_p) error = load_image(&handle, &snapshot, header->pages - 1); release_swap_reader(&handle); - blkdev_put(resume_bdev); + blkdev_put(resume_bdev, FMODE_READ); if (!error) pr_debug("PM: Image successfully loaded\n"); @@ -609,7 +609,7 @@ int swsusp_check(void) return -EINVAL; } if (error) - blkdev_put(resume_bdev); + blkdev_put(resume_bdev, FMODE_READ); else pr_debug("PM: Signature found, resuming\n"); } else { @@ -633,7 +633,7 @@ void swsusp_close(void) return; } - blkdev_put(resume_bdev); + blkdev_put(resume_bdev, 0); /* move up */ } static int swsusp_header_init(void) -- cgit v1.2.3-70-g09d2 From 30c40d2c01f68c7eb1a41ab3552bdaf5dbf300d4 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Fri, 22 Feb 2008 19:50:45 -0500 Subject: [PATCH] propagate mode through open_bdev_excl/close_bdev_excl replace open_bdev_excl/close_bdev_excl with variants taking fmode_t. superblock gets the value used to mount it stored in sb->s_mode Signed-off-by: Al Viro --- drivers/mtd/devices/block2mtd.c | 4 ++-- fs/block_dev.c | 24 +++++++++++------------- fs/reiserfs/journal.c | 3 ++- fs/super.c | 14 ++++++++++---- fs/xfs/linux-2.6/xfs_super.c | 4 ++-- include/linux/fs.h | 6 ++++-- 6 files changed, 31 insertions(+), 24 deletions(-) (limited to 'fs') diff --git a/drivers/mtd/devices/block2mtd.c b/drivers/mtd/devices/block2mtd.c index 91fbba76763..8c295f40d2a 100644 --- a/drivers/mtd/devices/block2mtd.c +++ b/drivers/mtd/devices/block2mtd.c @@ -224,7 +224,7 @@ static void block2mtd_free_device(struct block2mtd_dev *dev) if (dev->blkdev) { invalidate_mapping_pages(dev->blkdev->bd_inode->i_mapping, 0, -1); - close_bdev_excl(dev->blkdev); + close_bdev_exclusive(dev->blkdev, FMODE_READ|FMODE_WRITE); } kfree(dev); @@ -246,7 +246,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size) return NULL; /* Get a handle on the device */ - bdev = open_bdev_excl(devname, O_RDWR, NULL); + bdev = open_bdev_exclusive(devname, FMODE_READ|FMODE_WRITE, NULL); #ifndef MODULE if (IS_ERR(bdev)) { diff --git a/fs/block_dev.c b/fs/block_dev.c index 05131baf3cf..4b595904cef 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1309,32 +1309,29 @@ fail: EXPORT_SYMBOL(lookup_bdev); /** - * open_bdev_excl - open a block device by name and set it up for use + * open_bdev_exclusive - open a block device by name and set it up for use * * @path: special file representing the block device - * @flags: %MS_RDONLY for opening read-only + * @mode: FMODE_... combination to pass be used * @holder: owner for exclusion * * Open the blockdevice described by the special file at @path, claim it * for the @holder. */ -struct block_device *open_bdev_excl(const char *path, int flags, void *holder) +struct block_device *open_bdev_exclusive(const char *path, fmode_t mode, void *holder) { struct block_device *bdev; - fmode_t mode = FMODE_READ; int error = 0; bdev = lookup_bdev(path); if (IS_ERR(bdev)) return bdev; - if (!(flags & MS_RDONLY)) - mode |= FMODE_WRITE; error = blkdev_get(bdev, mode, 0); if (error) return ERR_PTR(error); error = -EACCES; - if (!(flags & MS_RDONLY) && bdev_read_only(bdev)) + if ((mode & FMODE_WRITE) && bdev_read_only(bdev)) goto blkdev_put; error = bd_claim(bdev, holder); if (error) @@ -1347,22 +1344,23 @@ blkdev_put: return ERR_PTR(error); } -EXPORT_SYMBOL(open_bdev_excl); +EXPORT_SYMBOL(open_bdev_exclusive); /** - * close_bdev_excl - release a blockdevice openen by open_bdev_excl() + * close_bdev_exclusive - close a blockdevice opened by open_bdev_exclusive() * * @bdev: blockdevice to close + * @mode: mode, must match that used to open. * - * This is the counterpart to open_bdev_excl(). + * This is the counterpart to open_bdev_exclusive(). */ -void close_bdev_excl(struct block_device *bdev) +void close_bdev_exclusive(struct block_device *bdev, fmode_t mode) { bd_release(bdev); - blkdev_put(bdev, 0); /* move up in the next patches */ + blkdev_put(bdev, mode); } -EXPORT_SYMBOL(close_bdev_excl); +EXPORT_SYMBOL(close_bdev_exclusive); int __invalidate_device(struct block_device *bdev) { diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c index 3261518478f..70b89607667 100644 --- a/fs/reiserfs/journal.c +++ b/fs/reiserfs/journal.c @@ -2628,7 +2628,8 @@ static int journal_init_dev(struct super_block *super, return 0; } - journal->j_dev_bd = open_bdev_excl(jdev_name, 0, journal); + journal->j_dev_bd = open_bdev_exclusive(jdev_name, + FMODE_READ|FMODE_WRITE, journal); if (IS_ERR(journal->j_dev_bd)) { result = PTR_ERR(journal->j_dev_bd); journal->j_dev_bd = NULL; diff --git a/fs/super.c b/fs/super.c index e931ae9511f..0d77ac20d03 100644 --- a/fs/super.c +++ b/fs/super.c @@ -760,9 +760,13 @@ int get_sb_bdev(struct file_system_type *fs_type, { struct block_device *bdev; struct super_block *s; + fmode_t mode = FMODE_READ; int error = 0; - bdev = open_bdev_excl(dev_name, flags, fs_type); + if (!(flags & MS_RDONLY)) + mode |= FMODE_WRITE; + + bdev = open_bdev_exclusive(dev_name, mode, fs_type); if (IS_ERR(bdev)) return PTR_ERR(bdev); @@ -785,11 +789,12 @@ int get_sb_bdev(struct file_system_type *fs_type, goto error_bdev; } - close_bdev_excl(bdev); + close_bdev_exclusive(bdev, mode); } else { char b[BDEVNAME_SIZE]; s->s_flags = flags; + s->s_mode = mode; strlcpy(s->s_id, bdevname(bdev, b), sizeof(s->s_id)); sb_set_blocksize(s, block_size(bdev)); error = fill_super(s, data, flags & MS_SILENT ? 1 : 0); @@ -807,7 +812,7 @@ int get_sb_bdev(struct file_system_type *fs_type, error_s: error = PTR_ERR(s); error_bdev: - close_bdev_excl(bdev); + close_bdev_exclusive(bdev, mode); error: return error; } @@ -817,10 +822,11 @@ EXPORT_SYMBOL(get_sb_bdev); void kill_block_super(struct super_block *sb) { struct block_device *bdev = sb->s_bdev; + fmode_t mode = sb->s_mode; generic_shutdown_super(sb); sync_blockdev(bdev); - close_bdev_excl(bdev); + close_bdev_exclusive(bdev, mode); } EXPORT_SYMBOL(kill_block_super); diff --git a/fs/xfs/linux-2.6/xfs_super.c b/fs/xfs/linux-2.6/xfs_super.c index e39013619b2..37ebe36056e 100644 --- a/fs/xfs/linux-2.6/xfs_super.c +++ b/fs/xfs/linux-2.6/xfs_super.c @@ -589,7 +589,7 @@ xfs_blkdev_get( { int error = 0; - *bdevp = open_bdev_excl(name, 0, mp); + *bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp); if (IS_ERR(*bdevp)) { error = PTR_ERR(*bdevp); printk("XFS: Invalid device [%s], error=%d\n", name, error); @@ -603,7 +603,7 @@ xfs_blkdev_put( struct block_device *bdev) { if (bdev) - close_bdev_excl(bdev); + close_bdev_exclusive(bdev, FMODE_READ|FMODE_WRITE); } /* diff --git a/include/linux/fs.h b/include/linux/fs.h index 04c8dc41f45..c6766314dc5 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1157,6 +1157,7 @@ struct super_block { char s_id[32]; /* Informational name */ void *s_fs_info; /* Filesystem private info */ + fmode_t s_mode; /* * The next field is for VFS *only*. No filesystems have any business @@ -1753,9 +1754,10 @@ extern void chrdev_show(struct seq_file *,off_t); extern const char *__bdevname(dev_t, char *buffer); extern const char *bdevname(struct block_device *bdev, char *buffer); extern struct block_device *lookup_bdev(const char *); -extern struct block_device *open_bdev_excl(const char *, int, void *); -extern void close_bdev_excl(struct block_device *); +extern struct block_device *open_bdev_exclusive(const char *, fmode_t, void *); +extern void close_bdev_exclusive(struct block_device *, fmode_t); extern void blkdev_show(struct seq_file *,off_t); + #else #define BLKDEV_MAJOR_HASH_SIZE 0 #endif -- cgit v1.2.3-70-g09d2 From e5eb8caa83a76191feb9705c1a0a689ca260b91e Mon Sep 17 00:00:00 2001 From: Al Viro Date: Mon, 8 Oct 2007 13:24:05 -0400 Subject: [PATCH] remember mode of reiserfs journal Signed-off-by: Al Viro --- fs/reiserfs/journal.c | 6 ++++-- include/linux/reiserfs_fs_sb.h | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'fs') diff --git a/fs/reiserfs/journal.c b/fs/reiserfs/journal.c index 70b89607667..9643c3bbeb3 100644 --- a/fs/reiserfs/journal.c +++ b/fs/reiserfs/journal.c @@ -2575,7 +2575,7 @@ static int release_journal_dev(struct super_block *super, if (journal->j_dev_bd != NULL) { if (journal->j_dev_bd->bd_dev != super->s_dev) bd_release(journal->j_dev_bd); - result = blkdev_put(journal->j_dev_bd, 0); /* move up */ + result = blkdev_put(journal->j_dev_bd, journal->j_dev_mode); journal->j_dev_bd = NULL; } @@ -2608,6 +2608,7 @@ static int journal_init_dev(struct super_block *super, /* there is no "jdev" option and journal is on separate device */ if ((!jdev_name || !jdev_name[0])) { journal->j_dev_bd = open_by_devnum(jdev, blkdev_mode); + journal->j_dev_mode = blkdev_mode; if (IS_ERR(journal->j_dev_bd)) { result = PTR_ERR(journal->j_dev_bd); journal->j_dev_bd = NULL; @@ -2628,8 +2629,9 @@ static int journal_init_dev(struct super_block *super, return 0; } + journal->j_dev_mode = blkdev_mode; journal->j_dev_bd = open_bdev_exclusive(jdev_name, - FMODE_READ|FMODE_WRITE, journal); + blkdev_mode, journal); if (IS_ERR(journal->j_dev_bd)) { result = PTR_ERR(journal->j_dev_bd); journal->j_dev_bd = NULL; diff --git a/include/linux/reiserfs_fs_sb.h b/include/linux/reiserfs_fs_sb.h index 315517e8bfa..bda6b562a1e 100644 --- a/include/linux/reiserfs_fs_sb.h +++ b/include/linux/reiserfs_fs_sb.h @@ -178,6 +178,7 @@ struct reiserfs_journal { struct reiserfs_journal_cnode *j_first; /* oldest journal block. start here for traverse */ struct block_device *j_dev_bd; + fmode_t j_dev_mode; int j_1st_reserved_block; /* first block on s_dev of reserved area journal */ unsigned long j_state; -- cgit v1.2.3-70-g09d2 From 572c48921574dbe6dceb958cf965aa962baefde4 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Mon, 8 Oct 2007 13:24:05 -0400 Subject: [PATCH] sanitize blkdev_get() and friends * get rid of fake struct file/struct dentry in __blkdev_get() * merge __blkdev_get() and do_open() * get rid of flags argument of blkdev_get() Signed-off-by: Al Viro --- drivers/block/pktcdvd.c | 4 +-- drivers/char/raw.c | 2 +- drivers/s390/block/dasd_genhd.c | 2 +- fs/block_dev.c | 65 ++++++++++++++--------------------------- fs/ocfs2/cluster/heartbeat.c | 2 +- fs/partitions/check.c | 2 +- include/linux/fs.h | 2 +- kernel/power/swap.c | 2 +- 8 files changed, 30 insertions(+), 51 deletions(-) (limited to 'fs') diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c index ce8c7190192..f20bf359b84 100644 --- a/drivers/block/pktcdvd.c +++ b/drivers/block/pktcdvd.c @@ -2332,7 +2332,7 @@ static int pkt_open_dev(struct pktcdvd_device *pd, fmode_t write) * so bdget() can't fail. */ bdget(pd->bdev->bd_dev); - if ((ret = blkdev_get(pd->bdev, FMODE_READ, O_RDONLY))) + if ((ret = blkdev_get(pd->bdev, FMODE_READ))) goto out; if ((ret = bd_claim(pd->bdev, pd))) @@ -2765,7 +2765,7 @@ static int pkt_new_dev(struct pktcdvd_device *pd, dev_t dev) bdev = bdget(dev); if (!bdev) return -ENOMEM; - ret = blkdev_get(bdev, FMODE_READ, O_RDONLY | O_NONBLOCK); + ret = blkdev_get(bdev, FMODE_READ | FMODE_NDELAY); if (ret) return ret; diff --git a/drivers/char/raw.c b/drivers/char/raw.c index bfd59e6bf54..f3cf5eb9b7f 100644 --- a/drivers/char/raw.c +++ b/drivers/char/raw.c @@ -65,7 +65,7 @@ static int raw_open(struct inode *inode, struct file *filp) if (!bdev) goto out; igrab(bdev->bd_inode); - err = blkdev_get(bdev, filp->f_mode, 0); + err = blkdev_get(bdev, filp->f_mode); if (err) goto out; err = bd_claim(bdev, raw_open); diff --git a/drivers/s390/block/dasd_genhd.c b/drivers/s390/block/dasd_genhd.c index 3c1b6915c9a..e99d566b69c 100644 --- a/drivers/s390/block/dasd_genhd.c +++ b/drivers/s390/block/dasd_genhd.c @@ -99,7 +99,7 @@ int dasd_scan_partitions(struct dasd_block *block) struct block_device *bdev; bdev = bdget_disk(block->gdp, 0); - if (!bdev || blkdev_get(bdev, FMODE_READ, 1) < 0) + if (!bdev || blkdev_get(bdev, FMODE_READ) < 0) return -ENODEV; /* * See fs/partition/check.c:register_disk,rescan_partitions diff --git a/fs/block_dev.c b/fs/block_dev.c index 4b595904cef..b89c956e04f 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -844,9 +844,8 @@ struct block_device *open_by_devnum(dev_t dev, fmode_t mode) { struct block_device *bdev = bdget(dev); int err = -ENOMEM; - int flags = mode & FMODE_WRITE ? O_RDWR : O_RDONLY; if (bdev) - err = blkdev_get(bdev, mode, flags); + err = blkdev_get(bdev, mode); return err ? ERR_PTR(err) : bdev; } @@ -975,8 +974,6 @@ void bd_set_size(struct block_device *bdev, loff_t size) } EXPORT_SYMBOL(bd_set_size); -static int __blkdev_get(struct block_device *bdev, fmode_t mode, unsigned flags, - int for_part); static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part); /* @@ -986,7 +983,7 @@ static int __blkdev_put(struct block_device *bdev, fmode_t mode, int for_part); * mutex_lock_nested(whole->bd_mutex, 1) */ -static int do_open(struct block_device *bdev, struct file *file, int for_part) +static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) { struct gendisk *disk; struct hd_struct *part = NULL; @@ -994,9 +991,9 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part) int partno; int perm = 0; - if (file->f_mode & FMODE_READ) + if (mode & FMODE_READ) perm |= MAY_READ; - if (file->f_mode & FMODE_WRITE) + if (mode & FMODE_WRITE) perm |= MAY_WRITE; /* * hooks: /n/, see "layering violations". @@ -1007,15 +1004,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part) return ret; } - if (file->f_flags & O_NDELAY) - file->f_mode |= FMODE_NDELAY; - if (file->f_flags & O_EXCL) - file->f_mode |= FMODE_EXCL; - if ((file->f_flags & O_ACCMODE) == 3) - file->f_mode |= FMODE_WRITE_IOCTL; - ret = -ENXIO; - file->f_mapping = bdev->bd_inode->i_mapping; lock_kernel(); @@ -1034,7 +1023,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part) if (!partno) { struct backing_dev_info *bdi; if (disk->fops->open) { - ret = disk->fops->open(bdev, file->f_mode); + ret = disk->fops->open(bdev, mode); if (ret) goto out_clear; } @@ -1054,7 +1043,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part) if (!whole) goto out_clear; BUG_ON(for_part); - ret = __blkdev_get(whole, file->f_mode, file->f_flags, 1); + ret = __blkdev_get(whole, mode, 1); if (ret) goto out_clear; bdev->bd_contains = whole; @@ -1075,7 +1064,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part) disk = NULL; if (bdev->bd_contains == bdev) { if (bdev->bd_disk->fops->open) { - ret = bdev->bd_disk->fops->open(bdev, file->f_mode); + ret = bdev->bd_disk->fops->open(bdev, mode); if (ret) goto out_unlock_bdev; } @@ -1095,7 +1084,7 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part) bdev->bd_part = NULL; bdev->bd_inode->i_data.backing_dev_info = &default_backing_dev_info; if (bdev != bdev->bd_contains) - __blkdev_put(bdev->bd_contains, file->f_mode, 1); + __blkdev_put(bdev->bd_contains, mode, 1); bdev->bd_contains = NULL; out_unlock_bdev: mutex_unlock(&bdev->bd_mutex); @@ -1111,28 +1100,9 @@ static int do_open(struct block_device *bdev, struct file *file, int for_part) return ret; } -static int __blkdev_get(struct block_device *bdev, fmode_t mode, unsigned flags, - int for_part) -{ - /* - * This crockload is due to bad choice of ->open() type. - * It will go away. - * For now, block device ->open() routine must _not_ - * examine anything in 'inode' argument except ->i_rdev. - */ - struct file fake_file = {}; - struct dentry fake_dentry = {}; - fake_file.f_mode = mode; - fake_file.f_flags = flags; - fake_file.f_path.dentry = &fake_dentry; - fake_dentry.d_inode = bdev->bd_inode; - - return do_open(bdev, &fake_file, for_part); -} - -int blkdev_get(struct block_device *bdev, fmode_t mode, unsigned flags) +int blkdev_get(struct block_device *bdev, fmode_t mode) { - return __blkdev_get(bdev, mode, flags, 0); + return __blkdev_get(bdev, mode, 0); } EXPORT_SYMBOL(blkdev_get); @@ -1149,15 +1119,24 @@ static int blkdev_open(struct inode * inode, struct file * filp) */ filp->f_flags |= O_LARGEFILE; + if (filp->f_flags & O_NDELAY) + filp->f_mode |= FMODE_NDELAY; + if (filp->f_flags & O_EXCL) + filp->f_mode |= FMODE_EXCL; + if ((filp->f_flags & O_ACCMODE) == 3) + filp->f_mode |= FMODE_WRITE_IOCTL; + bdev = bd_acquire(inode); if (bdev == NULL) return -ENOMEM; - res = do_open(bdev, filp, 0); + filp->f_mapping = bdev->bd_inode->i_mapping; + + res = blkdev_get(bdev, filp->f_mode); if (res) return res; - if (!(filp->f_flags & O_EXCL) ) + if (!(filp->f_mode & FMODE_EXCL)) return 0; if (!(res = bd_claim(bdev, filp))) @@ -1327,7 +1306,7 @@ struct block_device *open_bdev_exclusive(const char *path, fmode_t mode, void *h if (IS_ERR(bdev)) return bdev; - error = blkdev_get(bdev, mode, 0); + error = blkdev_get(bdev, mode); if (error) return ERR_PTR(error); error = -EACCES; diff --git a/fs/ocfs2/cluster/heartbeat.c b/fs/ocfs2/cluster/heartbeat.c index 4b6fdf591ee..6ebaa58e2c0 100644 --- a/fs/ocfs2/cluster/heartbeat.c +++ b/fs/ocfs2/cluster/heartbeat.c @@ -1268,7 +1268,7 @@ static ssize_t o2hb_region_dev_write(struct o2hb_region *reg, goto out; reg->hr_bdev = I_BDEV(filp->f_mapping->host); - ret = blkdev_get(reg->hr_bdev, FMODE_WRITE | FMODE_READ, 0); + ret = blkdev_get(reg->hr_bdev, FMODE_WRITE | FMODE_READ); if (ret) { reg->hr_bdev = NULL; goto out; diff --git a/fs/partitions/check.c b/fs/partitions/check.c index 5a35ff2e1a9..633f7a0ebb2 100644 --- a/fs/partitions/check.c +++ b/fs/partitions/check.c @@ -485,7 +485,7 @@ void register_disk(struct gendisk *disk) goto exit; bdev->bd_invalidated = 1; - err = blkdev_get(bdev, FMODE_READ, 0); + err = blkdev_get(bdev, FMODE_READ); if (err < 0) goto exit; blkdev_put(bdev, FMODE_READ); diff --git a/include/linux/fs.h b/include/linux/fs.h index c6766314dc5..cb78e389699 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1722,7 +1722,7 @@ extern int blkdev_driver_ioctl(struct inode *inode, struct file *file, struct gendisk *disk, unsigned cmd, unsigned long arg); extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long); -extern int blkdev_get(struct block_device *, fmode_t, unsigned); +extern int blkdev_get(struct block_device *, fmode_t); extern int blkdev_put(struct block_device *, fmode_t); extern int bd_claim(struct block_device *, void *); extern void bd_release(struct block_device *); diff --git a/kernel/power/swap.c b/kernel/power/swap.c index 178b001a4f1..b7713b53d07 100644 --- a/kernel/power/swap.c +++ b/kernel/power/swap.c @@ -172,7 +172,7 @@ static int swsusp_swap_check(void) /* This is called before saving image */ return res; root_swap = res; - res = blkdev_get(resume_bdev, FMODE_WRITE, O_RDWR); + res = blkdev_get(resume_bdev, FMODE_WRITE); if (res) return res; -- cgit v1.2.3-70-g09d2 From 56b26add02b4bdea81d5e0ebda60db1fe3311ad4 Mon Sep 17 00:00:00 2001 From: Al Viro Date: Fri, 19 Sep 2008 03:17:36 -0400 Subject: [PATCH] kill the rest of struct file propagation in block ioctls Now we can switch blkdev_ioctl() block_device/mode Signed-off-by: Al Viro --- block/compat_ioctl.c | 10 +++++----- block/ioctl.c | 9 +-------- drivers/char/raw.c | 2 +- fs/block_dev.c | 8 ++++++-- include/linux/fs.h | 2 +- 5 files changed, 14 insertions(+), 17 deletions(-) (limited to 'fs') diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c index 5b3db0640d8..3098c92402f 100644 --- a/block/compat_ioctl.c +++ b/block/compat_ioctl.c @@ -177,7 +177,7 @@ struct compat_blkpg_ioctl_arg { compat_caddr_t data; }; -static int compat_blkpg_ioctl(struct inode *inode, struct file *file, +static int compat_blkpg_ioctl(struct block_device *bdev, fmode_t mode, unsigned int cmd, struct compat_blkpg_ioctl_arg __user *ua32) { struct blkpg_ioctl_arg __user *a = compat_alloc_user_space(sizeof(*a)); @@ -196,7 +196,7 @@ static int compat_blkpg_ioctl(struct inode *inode, struct file *file, if (err) return err; - return blkdev_ioctl(inode, file, cmd, (unsigned long)a); + return blkdev_ioctl(bdev, mode, cmd, (unsigned long)a); } #define BLKBSZGET_32 _IOR(0x12, 112, int) @@ -715,13 +715,13 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg) * but we call blkdev_ioctl, which gets the lock for us */ case BLKRRPART: - return blkdev_ioctl(inode, file, cmd, + return blkdev_ioctl(bdev, mode, cmd, (unsigned long)compat_ptr(arg)); case BLKBSZSET_32: - return blkdev_ioctl(inode, file, BLKBSZSET, + return blkdev_ioctl(bdev, mode, BLKBSZSET, (unsigned long)compat_ptr(arg)); case BLKPG: - return compat_blkpg_ioctl(inode, file, cmd, compat_ptr(arg)); + return compat_blkpg_ioctl(bdev, mode, cmd, compat_ptr(arg)); case BLKRAGET: case BLKFRAGET: if (!arg) diff --git a/block/ioctl.c b/block/ioctl.c index 14b7f2c1066..c832d639b6e 100644 --- a/block/ioctl.c +++ b/block/ioctl.c @@ -230,20 +230,13 @@ EXPORT_SYMBOL_GPL(__blkdev_driver_ioctl); * always keep this in sync with compat_blkdev_ioctl() and * compat_blkdev_locked_ioctl() */ -int blkdev_ioctl(struct inode *inode, struct file *file, unsigned cmd, +int blkdev_ioctl(struct block_device *bdev, fmode_t mode, unsigned cmd, unsigned long arg) { - struct block_device *bdev = inode->i_bdev; struct gendisk *disk = bdev->bd_disk; struct backing_dev_info *bdi; loff_t size; int ret, n; - fmode_t mode = 0; - if (file) { - mode = file->f_mode; - if (file->f_flags & O_NDELAY) - mode |= FMODE_NDELAY_NOW; - } switch(cmd) { case BLKFLSBUF: diff --git a/drivers/char/raw.c b/drivers/char/raw.c index f3cf5eb9b7f..96adf28a17e 100644 --- a/drivers/char/raw.c +++ b/drivers/char/raw.c @@ -125,7 +125,7 @@ raw_ioctl(struct inode *inode, struct file *filp, { struct block_device *bdev = filp->private_data; - return blkdev_ioctl(bdev->bd_inode, NULL, command, arg); + return blkdev_ioctl(bdev, 0, command, arg); } static void bind_device(struct raw_config_request *rq) diff --git a/fs/block_dev.c b/fs/block_dev.c index b89c956e04f..05865b93f7e 100644 --- a/fs/block_dev.c +++ b/fs/block_dev.c @@ -1202,7 +1202,11 @@ static int blkdev_close(struct inode * inode, struct file * filp) static long block_ioctl(struct file *file, unsigned cmd, unsigned long arg) { - return blkdev_ioctl(file->f_mapping->host, file, cmd, arg); + struct block_device *bdev = I_BDEV(file->f_mapping->host); + fmode_t mode = file->f_mode; + if (file->f_flags & O_NDELAY) + mode |= FMODE_NDELAY_NOW; + return blkdev_ioctl(bdev, mode, cmd, arg); } static const struct address_space_operations def_blk_aops = { @@ -1238,7 +1242,7 @@ int ioctl_by_bdev(struct block_device *bdev, unsigned cmd, unsigned long arg) int res; mm_segment_t old_fs = get_fs(); set_fs(KERNEL_DS); - res = blkdev_ioctl(bdev->bd_inode, NULL, cmd, arg); + res = blkdev_ioctl(bdev, 0, cmd, arg); set_fs(old_fs); return res; } diff --git a/include/linux/fs.h b/include/linux/fs.h index 11de682c65a..ff536e106b4 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1717,7 +1717,7 @@ extern const struct file_operations bad_sock_fops; extern const struct file_operations def_fifo_fops; #ifdef CONFIG_BLOCK extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long); -extern int blkdev_ioctl(struct inode *, struct file *, unsigned, unsigned long); +extern int blkdev_ioctl(struct block_device *, fmode_t, unsigned, unsigned long); extern long compat_blkdev_ioctl(struct file *, unsigned, unsigned long); extern int blkdev_get(struct block_device *, fmode_t); extern int blkdev_put(struct block_device *, fmode_t); -- cgit v1.2.3-70-g09d2