[PATCH 03/11] nvme: export nvme_bdev_ops

sashiko-bot at kernel.org sashiko-bot at kernel.org
Fri Oct 23 01:14:32 PDT 2026


Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] nvme: exporting only nvme_bdev_ops misses multipathed NVMe namespaces
--

commit 764e628e097c80c3a597aca0fdc4893155c2715b
Author: Guixin Liu <kanie at linux.alibaba.com>

nvme: export nvme_bdev_ops

This commit exports nvme_bdev_ops so that external subsystems such as the
NVMe target FDP bridge can identify an NVMe namespace block device by its
block_device_operations pointer and access its underlying NVMe structures.

> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
> index 7eb0f9fe6b18d..0099ce5730b20 100644
> --- a/drivers/nvme/host/core.c
> +++ b/drivers/nvme/host/core.c
> @@ -2719,6 +2719,7 @@ const struct block_device_operations nvme_bdev_ops = {
>  	.report_zones	= nvme_report_zones,
>  	.pr_ops		= &nvme_pr_ops,
>  };
> +EXPORT_SYMBOL_GPL(nvme_bdev_ops);

[Severity: Medium]
Does exporting only nvme_bdev_ops work when NVMe multipathing is active for
the backing namespace?

When multipathing is enabled for a namespace, nvme_mpath_alloc_disk() in
drivers/nvme/host/multipath.c sets up the user-visible /dev/nvmeXnY gendisk
with nvme_ns_head_ops and stores struct nvme_ns_head * in private_data:

	head->disk->fops = &nvme_ns_head_ops;
	head->disk->private_data = head;

Meanwhile, nvme_alloc_ns() in drivers/nvme/host/core.c marks the
per-controller disk (which uses nvme_bdev_ops and stores struct nvme_ns * in
disk->private_data) as hidden so it cannot be opened as a backing block
device:

	if (nvme_ns_head_multipath(ns->head)) {
		sprintf(disk->disk_name, "nvme%dc%dn%d", ctrl->subsys->instance,
			ctrl->instance, ns->head->instance);
		disk->flags |= GENHD_FL_HIDDEN;
	}

When the NVMe target FDP bridge in nvmet_fdp_init_ns() checks
bdev->bd_disk->fops != &nvme_bdev_ops on an opened /dev/nvmeXnY device,
won't it reject valid multipathed NVMe namespaces with -EINVAL because
bdev->bd_disk->fops is &nvme_ns_head_ops?

Instead of exporting nvme_bdev_ops and having callers inspect
bdev->bd_disk->fops and bdev->bd_disk->private_data directly, would it make
sense to provide a helper in drivers/nvme/host/core.c (similar to
nvme_ctrl_from_file()) that handles both nvme_bdev_ops and nvme_ns_head_ops?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261023080251.2606443-1-kanie@linux.alibaba.com?part=3



More information about the Linux-nvme mailing list