All of lore.kernel.org
 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>,
	device-mapper development <dm-devel@lists.linux.dev>
Subject: Re: [PATCH 03/15] libmultipath: split out the code to wait for pending checkers
Date: Wed, 4 Sep 2024 14:16:04 -0400	[thread overview]
Message-ID: <Ztij5HLMXmw1apYh@redhat.com> (raw)
In-Reply-To: <43945011477a7fb65c6bd267c8302d91961d4c59.camel@suse.com>

On Wed, Sep 04, 2024 at 05:01:39PM +0200, Martin Wilck wrote:
> On Wed, 2024-08-28 at 18:17 -0400, Benjamin Marzinski wrote:

<snip>

> > diff --git a/libmultipath/checkers/tur.c
> > b/libmultipath/checkers/tur.c
> > index a2905af5..95af5214 100644
> > --- a/libmultipath/checkers/tur.c
> > +++ b/libmultipath/checkers/tur.c
> > @@ -323,6 +323,49 @@ static int tur_check_async_timeout(struct
> > checker *c)
> >  	return (now.tv_sec > ct->time);
> >  }
> >  
> > +int check_pending(struct checker *c, struct timespec endtime)
> > +{
> > +	struct tur_checker_context *ct = c->context;
> > +	int r, tur_status = PATH_PENDING;
> > +
> > +	pthread_mutex_lock(&ct->lock);
> > +
> > +	for (r = 0;
> > +	     r == 0 && ct->state == PATH_PENDING &&
> > +	     ct->msgid == MSG_TUR_RUNNING;
> > +	     r = pthread_cond_timedwait(&ct->active, &ct->lock,
> > &endtime));
> > +
> > +	if (!r) {
> > +		tur_status = ct->state;
> > +		c->msgid = ct->msgid;
> > +	}
> > +	pthread_mutex_unlock(&ct->lock);
> > +	if (tur_status == PATH_PENDING && c->msgid ==
> > MSG_TUR_RUNNING) {
> > +		condlog(4, "%d:%d : tur checker still running",
> > +			major(ct->devt), minor(ct->devt));
> > +	} else {
> > +		int running = uatomic_xchg(&ct->running, 0);
> > +		if (running)
> > +			pthread_cancel(ct->thread);
> > +		ct->thread = 0;
> > +	}
> > +
> > +	return tur_status;
> > +}
> > +
> > +int libcheck_pending(struct checker *c)
> > +{
> > +	struct timespec endtime;
> > +	struct tur_checker_context *ct = c->context;
> > +
> > +	/* The if path checker isn't running, just return the
> > exiting value. */
> > +	if (!ct || !ct->thread)
> > +		return c->path_state;
> > +
> > +	get_monotonic_time(&endtime);
> > +	return check_pending(c, endtime);
> 
> Does this work? 
> 
> https://pubs.opengroup.org/onlinepubs/009695299/functions/pthread_cond_timedwait.html
> says that "an error is returned [...] if the absolute time specified by
> abstime has already been passed at the time of the call".
> 
> Which would always be the case if you pass a timestamp that you 
> fetched previously unmodified, meaning that you'd always get ETIMEDOUT.
> Or am I misreading the docs?

No. You are reading the docs right.  I'm just don't understand why
that's a problem.  When you start the checker, you set a timeout that
you want to wait for, to give the checker a chance to complete in this
checker loop. Once that timeout has passed, if the thread is still
running, then libcheck_pending should return PATH_PENDING.
pthread_cond_timedwait() doesn't get called unless the thread is
running. So I would argue that pthread_cond_timedwait() always failing
once that timeout has passed is the correct thing to do.

Or are you arguing for having check_pending() manually check if the
timeout has passed, and skipping the call to pthread_cond_timedwait() in
that case? 

With the directio checker, we need to call get_events() even once our
timeout has passed, since we need to handle any async IOs that have
completed since the last call to check_pending(). But in there's no need
to call pthread_cond_timedwait() for the tur checker, so we could skip
it if we saw that the timeout had already passed. I would argue that
this is just duplicating the check from pthread_cond_timedwait() in
check_pending() for no real benfit though.

Or am I missing something here?

-Ben

> Martin
> 
> 
> 
> 
> 
> 
> 
> > +}
> > +
> >  int libcheck_check(struct checker * c)
> >  {
> >  	struct tur_checker_context *ct = c->context;
> > @@ -437,27 +480,7 @@ int libcheck_check(struct checker * c)
> >  			return tur_check(c->fd, c->timeout, &c-
> > >msgid);
> >  		}
> >  		tur_timeout(&tsp);
> > -		pthread_mutex_lock(&ct->lock);
> > -
> > -		for (r = 0;
> > -		     r == 0 && ct->state == PATH_PENDING &&
> > -			     ct->msgid == MSG_TUR_RUNNING;
> > -		     r = pthread_cond_timedwait(&ct->active, &ct-
> > >lock, &tsp));
> > -
> > -		if (!r) {
> > -			tur_status = ct->state;
> > -			c->msgid = ct->msgid;
> > -	}
> > -		pthread_mutex_unlock(&ct->lock);
> > -		if (tur_status == PATH_PENDING && c->msgid ==
> > MSG_TUR_RUNNING) {
> > -			condlog(4, "%d:%d : tur checker still
> > running",
> > -				major(ct->devt), minor(ct->devt));
> > -		} else {
> > -			int running = uatomic_xchg(&ct->running, 0);
> > -			if (running)
> > -				pthread_cancel(ct->thread);
> > -			ct->thread = 0;
> > -		}
> > +		tur_status = check_pending(c, tsp);
> >  	}
> >  
> >  	return tur_status;


  reply	other threads:[~2024-09-04 18:16 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-28 22:17 [PATCH 00/15] Yet Another path checker refactor Benjamin Marzinski
2024-08-28 22:17 ` [PATCH 01/15] libmultipath: store checker_check() result in checker struct Benjamin Marzinski
2024-09-04 16:13   ` Martin Wilck
2024-08-28 22:17 ` [PATCH 02/15] libmultipath: add missing checker function prototypes Benjamin Marzinski
2024-09-04 16:13   ` Martin Wilck
2024-08-28 22:17 ` [PATCH 03/15] libmultipath: split out the code to wait for pending checkers Benjamin Marzinski
2024-09-04 15:01   ` Martin Wilck
2024-09-04 18:16     ` Benjamin Marzinski [this message]
2024-09-04 19:48       ` Martin Wilck
2024-08-28 22:17 ` [PATCH 04/15] libmultipath: remove pending wait code from libcheck_check calls Benjamin Marzinski
2024-09-04 20:05   ` Martin Wilck
2024-09-04 21:17     ` Benjamin Marzinski
2024-09-05  7:53       ` Martin Wilck
2024-09-06 17:26         ` Benjamin Marzinski
2024-08-28 22:17 ` [PATCH 05/15] multipath-tools tests: fix up directio tests Benjamin Marzinski
2024-09-04 16:12   ` Martin Wilck
2024-09-04 18:29     ` Benjamin Marzinski
2024-09-04 19:36       ` Martin Wilck
2024-09-04 19:43         ` Martin Wilck
2024-09-04 22:53           ` Benjamin Marzinski
2024-09-05  7:57             ` Martin Wilck
2024-08-28 22:17 ` [PATCH 06/15] libmultipath: split get_state into two functions Benjamin Marzinski
2024-09-04 15:14   ` Martin Wilck
2024-09-04 18:43     ` Benjamin Marzinski
2024-08-28 22:17 ` [PATCH 07/15] libmultipath: change path_offline to path_sysfs_state Benjamin Marzinski
2024-09-04 15:31   ` Martin Wilck
2024-08-28 22:17 ` [PATCH 08/15] multipathd: split check_path_state into two functions Benjamin Marzinski
2024-08-28 22:17 ` [PATCH 09/15] multipathd: split do_checker_path Benjamin Marzinski
2024-08-28 22:17 ` [PATCH 10/15] multipathd: split check_path into two functions Benjamin Marzinski
2024-09-04 15:38   ` Martin Wilck
2024-09-04 18:51     ` Benjamin Marzinski
2024-09-05 19:02       ` Benjamin Marzinski
2024-09-06  7:45         ` Martin Wilck
2024-08-28 22:17 ` [PATCH 11/15] multipathd: split handle_uninitialized_path " Benjamin Marzinski
2024-08-28 22:17 ` [PATCH 12/15] multipathd: split check_paths " Benjamin Marzinski
2024-08-28 22:17 ` [PATCH 13/15] multipathd: update priority once after updating all paths Benjamin Marzinski
2024-09-04 15:06   ` Martin Wilck
2024-09-04 18:54     ` Benjamin Marzinski
2024-09-04 18:57   ` Martin Wilck
2024-09-04 19:51     ` Benjamin Marzinski
2024-09-04 20:14       ` Martin Wilck
2024-08-28 22:17 ` [PATCH 14/15] multipathd: remove pointless check Benjamin Marzinski
2024-09-04 16:07   ` Martin Wilck
2024-08-28 22:17 ` [PATCH 15/15] multipathd: fix deferred_failback_tick for reload removes Benjamin Marzinski
2024-09-04 16:10   ` Martin Wilck
2024-09-04 20:07 ` [PATCH 00/15] Yet Another path checker refactor 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=Ztij5HLMXmw1apYh@redhat.com \
    --to=bmarzins@redhat.com \
    --cc=christophe.varoqui@opensvc.com \
    --cc=dm-devel@lists.linux.dev \
    --cc=martin.wilck@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.