Commit 7abc0777 authored by Christoph Hellwig's avatar Christoph Hellwig Committed by Jens Axboe

block: remove delayed holder registration

Now that dm has been fixed to track of holder registrations before
add_disk, the somewhat buggy block layer code can be safely removed.
Signed-off-by: default avatarChristoph Hellwig <hch@lst.de>
Signed-off-by: default avatarYu Kuai <yukuai3@huawei.com>
Link: https://lore.kernel.org/r/20221115141054.1051801-8-yukuai1@huaweicloud.comSigned-off-by: default avatarJens Axboe <axboe@kernel.dk>
parent 1a581b72
...@@ -478,10 +478,6 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk, ...@@ -478,10 +478,6 @@ int __must_check device_add_disk(struct device *parent, struct gendisk *disk,
goto out_put_holder_dir; goto out_put_holder_dir;
} }
ret = bd_register_pending_holders(disk);
if (ret < 0)
goto out_put_slave_dir;
ret = blk_register_queue(disk); ret = blk_register_queue(disk);
if (ret) if (ret)
goto out_put_slave_dir; goto out_put_slave_dir;
......
...@@ -29,19 +29,6 @@ static void del_symlink(struct kobject *from, struct kobject *to) ...@@ -29,19 +29,6 @@ static void del_symlink(struct kobject *from, struct kobject *to)
sysfs_remove_link(from, kobject_name(to)); sysfs_remove_link(from, kobject_name(to));
} }
static int __link_disk_holder(struct block_device *bdev, struct gendisk *disk)
{
int ret;
ret = add_symlink(disk->slave_dir, bdev_kobj(bdev));
if (ret)
return ret;
ret = add_symlink(bdev->bd_holder_dir, &disk_to_dev(disk)->kobj);
if (ret)
del_symlink(disk->slave_dir, bdev_kobj(bdev));
return ret;
}
/** /**
* bd_link_disk_holder - create symlinks between holding disk and slave bdev * bd_link_disk_holder - create symlinks between holding disk and slave bdev
* @bdev: the claimed slave bdev * @bdev: the claimed slave bdev
...@@ -75,6 +62,9 @@ int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk) ...@@ -75,6 +62,9 @@ int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk)
struct bd_holder_disk *holder; struct bd_holder_disk *holder;
int ret = 0; int ret = 0;
if (WARN_ON_ONCE(!disk->slave_dir))
return -EINVAL;
mutex_lock(&disk->open_mutex); mutex_lock(&disk->open_mutex);
WARN_ON_ONCE(!bdev->bd_holder); WARN_ON_ONCE(!bdev->bd_holder);
...@@ -94,34 +84,32 @@ int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk) ...@@ -94,34 +84,32 @@ int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk)
INIT_LIST_HEAD(&holder->list); INIT_LIST_HEAD(&holder->list);
holder->bdev = bdev; holder->bdev = bdev;
holder->refcnt = 1; holder->refcnt = 1;
if (disk->slave_dir) { ret = add_symlink(disk->slave_dir, bdev_kobj(bdev));
ret = __link_disk_holder(bdev, disk); if (ret)
if (ret) { goto out_free_holder;
kfree(holder); ret = add_symlink(bdev->bd_holder_dir, &disk_to_dev(disk)->kobj);
goto out_unlock; if (ret)
} goto out_del_symlink;
}
list_add(&holder->list, &disk->slave_bdevs); list_add(&holder->list, &disk->slave_bdevs);
/* /*
* del_gendisk drops the initial reference to bd_holder_dir, so we need * del_gendisk drops the initial reference to bd_holder_dir, so we need
* to keep our own here to allow for cleanup past that point. * to keep our own here to allow for cleanup past that point.
*/ */
kobject_get(bdev->bd_holder_dir); kobject_get(bdev->bd_holder_dir);
mutex_unlock(&disk->open_mutex);
return 0;
out_del_symlink:
del_symlink(disk->slave_dir, bdev_kobj(bdev));
out_free_holder:
kfree(holder);
out_unlock: out_unlock:
mutex_unlock(&disk->open_mutex); mutex_unlock(&disk->open_mutex);
return ret; return ret;
} }
EXPORT_SYMBOL_GPL(bd_link_disk_holder); EXPORT_SYMBOL_GPL(bd_link_disk_holder);
static void __unlink_disk_holder(struct block_device *bdev,
struct gendisk *disk)
{
del_symlink(disk->slave_dir, bdev_kobj(bdev));
del_symlink(bdev->bd_holder_dir, &disk_to_dev(disk)->kobj);
}
/** /**
* bd_unlink_disk_holder - destroy symlinks created by bd_link_disk_holder() * bd_unlink_disk_holder - destroy symlinks created by bd_link_disk_holder()
* @bdev: the calimed slave bdev * @bdev: the calimed slave bdev
...@@ -136,11 +124,14 @@ void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk) ...@@ -136,11 +124,14 @@ void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk)
{ {
struct bd_holder_disk *holder; struct bd_holder_disk *holder;
if (WARN_ON_ONCE(!disk->slave_dir))
return;
mutex_lock(&disk->open_mutex); mutex_lock(&disk->open_mutex);
holder = bd_find_holder_disk(bdev, disk); holder = bd_find_holder_disk(bdev, disk);
if (!WARN_ON_ONCE(holder == NULL) && !--holder->refcnt) { if (!WARN_ON_ONCE(holder == NULL) && !--holder->refcnt) {
if (disk->slave_dir) del_symlink(disk->slave_dir, bdev_kobj(bdev));
__unlink_disk_holder(bdev, disk); del_symlink(bdev->bd_holder_dir, &disk_to_dev(disk)->kobj);
kobject_put(bdev->bd_holder_dir); kobject_put(bdev->bd_holder_dir);
list_del_init(&holder->list); list_del_init(&holder->list);
kfree(holder); kfree(holder);
...@@ -148,24 +139,3 @@ void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk) ...@@ -148,24 +139,3 @@ void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk)
mutex_unlock(&disk->open_mutex); mutex_unlock(&disk->open_mutex);
} }
EXPORT_SYMBOL_GPL(bd_unlink_disk_holder); EXPORT_SYMBOL_GPL(bd_unlink_disk_holder);
int bd_register_pending_holders(struct gendisk *disk)
{
struct bd_holder_disk *holder;
int ret;
mutex_lock(&disk->open_mutex);
list_for_each_entry(holder, &disk->slave_bdevs, list) {
ret = __link_disk_holder(holder->bdev, disk);
if (ret)
goto out_undo;
}
mutex_unlock(&disk->open_mutex);
return 0;
out_undo:
list_for_each_entry_continue_reverse(holder, &disk->slave_bdevs, list)
__unlink_disk_holder(holder->bdev, disk);
mutex_unlock(&disk->open_mutex);
return ret;
}
...@@ -833,7 +833,6 @@ void set_capacity(struct gendisk *disk, sector_t size); ...@@ -833,7 +833,6 @@ void set_capacity(struct gendisk *disk, sector_t size);
#ifdef CONFIG_BLOCK_HOLDER_DEPRECATED #ifdef CONFIG_BLOCK_HOLDER_DEPRECATED
int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk); int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk);
void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk); void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk);
int bd_register_pending_holders(struct gendisk *disk);
#else #else
static inline int bd_link_disk_holder(struct block_device *bdev, static inline int bd_link_disk_holder(struct block_device *bdev,
struct gendisk *disk) struct gendisk *disk)
...@@ -844,10 +843,6 @@ static inline void bd_unlink_disk_holder(struct block_device *bdev, ...@@ -844,10 +843,6 @@ static inline void bd_unlink_disk_holder(struct block_device *bdev,
struct gendisk *disk) struct gendisk *disk)
{ {
} }
static inline int bd_register_pending_holders(struct gendisk *disk)
{
return 0;
}
#endif /* CONFIG_BLOCK_HOLDER_DEPRECATED */ #endif /* CONFIG_BLOCK_HOLDER_DEPRECATED */
dev_t part_devt(struct gendisk *disk, u8 partno); dev_t part_devt(struct gendisk *disk, u8 partno);
......
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