NFS ftruncate patch for review

Tim Robbins tjr at FreeBSD.ORG
Thu Jul 17 23:41:26 PDT 2003


Any comments on this patch? The referenced PR contains more comments and a
test program. It's not obvious from the diff, but the changes are to
nfs_setattr() in the va_size != VNOVAL && v_type == VREG case.


Change 34590 by tjr at tjr_dev on 2003/07/16 04:40:35

	Fix a nasty problem when truncating files over NFS that was introduced
	between FreeBSD 4.4 and 4.5: we need to set np->n_size again after
	flushing/truncating buffers in case the cache calls nfs_write().
	
	For example, if the file is truncated to 0 bytes, nfs_write() will
	often detect that the file is being appended to (since the file
	is 0 bytes long and we're writing to offset 0), so it then updates
	np->n_size to reflect the size the file was before it was truncated.
	
	PR: 41792

Affected files ...

... //depot/user/tjr/freebsd-tjr/src/sys/nfsclient/nfs_vnops.c#7 edit

Differences ...

==== //depot/user/tjr/freebsd-tjr/src/sys/nfsclient/nfs_vnops.c#7 (text+ko) ====

@@ -662,7 +662,13 @@
  				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_write() could be called when flushing dirty
+			 * buffers, and nfs_write() can 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) &&


More information about the freebsd-fs mailing list