monotonic time for mount.cifs timeouts

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

attached are patches to spot the clock_gettime function and to use that and the
monotonic clock for timeout handling if possible.

If there are no objections, can you please apply them, Jeff?

Thanks
Björn
From 250d5b5df23d93ebed66a4c39bccf3a3614c54ad Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Jacke?= <bj@xxxxxxxxx>
Date: Tue, 24 Aug 2010 09:39:32 +0200
Subject: [PATCH 1/2] autoconf: add checks for clock_gettime

---
 configure.ac |   10 ++++++++++
 1 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/configure.ac b/configure.ac
index c7d420d..7f82cd6 100644
--- a/configure.ac
+++ b/configure.ac
@@ -110,6 +110,16 @@ AC_FUNC_STRNLEN
 # check for required functions
 AC_CHECK_FUNCS([alarm atexit endpwent getmntent getpass gettimeofday inet_ntop memset realpath setenv strchr strcmp strdup strerror strncasecmp strndup strpbrk strrchr strstr strtol strtoul tolower uname], , [AC_MSG_ERROR([necessary functions(s) not found])])
 
+AC_CHECK_FUNCS(clock_gettime, [], [
+  AC_CHECK_LIB(rt, clock_gettime, [
+      AC_DEFINE(HAVE_CLOCK_GETTIME, 1)
+	AC_DEFINE(HAVE_CLOCK_GETTIME,1,
+		[Whether the clock_gettime func is there])
+      LIBS="$LIBS -lrt"
+        ])
+  ])
+
+
 # ugly, but I'm not sure how to check for functions in a library that's not in $LIBS
 cu_saved_libs=$LIBS
 LIBS="$LIBS $KRB5_LDADD"
-- 
1.7.1

From 4e8d243b9b0a5eb7bf4619c4cddbd9d3a8f4eb2d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Jacke?= <bj@xxxxxxxxx>
Date: Tue, 24 Aug 2010 09:41:01 +0200
Subject: [PATCH 2/2] mount.cifs: use monotonic time for timeouts

this is especially important during the boot process, where the clock is often
being set initially and clock jumps are more common.
---
 mtab.c |   23 ++++++++++++++++++++---
 1 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/mtab.c b/mtab.c
index de1aabd..64e7250 100644
--- a/mtab.c
+++ b/mtab.c
@@ -39,6 +39,7 @@
 #include <stdlib.h>
 #include <signal.h>
 #include "mount.h"
+#include "config.h"
 
 
 /* Updating mtab ----------------------------------------------*/
@@ -60,6 +61,22 @@ setlkw_timeout (int sig __attribute__((unused))) {
      /* nothing, fcntl will fail anyway */
 }
 
+/* use monotonic time for timeouts */
+struct timeval
+mono_time(void) {
+	struct timeval ret;
+#if defined(HAVE_CLOCK_GETTIME) && defined(CLOCK_MONOTONIC)
+	struct timespec ts;
+	if (clock_gettime(CLOCK_MONOTONIC, &ts) == 0) {
+		ret.tv_sec = ts.tv_sec;
+		ret.tv_usec = ts.tv_nsec/1000;
+		return ret;
+	}
+#endif
+	gettimeofday(&ret,NULL);
+	return ret;
+}
+
 /* Remove lock file.  */
 void
 unlock_mtab (void) {
@@ -150,7 +167,7 @@ lock_mtab (void) {
 	}
 	close(i);
 
-	gettimeofday(&maxtime, NULL);
+	maxtime = mono_time();
 	maxtime.tv_sec += MOUNTLOCK_MAXTIME;
 
 	waittime.tv_sec = 0;
@@ -177,7 +194,7 @@ lock_mtab (void) {
 
 		if (lockfile_fd < 0) {
 			/* Strange... Maybe the file was just deleted? */
-			gettimeofday(&now, NULL);
+			now = mono_time();
 			if (errno == ENOENT && now.tv_sec < maxtime.tv_sec) {
 				we_created_lockfile = 0;
 				continue;
@@ -199,7 +216,7 @@ lock_mtab (void) {
 			(void) unlink(linktargetfile);
 		} else {
 			/* Someone else made the link. Wait. */
-			gettimeofday(&now, NULL);
+			now = mono_time();
 			if (now.tv_sec < maxtime.tv_sec) {
 				alarm(maxtime.tv_sec - now.tv_sec);
 				if (fcntl (lockfile_fd, F_SETLKW, &flock) == -1) {
-- 
1.7.1

Attachment: pgpOvglJSfKVn.pgp
Description: PGP signature


[Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux