From: Yu Kuai <yukuai1@huaweicloud.com> To: stable@vger.kernel.org, hch@lst.de, axboe@kernel.dk, snitzer@redhat.com Cc: dm-devel@redhat.com, linux-block@vger.kernel.org, yukuai3@huawei.com, yukuai1@huaweicloud.com, yi.zhang@huawei.com Subject: [PATCH stable 5.10 3/3] dm: delay registering the gendisk Date: Fri, 29 Jul 2022 14:23:56 +0800 [thread overview] Message-ID: <20220729062356.1663513-4-yukuai1@huaweicloud.com> (raw) In-Reply-To: <20220729062356.1663513-1-yukuai1@huaweicloud.com> From: Christoph Hellwig <hch@lst.de> commit 89f871af1b26d98d983cba7ed0e86effa45ba5f8 upstream. 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 <hch@lst.de> Reviewed-by: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Yu Kuai <yukuai3@huawei.com> --- drivers/md/dm.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index ab0e2338e47e..85efe2f1995f 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1795,7 +1795,12 @@ static void cleanup_mapped_device(struct mapped_device *md) spin_lock(&_minor_lock); md->disk->private_data = NULL; spin_unlock(&_minor_lock); - del_gendisk(md->disk); + if (dm_get_md_type(md) != DM_TYPE_NONE) { + dm_sysfs_exit(md); + del_gendisk(md->disk); + } else { + md->disk->queue = NULL; + } put_disk(md->disk); } @@ -1900,7 +1905,6 @@ static struct mapped_device *alloc_dev(int minor) } } - add_disk_no_queue_reg(md->disk); format_dev_t(md->name, MKDEV(_major, minor)); md->wq = alloc_workqueue("kdmflush", WQ_MEM_RECLAIM, 0); @@ -2098,19 +2102,12 @@ static struct dm_table *__unbind(struct mapped_device *md) */ int dm_create(int minor, struct mapped_device **result) { - int r; struct mapped_device *md; md = alloc_dev(minor); if (!md) return -ENXIO; - r = dm_sysfs_init(md); - if (r) { - free_dev(md); - return r; - } - *result = md; return 0; } @@ -2188,8 +2185,14 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t) return r; } dm_table_set_restrictions(t, md->queue, &limits); - blk_register_queue(md->disk); + add_disk(md->disk); + r = dm_sysfs_init(md); + if (r) { + del_gendisk(md->disk); + return r; + } + md->type = type; return 0; } @@ -2295,7 +2298,6 @@ static void __dm_destroy(struct mapped_device *md, bool wait) DMWARN("%s: Forcibly removing mapped_device still in use! (%d users)", dm_device_name(md), atomic_read(&md->holders)); - dm_sysfs_exit(md); dm_table_destroy(__unbind(md)); free_dev(md); } -- 2.31.1
WARNING: multiple messages have this Message-ID (diff)
From: Yu Kuai <yukuai1@huaweicloud.com> To: stable@vger.kernel.org, hch@lst.de, axboe@kernel.dk, snitzer@redhat.com Cc: linux-block@vger.kernel.org, yukuai3@huawei.com, dm-devel@redhat.com, yi.zhang@huawei.com, yukuai1@huaweicloud.com Subject: [dm-devel] [PATCH stable 5.10 3/3] dm: delay registering the gendisk Date: Fri, 29 Jul 2022 14:23:56 +0800 [thread overview] Message-ID: <20220729062356.1663513-4-yukuai1@huaweicloud.com> (raw) In-Reply-To: <20220729062356.1663513-1-yukuai1@huaweicloud.com> From: Christoph Hellwig <hch@lst.de> commit 89f871af1b26d98d983cba7ed0e86effa45ba5f8 upstream. 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 <hch@lst.de> Reviewed-by: Mike Snitzer <snitzer@redhat.com> Signed-off-by: Yu Kuai <yukuai3@huawei.com> --- drivers/md/dm.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/drivers/md/dm.c b/drivers/md/dm.c index ab0e2338e47e..85efe2f1995f 100644 --- a/drivers/md/dm.c +++ b/drivers/md/dm.c @@ -1795,7 +1795,12 @@ static void cleanup_mapped_device(struct mapped_device *md) spin_lock(&_minor_lock); md->disk->private_data = NULL; spin_unlock(&_minor_lock); - del_gendisk(md->disk); + if (dm_get_md_type(md) != DM_TYPE_NONE) { + dm_sysfs_exit(md); + del_gendisk(md->disk); + } else { + md->disk->queue = NULL; + } put_disk(md->disk); } @@ -1900,7 +1905,6 @@ static struct mapped_device *alloc_dev(int minor) } } - add_disk_no_queue_reg(md->disk); format_dev_t(md->name, MKDEV(_major, minor)); md->wq = alloc_workqueue("kdmflush", WQ_MEM_RECLAIM, 0); @@ -2098,19 +2102,12 @@ static struct dm_table *__unbind(struct mapped_device *md) */ int dm_create(int minor, struct mapped_device **result) { - int r; struct mapped_device *md; md = alloc_dev(minor); if (!md) return -ENXIO; - r = dm_sysfs_init(md); - if (r) { - free_dev(md); - return r; - } - *result = md; return 0; } @@ -2188,8 +2185,14 @@ int dm_setup_md_queue(struct mapped_device *md, struct dm_table *t) return r; } dm_table_set_restrictions(t, md->queue, &limits); - blk_register_queue(md->disk); + add_disk(md->disk); + r = dm_sysfs_init(md); + if (r) { + del_gendisk(md->disk); + return r; + } + md->type = type; return 0; } @@ -2295,7 +2298,6 @@ static void __dm_destroy(struct mapped_device *md, bool wait) DMWARN("%s: Forcibly removing mapped_device still in use! (%d users)", dm_device_name(md), atomic_read(&md->holders)); - dm_sysfs_exit(md); dm_table_destroy(__unbind(md)); free_dev(md); } -- 2.31.1 -- dm-devel mailing list dm-devel@redhat.com https://listman.redhat.com/mailman/listinfo/dm-devel
next prev parent reply other threads:[~2022-07-29 6:12 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2022-07-29 6:23 [PATCH stable 5.10 0/3] dm: fix nullptr crash Yu Kuai 2022-07-29 6:23 ` [dm-devel] " Yu Kuai 2022-07-29 6:23 ` [PATCH stable 5.10 1/3] block: look up holders by bdev Yu Kuai 2022-07-29 6:23 ` [dm-devel] " Yu Kuai 2022-08-01 11:19 ` Greg KH 2022-08-01 11:19 ` [dm-devel] " Greg KH 2022-08-01 12:25 ` Yu Kuai 2022-08-01 12:25 ` Yu Kuai 2022-08-01 13:17 ` Greg KH 2022-08-01 13:17 ` [dm-devel] " Greg KH 2022-08-01 13:39 ` Yu Kuai 2022-08-01 13:39 ` [dm-devel] " Yu Kuai 2022-08-01 13:43 ` Greg KH 2022-08-01 13:43 ` [dm-devel] " Greg KH 2022-08-01 18:04 ` Christoph Hellwig 2022-08-01 18:04 ` [dm-devel] " Christoph Hellwig 2022-08-02 5:11 ` Greg KH 2022-08-02 5:11 ` [dm-devel] " Greg KH 2022-08-08 3:31 ` Yu Kuai 2022-08-08 3:31 ` [dm-devel] " Yu Kuai 2022-07-29 6:23 ` [PATCH stable 5.10 2/3] block: support delayed holder registration Yu Kuai 2022-07-29 6:23 ` [dm-devel] " Yu Kuai 2022-07-29 6:23 ` Yu Kuai [this message] 2022-07-29 6:23 ` [dm-devel] [PATCH stable 5.10 3/3] dm: delay registering the gendisk Yu Kuai
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20220729062356.1663513-4-yukuai1@huaweicloud.com \ --to=yukuai1@huaweicloud.com \ --cc=axboe@kernel.dk \ --cc=dm-devel@redhat.com \ --cc=hch@lst.de \ --cc=linux-block@vger.kernel.org \ --cc=snitzer@redhat.com \ --cc=stable@vger.kernel.org \ --cc=yi.zhang@huawei.com \ --cc=yukuai3@huawei.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.