From: Yu Kuai yukuai3@huawei.com
From: Christoph Hellwig hch@lst.de
mainline inclusion from mainline-v5.11-rc1 commit 6b3ba9762f9f9f651873af34481ca20e4a6791e7 category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I4SA9G
---------------------------
Merge three hidden gendisk checks into one.
Signed-off-by: Christoph Hellwig hch@lst.de Reviewed-by: Hannes Reinecke hare@suse.de Signed-off-by: Jens Axboe axboe@kernel.dk Signed-off-by: Yu Kuai yukuai3@huawei.com --- block/genhd.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c index 6566eacc807d..2a61dcd98d73 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -904,6 +904,9 @@ void del_gendisk(struct gendisk *disk)
might_sleep();
+ if (WARN_ON_ONCE(!disk->queue)) + return; + blk_integrity_del(disk); disk_del_events(disk);
@@ -926,20 +929,18 @@ void del_gendisk(struct gendisk *disk) disk->flags &= ~GENHD_FL_UP; up_write(&disk->lookup_sem);
- if (!(disk->flags & GENHD_FL_HIDDEN)) + if (!(disk->flags & GENHD_FL_HIDDEN)) { sysfs_remove_link(&disk_to_dev(disk)->kobj, "bdi"); - if (disk->queue) { + /* * Unregister bdi before releasing device numbers (as they can * get reused and we'd get clashes in sysfs). */ - if (!(disk->flags & GENHD_FL_HIDDEN)) - bdi_unregister(disk->queue->backing_dev_info); - blk_unregister_queue(disk); - } else { - WARN_ON(1); + bdi_unregister(disk->queue->backing_dev_info); }
+ blk_unregister_queue(disk); + if (!(disk->flags & GENHD_FL_HIDDEN)) blk_unregister_region(disk_devt(disk), disk->minors); /*
From patchwork Wed Jan 26 08:35:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai yukuai3@huawei.com X-Patchwork-Id: 152657 Return-Path: yukuai3@huawei.com Received: from dggems704-chm.china.huawei.com (10.3.19.181) by dggems702-chm.china.huawei.com (10.3.19.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Mailbox Transport; Wed, 26 Jan 2022 16:24:48 +0800 Received: from kwepemm600009.china.huawei.com (7.193.23.164) by dggems704-chm.china.huawei.com (10.3.19.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:47 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:46 +0800 From: Yu Kuai yukuai3@huawei.com To: zhengzengkai@huawei.com, xiexiuqi@huawei.com, patchwork@huawei.com CC: yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, chenxiaosong2@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, luomeng12@huawei.com, yanaijie@huawei.com, yangerkun@huawei.com, yebin10@huawei.com, yuyufen@huawei.com, zhangxiaoxu5@huawei.com, zhengbin13@huawei.com, koulihong@huawei.com, qiulaibin@huawei.com, zhengliang6@huawei.com Subject: [PATCH OLK-5.10 02/12] block: fold register_disk into device_add_disk Date: Wed, 26 Jan 2022 16:35:24 +0800 Message-ID: 20220126083534.4016012-3-yukuai3@huawei.com X-Mailer: git-send-email 2.31.1 In-Reply-To: 20220126083534.4016012-1-yukuai3@huawei.com References: 20220126083534.4016012-1-yukuai3@huawei.com Content-Type: text/plain X-MS-Exchange-Organization-Network-Message-Id: 3218969e-1bda-4724-aaa8-08d9e0a55088 X-MS-Exchange-Organization-AuthSource: kwepemm600009.china.huawei.com X-MS-Exchange-Organization-AuthAs: Internal X-MS-Exchange-Organization-AuthMechanism: 07 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600009.china.huawei.com (7.193.23.164) X-MS-Exchange-Transport-EndToEndLatency: 00:00:01.8705511 X-MS-Exchange-Processed-By-BccFoldering: 15.01.2308.021 MIME-Version: 1.0
From: Christoph Hellwig hch@lst.de
mainline inclusion from mainline-v5.15-rc1 commit 52b85909f85d06efa69aaf4210e72467f1f58d2b category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I4SA9G
---------------------------
There is no real reason these should be separate. Also simplify the groups assignment a bit.
Signed-off-by: Christoph Hellwig hch@lst.de Signed-off-by: Yu Kuai yukuai3@huawei.com --- block/genhd.c | 129 +++++++++++++++++++++++--------------------------- 1 file changed, 58 insertions(+), 71 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c index 2a61dcd98d73..c0e1639131d9 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -700,69 +700,6 @@ static void disk_scan_partitions(struct gendisk *disk) blkdev_put(bdev, FMODE_READ); }
-static void register_disk(struct device *parent, struct gendisk *disk, - const struct attribute_group **groups) -{ - struct device *ddev = disk_to_dev(disk); - struct disk_part_iter piter; - struct hd_struct *part; - int err; - - ddev->parent = parent; - - dev_set_name(ddev, "%s", disk->disk_name); - - /* delay uevents, until we scanned partition table */ - dev_set_uevent_suppress(ddev, 1); - - if (groups) { - WARN_ON(ddev->groups); - ddev->groups = groups; - } - if (device_add(ddev)) - return; - if (!sysfs_deprecated) { - err = sysfs_create_link(block_depr, &ddev->kobj, - kobject_name(&ddev->kobj)); - if (err) { - device_del(ddev); - return; - } - } - - /* - * avoid probable deadlock caused by allocating memory with - * GFP_KERNEL in runtime_resume callback of its all ancestor - * devices - */ - pm_runtime_set_memalloc_noio(ddev, true); - - disk->part0.holder_dir = kobject_create_and_add("holders", &ddev->kobj); - disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj); - - if (disk->flags & GENHD_FL_HIDDEN) - return; - - disk_scan_partitions(disk); - - /* announce disk after possible partitions are created */ - dev_set_uevent_suppress(ddev, 0); - kobject_uevent(&ddev->kobj, KOBJ_ADD); - - /* announce possible partitions */ - disk_part_iter_init(&piter, disk, 0); - while ((part = disk_part_iter_next(&piter))) - kobject_uevent(&part_to_dev(part)->kobj, KOBJ_ADD); - disk_part_iter_exit(&piter); - - if (disk->queue->backing_dev_info->dev) { - err = sysfs_create_link(&ddev->kobj, - &disk->queue->backing_dev_info->dev->kobj, - "bdi"); - WARN_ON(err); - } -} - /** * __device_add_disk - add disk information to kernel list * @parent: parent device for the disk @@ -779,8 +716,11 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, const struct attribute_group **groups, bool register_queue) { + struct device *ddev = disk_to_dev(disk); + struct disk_part_iter piter; + struct hd_struct *part; dev_t devt; - int retval; + int ret;
/* * The disk queue should now be all set with enough information about @@ -801,8 +741,8 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk,
disk->flags |= GENHD_FL_UP;
- retval = blk_alloc_devt(&disk->part0, &devt); - if (retval) { + ret = blk_alloc_devt(&disk->part0, &devt); + if (ret) { WARN_ON(1); return; } @@ -820,18 +760,65 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, disk->flags |= GENHD_FL_NO_PART_SCAN; } else { struct backing_dev_info *bdi = disk->queue->backing_dev_info; - struct device *dev = disk_to_dev(disk); - int ret;
/* Register BDI before referencing it from bdev */ - dev->devt = devt; + ddev->devt = devt; ret = bdi_register(bdi, "%u:%u", MAJOR(devt), MINOR(devt)); WARN_ON(ret); - bdi_set_owner(bdi, dev); + bdi_set_owner(bdi, ddev); blk_register_region(disk_devt(disk), disk->minors, NULL, exact_match, exact_lock, disk); } - register_disk(parent, disk, groups); + + /* delay uevents, until we scanned partition table */ + dev_set_uevent_suppress(ddev, 1); + + ddev->parent = parent; + ddev->groups = groups; + dev_set_name(ddev, "%s", disk->disk_name); + + if (device_add(ddev)) + return; + if (!sysfs_deprecated) { + ret = sysfs_create_link(block_depr, &ddev->kobj, + kobject_name(&ddev->kobj)); + if (ret) { + device_del(ddev); + return; + } + } + + /* + * avoid probable deadlock caused by allocating memory with + * GFP_KERNEL in runtime_resume callback of its all ancestor + * devices + */ + pm_runtime_set_memalloc_noio(ddev, true); + + disk->part0.holder_dir = kobject_create_and_add("holders", &ddev->kobj); + disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj); + + if (!(disk->flags & GENHD_FL_HIDDEN)) { + disk_scan_partitions(disk); + + /* announce disk after possible partitions are created */ + dev_set_uevent_suppress(ddev, 0); + kobject_uevent(&ddev->kobj, KOBJ_ADD); + + /* announce possible partitions */ + disk_part_iter_init(&piter, disk, 0); + while ((part = disk_part_iter_next(&piter))) + kobject_uevent(&part_to_dev(part)->kobj, KOBJ_ADD); + disk_part_iter_exit(&piter); + + if (disk->queue->backing_dev_info->dev) { + ret = sysfs_create_link(&ddev->kobj, + &disk->queue->backing_dev_info->dev->kobj, + "bdi"); + WARN_ON(ret); + } + } + if (register_queue) blk_register_queue(disk);
From patchwork Wed Jan 26 08:35:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai yukuai3@huawei.com X-Patchwork-Id: 152658 Return-Path: yukuai3@huawei.com Received: from dggems706-chm.china.huawei.com (10.3.19.183) by dggems702-chm.china.huawei.com (10.3.19.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Mailbox Transport; Wed, 26 Jan 2022 16:24:49 +0800 Received: from kwepemm600009.china.huawei.com (7.193.23.164) by dggems706-chm.china.huawei.com (10.3.19.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:49 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:47 +0800 From: Yu Kuai yukuai3@huawei.com To: zhengzengkai@huawei.com, xiexiuqi@huawei.com, patchwork@huawei.com CC: yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, chenxiaosong2@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, luomeng12@huawei.com, yanaijie@huawei.com, yangerkun@huawei.com, yebin10@huawei.com, yuyufen@huawei.com, zhangxiaoxu5@huawei.com, zhengbin13@huawei.com, koulihong@huawei.com, qiulaibin@huawei.com, zhengliang6@huawei.com Subject: [PATCH OLK-5.10 03/12] block: set GENHD_FL_UP last in __device_add_disk() Date: Wed, 26 Jan 2022 16:35:25 +0800 Message-ID: 20220126083534.4016012-4-yukuai3@huawei.com X-Mailer: git-send-email 2.31.1 In-Reply-To: 20220126083534.4016012-1-yukuai3@huawei.com References: 20220126083534.4016012-1-yukuai3@huawei.com Content-Type: text/plain X-MS-Exchange-Organization-Network-Message-Id: d49516fb-3c05-44d0-73f3-08d9e0a55156 X-MS-Exchange-Organization-AuthSource: kwepemm600009.china.huawei.com X-MS-Exchange-Organization-AuthAs: Internal X-MS-Exchange-Organization-AuthMechanism: 07 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600009.china.huawei.com (7.193.23.164) X-MS-Exchange-Transport-EndToEndLatency: 00:00:01.7552871 X-MS-Exchange-Processed-By-BccFoldering: 15.01.2308.021 MIME-Version: 1.0
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I4SA9G
---------------------------
The flag will be checked before operations on the block device, thus don't set the flag is some errors occurred.
Signed-off-by: Yu Kuai yukuai3@huawei.com --- block/genhd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c index c0e1639131d9..59bdb43ccf17 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -739,8 +739,6 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, WARN_ON(!disk->minors && !(disk->flags & (GENHD_FL_EXT_DEVT | GENHD_FL_HIDDEN)));
- disk->flags |= GENHD_FL_UP; - ret = blk_alloc_devt(&disk->part0, &devt); if (ret) { WARN_ON(1); @@ -830,6 +828,8 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk,
disk_add_events(disk); blk_integrity_add(disk); + + disk->flags |= GENHD_FL_UP; }
void device_add_disk(struct device *parent, struct gendisk *disk,
From patchwork Wed Jan 26 08:35:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai yukuai3@huawei.com X-Patchwork-Id: 152659 Return-Path: yukuai3@huawei.com Received: from dggems705-chm.china.huawei.com (10.3.19.182) by dggems702-chm.china.huawei.com (10.3.19.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Mailbox Transport; Wed, 26 Jan 2022 16:24:50 +0800 Received: from kwepemm600009.china.huawei.com (7.193.23.164) by dggems705-chm.china.huawei.com (10.3.19.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:50 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:49 +0800 From: Yu Kuai yukuai3@huawei.com To: zhengzengkai@huawei.com, xiexiuqi@huawei.com, patchwork@huawei.com CC: yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, chenxiaosong2@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, luomeng12@huawei.com, yanaijie@huawei.com, yangerkun@huawei.com, yebin10@huawei.com, yuyufen@huawei.com, zhangxiaoxu5@huawei.com, zhengbin13@huawei.com, koulihong@huawei.com, qiulaibin@huawei.com, zhengliang6@huawei.com Subject: [PATCH OLK-5.10 04/12] block: call bdi_register() later in __device_add_disk() Date: Wed, 26 Jan 2022 16:35:26 +0800 Message-ID: 20220126083534.4016012-5-yukuai3@huawei.com X-Mailer: git-send-email 2.31.1 In-Reply-To: 20220126083534.4016012-1-yukuai3@huawei.com References: 20220126083534.4016012-1-yukuai3@huawei.com Content-Type: text/plain X-MS-Exchange-Organization-Network-Message-Id: 1a9bddc2-3045-4a62-422a-08d9e0a55221 X-MS-Exchange-Organization-AuthSource: kwepemm600009.china.huawei.com X-MS-Exchange-Organization-AuthAs: Internal X-MS-Exchange-Organization-AuthMechanism: 07 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600009.china.huawei.com (7.193.23.164) X-MS-Exchange-Transport-EndToEndLatency: 00:00:01.8140598 X-MS-Exchange-Processed-By-BccFoldering: 15.01.2308.021 MIME-Version: 1.0
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I4SA9G
---------------------------
This will simplify error handling going forward.
Conflict: "ddev->devt = devt" must be set before add_disk(). Signed-off-by: Yu Kuai yukuai3@huawei.com --- block/genhd.c | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c index 59bdb43ccf17..b0a6214fdbe1 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -749,24 +749,8 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk,
disk_alloc_events(disk);
- if (disk->flags & GENHD_FL_HIDDEN) { - /* - * Don't let hidden disks show up in /proc/partitions, - * and don't bother scanning for partitions either. - */ - disk->flags |= GENHD_FL_SUPPRESS_PARTITION_INFO; - disk->flags |= GENHD_FL_NO_PART_SCAN; - } else { - struct backing_dev_info *bdi = disk->queue->backing_dev_info; - - /* Register BDI before referencing it from bdev */ + if (!(disk->flags & GENHD_FL_HIDDEN)) ddev->devt = devt; - ret = bdi_register(bdi, "%u:%u", MAJOR(devt), MINOR(devt)); - WARN_ON(ret); - bdi_set_owner(bdi, ddev); - blk_register_region(disk_devt(disk), disk->minors, NULL, - exact_match, exact_lock, disk); - }
/* delay uevents, until we scanned partition table */ dev_set_uevent_suppress(ddev, 1); @@ -796,7 +780,22 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, disk->part0.holder_dir = kobject_create_and_add("holders", &ddev->kobj); disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj);
- if (!(disk->flags & GENHD_FL_HIDDEN)) { + if (disk->flags & GENHD_FL_HIDDEN) { + /* + * Don't let hidden disks show up in /proc/partitions, + * and don't bother scanning for partitions either. + */ + disk->flags |= GENHD_FL_SUPPRESS_PARTITION_INFO; + disk->flags |= GENHD_FL_NO_PART_SCAN; + } else { + struct backing_dev_info *bdi = disk->queue->backing_dev_info; + + ret = bdi_register(bdi, "%u:%u", MAJOR(devt), MINOR(devt)); + WARN_ON(ret); + bdi_set_owner(bdi, ddev); + blk_register_region(disk_devt(disk), disk->minors, NULL, + exact_match, exact_lock, disk); + disk_scan_partitions(disk);
/* announce disk after possible partitions are created */
From patchwork Wed Jan 26 08:35:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai yukuai3@huawei.com X-Patchwork-Id: 152660 Return-Path: yukuai3@huawei.com Received: from dggems701-chm.china.huawei.com (10.3.19.178) by dggems702-chm.china.huawei.com (10.3.19.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Mailbox Transport; Wed, 26 Jan 2022 16:24:52 +0800 Received: from kwepemm600009.china.huawei.com (7.193.23.164) by dggems701-chm.china.huawei.com (10.3.19.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:51 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:50 +0800 From: Yu Kuai yukuai3@huawei.com To: zhengzengkai@huawei.com, xiexiuqi@huawei.com, patchwork@huawei.com CC: yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, chenxiaosong2@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, luomeng12@huawei.com, yanaijie@huawei.com, yangerkun@huawei.com, yebin10@huawei.com, yuyufen@huawei.com, zhangxiaoxu5@huawei.com, zhengbin13@huawei.com, koulihong@huawei.com, qiulaibin@huawei.com, zhengliang6@huawei.com Subject: [PATCH OLK-5.10 05/12] block: create the bdi link earlier in device_add_disk Date: Wed, 26 Jan 2022 16:35:27 +0800 Message-ID: 20220126083534.4016012-6-yukuai3@huawei.com X-Mailer: git-send-email 2.31.1 In-Reply-To: 20220126083534.4016012-1-yukuai3@huawei.com References: 20220126083534.4016012-1-yukuai3@huawei.com Content-Type: text/plain X-MS-Exchange-Organization-Network-Message-Id: fad6c294-ac99-4316-207b-08d9e0a552ea X-MS-Exchange-Organization-AuthSource: kwepemm600009.china.huawei.com X-MS-Exchange-Organization-AuthAs: Internal X-MS-Exchange-Organization-AuthMechanism: 07 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600009.china.huawei.com (7.193.23.164) X-MS-Exchange-Transport-EndToEndLatency: 00:00:01.8454101 X-MS-Exchange-Processed-By-BccFoldering: 15.01.2308.021 MIME-Version: 1.0
From: Christoph Hellwig hch@lst.de
mainline inclusion from mainline-v5.15-rc1 commit 9d5ee6767c85762205b788ed1245f21fafd6c504 category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I4SA9G
---------------------------
This will simplify error handling going forward.
Signed-off-by: Christoph Hellwig hch@lst.de Signed-off-by: Yu Kuai yukuai3@huawei.com --- block/genhd.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c index b0a6214fdbe1..b875de09dd09 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -796,6 +796,13 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, blk_register_region(disk_devt(disk), disk->minors, NULL, exact_match, exact_lock, disk);
+ if (disk->queue->backing_dev_info->dev) { + ret = sysfs_create_link(&ddev->kobj, + &disk->queue->backing_dev_info->dev->kobj, + "bdi"); + WARN_ON(ret); + } + disk_scan_partitions(disk);
/* announce disk after possible partitions are created */ @@ -807,13 +814,6 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, while ((part = disk_part_iter_next(&piter))) kobject_uevent(&part_to_dev(part)->kobj, KOBJ_ADD); disk_part_iter_exit(&piter); - - if (disk->queue->backing_dev_info->dev) { - ret = sysfs_create_link(&ddev->kobj, - &disk->queue->backing_dev_info->dev->kobj, - "bdi"); - WARN_ON(ret); - } }
if (register_queue)
From patchwork Wed Jan 26 08:35:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai yukuai3@huawei.com X-Patchwork-Id: 152661 Return-Path: yukuai3@huawei.com Received: from dggems702-chm.china.huawei.com (10.3.19.179) by dggems702-chm.china.huawei.com (10.3.19.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Mailbox Transport; Wed, 26 Jan 2022 16:24:53 +0800 Received: from kwepemm600009.china.huawei.com (7.193.23.164) by dggems702-chm.china.huawei.com (10.3.19.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:53 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:51 +0800 From: Yu Kuai yukuai3@huawei.com To: zhengzengkai@huawei.com, xiexiuqi@huawei.com, patchwork@huawei.com CC: yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, chenxiaosong2@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, luomeng12@huawei.com, yanaijie@huawei.com, yangerkun@huawei.com, yebin10@huawei.com, yuyufen@huawei.com, zhangxiaoxu5@huawei.com, zhengbin13@huawei.com, koulihong@huawei.com, qiulaibin@huawei.com, zhengliang6@huawei.com Subject: [PATCH OLK-5.10 06/12] block: call blk_integrity_add earlier in device_add_disk Date: Wed, 26 Jan 2022 16:35:28 +0800 Message-ID: 20220126083534.4016012-7-yukuai3@huawei.com X-Mailer: git-send-email 2.31.1 In-Reply-To: 20220126083534.4016012-1-yukuai3@huawei.com References: 20220126083534.4016012-1-yukuai3@huawei.com Content-Type: text/plain X-MS-Exchange-Organization-Network-Message-Id: e89abd69-efcc-473e-5645-08d9e0a553b4 X-MS-Exchange-Organization-AuthSource: kwepemm600009.china.huawei.com X-MS-Exchange-Organization-AuthAs: Internal X-MS-Exchange-Organization-AuthMechanism: 07 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600009.china.huawei.com (7.193.23.164) X-MS-Exchange-Transport-EndToEndLatency: 00:00:01.7513136 X-MS-Exchange-Processed-By-BccFoldering: 15.01.2308.021 MIME-Version: 1.0
From: Christoph Hellwig hch@lst.de
mainline inclusion from mainline-v5.15-rc1 commit bab53f6b617d9f530978d6e3693f88e586d81a8a category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I4SA9G
---------------------------
Doing all the sysfs file creation before adding the bdev and thus allowing it to be opened will simplify the about to be added error handling.
Signed-off-by: Christoph Hellwig hch@lst.de Signed-off-by: Yu Kuai yukuai3@huawei.com --- block/genhd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/block/genhd.c b/block/genhd.c index b875de09dd09..aa109986a6b0 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -777,6 +777,8 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, */ pm_runtime_set_memalloc_noio(ddev, true);
+ blk_integrity_add(disk); + disk->part0.holder_dir = kobject_create_and_add("holders", &ddev->kobj); disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj);
@@ -826,7 +828,6 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, WARN_ON_ONCE(!blk_get_queue(disk->queue));
disk_add_events(disk); - blk_integrity_add(disk);
disk->flags |= GENHD_FL_UP; }
From patchwork Wed Jan 26 08:35:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai yukuai3@huawei.com X-Patchwork-Id: 152662 Return-Path: yukuai3@huawei.com Received: from dggems703-chm.china.huawei.com (10.3.19.180) by dggems702-chm.china.huawei.com (10.3.19.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Mailbox Transport; Wed, 26 Jan 2022 16:24:54 +0800 Received: from kwepemm600009.china.huawei.com (7.193.23.164) by dggems703-chm.china.huawei.com (10.3.19.180) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:54 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:53 +0800 From: Yu Kuai yukuai3@huawei.com To: zhengzengkai@huawei.com, xiexiuqi@huawei.com, patchwork@huawei.com CC: yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, chenxiaosong2@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, luomeng12@huawei.com, yanaijie@huawei.com, yangerkun@huawei.com, yebin10@huawei.com, yuyufen@huawei.com, zhangxiaoxu5@huawei.com, zhengbin13@huawei.com, koulihong@huawei.com, qiulaibin@huawei.com, zhengliang6@huawei.com Subject: [PATCH OLK-5.10 07/12] block: return errors from blk_integrity_add Date: Wed, 26 Jan 2022 16:35:29 +0800 Message-ID: 20220126083534.4016012-8-yukuai3@huawei.com X-Mailer: git-send-email 2.31.1 In-Reply-To: 20220126083534.4016012-1-yukuai3@huawei.com References: 20220126083534.4016012-1-yukuai3@huawei.com Content-Type: text/plain X-MS-Exchange-Organization-Network-Message-Id: 85f46a94-096f-4839-b1f3-08d9e0a5547e X-MS-Exchange-Organization-AuthSource: kwepemm600009.china.huawei.com X-MS-Exchange-Organization-AuthAs: Internal X-MS-Exchange-Organization-AuthMechanism: 07 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600009.china.huawei.com (7.193.23.164) X-MS-Exchange-Transport-EndToEndLatency: 00:00:01.7611417 X-MS-Exchange-Processed-By-BccFoldering: 15.01.2308.021 MIME-Version: 1.0
From: Luis Chamberlain mcgrof@kernel.org
mainline inclusion from mainline-v5.15-rc1 commit 614310c9c8ca15359f4e71a5bbd9165897b4d54e category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I4SA9G
---------------------------
Prepare for proper error handling in add_disk.
Signed-off-by: Luis Chamberlain mcgrof@kernel.org [hch: split from a larger patch] Signed-off-by: Christoph Hellwig hch@lst.de Reviewed-by: Hannes Reinecke hare@suse.de Link: https://lore.kernel.org/r/20210818144542.19305-8-hch@lst.de Signed-off-by: Jens Axboe axboe@kernel.dk Signed-off-by: Yu Kuai yukuai3@huawei.com --- block/blk-integrity.c | 12 +++++++----- block/blk.h | 5 +++-- 2 files changed, 10 insertions(+), 7 deletions(-)
diff --git a/block/blk-integrity.c b/block/blk-integrity.c index 9e83159f5a52..16d5d5338392 100644 --- a/block/blk-integrity.c +++ b/block/blk-integrity.c @@ -438,13 +438,15 @@ void blk_integrity_unregister(struct gendisk *disk) } EXPORT_SYMBOL(blk_integrity_unregister);
-void blk_integrity_add(struct gendisk *disk) +int blk_integrity_add(struct gendisk *disk) { - if (kobject_init_and_add(&disk->integrity_kobj, &integrity_ktype, - &disk_to_dev(disk)->kobj, "%s", "integrity")) - return; + int ret;
- kobject_uevent(&disk->integrity_kobj, KOBJ_ADD); + ret = kobject_init_and_add(&disk->integrity_kobj, &integrity_ktype, + &disk_to_dev(disk)->kobj, "%s", "integrity"); + if (!ret) + kobject_uevent(&disk->integrity_kobj, KOBJ_ADD); + return ret; }
void blk_integrity_del(struct gendisk *disk) diff --git a/block/blk.h b/block/blk.h index cd39fd0c93f1..80bb41a43120 100644 --- a/block/blk.h +++ b/block/blk.h @@ -134,7 +134,7 @@ static inline bool integrity_req_gap_front_merge(struct request *req, bip_next->bip_vec[0].bv_offset); }
-void blk_integrity_add(struct gendisk *); +int blk_integrity_add(struct gendisk *disk); void blk_integrity_del(struct gendisk *); #else /* CONFIG_BLK_DEV_INTEGRITY */ static inline bool blk_integrity_merge_rq(struct request_queue *rq, @@ -168,8 +168,9 @@ static inline bool bio_integrity_endio(struct bio *bio) static inline void bio_integrity_free(struct bio *bio) { } -static inline void blk_integrity_add(struct gendisk *disk) +static inline int blk_integrity_add(struct gendisk *disk) { + return 0; } static inline void blk_integrity_del(struct gendisk *disk) {
From patchwork Wed Jan 26 08:35:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai yukuai3@huawei.com X-Patchwork-Id: 152663 Return-Path: yukuai3@huawei.com Received: from dggems704-chm.china.huawei.com (10.3.19.181) by dggems702-chm.china.huawei.com (10.3.19.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Mailbox Transport; Wed, 26 Jan 2022 16:24:56 +0800 Received: from kwepemm600009.china.huawei.com (7.193.23.164) by dggems704-chm.china.huawei.com (10.3.19.181) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:55 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:54 +0800 From: Yu Kuai yukuai3@huawei.com To: zhengzengkai@huawei.com, xiexiuqi@huawei.com, patchwork@huawei.com CC: yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, chenxiaosong2@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, luomeng12@huawei.com, yanaijie@huawei.com, yangerkun@huawei.com, yebin10@huawei.com, yuyufen@huawei.com, zhangxiaoxu5@huawei.com, zhengbin13@huawei.com, koulihong@huawei.com, qiulaibin@huawei.com, zhengliang6@huawei.com Subject: [PATCH OLK-5.10 08/12] block: return errors from disk_alloc_events Date: Wed, 26 Jan 2022 16:35:30 +0800 Message-ID: 20220126083534.4016012-9-yukuai3@huawei.com X-Mailer: git-send-email 2.31.1 In-Reply-To: 20220126083534.4016012-1-yukuai3@huawei.com References: 20220126083534.4016012-1-yukuai3@huawei.com Content-Type: text/plain X-MS-Exchange-Organization-Network-Message-Id: 2664ecdf-dfd3-496d-02da-08d9e0a55548 X-MS-Exchange-Organization-AuthSource: kwepemm600009.china.huawei.com X-MS-Exchange-Organization-AuthAs: Internal X-MS-Exchange-Organization-AuthMechanism: 07 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600009.china.huawei.com (7.193.23.164) X-MS-Exchange-Transport-EndToEndLatency: 00:00:01.7000588 X-MS-Exchange-Processed-By-BccFoldering: 15.01.2308.021 MIME-Version: 1.0
From: Luis Chamberlain mcgrof@kernel.org
mainline inclusion from mainline-v5.15-rc1 commit 92e7755ebc69233e25a2d1b760aeff536dc4016b category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I4SA9G
---------------------------
Prepare for proper error handling in add_disk.
Signed-off-by: Luis Chamberlain mcgrof@kernel.org [hch: split from a larger patch] Signed-off-by: Christoph Hellwig hch@lst.de Reviewed-by: Hannes Reinecke hare@suse.de Link: https://lore.kernel.org/r/20210818144542.19305-9-hch@lst.de Signed-off-by: Jens Axboe axboe@kernel.dk Signed-off-by: Yu Kuai yukuai3@huawei.com --- block/genhd.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c index aa109986a6b0..ec1e2fe27249 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -40,7 +40,7 @@ static DEFINE_IDR(ext_devt_idr);
static void disk_check_events(struct disk_events *ev, unsigned int *clearing_ptr); -static void disk_alloc_events(struct gendisk *disk); +static int disk_alloc_events(struct gendisk *disk); static void disk_add_events(struct gendisk *disk); static void disk_del_events(struct gendisk *disk); static void disk_release_events(struct gendisk *disk); @@ -2311,17 +2311,17 @@ module_param_cb(events_dfl_poll_msecs, &disk_events_dfl_poll_msecs_param_ops, /* * disk_{alloc|add|del|release}_events - initialize and destroy disk_events. */ -static void disk_alloc_events(struct gendisk *disk) +static int disk_alloc_events(struct gendisk *disk) { struct disk_events *ev;
if (!disk->fops->check_events || !disk->events) - return; + return 0;
ev = kzalloc(sizeof(*ev), GFP_KERNEL); if (!ev) { pr_warn("%s: failed to initialize events\n", disk->disk_name); - return; + return -ENOMEM; }
INIT_LIST_HEAD(&ev->node); @@ -2333,6 +2333,7 @@ static void disk_alloc_events(struct gendisk *disk) INIT_DELAYED_WORK(&ev->dwork, disk_events_workfn);
disk->ev = ev; + return 0; }
static void disk_add_events(struct gendisk *disk)
From patchwork Wed Jan 26 08:35:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai yukuai3@huawei.com X-Patchwork-Id: 152664 Return-Path: yukuai3@huawei.com Received: from dggems706-chm.china.huawei.com (10.3.19.183) by dggems702-chm.china.huawei.com (10.3.19.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Mailbox Transport; Wed, 26 Jan 2022 16:24:57 +0800 Received: from kwepemm600009.china.huawei.com (7.193.23.164) by dggems706-chm.china.huawei.com (10.3.19.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:57 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:55 +0800 From: Yu Kuai yukuai3@huawei.com To: zhengzengkai@huawei.com, xiexiuqi@huawei.com, patchwork@huawei.com CC: yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, chenxiaosong2@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, luomeng12@huawei.com, yanaijie@huawei.com, yangerkun@huawei.com, yebin10@huawei.com, yuyufen@huawei.com, zhangxiaoxu5@huawei.com, zhengbin13@huawei.com, koulihong@huawei.com, qiulaibin@huawei.com, zhengliang6@huawei.com Subject: [PATCH OLK-5.10 09/12] block: refactor device number setup in __device_add_disk Date: Wed, 26 Jan 2022 16:35:31 +0800 Message-ID: 20220126083534.4016012-10-yukuai3@huawei.com X-Mailer: git-send-email 2.31.1 In-Reply-To: 20220126083534.4016012-1-yukuai3@huawei.com References: 20220126083534.4016012-1-yukuai3@huawei.com Content-Type: text/plain X-MS-Exchange-Organization-Network-Message-Id: d9a6c01c-83ab-4afd-0792-08d9e0a55611 X-MS-Exchange-Organization-AuthSource: kwepemm600009.china.huawei.com X-MS-Exchange-Organization-AuthAs: Internal X-MS-Exchange-Organization-AuthMechanism: 07 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600009.china.huawei.com (7.193.23.164) X-MS-Exchange-Transport-EndToEndLatency: 00:00:01.8228257 X-MS-Exchange-Processed-By-BccFoldering: 15.01.2308.021 MIME-Version: 1.0
mainline inclusion from mainline-v5.14-rc1 commit 7c3f828b522b07adb341b08fde1660685c5ba3eb category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I4SA9G
---------------------------
Untangle the mess around blk_alloc_devt by moving the check for the used allocation scheme into the callers.
Signed-off-by: Christoph Hellwig hch@lst.de Reviewed-by: Hannes Reinecke hare@suse.de Reviewed-by: Luis Chamberlain mcgrof@kernel.org Reviewed-by: Ulf Hansson ulf.hansson@linaro.org Link: https://lore.kernel.org/r/20210521055116.1053587-2-hch@lst.de Signed-off-by: Jens Axboe axboe@kernel.dk Signed-off-by: Yu Kuai yukuai3@huawei.com --- block/blk.h | 4 +- block/genhd.c | 89 +++++++++++++---------------------------- block/partitions/core.c | 16 ++++++-- 3 files changed, 42 insertions(+), 67 deletions(-)
diff --git a/block/blk.h b/block/blk.h index 80bb41a43120..88b00aa6e1c6 100644 --- a/block/blk.h +++ b/block/blk.h @@ -354,8 +354,8 @@ static inline void blk_queue_free_zone_bitmaps(struct request_queue *q) {}
struct hd_struct *disk_map_sector_rcu(struct gendisk *disk, sector_t sector);
-int blk_alloc_devt(struct hd_struct *part, dev_t *devt); -void blk_free_devt(dev_t devt); +int blk_alloc_ext_minor(struct hd_struct *part); +void blk_free_ext_minor(unsigned int minor); void blk_invalidate_devt(dev_t devt); char *disk_name(struct gendisk *hd, int partno, char *buf); #define ADDPART_FLAG_NONE 0 diff --git a/block/genhd.c b/block/genhd.c index ec1e2fe27249..019641280df3 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -557,31 +557,10 @@ static int blk_mangle_minor(int minor) return minor; }
-/** - * blk_alloc_devt - allocate a dev_t for a partition - * @part: partition to allocate dev_t for - * @devt: out parameter for resulting dev_t - * - * Allocate a dev_t for block device. - * - * RETURNS: - * 0 on success, allocated dev_t is returned in *@devt. -errno on - * failure. - * - * CONTEXT: - * Might sleep. - */ -int blk_alloc_devt(struct hd_struct *part, dev_t *devt) +int blk_alloc_ext_minor(struct hd_struct *part) { - struct gendisk *disk = part_to_disk(part); int idx;
- /* in consecutive minor range? */ - if (part->partno < disk->minors) { - *devt = MKDEV(disk->major, disk->first_minor + part->partno); - return 0; - } - /* allocate ext devt */ idr_preload(GFP_KERNEL);
@@ -590,32 +569,20 @@ int blk_alloc_devt(struct hd_struct *part, dev_t *devt) spin_unlock_bh(&ext_devt_lock);
idr_preload_end(); - if (idx < 0) - return idx == -ENOSPC ? -EBUSY : idx; + if (idx < 0) { + if (idx == -ENOSPC) + return -EBUSY; + return idx; + }
- *devt = MKDEV(BLOCK_EXT_MAJOR, blk_mangle_minor(idx)); - return 0; + return blk_mangle_minor(idx); }
-/** - * blk_free_devt - free a dev_t - * @devt: dev_t to free - * - * Free @devt which was allocated using blk_alloc_devt(). - * - * CONTEXT: - * Might sleep. - */ -void blk_free_devt(dev_t devt) +void blk_free_ext_minor(unsigned int minor) { - if (devt == MKDEV(0, 0)) - return; - - if (MAJOR(devt) == BLOCK_EXT_MAJOR) { - spin_lock_bh(&ext_devt_lock); - idr_remove(&ext_devt_idr, blk_mangle_minor(MINOR(devt))); - spin_unlock_bh(&ext_devt_lock); - } + spin_lock_bh(&ext_devt_lock); + idr_remove(&ext_devt_idr, blk_mangle_minor(minor)); + spin_unlock_bh(&ext_devt_lock); }
/* @@ -719,7 +686,6 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, struct device *ddev = disk_to_dev(disk); struct disk_part_iter piter; struct hd_struct *part; - dev_t devt; int ret;
/* @@ -731,26 +697,25 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, if (register_queue) elevator_init_mq(disk->queue);
- /* minors == 0 indicates to use ext devt from part0 and should - * be accompanied with EXT_DEVT flag. Make sure all - * parameters make sense. - */ - WARN_ON(disk->minors && !(disk->major || disk->first_minor)); - WARN_ON(!disk->minors && - !(disk->flags & (GENHD_FL_EXT_DEVT | GENHD_FL_HIDDEN))); + if (disk->major) { + WARN_ON(!disk->minors); + } else { + WARN_ON(disk->minors); + WARN_ON(!(disk->flags & (GENHD_FL_EXT_DEVT | GENHD_FL_HIDDEN)));
- ret = blk_alloc_devt(&disk->part0, &devt); - if (ret) { - WARN_ON(1); - return; + ret = blk_alloc_ext_minor(&disk->part0); + if (ret < 0) { + WARN_ON(1); + return; + } + disk->major = BLOCK_EXT_MAJOR; + disk->first_minor = MINOR(ret); } - disk->major = MAJOR(devt); - disk->first_minor = MINOR(devt);
disk_alloc_events(disk);
if (!(disk->flags & GENHD_FL_HIDDEN)) - ddev->devt = devt; + ddev->devt = MKDEV(disk->major, disk->first_minor);
/* delay uevents, until we scanned partition table */ dev_set_uevent_suppress(ddev, 1); @@ -792,7 +757,8 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, } else { struct backing_dev_info *bdi = disk->queue->backing_dev_info;
- ret = bdi_register(bdi, "%u:%u", MAJOR(devt), MINOR(devt)); + ret = bdi_register(bdi, "%u:%u", + disk->major, disk->first_minor); WARN_ON(ret); bdi_set_owner(bdi, ddev); blk_register_region(disk_devt(disk), disk->minors, NULL, @@ -1554,7 +1520,8 @@ static void disk_release(struct device *dev)
might_sleep();
- blk_free_devt(dev->devt); + if (MAJOR(dev->devt) == BLOCK_EXT_MAJOR) + blk_free_ext_minor(MINOR(dev->devt)); disk_release_events(disk); kfree(disk->random); disk_replace_part_tbl(disk, NULL); diff --git a/block/partitions/core.c b/block/partitions/core.c index 569b0ca9f6e1..68d75acc269a 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -258,7 +258,9 @@ static const struct attribute_group *part_attr_groups[] = { static void part_release(struct device *dev) { struct hd_struct *p = dev_to_part(dev); - blk_free_devt(dev->devt); + + if (MAJOR(dev->devt) == BLOCK_EXT_MAJOR) + blk_free_ext_minor(MINOR(dev->devt)); hd_free_part(p); kfree(p); } @@ -439,9 +441,15 @@ static struct hd_struct *add_partition(struct gendisk *disk, int partno, pdev->type = &part_type; pdev->parent = ddev;
- err = blk_alloc_devt(p, &devt); - if (err) - goto out_free_info; + /* in consecutive minor range? */ + if (partno < disk->minors) { + devt = MKDEV(disk->major, disk->first_minor + partno); + } else { + err = blk_alloc_ext_minor(p); + if (err < 0) + goto out_free_info; + devt = MKDEV(BLOCK_EXT_MAJOR, err); + } pdev->devt = devt;
/* delay uevent until 'holders' subdir is created */
From patchwork Wed Jan 26 08:35:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai yukuai3@huawei.com X-Patchwork-Id: 152665 Return-Path: yukuai3@huawei.com Received: from dggems705-chm.china.huawei.com (10.3.19.182) by dggems702-chm.china.huawei.com (10.3.19.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Mailbox Transport; Wed, 26 Jan 2022 16:24:58 +0800 Received: from kwepemm600009.china.huawei.com (7.193.23.164) by dggems705-chm.china.huawei.com (10.3.19.182) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:58 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:56 +0800 From: Yu Kuai yukuai3@huawei.com To: zhengzengkai@huawei.com, xiexiuqi@huawei.com, patchwork@huawei.com CC: yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, chenxiaosong2@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, luomeng12@huawei.com, yanaijie@huawei.com, yangerkun@huawei.com, yebin10@huawei.com, yuyufen@huawei.com, zhangxiaoxu5@huawei.com, zhengbin13@huawei.com, koulihong@huawei.com, qiulaibin@huawei.com, zhengliang6@huawei.com Subject: [PATCH OLK-5.10 10/12] block: automatically enable GENHD_FL_EXT_DEVT Date: Wed, 26 Jan 2022 16:35:32 +0800 Message-ID: 20220126083534.4016012-11-yukuai3@huawei.com X-Mailer: git-send-email 2.31.1 In-Reply-To: 20220126083534.4016012-1-yukuai3@huawei.com References: 20220126083534.4016012-1-yukuai3@huawei.com Content-Type: text/plain X-MS-Exchange-Organization-Network-Message-Id: 78c33535-647d-4416-5833-08d9e0a556da X-MS-Exchange-Organization-AuthSource: kwepemm600009.china.huawei.com X-MS-Exchange-Organization-AuthAs: Internal X-MS-Exchange-Organization-AuthMechanism: 07 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600009.china.huawei.com (7.193.23.164) X-MS-Exchange-Transport-EndToEndLatency: 00:00:01.8541754 X-MS-Exchange-Processed-By-BccFoldering: 15.01.2308.021 MIME-Version: 1.0
From: Christoph Hellwig hch@lst.de
mainline inclusion from mainline-v5.14-rc1 commit 0d1feb72ffd8578f6f167ca15b2096c276c1f6df category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I4SA9G
---------------------------
Automatically set the GENHD_FL_EXT_DEVT flag for all disks allocated without an explicit number of minors. This is what all new block drivers should do, so make sure it is the default without boilerplate code.
Signed-off-by: Christoph Hellwig hch@lst.de Reviewed-by: Hannes Reinecke hare@suse.de Reviewed-by: Luis Chamberlain mcgrof@kernel.org Reviewed-by: Ulf Hansson ulf.hansson@linaro.org Link: https://lore.kernel.org/r/20210521055116.1053587-4-hch@lst.de Signed-off-by: Jens Axboe axboe@kernel.dk Signed-off-by: Yu Kuai yukuai3@huawei.com --- block/genhd.c | 2 +- drivers/block/brd.c | 1 - drivers/block/loop.c | 1 - drivers/block/null_blk_main.c | 2 +- drivers/block/rbd.c | 2 -- drivers/block/virtio_blk.c | 1 - drivers/ide/ide-gd.c | 1 - drivers/lightnvm/core.c | 1 - drivers/md/md.c | 1 - drivers/memstick/core/ms_block.c | 1 - drivers/mmc/core/block.c | 1 - drivers/nvdimm/blk.c | 1 - drivers/nvdimm/btt.c | 1 - drivers/nvdimm/pmem.c | 1 - drivers/nvme/host/core.c | 2 +- drivers/nvme/host/multipath.c | 1 - drivers/scsi/sd.c | 1 - 17 files changed, 3 insertions(+), 18 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c index 019641280df3..c35bceed6870 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -701,7 +701,6 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, WARN_ON(!disk->minors); } else { WARN_ON(disk->minors); - WARN_ON(!(disk->flags & (GENHD_FL_EXT_DEVT | GENHD_FL_HIDDEN)));
ret = blk_alloc_ext_minor(&disk->part0); if (ret < 0) { @@ -710,6 +709,7 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, } disk->major = BLOCK_EXT_MAJOR; disk->first_minor = MINOR(ret); + disk->flags |= GENHD_FL_EXT_DEVT; }
disk_alloc_events(disk); diff --git a/drivers/block/brd.c b/drivers/block/brd.c index 085d1ff2bc03..395195edd5d7 100644 --- a/drivers/block/brd.c +++ b/drivers/block/brd.c @@ -411,7 +411,6 @@ static struct brd_device *brd_alloc(int i) disk->first_minor = i * max_part; disk->fops = &brd_fops; disk->private_data = brd; - disk->flags = GENHD_FL_EXT_DEVT; strlcpy(disk->disk_name, buf, DISK_NAME_LEN); set_capacity(disk, rd_size * 2);
diff --git a/drivers/block/loop.c b/drivers/block/loop.c index e354faf7c9e6..b761afd294a2 100644 --- a/drivers/block/loop.c +++ b/drivers/block/loop.c @@ -2154,7 +2154,6 @@ static int loop_add(struct loop_device **l, int i) */ if (!part_shift) disk->flags |= GENHD_FL_NO_PART_SCAN; - disk->flags |= GENHD_FL_EXT_DEVT; atomic_set(&lo->lo_refcnt, 0); lo->lo_number = i; spin_lock_init(&lo->lo_lock); diff --git a/drivers/block/null_blk_main.c b/drivers/block/null_blk_main.c index bb3686c3869d..4279db5bef59 100644 --- a/drivers/block/null_blk_main.c +++ b/drivers/block/null_blk_main.c @@ -1692,7 +1692,7 @@ static int null_gendisk_register(struct nullb *nullb) return -ENOMEM; set_capacity(disk, size);
- disk->flags |= GENHD_FL_EXT_DEVT | GENHD_FL_SUPPRESS_PARTITION_INFO; + disk->flags |= GENHD_FL_SUPPRESS_PARTITION_INFO; disk->major = null_major; disk->first_minor = nullb->index; if (queue_is_mq(nullb->q)) diff --git a/drivers/block/rbd.c b/drivers/block/rbd.c index 340b1df365f7..7249448b2a51 100644 --- a/drivers/block/rbd.c +++ b/drivers/block/rbd.c @@ -4973,8 +4973,6 @@ static int rbd_init_disk(struct rbd_device *rbd_dev) rbd_dev->dev_id); disk->major = rbd_dev->major; disk->first_minor = rbd_dev->minor; - if (single_major) - disk->flags |= GENHD_FL_EXT_DEVT; disk->fops = &rbd_bd_ops; disk->private_data = rbd_dev;
diff --git a/drivers/block/virtio_blk.c b/drivers/block/virtio_blk.c index 42acf9587ef3..eba1d6e06ca2 100644 --- a/drivers/block/virtio_blk.c +++ b/drivers/block/virtio_blk.c @@ -794,7 +794,6 @@ static int virtblk_probe(struct virtio_device *vdev) vblk->disk->first_minor = index_to_minor(index); vblk->disk->private_data = vblk; vblk->disk->fops = &virtblk_fops; - vblk->disk->flags |= GENHD_FL_EXT_DEVT; vblk->index = index;
/* configure queue flush support */ diff --git a/drivers/ide/ide-gd.c b/drivers/ide/ide-gd.c index e2b6c82586ce..1c19f6830704 100644 --- a/drivers/ide/ide-gd.c +++ b/drivers/ide/ide-gd.c @@ -395,7 +395,6 @@ static int ide_gd_probe(ide_drive_t *drive) set_capacity(g, ide_gd_capacity(drive));
g->minors = IDE_DISK_MINORS; - g->flags |= GENHD_FL_EXT_DEVT; if (drive->dev_flags & IDE_DFLAG_REMOVABLE) g->flags = GENHD_FL_REMOVABLE; g->fops = &ide_gd_ops; diff --git a/drivers/lightnvm/core.c b/drivers/lightnvm/core.c index 28ddcaa5358b..8903b7b57e61 100644 --- a/drivers/lightnvm/core.c +++ b/drivers/lightnvm/core.c @@ -383,7 +383,6 @@ static int nvm_create_tgt(struct nvm_dev *dev, struct nvm_ioctl_create *create) }
strlcpy(tdisk->disk_name, create->tgtname, sizeof(tdisk->disk_name)); - tdisk->flags = GENHD_FL_EXT_DEVT; tdisk->major = 0; tdisk->first_minor = 0; tdisk->fops = tt->bops; diff --git a/drivers/md/md.c b/drivers/md/md.c index a299fda5b0e9..1cc26fab10b1 100644 --- a/drivers/md/md.c +++ b/drivers/md/md.c @@ -5721,7 +5721,6 @@ static int md_alloc(dev_t dev, char *name) * 'mdp' device redundant, but we can't really * remove it now. */ - disk->flags |= GENHD_FL_EXT_DEVT; disk->events |= DISK_EVENT_MEDIA_CHANGE; mddev->gendisk = disk; add_disk(disk); diff --git a/drivers/memstick/core/ms_block.c b/drivers/memstick/core/ms_block.c index bc1f484f50f1..0ca990f7ca3e 100644 --- a/drivers/memstick/core/ms_block.c +++ b/drivers/memstick/core/ms_block.c @@ -2136,7 +2136,6 @@ static int msb_init_disk(struct memstick_dev *card) msb->disk->fops = &msb_bdops; msb->disk->private_data = msb; msb->disk->queue = msb->queue; - msb->disk->flags |= GENHD_FL_EXT_DEVT;
capacity = msb->pages_in_block * msb->logical_block_count; capacity *= (msb->page_size / 512); diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 94caee49da99..78a491ddcbf6 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -2347,7 +2347,6 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, md->disk->queue = md->queue.queue; md->parent = parent; set_disk_ro(md->disk, md->read_only || default_ro); - md->disk->flags = GENHD_FL_EXT_DEVT; if (area_type & (MMC_BLK_DATA_AREA_RPMB | MMC_BLK_DATA_AREA_BOOT)) md->disk->flags |= GENHD_FL_NO_PART_SCAN | GENHD_FL_SUPPRESS_PARTITION_INFO; diff --git a/drivers/nvdimm/blk.c b/drivers/nvdimm/blk.c index 22e5617b2cea..f1295f6896c9 100644 --- a/drivers/nvdimm/blk.c +++ b/drivers/nvdimm/blk.c @@ -267,7 +267,6 @@ static int nsblk_attach_disk(struct nd_namespace_blk *nsblk) disk->first_minor = 0; disk->fops = &nd_blk_fops; disk->queue = q; - disk->flags = GENHD_FL_EXT_DEVT; disk->private_data = nsblk; nvdimm_namespace_disk_name(&nsblk->common, disk->disk_name);
diff --git a/drivers/nvdimm/btt.c b/drivers/nvdimm/btt.c index 12ff6f8784ac..42d79a9a404f 100644 --- a/drivers/nvdimm/btt.c +++ b/drivers/nvdimm/btt.c @@ -1536,7 +1536,6 @@ static int btt_blk_init(struct btt *btt) btt->btt_disk->fops = &btt_fops; btt->btt_disk->private_data = btt; btt->btt_disk->queue = btt->btt_queue; - btt->btt_disk->flags = GENHD_FL_EXT_DEVT;
blk_queue_logical_block_size(btt->btt_queue, btt->sector_size); blk_queue_max_hw_sectors(btt->btt_queue, UINT_MAX); diff --git a/drivers/nvdimm/pmem.c b/drivers/nvdimm/pmem.c index d5dd79b59b16..ca2a1967c070 100644 --- a/drivers/nvdimm/pmem.c +++ b/drivers/nvdimm/pmem.c @@ -476,7 +476,6 @@ static int pmem_attach_disk(struct device *dev,
disk->fops = &pmem_fops; disk->queue = q; - disk->flags = GENHD_FL_EXT_DEVT; disk->private_data = pmem; nvdimm_namespace_disk_name(ndns, disk->disk_name); set_capacity(disk, (pmem->size - pmem->pfn_pad - pmem->data_offset) diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 9ccf44592fe4..24d59b73ac3e 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -3825,7 +3825,7 @@ static void nvme_alloc_ns(struct nvme_ctrl *ctrl, unsigned nsid, struct gendisk *disk; struct nvme_id_ns *id; char disk_name[DISK_NAME_LEN]; - int node = ctrl->numa_node, flags = GENHD_FL_EXT_DEVT, ret; + int node = ctrl->numa_node, flags = 0, ret;
if (nvme_identify_ns(ctrl, nsid, ids, &id)) return; diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c index 18a756444d5a..95a5222b3642 100644 --- a/drivers/nvme/host/multipath.c +++ b/drivers/nvme/host/multipath.c @@ -392,7 +392,6 @@ int nvme_mpath_alloc_disk(struct nvme_ctrl *ctrl, struct nvme_ns_head *head) head->disk->fops = &nvme_ns_head_ops; head->disk->private_data = head; head->disk->queue = q; - head->disk->flags = GENHD_FL_EXT_DEVT; sprintf(head->disk->disk_name, "nvme%dn%d", ctrl->subsys->instance, head->instance); return 0; diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index 3fc184e9702f..db7166fd05e1 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -3479,7 +3479,6 @@ static int sd_probe(struct device *dev)
sd_revalidate_disk(gd);
- gd->flags = GENHD_FL_EXT_DEVT; if (sdp->removable) { gd->flags |= GENHD_FL_REMOVABLE; gd->events |= DISK_EVENT_MEDIA_CHANGE;
From patchwork Wed Jan 26 08:35:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai yukuai3@huawei.com X-Patchwork-Id: 152666 Return-Path: yukuai3@huawei.com Received: from dggems701-chm.china.huawei.com (10.3.19.178) by dggems702-chm.china.huawei.com (10.3.19.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Mailbox Transport; Wed, 26 Jan 2022 16:25:00 +0800 Received: from kwepemm600009.china.huawei.com (7.193.23.164) by dggems701-chm.china.huawei.com (10.3.19.178) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:59 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:58 +0800 From: Yu Kuai yukuai3@huawei.com To: zhengzengkai@huawei.com, xiexiuqi@huawei.com, patchwork@huawei.com CC: yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, chenxiaosong2@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, luomeng12@huawei.com, yanaijie@huawei.com, yangerkun@huawei.com, yebin10@huawei.com, yuyufen@huawei.com, zhangxiaoxu5@huawei.com, zhengbin13@huawei.com, koulihong@huawei.com, qiulaibin@huawei.com, zhengliang6@huawei.com Subject: [PATCH OLK-5.10 11/12] block: add error handling for device_add_disk / add_disk Date: Wed, 26 Jan 2022 16:35:33 +0800 Message-ID: 20220126083534.4016012-12-yukuai3@huawei.com X-Mailer: git-send-email 2.31.1 In-Reply-To: 20220126083534.4016012-1-yukuai3@huawei.com References: 20220126083534.4016012-1-yukuai3@huawei.com Content-Type: text/plain X-MS-Exchange-Organization-Network-Message-Id: af00f8da-255b-48f7-afb7-08d9e0a557a7 X-MS-Exchange-Organization-AuthSource: kwepemm600009.china.huawei.com X-MS-Exchange-Organization-AuthAs: Internal X-MS-Exchange-Organization-AuthMechanism: 07 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600009.china.huawei.com (7.193.23.164) X-MS-Exchange-Transport-EndToEndLatency: 00:00:01.7770389 X-MS-Exchange-Processed-By-BccFoldering: 15.01.2308.021 MIME-Version: 1.0
hulk inclusion category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I4SA9G
---------------------------
Properly unwind on errors in device_add_disk. This is the initial work as drivers are not converted yet, which will follow in separate patches.
Signed-off-by: Yu Kuai yukuai3@huawei.com --- block/genhd.c | 91 +++++++++++++++++++++++++++++++++++---------------- 1 file changed, 63 insertions(+), 28 deletions(-)
diff --git a/block/genhd.c b/block/genhd.c index c35bceed6870..371fdd2e0786 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -676,10 +676,8 @@ static void disk_scan_partitions(struct gendisk *disk) * * This function registers the partitioning information in @disk * with the kernel. - * - * FIXME: error handling */ -static void __device_add_disk(struct device *parent, struct gendisk *disk, +static int __device_add_disk(struct device *parent, struct gendisk *disk, const struct attribute_group **groups, bool register_queue) { @@ -698,22 +696,20 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, elevator_init_mq(disk->queue);
if (disk->major) { - WARN_ON(!disk->minors); + if (WARN_ON(!disk->minors)) + return -EINVAL; } else { - WARN_ON(disk->minors); + if (WARN_ON(disk->minors)) + return -EINVAL;
ret = blk_alloc_ext_minor(&disk->part0); - if (ret < 0) { - WARN_ON(1); - return; - } + if (ret < 0) + return ret; disk->major = BLOCK_EXT_MAJOR; disk->first_minor = MINOR(ret); disk->flags |= GENHD_FL_EXT_DEVT; }
- disk_alloc_events(disk); - if (!(disk->flags & GENHD_FL_HIDDEN)) ddev->devt = MKDEV(disk->major, disk->first_minor);
@@ -724,15 +720,19 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, ddev->groups = groups; dev_set_name(ddev, "%s", disk->disk_name);
- if (device_add(ddev)) - return; + ret = device_add(ddev); + if (ret) + goto out_free_ext_minor; + + ret = disk_alloc_events(disk); + if (ret) + goto out_device_del; + if (!sysfs_deprecated) { ret = sysfs_create_link(block_depr, &ddev->kobj, kobject_name(&ddev->kobj)); - if (ret) { - device_del(ddev); - return; - } + if (ret) + goto out_device_del; }
/* @@ -742,10 +742,20 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, */ pm_runtime_set_memalloc_noio(ddev, true);
- blk_integrity_add(disk); + ret = blk_integrity_add(disk); + if (ret) + goto out_del_block_link;
disk->part0.holder_dir = kobject_create_and_add("holders", &ddev->kobj); + if (!disk->part0.holder_dir) { + ret = -ENOMEM; + goto out_del_integrity; + } disk->slave_dir = kobject_create_and_add("slaves", &ddev->kobj); + if (!disk->slave_dir) { + ret = -ENOMEM; + goto out_put_holder_dir; + }
if (disk->flags & GENHD_FL_HIDDEN) { /* @@ -759,17 +769,17 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk,
ret = bdi_register(bdi, "%u:%u", disk->major, disk->first_minor); - WARN_ON(ret); + if (ret) + goto out_put_slave_dir; bdi_set_owner(bdi, ddev); blk_register_region(disk_devt(disk), disk->minors, NULL, exact_match, exact_lock, disk);
- if (disk->queue->backing_dev_info->dev) { - ret = sysfs_create_link(&ddev->kobj, - &disk->queue->backing_dev_info->dev->kobj, - "bdi"); - WARN_ON(ret); - } + ret = sysfs_create_link(&ddev->kobj, + &disk->queue->backing_dev_info->dev->kobj, + "bdi"); + if (ret) + goto out_unregister_bdi;
disk_scan_partitions(disk);
@@ -784,8 +794,11 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, disk_part_iter_exit(&piter); }
- if (register_queue) - blk_register_queue(disk); + if (register_queue) { + ret = blk_register_queue(disk); + if (ret) + goto out_del_bdi_link; + }
/* * Take an extra ref on queue which will be put on disk_release() @@ -794,8 +807,30 @@ static void __device_add_disk(struct device *parent, struct gendisk *disk, WARN_ON_ONCE(!blk_get_queue(disk->queue));
disk_add_events(disk); - disk->flags |= GENHD_FL_UP; + return 0; + +out_del_bdi_link: + if (!(disk->flags & GENHD_FL_HIDDEN)) + sysfs_remove_link(&ddev->kobj, "bdi"); +out_unregister_bdi: + if (!(disk->flags & GENHD_FL_HIDDEN)) + bdi_unregister(disk->queue->backing_dev_info); +out_put_slave_dir: + kobject_put(disk->slave_dir); +out_put_holder_dir: + kobject_put(disk->part0.holder_dir); +out_del_integrity: + blk_integrity_del(disk); +out_del_block_link: + if (!sysfs_deprecated) + sysfs_remove_link(block_depr, dev_name(ddev)); +out_device_del: + device_del(ddev); +out_free_ext_minor: + if (disk->major == BLOCK_EXT_MAJOR) + blk_free_ext_minor(disk->first_minor); + return WARN_ON_ONCE(ret); /* keep until all callers handle errors */ }
void device_add_disk(struct device *parent, struct gendisk *disk,
From patchwork Wed Jan 26 08:35:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Kuai yukuai3@huawei.com X-Patchwork-Id: 152667 Return-Path: yukuai3@huawei.com Received: from dggems702-chm.china.huawei.com (10.3.19.179) by dggems702-chm.china.huawei.com (10.3.19.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21 via Mailbox Transport; Wed, 26 Jan 2022 16:25:01 +0800 Received: from kwepemm600009.china.huawei.com (7.193.23.164) by dggems702-chm.china.huawei.com (10.3.19.179) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:25:01 +0800 Received: from huawei.com (10.175.127.227) by kwepemm600009.china.huawei.com (7.193.23.164) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.21; Wed, 26 Jan 2022 16:24:59 +0800 From: Yu Kuai yukuai3@huawei.com To: zhengzengkai@huawei.com, xiexiuqi@huawei.com, patchwork@huawei.com CC: yukuai3@huawei.com, yi.zhang@huawei.com, houtao1@huawei.com, chenxiaosong2@huawei.com, chengzhihao1@huawei.com, libaokun1@huawei.com, luomeng12@huawei.com, yanaijie@huawei.com, yangerkun@huawei.com, yebin10@huawei.com, yuyufen@huawei.com, zhangxiaoxu5@huawei.com, zhengbin13@huawei.com, koulihong@huawei.com, qiulaibin@huawei.com, zhengliang6@huawei.com Subject: [PATCH OLK-5.10 12/12] sd: don't mess with SD_MINORS for CONFIG_DEBUG_BLOCK_EXT_DEVT Date: Wed, 26 Jan 2022 16:35:34 +0800 Message-ID: 20220126083534.4016012-13-yukuai3@huawei.com X-Mailer: git-send-email 2.31.1 In-Reply-To: 20220126083534.4016012-1-yukuai3@huawei.com References: 20220126083534.4016012-1-yukuai3@huawei.com Content-Type: text/plain X-MS-Exchange-Organization-Network-Message-Id: a409ac94-39e4-47fd-25f8-08d9e0a55871 X-MS-Exchange-Organization-AuthSource: kwepemm600009.china.huawei.com X-MS-Exchange-Organization-AuthAs: Internal X-MS-Exchange-Organization-AuthMechanism: 07 X-Originating-IP: [10.175.127.227] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600009.china.huawei.com (7.193.23.164) X-MS-Exchange-Transport-EndToEndLatency: 00:00:01.7893204 X-MS-Exchange-Processed-By-BccFoldering: 15.01.2308.021 MIME-Version: 1.0
From: Christoph Hellwig hch@lst.de
mainline inclusion from mainline-v5.14-rc2 commit 7fef2edf7cc753b51f7ccc74993971b0a9c81eca category: bugfix bugzilla: https://gitee.com/openeuler/kernel/issues/I4SA9G
---------------------------
No need to give up the original sd minor even with this option, and if we did we'd also need to fix the number of minors for this configuration to actually work.
Fixes: 7c3f828b522b0 ("block: refactor device number setup in __device_add_disk") Reported-by: Guenter Roeck linux@roeck-us.net Signed-off-by: Christoph Hellwig hch@lst.de Tested-by: Guenter Roeck linux@roeck-us.net Signed-off-by: Linus Torvalds torvalds@linux-foundation.org Signed-off-by: Yu Kuai yukuai3@huawei.com --- drivers/scsi/sd.c | 4 ---- 1 file changed, 4 deletions(-)
diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c index db7166fd05e1..2dfa5a34b048 100644 --- a/drivers/scsi/sd.c +++ b/drivers/scsi/sd.c @@ -98,11 +98,7 @@ MODULE_ALIAS_SCSI_DEVICE(TYPE_MOD); MODULE_ALIAS_SCSI_DEVICE(TYPE_RBC); MODULE_ALIAS_SCSI_DEVICE(TYPE_ZBC);
-#if !defined(CONFIG_DEBUG_BLOCK_EXT_DEVT) #define SD_MINORS 16 -#else -#define SD_MINORS 0 -#endif
static void sd_config_discard(struct scsi_disk *, unsigned int); static void sd_config_write_same(struct scsi_disk *);