File autofs-5-1-1-use-monotonic-clock-for-indirect-mount-condition.patch of Package autofs.6209
From: Yu Ning <ning.yu@ubuntu.com>
Subject: autofs-5.1.1 - use monotonic clock for indirect mount condition
Git-repo: git://git.kernel.org/pub/scm/linux/storage/autofs/autofs.git
Git-commit: 5e73b84d5260d9a7c1b8c045c4674dbc30ab1c2f
Patch-mainline: 5.1.2
References: bsc#1046493
The time returned by gettimeofday() is affected by discontinuous jumps
in the system time, so it causes an issue that autofs may not auto
unmount a mount point if system time is manually changed by the system
administrator.
To fix the issue we need to convert to using a monotonic clock source
instead of the clock source used by gettimeofday().
Change the indirect mount and expire thread creation to use a monotonic
clock source.
Signed-off-by: Yu Ning <ning.yu@ubuntu.com>
Signed-off-by: Ian Kent <raven@themaw.net>
Acked-by: Jeff Mahoney <jeffm@suse.com>
---
daemon/indirect.c | 20 ++++++--------------
1 file changed, 6 insertions(+), 14 deletions(-)
--- a/daemon/indirect.c
+++ b/daemon/indirect.c
@@ -638,7 +638,6 @@ int handle_packet_expire_indirect(struct
char buf[MAX_ERR_BUF];
pthread_t thid;
struct timespec wait;
- struct timeval now;
int status, state;
pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
@@ -656,9 +655,7 @@ int handle_packet_expire_indirect(struct
return 1;
}
- status = pthread_cond_init(&mt->cond, NULL);
- if (status)
- fatal(status);
+ pending_cond_init(mt);
status = pthread_mutex_init(&mt->mutex, NULL);
if (status)
@@ -693,9 +690,8 @@ int handle_packet_expire_indirect(struct
mt->signaled = 0;
while (!mt->signaled) {
- gettimeofday(&now, NULL);
- wait.tv_sec = now.tv_sec + 2;
- wait.tv_nsec = now.tv_usec * 1000;
+ clock_gettime(CLOCK_MONOTONIC, &wait);
+ wait.tv_sec += 2;
status = pthread_cond_timedwait(&mt->cond, &mt->mutex, &wait);
if (status && status != ETIMEDOUT)
fatal(status);
@@ -797,7 +793,6 @@ int handle_packet_missing_indirect(struc
char buf[MAX_ERR_BUF];
struct pending_args *mt;
struct timespec wait;
- struct timeval now;
struct mapent *me;
int status, state;
@@ -843,9 +838,7 @@ int handle_packet_missing_indirect(struc
}
memset(mt, 0, sizeof(struct pending_args));
- status = pthread_cond_init(&mt->cond, NULL);
- if (status)
- fatal(status);
+ pending_cond_init(mt);
status = pthread_mutex_init(&mt->mutex, NULL);
if (status)
@@ -886,9 +879,8 @@ int handle_packet_missing_indirect(struc
mt->signaled = 0;
while (!mt->signaled) {
- gettimeofday(&now, NULL);
- wait.tv_sec = now.tv_sec + 2;
- wait.tv_nsec = now.tv_usec * 1000;
+ clock_gettime(CLOCK_MONOTONIC, &wait);
+ wait.tv_sec += 2;
status = pthread_cond_timedwait(&mt->cond, &mt->mutex, &wait);
if (status && status != ETIMEDOUT)
fatal(status);