Mon Nov 20 17:00:36 2017 UTC ()
When truncating a file make sure to update mtime.
This fixes PR kern/51762 for rumpfs.


(martin)
diff -r1.151 -r1.152 src/sys/rump/librump/rumpvfs/rumpfs.c

cvs diff -r1.151 -r1.152 src/sys/rump/librump/rumpvfs/rumpfs.c (expand / switch to unified diff)

--- src/sys/rump/librump/rumpvfs/rumpfs.c 2017/11/20 00:01:05 1.151
+++ src/sys/rump/librump/rumpvfs/rumpfs.c 2017/11/20 17:00:35 1.152
@@ -1,14 +1,14 @@ @@ -1,14 +1,14 @@
1/* $NetBSD: rumpfs.c,v 1.151 2017/11/20 00:01:05 christos Exp $ */ 1/* $NetBSD: rumpfs.c,v 1.152 2017/11/20 17:00:35 martin Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 2009, 2010, 2011 Antti Kantee. All Rights Reserved. 4 * Copyright (c) 2009, 2010, 2011 Antti Kantee. All Rights Reserved.
5 * 5 *
6 * Redistribution and use in source and binary forms, with or without 6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions 7 * modification, are permitted provided that the following conditions
8 * are met: 8 * are met:
9 * 1. Redistributions of source code must retain the above copyright 9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer. 10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright 11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the 12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution. 13 * documentation and/or other materials provided with the distribution.
14 * 14 *
@@ -16,27 +16,27 @@ @@ -16,27 +16,27 @@
16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 16 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE. 25 * SUCH DAMAGE.
26 */ 26 */
27 27
28#include <sys/cdefs.h> 28#include <sys/cdefs.h>
29__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.151 2017/11/20 00:01:05 christos Exp $"); 29__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.152 2017/11/20 17:00:35 martin Exp $");
30 30
31#include <sys/param.h> 31#include <sys/param.h>
32#include <sys/atomic.h> 32#include <sys/atomic.h>
33#include <sys/buf.h> 33#include <sys/buf.h>
34#include <sys/dirent.h> 34#include <sys/dirent.h>
35#include <sys/errno.h> 35#include <sys/errno.h>
36#include <sys/filedesc.h> 36#include <sys/filedesc.h>
37#include <sys/fcntl.h> 37#include <sys/fcntl.h>
38#include <sys/kauth.h> 38#include <sys/kauth.h>
39#include <sys/malloc.h> 39#include <sys/malloc.h>
40#include <sys/module.h> 40#include <sys/module.h>
41#include <sys/mount.h> 41#include <sys/mount.h>
42#include <sys/namei.h> 42#include <sys/namei.h>
@@ -896,38 +896,41 @@ rump_vop_setattr(void *v) @@ -896,38 +896,41 @@ rump_vop_setattr(void *v)
896 CHANGED(va_birthtime.tv_sec, time_t) || 896 CHANGED(va_birthtime.tv_sec, time_t) ||
897 CHANGED(va_atime.tv_nsec, long) || 897 CHANGED(va_atime.tv_nsec, long) ||
898 CHANGED(va_ctime.tv_nsec, long) || 898 CHANGED(va_ctime.tv_nsec, long) ||
899 CHANGED(va_mtime.tv_nsec, long) || 899 CHANGED(va_mtime.tv_nsec, long) ||
900 CHANGED(va_birthtime.tv_nsec, long)) { 900 CHANGED(va_birthtime.tv_nsec, long)) {
901 error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_TIMES, vp, 901 error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_TIMES, vp,
902 NULL, genfs_can_chtimes(vp, vap->va_vaflags, attr->va_uid, 902 NULL, genfs_can_chtimes(vp, vap->va_vaflags, attr->va_uid,
903 cred)); 903 cred));
904 if (error) 904 if (error)
905 return error; 905 return error;
906 } 906 }
907 907
908 int flags = 0; 908 int flags = 0;
 909 getnanotime(&now);
909 if (vap->va_atime.tv_sec != VNOVAL) 910 if (vap->va_atime.tv_sec != VNOVAL)
910 if (!(vp->v_mount->mnt_flag & MNT_NOATIME)) 911 if (!(vp->v_mount->mnt_flag & MNT_NOATIME))
911 flags |= RUMPFS_ACCESS; 912 flags |= RUMPFS_ACCESS;
912 if (vap->va_mtime.tv_sec != VNOVAL) { 913 if (vap->va_mtime.tv_sec != VNOVAL) {
913 flags |= RUMPFS_CHANGE | RUMPFS_MODIFY; 914 flags |= RUMPFS_CHANGE | RUMPFS_MODIFY;
914 if (vp->v_mount->mnt_flag & MNT_RELATIME) 915 if (vp->v_mount->mnt_flag & MNT_RELATIME)
915 flags |= RUMPFS_ACCESS; 916 flags |= RUMPFS_ACCESS;
 917 } else if (vap->va_size == 0) {
 918 flags |= RUMPFS_MODIFY;
 919 vap->va_mtime = now;
916 } 920 }
917 SETIFVAL(va_birthtime.tv_sec, time_t); 921 SETIFVAL(va_birthtime.tv_sec, time_t);
918 SETIFVAL(va_birthtime.tv_nsec, long); 922 SETIFVAL(va_birthtime.tv_nsec, long);
919 flags |= RUMPFS_CHANGE; 923 flags |= RUMPFS_CHANGE;
920 getnanotime(&now); 
921 error = rumpfs_update(flags, vp, &vap->va_atime, &vap->va_mtime, &now); 924 error = rumpfs_update(flags, vp, &vap->va_atime, &vap->va_mtime, &now);
922 if (error) 925 if (error)
923 return error; 926 return error;
924 927
925 if (CHANGED(va_flags, u_long)) { 928 if (CHANGED(va_flags, u_long)) {
926 /* XXX Can we handle system flags here...? */ 929 /* XXX Can we handle system flags here...? */
927 error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_FLAGS, vp, 930 error = kauth_authorize_vnode(cred, KAUTH_VNODE_WRITE_FLAGS, vp,
928 NULL, genfs_can_chflags(cred, vp->v_type, attr->va_uid, 931 NULL, genfs_can_chflags(cred, vp->v_type, attr->va_uid,
929 false)); 932 false));
930 if (error) 933 if (error)
931 return error; 934 return error;
932 } 935 }
933 936