Module Name: src Committed By: manu Date: Tue Jan 13 16:51:30 UTC 2015
Modified Files: src/lib/libperfuse: ops.c Log Message: 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. To generate a diff of this commit: cvs rdiff -u -r1.81 -r1.82 src/lib/libperfuse/ops.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/lib/libperfuse/ops.c diff -u src/lib/libperfuse/ops.c:1.81 src/lib/libperfuse/ops.c:1.82 --- src/lib/libperfuse/ops.c:1.81 Wed Nov 12 05:08:43 2014 +++ src/lib/libperfuse/ops.c Tue Jan 13 16:51:30 2015 @@ -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 @@ perfuse_node_setattr_ttl(struct puffs_us } /* - * 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; - } + 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; + } - fsi->valid |= (FUSE_FATTR_MTIME|FUSE_FATTR_ATIME); + 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 @@ perfuse_node_setattr_ttl(struct puffs_us 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.