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