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