AutoFS development
 help / color / mirror / Atom feed
From: Ian Kent <raven@themaw.net>
To: Yu Ning <ning.yu@ubuntu.com>
Cc: autofs mailing list <autofs@vger.kernel.org>
Subject: [PATCH v5 5/8] autofs-5.1.1 - use monotonic clock for indirect mount condition
Date: Fri, 18 Sep 2015 17:34:56 +0800	[thread overview]
Message-ID: <20150918093454.29311.26064.stgit@pluto.fritz.box> (raw)
In-Reply-To: <20150918092704.29311.84246.stgit@pluto.fritz.box>

From: Yu Ning <ning.yu@ubuntu.com>

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>
---
 CHANGELOG         |    1 +
 daemon/indirect.c |   20 ++++++--------------
 2 files changed, 7 insertions(+), 14 deletions(-)

diff --git a/CHANGELOG b/CHANGELOG
index 6a51fa7..63b91aa 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -22,6 +22,7 @@
 - use monotonic clock for alarm thread condition wait.
 - define pending condition init helper function.
 - use monotonic clock for direct mount condition.
+- use monotonic clock for indirect mount condition.
 
 21/04/2015 autofs-5.1.1
 =======================
diff --git a/daemon/indirect.c b/daemon/indirect.c
index bfd181d..263fff1 100644
--- a/daemon/indirect.c
+++ b/daemon/indirect.c
@@ -640,7 +640,6 @@ int handle_packet_expire_indirect(struct autofs_point *ap, autofs_packet_expire_
 	char buf[MAX_ERR_BUF];
 	pthread_t thid;
 	struct timespec wait;
-	struct timeval now;
 	int status, state;
 
 	pthread_setcancelstate(PTHREAD_CANCEL_DISABLE, &state);
@@ -658,9 +657,7 @@ int handle_packet_expire_indirect(struct autofs_point *ap, autofs_packet_expire_
 		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)
@@ -695,9 +692,8 @@ int handle_packet_expire_indirect(struct autofs_point *ap, autofs_packet_expire_
 
 	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);
@@ -799,7 +795,6 @@ int handle_packet_missing_indirect(struct autofs_point *ap, autofs_packet_missin
 	char buf[MAX_ERR_BUF];
 	struct pending_args *mt;
 	struct timespec wait;
-	struct timeval now;
 	struct mapent *me;
 	int status, state;
 
@@ -845,9 +840,7 @@ int handle_packet_missing_indirect(struct autofs_point *ap, autofs_packet_missin
 	}
 	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)
@@ -888,9 +881,8 @@ int handle_packet_missing_indirect(struct autofs_point *ap, autofs_packet_missin
 
 	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);

--
To unsubscribe from this list: send the line "unsubscribe autofs" in

  parent reply	other threads:[~2015-09-18  9:34 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-18  9:34 [PATCH v5 0/8] Series to change autofs to using a monotonic clock Ian Kent
2015-09-18  9:34 ` [PATCH v5 1/8] autofs-5.1.1 - define monotonic clock helper functions Ian Kent
2015-09-18  9:34 ` [PATCH v5 2/8] autofs-5.1.1 - use monotonic clock for alarm thread condition wait Ian Kent
2015-09-18  9:34 ` [PATCH v5 3/8] autofs-5.1.1 - define pending condition init helper function Ian Kent
2015-09-18  9:34 ` [PATCH v5 4/8] autofs-5.1.1 - use monotonic clock for direct mount condition Ian Kent
2015-09-18  9:34 ` Ian Kent [this message]
2015-09-18  9:35 ` [PATCH v5 6/8] autofs-5.1.1 - change remaining gettimeofday() to use clock_gettime() Ian Kent
2015-09-18  9:35 ` [PATCH v5 7/8] autofs-5.1.1 - change time() to use monotonic_clock() Ian Kent
2015-09-18 10:12   ` Ning Yu
2015-09-20  2:12     ` Ian Kent
2015-09-18  9:35 ` [PATCH v5 8/8] autofs-5.1.1 - remove unused function elapsed() Ian Kent
2015-09-21  5:25   ` Ning Yu
2015-09-21  8:45     ` Ian Kent
2015-09-18 10:18 ` [PATCH v5 0/8] Series to change autofs to using a monotonic clock Ning Yu
2015-09-20  2:15   ` Ian Kent

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=20150918093454.29311.26064.stgit@pluto.fritz.box \
    --to=raven@themaw.net \
    --cc=autofs@vger.kernel.org \
    --cc=ning.yu@ubuntu.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox