From aae962d56ef0734dea72b7a57d3a1c0bbf62bf18 Mon Sep 17 00:00:00 2001 From: "Tim J. Robbins" Date: Tue, 29 Jul 2003 00:17:29 +0000 Subject: [PATCH] Fix a problem that occurs when truncating files on NFSv3 mounts: we need to set np->n_size back to the desired size again after calling nfs_meta_setsize(), since it could end up in nfs_loadattrcache() getting called, which would change n_size back to the value it had before the truncate request was issued. The result of this bug is that the size info cached in the nfsnode becomes incorrect, lseek(fd, ofs, SEEK_END) seeks past the end of the file, stat() returns the wrong size, etc. PR: 41792 MFC after: 2 weeks --- sys/nfsclient/nfs_vnops.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sys/nfsclient/nfs_vnops.c b/sys/nfsclient/nfs_vnops.c index 2e4fe050f73..158e76f3aed 100644 --- a/sys/nfsclient/nfs_vnops.c +++ b/sys/nfsclient/nfs_vnops.c @@ -662,7 +662,13 @@ nfs_setattr(struct vop_setattr_args *ap) return (error); } } - np->n_vattr.va_size = vap->va_size; + /* + * np->n_size has already been set to vap->va_size + * in nfs_meta_setsize(). We must set it again since + * nfs_loadattrcache() could be called through + * nfs_meta_setsize() and could modify np->n_size. + */ + np->n_vattr.va_size = np->n_size = vap->va_size; }; } else if ((vap->va_mtime.tv_sec != VNOVAL || vap->va_atime.tv_sec != VNOVAL) && (np->n_flag & NMODIFIED) &&