Skip to content

Commit 2638c20

Browse files
author
Al Viro
committed
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 <[email protected]>
1 parent 186ddac commit 2638c20

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

block/bdev.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -451,6 +451,16 @@ void bdev_add(struct block_device *bdev, dev_t dev)
451451
insert_inode_hash(bdev->bd_inode);
452452
}
453453

454+
void bdev_unhash(struct block_device *bdev)
455+
{
456+
remove_inode_hash(bdev->bd_inode);
457+
}
458+
459+
void bdev_drop(struct block_device *bdev)
460+
{
461+
iput(bdev->bd_inode);
462+
}
463+
454464
long nr_blockdev_pages(void)
455465
{
456466
struct inode *inode;

block/blk.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,8 @@ static inline int blkdev_zone_mgmt_ioctl(struct block_device *bdev,
428428

429429
struct block_device *bdev_alloc(struct gendisk *disk, u8 partno);
430430
void bdev_add(struct block_device *bdev, dev_t dev);
431+
void bdev_unhash(struct block_device *bdev);
432+
void bdev_drop(struct block_device *bdev);
431433

432434
int blk_alloc_ext_minor(void);
433435
void blk_free_ext_minor(unsigned int minor);

block/genhd.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ void del_gendisk(struct gendisk *disk)
656656
*/
657657
mutex_lock(&disk->open_mutex);
658658
xa_for_each(&disk->part_tbl, idx, part)
659-
remove_inode_hash(part->bd_inode);
659+
bdev_unhash(part);
660660
mutex_unlock(&disk->open_mutex);
661661

662662
/*
@@ -1191,7 +1191,7 @@ static void disk_release(struct device *dev)
11911191
if (test_bit(GD_ADDED, &disk->state) && disk->fops->free_disk)
11921192
disk->fops->free_disk(disk);
11931193

1194-
iput(disk->part0->bd_inode); /* frees the disk */
1194+
bdev_drop(disk->part0); /* frees the disk */
11951195
}
11961196

11971197
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,
13811381
out_destroy_part_tbl:
13821382
xa_destroy(&disk->part_tbl);
13831383
disk->part0->bd_disk = NULL;
1384-
iput(disk->part0->bd_inode);
1384+
bdev_drop(disk->part0);
13851385
out_free_bdi:
13861386
bdi_put(disk->bdi);
13871387
out_free_bioset:

block/partitions/core.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ static const struct attribute_group *part_attr_groups[] = {
243243
static void part_release(struct device *dev)
244244
{
245245
put_disk(dev_to_bdev(dev)->bd_disk);
246-
iput(dev_to_bdev(dev)->bd_inode);
246+
bdev_drop(dev_to_bdev(dev));
247247
}
248248

249249
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)
469469
* Just delete the partition and invalidate it.
470470
*/
471471

472-
remove_inode_hash(part->bd_inode);
472+
bdev_unhash(part);
473473
invalidate_bdev(part);
474474
drop_partition(part);
475475
ret = 0;
@@ -655,7 +655,7 @@ int bdev_disk_changed(struct gendisk *disk, bool invalidate)
655655
* it cannot be looked up any more even when openers
656656
* still hold references.
657657
*/
658-
remove_inode_hash(part->bd_inode);
658+
bdev_unhash(part);
659659

660660
/*
661661
* If @disk->open_partitions isn't elevated but there's

0 commit comments

Comments
 (0)