From: John Garry <john.garry@linux.dev>
To: axboe@kernel.dk, kbusch@kernel.org, sagi@grimberg.me, hch@lst.de
Cc: linux-block@vger.kernel.org, linux-nvme@lists.infradead.org,
John Garry <john.garry@linux.dev>
Subject: [PATCH v4 3/4] nvme-multipath: clone head disk partitions to per-path disks
Date: Mon, 21 Sep 2026 09:37:51 +0100 [thread overview]
Message-ID: <20260921083752.1154316-4-john.garry@linux.dev> (raw)
In-Reply-To: <20260921083752.1154316-1-john.garry@linux.dev>
To fix diskstats per partition, it is required that the per-path disk
actually has an up-to-date partition table. This partition table would be
a clone of the head disk partition table.
At two points the partition table needs to be updated:
- when the per-path disk is added in nvme_mpath_add_disk()
- for partition table updates to the head disk, add
nvme_ns_head_disk_changed() to clone the partition table to per-path
disks
Signed-off-by: John Garry <john.garry@linux.dev>
---
drivers/nvme/host/multipath.c | 32 ++++++++++++++++++++++++++++++++
1 file changed, 32 insertions(+)
diff --git a/drivers/nvme/host/multipath.c b/drivers/nvme/host/multipath.c
index 75dbb58286a3..e871ad40d893 100644
--- a/drivers/nvme/host/multipath.c
+++ b/drivers/nvme/host/multipath.c
@@ -623,6 +623,23 @@ static int nvme_ns_head_report_zones(struct gendisk *disk, sector_t sector,
#define nvme_ns_head_report_zones NULL
#endif /* CONFIG_BLK_DEV_ZONED */
+static void nvme_ns_head_disk_changed(struct gendisk *disk)
+{
+ struct nvme_ns_head *head = disk->private_data;
+ struct nvme_ns *ns;
+ int srcu_idx;
+
+ lockdep_assert_held(&disk->open_mutex);
+
+ srcu_idx = srcu_read_lock(&head->srcu);
+ list_for_each_entry_srcu(ns, &head->list, siblings,
+ srcu_read_lock_held(&head->srcu)) {
+ if (bdev_clone_partitions(head->disk, ns->disk))
+ clear_bit(NVME_NS_READY, &ns->flags);
+ }
+ srcu_read_unlock(&head->srcu, srcu_idx);
+}
+
const struct block_device_operations nvme_ns_head_ops = {
.owner = THIS_MODULE,
.submit_bio = nvme_ns_head_submit_bio,
@@ -634,6 +651,7 @@ const struct block_device_operations nvme_ns_head_ops = {
.get_unique_id = nvme_ns_head_get_unique_id,
.report_zones = nvme_ns_head_report_zones,
.pr_ops = &nvme_pr_ops,
+ .disk_changed_notify = nvme_ns_head_disk_changed,
};
static const struct file_operations nvme_ns_head_chr_fops = {
@@ -1360,6 +1378,20 @@ void nvme_mpath_remove_sysfs_link(struct nvme_ns *ns)
void nvme_mpath_add_disk(struct nvme_ns *ns, __le32 anagrpid)
{
+ struct nvme_ns_head *head = ns->head;
+ int ret;
+
+ if (!head->disk)
+ return;
+
+ mutex_lock(&head->disk->open_mutex);
+ ret = bdev_clone_partitions(head->disk, ns->disk);
+ mutex_unlock(&head->disk->open_mutex);
+ if (ret) {
+ clear_bit(NVME_NS_READY, &ns->flags);
+ return;
+ }
+
if (nvme_ctrl_use_ana(ns->ctrl)) {
struct nvme_ana_group_desc desc = {
.grpid = anagrpid,
--
2.43.0
next prev parent reply other threads:[~2026-09-21 8:38 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-21 8:37 [PATCH v4 0/4] fix NVMe multipath partition diskstats John Garry
2026-09-21 8:37 ` [PATCH v4 1/4] block: support cloning partitions John Garry
2026-09-21 8:37 ` [PATCH v4 2/4] block: don't show partition diskstats for GENHD_FL_HIDDEN John Garry
2026-09-21 8:37 ` John Garry [this message]
2026-09-21 8:37 ` [PATCH v4 4/4] nvme-multipath: fix diskstats for partitions John Garry
2026-09-28 7:30 ` [PATCH v4 0/4] fix NVMe multipath partition diskstats John Garry
2026-09-28 9:14 ` Christoph Hellwig
2026-09-28 10:16 ` John Garry
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=20260921083752.1154316-4-john.garry@linux.dev \
--to=john.garry@linux.dev \
--cc=axboe@kernel.dk \
--cc=hch@lst.de \
--cc=kbusch@kernel.org \
--cc=linux-block@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=sagi@grimberg.me \
/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: link
Be 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.