File autofs-5-1-1-define-monotonic-clock-helper-functions.patch of Package autofs.6209

From: Yu Ning <ning.yu@ubuntu.com>
Subject: autofs-5.1.1 - define monotonic clock helper functions
Git-repo: git://git.kernel.org/pub/scm/linux/storage/autofs/autofs.git
Git-commit: d2855a2a49e1ea15d7a728a63241abca4dd3fff6
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().

Start by defining two helper functions that will be used by later
patches.

Signed-off-by: Yu Ning <ning.yu@ubuntu.com>
Signed-off-by: Ian Kent <raven@themaw.net>
Acked-by: Jeff Mahoney <jeffm@suse.com>
---
 include/automount.h |   10 ++++++++++
 include/rpc_subs.h  |    1 +
 lib/rpc_subs.c      |   11 +++++++++++
 3 files changed, 22 insertions(+)

--- a/include/automount.h
+++ b/include/automount.h
@@ -545,6 +545,16 @@ do { \
 		fatal(_m_unlock); \
 } while(0)
 
+static inline time_t monotonic_time(time_t *t)
+{
+	struct timespec ts;
+
+	clock_gettime(CLOCK_MONOTONIC, &ts);
+	if (t)
+		*t = (time_t) ts.tv_sec;
+	return (time_t) ts.tv_sec;
+}
+
 /* Expire alarm handling routines */
 int alarm_start_handler(void);
 int alarm_add(struct autofs_point *ap, time_t seconds);
--- a/include/rpc_subs.h
+++ b/include/rpc_subs.h
@@ -71,6 +71,7 @@ int rpc_portmap_getport(struct conn_info
 int rpc_ping_proto(struct conn_info *);
 int rpc_ping(const char *, long, long, unsigned int);
 double elapsed(struct timeval, struct timeval);
+double monotonic_elapsed(struct timespec, struct timespec);
 int rpc_time(const char *, unsigned int, unsigned int, long, long, unsigned int, double *);
 const char *get_addr_string(struct sockaddr *, char *, socklen_t);
 
--- a/lib/rpc_subs.c
+++ b/lib/rpc_subs.c
@@ -1074,6 +1074,17 @@ double elapsed(struct timeval start, str
 	return t2-t1;
 }
 
+double monotonic_elapsed(struct timespec start, struct timespec end)
+{
+	double t1, t2;
+
+	t1 =  (double) start.tv_sec +
+		(double) (start.tv_nsec/(1000*1000*1000));
+	t2 =  (double) end.tv_sec +
+		(double) (end.tv_nsec/(1000*1000*1000));
+	return t2 - t1;
+}
+
 int rpc_time(const char *host,
 	     unsigned int ping_vers, unsigned int ping_proto,
 	     long seconds, long micros, unsigned int option, double *result)
openSUSE Build Service is sponsored by