All of lore.kernel.org
 help / color / mirror / Atom feed
From: Martin Wilck <mwilck@suse.com>
To: Benjamin Marzinski <bmarzins@redhat.com>
Cc: Bart Van Assche <Bart.VanAssche@wdc.com>,
	device-mapper development <dm-devel@redhat.com>
Subject: Re: [PATCH v2 1/7] libmultipath: fix tur checker locking
Date: Sat, 10 Feb 2018 17:03:15 +0100	[thread overview]
Message-ID: <1518278595.2937.24.camel@suse.com> (raw)
In-Reply-To: <20180210001706.GX14513@octiron.msp.redhat.com>

On Fri, 2018-02-09 at 18:17 -0600, Benjamin Marzinski wrote:
> On Sat, Feb 10, 2018 at 12:36:05AM +0100, Martin Wilck wrote:
> > On Sat, 2018-02-10 at 00:28 +0100, Martin Wilck wrote:
> > > Maybe it's easier than we thought. Attached is a patch on top of
> > > yours that I think might work, please have a look. 
> > > 
> > 
> > That one didn't even compile. This one is better.
> > 
> > Martin
> 
> So if we have this ordering
> 
> - checker calls uatomic_xchg() which returns 1 and then gets
> scheduled
> - thread calls uatomic_set() and then runs till it terminates
> - checker calls pthread_cancel()
> 
> You will get Bart's original bug. 

Yes, I realized that overnight :-( I shouldn't post stuff like this
around midnight. But I have another idea in my mind.

Martin

>  I realize that having the condlog()
> after the uatomic_set() in the thread makes this unlikely, but I
> don't
> races like this. I would be happier with simply taking the original
> code
> and moving the condlog(), if neither of my other two options are
> acceptable.
> 
> -Ben
> 
> > 
> > -- 
> > Dr. Martin Wilck <mwilck@suse.com>, Tel. +49 (0)911 74053 2107
> > SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham
> > Norton
> > HRB 21284 (AG Nürnberg)
> > From afb9c7de3658d49c4f28f6b9ee618a87b806ecdd Mon Sep 17 00:00:00
> > 2001
> > From: Martin Wilck <mwilck@suse.com>
> > Date: Sat, 10 Feb 2018 00:22:17 +0100
> > Subject: [PATCH] tur checker: make sure pthread_cancel isn't called
> > for exited
> >  thread
> > 
> > If we enter the cleanup function as the result of a pthread_cancel
> > by another
> > thread, we don't need to wait for a cancellation any more. If we
> > exit
> > regularly, just tell the other thread not to try to cancel us.
> > ---
> >  libmultipath/checkers/tur.c | 9 +++++----
> >  1 file changed, 5 insertions(+), 4 deletions(-)
> > 
> > diff --git a/libmultipath/checkers/tur.c
> > b/libmultipath/checkers/tur.c
> > index 894ad41c89c3..5d2b36bfa883 100644
> > --- a/libmultipath/checkers/tur.c
> > +++ b/libmultipath/checkers/tur.c
> > @@ -214,15 +214,13 @@ retry:
> >  
> >  static void cleanup_func(void *data)
> >  {
> > -	int running, holders;
> > +	int holders;
> >  	struct tur_checker_context *ct = data;
> >  
> > -	running = uatomic_xchg(&ct->running, 0);
> > +	uatomic_set(&ct->running, 0);
> >  	holders = uatomic_sub_return(&ct->holders, 1);
> >  	if (!holders)
> >  		cleanup_context(ct);
> > -	if (!running)
> > -		pause();
> >  }
> >  
> >  static int tur_running(struct tur_checker_context *ct)
> > @@ -266,6 +264,9 @@ static void *tur_thread(void *ctx)
> >  	pthread_cond_signal(&ct->active);
> >  	pthread_mutex_unlock(&ct->lock);
> >  
> > +	/* Tell main checker thread not to cancel us, as we exit
> > anyway */
> > +	uatomic_set(&ct->running, 0);
> > +
> >  	condlog(3, "%s: tur checker finished, state %s",
> >  		tur_devt(devt, sizeof(devt), ct),
> > checker_state_name(state));
> >  	tur_thread_cleanup_pop(ct);
> > -- 
> > 2.16.1
> > 
> 
> 

-- 
Dr. Martin Wilck <mwilck@suse.com>, Tel. +49 (0)911 74053 2107
SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton
HRB 21284 (AG Nürnberg)

--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel

  reply	other threads:[~2018-02-10 16:03 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-08 23:56 [PATCH v2 0/7] multipath: miscellaneous bug fixes Benjamin Marzinski
2018-02-08 23:56 ` [PATCH v2 1/7] libmultipath: fix tur checker locking Benjamin Marzinski
2018-02-09 16:15   ` Bart Van Assche
2018-02-09 17:26     ` Benjamin Marzinski
2018-02-09 17:42       ` Bart Van Assche
2018-02-09 20:30   ` Martin Wilck
2018-02-09 23:04     ` Benjamin Marzinski
2018-02-09 23:28       ` Martin Wilck
2018-02-09 23:36         ` Martin Wilck
2018-02-10  0:17           ` Benjamin Marzinski
2018-02-10 16:03             ` Martin Wilck [this message]
2018-02-10  0:36           ` Benjamin Marzinski
2018-02-10 16:11             ` Martin Wilck
2018-02-10 19:42               ` Martin Wilck
2018-02-12 18:44                 ` Benjamin Marzinski
2018-02-12 19:16                   ` Martin Wilck
2018-02-08 23:56 ` [PATCH v2 2/7] multipath: fix DEF_TIMEOUT use Benjamin Marzinski
2018-02-08 23:56 ` [PATCH v2 3/7] multipathd: remove coalesce_paths from ev_add_map Benjamin Marzinski
2018-02-12 20:30   ` Martin Wilck
2018-02-08 23:56 ` [PATCH v2 4/7] multipathd: remove unused configure parameter Benjamin Marzinski
2018-02-08 23:56 ` [PATCH v2 5/7] Fix set_no_path_retry() regression Benjamin Marzinski
2018-02-12 20:13   ` Martin Wilck
2018-02-08 23:56 ` [PATCH v2 6/7] multipathd: change spurious uevent msg priority Benjamin Marzinski
2018-02-08 23:56 ` [PATCH v2 7/7] multipath: print sysfs state in fast list mode Benjamin Marzinski
2018-02-12 20:33   ` Martin Wilck

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=1518278595.2937.24.camel@suse.com \
    --to=mwilck@suse.com \
    --cc=Bart.VanAssche@wdc.com \
    --cc=bmarzins@redhat.com \
    --cc=dm-devel@redhat.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.