[PATCH v2 00/13] libmultipath: a generic multipath lib for block drivers

John Garry posted 13 patches 1 month, 1 week ago
include/linux/multipath.h |  181 ++++++
lib/Kconfig               |    6 +
lib/Makefile              |    2 +
lib/multipath.c           | 1293 +++++++++++++++++++++++++++++++++++++
4 files changed, 1482 insertions(+)
create mode 100644 include/linux/multipath.h
create mode 100644 lib/multipath.c
[PATCH v2 00/13] libmultipath: a generic multipath lib for block drivers
Posted by John Garry 1 month, 1 week ago
libmultipath: a generic multipath lib for block drivers

This series introduces libmultipath. It is essentially a refactoring of
NVME multipath support, so we can have a common library to also support
native SCSI multipath.

Much of the code is taken directly from the NVMe multipath code. However,
NVMe specifics are removed. A template structure is provided so the driver
may provide callbacks for driver specifics, like ANA support for NVMe.

Important new structures introduced include:

- mpath_head
These contain much of the multipath-specific functionality from
nvme_ns_head, including a pointer to the gendisk structure and
a path SRCU-based array.

- mpath_device
This is the per-path structure, and contains much the same
multipath-specific functionality in nvme_ns

libmultipath provides functionality for path management, path selection,
data path, and failover handling.

Since the NVMe driver has some code in the sysfs and ioctl handling
which iterate all multipath NSes, functions like mpath_call_for_device()
are added to do the same per-path iteration.

Full series also available at
https://github.com/johnpgarry/linux/commits/scsi-multipath-pre-7.1-upstream-v2/

Differences to v1:
- put current_path[] at end of struct mpath_head (Nilay)
- drop struct mpath_disk and keep nvme_remove_head() (Nilay)
- don't pass iopolicy from mpath_find_path() (Benjamin)
- change mpath_access_state names (Nilay)
- fix for setting mpath_device.nr_active and .numa_node (Nilay)
- fix uninit'ed pointers in __mpath_find_path() (Nilay)
- simplify mpath_head_template.available_path (Nilay, Benjamin)
- use DEFINE_SIMPLE_SYSFS_GROUP_VISIBLE (Benjamin)
- check mpath_bdev_submit_bio() -> .clone_bio() for errors (Benjamin)
- drop struct mpath_pr_ops (Keith)
- drop mpath_head_template.bdev_ioctl
- drop mpath_head_template.get_unique_id
- drop mpath_head_template.report_zones
- drop mpath_head_template.get_access_state
- add mpath_head_template.ioctl_{begin, finish} and drop
mpath_head_read_unlock()
- add mpath_device.access_state
- add mpath_head_devices_empty()
- make mpath_delete_device() return a bool

John Garry (13):
  libmultipath: Add initial framework
  libmultipath: Add basic gendisk support
  libmultipath: Add path selection support
  libmultipath: Add bio handling
  libmultipath: Add support for mpath_device management
  libmultipath: Add cdev support
  libmultipath: Add delayed removal support
  libmultipath: Add sysfs helpers
  libmultipath: Add PR support
  libmultipath: Add mpath_bdev_report_zones()
  libmultipath: Add support for block device IOCTL
  libmultipath: Add mpath_bdev_getgeo()
  libmultipath: Add mpath_bdev_get_unique_id()

 include/linux/multipath.h |  181 ++++++
 lib/Kconfig               |    6 +
 lib/Makefile              |    2 +
 lib/multipath.c           | 1293 +++++++++++++++++++++++++++++++++++++
 4 files changed, 1482 insertions(+)
 create mode 100644 include/linux/multipath.h
 create mode 100644 lib/multipath.c

-- 
2.43.5
Re: [PATCH v2 00/13] libmultipath: a generic multipath lib for block drivers
Posted by Mike Snitzer 3 weeks, 6 days ago
On Tue, Apr 28, 2026 at 11:10:52AM +0000, John Garry wrote:
> libmultipath: a generic multipath lib for block drivers
> 
> This series introduces libmultipath. It is essentially a refactoring of
> NVME multipath support, so we can have a common library to also support
> native SCSI multipath.
> 
> Much of the code is taken directly from the NVMe multipath code. However,
> NVMe specifics are removed. A template structure is provided so the driver
> may provide callbacks for driver specifics, like ANA support for NVMe.
> 
> Important new structures introduced include:
> 
> - mpath_head
> These contain much of the multipath-specific functionality from
> nvme_ns_head, including a pointer to the gendisk structure and
> a path SRCU-based array.
> 
> - mpath_device
> This is the per-path structure, and contains much the same
> multipath-specific functionality in nvme_ns
> 
> libmultipath provides functionality for path management, path selection,
> data path, and failover handling.
> 
> Since the NVMe driver has some code in the sysfs and ioctl handling
> which iterate all multipath NSes, functions like mpath_call_for_device()
> are added to do the same per-path iteration.

To get upstream this library needs an in-tree consumer. So at the end
of the series, it'd makes sense to include the NVMe and/or SCSI
changes that uses it.

Mike
Re: [PATCH v2 00/13] libmultipath: a generic multipath lib for block drivers
Posted by John Garry 3 weeks, 5 days ago
On 15/05/2026 01:24, Mike Snitzer wrote:
> On Tue, Apr 28, 2026 at 11:10:52AM +0000, John Garry wrote:
>> libmultipath: a generic multipath lib for block drivers
>>
>> This series introduces libmultipath. It is essentially a refactoring of
>> NVME multipath support, so we can have a common library to also support
>> native SCSI multipath.
>>
>> Much of the code is taken directly from the NVMe multipath code. However,
>> NVMe specifics are removed. A template structure is provided so the driver
>> may provide callbacks for driver specifics, like ANA support for NVMe.
>>
>> Important new structures introduced include:
>>
>> - mpath_head
>> These contain much of the multipath-specific functionality from
>> nvme_ns_head, including a pointer to the gendisk structure and
>> a path SRCU-based array.
>>
>> - mpath_device
>> This is the per-path structure, and contains much the same
>> multipath-specific functionality in nvme_ns
>>
>> libmultipath provides functionality for path management, path selection,
>> data path, and failover handling.
>>
>> Since the NVMe driver has some code in the sysfs and ioctl handling
>> which iterate all multipath NSes, functions like mpath_call_for_device()
>> are added to do the same per-path iteration.
> To get upstream this library needs an in-tree consumer. So at the end
> of the series, it'd makes sense to include the NVMe and/or SCSI
> changes that uses it.

I just sent the SCSI and NVMe series separately. Many devs would find it 
off putting to review a series with so patches.
Re: [PATCH v2 00/13] libmultipath: a generic multipath lib for block drivers
Posted by Sagi Grimberg 1 month ago

On 28/04/2026 14:10, John Garry wrote:
> libmultipath: a generic multipath lib for block drivers

This is very nice John.

>
> This series introduces libmultipath. It is essentially a refactoring of
> NVME multipath support, so we can have a common library to also support
> native SCSI multipath.
>
> Much of the code is taken directly from the NVMe multipath code. However,
> NVMe specifics are removed. A template structure is provided so the driver
> may provide callbacks for driver specifics, like ANA support for NVMe.
>
> Important new structures introduced include:
>
> - mpath_head
> These contain much of the multipath-specific functionality from
> nvme_ns_head, including a pointer to the gendisk structure and
> a path SRCU-based array.

I think it should be placed first in its parent struct as it holds the 
hot-path
head->srcu and head->list.

>
> - mpath_device
> This is the per-path structure, and contains much the same
> multipath-specific functionality in nvme_ns
>
> libmultipath provides functionality for path management, path selection,
> data path, and failover handling.
>
> Since the NVMe driver has some code in the sysfs and ioctl handling
> which iterate all multipath NSes, functions like mpath_call_for_device()
> are added to do the same per-path iteration.

very nice, overall seems fairly straight forward.
Re: [PATCH v2 00/13] libmultipath: a generic multipath lib for block drivers
Posted by John Garry 1 month ago
On 10/05/2026 23:03, Sagi Grimberg wrote:
>> Important new structures introduced include:
>>
>> - mpath_head
>> These contain much of the multipath-specific functionality from
>> nvme_ns_head, including a pointer to the gendisk structure and
>> a path SRCU-based array.
> 
> I think it should be placed first in its parent struct as it holds the 
> hot-path
> head->srcu and head->list.
>

Yeah, I did originally try this. However it becomes a pain for managing 
the lifecycle of the mpath_head and nvme_ns_head/scsi_mpath_head 
structures, especially for the scenarios like the delayed head removal.

However I can see again if I can make it work.

>>
>> - mpath_device
>> This is the per-path structure, and contains much the same
>> multipath-specific functionality in nvme_ns
>>
>> libmultipath provides functionality for path management, path selection,
>> data path, and failover handling.
>>
>> Since the NVMe driver has some code in the sysfs and ioctl handling
>> which iterate all multipath NSes, functions like mpath_call_for_device()
>> are added to do the same per-path iteration.
> 
> very nice, overall seems fairly straight forward.

thanks a lot