190130
From c140d30382306d08eaf2bc5c53e5be26d3e381e1 Mon Sep 17 00:00:00 2001
190130
From: Kotresh HR <khiremat@redhat.com>
190130
Date: Mon, 18 Nov 2019 05:24:33 -0500
190130
Subject: [PATCH 423/449] ctime: Fix ctime inconsisteny with utimensat
190130
190130
Problem:
190130
When touch is used to create a file, the ctime is not matching
190130
atime and mtime which ideally should match. There is a difference
190130
in nano seconds.
190130
190130
Cause:
190130
When touch is used modify atime or mtime to current time (UTIME_NOW),
190130
the current time is taken from kernel. The ctime gets updated to current
190130
time when atime or mtime is updated. But the current time to update
190130
ctime is taken from utime xlator. Hence the difference in nano seconds.
190130
190130
Fix:
190130
When utimesat uses UTIME_NOW, use the current time from kernel.
190130
190130
>fixes: bz#1773530
190130
>Change-Id: I9ccfa47dcd39df23396852b4216f1773c49250ce
190130
>Signed-off-by: Kotresh HR <khiremat@redhat.com>
190130
190130
backport of: https://review.gluster.org/#/c/glusterfs/+/23719/
190130
BUG: 1761932
190130
Change-Id: I9ccfa47dcd39df23396852b4216f1773c49250ce
190130
Signed-off-by: Kotresh HR <khiremat@redhat.com>
190130
Reviewed-on: https://code.engineering.redhat.com/gerrit/202541
190130
Tested-by: RHGS Build Bot <nigelb@redhat.com>
190130
Reviewed-by: Sunil Kumar Heggodu Gopala Acharya <sheggodu@redhat.com>
190130
---
190130
 libglusterfs/src/glusterfs/xlator.h            |  2 ++
190130
 tests/basic/ctime/ctime-utimesat.t             | 28 ++++++++++++++++++++++++++
190130
 xlators/features/utime/src/utime-gen-fops-c.py | 10 +++++++++
190130
 xlators/mount/fuse/src/fuse-bridge.c           |  8 ++++++++
190130
 4 files changed, 48 insertions(+)
190130
 create mode 100644 tests/basic/ctime/ctime-utimesat.t
190130
190130
diff --git a/libglusterfs/src/glusterfs/xlator.h b/libglusterfs/src/glusterfs/xlator.h
190130
index da551e9..db04c4d 100644
190130
--- a/libglusterfs/src/glusterfs/xlator.h
190130
+++ b/libglusterfs/src/glusterfs/xlator.h
190130
@@ -35,6 +35,8 @@
190130
 #define GF_SET_ATTR_ATIME 0x10
190130
 #define GF_SET_ATTR_MTIME 0x20
190130
 #define GF_SET_ATTR_CTIME 0x40
190130
+#define GF_ATTR_ATIME_NOW 0x80
190130
+#define GF_ATTR_MTIME_NOW 0x100
190130
 
190130
 #define gf_attr_mode_set(mode) ((mode)&GF_SET_ATTR_MODE)
190130
 #define gf_attr_uid_set(mode) ((mode)&GF_SET_ATTR_UID)
190130
diff --git a/tests/basic/ctime/ctime-utimesat.t b/tests/basic/ctime/ctime-utimesat.t
190130
new file mode 100644
190130
index 0000000..540e57a
190130
--- /dev/null
190130
+++ b/tests/basic/ctime/ctime-utimesat.t
190130
@@ -0,0 +1,28 @@
190130
+#!/bin/bash
190130
+. $(dirname $0)/../../include.rc
190130
+. $(dirname $0)/../../volume.rc
190130
+. $(dirname $0)/../../afr.rc
190130
+cleanup;
190130
+
190130
+TEST glusterd
190130
+TEST pidof glusterd
190130
+TEST $CLI volume create $V0 replica 3 $H0:$B0/${V0}{0,1,2}
190130
+TEST $CLI volume set $V0 performance.stat-prefetch off
190130
+TEST $CLI volume set $V0 performance.read-ahead off
190130
+TEST $CLI volume set $V0 performance.quick-read off
190130
+TEST $CLI volume set $V0 performance.read-after-open off
190130
+TEST $CLI volume set $V0 performance.open-behind off
190130
+TEST $CLI volume set $V0 performance.write-behind off
190130
+TEST $CLI volume set $V0 performance.io-cache off
190130
+
190130
+TEST $CLI volume start $V0
190130
+
190130
+TEST glusterfs --volfile-id=$V0 --volfile-server=$H0 --entry-timeout=0 $M0;
190130
+
190130
+touch $M0/FILE
190130
+
190130
+atime=$(stat -c "%.X" $M0/FILE)
190130
+EXPECT $atime stat -c "%.Y" $M0/FILE
190130
+EXPECT $atime stat -c "%.Z" $M0/FILE
190130
+
190130
+cleanup
190130
diff --git a/xlators/features/utime/src/utime-gen-fops-c.py b/xlators/features/utime/src/utime-gen-fops-c.py
190130
index 8730a51..9fb3e1b 100755
190130
--- a/xlators/features/utime/src/utime-gen-fops-c.py
190130
+++ b/xlators/features/utime/src/utime-gen-fops-c.py
190130
@@ -95,6 +95,16 @@ gf_utime_@NAME@ (call_frame_t *frame, xlator_t *this,
190130
                 frame->root->flags |= MDATA_CTIME;
190130
         }
190130
 
190130
+        if (valid & (GF_SET_ATTR_ATIME | GF_SET_ATTR_MTIME)) {
190130
+            if (valid & GF_ATTR_ATIME_NOW) {
190130
+                frame->root->ctime.tv_sec = stbuf->ia_atime;
190130
+                frame->root->ctime.tv_nsec = stbuf->ia_atime_nsec;
190130
+            } else if (valid & GF_ATTR_MTIME_NOW) {
190130
+                frame->root->ctime.tv_sec = stbuf->ia_mtime;
190130
+                frame->root->ctime.tv_nsec = stbuf->ia_mtime_nsec;
190130
+            }
190130
+        }
190130
+
190130
         STACK_WIND (frame, gf_utime_@NAME@_cbk, FIRST_CHILD(this),
190130
                     FIRST_CHILD(this)->fops->@NAME@, @SHORT_ARGS@);
190130
         return 0;
190130
diff --git a/xlators/mount/fuse/src/fuse-bridge.c b/xlators/mount/fuse/src/fuse-bridge.c
190130
index 6e99053..fdeec49 100644
190130
--- a/xlators/mount/fuse/src/fuse-bridge.c
190130
+++ b/xlators/mount/fuse/src/fuse-bridge.c
190130
@@ -1706,6 +1706,14 @@ fattr_to_gf_set_attr(int32_t valid)
190130
         gf_valid |= GF_SET_ATTR_CTIME;
190130
 #endif
190130
 
190130
+#if FUSE_KERNEL_MINOR_VERSION >= 9
190130
+    if (valid & FATTR_ATIME_NOW)
190130
+        gf_valid |= GF_ATTR_ATIME_NOW;
190130
+
190130
+    if (valid & FATTR_MTIME_NOW)
190130
+        gf_valid |= GF_ATTR_MTIME_NOW;
190130
+#endif
190130
+
190130
     if (valid & FATTR_SIZE)
190130
         gf_valid |= GF_SET_ATTR_SIZE;
190130
 
190130
-- 
190130
1.8.3.1
190130