diff mbox series

[3/8] libmultipath: add mp_find_path_by_devt()

Message ID 20240417184644.6193-4-mwilck@suse.com (mailing list archive)
State Not Applicable, archived
Delegated to: christophe varoqui
Headers show
Series multipath-tools: max_sectors_kb rework | expand

Commit Message

Martin Wilck April 17, 2024, 6:46 p.m. UTC
A helper function that searches a struct multipath by dev_t, and
works whether or not mpp->paths is currently available.

Signed-off-by: Martin Wilck <mwilck@suse.com>
---
 libmultipath/structs.c | 19 +++++++++++++++++++
 libmultipath/structs.h |  3 +++
 2 files changed, 22 insertions(+)
diff mbox series

Patch

diff --git a/libmultipath/structs.c b/libmultipath/structs.c
index 74e31a1..e248fb5 100644
--- a/libmultipath/structs.c
+++ b/libmultipath/structs.c
@@ -526,6 +526,25 @@  find_path_by_devt (const struct _vector *pathvec, const char * dev_t)
 	return NULL;
 }
 
+struct path *mp_find_path_by_devt(const struct multipath *mpp, const char *devt)
+{
+	struct path *pp;
+	struct pathgroup *pgp;
+	unsigned int i, j;
+
+	pp = find_path_by_devt(mpp->paths, devt);
+	if (pp)
+		return pp;
+
+	vector_foreach_slot (mpp->pg, pgp, i){
+		vector_foreach_slot (pgp->paths, pp, j){
+			if (!strcmp(pp->dev_t, devt))
+				return pp;
+		}
+	}
+	return NULL;
+}
+
 static int do_pathcount(const struct multipath *mpp, const int *states,
 			unsigned int nr_states)
 {
diff --git a/libmultipath/structs.h b/libmultipath/structs.h
index 734905e..a25eb9d 100644
--- a/libmultipath/structs.h
+++ b/libmultipath/structs.h
@@ -568,6 +568,9 @@  struct path * find_path_by_devt (const struct _vector *pathvec, const char *devt
 struct path * find_path_by_dev (const struct _vector *pathvec, const char *dev);
 struct path * first_path (const struct multipath *mpp);
 
+struct path *mp_find_path_by_devt(const struct multipath *mpp, const char *devt);
+
+
 int pathcount (const struct multipath *, int);
 int count_active_paths(const struct multipath *);
 int count_active_pending_paths(const struct multipath *);