multipathd: fix mpp->hwe handling on path removal
authorMartin Wilck <mwilck@suse.com>
Mon, 25 Jun 2018 15:10:20 +0000 (17:10 +0200)
committerChristophe Varoqui <christophe.varoqui@opensvc.com>
Mon, 2 Jul 2018 09:56:20 +0000 (11:56 +0200)
In my previous patch f0462f0c8338, I overlooked that during path removal,
the path that mpp->hwe references may be removed and and thus mpp->hwe
may become stale. Fix it.

Fixes: f0462f0c8338 "libmultipath: use vector for for pp->hwe and mp->hwe"
Signed-off-by: Martin Wilck <mwilck@suse.com>
multipathd/main.c

index 72f06b5..cc493c1 100644 (file)
@@ -1076,6 +1076,14 @@ ev_remove_path (struct path *pp, struct vectors * vecs, int need_do_map)
                                mpp->alias);
                        goto fail;
                }
+
+               /*
+                * 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;
+
                if ((i = find_slot(mpp->paths, (void *)pp)) != -1)
                        vector_del_slot(mpp->paths, i);
 
@@ -1109,6 +1117,9 @@ 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);