summaryrefslogtreecommitdiff
path: root/block/genhd.c
diff options
context:
space:
mode:
authorChristoph Hellwig <hch@lst.de>2021-08-04 12:41:43 +0300
committerJens Axboe <axboe@kernel.dk>2021-08-09 20:50:42 +0300
commitd626338735909bc2b2e7cafc332f44ed41cfdeee (patch)
tree44449bb3fd601e4fbd630928ce20284e76469e3e /block/genhd.c
parent0dbcfe247f22a6d73302dfa691c48b3c14d31c4c (diff)
downloadlinux-d626338735909bc2b2e7cafc332f44ed41cfdeee.tar.xz
block: support delayed holder registration
device mapper needs to register holders before it is ready to do I/O. Currently it does so by registering the disk early, which can leave the disk and queue in a weird half state where the queue is registered with the disk, except for sysfs and the elevator. And this state has been a bit promlematic before, and will get more so when sorting out the responsibilities between the queue and the disk. Support registering holders on an initialized but not registered disk instead by delaying the sysfs registration until the disk is registered. Signed-off-by: Christoph Hellwig <hch@lst.de> Reviewed-by: Mike Snitzer <snitzer@redhat.com> Link: https://lore.kernel.org/r/20210804094147.459763-5-hch@lst.de Signed-off-by: Jens Axboe <axboe@kernel.dk>
Diffstat (limited to 'block/genhd.c')
-rw-r--r--block/genhd.c10
1 files changed, 10 insertions, 0 deletions
diff --git a/block/genhd.c b/block/genhd.c
index cd4eab744667..db916f779077 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -447,6 +447,16 @@ static void register_disk(struct device *parent, struct gendisk *disk,
kobject_create_and_add("holders", &ddev->kobj);
disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj);
+ /*
+ * XXX: this is a mess, can't wait for real error handling in add_disk.
+ * Make sure ->slave_dir is NULL if we failed some of the registration
+ * so that the cleanup in bd_unlink_disk_holder works properly.
+ */
+ if (bd_register_pending_holders(disk) < 0) {
+ kobject_put(disk->slave_dir);
+ disk->slave_dir = NULL;
+ }
+
if (disk->flags & GENHD_FL_HIDDEN)
return;