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