All of lore.kernel.org
 help / color / mirror / Atom feed
From: Benjamin Marzinski <bmarzins@redhat.com>
To: Martin Wilck <mwilck@suse.com>
Cc: dm-devel@redhat.com
Subject: Re: [PATCH 17/19] libmultipath: add udev and logsink symbols
Date: Wed, 23 Sep 2020 11:05:52 -0500	[thread overview]
Message-ID: <20200923160552.GD11108@octiron.msp.redhat.com> (raw)
In-Reply-To: <3c33e8dc3355a444d58bff8d5ccc24515931c523.camel@suse.com>

On Wed, Sep 23, 2020 at 10:16:48AM +0200, Martin Wilck wrote:
> On Mon, 2020-09-21 at 15:10 -0500, Benjamin Marzinski wrote:
> > 
> > After calling libmultipath_exit(), you can never reinitialized the
> > udev
> > device.  That seems fine, but it should probably set udev to null, so
> > that future calls to libmultipath_init() don't return success. Either
> > that or multipath_init() should use a mutex instead of pthread_once()
> > to
> > avoid races, so that you can reinitialize udev after a call to
> > libmultipath_exit().
> 
> I've been thinking about this some more. It makes a lot of sense to
> move more cleanup code into libmultipath_exit() in the future; thus
> this function will do more than just clean up "udev". I believe calling
> libmultipath_exit() will become the only supported way to clean up
> libmultipath, and basically mandatory, rather sooner than later. 
> 
> The handling of "udev" is the main cause of headache, because we don't
> know whether the application wants to continue to use the variable
> after libmultipath_exit(). In libmultipath_exit(), we can't determine
> if "udev" is the symbol from libmultipath or from some other object
> file. It's also impossible to tell by the return value of udev_unref()
> whether or not it destroyed the variable. Setting udev to NULL is
> dangerous if the uevent listener thread is still running, or if the
> application needs to use the variable further.
> 
> So this is my current idea for a "robust" design:
> 
> 1. libmultipath_init() initializes udev if it's NULL; otherwise, it
>    simply takes an additional ref. IOW, applications may (but
>    don't have to) initialize and use udev before calling
>    libmultipath_init().
> 2. libmultipath_exit() calls udev_unref(udev), without nullifying it.
>    Thus applications may continue using udev afterwards, if they own an
>    additional reference.
> 3. libmultipath_init() always fails after calling libmultipath_exit().
> 4. Other libmultipath calls after libmultipath_exit() may cause
>    undefined behavior.
> 5. Normal usage would be to call libmultipath_exit() at program exit.
> 6. Calling libmultipath_init() is currently only mandatory for
>    programs that don't initialize "udev" themselves. This may change
>    in the future.
> 7. Calling libmultipath_exit() will be mandatory for programs that
>    wish to avoid memory leaks.
> 
> The only downside that I see is that the application can't test whether
> "udev" is valid by checking if it's NULL. But that's by design of
> udev_unref(). The application needs to track its own references.
> 
> There is no rigorous reason for (3.). In principle, we could just
> handle re-initialization like (1.). But I don't think it's worth the
> effort of figuring out all possible ways in which re-initialization
> could go wrong, in particular if we want to initialize more stuff
> later.
> 
> Does this make sense? 

Yeah. After I sent off my message, I realized that there's no way to
know if you dropped the last reference, which means that NULLing out
udev doesn't make sense.

-Ben

> Martin
> 

  reply	other threads:[~2020-09-23 16:05 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-16 15:36 [PATCH 00/19] multipath-tools: shutdown, libdevmapper races, globals mwilck
2020-09-16 15:37 ` [PATCH 01/19] multipathd: allow shutdown during configure() mwilck
2020-09-16 15:37 ` [PATCH 02/19] multipathd: avoid sending "READY=1" to systemd on early shutdown mwilck
2020-09-16 15:37 ` [PATCH 03/19] multipathd: send "STOPPING=1" to systemd on shutdown mwilck
2020-09-16 15:37 ` [PATCH 04/19] multipathd: send "RELOADING=1" to systemd on DAEMON_CONFIGURE state mwilck
2020-09-16 15:37 ` [PATCH 05/19] multipathd: use volatile qualifier for running_state mwilck
2020-09-16 15:37 ` [PATCH 06/19] multipathd: generalize and fix wait_for_state_change_if() mwilck
2020-09-16 15:37 ` [PATCH 07/19] multipathd: set_config_state(): avoid code duplication mwilck
2020-09-19 19:01   ` Benjamin Marzinski
2020-09-16 15:37 ` [PATCH 08/19] multipathd: cancel threads early during shutdown mwilck
2020-09-16 15:37 ` [PATCH 09/19] multipath-tools: don't call dm_lib_release() any more mwilck
2020-09-16 15:37 ` [PATCH 10/19] libmultipath: devmapper: refactor libdm version determination mwilck
2020-09-19 22:14   ` Benjamin Marzinski
2020-09-21  8:35     ` Martin Wilck
2020-09-16 15:37 ` [PATCH 11/19] libmultipath: protect racy libdevmapper calls with a mutex mwilck
2020-09-16 15:37 ` [PATCH 12/19] libmultipath: constify file argument in config parser mwilck
2020-09-16 15:37 ` [PATCH 13/19] libmultipath: provide defaults for {get, put}_multipath_config mwilck
2020-09-21 19:08   ` Benjamin Marzinski
2020-09-21 19:42     ` Martin Wilck
2020-09-16 15:37 ` [PATCH 14/19] libmpathpersist: allow using libmultipath " mwilck
2020-09-16 15:37 ` [PATCH 15/19] multipath: use {get_put}_multipath_config from libmultipath mwilck
2020-09-16 15:37 ` [PATCH 16/19] mpathpersist: use {get, put}_multipath_config() " mwilck
2020-09-16 15:37 ` [PATCH 17/19] libmultipath: add udev and logsink symbols mwilck
2020-09-21 20:10   ` Benjamin Marzinski
2020-09-23  8:16     ` Martin Wilck
2020-09-23 16:05       ` Benjamin Marzinski [this message]
2020-09-16 15:37 ` [PATCH 18/19] multipath: remove logsink and udev mwilck
2020-09-16 15:37 ` [PATCH 19/19] mpathpersist: " mwilck
2020-09-21 20:15   ` Benjamin Marzinski
2020-09-22 11:32     ` Martin Wilck
2020-09-21 20:20 ` [PATCH 00/19] multipath-tools: shutdown, libdevmapper races, globals 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=20200923160552.GD11108@octiron.msp.redhat.com \
    --to=bmarzins@redhat.com \
    --cc=dm-devel@redhat.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 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.