Skip to content

Commit

Permalink
block: remove i_bdev
Browse files Browse the repository at this point in the history
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: Christoph Hellwig <[email protected]>
Reviewed-by: Jan Kara <[email protected]>
Reviewed-by: Hannes Reinecke <[email protected]>
Acked-by: Tejun Heo <[email protected]>
Acked-by: Coly Li <[email protected]>		[bcache]
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Christoph Hellwig authored and axboe committed Dec 1, 2020
1 parent 7918f0f commit 4e7b567
Show file tree
Hide file tree
Showing 18 changed files with 121 additions and 252 deletions.
3 changes: 1 addition & 2 deletions block/ioctl.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
8 changes: 3 additions & 5 deletions drivers/block/loop.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 ?:
Expand Down
20 changes: 11 additions & 9 deletions drivers/md/bcache/super.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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";
Expand Down
9 changes: 1 addition & 8 deletions drivers/md/dm-table.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
17 changes: 6 additions & 11 deletions drivers/mtd/mtdsuper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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 */

Expand Down
6 changes: 3 additions & 3 deletions drivers/target/target_core_file.c
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@ static int fd_configure_device(struct se_device *dev)
*/
inode = file->f_mapping->host;
if (S_ISBLK(inode->i_mode)) {
struct request_queue *q = bdev_get_queue(inode->i_bdev);
struct request_queue *q = bdev_get_queue(I_BDEV(inode));
unsigned long long dev_size;

fd_dev->fd_block_size = bdev_logical_block_size(inode->i_bdev);
fd_dev->fd_block_size = bdev_logical_block_size(I_BDEV(inode));
/*
* Determine the number of bytes from i_size_read() minus
* one (1) logical sector from underlying struct block_device
Expand Down Expand Up @@ -559,7 +559,7 @@ fd_execute_unmap(struct se_cmd *cmd, sector_t lba, sector_t nolb)

if (S_ISBLK(inode->i_mode)) {
/* The backend is block device, use discard */
struct block_device *bdev = inode->i_bdev;
struct block_device *bdev = I_BDEV(inode);
struct se_device *dev = cmd->se_dev;

ret = blkdev_issue_discard(bdev,
Expand Down
8 changes: 4 additions & 4 deletions drivers/usb/gadget/function/storage_common.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
if (!(filp->f_mode & FMODE_WRITE))
ro = 1;

inode = file_inode(filp);
inode = filp->f_mapping->host;
if ((!S_ISREG(inode->i_mode) && !S_ISBLK(inode->i_mode))) {
LINFO(curlun, "invalid file type: %s\n", filename);
goto out;
Expand All @@ -221,7 +221,7 @@ int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
if (!(filp->f_mode & FMODE_CAN_WRITE))
ro = 1;

size = i_size_read(inode->i_mapping->host);
size = i_size_read(inode);
if (size < 0) {
LINFO(curlun, "unable to find file size: %s\n", filename);
rc = (int) size;
Expand All @@ -231,8 +231,8 @@ int fsg_lun_open(struct fsg_lun *curlun, const char *filename)
if (curlun->cdrom) {
blksize = 2048;
blkbits = 11;
} else if (inode->i_bdev) {
blksize = bdev_logical_block_size(inode->i_bdev);
} else if (S_ISBLK(inode->i_mode)) {
blksize = bdev_logical_block_size(I_BDEV(inode));
blkbits = blksize_bits(blksize);
} else {
blksize = 512;
Expand Down
Loading

0 comments on commit 4e7b567

Please sign in to comment.