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