Ian Kent 1cd346
autofs-5.1.1 - use monotonic clock for direct mount condition
Ian Kent 1cd346
Ian Kent 1cd346
From: Yu Ning <ning.yu@ubuntu.com>
Ian Kent 1cd346
Ian Kent 1cd346
The time returned by gettimeofday() is affected by discontinuous jumps
Ian Kent 1cd346
in the system time, so it causes an issue that autofs may not auto
Ian Kent 1cd346
unmount a mount point if system time is manually changed by the system
Ian Kent 1cd346
administrator.
Ian Kent 1cd346
Ian Kent 1cd346
To fix the issue we need to convert to using a monotonic clock source
Ian Kent 1cd346
instead of the clock source used by gettimeofday().
Ian Kent 1cd346
Ian Kent 1cd346
Change the direct mount and expire thread creation to use a monotonic
Ian Kent 1cd346
clock source.
Ian Kent 1cd346
Ian Kent 1cd346
Signed-off-by: Yu Ning <ning.yu@ubuntu.com>
Ian Kent 1cd346
Signed-off-by: Ian Kent <raven@themaw.net>
Ian Kent 1cd346
---
Ian Kent 1cd346
 CHANGELOG       |    1 +
Ian Kent 1cd346
 daemon/direct.c |   20 ++++++--------------
Ian Kent 1cd346
 2 files changed, 7 insertions(+), 14 deletions(-)
Ian Kent 1cd346
Ian Kent 1cd346
diff --git a/CHANGELOG b/CHANGELOG
Ian Kent 1cd346
index 20a64a7..e3b1f04 100644
Ian Kent 1cd346
--- a/CHANGELOG
Ian Kent 1cd346
+++ b/CHANGELOG
Ian Kent 1cd346
@@ -26,6 +26,7 @@
Ian Kent 1cd346
 - define monotonic clock helper functions.
Ian Kent 1cd346
 - use monotonic clock for alarm thread condition wait.
Ian Kent 1cd346
 - define pending condition init helper function.
Ian Kent 1cd346
+- use monotonic clock for direct mount condition.
Ian Kent 1cd346
 
Ian Kent 1cd346
 21/04/2015 autofs-5.1.1
Ian Kent 1cd346
 =======================
Ian Kent 1cd346
diff --git a/daemon/direct.c b/daemon/direct.c
Ian Kent 1cd346
index 1962a58..9b7fd76 100644
Ian Kent 1cd346
--- a/daemon/direct.c
Ian Kent 1cd346
+++ b/daemon/direct.c
Ian Kent 1cd346
@@ -1045,7 +1045,6 @@ int handle_packet_expire_direct(struct autofs_point *ap, autofs_packet_expire_di
Ian Kent 1cd346
 	char buf[MAX_ERR_BUF];
Ian Kent 1cd346
 	pthread_t thid;
Ian Kent 1cd346
 	struct timespec wait;
Ian Kent 1cd346
-	struct timeval now;
Ian Kent 1cd346
 	int status, state;
Ian Kent 1cd346
 
Ian Kent 1cd346
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
Ian Kent 1cd346
@@ -1115,9 +1114,7 @@ int handle_packet_expire_direct(struct autofs_point *ap, autofs_packet_expire_di
Ian Kent 1cd346
 		return 1;
Ian Kent 1cd346
 	}
Ian Kent 1cd346
 
Ian Kent 1cd346
-	status = pthread_cond_init(&mt->cond, NULL);
Ian Kent 1cd346
-	if (status)
Ian Kent 1cd346
-		fatal(status);
Ian Kent 1cd346
+	pending_cond_init(mt);
Ian Kent 1cd346
 
Ian Kent 1cd346
 	status = pthread_mutex_init(&mt->mutex, NULL);
Ian Kent 1cd346
 	if (status)
Ian Kent 1cd346
@@ -1163,9 +1160,8 @@ int handle_packet_expire_direct(struct autofs_point *ap, autofs_packet_expire_di
Ian Kent 1cd346
 
Ian Kent 1cd346
 	mt->signaled = 0;
Ian Kent 1cd346
 	while (!mt->signaled) {
Ian Kent 1cd346
-		gettimeofday(&now, NULL);
Ian Kent 1cd346
-		wait.tv_sec = now.tv_sec + 2;
Ian Kent 1cd346
-		wait.tv_nsec = now.tv_usec * 1000;
Ian Kent 1cd346
+		clock_gettime(CLOCK_MONOTONIC, &wait);
Ian Kent 1cd346
+		wait.tv_sec += 2;
Ian Kent 1cd346
 		status = pthread_cond_timedwait(&mt->cond, &mt->mutex, &wait);
Ian Kent 1cd346
 		if (status && status != ETIMEDOUT)
Ian Kent 1cd346
 			fatal(status);
Ian Kent 1cd346
@@ -1300,7 +1296,6 @@ int handle_packet_missing_direct(struct autofs_point *ap, autofs_packet_missing_
Ian Kent 1cd346
 	char buf[MAX_ERR_BUF];
Ian Kent 1cd346
 	int status = 0;
Ian Kent 1cd346
 	struct timespec wait;
Ian Kent 1cd346
-	struct timeval now;
Ian Kent 1cd346
 	int ioctlfd, len, state;
Ian Kent 1cd346
 	unsigned int kver_major = get_kver_major();
Ian Kent 1cd346
 	unsigned int kver_minor = get_kver_minor();
Ian Kent 1cd346
@@ -1431,9 +1426,7 @@ int handle_packet_missing_direct(struct autofs_point *ap, autofs_packet_missing_
Ian Kent 1cd346
 	}
Ian Kent 1cd346
 	memset(mt, 0, sizeof(struct pending_args));
Ian Kent 1cd346
 
Ian Kent 1cd346
-	status = pthread_cond_init(&mt->cond, NULL);
Ian Kent 1cd346
-	if (status)
Ian Kent 1cd346
-		fatal(status);
Ian Kent 1cd346
+	pending_cond_init(mt);
Ian Kent 1cd346
 
Ian Kent 1cd346
 	status = pthread_mutex_init(&mt->mutex, NULL);
Ian Kent 1cd346
 	if (status)
Ian Kent 1cd346
@@ -1482,9 +1475,8 @@ int handle_packet_missing_direct(struct autofs_point *ap, autofs_packet_missing_
Ian Kent 1cd346
 
Ian Kent 1cd346
 	mt->signaled = 0;
Ian Kent 1cd346
 	while (!mt->signaled) {
Ian Kent 1cd346
-		gettimeofday(&now, NULL);
Ian Kent 1cd346
-		wait.tv_sec = now.tv_sec + 2;
Ian Kent 1cd346
-		wait.tv_nsec = now.tv_usec * 1000;
Ian Kent 1cd346
+		clock_gettime(CLOCK_MONOTONIC, &wait);
Ian Kent 1cd346
+		wait.tv_sec += 2;
Ian Kent 1cd346
 		status = pthread_cond_timedwait(&mt->cond, &mt->mutex, &wait);
Ian Kent 1cd346
 		if (status && status != ETIMEDOUT)
Ian Kent 1cd346
 			fatal(status);