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@xxxxxxxx> --- libmultipath/structs.c | 19 +++++++++++++++++++ libmultipath/structs.h | 3 +++ 2 files changed, 22 insertions(+) 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 *); -- 2.44.0