Skip to content

Commit 89f871a

Browse files
Christoph Hellwigaxboe
authored andcommitted
dm: delay registering the gendisk
device mapper is currently the only outlier that tries to call register_disk after add_disk, leading to fairly inconsistent state of these block layer data structures. Instead change device-mapper to just register the gendisk later now that the holder mechanism can cope with that. Note that this introduces a user visible change: the dm kobject is now only visible after the initial table has been loaded. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Mike Snitzer <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jens Axboe <[email protected]>
1 parent ba30585 commit 89f871a

File tree

2 files changed

+11
-13
lines changed

2 files changed

+11
-13
lines changed

drivers/md/dm-rq.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,6 @@ int dm_mq_init_request_queue(struct mapped_device *md, struct dm_table *t)
559559
err = blk_mq_init_allocated_queue(md->tag_set, md->queue);
560560
if (err)
561561
goto out_tag_set;
562-
elevator_init_mq(md->queue);
563562
return 0;
564563

565564
out_tag_set:

drivers/md/dm.c

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,7 +1693,10 @@ static void cleanup_mapped_device(struct mapped_device *md)
16931693
spin_lock(&_minor_lock);
16941694
md->disk->private_data = NULL;
16951695
spin_unlock(&_minor_lock);
1696-
del_gendisk(md->disk);
1696+
if (dm_get_md_type(md) != DM_TYPE_NONE) {
1697+
dm_sysfs_exit(md);
1698+
del_gendisk(md->disk);
1699+
}
16971700
dm_queue_destroy_keyslot_manager(md->queue);
16981701
blk_cleanup_disk(md->disk);
16991702
}
@@ -1788,7 +1791,6 @@ static struct mapped_device *alloc_dev(int minor)
17881791
goto bad;
17891792
}
17901793

1791-
add_disk_no_queue_reg(md->disk);
17921794
format_dev_t(md->name, MKDEV(_major, minor));
17931795

17941796
md->wq = alloc_workqueue("kdmflush", WQ_MEM_RECLAIM, 0);
@@ -1989,19 +1991,12 @@ static struct dm_table *__unbind(struct mapped_device *md)
19891991
*/
19901992
int dm_create(int minor, struct mapped_device **result)
19911993
{
1992-
int r;
19931994
struct mapped_device *md;
19941995

19951996
md = alloc_dev(minor);
19961997
if (!md)
19971998
return -ENXIO;
19981999

1999-
r = dm_sysfs_init(md);
2000-
if (r) {
2001-
free_dev(md);
2002-
return r;
2003-
}
2004-
20052000
*result = md;
20062001
return 0;
20072002
}
@@ -2081,10 +2076,15 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t)
20812076
r = dm_table_set_restrictions(t, md->queue, &limits);
20822077
if (r)
20832078
return r;
2084-
md->type = type;
20852079

2086-
blk_register_queue(md->disk);
2080+
add_disk(md->disk);
20872081

2082+
r = dm_sysfs_init(md);
2083+
if (r) {
2084+
del_gendisk(md->disk);
2085+
return r;
2086+
}
2087+
md->type = type;
20882088
return 0;
20892089
}
20902090

@@ -2190,7 +2190,6 @@ static void __dm_destroy(struct mapped_device *md, bool wait)
21902190
DMWARN("%s: Forcibly removing mapped_device still in use! (%d users)",
21912191
dm_device_name(md), atomic_read(&md->holders));
21922192

2193-
dm_sysfs_exit(md);
21942193
dm_table_destroy(__unbind(md));
21952194
free_dev(md);
21962195
}

0 commit comments

Comments
 (0)