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