From: John Garry If a disk is hidden (GENHD_FL_HIDDEN flags set), we currently do not scan the disk partition table. GENHD_FL_HIDDEN is used in NVMe multipath support to hide the per-path disk. However, it would be useful there to actually have the per-path disk partition table available for situations where we want to send bios to a specific per-path disk partition. Change GENHD_FL_HIDDEN to scan partitions. For anyone wanting to avoid scanning the partition, flag GENHD_FL_NO_PART can still be used. In diskstats_show(), don't show per-path partitions as this info is not too interesting and can just bloat the output. Signed-off-by: John Garry --- block/genhd.c | 20 ++++++++++---------- block/partitions/core.c | 5 +++-- drivers/nvme/host/core.c | 4 ---- include/linux/blkdev.h | 2 +- 4 files changed, 14 insertions(+), 17 deletions(-) diff --git a/block/genhd.c b/block/genhd.c index 30ac0ffe65174..05301ee5d4ca5 100644 --- a/block/genhd.c +++ b/block/genhd.c @@ -406,15 +406,15 @@ static void add_disk_final(struct gendisk *disk) { struct device *ddev = disk_to_dev(disk); - if (!(disk->flags & GENHD_FL_HIDDEN)) { - /* Make sure the first partition scan will be proceed */ - if (get_capacity(disk) && disk_has_partscan(disk)) - set_bit(GD_NEED_PART_SCAN, &disk->state); + /* Make sure the first partition scan will be proceed */ + if (get_capacity(disk) && disk_has_partscan(disk)) + set_bit(GD_NEED_PART_SCAN, &disk->state); - bdev_add(disk->part0, ddev->devt); - if (get_capacity(disk)) - disk_scan_partitions(disk, BLK_OPEN_READ); + bdev_add(disk->part0, ddev->devt); + if (get_capacity(disk)) + disk_scan_partitions(disk, BLK_OPEN_READ); + if (!(disk->flags & GENHD_FL_HIDDEN)) { /* * Announce the disk and partitions after all partitions are * created. (for hidden disks uevents remain suppressed forever) @@ -491,8 +491,7 @@ static int __add_disk(struct device *parent, struct gendisk *disk, dev_set_name(ddev, "%s", disk->disk_name); if (fwnode) device_set_node(ddev, fwnode); - if (!(disk->flags & GENHD_FL_HIDDEN)) - ddev->devt = MKDEV(disk->major, disk->first_minor); + ddev->devt = MKDEV(disk->major, disk->first_minor); ret = device_add(ddev); if (ret) goto out_free_ext_minor; @@ -1368,7 +1367,8 @@ static int diskstats_show(struct seq_file *seqf, void *v) rcu_read_lock(); xa_for_each(&gp->part_tbl, idx, hd) { - if (bdev_is_partition(hd) && !bdev_nr_sectors(hd)) + if (bdev_is_partition(hd) && + (!bdev_nr_sectors(hd) ||(gp->flags & GENHD_FL_HIDDEN))) continue; inflight = bdev_count_inflight(hd); diff --git a/block/partitions/core.c b/block/partitions/core.c index b5c59b79ca7cb..a48896c6c791d 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -152,7 +152,8 @@ static struct parsed_partitions *check_partition(struct gendisk *hd) } if (res > 0) { - printk(KERN_INFO "%s", seq_buf_str(&state->pp_buf)); + if (!(hd->flags & GENHD_FL_HIDDEN)) + printk(KERN_INFO "%s", seq_buf_str(&state->pp_buf)); kfree(state->pp_buf.buffer); return state; @@ -164,7 +165,7 @@ static struct parsed_partitions *check_partition(struct gendisk *hd) */ if (err) res = err; - if (res) { + if (res && !(hd->flags & GENHD_FL_HIDDEN)) { seq_buf_puts(&state->pp_buf, " unable to read partition table\n"); printk(KERN_INFO "%s", seq_buf_str(&state->pp_buf)); diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c index 1322c678f4eb8..ed21f4ef36c9a 100644 --- a/drivers/nvme/host/core.c +++ b/drivers/nvme/host/core.c @@ -1808,10 +1808,6 @@ static void nvme_enable_aen(struct nvme_ctrl *ctrl) static int nvme_ns_open(struct nvme_ns *ns) { - - /* should never be called due to GENHD_FL_HIDDEN */ - if (WARN_ON_ONCE(nvme_ns_head_multipath(ns->head))) - goto fail; if (!nvme_get_ns(ns)) goto fail; if (!try_module_get(ns->ctrl->ops->module)) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 9213a5716f95a..a270cf1394c7a 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -260,7 +260,7 @@ static inline unsigned int disk_openers(struct gendisk *disk) */ static inline bool disk_has_partscan(struct gendisk *disk) { - return !(disk->flags & (GENHD_FL_NO_PART | GENHD_FL_HIDDEN)) && + return !(disk->flags & GENHD_FL_NO_PART) && !test_bit(GD_SUPPRESS_PART_SCAN, &disk->state); } -- 2.43.7