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

140 lines
4.0 KiB
Diff
Raw Normal View History

2020-07-16 18:51:36 +08:00
From 4ac8e63deadf125004eacbc76859cfa7a46e1e16 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 +-
multipathd/main.c | 23 ++++++++++++++++++++++-
3 files changed, 29 insertions(+), 6 deletions(-)
diff --git a/libmultipath/discovery.c b/libmultipath/discovery.c
2020-07-16 18:51:36 +08:00
index c49848e..2458bf5 100644
2020-01-10 17:13:17 +08:00
--- a/libmultipath/discovery.c
+++ b/libmultipath/discovery.c
@@ -112,7 +112,7 @@ transport (int h)
}
int
-remove_local_path (vector pathvec, struct path *pp)
+remove_local_path (vector pathvec, struct path *pp, int isfree)
{
int i = -1;
@@ -127,7 +127,9 @@ remove_local_path (vector pathvec, struct path *pp)
if ((i = find_slot(pathvec, (void *)pp)) != -1) {
vector_del_slot(pathvec, i);
}
- free_path(pp);
+ if(isfree){
+ free_path(pp);
+ }
return 0;
}
2020-07-16 18:51:36 +08:00
@@ -241,7 +243,7 @@ path_discover (vector pathvec, struct config * conf,
2020-01-10 17:13:17 +08:00
if (err == 1)
return 1;
if (err == 0)
- remove_local_path(pathvec, pp);
+ remove_local_path(pathvec, pp, 1);
return 0;
}
}
2020-07-16 18:51:36 +08:00
@@ -249,7 +251,7 @@ path_discover (vector pathvec, struct config * conf,
2020-01-10 17:13:17 +08:00
if (err)
return err;
- remove_local_path(pathvec, pp);
+ remove_local_path(pathvec, pp, 1);
return err;
}
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-07-16 18:51:36 +08:00
index 41c4258..09ea102 100644
2020-01-10 17:13:17 +08:00
--- a/multipathd/main.c
+++ b/multipathd/main.c
2020-07-16 18:51:36 +08:00
@@ -841,6 +841,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-07-16 18:51:36 +08:00
@@ -883,6 +898,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-07-16 18:51:36 +08:00
@@ -944,8 +960,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-07-16 18:51:36 +08:00
@@ -960,6 +979,7 @@ ev_add_path (struct path * pp, struct vectors * vecs, int need_do_map)
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;
}
@@ -1205,6 +1225,7 @@ out:
2020-01-10 17:13:17 +08:00
if ((i = find_slot(vecs->pathvec, (void *)pp)) != -1)
vector_del_slot(vecs->pathvec, i);
+ clear_ref_from_mpp(pp, vecs);
free_path(pp);
return retval;
--
2020-07-16 18:51:36 +08:00
1.8.3.1
2020-01-10 17:13:17 +08:00