File autofs-5-1-1-change-remaining-gettimeofday-to-use-clock_gettime.patch of Package autofs.6209
From: Yu Ning <ning.yu@ubuntu.com>
Subject: autofs-5.1.1 - change remaining gettimeofday() to use clock_gettime()
Git-repo: git://git.kernel.org/pub/scm/linux/storage/autofs/autofs.git
Git-commit: ea30ac244d0ed514394ab108ffe9642549f67abd
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 reamining gettimeofday() function calls to clock_gettime()
calls.
Signed-off-by: Yu Ning <ning.yu@ubuntu.com>
Signed-off-by: Ian Kent <raven@themaw.net>
Acked-by: Jeff Mahoney <jeffm@suse.com>
---
lib/rpc_subs.c | 9 ++++-----
modules/replicated.c | 30 ++++++++++++++----------------
2 files changed, 18 insertions(+), 21 deletions(-)
--- a/lib/rpc_subs.c
+++ b/lib/rpc_subs.c
@@ -1091,19 +1091,18 @@ int rpc_time(const char *host,
{
int status;
double taken;
- struct timeval start, end;
- struct timezone tz;
+ struct timespec start, end;
int proto = (ping_proto & RPC_PING_UDP) ? IPPROTO_UDP : IPPROTO_TCP;
unsigned long vers = ping_vers;
- gettimeofday(&start, &tz);
+ clock_gettime(CLOCK_MONOTONIC, &start);
status = __rpc_ping(host, vers, proto, seconds, micros, option);
- gettimeofday(&end, &tz);
+ clock_gettime(CLOCK_MONOTONIC, &end);
if (status == RPC_PING_FAIL || status < 0)
return status;
- taken = elapsed(start, end);
+ taken = monotonic_elapsed(start, end);
if (result != NULL)
*result = taken;
--- a/modules/replicated.c
+++ b/modules/replicated.c
@@ -428,8 +428,7 @@ static unsigned int get_nfs_info(unsigne
socklen_t len = INET6_ADDRSTRLEN;
char buf[len + 1];
struct pmap parms;
- struct timeval start, end;
- struct timezone tz;
+ struct timespec start, end;
unsigned int supported = 0;
double taken = 0;
int status, count = 0;
@@ -489,9 +488,9 @@ static unsigned int get_nfs_info(unsigne
supported = status;
goto done_ver;
} else if (!status) {
- gettimeofday(&start, &tz);
+ clock_gettime(CLOCK_MONOTONIC, &start);
status = rpc_ping_proto(rpc_info);
- gettimeofday(&end, &tz);
+ clock_gettime(CLOCK_MONOTONIC, &end);
if (status == -ETIMEDOUT) {
supported = status;
goto done_ver;
@@ -503,7 +502,7 @@ static unsigned int get_nfs_info(unsigne
debug(logopt,
"nfs v4 random selection time: %f", reply);
} else {
- reply = elapsed(start, end);
+ reply = monotonic_elapsed(start, end);
debug(logopt, "nfs v4 rpc ping time: %f", reply);
}
taken += reply;
@@ -548,9 +547,9 @@ v3_ver:
supported = status;
goto done_ver;
} else if (!status) {
- gettimeofday(&start, &tz);
+ clock_gettime(CLOCK_MONOTONIC, &start);
status = rpc_ping_proto(rpc_info);
- gettimeofday(&end, &tz);
+ clock_gettime(CLOCK_MONOTONIC, &end);
if (status == -ETIMEDOUT) {
supported = status;
goto done_ver;
@@ -562,7 +561,7 @@ v3_ver:
debug(logopt,
"nfs v3 random selection time: %f", reply);
} else {
- reply = elapsed(start, end);
+ reply = monotonic_elapsed(start, end);
debug(logopt, "nfs v3 rpc ping time: %f", reply);
}
taken += reply;
@@ -604,9 +603,9 @@ v2_ver:
supported = status;
goto done_ver;
} else if (!status) {
- gettimeofday(&start, &tz);
+ clock_gettime(CLOCK_MONOTONIC, &start);
status = rpc_ping_proto(rpc_info);
- gettimeofday(&end, &tz);
+ clock_gettime(CLOCK_MONOTONIC, &end);
if (status == -ETIMEDOUT)
supported = status;
else if (status > 0) {
@@ -617,7 +616,7 @@ v2_ver:
debug(logopt,
"nfs v2 random selection time: %f", reply);
} else {
- reply = elapsed(start, end);;
+ reply = monotonic_elapsed(start, end);;
debug(logopt, "nfs v2 rpc ping time: %f", reply);
}
taken += reply;
@@ -720,8 +719,7 @@ static int get_supported_ver_and_cost(un
struct conn_info pm_info, rpc_info;
int proto;
unsigned int vers;
- struct timeval start, end;
- struct timezone tz;
+ struct timespec start, end;
double taken = 0;
time_t timeout = RPC_TIMEOUT;
int status = 0;
@@ -807,16 +805,16 @@ static int get_supported_ver_and_cost(un
if (status == -EHOSTUNREACH)
goto done;
else if (!status) {
- gettimeofday(&start, &tz);
+ clock_gettime(CLOCK_MONOTONIC, &start);
status = rpc_ping_proto(&rpc_info);
- gettimeofday(&end, &tz);
+ clock_gettime(CLOCK_MONOTONIC, &end);
if (status > 0) {
if (random_selection) {
/* Random value between 0 and 1 */
taken = ((float) random())/((float) RAND_MAX+1);
debug(logopt, "random selection time %f", taken);
} else {
- taken = elapsed(start, end);
+ taken = monotonic_elapsed(start, end);
debug(logopt, "rpc ping time %f", taken);
}
}