Skip to content

Commit

Permalink
block: add a disk_uevent helper
Browse files Browse the repository at this point in the history
Add a helper to call kobject_uevent for the disk and all partitions, and
unexport the disk_part_iter_* helpers that are now only used in the core
block code.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Acked-by: Tejun Heo <tj@kernel.org>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
  • Loading branch information
Christoph Hellwig authored and axboe committed Jan 25, 2021
1 parent 0b6e522 commit bc359d0
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 34 deletions.
27 changes: 14 additions & 13 deletions block/genhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,6 @@ void disk_part_iter_init(struct disk_part_iter *piter, struct gendisk *disk,

rcu_read_unlock();
}
EXPORT_SYMBOL_GPL(disk_part_iter_init);

/**
* disk_part_iter_next - proceed iterator to the next partition and return it
Expand Down Expand Up @@ -266,7 +265,6 @@ struct block_device *disk_part_iter_next(struct disk_part_iter *piter)

return piter->part;
}
EXPORT_SYMBOL_GPL(disk_part_iter_next);

/**
* disk_part_iter_exit - finish up partition iteration
Expand All @@ -283,7 +281,6 @@ void disk_part_iter_exit(struct disk_part_iter *piter)
bdput(piter->part);
piter->part = NULL;
}
EXPORT_SYMBOL_GPL(disk_part_iter_exit);

/**
* disk_has_partitions
Expand Down Expand Up @@ -555,6 +552,18 @@ static char *bdevt_str(dev_t devt, char *buf)
return buf;
}

void disk_uevent(struct gendisk *disk, enum kobject_action action)
{
struct disk_part_iter piter;
struct block_device *part;

disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
while ((part = disk_part_iter_next(&piter)))
kobject_uevent(bdev_kobj(part), action);
disk_part_iter_exit(&piter);
}
EXPORT_SYMBOL_GPL(disk_uevent);

static void disk_scan_partitions(struct gendisk *disk)
{
struct block_device *bdev;
Expand All @@ -572,8 +581,6 @@ static void register_disk(struct device *parent, struct gendisk *disk,
const struct attribute_group **groups)
{
struct device *ddev = disk_to_dev(disk);
struct disk_part_iter piter;
struct block_device *part;
int err;

ddev->parent = parent;
Expand Down Expand Up @@ -616,15 +623,9 @@ static void register_disk(struct device *parent, struct gendisk *disk,

disk_scan_partitions(disk);

/* announce disk after possible partitions are created */
/* announce the disk and partitions after all partitions are created */
dev_set_uevent_suppress(ddev, 0);
kobject_uevent(&ddev->kobj, KOBJ_ADD);

/* announce possible partitions */
disk_part_iter_init(&piter, disk, 0);
while ((part = disk_part_iter_next(&piter)))
kobject_uevent(bdev_kobj(part), KOBJ_ADD);
disk_part_iter_exit(&piter);
disk_uevent(disk, KOBJ_ADD);

if (disk->queue->backing_dev_info->dev) {
err = sysfs_create_link(&ddev->kobj,
Expand Down
26 changes: 5 additions & 21 deletions drivers/s390/block/dasd.c
Original file line number Diff line number Diff line change
Expand Up @@ -428,23 +428,15 @@ static int dasd_state_unfmt_to_basic(struct dasd_device *device)
static int
dasd_state_ready_to_online(struct dasd_device * device)
{
struct gendisk *disk;
struct disk_part_iter piter;
struct block_device *part;

device->state = DASD_STATE_ONLINE;
if (device->block) {
dasd_schedule_block_bh(device->block);
if ((device->features & DASD_FEATURE_USERAW)) {
disk = device->block->gdp;
kobject_uevent(&disk_to_dev(disk)->kobj, KOBJ_CHANGE);
kobject_uevent(&disk_to_dev(device->block->gdp)->kobj,
KOBJ_CHANGE);
return 0;
}
disk = device->block->bdev->bd_disk;
disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
while ((part = disk_part_iter_next(&piter)))
kobject_uevent(bdev_kobj(part), KOBJ_CHANGE);
disk_part_iter_exit(&piter);
disk_uevent(device->block->bdev->bd_disk, KOBJ_CHANGE);
}
return 0;
}
Expand All @@ -455,9 +447,6 @@ dasd_state_ready_to_online(struct dasd_device * device)
static int dasd_state_online_to_ready(struct dasd_device *device)
{
int rc;
struct gendisk *disk;
struct disk_part_iter piter;
struct block_device *part;

if (device->discipline->online_to_ready) {
rc = device->discipline->online_to_ready(device);
Expand All @@ -466,13 +455,8 @@ static int dasd_state_online_to_ready(struct dasd_device *device)
}

device->state = DASD_STATE_READY;
if (device->block && !(device->features & DASD_FEATURE_USERAW)) {
disk = device->block->bdev->bd_disk;
disk_part_iter_init(&piter, disk, DISK_PITER_INCL_PART0);
while ((part = disk_part_iter_next(&piter)))
kobject_uevent(bdev_kobj(part), KOBJ_CHANGE);
disk_part_iter_exit(&piter);
}
if (device->block && !(device->features & DASD_FEATURE_USERAW))
disk_uevent(device->block->bdev->bd_disk, KOBJ_CHANGE);
return 0;
}

Expand Down
2 changes: 2 additions & 0 deletions include/linux/genhd.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,8 @@ static inline dev_t disk_devt(struct gendisk *disk)
return MKDEV(disk->major, disk->first_minor);
}

void disk_uevent(struct gendisk *disk, enum kobject_action action);

/*
* Smarter partition iterator without context limits.
*/
Expand Down

0 comments on commit bc359d0

Please sign in to comment.