dm: track per-add_disk holder relations in DM
authorChristoph Hellwig <hch@lst.de>
Tue, 15 Nov 2022 14:10:50 +0000 (22:10 +0800)
committerJens Axboe <axboe@kernel.dk>
Wed, 16 Nov 2022 22:19:56 +0000 (15:19 -0700)
commit1a581b72169968f4154b5793828f3bc28b258b35
tree4a3d39c84e97ef49064809164aa6e826e9f04752
parentd563792c8933a810d28ce0f2831f0726c2b15a31
dm: track per-add_disk holder relations in DM

dm is a bit special in that it opens the underlying devices.  Commit
89f871af1b26 ("dm: delay registering the gendisk") tried to accommodate
that by allowing to add the holder to the list before add_gendisk and
then just add them to sysfs once add_disk is called.  But that leads to
really odd lifetime problems and error handling problems as we can't
know the state of the kobjects and don't unwind properly.  To fix this
switch to just registering all existing table_devices with the holder
code right after add_disk, and remove them before calling del_gendisk.

Fixes: 89f871af1b26 ("dm: delay registering the gendisk")
Reported-by: Yu Kuai <yukuai3@huawei.com>
Signed-off-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Yu Kuai <yukuai3@huawei.com>
Reviewed-by: Mike Snitzer <snitzer@kernel.org>
Link: https://lore.kernel.org/r/20221115141054.1051801-7-yukuai1@huaweicloud.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>
drivers/md/dm.c