Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-7]: src/sys/fs/puffs Pull up following revision(s) (requested by ...
details: https://anonhg.NetBSD.org/src/rev/6415535c51b7
branches: netbsd-7
changeset: 798422:6415535c51b7
user: martin <martin%NetBSD.org@localhost>
date: Mon Oct 13 18:57:46 2014 +0000
description:
Pull up following revision(s) (requested by manu in ticket #136):
sys/fs/puffs/puffs_vnops.c: revision 1.189-1.191
If we truncate a file open for writing, make sure we zero-fill the end
of the last page, otherwise if the file is later truncated to a larger
size (creating a hole), that area will not return zeroes as it should.
diffstat:
sys/fs/puffs/puffs_vnops.c | 52 ++++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 50 insertions(+), 2 deletions(-)
diffs (86 lines):
diff -r c9ff771643a5 -r 6415535c51b7 sys/fs/puffs/puffs_vnops.c
--- a/sys/fs/puffs/puffs_vnops.c Sat Oct 11 17:03:28 2014 +0000
+++ b/sys/fs/puffs/puffs_vnops.c Mon Oct 13 18:57:46 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: puffs_vnops.c,v 1.182.2.5 2014/09/30 18:14:22 martin Exp $ */
+/* $NetBSD: puffs_vnops.c,v 1.182.2.6 2014/10/13 18:57:46 martin 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.182.2.5 2014/09/30 18:14:22 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: puffs_vnops.c,v 1.182.2.6 2014/10/13 18:57:46 martin Exp $");
#include <sys/param.h>
#include <sys/buf.h>
@@ -1130,12 +1130,49 @@
return error;
}
+static void
+zerofill_lastpage(struct vnode *vp, voff_t off)
+{
+ char zbuf[PAGE_SIZE];
+ struct iovec iov;
+ struct uio uio;
+ vsize_t len;
+ int error;
+
+ if (trunc_page(off) == off)
+ return;
+
+ if (vp->v_writecount == 0)
+ return;
+
+ len = round_page(off) - off;
+ memset(zbuf, 0, len);
+
+ iov.iov_base = zbuf;
+ iov.iov_len = len;
+ UIO_SETUP_SYSSPACE(&uio);
+ uio.uio_iov = &iov;
+ uio.uio_iovcnt = 1;
+ uio.uio_offset = off;
+ uio.uio_resid = len;
+ uio.uio_rw = UIO_WRITE;
+
+ 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 " failed: error = %d\n",
+ len, off, error));
+
+ return;
+}
+
static int
dosetattr(struct vnode *vp, struct vattr *vap, kauth_cred_t cred, int flags)
{
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));
@@ -1208,6 +1245,17 @@
}
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);
Home |
Main Index |
Thread Index |
Old Index