libmultipath: find_mpe(): don't match with empty WWID
PATCH 1/2 libmultipath: find_mpe(): don't match with empty WWID
From: Martin Wilck <[email protected]>
--- libmultipath/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libmultipath/config.c +1 -1
@@ -147,7 +147,7 @@ struct mpentry *find_mpe(vector mptable, char *wwid)int i;struct mpentry * mpe; -if (!wwid) +if (!wwid || !*wwid)return NULL ;vector_foreach_slot (mptable, mpe, i)
Signature · 1 line
2.28.0
PATCH 2/2 libmultipath: copy mpp->hwe from pp->hwe
From: Martin Wilck <[email protected]>
Since f0462f0 ("libmultipath: use vector for for pp->hwe and mp->hwe"), we've been trying to fix issues caused by paths getting freed and mpp->hwe dangling. This approach couldn't work because we need mpp->hwe to persist, even if all paths are removed from the map. Before f0462f0, a simple assignment worked, because the lifetime of the hwe wasn't bound to the path. But now, we need to copy the vector. It turns out that we need to set mpp->hwe only in two places, add_map_with_path() and setup_map(), and that the code is simplified overall.
Even now, it can happen that a map is added with add_map_without_paths(), and has no paths. In that case, calling do_set_from_hwe() with a NULL pointer is not a bug, so remove the message.
--- libmultipath/configure.c | 7 +++++ libmultipath/propsel.c | 4 +-- libmultipath/structs.c | 15 +++++++++++ libmultipath/structs.h | 1 + libmultipath/structs_vec.c | 54 ++++++++++++++++---------------------- multipathd/main.c | 10 ------- 6 files changed, 46 insertions(+), 45 deletions(-)
libmultipath/configure.c +7 -0
@@ -311,6 +311,13 @@ int setup_map(struct multipath *mpp, char *params, int params_size,if (mpp->disable_queueing &&VECTOR_SIZE (mpp->paths) !=0 ) mpp->disable_queueing =0 ; +/* +* If this map was created with add_map_without_path(), +* mpp->hwe might not be set yet. +*/ +if (!mpp->hwe) +extract_hwe_from_path (mpp); +/* * properties selectors *
libmultipath/propsel.c +1 -3
@@ -65,9 +65,7 @@ do { \ __do_set_from_vec(struct hwentry, var, (src)->hwe, dest)#define do_set_from_hwe (var, src, dest, msg) \ - if (!src->hwe) { \ - condlog(0, "BUG: do_set_from_hwe called with hwe == NULL"); \ - } else if (__do_set_from_hwe(var, src, dest)) { \ + if (src->hwe && __do_set_from_hwe(var, src, dest)) { \ origin = msg; \ goto out; \ }
libmultipath/structs.c +15 -0
@@ -234,6 +234,17 @@ alloc_multipath (void)return mpp; } +void *set_mpp_hwe (struct multipath *mpp,const struct path *pp) +{ +if (!mpp || !pp || !pp->hwe) +return NULL ; +if (mpp->hwe) +return mpp->hwe; + mpp->hwe =vector_convert (NULL , pp->hwe, + struct hwentry, identity); +return mpp->hwe; +} +void free_multipath_attributes (struct multipath *mpp) {if (!mpp)
@@ -290,6 +301,10 @@ free_multipath (struct multipath * mpp, enum free_path_mode free_paths)free_pathvec (mpp->paths, free_paths);free_pgvec (mpp->pg, free_paths); +if (mpp->hwe) { +vector_free (mpp->hwe); + mpp->hwe =NULL ; + }FREE_PTR (mpp->mpcontext);FREE (mpp); }
libmultipath/structs.h +1 -0
@@ -421,6 +421,7 @@ struct host_group {struct path *alloc_path (void );struct pathgroup *alloc_pathgroup (void );struct multipath *alloc_multipath (void ); +void *set_mpp_hwe (struct multipath *mpp,const struct path *pp);void uninitialize_path (struct path *pp);void free_path (struct path *);void free_pathvec (vector vec,enum free_path_mode free_paths);
libmultipath/structs_vec.c +22 -32
109 lines not on this page · raw message
multipathd/main.c +0 -10
@@ -1153,13 +1153,6 @@ ev_remove_path (struct path *pp, struct vectors * vecs, int need_do_map)if (i !=-1 )vector_del_slot (mpp->paths, i); -/* -* Make sure mpp->hwe doesn't point to freed memory -* We call extract_hwe_from_path() below to restore mpp->hwe -*/ -if (mpp->hwe == pp->hwe) - mpp->hwe =NULL ; -/* * remove the map IF removing the last path */
@@ -1191,9 +1184,6 @@ ev_remove_path (struct path *pp, struct vectors * vecs, int need_do_map)*/ } -if (mpp->hwe ==NULL ) -extract_hwe_from_path (mpp); -if (setup_map (mpp, params,PARAMS_SIZE , vecs)) {condlog (0 ,"%s: failed to setup map for" " removal of path %s" , mpp->alias, pp->dev);
Signature · 1 line
2.28.0