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