From: Hannes Reinecke <hare@suse.de>
To: John Garry <john.g.garry@oracle.com>,
martin.petersen@oracle.com,
james.bottomley@hansenpartnership.com, hare@suse.com
Cc: jmeneghi@redhat.com, linux-nvme@lists.infradead.org,
linux-scsi@vger.kernel.org, michael.christie@oracle.com,
snitzer@kernel.org, bmarzins@redhat.com,
dm-devel@lists.linux.dev, linux-kernel@vger.kernel.org,
nilay@linux.ibm.com, john.garry@linux.dev, hch@lst.de,
kbusch@kernel.org, sagi@grimberg.me
Subject: Re: [PATCH v4 01/28] libmultipath: Add initial framework
Date: Fri, 24 Jul 2026 08:50:40 +0200 [thread overview]
Message-ID: <ba62d294-6954-44d3-af79-6c7da33a5ccd@suse.de> (raw)
In-Reply-To: <20260723093627.2327456-2-john.g.garry@oracle.com>
On 7/23/26 11:35 AM, John Garry wrote:
> Add initial framework for libmultipath. libmultipath is a library for
> multipath-capable block drivers, such as NVMe. The main function is to
> support path management, path selection, and failover handling.
>
> Basic support to add and remove the head structure - mpath_head - is
> included.
>
> This main purpose of this structure is to manage available paths and path
> selection. It is quite similar to the multipath functionality in
> nvme_ns_head. It also manages the multipath gendisk.
>
> Each path is represented by the mpath_device structure. It should hold a
> pointer to the per-path gendisk and also a list element for all siblings
> of paths. For NVMe, there would be a mpath_device per nvme_ns.
>
> All the libmultipath code is more or less taken from
> drivers/nvme/host/multipath.c, which was originally authored by Christoph
> Hellwig <hch@lst.de>.
>
> Signed-off-by: John Garry <john.g.garry@oracle.com>
> ---
> include/linux/multipath.h | 28 +++++++++++++++++
> lib/Kconfig | 6 ++++
> lib/Makefile | 2 ++
> lib/multipath.c | 66 +++++++++++++++++++++++++++++++++++++++
> 4 files changed, 102 insertions(+)
> create mode 100644 include/linux/multipath.h
> create mode 100644 lib/multipath.c
>
> diff --git a/include/linux/multipath.h b/include/linux/multipath.h
> new file mode 100644
> index 0000000000000..e98b4b241020a
> --- /dev/null
> +++ b/include/linux/multipath.h
> @@ -0,0 +1,28 @@
Please add an SPDX tag.
And possibly a copyright.
> +
> +#ifndef _LIBMULTIPATH_H
> +#define _LIBMULTIPATH_H
> +
> +#include <linux/blkdev.h>
> +#include <linux/srcu.h>
> +
> +struct mpath_device {
> + struct list_head siblings;
> + struct gendisk *disk;
> +};
> +
> +struct mpath_head {
> + struct srcu_struct srcu;
> + struct list_head dev_list; /* list of all mpath_devs */
> + struct mutex lock;
> +
> + refcount_t refcount;
> +
> + struct mpath_device __rcu *current_path[MAX_NUMNODES];
> +};
> +
> +int mpath_get_head(struct mpath_head *mpath_head);
> +void mpath_put_head(struct mpath_head *mpath_head);
> +int mpath_head_init(struct mpath_head *mpath_head);
> +void mpath_head_uninit(struct mpath_head *mpath_head);
> +
> +#endif // _LIBMULTIPATH_H
> diff --git a/lib/Kconfig b/lib/Kconfig
> index 55748b68714e0..d0258bef374a1 100644
> --- a/lib/Kconfig
> +++ b/lib/Kconfig
> @@ -636,3 +636,9 @@ config UNION_FIND
>
> config MIN_HEAP
> bool
> +
> +config LIBMULTIPATH
> + bool "MULTIPATH BLOCK DRIVER LIBRARY"
> + depends on BLOCK
> + help
> + If you say yes here then you get a multipath lib for block drivers
> diff --git a/lib/Makefile b/lib/Makefile
> index 7f75cc6edf94a..7ba5e13be4171 100644
> --- a/lib/Makefile
> +++ b/lib/Makefile
> @@ -334,3 +334,5 @@ CONTEXT_ANALYSIS_test_context-analysis.o := y
> obj-$(CONFIG_CONTEXT_ANALYSIS_TEST) += test_context-analysis.o
>
> subdir-$(CONFIG_FORTIFY_SOURCE) += test_fortify
> +
> +obj-$(CONFIG_LIBMULTIPATH) += multipath.o
> diff --git a/lib/multipath.c b/lib/multipath.c
> new file mode 100644
> index 0000000000000..9cc398d266adf
> --- /dev/null
> +++ b/lib/multipath.c
> @@ -0,0 +1,66 @@
> +// SPDX-License-Identifier: GPL-2.0-only
> +/*
> + * Copyright (c) 2017-2018 Christoph Hellwig.
A bit unusual, creating a new file and add a copyright
from _another_ person ...
> + * Copyright (c) 2026 Oracle and/or its affiliates.
> + */
> +#include <linux/module.h>
> +#include <linux/multipath.h>
> +
> +static struct workqueue_struct *mpath_wq;
> +
> +int mpath_get_head(struct mpath_head *mpath_head)
> +{
> + if (!refcount_inc_not_zero(&mpath_head->refcount))
> + return -ENXIO;
> + return 0;
> +}
> +EXPORT_SYMBOL_GPL(mpath_get_head);
> +
> +void mpath_put_head(struct mpath_head *mpath_head)
> +{
> + refcount_t *refcount = &mpath_head->refcount;
> +
> + if (refcount_dec_and_test(&mpath_head->refcount))
> + wake_up_var(refcount);
> +}
> +EXPORT_SYMBOL_GPL(mpath_put_head);
> +
> +void mpath_head_uninit(struct mpath_head *mpath_head)
> +{
> + refcount_t *refcount = &mpath_head->refcount;
> +
> + if (!refcount_dec_and_test(refcount))
> + wait_var_event(refcount, !refcount_read(refcount));
> + cleanup_srcu_struct(&mpath_head->srcu);
> +}
> +EXPORT_SYMBOL_GPL(mpath_head_uninit);
> +
> +int mpath_head_init(struct mpath_head *mpath_head)
> +{
> + memset(mpath_head, 0, sizeof(*mpath_head));
> + INIT_LIST_HEAD(&mpath_head->dev_list);
> + mutex_init(&mpath_head->lock);
> + refcount_set(&mpath_head->refcount, 1);
> +
> + return init_srcu_struct(&mpath_head->srcu);
> +}
> +EXPORT_SYMBOL_GPL(mpath_head_init);
> +
> +static int __init mpath_init(void)
> +{
> + mpath_wq = alloc_workqueue("mpath-wq",
> + WQ_UNBOUND | WQ_MEM_RECLAIM | WQ_SYSFS, 0);
> + if (!mpath_wq)
> + return -ENOMEM;
> + return 0;
> +}
> +
> +static void __exit mpath_exit(void)
> +{
> + destroy_workqueue(mpath_wq);
> +}
> +
> +module_init(mpath_init);
> +module_exit(mpath_exit);
> +MODULE_LICENSE("GPL");
> +MODULE_DESCRIPTION("libmultipath");
Otherwise:
Reviewed-by: Hannes Reinecke <hare@kernel.org>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
next prev parent reply other threads:[~2026-07-24 6:50 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-23 9:35 [PATCH v4 00/28] Native SCSI Multipath support John Garry
2026-07-23 9:35 ` [PATCH v4 01/28] libmultipath: Add initial framework John Garry
2026-07-24 6:50 ` Hannes Reinecke [this message]
2026-07-24 8:00 ` John Garry
2026-07-23 9:36 ` [PATCH v4 02/28] libmultipath: Add basic gendisk support John Garry
2026-07-23 9:36 ` [PATCH v4 03/28] libmultipath: Add path selection support John Garry
2026-07-23 9:36 ` [PATCH v4 04/28] libmultipath: Add bio handling John Garry
2026-07-23 9:36 ` [PATCH v4 05/28] libmultipath: Add support for mpath_device management John Garry
2026-07-23 9:36 ` [PATCH v4 06/28] libmultipath: Add delayed removal support John Garry
2026-07-23 9:36 ` [PATCH v4 07/28] libmultipath: Add sysfs helpers John Garry
2026-07-23 9:36 ` [PATCH v4 08/28] libmultipath: Add mpath_bdev_report_zones() John Garry
2026-07-23 9:36 ` [PATCH v4 09/28] libmultipath: Add support for block device IOCTL John Garry
2026-07-23 9:36 ` [PATCH v4 10/28] libmultipath: Add mpath_bdev_getgeo() John Garry
2026-07-23 9:36 ` [PATCH v4 11/28] libmultipath: Add mpath_bdev_get_unique_id() John Garry
2026-07-23 9:36 ` [PATCH v4 12/28] scsi-multipath: introduce basic SCSI device support John Garry
2026-07-23 9:36 ` [PATCH v4 13/28] scsi-multipath: introduce scsi_device head structure John Garry
2026-07-23 9:36 ` [PATCH v4 14/28] scsi-multipath: provide sysfs link from to scsi_device John Garry
2026-07-23 9:36 ` [PATCH v4 15/28] scsi-multipath: support iopolicy John Garry
2026-07-23 9:36 ` [PATCH v4 16/28] scsi-multipath: clone each bio John Garry
2026-07-23 9:36 ` [PATCH v4 17/28] scsi-multipath: clear path when device is blocked John Garry
2026-07-23 9:36 ` [PATCH v4 18/28] scsi-multipath: revalidate paths upon device unblock John Garry
2026-07-23 9:36 ` [PATCH v4 19/28] scsi-multipath: failover handling John Garry
2026-07-23 9:36 ` [PATCH v4 20/28] scsi-multipath: provide callbacks for path state John Garry
2026-07-23 9:36 ` [PATCH v4 21/28] scsi-multipath: add scsi_mpath_{start,end}_request() John Garry
2026-07-23 9:36 ` [PATCH v4 22/28] scsi-multipath: add delayed disk removal support John Garry
2026-07-23 9:36 ` [PATCH v4 23/28] scsi: sd: add multipath disk class John Garry
2026-07-23 9:36 ` [PATCH v4 24/28] scsi: sd: add multipath disk attr groups John Garry
2026-07-23 9:36 ` [PATCH v4 25/28] scsi: sd: support multipath disk John Garry
2026-07-23 9:36 ` [PATCH v4 26/28] scsi: sd: add mpath_dev file John Garry
2026-07-23 9:36 ` [PATCH v4 27/28] scsi: sd: add mpath_numa_nodes dev attribute John Garry
2026-07-23 9:36 ` [PATCH v4 28/28] scsi: sd: add mpath_queue_depth " 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=ba62d294-6954-44d3-af79-6c7da33a5ccd@suse.de \
--to=hare@suse.de \
--cc=bmarzins@redhat.com \
--cc=dm-devel@lists.linux.dev \
--cc=hare@suse.com \
--cc=hch@lst.de \
--cc=james.bottomley@hansenpartnership.com \
--cc=jmeneghi@redhat.com \
--cc=john.g.garry@oracle.com \
--cc=john.garry@linux.dev \
--cc=kbusch@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.org \
--cc=linux-scsi@vger.kernel.org \
--cc=martin.petersen@oracle.com \
--cc=michael.christie@oracle.com \
--cc=nilay@linux.ibm.com \
--cc=sagi@grimberg.me \
--cc=snitzer@kernel.org \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®