Module Name: src Committed By: manu Date: Mon Oct 6 04:41:59 UTC 2014
Modified Files: src/sys/fs/puffs: puffs_vnops.c Log Message: Improve zero-fill of last page after shrink fix: 1) do it only if the file is open for writing, otherwise we send write requests to the FS on a file that has never been open. 2) do it inside existing if (vap->va_size != VNOVAL) block To generate a diff of this commit: cvs rdiff -u -r1.189 -r1.190 src/sys/fs/puffs/puffs_vnops.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/fs/puffs/puffs_vnops.c diff -u src/sys/fs/puffs/puffs_vnops.c:1.189 src/sys/fs/puffs/puffs_vnops.c:1.190 --- src/sys/fs/puffs/puffs_vnops.c:1.189 Sun Oct 5 09:28:24 2014 +++ src/sys/fs/puffs/puffs_vnops.c Mon Oct 6 04:41:59 2014 @@ -1,4 +1,4 @@ -/* $NetBSD: puffs_vnops.c,v 1.189 2014/10/05 09:28:24 justin Exp $ */ +/* $NetBSD: puffs_vnops.c,v 1.190 2014/10/06 04:41:59 manu Exp $ */ /* * Copyright (c) 2005, 2006, 2007 Antti Kantee. All Rights Reserved. @@ -30,7 +30,7 @@ */ #include <sys/cdefs.h> -__KERNEL_RCSID(0, "$NetBSD: puffs_vnops.c,v 1.189 2014/10/05 09:28:24 justin Exp $"); +__KERNEL_RCSID(0, "$NetBSD: puffs_vnops.c,v 1.190 2014/10/06 04:41:59 manu Exp $"); #include <sys/param.h> #include <sys/buf.h> @@ -1141,6 +1141,9 @@ zerofill_lastpage(struct vnode *vp, voff if (trunc_page(off) == off) return; + + if (vp->v_writecount == 0) + return; len = round_page(off) - off; memset(zbuf, 0, len); @@ -1157,7 +1160,7 @@ zerofill_lastpage(struct vnode *vp, voff error = ubc_uiomove(&vp->v_uobj, &uio, len, UVM_ADV_SEQUENTIAL, UBC_WRITE|UBC_UNMAP_FLAG(vp)); if (error) - DPRINTF(("zero-fill 0x%lx@0x%" PRIx64 " => %d\n", len, off, error)); + DPRINTF(("zero-fill 0x%lx@0x%llx => %d\n", len, off, error)); return; } @@ -1168,6 +1171,7 @@ dosetattr(struct vnode *vp, struct vattr PUFFS_MSG_VARS(vn, setattr); struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount); struct puffs_node *pn = vp->v_data; + vsize_t oldsize = vp->v_size; int error = 0; KASSERT(!(flags & SETATTR_CHSIZE) || mutex_owned(&pn->pn_sizemtx)); @@ -1223,17 +1227,6 @@ dosetattr(struct vnode *vp, struct vattr if ((flags & SETATTR_ASYNC) == 0) error = puffs_msg_wait2(pmp, park_setattr, vp->v_data, NULL); - /* - * If we truncate the file, make sure we zero-fill - * the end of the last page, otherwise if the file - * is later truncated to a larger size (creating a - * a hole), that area will not return zeroes as it - * should. - */ - if ((error == 0) && (flags & SETATTR_CHSIZE) && - (vap->va_size != VNOVAL) && (vap->va_size < vp->v_size)) - zerofill_lastpage(vp, vap->va_size); - if ((error == 0) && PUFFS_USE_FS_TTL(pmp)) { struct timespec *va_ttl = &setattr_msg->pvnr_va_ttl; struct vattr *rvap = &setattr_msg->pvnr_va; @@ -1251,6 +1244,17 @@ dosetattr(struct vnode *vp, struct vattr } if (vap->va_size != VNOVAL) { + /* + * If we truncated the file, make sure the data beyond + * EOF in last page does not remain in cache, otherwise + * if the file is later truncated to a larger size (creating + * a hole), that area will not return zeroes as it + * should. + */ + if ((flags & SETATTR_CHSIZE) && PUFFS_USE_PAGECACHE(pmp) && + (vap->va_size < oldsize)) + zerofill_lastpage(vp, vap->va_size); + pn->pn_serversize = vap->va_size; if (flags & SETATTR_CHSIZE) uvm_vnp_setsize(vp, vap->va_size);