提交 d7c2ddc8 编写于 作者: Y Yu Kuai 提交者: Zheng Zengkai

block: fix that part scan is disabled in device_add_disk()

hulk inclusion
category: bugfix
bugzilla: https://gitee.com/openeuler/kernel/issues/I5ETAB
CVE: NA

--------------------------------

Patch ("block: Fix warning in bd_link_disk_holder()") moves the
setting of flag 'GENHD_FL_UP' behind blkdev_get, which will
disabled part scan:

devcie_add_disk
 register_disk
  blkdev_get
   __blkdev_get
    bdev_get_gendisk
     get_gendisk -> failed because 'GENHD_FL_UP' is not set

And this will cause tests block/017, block/018 and scsi/004 to fail.

Fix the problem by moving part scan as well.
Signed-off-by: NYu Kuai <yukuai3@huawei.com>
Reviewed-by: NJason Yan <yanaijie@huawei.com>
Signed-off-by: NZheng Zengkai <zhengzengkai@huawei.com>
上级 a51eb65b
...@@ -821,6 +821,38 @@ struct kobj_type blk_queue_ktype = { ...@@ -821,6 +821,38 @@ struct kobj_type blk_queue_ktype = {
.release = blk_release_queue, .release = blk_release_queue,
}; };
static void disk_scan_partitions(struct gendisk *disk)
{
struct block_device *bdev;
if (!get_capacity(disk) || !disk_part_scan_enabled(disk))
return;
set_bit(GD_NEED_PART_SCAN, &disk->state);
bdev = blkdev_get_by_dev(disk_devt(disk), FMODE_READ, NULL);
if (!IS_ERR(bdev))
blkdev_put(bdev, FMODE_READ);
}
static void disk_init_partition(struct gendisk *disk)
{
struct device *ddev = disk_to_dev(disk);
struct disk_part_iter piter;
struct hd_struct *part;
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);
}
/** /**
* blk_register_queue - register a block layer queue with sysfs * blk_register_queue - register a block layer queue with sysfs
* @disk: Disk of which the request queue should be registered with sysfs. * @disk: Disk of which the request queue should be registered with sysfs.
...@@ -916,6 +948,7 @@ int blk_register_queue(struct gendisk *disk) ...@@ -916,6 +948,7 @@ int blk_register_queue(struct gendisk *disk)
* before it's registration is done. * before it's registration is done.
*/ */
disk->flags |= GENHD_FL_UP; disk->flags |= GENHD_FL_UP;
disk_init_partition(disk);
ret = 0; ret = 0;
unlock: unlock:
mutex_unlock(&q->sysfs_dir_lock); mutex_unlock(&q->sysfs_dir_lock);
......
...@@ -687,25 +687,10 @@ static int exact_lock(dev_t devt, void *data) ...@@ -687,25 +687,10 @@ static int exact_lock(dev_t devt, void *data)
return 0; return 0;
} }
static void disk_scan_partitions(struct gendisk *disk)
{
struct block_device *bdev;
if (!get_capacity(disk) || !disk_part_scan_enabled(disk))
return;
set_bit(GD_NEED_PART_SCAN, &disk->state);
bdev = blkdev_get_by_dev(disk_devt(disk), FMODE_READ, NULL);
if (!IS_ERR(bdev))
blkdev_put(bdev, FMODE_READ);
}
static void register_disk(struct device *parent, struct gendisk *disk, static void register_disk(struct device *parent, struct gendisk *disk,
const struct attribute_group **groups) const struct attribute_group **groups)
{ {
struct device *ddev = disk_to_dev(disk); struct device *ddev = disk_to_dev(disk);
struct disk_part_iter piter;
struct hd_struct *part;
int err; int err;
ddev->parent = parent; ddev->parent = parent;
...@@ -743,18 +728,6 @@ static void register_disk(struct device *parent, struct gendisk *disk, ...@@ -743,18 +728,6 @@ static void register_disk(struct device *parent, struct gendisk *disk,
if (disk->flags & GENHD_FL_HIDDEN) if (disk->flags & GENHD_FL_HIDDEN)
return; 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) { if (disk->queue->backing_dev_info->dev) {
err = sysfs_create_link(&ddev->kobj, err = sysfs_create_link(&ddev->kobj,
&disk->queue->backing_dev_info->dev->kobj, &disk->queue->backing_dev_info->dev->kobj,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册