All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] multipathd daemon: Fix incorrect use of CLOCK_MONOTONIC in pthread
@ 2017-08-09 13:22 Gris Ge
  2017-08-09 15:03 ` Bart Van Assche
  2017-08-09 16:21 ` [PATCH V2] " Gris Ge
  0 siblings, 2 replies; 5+ messages in thread
From: Gris Ge @ 2017-08-09 13:22 UTC (permalink / raw)
  To: dm-devel; +Cc: Gris Ge

Issue:
    When multipathd is starting up, it will reply "timeout\n" immediatly
    when got any IPC command from socket. The expected way is to wait
    uxsock_timeout/1000 seconds.

Root cause:
    pthread_mutex_timedlock() are expecting a CLOCK_REALTIME time.

Fix:
    Use CLOCK_REALTIME for pthread_mutex_timedlock() and
    pthread_cond_timedwait().

Signed-off-by: Gris Ge <fge@redhat.com>
---
 multipathd/cli.c  | 2 +-
 multipathd/main.c | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/multipathd/cli.c b/multipathd/cli.c
index 32d49766..002abe61 100644
--- a/multipathd/cli.c
+++ b/multipathd/cli.c
@@ -475,7 +475,7 @@ parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout )
 	/*
 	 * execute handler
 	 */
-	if (clock_gettime(CLOCK_MONOTONIC, &tmo) == 0) {
+	if (clock_gettime(CLOCK_REALTIME, &tmo) == 0) {
 		tmo.tv_sec += timeout;
 	} else {
 		tmo.tv_sec = 0;
diff --git a/multipathd/main.c b/multipathd/main.c
index 4be2c579..67997d08 100644
--- a/multipathd/main.c
+++ b/multipathd/main.c
@@ -198,7 +198,7 @@ int set_config_state(enum daemon_status state)
 		if (running_state != DAEMON_IDLE) {
 			struct timespec ts;
 
-			clock_gettime(CLOCK_MONOTONIC, &ts);
+			clock_gettime(CLOCK_REALTIME, &ts);
 			ts.tv_sec += 1;
 			rc = pthread_cond_timedwait(&config_cond,
 						    &config_lock, &ts);
-- 
2.14.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH] multipathd daemon: Fix incorrect use of CLOCK_MONOTONIC in pthread
  2017-08-09 13:22 [PATCH] multipathd daemon: Fix incorrect use of CLOCK_MONOTONIC in pthread Gris Ge
@ 2017-08-09 15:03 ` Bart Van Assche
  2017-08-09 16:19   ` Gris Ge
  2017-08-09 16:21 ` [PATCH V2] " Gris Ge
  1 sibling, 1 reply; 5+ messages in thread
From: Bart Van Assche @ 2017-08-09 15:03 UTC (permalink / raw)
  To: dm-devel@redhat.com, fge@redhat.com

On Wed, 2017-08-09 at 21:22 +0800, Gris Ge wrote:
> diff --git a/multipathd/cli.c b/multipathd/cli.c
> index 32d49766..002abe61 100644
> --- a/multipathd/cli.c
> +++ b/multipathd/cli.c
> @@ -475,7 +475,7 @@ parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout )
>  	/*
>  	 * execute handler
>  	 */
> -	if (clock_gettime(CLOCK_MONOTONIC, &tmo) == 0) {
> +	if (clock_gettime(CLOCK_REALTIME, &tmo) == 0) {
>  		tmo.tv_sec += timeout;
>  	} else {
>  		tmo.tv_sec = 0;

Hello Gris,

This is a good catch. Thanks for this fix.

> diff --git a/multipathd/main.c b/multipathd/main.c
> index 4be2c579..67997d08 100644
> --- a/multipathd/main.c
> +++ b/multipathd/main.c
> @@ -198,7 +198,7 @@ int set_config_state(enum daemon_status state)
>  		if (running_state != DAEMON_IDLE) {
>  			struct timespec ts;
>  
> -			clock_gettime(CLOCK_MONOTONIC, &ts);
> +			clock_gettime(CLOCK_REALTIME, &ts);
>  			ts.tv_sec += 1;
>  			rc = pthread_cond_timedwait(&config_cond,
>  						    &config_lock, &ts);

But this change looks wrong to me. Have you noticed that
pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) is used to make
config_cond use the monotonic clock? See also libmultipath/time-util.c.

Bart.

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH] multipathd daemon: Fix incorrect use of CLOCK_MONOTONIC in pthread
  2017-08-09 15:03 ` Bart Van Assche
@ 2017-08-09 16:19   ` Gris Ge
  0 siblings, 0 replies; 5+ messages in thread
From: Gris Ge @ 2017-08-09 16:19 UTC (permalink / raw)
  To: Bart Van Assche; +Cc: dm-devel@redhat.com


[-- Attachment #1.1: Type: text/plain, Size: 913 bytes --]

On Wed, Aug 09, 2017 at 03:03:00PM +0000, Bart Van Assche wrote:
> > diff --git a/multipathd/main.c b/multipathd/main.c
> > index 4be2c579..67997d08 100644
> > --- a/multipathd/main.c
> > +++ b/multipathd/main.c
> > @@ -198,7 +198,7 @@ int set_config_state(enum daemon_status state)
> >  		if (running_state != DAEMON_IDLE) {
> >  			struct timespec ts;
> >  
> > -			clock_gettime(CLOCK_MONOTONIC, &ts);
> > +			clock_gettime(CLOCK_REALTIME, &ts);
> >  			ts.tv_sec += 1;
> >  			rc = pthread_cond_timedwait(&config_cond,
> >  						    &config_lock, &ts);
> 
> But this change looks wrong to me. Have you noticed that
> pthread_condattr_setclock(&attr, CLOCK_MONOTONIC) is used to make
> config_cond use the monotonic clock? See also libmultipath/time-util.c.
> 
> Bart.
Hi Bart,

I missed the pthread_cond_init_mono().
Will send V2 patch without this change.

Thanks.

-- 
Gris Ge

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

[-- Attachment #2: Type: text/plain, Size: 0 bytes --]



^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH V2] multipathd daemon: Fix incorrect use of CLOCK_MONOTONIC in pthread
  2017-08-09 13:22 [PATCH] multipathd daemon: Fix incorrect use of CLOCK_MONOTONIC in pthread Gris Ge
  2017-08-09 15:03 ` Bart Van Assche
@ 2017-08-09 16:21 ` Gris Ge
  2017-08-09 16:25   ` Bart Van Assche
  1 sibling, 1 reply; 5+ messages in thread
From: Gris Ge @ 2017-08-09 16:21 UTC (permalink / raw)
  To: dm-devel; +Cc: Gris Ge

Issue:
    When multipathd is starting up, it will reply "timeout\n" immediatly
    when got any IPC command from socket. The expected way is to wait
    uxsock_timeout/1000 seconds.

Root cause:
    pthread_mutex_timedlock() is expecting a CLOCK_REALTIME time.

Fix:
    Use CLOCK_REALTIME for pthread_mutex_timedlock().

Signed-off-by: Gris Ge <fge@redhat.com>
---
 multipathd/cli.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/multipathd/cli.c b/multipathd/cli.c
index 32d49766..002abe61 100644
--- a/multipathd/cli.c
+++ b/multipathd/cli.c
@@ -475,7 +475,7 @@ parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout )
 	/*
 	 * execute handler
 	 */
-	if (clock_gettime(CLOCK_MONOTONIC, &tmo) == 0) {
+	if (clock_gettime(CLOCK_REALTIME, &tmo) == 0) {
 		tmo.tv_sec += timeout;
 	} else {
 		tmo.tv_sec = 0;
-- 
2.14.0

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH V2] multipathd daemon: Fix incorrect use of CLOCK_MONOTONIC in pthread
  2017-08-09 16:21 ` [PATCH V2] " Gris Ge
@ 2017-08-09 16:25   ` Bart Van Assche
  0 siblings, 0 replies; 5+ messages in thread
From: Bart Van Assche @ 2017-08-09 16:25 UTC (permalink / raw)
  To: dm-devel@redhat.com, fge@redhat.com

On Thu, 2017-08-10 at 00:21 +0800, Gris Ge wrote:
> diff --git a/multipathd/cli.c b/multipathd/cli.c
> index 32d49766..002abe61 100644
> --- a/multipathd/cli.c
> +++ b/multipathd/cli.c
> @@ -475,7 +475,7 @@ parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout )
>  	/*
>  	 * execute handler
>  	 */
> -	if (clock_gettime(CLOCK_MONOTONIC, &tmo) == 0) {
> +	if (clock_gettime(CLOCK_REALTIME, &tmo) == 0) {
>  		tmo.tv_sec += timeout;
>  	} else {
>  		tmo.tv_sec = 0;

Reviewed-by: Bart Van Assche <bart.vanassche@wdc.com>

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-08-09 16:25 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-09 13:22 [PATCH] multipathd daemon: Fix incorrect use of CLOCK_MONOTONIC in pthread Gris Ge
2017-08-09 15:03 ` Bart Van Assche
2017-08-09 16:19   ` Gris Ge
2017-08-09 16:21 ` [PATCH V2] " Gris Ge
2017-08-09 16:25   ` Bart Van Assche

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.