summaryrefslogtreecommitdiffstats
path: root/libglusterfs/src
diff options
context:
space:
mode:
authorKotresh HR <khiremat@redhat.com>2019-08-20 15:49:40 +0530
committerhari gowtham <hari.gowtham005@gmail.com>2019-08-28 08:31:13 +0000
commit2c46789ad04500b1e31585c6d51cd925d2ad895d (patch)
tree88756a07951de832bbd308f447b0c79a45dd76e3 /libglusterfs/src
parent6e7597e10c23aa0dea13fc4c390cb201cd22f1f7 (diff)
ctime: Fix incorrect realtime passed to frame->root->ctime
On systems that don't support "timespec_get"(e.g., centos6), it was using "clock_gettime" with "CLOCK_MONOTONIC" to get unix epoch time which is incorrect. This patch introduces "timespec_now_realtime" which uses "clock_gettime" with "CLOCK_REALTIME" which fixes the issue. Backport of: > Patch: https://review.gluster.org/23274/ > Change-Id: I57be35ce442d7e05319e82112b687eb4f28d7612 > Signed-off-by: Kotresh HR <khiremat@redhat.com> > BUG: 1743652 (cherry picked from commit d14d0749340d9cb1ef6fc4b35f2fb3015ed0339d) Change-Id: I57be35ce442d7e05319e82112b687eb4f28d7612 Signed-off-by: Kotresh HR <khiremat@redhat.com> fixes: bz#1726175
Diffstat (limited to 'libglusterfs/src')
-rw-r--r--libglusterfs/src/glusterfs/timespec.h2
-rw-r--r--libglusterfs/src/libglusterfs.sym1
-rw-r--r--libglusterfs/src/timespec.c22
3 files changed, 25 insertions, 0 deletions
diff --git a/libglusterfs/src/glusterfs/timespec.h b/libglusterfs/src/glusterfs/timespec.h
index 871871d538c..bb9ab446a5f 100644
--- a/libglusterfs/src/glusterfs/timespec.h
+++ b/libglusterfs/src/glusterfs/timespec.h
@@ -21,6 +21,8 @@
void
timespec_now(struct timespec *ts);
void
+timespec_now_realtime(struct timespec *ts);
+void
timespec_adjust_delta(struct timespec *ts, struct timespec delta);
void
timespec_sub(const struct timespec *begin, const struct timespec *end,
diff --git a/libglusterfs/src/libglusterfs.sym b/libglusterfs/src/libglusterfs.sym
index 6a10af86a23..a921b4133a9 100644
--- a/libglusterfs/src/libglusterfs.sym
+++ b/libglusterfs/src/libglusterfs.sym
@@ -1072,6 +1072,7 @@ sys_accept
tbf_init
tbf_throttle
timespec_now
+timespec_now_realtime
timespec_sub
timespec_adjust_delta
timespec_cmp
diff --git a/libglusterfs/src/timespec.c b/libglusterfs/src/timespec.c
index c01527f009a..d0d5005fbb3 100644
--- a/libglusterfs/src/timespec.c
+++ b/libglusterfs/src/timespec.c
@@ -71,6 +71,28 @@ timespec_now(struct timespec *ts)
}
void
+timespec_now_realtime(struct timespec *ts)
+{
+#if defined GF_LINUX_HOST_OS || defined GF_SOLARIS_HOST_OS || \
+ defined GF_BSD_HOST_OS
+ if (0 == clock_gettime(CLOCK_REALTIME, ts)) {
+ return;
+ }
+#endif
+
+ /* Fall back to gettimeofday()*/
+ struct timeval tv = {
+ 0,
+ };
+ if (0 == gettimeofday(&tv, NULL)) {
+ TIMEVAL_TO_TIMESPEC(&tv, ts);
+ return;
+ }
+
+ return;
+}
+
+void
timespec_adjust_delta(struct timespec *ts, struct timespec delta)
{
ts->tv_nsec = ((ts->tv_nsec + delta.tv_nsec) % 1000000000);