All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Marzinski <bmarzins@redhat.com>
To: Martin Wilck <mwilck@suse.com>
Cc: Christophe Varoqui <christophe.varoqui@opensvc.com>,
	dm-devel@lists.linux.dev, Benjamin Marzinski <bmarzins@suse.com>
Subject: Re: [PATCH v2 14/26] multipathd: add_map_without_path(): orphan paths instead of freeing them
Date: Mon, 5 Jan 2026 18:17:53 -0500	[thread overview]
Message-ID: <aVxGoTt8zHbnmGXI@redhat.com> (raw)
In-Reply-To: <f74331bcf74067f85a8836e014d322eccf2995ed.camel@suse.com>

On Mon, Jan 05, 2026 at 04:15:37PM +0100, Martin Wilck wrote:
> On Fri, 2025-12-19 at 23:23 -0500, Benjamin Marzinski wrote:
> > On Fri, Dec 19, 2025 at 03:40:56PM +0100, Martin Wilck wrote:
> > > If add_map_without_path() fails to set up the multipath data
> > > structures,
> > > don't free the paths associated with the map as
> > > cleanup_multipath_and_paths() would; just orphan the paths.
> > > update_pathvec_from_dm() will handle the paths and see if they
> > > need to be removed.
> > > 
> > > Suggested-by: Benjamin Marzinski <bmarzins@suse.com>
> > > Signed-off-by: Martin Wilck <mwilck@suse.com>
> > > ---
> > >  multipathd/main.c | 12 +++++++-----
> > >  1 file changed, 7 insertions(+), 5 deletions(-)
> > > 
> > > diff --git a/multipathd/main.c b/multipathd/main.c
> > > index c03546b..7b522e8 100644
> > > --- a/multipathd/main.c
> > > +++ b/multipathd/main.c
> > > @@ -771,8 +771,8 @@ fail:
> > >  
> > >  static int add_map_without_path (struct vectors *vecs, const char
> > > *alias)
> > >  {
> > > -	struct multipath
> > > __attribute__((cleanup(cleanup_multipath_and_paths)))
> > > -		*mpp = alloc_multipath();
> > > +	struct multipath
> > > __attribute__((cleanup(cleanup_multipath))) *mpp =
> > > +		alloc_multipath();
> > >  	char __attribute__((cleanup(cleanup_charp))) *params =
> > > NULL;
> > >  	char __attribute__((cleanup(cleanup_charp))) *status =
> > > NULL;
> > >  	struct config *conf;
> > > @@ -802,11 +802,13 @@ static int add_map_without_path (struct
> > > vectors *vecs, const char *alias)
> > >  	mpp->mpe = find_mpe(conf->mptable, mpp->wwid);
> > >  	put_multipath_config(conf);
> > >  
> > > -	if ((rc = update_multipath_table__(mpp, vecs->pathvec, 0,
> > > params, status)) != DMP_OK)
> > > +	if (update_multipath_table__(mpp, vecs->pathvec, 0,
> > > params, status) != DMP_OK ||
> > > +	    !vector_alloc_slot(vecs->mpvec)) {
> > > +		orphan_paths(vecs->pathvec, mpp, "failed to add
> > > map");
> > >  		return DMP_ERR;
> > 
> > I'm not sure we should just call orphan_paths() after we call
> > update_multipath_table__(). If we hit a cancellation point in the
> > middle
> > of update_multipath_table__(), we want to fully orphan any paths that
> > got added to the device before we cancelled.  
> 
> Sorry, I don't understand.
> 
> The __attribute__((cleanup())) functions don't protect against thread
> cancellation. If we want to achieve what you describe, we must add a
> pthread_cleanup_push()/pop() pair around the update_multipath_table__()
> call.

I'm pretty sure they do run during cancellation after I added ca957f2a
("multipath-tools: Makefile.inc: compile with -fexceptions").
 
> But would that buy us anything? update_multipath_table__() only
> manipulates multipathd's internal data structures, which, if a
> cancellation happens, will almost immediately all be freed anyway. What
> harm would be done if these paths weren't orphaned in such a case? Yes,
> the some paths might now link to a non-existing struct multipath. I'd
> see your point if we accessed pp->mpp in the path-freeing code path,
> but we don't do this any more.

We check whether pp->mpp is set in lots of places in the code to decide
what to do with the paths. But you are correct that we don't ever call
add_map_without_path() from a thread that can be cancelled and have
multipathd continue running, and we aren't likely to do so.

> > Perhaps the easiest way to
> > solve this is to make cleanup_multipath_and_paths() loop through all
> > the
> > path in mpp->pg and orphan them before calling free_multipath().
> 
> Like I said above, that would have no effect in the case of
> cancellation.
> 
> I can add pthread_cleanup_push()/pop() pair if you insist, but so far I
> don't see the benefit.

Sure. I drop my objection.

Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>

> Regards
> Martin


  reply	other threads:[~2026-01-05 23:18 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-12-19 14:40 [PATCH v2 00/26] Multipath-tools: various bug fixes Martin Wilck
2025-12-19 14:40 ` [PATCH v2 01/26] libmultipath: drop drop_multipath Martin Wilck
2025-12-19 14:40 ` [PATCH v2 02/26] libmultipath: don't access path members in free_pgvec() Martin Wilck
2025-12-19 14:40 ` [PATCH v2 03/26] libmpathutil: constify find_slot() Martin Wilck
2025-12-19 14:40 ` [PATCH v2 04/26] libmultipath: don't touch mpvec in remove_map() Martin Wilck
2025-12-19 14:40 ` [PATCH v2 05/26] libmultipath: export orphan_paths() Martin Wilck
2025-12-19 14:40 ` [PATCH v2 06/26] libmultipath: export cleanup_multipath() Martin Wilck
2025-12-19 14:40 ` [PATCH v2 07/26] libmultipath: add cleanup_pathvec_and_free_paths() Martin Wilck
2025-12-19 14:40 ` [PATCH v2 08/26] libmultipath: don't free paths in orphan_paths() Martin Wilck
2025-12-19 14:40 ` [PATCH v2 09/26] multipathd: free orphaned paths in checker_finished() Martin Wilck
2025-12-19 14:40 ` [PATCH v2 10/26] libmultipath: remove free_paths argument from free_pathgroup() Martin Wilck
2025-12-19 14:40 ` [PATCH v2 11/26] libmultipath: remove free_paths argument from free_pgvec() Martin Wilck
2025-12-19 14:40 ` [PATCH v2 12/26] libmultipath: remove free_paths argument from free_multipathvec() Martin Wilck
2025-12-19 14:40 ` [PATCH v2 13/26] multipath: free paths through pathvec in check_usable_paths() Martin Wilck
2025-12-20  4:19   ` Benjamin Marzinski
2026-01-05 14:38     ` Martin Wilck
2025-12-19 14:40 ` [PATCH v2 14/26] multipathd: add_map_without_path(): orphan paths instead of freeing them Martin Wilck
2025-12-19 14:46   ` Martin Wilck
2025-12-20  4:23   ` Benjamin Marzinski
2026-01-05 15:15     ` Martin Wilck
2026-01-05 23:17       ` Benjamin Marzinski [this message]
2026-01-06 10:31         ` Martin Wilck
2025-12-19 14:40 ` [PATCH v2 15/26] libmultipath: remove free_paths argument from free_multipath() Martin Wilck
2025-12-19 14:40 ` [PATCH v2 16/26] libmultipath: remove cleanup_multipath_and_paths() Martin Wilck
2025-12-20  4:26   ` Benjamin Marzinski
2025-12-19 14:40 ` [PATCH v2 17/26] libmultipaths: annotate functions that may free paths Martin Wilck
2025-12-20  4:35   ` Benjamin Marzinski
2025-12-19 14:41 ` [PATCH v2 18/26] multipath-tools: Fix ISO C23 errors with strchr() Martin Wilck
2025-12-19 14:41 ` [PATCH v2 19/26] libmultipath: simplify sysfs_get_target_nodename() Martin Wilck
2025-12-19 14:41 ` [PATCH v2 20/26] multipathd: join the init_unwinder dummy thread Martin Wilck
2025-12-19 14:41 ` [PATCH v2 21/26] kpartx: fix some memory leaks Martin Wilck
2025-12-19 14:41 ` [PATCH v2 22/26] libmpathutil: use union for bitfield Martin Wilck
2025-12-19 14:41 ` [PATCH v2 23/26] libmpathutil: add wrapper code for libudev Martin Wilck
2025-12-19 14:41 ` [PATCH v2 24/26] multipath-tools: use the libudev wrapper functions Martin Wilck
2025-12-19 14:41 ` [PATCH v2 25/26] Makefile: add functionality to determine cmocka version Martin Wilck
2025-12-19 14:41 ` [PATCH v2 26/26] multipath-tools tests: adaptations for cmocka 2.0 Martin Wilck
2025-12-20  4:41 ` [PATCH v2 00/26] 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=aVxGoTt8zHbnmGXI@redhat.com \
    --to=bmarzins@redhat.com \
    --cc=bmarzins@suse.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@lists.linux.dev \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.