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