libmultipath: a generic multipath lib for block drivers
Subsystems (4)
v2 cover libmultipath: a generic multipath lib for block drivers
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
Signature · 1 line
2.43.5
PATCH v2 1/13 libmultipath: Add initial framework
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 <[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
include/linux/multipath.h new file +28 -0
@@ -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; + +void *drvdata; +struct mpath_device __rcu *current_path[]; +}; + +int mpath_get_head (struct mpath_head *mpath_head); +void mpath_put_head (struct mpath_head *mpath_head); +struct mpath_head *mpath_alloc_head (void ); + +#endif // _LIBMULTIPATH_H
lib/Kconfig +6 -0
@@ -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
lib/Makefile +2 -0
@@ -335,3 +335,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
lib/multipath.c new file +74 -0
74 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v2 2/13 libmultipath: Add basic gendisk support
In reply to John GarryAdd support to allocate and free a multipath gendisk.
NVMe has almost like-for-like equivalents here:
- mpath_alloc_head_disk() -> nvme_mpath_alloc_disk()
- multipath_partition_scan_work() -> nvme_partition_scan_work()
- mpath_remove_disk() -> nvme_remove_head()
- mpath_device_set_live() -> nvme_mpath_set_live()
struct mpath_head_template is introduced as a method for drivers to provide custom multipath functionality.
--- include/linux/multipath.h | 38 ++++++++++++++++ lib/multipath.c | 96 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+)
include/linux/multipath.h +38 -0
@@ -5,11 +5,19 @@#include <linux/blkdev.h> #include <linux/srcu.h> +extern const struct block_device_operations mpath_ops; +struct mpath_device { +struct mpath_head *mpath_head;struct list_head siblings;struct gendisk *disk; }; +struct mpath_head_template { +}; + +#define MPATH_HEAD_DISK_LIVE 0 +struct mpath_head {struct srcu_struct srcu;struct list_head dev_list;/* list of all mpath_devs */
@@ -18,11 +26,41 @@ struct mpath_head {struct kref ref;void *drvdata; +unsigned long flags; +struct gendisk *disk; +struct work_struct partition_scan_work; +struct device *parent; +const struct attribute_group **disk_groups; +const struct mpath_head_template *mpdt;struct mpath_device __rcu *current_path[]; }; +static inline struct mpath_head *mpath_bd_device_to_head (struct device *dev) +{ +return dev_get_drvdata (dev); +} + +static inline struct mpath_head *mpath_gendisk_to_head (struct gendisk *disk) +{ +return mpath_bd_device_to_head (disk_to_dev (disk)); +} +int mpath_get_head (struct mpath_head *mpath_head);void mpath_put_head (struct mpath_head *mpath_head);struct mpath_head *mpath_alloc_head (void ); +void mpath_put_disk (struct mpath_head *mpath_head); +void mpath_remove_disk (struct mpath_head *mpath_head); +int mpath_alloc_head_disk (struct mpath_head *mpath_head, +struct queue_limits *lim,int numa_node); +void mpath_device_set_live (struct mpath_device *mpath_device); + +static inline bool is_mpath_disk (struct gendisk *disk) +{ +#if IS_ENABLED (CONFIG_LIBMULTIPATH ) +return disk->fops == &mpath_ops; +#else +return false; +#endif +}#endif // _LIBMULTIPATH_H
lib/multipath.c +96 -0
108 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v2 3/13 libmultipath: Add path selection support
In reply to John GarryAdd code for path selection.
NVMe ANA is abstracted into enum mpath_access_state. The motivation here is so that SCSI ALUA can be used. Callbacks .is_disabled, .is_optimized, .get_access_state are added to get the path access state.
Path selection modes round-robin, NUMA, and queue-depth are added, same as NVMe supports.
NVMe has almost like-for-like equivalents here:
- __mpath_find_path() -> __nvme_find_path()
- mpath_find_path() -> nvme_find_path()
and similar for all introduced callee functions.
Functions mpath_set_iopolicy() and mpath_get_iopolicy() are added for setting default iopolicy.
A separate mpath_iopolicy structure is introduced. There is no iopolicy member included in the mpath_head structure as it may not suit NVMe, where iopolicy is per-subsystem and not per namespace.
--- include/linux/multipath.h | 37 ++++++ lib/multipath.c | 248 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 285 insertions(+)
include/linux/multipath.h +37 -0
@@ -7,13 +7,36 @@extern const struct block_device_operations mpath_ops; +enum mpath_iopolicy_e { +MPATH_IOPOLICY_NUMA , +MPATH_IOPOLICY_RR , +MPATH_IOPOLICY_QD , +}; + +struct mpath_iopolicy { +enum mpath_iopolicy_e iopolicy; +}; + +enum mpath_access_state { +MPATH_STATE_OPTIMIZED , +MPATH_STATE_NONOPTIMIZED , +MPATH_STATE_OTHER +}; +struct mpath_device {struct mpath_head *mpath_head;struct list_head siblings;struct gendisk *disk; +int numa_node; +enum mpath_access_state access_state; };struct mpath_head_template { +bool (*is_disabled)(struct mpath_device *); +bool (*is_optimized)(struct mpath_device *); +int (*get_nr_active)(struct mpath_device *); +enum mpath_iopolicy_e (*get_iopolicy)(struct mpath_head *); +const struct attribute_group **device_groups; };#define MPATH_HEAD_DISK_LIVE 0
@@ -45,6 +68,14 @@ static inline struct mpath_head *mpath_gendisk_to_head(struct gendisk *disk)return mpath_bd_device_to_head (disk_to_dev (disk)); } +static inline enum mpath_iopolicy_e mpath_read_iopolicy ( +struct mpath_iopolicy *mpath_iopolicy) +{ +return READ_ONCE (mpath_iopolicy->iopolicy); +} +void mpath_synchronize (struct mpath_head *mpath_head); +int mpath_set_iopolicy (const char *val,int *iopolicy); +int mpath_get_iopolicy (char *buf,int iopolicy);int mpath_get_head (struct mpath_head *mpath_head);void mpath_put_head (struct mpath_head *mpath_head);struct mpath_head *mpath_alloc_head (void );
@@ -63,4 +94,10 @@ static inline bool is_mpath_disk(struct gendisk *disk)return false; #endif } + +static inline bool mpath_qd_iopolicy (struct mpath_iopolicy *mpath_iopolicy) +{ +return mpath_read_iopolicy (mpath_iopolicy) ==MPATH_IOPOLICY_QD ; +} +#endif // _LIBMULTIPATH_H
lib/multipath.c +248 -0
268 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v2 4/13 libmultipath: Add bio handling
In reply to John GarryAdd support to submit a bio per-path. In addition, for failover, add support to requeue a failed bio.
NVMe has almost like-for-like equivalents here:
- nvme_available_path() -> mpath_available_path()
- nvme_requeue_work() -> mpath_requeue_work()
- nvme_ns_head_submit_bio() -> mpath_bdev_submit_bio()
For failover, a driver may want to re-submit a bio, so add support to clone a bio prior to submission.
A bio which is submitted to a per-path device has flag REQ_MPATH set, same as what is done for NVMe with REQ_NVME_MPATH.
--- include/linux/multipath.h | 18 +++++++ lib/multipath.c | 100 +++++++++++++++++++++++++++++++++++++- 2 files changed, 116 insertions(+), 2 deletions(-)
include/linux/multipath.h +18 -0
@@ -3,6 +3,7 @@#define _LIBMULTIPATH_H#include <linux/blkdev.h> +#include <linux/blk-mq.h> #include <linux/srcu.h> extern const struct block_device_operations mpath_ops;
@@ -32,10 +33,12 @@ struct mpath_device { };struct mpath_head_template { +bool (*available_path)(struct mpath_device *);bool (*is_disabled)(struct mpath_device *);bool (*is_optimized)(struct mpath_device *);int (*get_nr_active)(struct mpath_device *);enum mpath_iopolicy_e (*get_iopolicy)(struct mpath_head *); +struct bio *(*clone_bio)(struct bio *);const struct attribute_group **device_groups; };
@@ -48,6 +51,10 @@ struct mpath_head {struct kref ref; +struct bio_list requeue_list;/* list for requeing bio */ +spinlock_t requeue_lock; +struct work_struct requeue_work;/* work struct for requeue */ +void *drvdata;unsigned long flags;struct gendisk *disk;
@@ -58,6 +65,13 @@ struct mpath_head {struct mpath_device __rcu *current_path[]; }; +#define REQ_MPATH REQ_DRV + +static inline bool is_mpath_request (struct request *req) +{ +return req->cmd_flags &REQ_MPATH ; +} +static inline struct mpath_head *mpath_bd_device_to_head (struct device *dev) {return dev_get_drvdata (dev);
@@ -100,4 +114,8 @@ static inline bool mpath_qd_iopolicy(struct mpath_iopolicy *mpath_iopolicy) return mpath_read_iopolicy(mpath_iopolicy) == MPATH_IOPOLICY_QD; } +static inline void mpath_schedule_requeue_work (struct mpath_head *mpath_head) +{ +kblockd_schedule_work (&mpath_head->requeue_work); +}#endif // _LIBMULTIPATH_H
lib/multipath.c +98 -2
159 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v2 5/13 libmultipath: Add support for mpath_device management
In reply to John GarryAdd support to add or remove a mpath_device as a path.
NVMe has almost like-for-like equivalents here:
- nvme_mpath_clear_current_path() -> mpath_clear_current_path()
- nvme_mpath_add_sysfs_link() -> mpath_add_sysfs_link()
- nvme_mpath_remove_sysfs_link() -> mpath_remove_sysfs_link()
- nvme_mpath_revalidate_paths() -> mpath_revalidate_paths()
mpath_revalidate_paths() has a CB arg for NVMe specific handling.
The functionality in mpath_clear_paths() and mpath_synchronize() have the same pattern which is frequently used in the NVMe code.
Helper mpath_call_for_device() is added to allow a driver run a callback on any path available. It is intended to be used for occasions when the NVMe drivers accesses the list of paths outside its multipath code, like NVMe sysfs.c
--- include/linux/multipath.h | 16 ++++ lib/multipath.c | 182 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 198 insertions(+)
include/linux/multipath.h +16 -0
@@ -24,10 +24,13 @@ enum mpath_access_state { MPATH_STATE_OTHER }; +#define MPATH_DEVICE_SYSFS_ATTR_LINK 0 +struct mpath_device {struct mpath_head *mpath_head;struct list_head siblings;struct gendisk *disk; +unsigned long flags;int numa_node;enum mpath_access_state access_state; };
@@ -90,6 +93,19 @@ static inline enum mpath_iopolicy_e mpath_read_iopolicy(void mpath_synchronize (struct mpath_head *mpath_head);int mpath_set_iopolicy (const char *val,int *iopolicy);int mpath_get_iopolicy (char *buf,int iopolicy); +bool mpath_clear_current_path (struct mpath_device *mpath_device); +void mpath_synchronize (struct mpath_head *mpath_head); +void mpath_add_device (struct mpath_head *mpath_head, +struct mpath_device *mpath_device); +bool mpath_delete_device (struct mpath_device *mpath_device); +bool mpath_head_devices_empty (struct mpath_head *mpath_head); +int mpath_call_for_device (struct mpath_head *mpath_head, +int (*cb)(struct mpath_device *mpath_device)); +void mpath_clear_paths (struct mpath_head *mpath_head); +void mpath_revalidate_paths (struct mpath_head *mpath_head, +void (*not_ready_cb)(struct mpath_device *mpath_device)); +void mpath_add_sysfs_link (struct mpath_head *mpath_head); +void mpath_remove_sysfs_link (struct mpath_device *mpath_device);int mpath_get_head (struct mpath_head *mpath_head);void mpath_put_head (struct mpath_head *mpath_head);struct mpath_head *mpath_alloc_head (void );
lib/multipath.c +182 -0
200 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v2 6/13 libmultipath: Add cdev support
In reply to John GarryAdd support to create a cdev multipath device. The functionality is much the same as NVMe, where the cdev is created when a mpath device is set live.
The driver must provide a mpath_head_template.cdev_ioctl callback to actually handle the ioctl.
Structure mpath_generic_chr_fops would be used for setting the cdev fops in the mpath_head_template.add_cdev callback.
NVMe cdev iotcl handler has special handling for NVMe controller commands. In this case, the SRCU read lock is dropped before executing the ioctl. For reference, see nvme_ns_head_ctrl_ioctl(). This makes having the SRCU lock when calling not always possible. To handle this scenario, add template callbacks .ioctl_begin and .ioctl_finish to be called around the before and after the ioctl callback - if the .ioctl_begin returns data then we know to drop the SRCU lock before calling the ioctl callback, and then later call .ioctl_finish callback with that same data. For NVMe using libmultipath, we would take a reference to the controller structure and pass a pointer to the controller structure back in .ioctl_begin callback and use that same data in the .ioctl_finish callback to put the reference to the controller.
--- include/linux/multipath.h | 18 ++++++ lib/multipath.c | 129 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 147 insertions(+)
include/linux/multipath.h +18 -0
@@ -4,8 +4,11 @@#include <linux/blkdev.h> #include <linux/blk-mq.h> +#include <linux/cdev.h> #include <linux/srcu.h> +#include <linux/io_uring/cmd.h> +extern const struct file_operations mpath_chr_fops;extern const struct block_device_operations mpath_ops;enum mpath_iopolicy_e {
@@ -37,12 +40,24 @@ struct mpath_device {struct mpath_head_template {bool (*available_path)(struct mpath_device *); +int (*add_cdev)(struct mpath_head *); +void (*del_cdev)(struct mpath_head *);bool (*is_disabled)(struct mpath_device *);bool (*is_optimized)(struct mpath_device *);int (*get_nr_active)(struct mpath_device *); +long (*cdev_ioctl)(struct mpath_device *,unsigned int cmd, +unsigned long arg,bool open_for_write); +int (*chr_uring_cmd)(struct mpath_device *, +struct io_uring_cmd *ioucmd, +unsigned int issue_flags); +int (*chr_uring_cmd_iopoll)(struct io_uring_cmd *ioucmd, +struct io_comp_batch *iob, +unsigned int poll_flags);enum mpath_iopolicy_e (*get_iopolicy)(struct mpath_head *);struct bio *(*clone_bio)(struct bio *);const struct attribute_group **device_groups; +void (*ioctl_begin)(struct mpath_device *,unsigned int cmd,void **); +void (*ioctl_finish)(void *opaque); };#define MPATH_HEAD_DISK_LIVE 0
@@ -58,6 +73,9 @@ struct mpath_head {spinlock_t requeue_lock;struct work_struct requeue_work;/* work struct for requeue */ +struct cdev cdev; +struct device cdev_device; +void *drvdata;unsigned long flags;struct gendisk *disk;
lib/multipath.c +129 -0
153 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v2 7/13 libmultipath: Add delayed removal support
In reply to John GarryAdd support for delayed removal, same as exists for NVMe.
The purpose of this feature is to keep the multipath disk and cdev present for intermittent periods of no available path.
Helpers mpath_delayed_removal_secs_show() and mpath_delayed_removal_secs_store() may be used in the driver sysfs code.
The driver is responsible for supplying the removal work callback for the delayed work.
--- include/linux/multipath.h | 18 ++++++++ lib/multipath.c | 91 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 108 insertions(+), 1 deletion(-)
include/linux/multipath.h +18 -0
@@ -40,6 +40,7 @@ struct mpath_device {struct mpath_head_template {bool (*available_path)(struct mpath_device *); +void (*remove_head)(struct mpath_head *);int (*add_cdev)(struct mpath_head *);void (*del_cdev)(struct mpath_head *);bool (*is_disabled)(struct mpath_device *);
@@ -61,6 +62,7 @@ struct mpath_head_template { };#define MPATH_HEAD_DISK_LIVE 0 +#define MPATH_HEAD_QUEUE_IF_NO_PATH 1struct mpath_head {struct srcu_struct srcu;
@@ -76,6 +78,10 @@ struct mpath_head {struct cdev cdev;struct device cdev_device; +struct delayed_work remove_work; +unsigned int delayed_removal_secs; +struct module *drv_module; +void *drvdata;unsigned long flags;struct gendisk *disk;
@@ -133,6 +139,11 @@ void mpath_remove_disk(struct mpath_head *mpath_head);int mpath_alloc_head_disk (struct mpath_head *mpath_head,struct queue_limits *lim,int numa_node);void mpath_device_set_live (struct mpath_device *mpath_device); +bool mpath_can_remove_head (struct mpath_head *mpath_head); +ssize_t mpath_delayed_removal_secs_show (struct mpath_head *mpath_head, +char *buf); +ssize_t mpath_delayed_removal_secs_store (struct mpath_head *mpath_head, +const char *buf,size_t count);static inline bool is_mpath_disk (struct gendisk *disk) {
@@ -148,6 +159,13 @@ static inline bool mpath_qd_iopolicy(struct mpath_iopolicy *mpath_iopolicy)return mpath_read_iopolicy (mpath_iopolicy) ==MPATH_IOPOLICY_QD ; } +static inline bool mpath_head_queue_if_no_path (struct mpath_head *mpath_head) +{ +if (test_bit (MPATH_HEAD_QUEUE_IF_NO_PATH , &mpath_head->flags)) +return true; +return false; +} +static inline void mpath_schedule_requeue_work (struct mpath_head *mpath_head) {kblockd_schedule_work (&mpath_head->requeue_work);
lib/multipath.c +90 -1
121 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v2 8/13 libmultipath: Add sysfs helpers
In reply to John GarryAdd helpers for driver sysfs code for the following functionality:
- get/set iopolicy with mpath_iopolicy_store() and mpath_iopolicy_show()
- show device path per NUMA node
- "multipath" attribute group, equivalent to nvme_ns_mpath_attr_group
- device groups attribute array, similar to nvme_ns_attr_groups but not containing NVMe members.
Note that mpath_iopolicy_store() has a update callback to allow same functionality as nvme_subsys_iopolicy_update() be run for clearing paths.
--- include/linux/multipath.h | 7 +++ lib/multipath.c | 96 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+)
include/linux/multipath.h +7 -0
@@ -10,6 +10,8 @@extern const struct file_operations mpath_chr_fops;extern const struct block_device_operations mpath_ops; +extern const struct attribute_group mpath_attr_group; +extern const struct attribute_group *mpath_device_groups[];enum mpath_iopolicy_e {MPATH_IOPOLICY_NUMA ,
@@ -140,6 +142,11 @@ int mpath_alloc_head_disk(struct mpath_head *mpath_head, struct queue_limits *lim, int numa_node);void mpath_device_set_live (struct mpath_device *mpath_device);bool mpath_can_remove_head (struct mpath_head *mpath_head); +ssize_t mpath_numa_nodes_show (struct mpath_device *mpath_device, +struct mpath_iopolicy *iopolicy,char *buf); +ssize_t mpath_iopolicy_show (struct mpath_iopolicy *mpath_iopolicy,char *buf); +bool mpath_iopolicy_store (struct mpath_iopolicy *mpath_iopolicy, +const char *buf,size_t count);ssize_t mpath_delayed_removal_secs_show (struct mpath_head *mpath_head,char *buf); ssize_t mpath_delayed_removal_secs_store(struct mpath_head *mpath_head,
lib/multipath.c +96 -0
102 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v2 9/13 libmultipath: Add PR support
In reply to John GarryAdd support for persistent reservations.
Effectively all that is done here is that a multipath version of pr_ops is created which calls into the bdev fops callback for the mpath_device selected.
--- include/linux/multipath.h | 1 + lib/multipath.c | 182 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 183 insertions(+)
include/linux/multipath.h +1 -0
@@ -5,6 +5,7 @@#include <linux/blkdev.h> #include <linux/blk-mq.h> #include <linux/cdev.h> +#include <linux/pr.h> #include <linux/srcu.h> #include <linux/io_uring/cmd.h>
lib/multipath.c +182 -0
193 lines not on this page · raw message
Signature · 1 line
2.43.5
PATCH v2 10/13 libmultipath: Add mpath_bdev_report_zones()
In reply to John GarryAdd a multipath handler for block_device_operations.report_zones
--- lib/multipath.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+)
lib/multipath.c +25 -0
@@ -40,6 +40,30 @@ int mpath_get_iopolicy(char *buf, int iopolicy) }EXPORT_SYMBOL_GPL (mpath_get_iopolicy); +#ifdef CONFIG_BLK_DEV_ZONED +static int mpath_bdev_report_zones (struct gendisk *disk,sector_t sector, +unsigned int nr_zones,struct blk_report_zones_args *args) +{ +struct mpath_head *mpath_head =mpath_gendisk_to_head (disk); +struct mpath_device *mpath_device; +int srcu_idx, ret = -EWOULDBLOCK ; + + srcu_idx =srcu_read_lock (&mpath_head->srcu); + mpath_device =mpath_find_path (mpath_head); +if (mpath_device) { +if (mpath_device->disk->fops->report_zones) + ret = mpath_device->disk->fops->report_zones + (mpath_device->disk, sector, nr_zones, args); +else + ret = -EOPNOTSUPP ; + } +srcu_read_unlock (&mpath_head->srcu, srcu_idx); +return ret; +} +#else +#define mpath_bdev_report_zones NULL +#endif /* CONFIG_BLK_DEV_ZONED */ +void mpath_synchronize (struct mpath_head *mpath_head) {synchronize_srcu (&mpath_head->srcu);
@@ -652,6 +676,7 @@ const struct block_device_operations mpath_ops = { .open = mpath_bdev_open, .release = mpath_bdev_release, .submit_bio = mpath_bdev_submit_bio, + .report_zones = mpath_bdev_report_zones, .pr_ops = &mpath_pr_ops, };EXPORT_SYMBOL_GPL (mpath_ops);
Signature · 1 line
2.43.5
PATCH v2 11/13 libmultipath: Add support for block device IOCTL
In reply to John GarryAdd mpath_bdev_ioctl() as a multipath block device IOCTL handler. This handler calls into the mpath_device bdev fops handler.
Like what is done for cdev IOCTL handler, use .ioctl_begin and .ioctl_finish methods to know when the until the SRCU read lock - this is for special NVMe controller IOCTL handling.
The .compat_ioctl handler is given the standard handler.
--- lib/multipath.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
lib/multipath.c +34 -0
@@ -490,6 +490,38 @@ static void mpath_bdev_release(struct gendisk *disk)mpath_put_head (mpath_head); } +static int mpath_bdev_ioctl (struct block_device *bdev,blk_mode_t mode, +unsigned int cmd,unsigned long arg) +{ +struct gendisk *disk = bdev->bd_disk; +struct mpath_head *mpath_head =mpath_gendisk_to_head (disk); +struct mpath_device *mpath_device; +int srcu_idx, err; +void *unlocked_ioctl_data =NULL ; + + srcu_idx =srcu_read_lock (&mpath_head->srcu); + mpath_device =mpath_find_path (mpath_head); +if (!mpath_device) { + err = -EWOULDBLOCK ; + goto out_unlock; + } + +if (mpath_head->mpdt->ioctl_begin) + mpath_head->mpdt->ioctl_begin (mpath_device, cmd, + &unlocked_ioctl_data); +if (unlocked_ioctl_data) +srcu_read_unlock (&mpath_head->srcu, srcu_idx); + err = mpath_device->disk->fops->ioctl ( + mpath_device->disk->part0, mode, cmd, arg); +if (unlocked_ioctl_data) { + mpath_head->mpdt->ioctl_finish (unlocked_ioctl_data); +return err; + } +out_unlock: +srcu_read_unlock (&mpath_head->srcu, srcu_idx); +return err; +} +static int mpath_pr_register (struct block_device *bdev,u64 old_key,u64 new_key,unsigned int flags) {
@@ -676,6 +708,8 @@ const struct block_device_operations mpath_ops = { .open = mpath_bdev_open, .release = mpath_bdev_release, .submit_bio = mpath_bdev_submit_bio, + .ioctl = mpath_bdev_ioctl, + .compat_ioctl = blkdev_compat_ptr_ioctl, .report_zones = mpath_bdev_report_zones, .pr_ops = &mpath_pr_ops, };
Signature · 1 line
2.43.5
PATCH v2 12/13 libmultipath: Add mpath_bdev_getgeo()
In reply to John GarryAdd mpath_bdev_getgeo() as a multipath block device .getgeo handler.
Here we just redirect into the selected mpath_device disk fops->getgeo handler.
--- lib/multipath.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
lib/multipath.c +21 -0
@@ -522,6 +522,26 @@ static int mpath_bdev_ioctl(struct block_device *bdev, blk_mode_t mode,return err; } +static int mpath_bdev_getgeo (struct gendisk *disk,struct hd_geometry *geo) +{ +struct mpath_head *mpath_head =mpath_gendisk_to_head (disk); +int srcu_idx, ret = -EWOULDBLOCK ; +struct mpath_device *mpath_device; + + srcu_idx =srcu_read_lock (&mpath_head->srcu); + mpath_device =mpath_find_path (mpath_head); +if (mpath_device) { +if (mpath_device->disk->fops->getgeo) + ret = mpath_device->disk->fops->getgeo ( + mpath_device->disk, geo); +else + ret = -ENOTTY ;/* See blkdev_getgeo */ + } +srcu_read_unlock (&mpath_head->srcu, srcu_idx); + +return ret; +} +static int mpath_pr_register (struct block_device *bdev,u64 old_key,u64 new_key,unsigned int flags) {
@@ -711,6 +731,7 @@ const struct block_device_operations mpath_ops = { .ioctl = mpath_bdev_ioctl, .compat_ioctl = blkdev_compat_ptr_ioctl, .report_zones = mpath_bdev_report_zones, + .getgeo = mpath_bdev_getgeo, .pr_ops = &mpath_pr_ops, };EXPORT_SYMBOL_GPL (mpath_ops);
Signature · 1 line
2.43.5
PATCH v2 13/13 libmultipath: Add mpath_bdev_get_unique_id()
In reply to John GarryAdd mpath_bdev_get_unique_id() as a multipath block device .get_unique_id handler.
--- lib/multipath.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
lib/multipath.c +21 -0
@@ -490,6 +490,26 @@ static void mpath_bdev_release(struct gendisk *disk)mpath_put_head (mpath_head); } +static int mpath_bdev_get_unique_id (struct gendisk *disk,u8 id[16 ], +enum blk_unique_id type) +{ +struct mpath_head *mpath_head =mpath_gendisk_to_head (disk); +int srcu_idx, ret = -EWOULDBLOCK ; +struct mpath_device *mpath_device; + + srcu_idx =srcu_read_lock (&mpath_head->srcu); + mpath_device =mpath_find_path (mpath_head); +if (mpath_device) { +if (mpath_device->disk->fops->get_unique_id) + ret = mpath_device->disk->fops->get_unique_id ( + mpath_device->disk, id, type); +else + ret =0 ;/* referencing __dm_get_unique_id() */ + } +srcu_read_unlock (&mpath_head->srcu, srcu_idx); + +return ret; +}static int mpath_bdev_ioctl (struct block_device *bdev,blk_mode_t mode,unsigned int cmd,unsigned long arg) {
@@ -730,6 +750,7 @@ const struct block_device_operations mpath_ops = { .submit_bio = mpath_bdev_submit_bio, .ioctl = mpath_bdev_ioctl, .compat_ioctl = blkdev_compat_ptr_ioctl, + .get_unique_id = mpath_bdev_get_unique_id, .report_zones = mpath_bdev_report_zones, .getgeo = mpath_bdev_getgeo, .pr_ops = &mpath_pr_ops,
Signature · 1 line
2.43.5
Sagi Grimberg
maintainerQuoted 1 line · John Garry
libmultipath: a generic multipath lib for block drivers
This is very nice John.
Quoted 9 lines
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.
Quoted 6 lines
Important new structures introduced include:
-
mpath_head
These contain much of the multipath-specific functionality fromnvme_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.
Quoted 11 lines
-
mpath_device
This is the per-path structure, and contains much the same multipath-specific functionality innvme_nslibmultipath 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.
Quoted 10 lines · Sagi Grimberg
Quoted 6 lines
Important new structures introduced include:
-
mpath_head
These contain much of the multipath-specific functionality fromnvme_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->srcuandhead->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.
Quoted 5 lines
Quoted 5 lines
-
mpath_device
This is the per-path structure, and contains much the same multipath-specific functionality innvme_ns
Quoted 8 lines
Quoted 6 lines
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
Mike Snitzer
maintainerQuoted 21 lines · John Garry
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 fromnvme_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 innvme_ns
Quoted 6 lines
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
Quoted 25 lines · Mike Snitzer
Quoted 24 lines · John Garry
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 fromnvme_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 innvme_nslibmultipath provides functionality for path management, path selection, data path, and failover handling.
Quoted 6 lines
Quoted 3 lines
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.