Commit 4e7b5671 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe
Browse files

block: remove i_bdev



Switch the block device lookup interfaces to directly work with a dev_t
so that struct block_device references are only acquired by the
blkdev_get variants (and the blk-cgroup special case).  This means that
we now don't need an extra reference in the inode and can generally
simplify handling of struct block_device to keep the lookups contained
in the core block layer code.

Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarJan Kara <jack@suse.cz>
Reviewed-by: default avatarHannes Reinecke <hare@suse.de>
Acked-by: default avatarTejun Heo <tj@kernel.org>
Acked-by: Coly Li <colyli@suse.de>		[bcache]
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 7918f0f6
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -590,8 +590,7 @@ long compat_blkdev_ioctl(struct file *file, unsigned cmd, unsigned long arg)
{
	int ret;
	void __user *argp = compat_ptr(arg);
	struct inode *inode = file->f_mapping->host;
	struct block_device *bdev = inode->i_bdev;
	struct block_device *bdev = I_BDEV(file->f_mapping->host);
	struct gendisk *disk = bdev->bd_disk;
	fmode_t mode = file->f_mode;
	loff_t size;
+3 −5
Original line number Diff line number Diff line
@@ -675,10 +675,10 @@ static int loop_validate_file(struct file *file, struct block_device *bdev)
	while (is_loop_device(f)) {
		struct loop_device *l;

		if (f->f_mapping->host->i_bdev == bdev)
		if (f->f_mapping->host->i_rdev == bdev->bd_dev)
			return -EBADF;

		l = f->f_mapping->host->i_bdev->bd_disk->private_data;
		l = I_BDEV(f->f_mapping->host)->bd_disk->private_data;
		if (l->lo_state != Lo_bound) {
			return -EINVAL;
		}
@@ -885,9 +885,7 @@ static void loop_config_discard(struct loop_device *lo)
	 * file-backed loop devices: discarded regions read back as zero.
	 */
	if (S_ISBLK(inode->i_mode) && !lo->lo_encrypt_key_size) {
		struct request_queue *backingq;

		backingq = bdev_get_queue(inode->i_bdev);
		struct request_queue *backingq = bdev_get_queue(I_BDEV(inode));

		max_discard_sectors = backingq->limits.max_write_zeroes_sectors;
		granularity = backingq->limits.discard_granularity ?:
+11 −9
Original line number Diff line number Diff line
@@ -2380,38 +2380,38 @@ kobj_attribute_write(register, register_bcache);
kobj_attribute_write(register_quiet,	register_bcache);
kobj_attribute_write(pendings_cleanup,	bch_pending_bdevs_cleanup);

static bool bch_is_open_backing(struct block_device *bdev)
static bool bch_is_open_backing(dev_t dev)
{
	struct cache_set *c, *tc;
	struct cached_dev *dc, *t;

	list_for_each_entry_safe(c, tc, &bch_cache_sets, list)
		list_for_each_entry_safe(dc, t, &c->cached_devs, list)
			if (dc->bdev == bdev)
			if (dc->bdev->bd_dev == dev)
				return true;
	list_for_each_entry_safe(dc, t, &uncached_devices, list)
		if (dc->bdev == bdev)
		if (dc->bdev->bd_dev == dev)
			return true;
	return false;
}

static bool bch_is_open_cache(struct block_device *bdev)
static bool bch_is_open_cache(dev_t dev)
{
	struct cache_set *c, *tc;

	list_for_each_entry_safe(c, tc, &bch_cache_sets, list) {
		struct cache *ca = c->cache;

		if (ca->bdev == bdev)
		if (ca->bdev->bd_dev == dev)
			return true;
	}

	return false;
}

static bool bch_is_open(struct block_device *bdev)
static bool bch_is_open(dev_t dev)
{
	return bch_is_open_cache(bdev) || bch_is_open_backing(bdev);
	return bch_is_open_cache(dev) || bch_is_open_backing(dev);
}

struct async_reg_args {
@@ -2535,9 +2535,11 @@ static ssize_t register_bcache(struct kobject *k, struct kobj_attribute *attr,
				  sb);
	if (IS_ERR(bdev)) {
		if (bdev == ERR_PTR(-EBUSY)) {
			bdev = lookup_bdev(strim(path));
			dev_t dev;

			mutex_lock(&bch_register_lock);
			if (!IS_ERR(bdev) && bch_is_open(bdev))
			if (lookup_bdev(strim(path), &dev) == 0 &&
			    bch_is_open(dev))
				err = "device already registered";
			else
				err = "device busy";
+1 −8
Original line number Diff line number Diff line
@@ -348,16 +348,9 @@ static int upgrade_mode(struct dm_dev_internal *dd, fmode_t new_mode,
dev_t dm_get_dev_t(const char *path)
{
	dev_t dev;
	struct block_device *bdev;

	bdev = lookup_bdev(path);
	if (IS_ERR(bdev))
	if (lookup_bdev(path, &dev))
		dev = name_to_dev_t(path);
	else {
		dev = bdev->bd_dev;
		bdput(bdev);
	}

	return dev;
}
EXPORT_SYMBOL_GPL(dm_get_dev_t);
+6 −11
Original line number Diff line number Diff line
@@ -120,8 +120,8 @@ int get_tree_mtd(struct fs_context *fc,
				struct fs_context *fc))
{
#ifdef CONFIG_BLOCK
	struct block_device *bdev;
	int ret, major;
	dev_t dev;
	int ret;
#endif
	int mtdnr;

@@ -169,20 +169,15 @@ int get_tree_mtd(struct fs_context *fc,
	/* try the old way - the hack where we allowed users to mount
	 * /dev/mtdblock$(n) but didn't actually _use_ the blockdev
	 */
	bdev = lookup_bdev(fc->source);
	if (IS_ERR(bdev)) {
		ret = PTR_ERR(bdev);
	ret = lookup_bdev(fc->source, &dev);
	if (ret) {
		errorf(fc, "MTD: Couldn't look up '%s': %d", fc->source, ret);
		return ret;
	}
	pr_debug("MTDSB: lookup_bdev() returned 0\n");

	major = MAJOR(bdev->bd_dev);
	mtdnr = MINOR(bdev->bd_dev);
	bdput(bdev);

	if (major == MTD_BLOCK_MAJOR)
		return mtd_get_sb_by_nr(fc, mtdnr, fill_super);
	if (MAJOR(dev) == MTD_BLOCK_MAJOR)
		return mtd_get_sb_by_nr(fc, MINOR(dev), fill_super);

#endif /* CONFIG_BLOCK */

Loading