f338ef
From fa3cc9971bf1bf4ea52edfedc0cea67a0d6990d1 Mon Sep 17 00:00:00 2001
f338ef
From: Kotresh HR <khiremat@redhat.com>
f338ef
Date: Tue, 20 Aug 2019 15:49:40 +0530
f338ef
Subject: [PATCH 281/284] ctime: Fix incorrect realtime passed to
f338ef
 frame->root->ctime
f338ef
f338ef
On systems that don't support "timespec_get"(e.g., centos6), it
f338ef
was using "clock_gettime" with "CLOCK_MONOTONIC" to get unix epoch
f338ef
time which is incorrect. This patch introduces "timespec_now_realtime"
f338ef
which uses "clock_gettime" with "CLOCK_REALTIME" which fixes
f338ef
the issue.
f338ef
f338ef
Backport of:
f338ef
 > Patch: https://review.gluster.org/23274/
f338ef
 > Change-Id: I57be35ce442d7e05319e82112b687eb4f28d7612
f338ef
 > Signed-off-by: Kotresh HR <khiremat@redhat.com>
f338ef
 > fixes: bz#1743652
f338ef
f338ef
Change-Id: I57be35ce442d7e05319e82112b687eb4f28d7612
f338ef
Signed-off-by: Kotresh HR <khiremat@redhat.com>
f338ef
BUG: 1743611
f338ef
Reviewed-on: https://code.engineering.redhat.com/gerrit/179185
f338ef
Tested-by: RHGS Build Bot <nigelb@redhat.com>
f338ef
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
f338ef
---
f338ef
 libglusterfs/src/glusterfs/timespec.h      |  2 ++
f338ef
 libglusterfs/src/libglusterfs.sym          |  1 +
f338ef
 libglusterfs/src/timespec.c                | 22 ++++++++++++++++++++++
f338ef
 xlators/features/utime/src/utime-helpers.c |  2 +-
f338ef
 4 files changed, 26 insertions(+), 1 deletion(-)
f338ef
f338ef
diff --git a/libglusterfs/src/glusterfs/timespec.h b/libglusterfs/src/glusterfs/timespec.h
f338ef
index 871871d..bb9ab44 100644
f338ef
--- a/libglusterfs/src/glusterfs/timespec.h
f338ef
+++ b/libglusterfs/src/glusterfs/timespec.h
f338ef
@@ -21,6 +21,8 @@
f338ef
 void
f338ef
 timespec_now(struct timespec *ts);
f338ef
 void
f338ef
+timespec_now_realtime(struct timespec *ts);
f338ef
+void
f338ef
 timespec_adjust_delta(struct timespec *ts, struct timespec delta);
f338ef
 void
f338ef
 timespec_sub(const struct timespec *begin, const struct timespec *end,
f338ef
diff --git a/libglusterfs/src/libglusterfs.sym b/libglusterfs/src/libglusterfs.sym
f338ef
index b161380..467a1b7 100644
f338ef
--- a/libglusterfs/src/libglusterfs.sym
f338ef
+++ b/libglusterfs/src/libglusterfs.sym
f338ef
@@ -1073,6 +1073,7 @@ sys_accept
f338ef
 tbf_init
f338ef
 tbf_throttle
f338ef
 timespec_now
f338ef
+timespec_now_realtime
f338ef
 timespec_sub
f338ef
 timespec_adjust_delta
f338ef
 timespec_cmp
f338ef
diff --git a/libglusterfs/src/timespec.c b/libglusterfs/src/timespec.c
f338ef
index c01527f..d0d5005 100644
f338ef
--- a/libglusterfs/src/timespec.c
f338ef
+++ b/libglusterfs/src/timespec.c
f338ef
@@ -71,6 +71,28 @@ timespec_now(struct timespec *ts)
f338ef
 }
f338ef
 
f338ef
 void
f338ef
+timespec_now_realtime(struct timespec *ts)
f338ef
+{
f338ef
+#if defined GF_LINUX_HOST_OS || defined GF_SOLARIS_HOST_OS ||                  \
f338ef
+    defined GF_BSD_HOST_OS
f338ef
+    if (0 == clock_gettime(CLOCK_REALTIME, ts)) {
f338ef
+        return;
f338ef
+    }
f338ef
+#endif
f338ef
+
f338ef
+    /* Fall back to gettimeofday()*/
f338ef
+    struct timeval tv = {
f338ef
+        0,
f338ef
+    };
f338ef
+    if (0 == gettimeofday(&tv, NULL)) {
f338ef
+        TIMEVAL_TO_TIMESPEC(&tv, ts);
f338ef
+        return;
f338ef
+    }
f338ef
+
f338ef
+    return;
f338ef
+}
f338ef
+
f338ef
+void
f338ef
 timespec_adjust_delta(struct timespec *ts, struct timespec delta)
f338ef
 {
f338ef
     ts->tv_nsec = ((ts->tv_nsec + delta.tv_nsec) % 1000000000);
f338ef
diff --git a/xlators/features/utime/src/utime-helpers.c b/xlators/features/utime/src/utime-helpers.c
f338ef
index 79cc014..29d9ad9 100644
f338ef
--- a/xlators/features/utime/src/utime-helpers.c
f338ef
+++ b/xlators/features/utime/src/utime-helpers.c
f338ef
@@ -17,7 +17,7 @@ gl_timespec_get(struct timespec *ts)
f338ef
 #ifdef TIME_UTC
f338ef
     timespec_get(ts, TIME_UTC);
f338ef
 #else
f338ef
-    timespec_now(ts);
f338ef
+    timespec_now_realtime(ts);
f338ef
 #endif
f338ef
 }
f338ef
 
f338ef
-- 
f338ef
1.8.3.1
f338ef