Skip to content

Commit

Permalink
block: move holder_dir to struct block_device
Browse files Browse the repository at this point in the history
Move the holder_dir field to struct block_device in preparation for
kill struct hd_struct.

Signed-off-by: Christoph Hellwig <[email protected]>
Reviewed-by: Jan Kara <[email protected]>
Reviewed-by: Hannes Reinecke <[email protected]>
Signed-off-by: Jens Axboe <[email protected]>
  • Loading branch information
Christoph Hellwig authored and axboe committed Dec 1, 2020
1 parent 231926d commit 1bdd5ae
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
5 changes: 3 additions & 2 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -681,7 +681,8 @@ static void register_disk(struct device *parent, struct gendisk *disk,
*/
pm_runtime_set_memalloc_noio(ddev, true);

disk->part0.holder_dir = kobject_create_and_add("holders", &ddev->kobj);
disk->part0.bdev->bd_holder_dir =
kobject_create_and_add("holders", &ddev->kobj);
disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj);

if (disk->flags & GENHD_FL_HIDDEN) {
Expand Down Expand Up @@ -887,7 +888,7 @@ void del_gendisk(struct gendisk *disk)

blk_unregister_queue(disk);

kobject_put(disk->part0.holder_dir);
kobject_put(disk->part0.bdev->bd_holder_dir);
kobject_put(disk->slave_dir);

part_stat_set_all(&disk->part0, 0);
Expand Down
8 changes: 4 additions & 4 deletions block/partitions/core.c
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ void delete_partition(struct hd_struct *part)
*/
get_device(disk_to_dev(disk));
rcu_assign_pointer(ptbl->part[part->partno], NULL);
kobject_put(part->holder_dir);
kobject_put(part->bdev->bd_holder_dir);
device_del(part_to_dev(part));

/*
Expand Down Expand Up @@ -452,8 +452,8 @@ static struct hd_struct *add_partition(struct gendisk *disk, int partno,
goto out_put;

err = -ENOMEM;
p->holder_dir = kobject_create_and_add("holders", &pdev->kobj);
if (!p->holder_dir)
bdev->bd_holder_dir = kobject_create_and_add("holders", &pdev->kobj);
if (!bdev->bd_holder_dir)
goto out_del;

dev_set_uevent_suppress(pdev, 0);
Expand Down Expand Up @@ -487,7 +487,7 @@ static struct hd_struct *add_partition(struct gendisk *disk, int partno,
out_remove_file:
device_remove_file(pdev, &dev_attr_whole_disk);
out_del:
kobject_put(p->holder_dir);
kobject_put(bdev->bd_holder_dir);
device_del(pdev);
out_put:
put_device(pdev);
Expand Down
11 changes: 5 additions & 6 deletions fs/block_dev.c
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk)
WARN_ON_ONCE(!bdev->bd_holder);

/* FIXME: remove the following once add_disk() handles errors */
if (WARN_ON(!disk->slave_dir || !bdev->bd_part->holder_dir))
if (WARN_ON(!disk->slave_dir || !bdev->bd_holder_dir))
goto out_unlock;

holder = bd_find_holder_disk(bdev, disk);
Expand All @@ -1165,14 +1165,14 @@ int bd_link_disk_holder(struct block_device *bdev, struct gendisk *disk)
if (ret)
goto out_free;

ret = add_symlink(bdev->bd_part->holder_dir, &disk_to_dev(disk)->kobj);
ret = add_symlink(bdev->bd_holder_dir, &disk_to_dev(disk)->kobj);
if (ret)
goto out_del;
/*
* bdev could be deleted beneath us which would implicitly destroy
* the holder directory. Hold on to it.
*/
kobject_get(bdev->bd_part->holder_dir);
kobject_get(bdev->bd_holder_dir);

list_add(&holder->list, &bdev->bd_holder_disks);
goto out_unlock;
Expand Down Expand Up @@ -1207,9 +1207,8 @@ void bd_unlink_disk_holder(struct block_device *bdev, struct gendisk *disk)

if (!WARN_ON_ONCE(holder == NULL) && !--holder->refcnt) {
del_symlink(disk->slave_dir, bdev_kobj(bdev));
del_symlink(bdev->bd_part->holder_dir,
&disk_to_dev(disk)->kobj);
kobject_put(bdev->bd_part->holder_dir);
del_symlink(bdev->bd_holder_dir, &disk_to_dev(disk)->kobj);
kobject_put(bdev->bd_holder_dir);
list_del_init(&holder->list);
kfree(holder);
}
Expand Down
1 change: 1 addition & 0 deletions include/linux/blk_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ struct block_device {
#ifdef CONFIG_SYSFS
struct list_head bd_holder_disks;
#endif
struct kobject *bd_holder_dir;
u8 bd_partno;
struct hd_struct * bd_part;
/* number of times partitions within this device have been opened. */
Expand Down
1 change: 0 additions & 1 deletion include/linux/genhd.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ struct hd_struct {

struct block_device *bdev;
struct device __dev;
struct kobject *holder_dir;
int policy, partno;
#ifdef CONFIG_FAIL_MAKE_REQUEST
int make_it_fail;
Expand Down

0 comments on commit 1bdd5ae

Please sign in to comment.