[PATCH 00/19] nvme: switch to libmultipath

John Garry posted 19 patches 1 month, 1 week ago
drivers/nvme/host/Kconfig     |   1 +
drivers/nvme/host/core.c      |  81 ++-
drivers/nvme/host/ioctl.c     |  96 ++--
drivers/nvme/host/multipath.c | 962 +++++++++++-----------------------
drivers/nvme/host/nvme.h      | 117 +++--
drivers/nvme/host/pr.c        | 205 ++++++--
drivers/nvme/host/sysfs.c     |  84 +--
7 files changed, 632 insertions(+), 914 deletions(-)
[PATCH 00/19] nvme: switch to libmultipath
Posted by John Garry 1 month, 1 week ago
This switches the NVMe host driver to use libmultipath. That library
is very heavily based on the NVMe multipath code, so the change over
should hopefully be straightforward. There is often a direct replacement
for functions.

The multipath functionality in nvme_ns_head and nvme_ns structures are
replaced with the mpath_head, mpath_disk, and mpath_device structures.

In the driver we have places which test is the nvme_ns_head structure has
member nvme_ns' - for this the nvme_ns_head list was used. Since that
member will disappear, a count of nvme_ns' is added.

It's hard to switch to libmulipath in a step-by-step fashion without
breaking builds or functionality. To make the series reviewable, I took
the approach of adding libmultipath-based code, which would initially be
unused, and then finally making the full switch.

I think that more testing is required here and any help on that would be
appreciated.

The series is based on baa47c4f89eb (nvme/nvme-7.0) nvme-pci: do not
try to add queue maps at runtime and [0]

[0] https://lore.kernel.org/linux-block/20260225153225.1031169-1-john.g.garry@oracle.com/T/#m928333859c0320e57ece0dfcf4ecf58baae3220f

John Garry (19):
  nvme-multipath: pass NS head to nvme_mpath_revalidate_paths()
  nvme: introduce a namespace count in the ns head structure
  nvme-multipath: add nvme_is_mpath_request()
  nvme-multipath: add initial support for using libmultipath
  nvme-multipath: add nvme_mpath_available_path()
  nvme-multipath: add nvme_mpath_{add, remove}_cdev()
  nvme-multipath: add nvme_mpath_is_{disabled, optimised}
  nvme-multipath: add nvme_mpath_get_access_state()
  nvme-multipath: add nvme_mpath_{bdev, cdev}_ioctl()
  nvme-multipath: add uring_cmd support
  nvme-multipath: add nvme_mpath_get_iopolicy()
  nvme-multipath: add PR support for libmultipath
  nvme-multipath: add nvme_mpath_report_zones()
  nvme-multipath: add nvme_mpath_get_unique_id()
  nvme-multipath: add nvme_mpath_synchronize()
  nvme-multipath: add nvme_mpath_{add,delete}_ns()
  nvme-multipath: add nvme_mpath_head_queue_if_no_path()
  nvme-multipath: set mpath_head_template.device_groups
  nvme-multipath: switch to use libmultipath

 drivers/nvme/host/Kconfig     |   1 +
 drivers/nvme/host/core.c      |  81 ++-
 drivers/nvme/host/ioctl.c     |  96 ++--
 drivers/nvme/host/multipath.c | 962 +++++++++++-----------------------
 drivers/nvme/host/nvme.h      | 117 +++--
 drivers/nvme/host/pr.c        | 205 ++++++--
 drivers/nvme/host/sysfs.c     |  84 +--
 7 files changed, 632 insertions(+), 914 deletions(-)

-- 
2.43.5
Re: [PATCH 00/19] nvme: switch to libmultipath
Posted by Christoph Hellwig 1 month ago
On Wed, Feb 25, 2026 at 03:39:48PM +0000, John Garry wrote:
> This switches the NVMe host driver to use libmultipath. That library
> is very heavily based on the NVMe multipath code, so the change over
> should hopefully be straightforward. There is often a direct replacement
> for functions.

Given how little code this removes while adding the new libmultipath
dependency and abstractions I can't say I like this at all.
Re: [PATCH 00/19] nvme: switch to libmultipath
Posted by John Garry 1 month ago
On 02/03/2026 14:12, Christoph Hellwig wrote:
> On Wed, Feb 25, 2026 at 03:39:48PM +0000, John Garry wrote:
>> This switches the NVMe host driver to use libmultipath. That library
>> is very heavily based on the NVMe multipath code, so the change over
>> should hopefully be straightforward. There is often a direct replacement
>> for functions.
> 
> Given how little code this removes while adding the new libmultipath
> dependency and abstractions I can't say I like this at all.
> 

Yeah, so we're losing about 300 lines here in the conversion. However 
nvme mulitpath.c goes from 1410 -> 1250 lines with this series - that's 
not good enough to justify the change.

In a quick review of the code, there is more stuff which I push down 
(into the lib). And a lot of the abstraction code can be condensed - if 
you check something like numa_node_show(), there are 6 variables needed 
just to get to the point where the common helper could be called - that 
is just silly.

Another issue is just that the remaining code is NVMe specific, like ANA 
support, or just doesn't fit the SCSI model, e.g. NVMe iopolicy is per 
subsystem, while for SCSI we don't have a subsystem concept and I so 
made iopolicy per multipathed SCSI disk.
Re: [PATCH 00/19] nvme: switch to libmultipath
Posted by John Garry 1 week ago
On 02/03/2026 14:58, John Garry wrote:
>> Given how little code this removes while adding the new libmultipath
>> dependency and abstractions I can't say I like this at all.
>>
> 

I have been doing some code trimming, and now I am getting a diff like this:

  drivers/nvme/host/core.c      |  84 ++--
  drivers/nvme/host/ioctl.c     | 110 ++--
  drivers/nvme/host/multipath.c | 917 +++++++---------------------------
  drivers/nvme/host/nvme.h      | 144 +++---
  drivers/nvme/host/pr.c        |  18 -
  drivers/nvme/host/sysfs.c     |  86 +---
  6 files changed, 357 insertions(+), 1002 deletions(-)

That is losing 645 LoC - previously it was 282. Would that be a sort of 
acceptable diff?
Obviously that is before thorough review (so prone to change).