Source-Changes-HG archive

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

[src/netbsd-7]: src Pull up following revision(s) (requested by manu in ticke...



details:   https://anonhg.NetBSD.org/src/rev/a860917e9ba4
branches:  netbsd-7
changeset: 799036:a860917e9ba4
user:      martin <martin%NetBSD.org@localhost>
date:      Fri Feb 27 19:39:56 2015 +0000

description:
Pull up following revision(s) (requested by manu in ticket #555):
        lib/libpuffs/puffs.3: revision 1.60
        sys/fs/puffs/puffs_msgif.h: revision 1.84
        lib/libperfuse/ops.c: revision 1.83
        sys/fs/puffs/puffs_sys.h: revision 1.89
        sys/fs/puffs/puffs_vfsops.c: revision 1.116
        lib/libperfuse/perfuse.c: revision 1.36
        sys/fs/puffs/puffs_vnops.c: revision 1.200-1.202

Add PUFFS_KFLAG_NOFLUSH_META to prevent sending metadata flush to FUSE

FUSE filesystems do not expect to get metadata updates for [amc]time
and size, they updates the value on their own after operations.

The PUFFS PUFFS_KFLAG_NOFLUSH_META option prevents regular metadata cache
flushes to the filesystem , and libperfuse uses it to match Linux FUSE
behavior.

While there, fix a bug in SETATTR: do not update kernel metadata cache
from SETATTR reply when the request is asynchronous, as we do not have
the reply yet.

Update file size after write without metadata flush
If we do not use metadata flush, we must make sure the size is updated
in the filesystem after a write, otherwise the next GETATTR will get us
a stale value and the file will be truncated.

diffstat:

 lib/libperfuse/ops.c        |   4 ++-
 lib/libperfuse/perfuse.c    |  11 +++++++-
 lib/libpuffs/puffs.3        |   5 +++-
 sys/fs/puffs/puffs_msgif.h  |   5 ++-
 sys/fs/puffs/puffs_sys.h    |   4 ++-
 sys/fs/puffs/puffs_vfsops.c |   5 ++-
 sys/fs/puffs/puffs_vnops.c  |  60 +++++++++++++++++++++++++++++++-------------
 7 files changed, 68 insertions(+), 26 deletions(-)

diffs (245 lines):

diff -r a5fa1d053259 -r a860917e9ba4 lib/libperfuse/ops.c
--- a/lib/libperfuse/ops.c      Fri Feb 27 12:01:08 2015 +0000
+++ b/lib/libperfuse/ops.c      Fri Feb 27 19:39:56 2015 +0000
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.66.2.14 2015/01/17 11:47:27 martin Exp $ */
+/*  $NetBSD: ops.c,v 1.66.2.15 2015/02/27 19:39:56 martin Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -1828,6 +1828,7 @@
                fsi->valid |= FUSE_FATTR_LOCKOWNER;
        }
 
+#ifndef PUFFS_KFLAG_NOFLUSH_META
        /*
         * ftruncate() sends only va_size, and metadata cache
         * flush adds va_atime and va_mtime. Some FUSE
@@ -1856,6 +1857,7 @@
         */
        if (fsi->valid == FUSE_FATTR_ATIME)
                fsi->valid &= ~FUSE_FATTR_ATIME;
+#endif /* PUFFS_KFLAG_NOFLUSH_META */
                    
        /*
         * If nothing remain, discard the operation.
diff -r a5fa1d053259 -r a860917e9ba4 lib/libperfuse/perfuse.c
--- a/lib/libperfuse/perfuse.c  Fri Feb 27 12:01:08 2015 +0000
+++ b/lib/libperfuse/perfuse.c  Fri Feb 27 19:39:56 2015 +0000
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.31.10.3 2014/11/05 18:11:30 snj Exp $ */
+/*  $NetBSD: perfuse.c,v 1.31.10.4 2015/02/27 19:39:56 martin Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -539,6 +539,15 @@
        puffs_flags |= PUFFS_FLAG_IAONDEMAND;
 #endif
 
+       /*
+        * FUSE filesystem do not expect [amc]time and size
+        * updates to be sent by the kernel, they do the
+        * updates on their own after other operations.
+        */
+#ifdef PUFFS_KFLAG_NOFLUSH_META
+       puffs_flags |= PUFFS_KFLAG_NOFLUSH_META;
+#endif
+
        if (perfuse_diagflags & PDF_PUFFS)
                puffs_flags |= PUFFS_FLAG_OPDUMP;
 
diff -r a5fa1d053259 -r a860917e9ba4 lib/libpuffs/puffs.3
--- a/lib/libpuffs/puffs.3      Fri Feb 27 12:01:08 2015 +0000
+++ b/lib/libpuffs/puffs.3      Fri Feb 27 19:39:56 2015 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: puffs.3,v 1.59 2014/03/18 18:20:38 riastradh Exp $
+.\"    $NetBSD: puffs.3,v 1.59.4.1 2015/02/27 19:39:56 martin Exp $
 .\"
 .\" Copyright (c) 2006, 2007, 2008 Antti Kantee.  All rights reserved.
 .\"
@@ -263,6 +263,9 @@
 .Dq ..
 to the filesystem.
 Parent vnodes are all kept active until their children are reclaimed.
+.It Dv PUFFS_KFLAG_NOFLUSH_META
+Do not send metadata cache flushes for time and size to the filesystem,
+which should take care of updating the values on its own.
 .It Dv PUFFS_FLAG_OPDUMP
 This option makes the framework dump a textual representation of
 each operation before executing it.
diff -r a5fa1d053259 -r a860917e9ba4 sys/fs/puffs/puffs_msgif.h
--- a/sys/fs/puffs/puffs_msgif.h        Fri Feb 27 12:01:08 2015 +0000
+++ b/sys/fs/puffs/puffs_msgif.h        Fri Feb 27 19:39:56 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: puffs_msgif.h,v 1.80.14.2 2014/11/05 18:11:31 snj Exp $        */
+/*     $NetBSD: puffs_msgif.h,v 1.80.14.3 2015/02/27 19:39:56 martin Exp $     */
 
 /*
  * Copyright (c) 2005, 2006, 2007  Antti Kantee.  All Rights Reserved.
@@ -163,7 +163,8 @@
 #define PUFFS_KFLAG_NOCACHE_ATTR       0x040   /* no attrib cache (unused) */
 #define PUFFS_KFLAG_CACHE_FS_TTL       0x080   /* cache use TTL from FS    */
 #define PUFFS_KFLAG_CACHE_DOTDOT       0x100   /* don't send lookup for .. */
-#define PUFFS_KFLAG_MASK               0x1bf
+#define PUFFS_KFLAG_NOFLUSH_META       0x200   /* don't flush metadata cache*/
+#define PUFFS_KFLAG_MASK               0x3bf
 
 #define PUFFS_FHFLAG_DYNAMIC           0x01
 #define PUFFS_FHFLAG_NFSV2             0x02
diff -r a5fa1d053259 -r a860917e9ba4 sys/fs/puffs/puffs_sys.h
--- a/sys/fs/puffs/puffs_sys.h  Fri Feb 27 12:01:08 2015 +0000
+++ b/sys/fs/puffs/puffs_sys.h  Fri Feb 27 19:39:56 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: puffs_sys.h,v 1.84.4.2 2014/08/29 11:55:34 martin Exp $        */
+/*     $NetBSD: puffs_sys.h,v 1.84.4.3 2015/02/27 19:39:56 martin Exp $        */
 
 /*
  * Copyright (c) 2005, 2006  Antti Kantee.  All Rights Reserved.
@@ -94,6 +94,8 @@
     ((pmp)->pmp_flags & PUFFS_KFLAG_CACHE_FS_TTL)
 #define PUFFS_USE_DOTDOTCACHE(pmp)     \
     ((pmp)->pmp_flags & PUFFS_KFLAG_CACHE_DOTDOT)
+#define PUFFS_USE_METAFLUSH(pmp)       \
+    (((pmp)->pmp_flags & PUFFS_KFLAG_NOFLUSH_META) == 0)
 
 #define PUFFS_WCACHEINFO(pmp)  (__USE(pmp), 0)
 
diff -r a5fa1d053259 -r a860917e9ba4 sys/fs/puffs/puffs_vfsops.c
--- a/sys/fs/puffs/puffs_vfsops.c       Fri Feb 27 12:01:08 2015 +0000
+++ b/sys/fs/puffs/puffs_vfsops.c       Fri Feb 27 19:39:56 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: puffs_vfsops.c,v 1.113.2.2 2015/01/17 12:10:54 martin Exp $    */
+/*     $NetBSD: puffs_vfsops.c,v 1.113.2.3 2015/02/27 19:39:56 martin Exp $    */
 
 /*
  * Copyright (c) 2005, 2006  Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: puffs_vfsops.c,v 1.113.2.2 2015/01/17 12:10:54 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: puffs_vfsops.c,v 1.113.2.3 2015/02/27 19:39:56 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -124,6 +124,7 @@
                goto out;
        }
 
+printf("args->pa_flags = 0x%x\n", args->pa_flags);
        if ((args->pa_flags & ~PUFFS_KFLAG_MASK) != 0) {
                printf("puffs_mount: invalid KFLAGs 0x%x\n", args->pa_flags);
                error = EINVAL;
diff -r a5fa1d053259 -r a860917e9ba4 sys/fs/puffs/puffs_vnops.c
--- a/sys/fs/puffs/puffs_vnops.c        Fri Feb 27 12:01:08 2015 +0000
+++ b/sys/fs/puffs/puffs_vnops.c        Fri Feb 27 19:39:56 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: puffs_vnops.c,v 1.182.2.12 2015/01/17 11:49:09 martin Exp $    */
+/*     $NetBSD: puffs_vnops.c,v 1.182.2.13 2015/02/27 19:39:56 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.12 2015/01/17 11:49:09 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: puffs_vnops.c,v 1.182.2.13 2015/02/27 19:39:56 martin Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
@@ -1000,6 +1000,8 @@
          struct timespec *va_ttl, struct timespec *cn_ttl, int flags)
 {
        struct puffs_node *pn = VPTOPP(vp);
+       struct puffs_mount *pmp = MPTOPUFFSMP(vp->v_mount);
+       int use_metacache;
 
        if (TTL_VALID(cn_ttl)) {
                pn->pn_cn_timeout = TTL_TO_TIMEOUT(cn_ttl);
@@ -1023,17 +1025,21 @@
                (void) memcpy(vap, rvap, sizeof(struct vattr));
                vap->va_fsid = vp->v_mount->mnt_stat.f_fsidx.__fsid_val[0];
 
-               if (pn->pn_stat & PNODE_METACACHE_ATIME)
-                       vap->va_atime = pn->pn_mc_atime;
-               if (pn->pn_stat & PNODE_METACACHE_CTIME)
-                       vap->va_ctime = pn->pn_mc_ctime;
-               if (pn->pn_stat & PNODE_METACACHE_MTIME)
-                       vap->va_mtime = pn->pn_mc_mtime;
-               if (pn->pn_stat & PNODE_METACACHE_SIZE)
-                       vap->va_size = pn->pn_mc_size;
+               if (PUFFS_USE_METAFLUSH(pmp)) {
+                       if (pn->pn_stat & PNODE_METACACHE_ATIME)
+                               vap->va_atime = pn->pn_mc_atime;
+                       if (pn->pn_stat & PNODE_METACACHE_CTIME)
+                               vap->va_ctime = pn->pn_mc_ctime;
+                       if (pn->pn_stat & PNODE_METACACHE_MTIME)
+                               vap->va_mtime = pn->pn_mc_mtime;
+                       if (pn->pn_stat & PNODE_METACACHE_SIZE)
+                               vap->va_size = pn->pn_mc_size;
+               }
        }
 
-       if (!(pn->pn_stat & PNODE_METACACHE_SIZE) && (flags & SETATTR_CHSIZE)) {
+       use_metacache = PUFFS_USE_METAFLUSH(pmp) &&
+                       (pn->pn_stat & PNODE_METACACHE_SIZE);
+       if (!use_metacache && (flags & SETATTR_CHSIZE)) {
                if (rvap->va_size != VNOVAL
                    && vp->v_type != VBLK && vp->v_type != VCHR) {
                        uvm_vnp_setsize(vp, rvap->va_size);
@@ -1201,7 +1207,7 @@
         * parameters, treat them as information overriding metacache
         * information.
         */
-       if (pn->pn_stat & PNODE_METACACHE_MASK) {
+       if (PUFFS_USE_METAFLUSH(pmp) && pn->pn_stat & PNODE_METACACHE_MASK) {
                if ((pn->pn_stat & PNODE_METACACHE_ATIME)
                    && vap->va_atime.tv_sec == VNOVAL)
                        vap->va_atime = pn->pn_mc_atime;
@@ -1234,14 +1240,15 @@
                puffs_msg_setfaf(park_setattr);
 
        puffs_msg_enqueue(pmp, park_setattr);
-       if ((flags & SETATTR_ASYNC) == 0)
+       if ((flags & SETATTR_ASYNC) == 0) {
                error = puffs_msg_wait2(pmp, park_setattr, vp->v_data, NULL);
 
-       if ((error == 0) && PUFFS_USE_FS_TTL(pmp)) {
-               struct timespec *va_ttl = &setattr_msg->pvnr_va_ttl;
-               struct vattr *rvap = &setattr_msg->pvnr_va;
-
-               update_va(vp, NULL, rvap, va_ttl, NULL, flags);
+               if ((error == 0) && PUFFS_USE_FS_TTL(pmp)) {
+                       struct timespec *va_ttl = &setattr_msg->pvnr_va_ttl;
+                       struct vattr *rvap = &setattr_msg->pvnr_va;
+
+                       update_va(vp, NULL, rvap, va_ttl, NULL, flags);
+               }
        }
 
        PUFFS_MSG_RELEASE(setattr);
@@ -2544,6 +2551,23 @@
        uflags |= PUFFS_UPDATEMTIME;
        puffs_updatenode(VPTOPP(vp), uflags, vp->v_size);
 
+       /*
+        * If we do not use meta flush, we need to update the
+        * filesystem now, otherwise we will get a stale value
+        * on the next GETATTR
+        */
+       if (!PUFFS_USE_METAFLUSH(pmp) && (uflags & PUFFS_UPDATESIZE)) {
+               struct vattr va;
+               int ret;
+
+               vattr_null(&va);
+               va.va_size = vp->v_size;
+               ret = dosetattr(vp, &va, FSCRED, 0);
+               if (ret) {
+                       DPRINTF(("dosetattr set size to %jd failed: %d\n",
+                           (intmax_t)vp->v_size, ret));
+               }
+       }
        mutex_exit(&pn->pn_sizemtx);
        return error;
 }



Home | Main Index | Thread Index | Old Index