upstream-queue-libmultipath: fix memory leak when iscsi login/out and "multipath -r" executed
When one iscsi device logs in and logs out with the "multipath -r" executed at the same time, memory leak happens in multipathd process.
The reason is following. When "multipath -r" is executed, the path will be free in configure function. Before path_discovery executed, iscsi device logs out. Then path_discovery will not find any path and there is no path in the gvecs->pathvec. When map_discovery function is executed, disassemble_map function will be called. Because gvecs->pathvec->slot is empty and is_deamon is 1, a path will be allocated and is not stored in gvecs->pathvec but store in mpp->pg. But when the mpp is removed and freed by remove_map function, the path will not be free and can't be find anymore.
The procedure details given as follows,
1."multipath -r" is executed
main
->child ->reconfigure ->configure ->path_discovery //after iscsi logout ->map_discovery ->update_multipath_table ->disassemble_map ->alloc_path 2.then "multipath -r" is executed again main main ->child ->reconfigure ->remove_maps_and_stop_waiters ->remove_maps
Here, we delete checking is_deamon. Because whether the process is a daemon process or not, we think the path should be add to gvecs->pathvec.
--- libmultipath/dmparser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
libmultipath/dmparser.c +1 -1
@@ -315,7 +315,7 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp, WWID_SIZE); }/* Only call this in multipath client mode */ -if (!is_daemon &&store_path (pathvec, pp)) +if (store_path (pathvec, pp)) goto out1; }else { if (!strlen(pp->wwid) &&
--
Benjamin Marzinski
maintainerQuoted 33 lines · lixiaokeng
When one iscsi device logs in and logs out with the "multipath -r" executed at the same time, memory leak happens in multipathd process.
The reason is following. When "multipath -r" is executed, the path will be free in configure function. Before
path_discoveryexecuted, iscsi device logs out. Thenpath_discoverywill not find any path and there is no path in thegvecs->pathvec. Whenmap_discoveryfunction is executed,disassemble_mapfunction will be called. Becausegvecs->pathvec->slotis empty andis_deamonis 1, a path will be allocated and is not stored ingvecs->pathvecbut store inmpp->pg. But when the mpp is removed and freed byremove_mapfunction, the path will not be free and can't be find anymore.The procedure details given as follows,
1."multipath -r" is executed
main->child ->reconfigure ->configure ->path_discovery //after iscsi logout ->map_discovery ->update_multipath_table ->disassemble_map ->alloc_path 2.then "multipath -r" is executed again main main ->child ->reconfigure ->remove_maps_and_stop_waiters ->remove_maps
Quoted 2 lines
Here, we delete checking
is_deamon. Because whether the process is a daemon process or not, we think the path should be add togvecs->pathvec.
There is more work that needs to be done to besides removing the is_daemon check. However, Martin already posted patches that deal with this as part of the his large patchset.
https://www.redhat.com/archives/dm-devel/2020-July/msg00245.html
You should take a look at those, and at my comments on them, because they should resolve your issue.
-Ben
Quoted 23 lines
Reported-by Tianxiong Li <[email protected]>Signed-off-by Lixiaokeng <[email protected]>Signed-off-by Zhiqiang Liu <[email protected]>--- libmultipath/dmparser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libmultipath/dmparser.c +1
-2@@ -315,7 +315,7 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp, WWID_SIZE); }/* Only call this in multipath client mode */ -if (!is_daemon &&store_path (pathvec, pp)) +if (store_path (pathvec, pp)) goto out1; }else { if (!strlen(pp->wwid) && --
Hi.
Thanks very much! I will try these patches.
-Lixiaokeng
Quoted 75 lines · Benjamin Marzinski
Quoted 33 lines · lixiaokeng
When one iscsi device logs in and logs out with the "multipath -r" executed at the same time, memory leak happens in multipathd process.
The reason is following. When "multipath -r" is executed, the path will be free in configure function. Before
path_discoveryexecuted, iscsi device logs out. Thenpath_discoverywill not find any path and there is no path in thegvecs->pathvec. Whenmap_discoveryfunction is executed,disassemble_mapfunction will be called. Becausegvecs->pathvec->slotis empty andis_deamonis 1, a path will be allocated and is not stored ingvecs->pathvecbut store inmpp->pg. But when the mpp is removed and freed byremove_mapfunction, the path will not be free and can't be find anymore.The procedure details given as follows,
1."multipath -r" is executed
main->child ->reconfigure ->configure ->path_discovery //after iscsi logout ->map_discovery ->update_multipath_table ->disassemble_map ->alloc_path 2.then "multipath -r" is executed again main main ->child ->reconfigure ->remove_maps_and_stop_waiters ->remove_mapsQuoted 2 lines
Here, we delete checking
is_deamon. Because whether the process is a daemon process or not, we think the path should be add togvecs->pathvec.There is more work that needs to be done to besides removing the
is_daemoncheck. However, Martin already posted patches that deal with this as part of the his large patchset.https://www.redhat.com/archives/dm-devel/2020-July/msg00245.html
You should take a look at those, and at my comments on them, because they should resolve your issue.
-Ben
Quoted 14 lines
Reported-by Tianxiong Li <[email protected]>Signed-off-by Lixiaokeng <[email protected]>Signed-off-by Zhiqiang Liu <[email protected]>--- libmultipath/dmparser.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)libmultipath/dmparser.c +0
-0libmultipath/dmparser.c int disassemble_map(vector pathvec, char *params, struct multipath *mpp,
Quoted 9 lines
libmultipath/dmparser.c +1
-2@@ -315,7 +315,7 @@ int disassemble_map(vector pathvec, char *params, struct multipath *mpp, WWID_SIZE); }/* Only call this in multipath client mode */ -if (!is_daemon &&store_path (pathvec, pp)) +if (store_path (pathvec, pp)) goto out1; }else { if (!strlen(pp->wwid) && --.