multipathd daemon: Fix incorrect use of CLOCK_MONOTONIC in pthread
PATCH 1/1 multipathd daemon: Fix incorrect use of CLOCK_MONOTONIC in pthread
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().
--- multipathd/cli.c | 2 +- multipathd/main.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-)
multipathd/cli.c +1 -1
@@ -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 ;
multipathd/main.c +1 -1
@@ -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);
Signature · 1 line
2.14.0
multipathd/cli.c parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout ) · line 481
Quoted 13 lines · Gris Ge
multipathd/cli.c +1
-1@@ -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.
multipathd/main.c int set_config_state(enum daemon_status state) · line 204
Quoted 13 lines
multipathd/main.c +1
-1@@ -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.
Quoted 18 lines · Bart Van Assche
multipathd/main.c int set_config_state(enum daemon_status state) · line 204
Quoted 13 lines
multipathd/main.c +1
-1@@ -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 makeconfig_conduse the monotonic clock? See alsolibmultipath/time-util.c.
Quoted 1 line
Bart.
Hi Bart,
I missed the pthread_cond_init_mono().
Will send V2 patch without this change.
Thanks.
Signature · 1 line
Gris Ge
PATCH v2 1/1 multipathd daemon: Fix incorrect use of CLOCK_MONOTONIC in pthread
In reply to Gris GeIssue:
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().
--- multipathd/cli.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
multipathd/cli.c +1 -1
@@ -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 ;
Signature · 1 line
2.14.0
multipathd/cli.c parse_cmd (char * cmd, char ** reply, int * len, void * data, int timeout ) · line 481
Quoted 13 lines · Gris Ge
multipathd/cli.c +1
-1@@ -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 ;