Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libperfuse Fix atime update



details:   https://anonhg.NetBSD.org/src/rev/b0bf1fa6179e
branches:  trunk
changeset: 335556:b0bf1fa6179e
user:      manu <manu%NetBSD.org@localhost>
date:      Tue Jan 13 16:51:30 2015 +0000

description:
Fix atime update

FUSE filesystems assume that SETATTR with atime is the result of utiimes()
being called. As a result, atime and mtime will be updated.  This happens
with MooseFS and glusterFS. atime is supposed to be updated by the
filesystem itself when it gets read operations.

We fix the problem in SETATTR operations by
1) do not create a mtime update when we have an atime update (and vice
   versa), just fill the fields to avoid the filesystem restting the
   missing field to Epoch, but do not pretend we want to update it.
2) If the change is limited to atime, iscard it, as updates should be
   done by READ operations
3) Kernel part of PUFFS has been fixed to make sure reads on empty file
   are sent to the filesystem:
   http://mail-index.netbsd.org/source-changes/2015/01/13/msg062364.html

Thanks to Tom Ivar Helbekkmo for reporting this issue.

diffstat:

 lib/libperfuse/ops.c |  53 ++++++++++++++++++++++++++++-----------------------
 1 files changed, 29 insertions(+), 24 deletions(-)

diffs (75 lines):

diff -r 76f8c9a9e63a -r b0bf1fa6179e lib/libperfuse/ops.c
--- a/lib/libperfuse/ops.c      Tue Jan 13 16:39:51 2015 +0000
+++ b/lib/libperfuse/ops.c      Tue Jan 13 16:51:30 2015 +0000
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.81 2014/11/12 05:08:43 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.82 2015/01/13 16:51:30 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -1785,30 +1785,27 @@
        }
 
        /*
-        * Setting mtime without atime or vice versa leads to
-        * dates being reset to Epoch on glusterfs. If one
-        * is missing, use the old value.
+        * When not sending a time field, still fill with
+        * current value, as the filesystem may just reset
+        * the field to Epoch even if fsi->valid bit is
+        * not set (GlusterFS does that).
         */
-       if ((vap->va_mtime.tv_sec != (time_t)PUFFS_VNOVAL) || 
-           (vap->va_atime.tv_sec != (time_t)PUFFS_VNOVAL)) {
-               
-               if (vap->va_atime.tv_sec != (time_t)PUFFS_VNOVAL) {
-                       fsi->atime = vap->va_atime.tv_sec;
-                       fsi->atimensec = (uint32_t)vap->va_atime.tv_nsec;
-               } else {
-                       fsi->atime = old_va->va_atime.tv_sec;
-                       fsi->atimensec = (uint32_t)old_va->va_atime.tv_nsec;
-               }
-
-               if (vap->va_mtime.tv_sec != (time_t)PUFFS_VNOVAL) {
-                       fsi->mtime = vap->va_mtime.tv_sec;
-                       fsi->mtimensec = (uint32_t)vap->va_mtime.tv_nsec;
-               } else {
-                       fsi->mtime = old_va->va_mtime.tv_sec;
-                       fsi->mtimensec = (uint32_t)old_va->va_mtime.tv_nsec;
-               }
-
-               fsi->valid |= (FUSE_FATTR_MTIME|FUSE_FATTR_ATIME);
+       if (vap->va_atime.tv_sec != (time_t)PUFFS_VNOVAL) {
+               fsi->atime = vap->va_atime.tv_sec;
+               fsi->atimensec = (uint32_t)vap->va_atime.tv_nsec;
+               fsi->valid |= FUSE_FATTR_ATIME;
+       } else {
+               fsi->atime = old_va->va_atime.tv_sec;
+               fsi->atimensec = (uint32_t)old_va->va_atime.tv_nsec;
+       }
+
+       if (vap->va_mtime.tv_sec != (time_t)PUFFS_VNOVAL) {
+               fsi->mtime = vap->va_mtime.tv_sec;
+               fsi->mtimensec = (uint32_t)vap->va_mtime.tv_nsec;
+               fsi->valid |= FUSE_FATTR_MTIME;
+       } else {
+               fsi->mtime = old_va->va_mtime.tv_sec;
+               fsi->mtimensec = (uint32_t)old_va->va_mtime.tv_nsec;
        }
 
        if (vap->va_mode != (mode_t)PUFFS_VNOVAL) {
@@ -1851,6 +1848,14 @@
                fsi->mtimensec = 0;
                fsi->valid &= ~(FUSE_FATTR_ATIME|FUSE_FATTR_MTIME);
        }
+
+       /*
+        * If only atime is changed, discard the operation: it
+        * happens after read, and in that case the filesystem 
+        * already updaed atime. NB: utimes() also change mtime.
+        */
+       if (fsi->valid == FUSE_FATTR_ATIME)
+               fsi->valid &= ~FUSE_FATTR_ATIME;
                    
        /*
         * If nothing remain, discard the operation.



Home | Main Index | Thread Index | Old Index