missing helpers: bdev_unhash(), bdev_drop()

bdev_unhash(): make block device invisible to lookups by device number
bdev_drop(): drop reference to associated inode.

Both are internal, for use by genhd and partition-related code - similar
to bdev_add().  The logics in there (especially the lifetime-related
parts of it) ought to be cleaned up, but that's a separate story; here
we just encapsulate getting to associated inode.

Signed-off-by: Al Viro <viro@zeniv.linux.org.uk>
This commit is contained in:
Al Viro 2024-04-28 19:01:39 -04:00
parent 186ddac207
commit 2638c20876
4 changed files with 18 additions and 6 deletions

View file

@ -451,6 +451,16 @@ void bdev_add(struct block_device *bdev, dev_t dev)
insert_inode_hash(bdev->bd_inode); insert_inode_hash(bdev->bd_inode);
} }
void bdev_unhash(struct block_device *bdev)
{
remove_inode_hash(bdev->bd_inode);
}
void bdev_drop(struct block_device *bdev)
{
iput(bdev->bd_inode);
}
long nr_blockdev_pages(void) long nr_blockdev_pages(void)
{ {
struct inode *inode; struct inode *inode;

View file

@ -428,6 +428,8 @@ static inline int blkdev_zone_mgmt_ioctl(struct block_device *bdev,
struct block_device *bdev_alloc(struct gendisk *disk, u8 partno); struct block_device *bdev_alloc(struct gendisk *disk, u8 partno);
void bdev_add(struct block_device *bdev, dev_t dev); void bdev_add(struct block_device *bdev, dev_t dev);
void bdev_unhash(struct block_device *bdev);
void bdev_drop(struct block_device *bdev);
int blk_alloc_ext_minor(void); int blk_alloc_ext_minor(void);
void blk_free_ext_minor(unsigned int minor); void blk_free_ext_minor(unsigned int minor);

View file

@ -656,7 +656,7 @@ void del_gendisk(struct gendisk *disk)
*/ */
mutex_lock(&disk->open_mutex); mutex_lock(&disk->open_mutex);
xa_for_each(&disk->part_tbl, idx, part) xa_for_each(&disk->part_tbl, idx, part)
remove_inode_hash(part->bd_inode); bdev_unhash(part);
mutex_unlock(&disk->open_mutex); mutex_unlock(&disk->open_mutex);
/* /*
@ -1191,7 +1191,7 @@ static void disk_release(struct device *dev)
if (test_bit(GD_ADDED, &disk->state) && disk->fops->free_disk) if (test_bit(GD_ADDED, &disk->state) && disk->fops->free_disk)
disk->fops->free_disk(disk); disk->fops->free_disk(disk);
iput(disk->part0->bd_inode); /* frees the disk */ bdev_drop(disk->part0); /* frees the disk */
} }
static int block_uevent(const struct device *dev, struct kobj_uevent_env *env) static int block_uevent(const struct device *dev, struct kobj_uevent_env *env)
@ -1381,7 +1381,7 @@ struct gendisk *__alloc_disk_node(struct request_queue *q, int node_id,
out_destroy_part_tbl: out_destroy_part_tbl:
xa_destroy(&disk->part_tbl); xa_destroy(&disk->part_tbl);
disk->part0->bd_disk = NULL; disk->part0->bd_disk = NULL;
iput(disk->part0->bd_inode); bdev_drop(disk->part0);
out_free_bdi: out_free_bdi:
bdi_put(disk->bdi); bdi_put(disk->bdi);
out_free_bioset: out_free_bioset:

View file

@ -243,7 +243,7 @@ static const struct attribute_group *part_attr_groups[] = {
static void part_release(struct device *dev) static void part_release(struct device *dev)
{ {
put_disk(dev_to_bdev(dev)->bd_disk); put_disk(dev_to_bdev(dev)->bd_disk);
iput(dev_to_bdev(dev)->bd_inode); bdev_drop(dev_to_bdev(dev));
} }
static int part_uevent(const struct device *dev, struct kobj_uevent_env *env) static int part_uevent(const struct device *dev, struct kobj_uevent_env *env)
@ -469,7 +469,7 @@ int bdev_del_partition(struct gendisk *disk, int partno)
* Just delete the partition and invalidate it. * Just delete the partition and invalidate it.
*/ */
remove_inode_hash(part->bd_inode); bdev_unhash(part);
invalidate_bdev(part); invalidate_bdev(part);
drop_partition(part); drop_partition(part);
ret = 0; ret = 0;
@ -655,7 +655,7 @@ int bdev_disk_changed(struct gendisk *disk, bool invalidate)
* it cannot be looked up any more even when openers * it cannot be looked up any more even when openers
* still hold references. * still hold references.
*/ */
remove_inode_hash(part->bd_inode); bdev_unhash(part);
/* /*
* If @disk->open_partitions isn't elevated but there's * If @disk->open_partitions isn't elevated but there's