Hi John,
On 2/25/26 9:02 PM, 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. However a separate structure will introduced after to manage
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 <[email protected]>.
Signed-off-by: John Garry <[email protected]>
---
include/linux/multipath.h | 28 +++++++++++++++
lib/Kconfig | 6 ++++
lib/Makefile | 2 ++
lib/multipath.c | 74 +++++++++++++++++++++++++++++++++++++++
4 files changed, 110 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..18cd133b7ca21
--- /dev/null
+++ b/include/linux/multipath.h
@@ -0,0 +1,28 @@
+
+#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;
+
+ struct kref ref;
+
+ struct mpath_device __rcu *current_path[MAX_NUMNODES];
+ void *drvdata;
+};
Can we use current_path[] as last element and flex array (same as what
we have today under struct nvme_ns_head) so that we don't need to
allocate array as big as MAX_NUMANODES? With flex array we can use
num_possible_nodes() which may be much smaller than MAX_NUMANODES.
Thanks,
--Nilay