public inbox for dm-devel@redhat.com
 help / color / mirror / Atom feed
From: Benjamin Marzinski <bmarzins@redhat.com>
To: Martin Wilck <martin.wilck@suse.com>
Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>,
	dm-devel@lists.linux.dev, Martin Wilck <mwilck@suse.com>
Subject: Re: [PATCH 12/21] libmultipath: free_multipath: fix FREE_PATHS case
Date: Thu, 18 Dec 2025 19:15:04 -0500	[thread overview]
Message-ID: <aUSZCCPwZk_qATDx@redhat.com> (raw)
In-Reply-To: <20251217212113.234959-13-mwilck@suse.com>

On Wed, Dec 17, 2025 at 10:21:04PM +0100, Martin Wilck wrote:
> free_multipath was passing FREE_PATHS to both free_pgvec() and
> free_pathvec(), which was wrong because a path could be referenced
> in both structures. This can't happen any more now, as free_pgvec()
> has lost the ability to free paths.
> 
> In general, free_multipath can't make any assumptions about whether
> a given path is referenced in mpp->paths, mpp->pg, or both. Therefore
> look first for paths that are referenced in mpp->pg but not in mpp->paths,
> clean them, and finally loop over mpp->paths.

Like I said in 07/21, I don't think we should free paths here. The paths
linked from the multipath device are also in the pathvec. We should
always be freeing them from there, so we don't have a pathvec with freed
paths.

-Ben
 
> Signed-off-by: Martin Wilck <mwilck@suse.com>
> ---
>  libmultipath/structs.c | 44 +++++++++++++++++++++++++++++-------------
>  1 file changed, 31 insertions(+), 13 deletions(-)
> 
> diff --git a/libmultipath/structs.c b/libmultipath/structs.c
> index 1ee29f6..29b62e4 100644
> --- a/libmultipath/structs.c
> +++ b/libmultipath/structs.c
> @@ -298,8 +298,12 @@ void free_multipath_attributes(struct multipath *mpp)
>  }
>  
>  void
> -free_multipath (struct multipath * mpp, enum free_path_mode free_paths)
> +free_multipath (struct multipath *mpp, enum free_path_mode free_paths)
>  {
> +	struct pathgroup *pgp;
> +	struct path *pp;
> +	int i, j;
> +
>  	if (!mpp)
>  		return;
>  
> @@ -310,22 +314,36 @@ free_multipath (struct multipath * mpp, enum free_path_mode free_paths)
>  		mpp->alias = NULL;
>  	}
>  
> -	if (free_paths == KEEP_PATHS && mpp->pg) {
> -		struct pathgroup *pgp;
> -		struct path *pp;
> -		int i, j;
> -
> -		/*
> -		 * Make sure paths carry no reference to this mpp any more
> -		 */
> -		vector_foreach_slot(mpp->pg, pgp, i) {
> -			vector_foreach_slot(pgp->paths, pp, j)
> -				if (pp->mpp == mpp)
> +	/*
> +	 * If free_paths == FREE_PATHS, free all paths.
> +	 * Otherwise, make sure no references to this mpp remain.
> +	 *
> +	 * First loop over mpp->pg and clean the paths that might
> +	 * be missing in mpp->paths. Then clean the rest
> +	 * by looping over mpp->paths.
> +	 */
> +	vector_foreach_slot(mpp->pg, pgp, i) {
> +		vector_foreach_slot(pgp->paths, pp, j) {
> +			if (find_slot(mpp->paths, pp) == -1) {
> +				if (free_paths == FREE_PATHS)
> +					free_path(pp);
> +				else
>  					pp->mpp = NULL;
> +			}
>  		}
>  	}
>  
> -	free_pathvec(mpp->paths, free_paths);
> +	vector_foreach_slot(mpp->paths, pp, i) {
> +		if (free_paths == FREE_PATHS)
> +			free_path(pp);
> +		else
> +			pp->mpp = NULL;
> +	}
> +
> +	/*
> +	 * We've freed paths above already, use KEEP_PATHS here
> +	 */
> +	free_pathvec(mpp->paths, KEEP_PATHS);
>  	free_pgvec(mpp->pg);
>  	if (mpp->hwe) {
>  		vector_free(mpp->hwe);
> -- 
> 2.52.0


  reply	other threads:[~2025-12-19  0:15 UTC|newest]

Thread overview: 33+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-17 21:20 [PATCH 00/21] Multipath-tools: various bug fixes Martin Wilck
2025-12-17 21:20 ` [PATCH 01/21] libmultipath: drop drop_multipath Martin Wilck
2025-12-17 21:20 ` [PATCH 02/21] libmultipath: don't access path members in free_pgvec() Martin Wilck
2025-12-17 21:20 ` [PATCH 03/21] multipathd: free paths in checker_finished() Martin Wilck
2025-12-18 23:34   ` Benjamin Marzinski
2025-12-18 23:40     ` Martin Wilck
2025-12-19 10:38       ` Martin Wilck
2025-12-17 21:20 ` [PATCH 04/21] libmultipath: don't touch mpvec in remove_map() Martin Wilck
2025-12-17 21:20 ` [PATCH 05/21] libmpathutil: constify find_slot() Martin Wilck
2025-12-17 21:20 ` [PATCH 06/21] libmultipath: don't free paths in orphan_paths() Martin Wilck
2025-12-17 21:20 ` [PATCH 07/21] libmultipath: free orphaned paths in check_removed_paths() Martin Wilck
2025-12-17 21:21 ` [PATCH 08/21] libmultipath: remove free_paths argument from free_pathgroup() Martin Wilck
2025-12-17 21:21 ` [PATCH 09/21] libmultipath: fix numeric value of free_paths in free_multipaths() Martin Wilck
2025-12-19  0:10   ` Benjamin Marzinski
2025-12-17 21:21 ` [PATCH 10/21] libmultipath: remove free_paths argument from free_pgvec() Martin Wilck
2025-12-17 21:21 ` [PATCH 11/21] libmultipath: remove free_paths argument from free_multipathvec() Martin Wilck
2025-12-17 21:21 ` [PATCH 12/21] libmultipath: free_multipath: fix FREE_PATHS case Martin Wilck
2025-12-19  0:15   ` Benjamin Marzinski [this message]
2025-12-17 21:21 ` [PATCH 13/21] multipath-tools: Fix ISO C23 errors with strchr() Martin Wilck
2025-12-17 21:21 ` [PATCH 14/21] libmultipath: simplify sysfs_get_target_nodename() Martin Wilck
2025-12-17 21:21 ` [PATCH 15/21] multipathd: join the init_unwinder dummy thread Martin Wilck
2025-12-17 21:21 ` [PATCH 16/21] kpartx: fix some memory leaks Martin Wilck
2025-12-17 21:21 ` [PATCH 17/21] libmpathutil: use union for bitfield Martin Wilck
2025-12-19  0:17   ` Benjamin Marzinski
2025-12-19  8:08     ` Martin Wilck
2025-12-17 21:21 ` [PATCH 18/21] libmpathutil: add wrapper code for libudev Martin Wilck
2025-12-19  0:38   ` Benjamin Marzinski
2025-12-19  8:06     ` Martin Wilck
2025-12-19 17:27       ` Benjamin Marzinski
2025-12-17 21:21 ` [PATCH 19/21] multipath-tools: use the libudev wrapper functions Martin Wilck
2025-12-17 21:21 ` [PATCH 20/21] Makefile: add functionality to determine cmocka version Martin Wilck
2025-12-17 21:21 ` [PATCH 21/21] multipath-tools tests: adaptations for cmocka 2.0 Martin Wilck
2025-12-19  0:40 ` [PATCH 00/21] Multipath-tools: various bug fixes Benjamin Marzinski

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=aUSZCCPwZk_qATDx@redhat.com \
    --to=bmarzins@redhat.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=martin.wilck@suse.com \
    --cc=mwilck@suse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox