Commit d4d77629 authored by Tejun Heo's avatar Tejun Heo

block: clean up blkdev_get() wrappers and their users

After recent blkdev_get() modifications, open_by_devnum() and
open_bdev_exclusive() are simple wrappers around blkdev_get().
Replace them with blkdev_get_by_dev() and blkdev_get_by_path().

blkdev_get_by_dev() is identical to open_by_devnum().
blkdev_get_by_path() is slightly different in that it doesn't
automatically add %FMODE_EXCL to @mode.

All users are converted.  Most conversions are mechanical and don't
introduce any behavior difference.  There are several exceptions.

* btrfs now sets FMODE_EXCL in btrfs_device->mode, so there's no
  reason to OR it explicitly on blkdev_put().

* gfs2, nilfs2 and the generic mount_bdev() now set FMODE_EXCL in
  sb->s_mode.

* With the above changes, sb->s_mode now always should contain
  FMODE_EXCL.  WARN_ON_ONCE() added to kill_block_super() to detect
  errors.

The new blkdev_get_*() functions are with proper docbook comments.
While at it, add function description to blkdev_get() too.
Signed-off-by: default avatarTejun Heo <tj@kernel.org>
Cc: Philipp Reisner <philipp.reisner@linbit.com>
Cc: Neil Brown <neilb@suse.de>
Cc: Mike Snitzer <snitzer@redhat.com>
Cc: Joern Engel <joern@lazybastard.org>
Cc: Chris Mason <chris.mason@oracle.com>
Cc: Jan Kara <jack@suse.cz>
Cc: "Theodore Ts'o" <tytso@mit.edu>
Cc: KONISHI Ryusuke <konishi.ryusuke@lab.ntt.co.jp>
Cc: reiserfs-devel@vger.kernel.org
Cc: xfs-masters@oss.sgi.com
Cc: Alexander Viro <viro@zeniv.linux.org.uk>
parent 75f1dc0d
...@@ -902,8 +902,8 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp ...@@ -902,8 +902,8 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
} }
} }
bdev = open_bdev_exclusive(nbc->dc.backing_dev, bdev = blkdev_get_by_path(nbc->dc.backing_dev,
FMODE_READ | FMODE_WRITE, mdev); FMODE_READ | FMODE_WRITE | FMODE_EXCL, mdev);
if (IS_ERR(bdev)) { if (IS_ERR(bdev)) {
dev_err(DEV, "open(\"%s\") failed with %ld\n", nbc->dc.backing_dev, dev_err(DEV, "open(\"%s\") failed with %ld\n", nbc->dc.backing_dev,
PTR_ERR(bdev)); PTR_ERR(bdev));
...@@ -920,8 +920,8 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp ...@@ -920,8 +920,8 @@ static int drbd_nl_disk_conf(struct drbd_conf *mdev, struct drbd_nl_cfg_req *nlp
* should check it for you already; but if you don't, or * should check it for you already; but if you don't, or
* someone fooled it, we need to double check here) * someone fooled it, we need to double check here)
*/ */
bdev = open_bdev_exclusive(nbc->dc.meta_dev, bdev = blkdev_get_by_path(nbc->dc.meta_dev,
FMODE_READ | FMODE_WRITE, FMODE_READ | FMODE_WRITE | FMODE_EXCL,
(nbc->dc.meta_dev_idx < 0) ? (nbc->dc.meta_dev_idx < 0) ?
(void *)mdev : (void *)drbd_m_holder); (void *)mdev : (void *)drbd_m_holder);
if (IS_ERR(bdev)) { if (IS_ERR(bdev)) {
......
...@@ -325,7 +325,7 @@ static int open_dev(struct dm_dev_internal *d, dev_t dev, ...@@ -325,7 +325,7 @@ static int open_dev(struct dm_dev_internal *d, dev_t dev,
BUG_ON(d->dm_dev.bdev); BUG_ON(d->dm_dev.bdev);
bdev = open_by_devnum(dev, d->dm_dev.mode | FMODE_EXCL, _claim_ptr); bdev = blkdev_get_by_dev(dev, d->dm_dev.mode | FMODE_EXCL, _claim_ptr);
if (IS_ERR(bdev)) if (IS_ERR(bdev))
return PTR_ERR(bdev); return PTR_ERR(bdev);
......
...@@ -1934,7 +1934,7 @@ static int lock_rdev(mdk_rdev_t *rdev, dev_t dev, int shared) ...@@ -1934,7 +1934,7 @@ static int lock_rdev(mdk_rdev_t *rdev, dev_t dev, int shared)
struct block_device *bdev; struct block_device *bdev;
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];
bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
shared ? (mdk_rdev_t *)lock_rdev : rdev); shared ? (mdk_rdev_t *)lock_rdev : rdev);
if (IS_ERR(bdev)) { if (IS_ERR(bdev)) {
printk(KERN_ERR "md: could not open %s.\n", printk(KERN_ERR "md: could not open %s.\n",
......
...@@ -247,7 +247,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size) ...@@ -247,7 +247,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
return NULL; return NULL;
/* Get a handle on the device */ /* Get a handle on the device */
bdev = open_bdev_exclusive(devname, mode, dev); bdev = blkdev_get_by_path(devname, mode, dev);
#ifndef MODULE #ifndef MODULE
if (IS_ERR(bdev)) { if (IS_ERR(bdev)) {
...@@ -256,7 +256,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size) ...@@ -256,7 +256,7 @@ static struct block2mtd_dev *add_device(char *devname, int erase_size)
dev_t devt = name_to_dev_t(devname); dev_t devt = name_to_dev_t(devname);
if (devt) if (devt)
bdev = open_by_devnum(devt, mode, dev); bdev = blkdev_get_by_dev(devt, mode, dev);
} }
#endif #endif
......
...@@ -854,24 +854,6 @@ static inline void bd_unlink_disk_holder(struct block_device *bdev) ...@@ -854,24 +854,6 @@ static inline void bd_unlink_disk_holder(struct block_device *bdev)
{ } { }
#endif #endif
/*
* Tries to open block device by device number. Use it ONLY if you
* really do not have anything better - i.e. when you are behind a
* truly sucky interface and all you are given is a device number. _Never_
* to be used for internal purposes. If you ever need it - reconsider
* your API.
*/
struct block_device *open_by_devnum(dev_t dev, fmode_t mode, void *holder)
{
struct block_device *bdev = bdget(dev);
int err = -ENOMEM;
if (bdev)
err = blkdev_get(bdev, mode, holder);
return err ? ERR_PTR(err) : bdev;
}
EXPORT_SYMBOL(open_by_devnum);
/** /**
* flush_disk - invalidates all buffer-cache entries on a disk * flush_disk - invalidates all buffer-cache entries on a disk
* *
...@@ -1132,6 +1114,25 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part) ...@@ -1132,6 +1114,25 @@ static int __blkdev_get(struct block_device *bdev, fmode_t mode, int for_part)
return ret; return ret;
} }
/**
* blkdev_get - open a block device
* @bdev: block_device to open
* @mode: FMODE_* mask
* @holder: exclusive holder identifier
*
* Open @bdev with @mode. If @mode includes %FMODE_EXCL, @bdev is
* open with exclusive access. Specifying %FMODE_EXCL with %NULL
* @holder is invalid. Exclusive opens may nest for the same @holder.
*
* On success, the reference count of @bdev is unchanged. On failure,
* @bdev is put.
*
* CONTEXT:
* Might sleep.
*
* RETURNS:
* 0 on success, -errno on failure.
*/
int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder) int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder)
{ {
struct block_device *whole = NULL; struct block_device *whole = NULL;
...@@ -1186,6 +1187,80 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder) ...@@ -1186,6 +1187,80 @@ int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder)
} }
EXPORT_SYMBOL(blkdev_get); EXPORT_SYMBOL(blkdev_get);
/**
* blkdev_get_by_path - open a block device by name
* @path: path to the block device to open
* @mode: FMODE_* mask
* @holder: exclusive holder identifier
*
* Open the blockdevice described by the device file at @path. @mode
* and @holder are identical to blkdev_get().
*
* On success, the returned block_device has reference count of one.
*
* CONTEXT:
* Might sleep.
*
* RETURNS:
* Pointer to block_device on success, ERR_PTR(-errno) on failure.
*/
struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
void *holder)
{
struct block_device *bdev;
int err;
bdev = lookup_bdev(path);
if (IS_ERR(bdev))
return bdev;
err = blkdev_get(bdev, mode, holder);
if (err)
return ERR_PTR(err);
return bdev;
}
EXPORT_SYMBOL(blkdev_get_by_path);
/**
* blkdev_get_by_dev - open a block device by device number
* @dev: device number of block device to open
* @mode: FMODE_* mask
* @holder: exclusive holder identifier
*
* Open the blockdevice described by device number @dev. @mode and
* @holder are identical to blkdev_get().
*
* Use it ONLY if you really do not have anything better - i.e. when
* you are behind a truly sucky interface and all you are given is a
* device number. _Never_ to be used for internal purposes. If you
* ever need it - reconsider your API.
*
* On success, the returned block_device has reference count of one.
*
* CONTEXT:
* Might sleep.
*
* RETURNS:
* Pointer to block_device on success, ERR_PTR(-errno) on failure.
*/
struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode, void *holder)
{
struct block_device *bdev;
int err;
bdev = bdget(dev);
if (!bdev)
return ERR_PTR(-ENOMEM);
err = blkdev_get(bdev, mode, holder);
if (err)
return ERR_PTR(err);
return bdev;
}
EXPORT_SYMBOL(blkdev_get_by_dev);
static int blkdev_open(struct inode * inode, struct file * filp) static int blkdev_open(struct inode * inode, struct file * filp)
{ {
struct block_device *bdev; struct block_device *bdev;
...@@ -1436,34 +1511,6 @@ struct block_device *lookup_bdev(const char *pathname) ...@@ -1436,34 +1511,6 @@ struct block_device *lookup_bdev(const char *pathname)
} }
EXPORT_SYMBOL(lookup_bdev); EXPORT_SYMBOL(lookup_bdev);
/**
* open_bdev_exclusive - open a block device by name and set it up for use
*
* @path: special file representing the block device
* @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_exclusive(const char *path, fmode_t mode, void *holder)
{
struct block_device *bdev;
int error;
bdev = lookup_bdev(path);
if (IS_ERR(bdev))
return bdev;
error = blkdev_get(bdev, mode | FMODE_EXCL, holder);
if (error)
return ERR_PTR(error);
return bdev;
}
EXPORT_SYMBOL(open_bdev_exclusive);
int __invalidate_device(struct block_device *bdev) int __invalidate_device(struct block_device *bdev)
{ {
struct super_block *sb = get_super(bdev); struct super_block *sb = get_super(bdev);
......
...@@ -489,7 +489,7 @@ int btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices) ...@@ -489,7 +489,7 @@ int btrfs_close_extra_devices(struct btrfs_fs_devices *fs_devices)
continue; continue;
if (device->bdev) { if (device->bdev) {
blkdev_put(device->bdev, device->mode | FMODE_EXCL); blkdev_put(device->bdev, device->mode);
device->bdev = NULL; device->bdev = NULL;
fs_devices->open_devices--; fs_devices->open_devices--;
} }
...@@ -523,7 +523,7 @@ static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices) ...@@ -523,7 +523,7 @@ static int __btrfs_close_devices(struct btrfs_fs_devices *fs_devices)
list_for_each_entry(device, &fs_devices->devices, dev_list) { list_for_each_entry(device, &fs_devices->devices, dev_list) {
if (device->bdev) { if (device->bdev) {
blkdev_put(device->bdev, device->mode | FMODE_EXCL); blkdev_put(device->bdev, device->mode);
fs_devices->open_devices--; fs_devices->open_devices--;
} }
if (device->writeable) { if (device->writeable) {
...@@ -580,13 +580,15 @@ static int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices, ...@@ -580,13 +580,15 @@ static int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
int seeding = 1; int seeding = 1;
int ret = 0; int ret = 0;
flags |= FMODE_EXCL;
list_for_each_entry(device, head, dev_list) { list_for_each_entry(device, head, dev_list) {
if (device->bdev) if (device->bdev)
continue; continue;
if (!device->name) if (!device->name)
continue; continue;
bdev = open_bdev_exclusive(device->name, flags, holder); bdev = blkdev_get_by_path(device->name, flags, holder);
if (IS_ERR(bdev)) { if (IS_ERR(bdev)) {
printk(KERN_INFO "open %s failed\n", device->name); printk(KERN_INFO "open %s failed\n", device->name);
goto error; goto error;
...@@ -638,7 +640,7 @@ static int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices, ...@@ -638,7 +640,7 @@ static int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices,
error_brelse: error_brelse:
brelse(bh); brelse(bh);
error_close: error_close:
blkdev_put(bdev, flags | FMODE_EXCL); blkdev_put(bdev, flags);
error: error:
continue; continue;
} }
...@@ -684,7 +686,8 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, ...@@ -684,7 +686,8 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
mutex_lock(&uuid_mutex); mutex_lock(&uuid_mutex);
bdev = open_bdev_exclusive(path, flags, holder); flags |= FMODE_EXCL;
bdev = blkdev_get_by_path(path, flags, holder);
if (IS_ERR(bdev)) { if (IS_ERR(bdev)) {
ret = PTR_ERR(bdev); ret = PTR_ERR(bdev);
...@@ -716,7 +719,7 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, ...@@ -716,7 +719,7 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder,
brelse(bh); brelse(bh);
error_close: error_close:
blkdev_put(bdev, flags | FMODE_EXCL); blkdev_put(bdev, flags);
error: error:
mutex_unlock(&uuid_mutex); mutex_unlock(&uuid_mutex);
return ret; return ret;
...@@ -1179,7 +1182,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) ...@@ -1179,7 +1182,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
goto out; goto out;
} }
} else { } else {
bdev = open_bdev_exclusive(device_path, FMODE_READ, bdev = blkdev_get_by_path(device_path, FMODE_READ | FMODE_EXCL,
root->fs_info->bdev_holder); root->fs_info->bdev_holder);
if (IS_ERR(bdev)) { if (IS_ERR(bdev)) {
ret = PTR_ERR(bdev); ret = PTR_ERR(bdev);
...@@ -1244,7 +1247,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) ...@@ -1244,7 +1247,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path)
root->fs_info->fs_devices->latest_bdev = next_device->bdev; root->fs_info->fs_devices->latest_bdev = next_device->bdev;
if (device->bdev) { if (device->bdev) {
blkdev_put(device->bdev, device->mode | FMODE_EXCL); blkdev_put(device->bdev, device->mode);
device->bdev = NULL; device->bdev = NULL;
device->fs_devices->open_devices--; device->fs_devices->open_devices--;
} }
...@@ -1439,7 +1442,8 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path) ...@@ -1439,7 +1442,8 @@ int btrfs_init_new_device(struct btrfs_root *root, char *device_path)
if ((sb->s_flags & MS_RDONLY) && !root->fs_info->fs_devices->seeding) if ((sb->s_flags & MS_RDONLY) && !root->fs_info->fs_devices->seeding)
return -EINVAL; return -EINVAL;
bdev = open_bdev_exclusive(device_path, 0, root->fs_info->bdev_holder); bdev = blkdev_get_by_path(device_path, FMODE_EXCL,
root->fs_info->bdev_holder);
if (IS_ERR(bdev)) if (IS_ERR(bdev))
return PTR_ERR(bdev); return PTR_ERR(bdev);
......
...@@ -49,7 +49,7 @@ struct btrfs_device { ...@@ -49,7 +49,7 @@ struct btrfs_device {
struct block_device *bdev; struct block_device *bdev;
/* the mode sent to open_bdev_exclusive */ /* the mode sent to blkdev_get */
fmode_t mode; fmode_t mode;
char *name; char *name;
......
...@@ -347,7 +347,7 @@ static struct block_device *ext3_blkdev_get(dev_t dev, struct super_block *sb) ...@@ -347,7 +347,7 @@ static struct block_device *ext3_blkdev_get(dev_t dev, struct super_block *sb)
struct block_device *bdev; struct block_device *bdev;
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];
bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb); bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb);
if (IS_ERR(bdev)) if (IS_ERR(bdev))
goto fail; goto fail;
return bdev; return bdev;
......
...@@ -647,7 +647,7 @@ static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb) ...@@ -647,7 +647,7 @@ static struct block_device *ext4_blkdev_get(dev_t dev, struct super_block *sb)
struct block_device *bdev; struct block_device *bdev;
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];
bdev = open_by_devnum(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb); bdev = blkdev_get_by_dev(dev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, sb);
if (IS_ERR(bdev)) if (IS_ERR(bdev))
goto fail; goto fail;
return bdev; return bdev;
......
...@@ -1268,7 +1268,7 @@ static struct dentry *gfs2_mount(struct file_system_type *fs_type, int flags, ...@@ -1268,7 +1268,7 @@ static struct dentry *gfs2_mount(struct file_system_type *fs_type, int flags,
{ {
struct block_device *bdev; struct block_device *bdev;
struct super_block *s; struct super_block *s;
fmode_t mode = FMODE_READ; fmode_t mode = FMODE_READ | FMODE_EXCL;
int error; int error;
struct gfs2_args args; struct gfs2_args args;
struct gfs2_sbd *sdp; struct gfs2_sbd *sdp;
...@@ -1276,7 +1276,7 @@ static struct dentry *gfs2_mount(struct file_system_type *fs_type, int flags, ...@@ -1276,7 +1276,7 @@ static struct dentry *gfs2_mount(struct file_system_type *fs_type, int flags,
if (!(flags & MS_RDONLY)) if (!(flags & MS_RDONLY))
mode |= FMODE_WRITE; mode |= FMODE_WRITE;
bdev = open_bdev_exclusive(dev_name, mode, fs_type); bdev = blkdev_get_by_path(dev_name, mode, fs_type);
if (IS_ERR(bdev)) if (IS_ERR(bdev))
return ERR_CAST(bdev); return ERR_CAST(bdev);
...@@ -1298,7 +1298,7 @@ static struct dentry *gfs2_mount(struct file_system_type *fs_type, int flags, ...@@ -1298,7 +1298,7 @@ static struct dentry *gfs2_mount(struct file_system_type *fs_type, int flags,
goto error_bdev; goto error_bdev;
if (s->s_root) if (s->s_root)
blkdev_put(bdev, mode | FMODE_EXCL); blkdev_put(bdev, mode);
memset(&args, 0, sizeof(args)); memset(&args, 0, sizeof(args));
args.ar_quota = GFS2_QUOTA_DEFAULT; args.ar_quota = GFS2_QUOTA_DEFAULT;
...@@ -1342,7 +1342,7 @@ static struct dentry *gfs2_mount(struct file_system_type *fs_type, int flags, ...@@ -1342,7 +1342,7 @@ static struct dentry *gfs2_mount(struct file_system_type *fs_type, int flags,
deactivate_locked_super(s); deactivate_locked_super(s);
return ERR_PTR(error); return ERR_PTR(error);
error_bdev: error_bdev:
blkdev_put(bdev, mode | FMODE_EXCL); blkdev_put(bdev, mode);
return ERR_PTR(error); return ERR_PTR(error);
} }
......
...@@ -1120,7 +1120,7 @@ int lmLogOpen(struct super_block *sb) ...@@ -1120,7 +1120,7 @@ int lmLogOpen(struct super_block *sb)
* file systems to log may have n-to-1 relationship; * file systems to log may have n-to-1 relationship;
*/ */
bdev = open_by_devnum(sbi->logdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL, bdev = blkdev_get_by_dev(sbi->logdev, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
log); log);
if (IS_ERR(bdev)) { if (IS_ERR(bdev)) {
rc = -PTR_ERR(bdev); rc = -PTR_ERR(bdev);
......
...@@ -325,7 +325,8 @@ int logfs_get_sb_bdev(struct logfs_super *p, struct file_system_type *type, ...@@ -325,7 +325,8 @@ int logfs_get_sb_bdev(struct logfs_super *p, struct file_system_type *type,
{ {
struct block_device *bdev; struct block_device *bdev;
bdev = open_bdev_exclusive(devname, FMODE_READ|FMODE_WRITE, type); bdev = blkdev_get_by_path(devname, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
type);
if (IS_ERR(bdev)) if (IS_ERR(bdev))
return PTR_ERR(bdev); return PTR_ERR(bdev);
......
...@@ -1147,14 +1147,14 @@ nilfs_mount(struct file_system_type *fs_type, int flags, ...@@ -1147,14 +1147,14 @@ nilfs_mount(struct file_system_type *fs_type, int flags,
{ {
struct nilfs_super_data sd; struct nilfs_super_data sd;
struct super_block *s; struct super_block *s;
fmode_t mode = FMODE_READ; fmode_t mode = FMODE_READ | FMODE_EXCL;
struct dentry *root_dentry; struct dentry *root_dentry;
int err, s_new = false; int err, s_new = false;
if (!(flags & MS_RDONLY)) if (!(flags & MS_RDONLY))
mode |= FMODE_WRITE; mode |= FMODE_WRITE;
sd.bdev = open_bdev_exclusive(dev_name, mode, fs_type); sd.bdev = blkdev_get_by_path(dev_name, mode, fs_type);
if (IS_ERR(sd.bdev)) if (IS_ERR(sd.bdev))
return ERR_CAST(sd.bdev); return ERR_CAST(sd.bdev);
...@@ -1233,7 +1233,7 @@ nilfs_mount(struct file_system_type *fs_type, int flags, ...@@ -1233,7 +1233,7 @@ nilfs_mount(struct file_system_type *fs_type, int flags,
} }
if (!s_new) if (!s_new)
blkdev_put(sd.bdev, mode | FMODE_EXCL); blkdev_put(sd.bdev, mode);
return root_dentry; return root_dentry;
...@@ -1242,7 +1242,7 @@ nilfs_mount(struct file_system_type *fs_type, int flags, ...@@ -1242,7 +1242,7 @@ nilfs_mount(struct file_system_type *fs_type, int flags,
failed: failed:
if (!s_new) if (!s_new)
blkdev_put(sd.bdev, mode | FMODE_EXCL); blkdev_put(sd.bdev, mode);
return ERR_PTR(err); return ERR_PTR(err);
} }
......
...@@ -2585,7 +2585,8 @@ static int journal_init_dev(struct super_block *super, ...@@ -2585,7 +2585,8 @@ static int journal_init_dev(struct super_block *super,
if ((!jdev_name || !jdev_name[0])) { if ((!jdev_name || !jdev_name[0])) {
if (jdev == super->s_dev) if (jdev == super->s_dev)
blkdev_mode &= ~FMODE_EXCL; blkdev_mode &= ~FMODE_EXCL;
journal->j_dev_bd = open_by_devnum(jdev, blkdev_mode, journal); journal->j_dev_bd = blkdev_get_by_dev(jdev, blkdev_mode,
journal);
journal->j_dev_mode = blkdev_mode; journal->j_dev_mode = blkdev_mode;
if (IS_ERR(journal->j_dev_bd)) { if (IS_ERR(journal->j_dev_bd)) {
result = PTR_ERR(journal->j_dev_bd); result = PTR_ERR(journal->j_dev_bd);
...@@ -2601,8 +2602,7 @@ static int journal_init_dev(struct super_block *super, ...@@ -2601,8 +2602,7 @@ static int journal_init_dev(struct super_block *super,
} }
journal->j_dev_mode = blkdev_mode; journal->j_dev_mode = blkdev_mode;
journal->j_dev_bd = open_bdev_exclusive(jdev_name, journal->j_dev_bd = blkdev_get_by_path(jdev_name, blkdev_mode, journal);
blkdev_mode, journal);
if (IS_ERR(journal->j_dev_bd)) { if (IS_ERR(journal->j_dev_bd)) {
result = PTR_ERR(journal->j_dev_bd); result = PTR_ERR(journal->j_dev_bd);
journal->j_dev_bd = NULL; journal->j_dev_bd = NULL;
......
...@@ -766,13 +766,13 @@ struct dentry *mount_bdev(struct file_system_type *fs_type, ...@@ -766,13 +766,13 @@ struct dentry *mount_bdev(struct file_system_type *fs_type,
{ {
struct block_device *bdev; struct block_device *bdev;
struct super_block *s; struct super_block *s;
fmode_t mode = FMODE_READ; fmode_t mode = FMODE_READ | FMODE_EXCL;
int error = 0; int error = 0;
if (!(flags & MS_RDONLY)) if (!(flags & MS_RDONLY))
mode |= FMODE_WRITE; mode |= FMODE_WRITE;
bdev = open_bdev_exclusive(dev_name, mode, fs_type); bdev = blkdev_get_by_path(dev_name, mode, fs_type);
if (IS_ERR(bdev)) if (IS_ERR(bdev))
return ERR_CAST(bdev); return ERR_CAST(bdev);
...@@ -807,7 +807,7 @@ struct dentry *mount_bdev(struct file_system_type *fs_type, ...@@ -807,7 +807,7 @@ struct dentry *mount_bdev(struct file_system_type *fs_type,
* holding an active reference. * holding an active reference.
*/ */
up_write(&s->s_umount); up_write(&s->s_umount);
blkdev_put(bdev, mode | FMODE_EXCL); blkdev_put(bdev, mode);
down_write(&s->s_umount); down_write(&s->s_umount);
} else { } else {
char b[BDEVNAME_SIZE]; char b[BDEVNAME_SIZE];
...@@ -831,7 +831,7 @@ struct dentry *mount_bdev(struct file_system_type *fs_type, ...@@ -831,7 +831,7 @@ struct dentry *mount_bdev(struct file_system_type *fs_type,
error_s: error_s:
error = PTR_ERR(s); error = PTR_ERR(s);
error_bdev: error_bdev:
blkdev_put(bdev, mode | FMODE_EXCL); blkdev_put(bdev, mode);
error: error:
return ERR_PTR(error); return ERR_PTR(error);
} }
...@@ -862,6 +862,7 @@ void kill_block_super(struct super_block *sb) ...@@ -862,6 +862,7 @@ void kill_block_super(struct super_block *sb)
bdev->bd_super = NULL; bdev->bd_super = NULL;
generic_shutdown_super(sb); generic_shutdown_super(sb);
sync_blockdev(bdev); sync_blockdev(bdev);
WARN_ON_ONCE(!(mode & FMODE_EXCL));
blkdev_put(bdev, mode | FMODE_EXCL); blkdev_put(bdev, mode | FMODE_EXCL);
} }
......
...@@ -609,7 +609,8 @@ xfs_blkdev_get( ...@@ -609,7 +609,8 @@ xfs_blkdev_get(
{ {
int error = 0; int error = 0;
*bdevp = open_bdev_exclusive(name, FMODE_READ|FMODE_WRITE, mp); *bdevp = blkdev_get_by_path(name, FMODE_READ|FMODE_WRITE|FMODE_EXCL,
mp);
if (IS_ERR(*bdevp)) { if (IS_ERR(*bdevp)) {
error = PTR_ERR(*bdevp); error = PTR_ERR(*bdevp);
printk("XFS: Invalid device [%s], error=%d\n", name, error); printk("XFS: Invalid device [%s], error=%d\n", name, error);
......
...@@ -2006,8 +2006,6 @@ extern struct block_device *bdgrab(struct block_device *bdev); ...@@ -2006,8 +2006,6 @@ extern struct block_device *bdgrab(struct block_device *bdev);
extern void bd_set_size(struct block_device *, loff_t size); extern void bd_set_size(struct block_device *, loff_t size);
extern void bd_forget(struct inode *inode); extern void bd_forget(struct inode *inode);
extern void bdput(struct block_device *); extern void bdput(struct block_device *);
extern struct block_device *open_by_devnum(dev_t dev, fmode_t mode,
void *holder);
extern void invalidate_bdev(struct block_device *); extern void invalidate_bdev(struct block_device *);
extern int sync_blockdev(struct block_device *bdev); extern int sync_blockdev(struct block_device *bdev);
extern struct super_block *freeze_bdev(struct block_device *); extern struct super_block *freeze_bdev(struct block_device *);
...@@ -2039,6 +2037,10 @@ extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long); ...@@ -2039,6 +2037,10 @@ extern int ioctl_by_bdev(struct block_device *, unsigned, unsigned long);
extern int blkdev_ioctl(struct block_device *, fmode_t, 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 long compat_blkdev_ioctl(struct file *, unsigned, unsigned long);
extern int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder); extern int blkdev_get(struct block_device *bdev, fmode_t mode, void *holder);
extern struct block_device *blkdev_get_by_path(const char *path, fmode_t mode,
void *holder);
extern struct block_device *blkdev_get_by_dev(dev_t dev, fmode_t mode,
void *holder);
extern int blkdev_put(struct block_device *bdev, fmode_t mode); extern int blkdev_put(struct block_device *bdev, fmode_t mode);
#ifdef CONFIG_SYSFS #ifdef CONFIG_SYSFS
extern int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk); extern int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk);
...@@ -2083,7 +2085,6 @@ static inline void unregister_chrdev(unsigned int major, const char *name) ...@@ -2083,7 +2085,6 @@ static inline void unregister_chrdev(unsigned int major, const char *name)
extern const char *__bdevname(dev_t, char *buffer); extern const char *__bdevname(dev_t, char *buffer);
extern const char *bdevname(struct block_device *bdev, char *buffer); extern const char *bdevname(struct block_device *bdev, char *buffer);
extern struct block_device *lookup_bdev(const char *); extern struct block_device *lookup_bdev(const char *);
extern struct block_device *open_bdev_exclusive(const char *, fmode_t, void *);
extern void blkdev_show(struct seq_file *,off_t); extern void blkdev_show(struct seq_file *,off_t);
#else #else
......
...@@ -907,7 +907,7 @@ int swsusp_check(void) ...@@ -907,7 +907,7 @@ int swsusp_check(void)
{ {
int error; int error;
hib_resume_bdev = open_by_devnum(swsusp_resume_device, hib_resume_bdev = blkdev_get_by_dev(swsusp_resume_device,
FMODE_READ, NULL); FMODE_READ, NULL);
if (!IS_ERR(hib_resume_bdev)) { if (!IS_ERR(hib_resume_bdev)) {
set_blocksize(hib_resume_bdev, PAGE_SIZE); set_blocksize(hib_resume_bdev, PAGE_SIZE);
......
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