Module Name:    src
Committed By:   manu
Date:           Sun Feb 15 20:21:29 UTC 2015

Modified Files:
        src/lib/libperfuse: ops.c perfuse.c
        src/lib/libpuffs: puffs.3
        src/sys/fs/puffs: puffs_msgif.h puffs_sys.h puffs_vfsops.c
            puffs_vnops.c

Log Message:
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.


To generate a diff of this commit:
cvs rdiff -u -r1.82 -r1.83 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.35 -r1.36 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.59 -r1.60 src/lib/libpuffs/puffs.3
cvs rdiff -u -r1.83 -r1.84 src/sys/fs/puffs/puffs_msgif.h
cvs rdiff -u -r1.88 -r1.89 src/sys/fs/puffs/puffs_sys.h
cvs rdiff -u -r1.115 -r1.116 src/sys/fs/puffs/puffs_vfsops.c
cvs rdiff -u -r1.199 -r1.200 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/lib/libperfuse/ops.c
diff -u src/lib/libperfuse/ops.c:1.82 src/lib/libperfuse/ops.c:1.83
--- src/lib/libperfuse/ops.c:1.82	Tue Jan 13 16:51:30 2015
+++ src/lib/libperfuse/ops.c	Sun Feb 15 20:21:29 2015
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.82 2015/01/13 16:51:30 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.83 2015/02/15 20:21:29 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -1828,6 +1828,7 @@ perfuse_node_setattr_ttl(struct puffs_us
 		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 @@ perfuse_node_setattr_ttl(struct puffs_us
 	 */
 	if (fsi->valid == FUSE_FATTR_ATIME)
 		fsi->valid &= ~FUSE_FATTR_ATIME;
+#endif /* PUFFS_KFLAG_NOFLUSH_META */
 		    
 	/*
 	 * If nothing remain, discard the operation.

Index: src/lib/libperfuse/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.35 src/lib/libperfuse/perfuse.c:1.36
--- src/lib/libperfuse/perfuse.c:1.35	Fri Oct 31 15:12:15 2014
+++ src/lib/libperfuse/perfuse.c	Sun Feb 15 20:21:29 2015
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.35 2014/10/31 15:12:15 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.36 2015/02/15 20:21:29 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -539,6 +539,15 @@ perfuse_init(struct perfuse_callbacks *p
 	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;
 

Index: src/lib/libpuffs/puffs.3
diff -u src/lib/libpuffs/puffs.3:1.59 src/lib/libpuffs/puffs.3:1.60
--- src/lib/libpuffs/puffs.3:1.59	Tue Mar 18 18:20:38 2014
+++ src/lib/libpuffs/puffs.3	Sun Feb 15 20:21:29 2015
@@ -1,4 +1,4 @@
-.\"	$NetBSD: puffs.3,v 1.59 2014/03/18 18:20:38 riastradh Exp $
+.\"	$NetBSD: puffs.3,v 1.60 2015/02/15 20:21:29 manu Exp $
 .\"
 .\" Copyright (c) 2006, 2007, 2008 Antti Kantee.  All rights reserved.
 .\"
@@ -263,6 +263,9 @@ Never send lookups for
 .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.

Index: src/sys/fs/puffs/puffs_msgif.h
diff -u src/sys/fs/puffs/puffs_msgif.h:1.83 src/sys/fs/puffs/puffs_msgif.h:1.84
--- src/sys/fs/puffs/puffs_msgif.h:1.83	Fri Oct 31 14:20:54 2014
+++ src/sys/fs/puffs/puffs_msgif.h	Sun Feb 15 20:21:29 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: puffs_msgif.h,v 1.83 2014/10/31 14:20:54 manu Exp $	*/
+/*	$NetBSD: puffs_msgif.h,v 1.84 2015/02/15 20:21:29 manu Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006, 2007  Antti Kantee.  All Rights Reserved.
@@ -163,7 +163,8 @@ struct puffs_kargs {
 #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

Index: src/sys/fs/puffs/puffs_sys.h
diff -u src/sys/fs/puffs/puffs_sys.h:1.88 src/sys/fs/puffs/puffs_sys.h:1.89
--- src/sys/fs/puffs/puffs_sys.h:1.88	Sun Oct  5 20:40:46 2014
+++ src/sys/fs/puffs/puffs_sys.h	Sun Feb 15 20:21:29 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: puffs_sys.h,v 1.88 2014/10/05 20:40:46 apb Exp $	*/
+/*	$NetBSD: puffs_sys.h,v 1.89 2015/02/15 20:21:29 manu Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006  Antti Kantee.  All Rights Reserved.
@@ -98,6 +98,8 @@ extern int puffsdebug; /* puffs_subr.c *
     ((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)
 

Index: src/sys/fs/puffs/puffs_vfsops.c
diff -u src/sys/fs/puffs/puffs_vfsops.c:1.115 src/sys/fs/puffs/puffs_vfsops.c:1.116
--- src/sys/fs/puffs/puffs_vfsops.c:1.115	Mon Nov 10 18:46:33 2014
+++ src/sys/fs/puffs/puffs_vfsops.c	Sun Feb 15 20:21:29 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: puffs_vfsops.c,v 1.115 2014/11/10 18:46:33 maxv Exp $	*/
+/*	$NetBSD: puffs_vfsops.c,v 1.116 2015/02/15 20:21:29 manu 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.115 2014/11/10 18:46:33 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: puffs_vfsops.c,v 1.116 2015/02/15 20:21:29 manu Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -124,6 +124,7 @@ puffs_vfsop_mount(struct mount *mp, cons
 		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;

Index: src/sys/fs/puffs/puffs_vnops.c
diff -u src/sys/fs/puffs/puffs_vnops.c:1.199 src/sys/fs/puffs/puffs_vnops.c:1.200
--- src/sys/fs/puffs/puffs_vnops.c:1.199	Tue Jan 13 16:39:51 2015
+++ src/sys/fs/puffs/puffs_vnops.c	Sun Feb 15 20:21:29 2015
@@ -1,4 +1,4 @@
-/*	$NetBSD: puffs_vnops.c,v 1.199 2015/01/13 16:39:51 manu Exp $	*/
+/*	$NetBSD: puffs_vnops.c,v 1.200 2015/02/15 20:21:29 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.199 2015/01/13 16:39:51 manu Exp $");
+__KERNEL_RCSID(0, "$NetBSD: puffs_vnops.c,v 1.200 2015/02/15 20:21:29 manu Exp $");
 
 #include <sys/param.h>
 #include <sys/buf.h>
@@ -1000,6 +1000,8 @@ update_va(struct vnode *vp, struct vattr
 	  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 @@ update_va(struct vnode *vp, struct vattr
 		(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 @@ dosetattr(struct vnode *vp, struct vattr
 	 * 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 @@ dosetattr(struct vnode *vp, struct vattr
 		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;
+		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);
+			update_va(vp, NULL, rvap, va_ttl, NULL, flags);
+		}
 	}
 
 	PUFFS_MSG_RELEASE(setattr);

Reply via email to