multipath-tools/0016-bugfix-clear-mpp-path-reference-when-path-is-freed-otherwis.patch

141 lines
4.1 KiB
Diff
Raw Normal View History

2020-11-04 21:19:44 +08:00
From dd0c8768be8605040100cf8260f6b1405c264ffe Mon Sep 17 00:00:00 2001
2020-01-10 17:13:17 +08:00
From: root <root@localhost.localdomain>
Date: Fri, 22 Mar 2019 19:48:35 +0800
Subject: [PATCH] clear mpp path reference when path is freed, otherwise double
2020-07-16 18:51:36 +08:00
free may occur in verify_paths.
2020-01-10 17:13:17 +08:00
call stack:
vecs=vecs@entry=0x557b01d62140, rpvec=rpvec@entry=0x0) at structs_vec.c:521
at main.c:574
uev=<optimized out>) at main.c:510
uev_trigger=uev_trigger@entry=0x557affdfe3d0 <uev_trigger>, trigger_data=<optimized out>)
at uevent.c:178
---
libmultipath/discovery.c | 10 ++++++----
libmultipath/discovery.h | 2 +-
2020-11-04 21:19:44 +08:00
multipathd/main.c | 24 +++++++++++++++++++++++-
3 files changed, 30 insertions(+), 6 deletions(-)
2020-01-10 17:13:17 +08:00
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
2020-11-04 21:19:44 +08:00
index 24e9b50..b5cbc88 100644
2020-01-10 17:13:17 +08:00
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
2020-11-04 21:19:44 +08:00
@@ -114,7 +114,7 @@ transport (int h)
2020-01-10 17:13:17 +08:00
}
int
-remove_local_path (vector pathvec, struct path *pp)
+remove_local_path (vector pathvec, struct path *pp, int isfree)
{
int i = -1;
2020-11-04 21:19:44 +08:00
@@ -129,7 +129,9 @@ remove_local_path (vector pathvec, struct path *pp)
2020-01-10 17:13:17 +08:00
if ((i = find_slot(pathvec, (void *)pp)) != -1) {
vector_del_slot(pathvec, i);
}
- free_path(pp);
+ if(isfree){
+ free_path(pp);
+ }
return 0;
}
2020-11-04 21:19:44 +08:00
@@ -237,7 +239,7 @@ path_discover (vector pathvec, struct config * conf,
if (err == 1)
return 1;
if (err == 0)
- remove_local_path(pathvec, pp);
+ remove_local_path(pathvec, pp, 1);
return 0;
2020-01-10 17:13:17 +08:00
}
2020-11-04 21:19:44 +08:00
else {
@@ -250,7 +252,7 @@ path_discover (vector pathvec, struct config * conf,
if (err)
return err;
- remove_local_path(pathvec, pp);
+ remove_local_path(pathvec, pp, 1);
2020-01-10 17:13:17 +08:00
return err;
2020-11-04 21:19:44 +08:00
}
2020-01-10 17:13:17 +08:00
}
diff --git a/libmultipath/discovery.h b/libmultipath/discovery.h
2020-07-16 18:51:36 +08:00
index a438b44..ab73493 100644
2020-01-10 17:13:17 +08:00
--- a/libmultipath/discovery.h
+++ b/libmultipath/discovery.h
2020-07-16 18:51:36 +08:00
@@ -56,7 +56,7 @@ int sysfs_get_asymmetric_access_state(struct path *pp,
2020-01-10 17:13:17 +08:00
char *buff, int buflen);
2020-07-16 18:51:36 +08:00
int get_uid(struct path * pp, int path_state, struct udev_device *udev,
int allow_fallback);
2020-01-10 17:13:17 +08:00
-int remove_local_path(vector pathvec, struct path *pp);
+int remove_local_path(vector pathvec, struct path *pp, int isfree);
/*
* discovery bitmask
diff --git a/multipathd/main.c b/multipathd/main.c
2020-11-04 21:19:44 +08:00
index 0b572ee..a10eba0 100644
2020-01-10 17:13:17 +08:00
--- a/multipathd/main.c
+++ b/multipathd/main.c
2020-11-04 21:19:44 +08:00
@@ -813,6 +813,21 @@ ev_remove_map (char * devname, char * alias, int minor, struct vectors * vecs)
2020-01-10 17:13:17 +08:00
return flush_map(mpp, vecs, 0);
}
+static
+void clear_ref_from_mpp(struct path * pp, struct vectors * vecs)
+{
+ struct multipath * mpp = NULL;
+ int i = -1;
+
+ mpp = find_mp_by_wwid(vecs->mpvec, pp->wwid);
+ if(!!mpp){
+ condlog(2, "%s: clear path from mpp %s", pp->dev, mpp->alias);
+ if ((i = find_slot(mpp->paths, (void *)pp)) != -1){
+ vector_del_slot(mpp->paths, i);
+ }
+ }
+}
+
static int
uev_add_path (struct uevent *uev, struct vectors * vecs, int need_do_map)
{
2020-11-04 21:19:44 +08:00
@@ -904,6 +919,7 @@ uev_add_path (struct uevent *uev, struct vectors * vecs, int need_do_map)
2020-01-10 17:13:17 +08:00
i = find_slot(vecs->pathvec, (void *)pp);
if (i != -1)
vector_del_slot(vecs->pathvec, i);
+ clear_ref_from_mpp(pp, vecs);
free_path(pp);
} else {
condlog(0, "%s: failed to reinitialize path",
2020-11-04 21:19:44 +08:00
@@ -965,8 +981,11 @@ ev_add_path (struct path * pp, struct vectors * vecs, int need_do_map)
2020-01-10 17:13:17 +08:00
int ret;
/* if pp is local path,remove it and return 0. */
- if (!remove_local_path(vecs->pathvec, pp))
+ if (!remove_local_path(vecs->pathvec, pp, 0)){
+ clear_ref_from_mpp(pp, vecs);
+ free_path(pp);
return 0;
+ }
/*
* need path UID to go any further
2020-11-04 21:19:44 +08:00
@@ -981,6 +1000,7 @@ ev_add_path (struct path * pp, struct vectors * vecs, int need_do_map)
2020-07-16 18:51:36 +08:00
int i = find_slot(vecs->pathvec, (void *)pp);
if (i != -1)
vector_del_slot(vecs->pathvec, i);
+ clear_ref_from_mpp(pp, vecs);
free_path(pp);
return 1;
}
2020-11-04 21:19:44 +08:00
@@ -1242,6 +1262,8 @@ ev_remove_path (struct path *pp, struct vectors * vecs, int need_do_map)
/* mpp == NULL */
if ((i = find_slot(vecs->pathvec, (void *)pp)) != -1)
vector_del_slot(vecs->pathvec, i);
+
+ clear_ref_from_mpp(pp, vecs);
free_path(pp);
}
out:
2020-01-10 17:13:17 +08:00
--
2020-07-16 18:51:36 +08:00
1.8.3.1
2020-01-10 17:13:17 +08:00