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)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Sat, 31 Dec 2022 12:32:12 +0000 (13:32 +0100)
commit773bfda35c9511734d7f898e2ee73cd60d2a3f38
treed4ecbfe1d2568dae099a49c9273524ee27020553
parentce65ef11d37e8342f17e7c822c43a2ff9317c016
dm: track per-add_disk holder relations in DM

[ Upstream commit 1a581b72169968f4154b5793828f3bc28b258b35 ]

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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/md/dm.c