Linux Device Mapper development
 help / color / mirror / Atom feed
From: Martin Wilck <mwilck@suse.com>
To: Benjamin Marzinski <bmarzins@redhat.com>
Cc: device-mapper development <dm-devel@redhat.com>
Subject: Re: [PATCH 1/3] multipathd: fix waiter thread cancelling
Date: Mon, 19 Mar 2018 21:02:33 +0100	[thread overview]
Message-ID: <1521489753.3798.114.camel@suse.com> (raw)
In-Reply-To: <20180319162555.GK14513@octiron.msp.redhat.com>

On Mon, 2018-03-19 at 11:25 -0500, Benjamin Marzinski wrote:
> On Mon, Mar 19, 2018 at 01:59:24PM +0100, Martin Wilck wrote:
> > On Fri, 2018-03-16 at 16:31 -0500, Benjamin Marzinski wrote:
> > > diff --git a/multipathd/waiter.c b/multipathd/waiter.c
> > > index cb9708b..e894294 100644
> > > --- a/multipathd/waiter.c
> > > +++ b/multipathd/waiter.c
> > > @@ -23,6 +23,7 @@
> > >  #include "waiter.h"
> > >  
> > >  pthread_attr_t waiter_attr;
> > > +struct mutex_lock waiter_lock = { .mutex =
> > > PTHREAD_MUTEX_INITIALIZER
> > > };
> > >  
> > >  static struct event_thread *alloc_waiter (void)
> > >  {
> > > @@ -59,8 +60,12 @@ void stop_waiter_thread (struct multipath
> > > *mpp,
> > > struct vectors *vecs)
> > >  		mpp->waiter);
> > >  	thread = mpp->waiter;
> > >  	mpp->waiter = (pthread_t)0;
> > > -	pthread_cancel(thread);
> > > +	pthread_cleanup_push(cleanup_lock, &waiter_lock);
> > > +	lock(&waiter_lock);
> > > +	pthread_testcancel();
> > 
> > What's the purpose of this pthread_testcancel() call?
> > 
> 
> It's not necessary. I feel like in general, after you get done
> waiting
> on a lock, it's good form to see if you've been cancelled while you
> were
> waiting. However, it's really unlikely that a thread will be waiting
> here long, and this pthread_cancel isn't protecting it form accessing
> any freed data. If you think it's likely to confuse people, I have no
> problem with removing it.

My thinking was: this thread is just about to cancel another thread. If
it's cancelled itself just before doing that, the other one won't be
cancelled. I find it hard to imagine conditions where that would be the
right thing. So if at all, I'd call pthread_testcancel() after
releasing the lock. But probably it's best just to remove it here.

Regards,
Martin

-- 
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-03-19 20:02 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-03-16 21:31 [PATCH 0/3] multipathd per-device waiter fixes Benjamin Marzinski
2018-03-16 21:31 ` [PATCH 1/3] multipathd: fix waiter thread cancelling Benjamin Marzinski
2018-03-19 12:59   ` Martin Wilck
2018-03-19 16:25     ` Benjamin Marzinski
2018-03-19 20:02       ` Martin Wilck [this message]
2018-03-16 21:31 ` [PATCH 2/3] multipathd: move __setup_multipath to multipathd Benjamin Marzinski
2018-03-19 13:07   ` Martin Wilck
2018-03-16 21:31 ` [PATCH 3/3] multipathd: stop waiter in __setup_multipath Benjamin Marzinski
2018-03-19 13:08   ` 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=1521489753.3798.114.camel@suse.com \
    --to=mwilck@suse.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox