Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/netbsd-6]: src/sys/fs/puffs Pull up following revision(s) (requested by ...



details:   https://anonhg.NetBSD.org/src/rev/2a637e1b3522
branches:  netbsd-6
changeset: 776774:2a637e1b3522
user:      msaitoh <msaitoh%NetBSD.org@localhost>
date:      Sun Nov 09 06:28:03 2014 +0000

description:
Pull up following revision(s) (requested by manu in ticket #1166):
        sys/fs/puffs/puffs_vnops.c: revision 1.188-1.194
- 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 hole), that area will not return zeroes as it should.
- Use PRIx64 for printing offsets
- 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
- Retore LP64 fix that was removed by mistake
- Make this build again without debugging enabled; DPRINTF() can end up
  as empty, and in an if conditional, you then need braces if that's the
  only potential body.
- As is evidenced by several of our 32-bit MIPS ports, it's wrong to
  print vsize_t with PRIx64 -- instead use our own PRIxVSIZE macro.
- Do the previous correctly...

diffstat:

 sys/fs/puffs/puffs_vnops.c |  53 ++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 51 insertions(+), 2 deletions(-)

diffs (87 lines):

diff -r fd8cbcc337c3 -r 2a637e1b3522 sys/fs/puffs/puffs_vnops.c
--- a/sys/fs/puffs/puffs_vnops.c        Sun Nov 09 06:16:50 2014 +0000
+++ b/sys/fs/puffs/puffs_vnops.c        Sun Nov 09 06:28:03 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: puffs_vnops.c,v 1.163.2.7 2014/11/03 19:51:36 msaitoh Exp $    */
+/*     $NetBSD: puffs_vnops.c,v 1.163.2.8 2014/11/09 06:28:03 msaitoh 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.163.2.7 2014/11/03 19:51:36 msaitoh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: puffs_vnops.c,v 1.163.2.8 2014/11/09 06:28:03 msaitoh Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
@@ -1117,12 +1117,50 @@
        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%" PRIxVSIZE "@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));
@@ -1195,6 +1233,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