Add mpath_call_for_all_devices(), which iteratively calls a CB function
for all devices.

Signed-off-by: John Garry <[email protected]>
---
 include/linux/multipath.h |  2 ++
 lib/multipath.c           | 15 +++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/include/linux/multipath.h b/include/linux/multipath.h
index 1aa70ae11a195..153eb4c0258ef 100644
--- a/include/linux/multipath.h
+++ b/include/linux/multipath.h
@@ -153,6 +153,8 @@ void mpath_delete_device(struct mpath_head *mpath_head,
                        struct mpath_device *mpath_device);
 int mpath_call_for_device(struct mpath_head *mpath_head,
                        int (*cb)(struct mpath_device *mpath_device));
+void mpath_call_for_all_devices(struct mpath_head *mpath_head,
+                       void (*cb)(struct mpath_device *mpath_device));
 void mpath_clear_paths(struct mpath_head *mpath_head);
 void mpath_revalidate_paths(struct mpath_disk *mpath_disk,
        void (*cb)(struct mpath_device *mpath_device, sector_t capacity));
diff --git a/lib/multipath.c b/lib/multipath.c
index bba13b18215ee..96c6730680729 100644
--- a/lib/multipath.c
+++ b/lib/multipath.c
@@ -105,6 +105,21 @@ int mpath_call_for_device(struct mpath_head *mpath_head,
 }
 EXPORT_SYMBOL_GPL(mpath_call_for_device);
 
+void mpath_call_for_all_devices(struct mpath_head *mpath_head,
+                       void (*cb)(struct mpath_device *mpath_device))
+{
+       struct mpath_device *mpath_device;
+       int srcu_idx;
+
+       srcu_idx = srcu_read_lock(&mpath_head->srcu);
+       list_for_each_entry_srcu(mpath_device, &mpath_head->dev_list, siblings,
+                                srcu_read_lock_held(&mpath_head->srcu)) {
+               cb(mpath_device);
+       }
+       srcu_read_unlock(&mpath_head->srcu, srcu_idx);
+}
+EXPORT_SYMBOL_GPL(mpath_call_for_all_devices);
+
 bool mpath_clear_current_path(struct mpath_head *mpath_head,
                        struct mpath_device *mpath_device)
 {
-- 
2.43.5


Reply via email to