CVS commit: src/lib/libperfuse

2019-02-08 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sat Feb  9 02:22:45 UTC 2019

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Fix directory filehandle usage with libufse. Fix lookup count

libfuse does not use filehandle the same way for directories and other
objects. As a result, filehandles obtained by OPENDIR should not be
sent on non-directory related operations like READ/WRITE/GETATTR...

While there, fix the lookup count sent to the FORGET operation, which
led to leaked nodes.


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/lib/libperfuse/ops.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.85 src/lib/libperfuse/ops.c:1.86
--- src/lib/libperfuse/ops.c:1.85	Fri Nov 16 02:39:02 2018
+++ src/lib/libperfuse/ops.c	Sat Feb  9 02:22:45 2019
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.85 2018/11/16 02:39:02 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.86 2019/02/09 02:22:45 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -105,6 +105,9 @@ const int vttoif_tab[9] = { 
 #define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12])
 #define VTTOIF(indx) (vttoif_tab[(int)(indx)])
 
+#define PN_ISDIR(opc) \
+	(puffs_pn_getvap((struct puffs_node *)opc)->va_type == VDIR)
+
 #if 0
 static void 
 print_node(const char *func, puffs_cookie_t opc)
@@ -141,7 +144,7 @@ perfuse_node_close_common(struct puffs_u
 	pn = (struct puffs_node *)opc;
 	pnd = PERFUSE_NODE_DATA(pn);
 
-	if (puffs_pn_getvap(pn)->va_type == VDIR) {
+	if (PN_ISDIR(opc)) {
 		op = FUSE_RELEASEDIR;
 		mode = FREAD;
 	} else {
@@ -479,13 +482,14 @@ node_lookup_common(struct puffs_usermoun
 	fuse_attr_to_vap(ps, &pn->pn_va, &feo->attr);
 	pn->pn_va.va_gen = (u_long)(feo->generation);
 	PERFUSE_NODE_DATA(pn)->pnd_fuse_nlookup++;
+	PERFUSE_NODE_DATA(pn)->pnd_puffs_nlookup++;
 
 	*pnp = pn;
 
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & PDF_FILENAME)
 		DPRINTF("%s: opc = %p, looked up opc = %p, "
-			"nodeid = 0x%"PRIx64" file = \"%s\"\n", __func__, 
+			"nodeid = 0x%"PRIx64" file = \"%s\"\n", __func__,
 			(void *)opc, pn, feo->nodeid, path);
 #endif
 
@@ -533,6 +537,7 @@ node_mk_common(struct puffs_usermount *p
 
 	pn = perfuse_new_pn(pu, pcn->pcn_name, opc);
 	PERFUSE_NODE_DATA(pn)->pnd_nodeid = feo->nodeid;
+	PERFUSE_NODE_DATA(pn)->pnd_fuse_nlookup++;
 	PERFUSE_NODE_DATA(pn)->pnd_puffs_nlookup++;
 	perfuse_node_cache(ps, pn);
 
@@ -1138,6 +1143,7 @@ perfuse_node_lookup(struct puffs_usermou
 		break;
 	}
 
+	PERFUSE_NODE_DATA(pn)->pnd_fuse_nlookup++;
 	PERFUSE_NODE_DATA(pn)->pnd_puffs_nlookup++;
 
 	error = 0;
@@ -1247,6 +1253,7 @@ perfuse_node_create(struct puffs_usermou
 	pn = perfuse_new_pn(pu, name, opc);
 	perfuse_new_fh((puffs_cookie_t)pn, foo->fh, FWRITE);
 	PERFUSE_NODE_DATA(pn)->pnd_nodeid = feo->nodeid;
+	PERFUSE_NODE_DATA(pn)->pnd_fuse_nlookup++;
 	PERFUSE_NODE_DATA(pn)->pnd_puffs_nlookup++;
 	perfuse_node_cache(ps, pn);
 
@@ -1355,11 +1362,9 @@ perfuse_node_open2(struct puffs_usermoun
 	int op;
 	struct fuse_open_in *foi;
 	struct fuse_open_out *foo;
-	struct puffs_node *pn;
 	int error;
 	
 	ps = puffs_getspecific(pu);
-	pn = (struct puffs_node *)opc;
 	pnd = PERFUSE_NODE_DATA(opc);
 	error = 0;
 
@@ -1368,7 +1373,7 @@ perfuse_node_open2(struct puffs_usermoun
 
 	node_ref(opc);
 
-	if (puffs_pn_getvap(pn)->va_type == VDIR)
+	if (PN_ISDIR(opc))
 		op = FUSE_OPENDIR;
 	else
 		op = FUSE_OPEN;
@@ -1592,9 +1597,9 @@ perfuse_node_getattr_ttl(struct puffs_us
 	fgi = GET_INPAYLOAD(ps, pm, fuse_getattr_in);
 	fgi->getattr_flags = 0; 
 	fgi->dummy = 0;
-	fgi->fh = 0;
+	fgi->fh = FUSE_UNKNOWN_FH;
 
-	if (PERFUSE_NODE_DATA(opc)->pnd_flags & PND_OPEN) {
+	if (!PN_ISDIR(opc) && PERFUSE_NODE_DATA(opc)->pnd_flags & PND_OPEN) {
 		fgi->fh = perfuse_get_fh(opc, FREAD);
 		fgi->getattr_flags |= FUSE_GETATTR_FH;
 	}
@@ -1728,7 +1733,7 @@ perfuse_node_setattr_ttl(struct puffs_us
 	
 	node_ref(opc);
 	
-	if (pnd->pnd_flags & PND_WFH)
+	if (!PN_ISDIR(opc) && pnd->pnd_flags & PND_WFH)
 		fh = perfuse_get_fh(opc, FWRITE);
 	else
 		fh = FUSE_UNKNOWN_FH;
@@ -1954,7 +1959,7 @@ perfuse_node_poll(struct puffs_usermount
  	 */
 	pm = ps->ps_new_msg(pu, opc, FUSE_POLL, sizeof(*fpi), NULL);
 	fpi = GET_INPAYLOAD(ps, pm, fuse_poll_in);
-	fpi->fh = perfuse_get_fh(opc, FREAD);
+	fpi->fh = PN_ISDIR(opc) ? FUSE_UNKNOWN_FH : perfuse_get_fh(opc, FREAD);
 	fpi->kh = 0;
 	fpi->flags = 0;
 
@@ -2010,7 +2015,7 @@ perfuse_node_fsync(struct puffs_usermoun
 
 	node_ref(opc);
 
-	if (puffs_pn_getvap((struct puffs_node *)opc)->va_type == VDIR) 
+	if (PN_ISDIR(opc))
 		op = FUSE_FSYNCDIR;
 	else 		/* VREG but also other types such as VLNK */
 		op = FUSE_FSYNC;
@@ -2513,7 +2518,7 @@ perfuse_node_readdir(struct puffs_usermo
 			goto out;
 	}
 
-	fh = perfuse_get_fh(opc, FREAD);
+	fh = perfuse_get_fh(opc, FREAD); 
 
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & PDF_F

CVS commit: src/lib/libperfuse

2019-01-23 Thread Valeriy E. Ushakov
Module Name:src
Committed By:   uwe
Date:   Wed Jan 23 19:43:49 UTC 2019

Modified Files:
src/lib/libperfuse: libperfuse.3

Log Message:
It's section 3 page, not section 2.  While here, xref puffs(3) in the
SEE ALSO section too.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libperfuse/libperfuse.3

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/libperfuse.3
diff -u src/lib/libperfuse/libperfuse.3:1.5 src/lib/libperfuse/libperfuse.3:1.6
--- src/lib/libperfuse/libperfuse.3:1.5	Tue Oct 18 22:26:13 2016
+++ src/lib/libperfuse/libperfuse.3	Wed Jan 23 19:43:49 2019
@@ -1,4 +1,4 @@
-.\" $NetBSD: libperfuse.3,v 1.5 2016/10/18 22:26:13 wiz Exp $
+.\" $NetBSD: libperfuse.3,v 1.6 2019/01/23 19:43:49 uwe Exp $
 .\"
 .\" Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
 .\"
@@ -23,8 +23,8 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.Dd August 12, 2010
-.Dt LIBPERFUSE 2
+.Dd January 23, 2019
+.Dt LIBPERFUSE 3
 .Os
 .Sh NAME
 .Nm perfuse_mount ,
@@ -130,6 +130,7 @@ bytes, which is enough to queue 16 FUSE 
 .Xr df 1 ,
 .Xr mount 2 ,
 .Xr open 2 ,
+.Xr puffs 3 ,
 .Xr mount 8 ,
 .Xr perfused 8
 .Sh AUTHORS



CVS commit: src/lib/libperfuse

2018-11-15 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Fri Nov 16 02:39:02 UTC 2018

Modified Files:
src/lib/libperfuse: debug.c ops.c perfuse.c perfuse_priv.h

Log Message:
Use reclaim2 to fix reclaim/lookup race conditions

The PUFFS reclaim operation had a race condition with lookups: we could
be asked to lookup a node, then to reclaim it before lookup completion.
At lookup completion, we would then create a leaked node.

Enter the PUFFS reclaim2 operation, which features a nlookup argument.
That let us count how many lookups are pending and avoid the above
described scenario. It also makes the codes simplier.


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libperfuse/debug.c
cvs rdiff -u -r1.84 -r1.85 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.40 -r1.41 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.36 -r1.37 src/lib/libperfuse/perfuse_priv.h

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/debug.c
diff -u src/lib/libperfuse/debug.c:1.12 src/lib/libperfuse/debug.c:1.13
--- src/lib/libperfuse/debug.c:1.12	Sat Jul 21 05:49:42 2012
+++ src/lib/libperfuse/debug.c	Fri Nov 16 02:39:02 2018
@@ -1,4 +1,4 @@
-/*  $NetBSD: debug.c,v 1.12 2012/07/21 05:49:42 manu Exp $ */
+/*  $NetBSD: debug.c,v 1.13 2018/11/16 02:39:02 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -270,7 +270,6 @@ perfuse_trace_dump(struct puffs_usermoun
 	fprintf(fp, "\n\nGlobal statistics\n");
 	fprintf(fp, "Nodes: %d\n", ps->ps_nodecount);
 	fprintf(fp, "Exchanges: %d\n", ps->ps_xchgcount);
-	fprintf(fp, "Nodes possibly leaked: %d\n", ps->ps_nodeleakcount);
 	
 	(void)fflush(fp);
 	return;

Index: src/lib/libperfuse/ops.c
diff -u src/lib/libperfuse/ops.c:1.84 src/lib/libperfuse/ops.c:1.85
--- src/lib/libperfuse/ops.c:1.84	Wed Jun  3 14:07:05 2015
+++ src/lib/libperfuse/ops.c	Fri Nov 16 02:39:02 2018
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.84 2015/06/03 14:07:05 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.85 2018/11/16 02:39:02 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -500,11 +500,6 @@ node_lookup_common(struct puffs_usermoun
 		puffs_newinfo_setrdev(pni, pn->pn_va.va_rdev);
 	}
 
-	if (PERFUSE_NODE_DATA(pn)->pnd_flags & PND_NODELEAK) {
-		PERFUSE_NODE_DATA(pn)->pnd_flags &= ~PND_NODELEAK;
-		ps->ps_nodeleakcount--;
-	}
-
 	ps->ps_destroy_msg(pm);
 
 	return 0;
@@ -672,7 +667,7 @@ fuse_to_dirent(struct puffs_usermount *p
 	   "failed: %d", name, error);
 } else {
 	fd->ino = pn->pn_va.va_fileid;
-	(void)perfuse_node_reclaim(pu, pn);
+	(void)perfuse_node_reclaim2(pu, pn, 1);
 }
 			}
 		}
@@ -1135,7 +1130,7 @@ perfuse_node_lookup(struct puffs_usermou
 	case NAMEI_RENAME:
 		error = sticky_access(opc, pn, pcn->pcn_cred);
 		if (error != 0) {
-			(void)perfuse_node_reclaim(pu, pn);
+			(void)perfuse_node_reclaim2(pu, pn, 1);
 			goto out;
 		}
 		break;
@@ -1182,7 +1177,7 @@ perfuse_node_create(struct puffs_usermou
 		error = node_lookup_common(pu, opc, NULL, pcn->pcn_name,
 	   pcn->pcn_cred, &pn);
 		if (error == 0)	{
-			(void)perfuse_node_reclaim(pu, pn);
+			(void)perfuse_node_reclaim2(pu, pn, 1);
 			error = EEXIST;
 			goto out;
 		}
@@ -2682,17 +2677,22 @@ out:
 }
 
 int 
-perfuse_node_reclaim(struct puffs_usermount *pu, puffs_cookie_t opc)
+perfuse_node_reclaim2(struct puffs_usermount *pu,
+		  puffs_cookie_t opc, int nlookup)
 {
 	struct perfuse_state *ps;
 	perfuse_msg_t *pm;
 	struct perfuse_node_data *pnd;
 	struct fuse_forget_in *ffi;
-	int nlookup;
-	struct timespec now;
 	
-	if (opc == 0)
+#ifdef PERFUSE_DEBUG
+		if (perfuse_diagflags & PDF_RECLAIM)
+			DPRINTF("%s called with opc = %p, nlookup = %d\n",
+__func__, (void *)opc, nlookup);
+#endif
+	if (opc == 0 || nlookup == 0) {
 		return 0;
+	}
 
 	ps = puffs_getspecific(pu);
 	pnd = PERFUSE_NODE_DATA(opc);
@@ -2703,43 +2703,23 @@ perfuse_node_reclaim(struct puffs_usermo
 	if (pnd->pnd_nodeid == FUSE_ROOT_ID)
 		return 0;
 
+#ifdef PERFUSE_DEBUG
+	if (perfuse_diagflags & PDF_RECLAIM)
+		DPRINTF("%s (nodeid %"PRId64") reclaimed, nlookup = %d/%d\n", 
+			perfuse_node_path(ps, opc), pnd->pnd_nodeid,
+			nlookup, pnd->pnd_puffs_nlookup);
+#endif
 	/*
-	 * There is a race condition between reclaim and lookup.
-	 * When looking up an already known node, the kernel cannot
-	 * hold a reference on the result until it gets the PUFFS
-	 * reply. It mayy therefore reclaim the node after the 
-	 * userland looked it up, and before it gets the reply. 
-	 * On rely, the kernel re-creates the node, but at that 
-	 * time the node has been reclaimed in userland.
-	 *
-	 * In order to avoid this, we refuse reclaiming nodes that
-	 * are too young since the last lookup - and that we do 
-	 * not have removed on our own, of course. 
-	 */
-	if (clock_gettime(CLOCK_REALTIME, &now) != 0)
-		DERR(EX_OSERR, "clock_gettime failed"); 
-
-	if (ti

CVS commit: src/lib/libperfuse

2016-10-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Wed Oct 19 01:30:35 UTC 2016

Modified Files:
src/lib/libperfuse: perfuse.c perfuse_if.h

Log Message:
make the env stuff visible.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.21 -r1.22 src/lib/libperfuse/perfuse_if.h

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/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.39 src/lib/libperfuse/perfuse.c:1.40
--- src/lib/libperfuse/perfuse.c:1.39	Tue Oct 18 13:56:31 2016
+++ src/lib/libperfuse/perfuse.c	Tue Oct 18 21:30:35 2016
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.39 2016/10/18 17:56:31 christos Exp $ */
+/*  $NetBSD: perfuse.c,v 1.40 2016/10/19 01:30:35 christos Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -52,8 +52,6 @@ extern char **environ;
 
 static struct perfuse_state *init_state(void);
 static int get_fd(const char *);
-static uint32_t bufvar_from_env(const char *, uint32_t);
-
 
 static struct perfuse_state *
 init_state(void)
@@ -148,8 +146,8 @@ get_fd(const char *data)
 
 }
 
-static uint32_t 
-bufvar_from_env(const char *name, uint32_t defval)
+uint32_t 
+perfuse_bufvar_from_env(const char *name, uint32_t defval)
 {
 	char valstr[1024];
 	int e;
@@ -204,7 +202,8 @@ perfuse_open(const char *path, int flags
 	 * Set a buffer lentgh large enough so that enough FUSE packets
 	 * will fit.
 	 */
-	opt = bufvar_from_env("PERFUSE_BUFSIZE", (uint32_t)(16 * FUSE_BUFSIZE));
+	opt = perfuse_bufvar_from_env("PERFUSE_BUFSIZE",
+	(uint32_t)(16 * FUSE_BUFSIZE));
 	optlen = sizeof(opt);
 	if (setsockopt(sv[0], SOL_SOCKET, SO_SNDBUF, &opt, optlen) != 0)
 		DWARN("%s: setsockopt SO_SNDBUF to %d failed", __func__, opt);
@@ -235,7 +234,8 @@ perfuse_open(const char *path, int flags
 	 * Set a buffer lentgh large enough so that enough FUSE packets
 	 * will fit.
 	 */
-	opt = bufvar_from_env("PERFUSE_BUFSIZE", (uint32_t)(16 * FUSE_BUFSIZE));
+	opt = perfuse_bufvar_from_env("PERFUSE_BUFSIZE",
+	(uint32_t)(16 * FUSE_BUFSIZE));
 	optlen = sizeof(opt);
 	if (setsockopt(sv[0], SOL_SOCKET, SO_SNDBUF, &opt, optlen) != 0)
 		DWARN("%s: setsockopt SO_SNDBUF to %d failed", __func__, opt);

Index: src/lib/libperfuse/perfuse_if.h
diff -u src/lib/libperfuse/perfuse_if.h:1.21 src/lib/libperfuse/perfuse_if.h:1.22
--- src/lib/libperfuse/perfuse_if.h:1.21	Tue Oct 18 13:56:31 2016
+++ src/lib/libperfuse/perfuse_if.h	Tue Oct 18 21:30:35 2016
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_if.h,v 1.21 2016/10/18 17:56:31 christos Exp $ */
+/*  $NetBSD: perfuse_if.h,v 1.22 2016/10/19 01:30:35 christos Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -219,5 +219,6 @@ int perfuse_mainloop(struct puffs_usermo
 int perfuse_unmount(struct puffs_usermount *);
 void perfuse_trace_dump(struct puffs_usermount *, FILE *);
 void perfuse_fsreq(struct puffs_usermount *, perfuse_msg_t *);
+uint32_t perfuse_bufvar_from_env(const char *, uint32_t);
 
 #endif /* _PERFUSE_IF_H */



CVS commit: src/lib/libperfuse

2016-10-18 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Tue Oct 18 22:26:13 UTC 2016

Modified Files:
src/lib/libperfuse: libperfuse.3

Log Message:
Sort sections. new sentence, new line. Whitespace.


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libperfuse/libperfuse.3

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/libperfuse.3
diff -u src/lib/libperfuse/libperfuse.3:1.4 src/lib/libperfuse/libperfuse.3:1.5
--- src/lib/libperfuse/libperfuse.3:1.4	Tue Oct 18 15:06:17 2016
+++ src/lib/libperfuse/libperfuse.3	Tue Oct 18 22:26:13 2016
@@ -1,4 +1,4 @@
-.\" $NetBSD: libperfuse.3,v 1.4 2016/10/18 15:06:17 manu Exp $
+.\" $NetBSD: libperfuse.3,v 1.5 2016/10/18 22:26:13 wiz Exp $
 .\"
 .\" Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
 .\"
@@ -100,26 +100,27 @@ is different than
 .Fn perfuse_open
 handles control to the regular
 .Xr open 2 .
+.Sh RETURN VALUES
+.Fn perfuse_mount
+returns a file descriptor to the
+.Pa /dev/fuse
+socket on success, and causes exit on failure.
 .Sh ENVIRONMENT
 .Bl -tag -width Er
 .It Ev PERFUSE_OPTIONS
-Comma-separated values controlling the usage of some FUSE methods. Allowed
-values are
+Comma-separated values controlling the usage of some FUSE methods.
+Allowed values are
 .Li enable_access ,
 .Li disable_access ,
 .Li enable_creat ,
 .Li disable_creat .
 .It Ev PERFUSE_BUFSIZE
 Set the socket buffer sizes used for communication with the filesystem.
-This should be raised as operation throughput requires it. Default is 
+This should be raised as operation throughput requires it.
+Default is
 .Li 2162688
 bytes, which is enough to queue 16 FUSE packets of maximum 132 kB length.
 .El
-.Sh RETURN VALUES
-.Fn perfuse_mount
-returns a file descriptor to the
-.Pa /dev/fuse
-socket on success, and causes exit on failure.
 .\".Sh ERRORS
 .\".Fn perfuse_mount
 .\"will fail when one of the following occurs:



CVS commit: src/lib/libperfuse

2016-10-18 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Tue Oct 18 17:56:31 UTC 2016

Modified Files:
src/lib/libperfuse: fuse.h perfuse.c perfuse_if.h

Log Message:
make this compile again, and simplify.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libperfuse/fuse.h
cvs rdiff -u -r1.38 -r1.39 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.20 -r1.21 src/lib/libperfuse/perfuse_if.h

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/fuse.h
diff -u src/lib/libperfuse/fuse.h:1.6 src/lib/libperfuse/fuse.h:1.7
--- src/lib/libperfuse/fuse.h:1.6	Fri Oct 31 11:12:15 2014
+++ src/lib/libperfuse/fuse.h	Tue Oct 18 13:56:31 2016
@@ -1,4 +1,4 @@
-/*  $NetBSD: fuse.h,v 1.6 2014/10/31 15:12:15 manu Exp $ */
+/*  $NetBSD: fuse.h,v 1.7 2016/10/18 17:56:31 christos Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -34,8 +34,8 @@
 #define FUSE_UNKNOWN_FH (uint64_t)0
 
 #ifndef FUSE_BUFSIZE
-#define FUSE_MIN_BUFSIZE 0x21000
-#define FUSE_PREF_BUFSIZE (sysconf(_SC_PAGESIZE) + 0x1000)
+#define FUSE_MIN_BUFSIZE ((size_t)0x21000)
+#define FUSE_PREF_BUFSIZE ((size_t)(sysconf(_SC_PAGESIZE) + 0x1000))
 #define FUSE_BUFSIZE MAX(FUSE_PREF_BUFSIZE /* CONSTCOND */, FUSE_MIN_BUFSIZE)
 #endif /* FUSE_BUFSIZE */
 

Index: src/lib/libperfuse/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.38 src/lib/libperfuse/perfuse.c:1.39
--- src/lib/libperfuse/perfuse.c:1.38	Tue Oct 18 11:06:17 2016
+++ src/lib/libperfuse/perfuse.c	Tue Oct 18 13:56:31 2016
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.38 2016/10/18 15:06:17 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.39 2016/10/18 17:56:31 christos Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -32,6 +32,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -51,7 +52,7 @@ extern char **environ;
 
 static struct perfuse_state *init_state(void);
 static int get_fd(const char *);
-static uint32_t bufvar_from_env(const char *, const uint32_t);
+static uint32_t bufvar_from_env(const char *, uint32_t);
 
 
 static struct perfuse_state *
@@ -148,32 +149,22 @@ get_fd(const char *data)
 }
 
 static uint32_t 
-bufvar_from_env(name, defval)
-	const char *name;
-	const uint32_t defval;
+bufvar_from_env(const char *name, uint32_t defval)
 {
 	char valstr[1024];
-	uint32_t retval = defval;
+	int e;
+	uint32_t retval;
 
-	if (getenv_r(name, valstr, sizeof(valstr)) != -1) {
-		long int val;
-		char *ep;
-
-		errno = 0;
-		val = (int)strtol(valstr, &ep, 10);
-		if (*valstr == '\0' || *ep != '\0')
-			DWARNX("bad %s value \"%s\"", name, valstr);
-		else if (errno != 0)
-			DWARN("bad %s value \"%s\"", name, valstr);
-		else if (val <= 0L ||
-			 (unsigned long int)val > (unsigned long int)UINT32_MAX)
-			DWARNX("%s value %ld out of "
-			   "uint32_t bounds", name, val);
-		else
-			retval = val;
-	}
+	if (getenv_r(name, valstr, sizeof(valstr)) == -1)
+		return defval;
 
-	return retval;
+	retval = (uint32_t)strtoi(valstr, NULL, 0, 0, UINT32_MAX, &e);
+	if (!e)
+		return retval;
+
+	DWARNC(e, "conversion from `%s' to uint32_t failed, using %u",
+	valstr, defval);
+	return defval;
 }
 
 int
@@ -213,7 +204,7 @@ perfuse_open(const char *path, int flags
 	 * Set a buffer lentgh large enough so that enough FUSE packets
 	 * will fit.
 	 */
-	opt = bufvar_from_env("PERFUSE_BUFSIZE", 16 * FUSE_BUFSIZE);
+	opt = bufvar_from_env("PERFUSE_BUFSIZE", (uint32_t)(16 * FUSE_BUFSIZE));
 	optlen = sizeof(opt);
 	if (setsockopt(sv[0], SOL_SOCKET, SO_SNDBUF, &opt, optlen) != 0)
 		DWARN("%s: setsockopt SO_SNDBUF to %d failed", __func__, opt);
@@ -244,7 +235,7 @@ perfuse_open(const char *path, int flags
 	 * Set a buffer lentgh large enough so that enough FUSE packets
 	 * will fit.
 	 */
-	opt = bufvar_from_env("PERFUSE_BUFSIZE", 16 * FUSE_BUFSIZE);
+	opt = bufvar_from_env("PERFUSE_BUFSIZE", (uint32_t)(16 * FUSE_BUFSIZE));
 	optlen = sizeof(opt);
 	if (setsockopt(sv[0], SOL_SOCKET, SO_SNDBUF, &opt, optlen) != 0)
 		DWARN("%s: setsockopt SO_SNDBUF to %d failed", __func__, opt);

Index: src/lib/libperfuse/perfuse_if.h
diff -u src/lib/libperfuse/perfuse_if.h:1.20 src/lib/libperfuse/perfuse_if.h:1.21
--- src/lib/libperfuse/perfuse_if.h:1.20	Sat Jul 21 01:49:42 2012
+++ src/lib/libperfuse/perfuse_if.h	Tue Oct 18 13:56:31 2016
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_if.h,v 1.20 2012/07/21 05:49:42 manu Exp $ */
+/*  $NetBSD: perfuse_if.h,v 1.21 2016/10/18 17:56:31 christos Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -103,13 +103,20 @@ extern int perfuse_diagflags;
 } while (0 /* CONSTCOND */)
 
 #define DWARN(fmt, ...) do {		\
-	\
 	if (perfuse_diagflags & PDF_SYSLOG) \
 		syslog(LOG_WARNING, fmt ": %m", ## __VA_ARGS__);	\
 	\
 	warn(fmt, ## __VA_ARGS__);	\
 } while (0 /* CONSTCOND */)
 
+#define DWARNC(e, fmt, ...) do {	\
+	if (

CVS commit: src/lib/libperfuse

2016-01-22 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Fri Jan 22 22:25:50 UTC 2016

Modified Files:
src/lib/libperfuse: perfuse.h

Log Message:
Needs sys/cdefs.h for __BEGIN_DECLS and sys/types.h for mode_t.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libperfuse/perfuse.h

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/perfuse.h
diff -u src/lib/libperfuse/perfuse.h:1.1 src/lib/libperfuse/perfuse.h:1.2
--- src/lib/libperfuse/perfuse.h:1.1	Wed Aug 25 07:16:00 2010
+++ src/lib/libperfuse/perfuse.h	Fri Jan 22 22:25:50 2016
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.h,v 1.1 2010/08/25 07:16:00 manu Exp $ */
+/*  $NetBSD: perfuse.h,v 1.2 2016/01/22 22:25:50 dholland Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -28,6 +28,9 @@
 #ifndef _REFUSE_PERFUSE_WRAPPER_H
 #define _REFUSE_PERFUSE_WRAPPER_H
 
+#include 
+#include 
+
 __BEGIN_DECLS
 
 int perfuse_open(const char *, int, mode_t);



CVS commit: src/lib/libperfuse

2015-06-19 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Jun 19 17:33:21 UTC 2015

Modified Files:
src/lib/libperfuse: perfuse.c

Log Message:
Deal with limits properly.
Don't print strerror() 2ice.
XXX: pullup-7


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/lib/libperfuse/perfuse.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/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.36 src/lib/libperfuse/perfuse.c:1.37
--- src/lib/libperfuse/perfuse.c:1.36	Sun Feb 15 15:21:29 2015
+++ src/lib/libperfuse/perfuse.c	Fri Jun 19 13:33:20 2015
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.36 2015/02/15 20:21:29 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.37 2015/06/19 17:33:20 christos Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -391,6 +391,27 @@ perfuse_next_unique(struct puffs_usermou
 	return ps->ps_unique++;
 } 
 
+static void
+updatelimit(const char *func, int lim, const char *name)
+{
+	struct rlimit rl;
+
+	/* Try infinity but that will fail unless we are root */
+	rl.rlim_cur = RLIM_INFINITY;
+	rl.rlim_max = RLIM_INFINITY;
+	if (setrlimit(lim, &rl) != -1)
+		return;
+
+	/* Get and set to the maximum allowed */
+	if (getrlimit(lim, &rl) == -1)
+		DERR(EX_OSERR, "%s: getrlimit %s failed", func, name);
+
+	rl.rlim_cur = rl.rlim_max;
+	if (setrlimit(lim, &rl) == -1)
+		DERR(EX_OSERR, "%s: setrlimit %s to %ju failed", func,
+		name, (uintmax_t)rl.rlim_cur);
+}
+
 struct puffs_usermount *
 perfuse_init(struct perfuse_callbacks *pc, struct perfuse_mount_info *pmi)
 {
@@ -402,23 +423,12 @@ perfuse_init(struct perfuse_callbacks *p
 	unsigned int puffs_flags;
 	struct puffs_node *pn_root;
 	struct puffs_pathobj *po_root;
-	struct rlimit rl;
 
 	/*
 	 * perfused can grow quite large, let assume there's enough ram ...
 	 */
-	rl.rlim_cur = RLIM_INFINITY;
-	rl.rlim_max = RLIM_INFINITY;
-
-	if (setrlimit(RLIMIT_DATA, &rl) < 0) {
-		DERR(EX_OSERR, "%s: setrlimit failed: %s", __func__,
-		strerror(errno));
-	}
-
-	if (setrlimit(RLIMIT_AS, &rl) < 0) {
-		DERR(EX_OSERR, "%s: setrlimit failed: %s", __func__,
-		strerror(errno));
-	}
+	updatelimit(__func__, RLIMIT_DATA, "RLIMIT_DATA");
+	updatelimit(__func__, RLIMIT_AS, "RLIMIT_AS");
 
 	ps = init_state();
 	ps->ps_owner_uid = pmi->pmi_uid;



CVS commit: src/lib/libperfuse

2015-06-03 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Wed Jun  3 14:07:06 UTC 2015

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Fix dot-lookup when readdir does not provide inodes

Some filesystems do not provide inode numbers through readdir (FUSE mounts
without -o use_ino). We therefore have to lookup each directory entry to
get the missing numbers.

dot and double-dot are exceptions, as we already know the values. Moreover,
the lookup code does not expect to get requests for dot and will abort
perfused(8) when it gets some. In order to fix that, we just check for
dot and double-dot special case and use the known values instead of sending
a lookup.


To generate a diff of this commit:
cvs rdiff -u -r1.83 -r1.84 src/lib/libperfuse/ops.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.83 src/lib/libperfuse/ops.c:1.84
--- src/lib/libperfuse/ops.c:1.83	Sun Feb 15 20:21:29 2015
+++ src/lib/libperfuse/ops.c	Wed Jun  3 14:07:05 2015
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.83 2015/02/15 20:21:29 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.84 2015/06/03 14:07:05 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -651,13 +651,17 @@ fuse_to_dirent(struct puffs_usermount *p
 			struct puffs_node *pn;
 			struct perfuse_node_data *pnd = PERFUSE_NODE_DATA(opc);
 
-			/* 
-			 * Avoid breaking out of fs 
-			 * by lookup to .. on root
-			 */
-			if ((strcmp(name, "..") == 0) && 
-			(pnd->pnd_nodeid == FUSE_ROOT_ID)) {
-fd->ino = FUSE_ROOT_ID;
+			if (strcmp(name, "..") == 0) {
+/* 
+ * Avoid breaking out of fs 
+ * by lookup to .. on root
+ */
+if (pnd->pnd_nodeid == FUSE_ROOT_ID)
+	fd->ino = FUSE_ROOT_ID;
+else
+	fd->ino = pnd->pnd_parent_nodeid;
+			} else if (strcmp(name, ".") == 0 ) {
+fd->ino = pnd->pnd_nodeid;
 			} else {
 int error;
 



CVS commit: src/lib/libperfuse

2015-01-13 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue Jan 13 16:51:30 UTC 2015

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Fix atime update

FUSE filesystems assume that SETATTR with atime is the result of utiimes()
being called. As a result, atime and mtime will be updated.  This happens
with MooseFS and glusterFS. atime is supposed to be updated by the
filesystem itself when it gets read operations.

We fix the problem in SETATTR operations by
1) do not create a mtime update when we have an atime update (and vice
   versa), just fill the fields to avoid the filesystem restting the
   missing field to Epoch, but do not pretend we want to update it.
2) If the change is limited to atime, iscard it, as updates should be
   done by READ operations
3) Kernel part of PUFFS has been fixed to make sure reads on empty file
   are sent to the filesystem:
   http://mail-index.netbsd.org/source-changes/2015/01/13/msg062364.html

Thanks to Tom Ivar Helbekkmo for reporting this issue.


To generate a diff of this commit:
cvs rdiff -u -r1.81 -r1.82 src/lib/libperfuse/ops.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.81 src/lib/libperfuse/ops.c:1.82
--- src/lib/libperfuse/ops.c:1.81	Wed Nov 12 05:08:43 2014
+++ src/lib/libperfuse/ops.c	Tue Jan 13 16:51:30 2015
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.81 2014/11/12 05:08:43 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.82 2015/01/13 16:51:30 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -1785,30 +1785,27 @@ perfuse_node_setattr_ttl(struct puffs_us
 	}
 
 	/*
- 	 * Setting mtime without atime or vice versa leads to
-	 * dates being reset to Epoch on glusterfs. If one
-	 * is missing, use the old value.
+ 	 * When not sending a time field, still fill with
+	 * current value, as the filesystem may just reset
+	 * the field to Epoch even if fsi->valid bit is
+	 * not set (GlusterFS does that).
  	 */
-	if ((vap->va_mtime.tv_sec != (time_t)PUFFS_VNOVAL) || 
-	(vap->va_atime.tv_sec != (time_t)PUFFS_VNOVAL)) {
-		
-		if (vap->va_atime.tv_sec != (time_t)PUFFS_VNOVAL) {
-			fsi->atime = vap->va_atime.tv_sec;
-			fsi->atimensec = (uint32_t)vap->va_atime.tv_nsec;
-		} else {
-			fsi->atime = old_va->va_atime.tv_sec;
-			fsi->atimensec = (uint32_t)old_va->va_atime.tv_nsec;
-		}
-
-		if (vap->va_mtime.tv_sec != (time_t)PUFFS_VNOVAL) {
-			fsi->mtime = vap->va_mtime.tv_sec;
-			fsi->mtimensec = (uint32_t)vap->va_mtime.tv_nsec;
-		} else {
-			fsi->mtime = old_va->va_mtime.tv_sec;
-			fsi->mtimensec = (uint32_t)old_va->va_mtime.tv_nsec;
-		}
+	if (vap->va_atime.tv_sec != (time_t)PUFFS_VNOVAL) {
+		fsi->atime = vap->va_atime.tv_sec;
+		fsi->atimensec = (uint32_t)vap->va_atime.tv_nsec;
+		fsi->valid |= FUSE_FATTR_ATIME;
+	} else {
+		fsi->atime = old_va->va_atime.tv_sec;
+		fsi->atimensec = (uint32_t)old_va->va_atime.tv_nsec;
+	}
 
-		fsi->valid |= (FUSE_FATTR_MTIME|FUSE_FATTR_ATIME);
+	if (vap->va_mtime.tv_sec != (time_t)PUFFS_VNOVAL) {
+		fsi->mtime = vap->va_mtime.tv_sec;
+		fsi->mtimensec = (uint32_t)vap->va_mtime.tv_nsec;
+		fsi->valid |= FUSE_FATTR_MTIME;
+	} else {
+		fsi->mtime = old_va->va_mtime.tv_sec;
+		fsi->mtimensec = (uint32_t)old_va->va_mtime.tv_nsec;
 	}
 
 	if (vap->va_mode != (mode_t)PUFFS_VNOVAL) {
@@ -1851,6 +1848,14 @@ perfuse_node_setattr_ttl(struct puffs_us
 		fsi->mtimensec = 0;
 		fsi->valid &= ~(FUSE_FATTR_ATIME|FUSE_FATTR_MTIME);
 	}
+
+	/*
+	 * If only atime is changed, discard the operation: it
+	 * happens after read, and in that case the filesystem 
+	 * already updaed atime. NB: utimes() also change mtime.
+	 */
+	if (fsi->valid == FUSE_FATTR_ATIME)
+		fsi->valid &= ~FUSE_FATTR_ATIME;
 		
 	/*
 	 * If nothing remain, discard the operation.



CVS commit: src/lib/libperfuse

2014-11-11 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Wed Nov 12 05:08:44 UTC 2014

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Allow setxattr to be called with a NULL value, instead of crashing.


To generate a diff of this commit:
cvs rdiff -u -r1.80 -r1.81 src/lib/libperfuse/ops.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.80 src/lib/libperfuse/ops.c:1.81
--- src/lib/libperfuse/ops.c:1.80	Tue Nov  4 09:17:31 2014
+++ src/lib/libperfuse/ops.c	Wed Nov 12 05:08:43 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.80 2014/11/04 09:17:31 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.81 2014/11/12 05:08:43 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -3460,6 +3460,7 @@ perfuse_node_setextattr(struct puffs_use
 	perfuse_msg_t *pm;
 	struct fuse_setxattr_in *fsi;
 	size_t attrnamelen;
+	size_t datalen;
 	size_t len;
 	char *np;
 	int error;
@@ -3472,23 +3473,27 @@ perfuse_node_setextattr(struct puffs_use
 	ps = puffs_getspecific(pu);
 	attrname = perfuse_native_ns(attrns, attrname, fuse_attrname);
 	attrnamelen = strlen(attrname) + 1;
-	len = sizeof(*fsi) + attrnamelen + *resid;
+
+	datalen = (resid != NULL) ? *resid : 0;
+	len = sizeof(*fsi) + attrnamelen + datalen;
 
 	pm = ps->ps_new_msg(pu, opc, FUSE_SETXATTR, len, pcr);
 	fsi = GET_INPAYLOAD(ps, pm, fuse_setxattr_in);
-	fsi->size = (unsigned int)*resid;
+	fsi->size = (unsigned int)datalen;
 	fsi->flags = 0;
 	np = (char *)(void *)(fsi + 1);
 	(void)strlcpy(np, attrname, attrnamelen);
 	np += attrnamelen;
-	(void)memcpy(np, (char *)attr, *resid);
+	if (datalen)
+		(void)memcpy(np, (char *)attr, datalen);
 
 	if ((error = xchg_msg(pu, opc, pm, 
 			  NO_PAYLOAD_REPLY_LEN, wait_reply)) != 0)
 		goto out;
 
 	ps->ps_destroy_msg(pm);
-	*resid = 0;
+	if (resid)
+		*resid = 0;
 	error = 0;
 
 out:



CVS commit: src/lib/libperfuse

2014-11-04 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue Nov  4 09:17:32 UTC 2014

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Restore build with -DDEBUG, and avoid a spurious diagnostic error with -DDEBUG


To generate a diff of this commit:
cvs rdiff -u -r1.79 -r1.80 src/lib/libperfuse/ops.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.79 src/lib/libperfuse/ops.c:1.80
--- src/lib/libperfuse/ops.c:1.79	Fri Oct 31 15:20:08 2014
+++ src/lib/libperfuse/ops.c	Tue Nov  4 09:17:31 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.79 2014/10/31 15:20:08 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.80 2014/11/04 09:17:31 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -813,11 +813,6 @@ requeue_request(struct puffs_usermount *
 {
 	struct perfuse_cc_queue pcq;
 	struct perfuse_node_data *pnd;
-#ifdef PERFUSE_DEBUG
-	struct perfuse_state *ps;
-
-	ps = perfuse_getspecific(pu);
-#endif
 
 	pnd = PERFUSE_NODE_DATA(opc);
 	pcq.pcq_type = type;
@@ -2821,11 +2816,11 @@ perfuse_node_inactive(struct puffs_userm
 	if (opc == 0)
 		return 0;
 
-	node_ref(opc);
 	pnd = PERFUSE_NODE_DATA(opc);
-
 	if (!(pnd->pnd_flags & (PND_OPEN|PND_REMOVED)))
-		goto out;
+		return 0;
+
+	node_ref(opc);
 
 	/*
 	 * Make sure all operation are finished



CVS commit: src/lib/libperfuse

2014-10-31 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Fri Oct 31 15:20:08 UTC 2014

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Avoid deadlocks on write errors

On write errors, we failed to dequeue some operations, leading to
rare but unpleasant deadlocks


To generate a diff of this commit:
cvs rdiff -u -r1.78 -r1.79 src/lib/libperfuse/ops.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.78 src/lib/libperfuse/ops.c:1.79
--- src/lib/libperfuse/ops.c:1.78	Fri Oct 31 15:12:15 2014
+++ src/lib/libperfuse/ops.c	Fri Oct 31 15:20:08 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.78 2014/10/31 15:12:15 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.79 2014/10/31 15:20:08 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -3299,6 +3299,7 @@ perfuse_node_write2(struct puffs_usermou
 	if (*resid != 0)
 		error = EFBIG;
 
+out:
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & PDF_RESIZE) {
 		if (offset > (off_t)vap->va_size)
@@ -3315,16 +3316,6 @@ perfuse_node_write2(struct puffs_usermou
 	if (offset > (off_t)vap->va_size) 
 		vap->va_size = offset;
 
-	if (inresize) {
-#ifdef PERFUSE_DEBUG
-		if (!(pnd->pnd_flags & PND_INRESIZE))
-			DERRX(EX_SOFTWARE, "file write grow without resize");
-#endif
-		pnd->pnd_flags &= ~PND_INRESIZE;
-		(void)dequeue_requests(opc, PCQ_RESIZE, DEQUEUE_ALL);
-	}
-
-
 	/*
 	 * Statistics
 	 */
@@ -3344,7 +3335,15 @@ perfuse_node_write2(struct puffs_usermou
 			__func__, (void*)opc, perfuse_node_path(ps, opc));
 #endif
 
-out:
+	if (inresize) {
+#ifdef PERFUSE_DEBUG
+		if (!(pnd->pnd_flags & PND_INRESIZE))
+			DERRX(EX_SOFTWARE, "file write grow without resize");
+#endif
+		pnd->pnd_flags &= ~PND_INRESIZE;
+		(void)dequeue_requests(opc, PCQ_RESIZE, DEQUEUE_ALL);
+	}
+
 	/*
 	 * VOP_PUTPAGE causes FAF write where kernel does not 
 	 * check operation result. At least warn if it failed.



CVS commit: src/lib/libperfuse

2014-10-31 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Fri Oct 31 15:12:15 UTC 2014

Modified Files:
src/lib/libperfuse: fuse.h ops.c perfuse.c perfuse_priv.h

Log Message:
FUSE fallocate support
There seems to be no fdiscard FUSE operation at the moment, hence that one
is left unused.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libperfuse/fuse.h
cvs rdiff -u -r1.77 -r1.78 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.34 -r1.35 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.35 -r1.36 src/lib/libperfuse/perfuse_priv.h

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/fuse.h
diff -u src/lib/libperfuse/fuse.h:1.5 src/lib/libperfuse/fuse.h:1.6
--- src/lib/libperfuse/fuse.h:1.5	Wed Dec 28 17:33:53 2011
+++ src/lib/libperfuse/fuse.h	Fri Oct 31 15:12:15 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: fuse.h,v 1.5 2011/12/28 17:33:53 manu Exp $ */
+/*  $NetBSD: fuse.h,v 1.6 2014/10/31 15:12:15 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -169,6 +169,9 @@ enum fuse_opcode {
 	FUSE_DESTROY   = 38,
 	FUSE_IOCTL = 39,
 	FUSE_POLL  = 40,
+	FUSE_NOTIFY_REPLY  = 41,
+	FUSE_BATCH_FORGET  = 42,
+	FUSE_FALLOCATE = 43,
 	FUSE_OPCODE_MAX,
 
 	FUSE_CUSE_INIT = 4096
@@ -441,6 +444,14 @@ struct fuse_notify_poll_wakeup_out {
 	uint64_t	kh;
 };
 
+struct fuse_fallocate_in {
+	uint64_t	fh;
+	uint64_t	offset;
+	uint64_t	length;
+	uint32_t	mode;
+	uint32_t	padding;
+};
+
 #if 0 /* Duplicated in perfuse.h to avoid making fuse.h public */
 /* Send from kernel to proces */
 struct fuse_in_header {

Index: src/lib/libperfuse/ops.c
diff -u src/lib/libperfuse/ops.c:1.77 src/lib/libperfuse/ops.c:1.78
--- src/lib/libperfuse/ops.c:1.77	Tue Oct 28 16:54:11 2014
+++ src/lib/libperfuse/ops.c	Fri Oct 31 15:12:15 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.77 2014/10/28 16:54:11 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.78 2014/10/31 15:12:15 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -3635,8 +3635,47 @@ perfuse_node_deleteextattr(struct puffs_
 	error = xchg_msg(pu, opc, pm, NO_PAYLOAD_REPLY_LEN, wait_reply);
 	if (error != 0)
 		goto out;
+		
+	ps->ps_destroy_msg(pm);
+
+out:
+	node_rele(opc);
+	return error;
+}
+
+int
+perfuse_node_fallocate(struct puffs_usermount *pu, puffs_cookie_t opc,
+	off_t off, off_t len)
+{
+	struct perfuse_state *ps;
+	perfuse_msg_t *pm;
+	struct fuse_fallocate_in *fai;
+	int error;
 	
+	ps = puffs_getspecific(pu);
+	if (ps->ps_flags & PS_NO_FALLOCATE)
+		return EOPNOTSUPP;
+
+	node_ref(opc);
+
+	pm = ps->ps_new_msg(pu, opc, FUSE_FALLOCATE, sizeof(*fai), NULL);
+
+	fai = GET_INPAYLOAD(ps, pm, fuse_fallocate_in);
+	fai->fh = perfuse_get_fh(opc, FWRITE);
+	fai->offset = off;
+	fai->length = len;
+	fai->mode = 0;
+		
+	error = xchg_msg(pu, opc, pm, NO_PAYLOAD_REPLY_LEN, wait_reply);
+	if (error == EOPNOTSUPP || error == ENOSYS) {
+		ps->ps_flags |= PS_NO_FALLOCATE;
+		error = EOPNOTSUPP;
+	}
+	if (error != 0)
+		goto out;
+		
 	ps->ps_destroy_msg(pm);
+
 out:
 	node_rele(opc);
 	return error;

Index: src/lib/libperfuse/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.34 src/lib/libperfuse/perfuse.c:1.35
--- src/lib/libperfuse/perfuse.c:1.34	Wed Sep  3 16:01:45 2014
+++ src/lib/libperfuse/perfuse.c	Fri Oct 31 15:12:15 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.34 2014/09/03 16:01:45 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.35 2014/10/31 15:12:15 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -503,6 +503,9 @@ perfuse_init(struct perfuse_callbacks *p
 #ifdef PUFFS_OPEN_IO_DIRECT 
 	PUFFSOP_SET(pops, perfuse, node, open2);
 #endif /* PUFFS_OPEN_IO_DIRECT */
+#ifdef PUFFS_HAVE_FALLOCATE
+	PUFFSOP_SET(pops, perfuse, node, fallocate);
+#endif /* PUFFS_HAVE_FALLOCATE */
 
 	/*
 	 * PUFFS_KFLAG_NOCACHE_NAME is required so that we can see changes

Index: src/lib/libperfuse/perfuse_priv.h
diff -u src/lib/libperfuse/perfuse_priv.h:1.35 src/lib/libperfuse/perfuse_priv.h:1.36
--- src/lib/libperfuse/perfuse_priv.h:1.35	Wed Sep  3 23:59:58 2014
+++ src/lib/libperfuse/perfuse_priv.h	Fri Oct 31 15:12:15 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_priv.h,v 1.35 2014/09/03 23:59:58 enami Exp $ */
+/*  $NetBSD: perfuse_priv.h,v 1.36 2014/10/31 15:12:15 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -67,6 +67,7 @@ struct perfuse_state {
 #define PS_NO_ACCESS	0x0001	/* access is unimplemented; */
 #define PS_NO_CREAT	0x0004	/* create is unimplemented */
 #define PS_INLOOP	0x0008	/* puffs mainloop started */
+#define PS_NO_FALLOCATE	0x0010	/* fallocate is unimplemented */
 	uint64_t ps_fsid;
 	uint32_t ps_max_readahead;
 	uint32_t ps_max_write;
@@ -277,6 +278,8 @@ int perfuse_node_getattr_ttl(struct puff
 int perfuse_node_setattr_ttl(struct puffs_usermount *,
 puffs_cookie_t, struct vattr *, const struct puffs_c

CVS commit: src/lib/libperfuse

2014-10-28 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue Oct 28 16:54:11 UTC 2014

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Fix invalid free in deletextattr FUSE handler

Do not free FUSE message on error as it was not allocated.


To generate a diff of this commit:
cvs rdiff -u -r1.76 -r1.77 src/lib/libperfuse/ops.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.76 src/lib/libperfuse/ops.c:1.77
--- src/lib/libperfuse/ops.c:1.76	Sat Oct 11 04:19:38 2014
+++ src/lib/libperfuse/ops.c	Tue Oct 28 16:54:11 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.76 2014/10/11 04:19:38 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.77 2014/10/28 16:54:11 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -3633,9 +3633,11 @@ perfuse_node_deleteextattr(struct puffs_
 	(void)strlcpy(np, attrname, attrnamelen);
 	
 	error = xchg_msg(pu, opc, pm, NO_PAYLOAD_REPLY_LEN, wait_reply);
+	if (error != 0)
+		goto out;
 	
 	ps->ps_destroy_msg(pm);
-
+out:
 	node_rele(opc);
 	return error;
 }



CVS commit: src/lib/libperfuse

2014-10-10 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sat Oct 11 04:19:38 UTC 2014

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Report allocated bytes on FS correctly, instead of using file size
(which is wrong for sparse files)


To generate a diff of this commit:
cvs rdiff -u -r1.75 -r1.76 src/lib/libperfuse/ops.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.75 src/lib/libperfuse/ops.c:1.76
--- src/lib/libperfuse/ops.c:1.75	Tue Sep 30 00:06:19 2014
+++ src/lib/libperfuse/ops.c	Sat Oct 11 04:19:38 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.75 2014/09/30 00:06:19 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.76 2014/10/11 04:19:38 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -321,7 +321,7 @@ fuse_attr_to_vap(struct perfuse_state *p
 	vap->va_gen = 0; 
 	vap->va_flags = 0;
 	vap->va_rdev = fa->rdev;
-	vap->va_bytes = fa->size;
+	vap->va_bytes = fa->blocks * S_BLKSIZE;
 	vap->va_filerev = (u_quad_t)PUFFS_VNOVAL;
 	vap->va_vaflags = 0;
 



CVS commit: src/lib/libperfuse

2014-09-29 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue Sep 30 00:06:19 UTC 2014

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Do not trust the filesystem's readdir to give us nul-terminated file names


To generate a diff of this commit:
cvs rdiff -u -r1.74 -r1.75 src/lib/libperfuse/ops.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.74 src/lib/libperfuse/ops.c:1.75
--- src/lib/libperfuse/ops.c:1.74	Thu Sep 11 04:05:52 2014
+++ src/lib/libperfuse/ops.c	Tue Sep 30 00:06:19 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.74 2014/09/11 04:05:52 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.75 2014/09/30 00:06:19 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -607,6 +607,7 @@ fuse_to_dirent(struct puffs_usermount *p
 	do {
 		char *ndp;
 		size_t reclen;
+		char name[MAXPATHLEN];
 
 		reclen = _DIRENT_RECLEN(dents, fd->namelen);
 
@@ -639,6 +640,9 @@ fuse_to_dirent(struct puffs_usermount *p
 			dents = (struct dirent *)(void *)ndp;
 		}
 		
+		strncpy(name, fd->name, fd->namelen);
+		name[fd->namelen] = '\0';
+
 		/*
 		 * Filesystem was mounted without -o use_ino
 		 * Perform a lookup to find it.
@@ -651,13 +655,17 @@ fuse_to_dirent(struct puffs_usermount *p
 			 * Avoid breaking out of fs 
 			 * by lookup to .. on root
 			 */
-			if ((strcmp(fd->name, "..") == 0) && 
+			if ((strcmp(name, "..") == 0) && 
 			(pnd->pnd_nodeid == FUSE_ROOT_ID)) {
 fd->ino = FUSE_ROOT_ID;
 			} else {
-if (node_lookup_common(pu, opc, NULL, fd->name,
-		   NULL, &pn) != 0) {
-	DWARNX("node_lookup_common failed");
+int error;
+
+error = node_lookup_common(pu, opc, NULL, 
+			   name, NULL, &pn);
+if (error != 0) {
+	DWARNX("node_lookup_common %s "
+	   "failed: %d", name, error);
 } else {
 	fd->ino = pn->pn_va.va_fileid;
 	(void)perfuse_node_reclaim(pu, pn);
@@ -669,7 +677,7 @@ fuse_to_dirent(struct puffs_usermount *p
 		dents->d_reclen = (unsigned short)reclen;
 		dents->d_namlen = fd->namelen;
 		dents->d_type = fd->type;
-		strlcpy(dents->d_name, fd->name, fd->namelen + 1);
+		strlcpy(dents->d_name, name, fd->namelen + 1);
 
 #ifdef PERFUSE_DEBUG
 		if (perfuse_diagflags & PDF_READDIR)
@@ -720,7 +728,7 @@ fuse_to_dirent(struct puffs_usermount *p
 	 */
 	if (written != -1)
 		PERFUSE_NODE_DATA(opc)->pnd_dirent_len = written;
-	
+
 	return written;
 }
 



CVS commit: src/lib/libperfuse

2014-09-10 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Thu Sep 11 04:05:52 UTC 2014

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Avoid a file resize serialization deadlock when writing with
PUFFS_IO_APPEND flag. The symptom was a hang when appending to
a file with a null size.


To generate a diff of this commit:
cvs rdiff -u -r1.73 -r1.74 src/lib/libperfuse/ops.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.73 src/lib/libperfuse/ops.c:1.74
--- src/lib/libperfuse/ops.c:1.73	Fri Sep  5 15:20:16 2014
+++ src/lib/libperfuse/ops.c	Thu Sep 11 04:05:52 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.73 2014/09/05 15:20:16 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.74 2014/09/11 04:05:52 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -3198,16 +3198,6 @@ perfuse_node_write2(struct puffs_usermou
 		requeue_request(pu, opc, PCQ_WRITE);
 	pnd->pnd_flags |= PND_INWRITE;
 
-	/* 
-	 * Serialize size access, see comment in perfuse_node_setattr().
-	 */
-	if ((u_quad_t)offset + *resid > vap->va_size) {
-		while (pnd->pnd_flags & PND_INRESIZE)
-			requeue_request(pu, opc, PCQ_RESIZE);
-		pnd->pnd_flags |= PND_INRESIZE;
-		inresize = 1;
-	}
-
 	/*
 	 * append flag: re-read the file size so that 
 	 * we get the latest value.
@@ -3219,6 +3209,16 @@ perfuse_node_write2(struct puffs_usermou
 		offset = vap->va_size;
 	}
 
+	/* 
+	 * Serialize size access, see comment in perfuse_node_setattr().
+	 */
+	if ((u_quad_t)offset + *resid > vap->va_size) {
+		while (pnd->pnd_flags & PND_INRESIZE)
+			requeue_request(pu, opc, PCQ_RESIZE);
+		pnd->pnd_flags |= PND_INRESIZE;
+		inresize = 1;
+	}
+
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & PDF_RESIZE)
 		DPRINTF(">> %s %p %" PRIu64 "\n", __func__,



CVS commit: src/lib/libperfuse

2014-09-05 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Fri Sep  5 15:20:17 UTC 2014

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
rmdir dir/.. must return an error. Use ENOTEMPRY like FFS does.


To generate a diff of this commit:
cvs rdiff -u -r1.72 -r1.73 src/lib/libperfuse/ops.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.72 src/lib/libperfuse/ops.c:1.73
--- src/lib/libperfuse/ops.c:1.72	Wed Sep  3 23:59:58 2014
+++ src/lib/libperfuse/ops.c	Fri Sep  5 15:20:16 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.72 2014/09/03 23:59:58 enami Exp $ */
+/*  $NetBSD: ops.c,v 1.73 2014/09/05 15:20:16 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -2352,6 +2352,12 @@ perfuse_node_rmdir(struct puffs_usermoun
 	(PERFUSE_NODE_DATA(targ)->pnd_flags & PND_REMOVED))
 		return ENOENT;
 
+	/*
+	 * Attempt to rmdir dir/.. shoud raise ENOTEMPTY
+	 */
+	if (PERFUSE_NODE_DATA(targ)->pnd_nodeid == pnd->pnd_parent_nodeid)
+		return ENOTEMPTY;
+
 	node_ref(opc);
 	node_ref(targ);
 



CVS commit: src/lib/libperfuse

2014-09-03 Thread enami tsugutomo
Module Name:src
Committed By:   enami
Date:   Wed Sep  3 23:59:58 UTC 2014

Modified Files:
src/lib/libperfuse: ops.c perfuse_priv.h

Log Message:
Fix build failure on amd64.


To generate a diff of this commit:
cvs rdiff -u -r1.71 -r1.72 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.34 -r1.35 src/lib/libperfuse/perfuse_priv.h

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.71 src/lib/libperfuse/ops.c:1.72
--- src/lib/libperfuse/ops.c:1.71	Wed Sep  3 16:01:45 2014
+++ src/lib/libperfuse/ops.c	Wed Sep  3 23:59:58 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.71 2014/09/03 16:01:45 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.72 2014/09/03 23:59:58 enami Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -2888,7 +2888,7 @@ perfuse_node_print(struct puffs_usermoun
 
 int
 perfuse_node_pathconf(struct puffs_usermount *pu, puffs_cookie_t opc,
-	int name, int *retval)
+	int name, register_t *retval)
 {
 	perfuse_msg_t *pm;
 	struct perfuse_state *ps;

Index: src/lib/libperfuse/perfuse_priv.h
diff -u src/lib/libperfuse/perfuse_priv.h:1.34 src/lib/libperfuse/perfuse_priv.h:1.35
--- src/lib/libperfuse/perfuse_priv.h:1.34	Sat Aug 16 16:31:15 2014
+++ src/lib/libperfuse/perfuse_priv.h	Wed Sep  3 23:59:58 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_priv.h,v 1.34 2014/08/16 16:31:15 manu Exp $ */
+/*  $NetBSD: perfuse_priv.h,v 1.35 2014/09/03 23:59:58 enami Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -249,7 +249,7 @@ int perfuse_node_reclaim(struct puffs_us
 int perfuse_node_inactive(struct puffs_usermount *, puffs_cookie_t);
 int perfuse_node_print(struct puffs_usermount *, puffs_cookie_t);
 int perfuse_node_pathconf(struct puffs_usermount *,
-puffs_cookie_t, int, int *);
+puffs_cookie_t, int, register_t *);
 int perfuse_node_advlock(struct puffs_usermount *,
 puffs_cookie_t, void *, int, struct flock *, int);
 int perfuse_node_read(struct puffs_usermount *, puffs_cookie_t,



CVS commit: src/lib/libperfuse

2014-09-03 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Wed Sep  3 16:01:45 UTC 2014

Modified Files:
src/lib/libperfuse: ops.c perfuse.c

Log Message:
Improve POSIX compliance of FUSE filesystems through PERUSE
- access denied is EPERM and not EACCES
- access to file owned by someone else in a sticy-bit directory should
  be allowed for the sticy-bit directory owner
- setting sticky-bit on a non directory should produce EFTYPE
- implement PATHCONF method as much as we can.


To generate a diff of this commit:
cvs rdiff -u -r1.70 -r1.71 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.33 -r1.34 src/lib/libperfuse/perfuse.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.70 src/lib/libperfuse/ops.c:1.71
--- src/lib/libperfuse/ops.c:1.70	Fri Aug 29 04:58:40 2014
+++ src/lib/libperfuse/ops.c	Wed Sep  3 16:01:45 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.70 2014/08/29 04:58:40 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.71 2014/09/03 16:01:45 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -269,7 +269,7 @@ sticky_access(puffs_cookie_t opc, struct
 	  const struct puffs_cred *pcr)
 {
 	uid_t uid;
-	int sticky, owner;
+	int sticky, owner, parent_owner;
 
 	/*
 	 * This covers the case where the kernel requests a DELETE
@@ -288,9 +288,10 @@ sticky_access(puffs_cookie_t opc, struct
 
 	sticky = puffs_pn_getvap(opc)->va_mode & S_ISTXT;
 	owner = puffs_pn_getvap(targ)->va_uid == uid;
+	parent_owner = puffs_pn_getvap(opc)->va_uid == uid;
 
-	if (sticky && !owner)
-		return EACCES;
+	if (sticky && !owner && !parent_owner)
+		return EPERM;
 
 	return 0;
 }
@@ -1305,7 +1306,7 @@ perfuse_node_mknod(struct puffs_usermoun
 		break;
 	default:	/* VNON, VBLK, VCHR, VBAD */
 		if (!puffs_cred_isjuggernaut(pcn->pcn_cred)) {
-			error = EACCES;
+			error = EPERM;
 			goto out;
 		}
 		break;
@@ -1696,7 +1697,7 @@ perfuse_node_setattr_ttl(struct puffs_us
 	 (vap->va_mtime.tv_sec != (time_t)PUFFS_VNOVAL)) &&
 	(puffs_access_times(old_va->va_uid, old_va->va_gid,
 old_va->va_mode, 0, pcr) != 0))
-		return EACCES;
+		return EPERM;
 
 	/*
 	 * Check for permission to change owner and group
@@ -1705,7 +1706,15 @@ perfuse_node_setattr_ttl(struct puffs_us
 	 (vap->va_gid != (gid_t)PUFFS_VNOVAL)) &&
 	(puffs_access_chown(old_va->va_uid, old_va->va_gid,
 vap->va_uid, vap->va_gid, pcr)) != 0)
-		return EACCES;
+		return EPERM;
+
+	/*
+	 * Check for sticky bit on non-directory by non root user
+	 */
+	if ((vap->va_mode != (mode_t)PUFFS_VNOVAL) &&
+	(vap->va_mode & S_ISTXT) && (old_va->va_type != VDIR) &&
+	!puffs_cred_isjuggernaut(pcr))
+		return EFTYPE;
 
 	/*
 	 * Check for permission to change permissions
@@ -1713,7 +1722,7 @@ perfuse_node_setattr_ttl(struct puffs_us
 	if ((vap->va_mode != (mode_t)PUFFS_VNOVAL) &&
 	(puffs_access_chmod(old_va->va_uid, old_va->va_gid,
 old_va->va_type, vap->va_mode, pcr)) != 0)
-		return EACCES;
+		return EPERM;
 	
 	node_ref(opc);
 	
@@ -2877,13 +2886,68 @@ perfuse_node_print(struct puffs_usermoun
 	return 0;
 }
 
-/* ARGSUSED0 */
 int
 perfuse_node_pathconf(struct puffs_usermount *pu, puffs_cookie_t opc,
 	int name, int *retval)
 {
-	DERRX(EX_SOFTWARE, "%s: UNIMPLEMENTED (FATAL)", __func__);
-	return 0;
+	perfuse_msg_t *pm;
+	struct perfuse_state *ps;
+	struct fuse_statfs_out *fso;
+	int error = 0;
+
+	/*
+	 * Static values copied from UFS 
+	 * in src/sys/ufs/ufs/ufs_vnops.c
+	 */
+	switch (name) {
+	case _PC_LINK_MAX:
+		*retval = LINK_MAX;
+		break;
+	case _PC_PATH_MAX:
+		*retval = PATH_MAX;
+		break;
+	case _PC_PIPE_BUF:
+		*retval = PIPE_BUF;
+		break;
+	case _PC_CHOWN_RESTRICTED:
+		*retval = 1;
+		break;
+	case _PC_NO_TRUNC:
+		*retval = 1;
+		break;
+	case _PC_SYNC_IO:
+		*retval = 1;
+		break;
+	case _PC_FILESIZEBITS:
+		*retval = 42;
+		break;
+	case _PC_SYMLINK_MAX:
+		*retval = MAXPATHLEN;
+		break;
+	case _PC_2_SYMLINKS:
+		*retval = 1;
+		break;
+	case _PC_NAME_MAX:
+		ps = puffs_getspecific(pu);
+		pm = ps->ps_new_msg(pu, opc, FUSE_STATFS, 0, NULL);
+
+		error = xchg_msg(pu, opc, pm, sizeof(*fso), wait_reply);
+		if (error != 0)
+			return error;
+
+		fso = GET_OUTPAYLOAD(ps, pm, fuse_statfs_out);
+		*retval = fso->st.namelen;
+
+		ps->ps_destroy_msg(pm);
+	
+		break;
+	default:
+		DWARN("Unimplemented pathconf for name = %d", name);
+		error = ENOSYS;
+		break;
+	}
+
+	return error;
 }
 
 int

Index: src/lib/libperfuse/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.33 src/lib/libperfuse/perfuse.c:1.34
--- src/lib/libperfuse/perfuse.c:1.33	Sat Aug 16 16:31:15 2014
+++ src/lib/libperfuse/perfuse.c	Wed Sep  3 16:01:45 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.33 2014/08/16 16:31:15 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.34 2014/09/03 16:01:45 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -483,6 +483,7 

CVS commit: src/lib/libperfuse

2014-08-28 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Fri Aug 29 04:58:40 UTC 2014

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
We used to remove the trailing zeros in FUSE readlink replies, but
it seems it does not always happen. Just remove them if present.


To generate a diff of this commit:
cvs rdiff -u -r1.69 -r1.70 src/lib/libperfuse/ops.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.69 src/lib/libperfuse/ops.c:1.70
--- src/lib/libperfuse/ops.c:1.69	Tue Aug 19 15:29:14 2014
+++ src/lib/libperfuse/ops.c	Fri Aug 29 04:58:40 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.69 2014/08/19 15:29:14 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.70 2014/08/29 04:58:40 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -2633,12 +2633,16 @@ perfuse_node_readlink(struct puffs_userm
 	if (len == 0)
 		DERRX(EX_PROTOCOL, "path len = %zd too short", len);
 		
+	(void)memcpy(linkname, _GET_OUTPAYLOAD(ps, pm, char *), len);
+
 	/*
 	 * FUSE filesystems return a NUL terminated string, we 
-	 * do not want to trailing \0
+	 * do not want the trailing \0
 	 */
-	*linklen = len - 1;
-	(void)memcpy(linkname, _GET_OUTPAYLOAD(ps, pm, char *), len);
+	while (len > 0 && linkname[len - 1] == '\0')
+		len--;
+
+	*linklen = len;
 
 	ps->ps_destroy_msg(pm);
 	error = 0;



CVS commit: src/lib/libperfuse

2014-08-19 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue Aug 19 15:29:14 UTC 2014

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Remove usless warning that happens often with direct IO


To generate a diff of this commit:
cvs rdiff -u -r1.68 -r1.69 src/lib/libperfuse/ops.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.68 src/lib/libperfuse/ops.c:1.69
--- src/lib/libperfuse/ops.c:1.68	Sat Aug 16 16:31:15 2014
+++ src/lib/libperfuse/ops.c	Tue Aug 19 15:29:14 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.68 2014/08/16 16:31:15 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.69 2014/08/19 15:29:14 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -3139,8 +3139,6 @@ perfuse_node_write2(struct puffs_usermou
 	 * we get the latest value.
 	 */
 	if (ioflag & PUFFS_IO_APPEND) {
-		DWARNX("%s: PUFFS_IO_APPEND set, untested code", __func__);
-
 		if ((error = perfuse_node_getattr(pu, opc, vap, pcr)) != 0)
 			goto out;
 



CVS commit: src/lib/libperfuse

2014-08-16 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sat Aug 16 16:31:16 UTC 2014

Modified Files:
src/lib/libperfuse: ops.c perfuse.c perfuse_priv.h

Log Message:
Removed unimplemented mmap and seek method. seek's declaration caused
seek request to be passed backand forth between kernel and userland
while we did nothing about them.


To generate a diff of this commit:
cvs rdiff -u -r1.67 -r1.68 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.32 -r1.33 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.33 -r1.34 src/lib/libperfuse/perfuse_priv.h

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.67 src/lib/libperfuse/ops.c:1.68
--- src/lib/libperfuse/ops.c:1.67	Sat Aug 16 16:28:43 2014
+++ src/lib/libperfuse/ops.c	Sat Aug 16 16:31:15 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.67 2014/08/16 16:28:43 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.68 2014/08/16 16:31:15 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -1960,17 +1960,6 @@ out:
 	return error;
 }
 
-/* ARGSUSED0 */
-int
-perfuse_node_mmap(struct puffs_usermount *pu, puffs_cookie_t opc, int flags,
-	const struct puffs_cred *pcr)
-{
-	/* 
-	 * Not implemented anymore in libfuse
-	 */
-	return ENOSYS;
-}
-
 /* ARGSUSED2 */
 int
 perfuse_node_fsync(struct puffs_usermount *pu, puffs_cookie_t opc,
@@ -2085,14 +2074,6 @@ out:
 	return error;
 }
 
-/* ARGSUSED0 */
-int
-perfuse_node_seek(struct puffs_usermount *pu, puffs_cookie_t opc,
-	off_t oldoff, off_t newoff, const struct puffs_cred *pcr)
-{
-	return 0;
-}
-
 int
 perfuse_node_remove(struct puffs_usermount *pu, puffs_cookie_t opc,
 	puffs_cookie_t targ, const struct puffs_cn *pcn)

Index: src/lib/libperfuse/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.32 src/lib/libperfuse/perfuse.c:1.33
--- src/lib/libperfuse/perfuse.c:1.32	Sat Aug 16 16:28:43 2014
+++ src/lib/libperfuse/perfuse.c	Sat Aug 16 16:31:15 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.32 2014/08/16 16:28:43 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.33 2014/08/16 16:31:15 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -471,11 +471,7 @@ perfuse_init(struct perfuse_callbacks *p
 	PUFFSOP_SET(pops, perfuse, node, getattr);
 	PUFFSOP_SET(pops, perfuse, node, setattr);
 	PUFFSOP_SET(pops, perfuse, node, poll);
-#if 0 
-	PUFFSOP_SET(pops, perfuse, node, mmap);
-#endif
 	PUFFSOP_SET(pops, perfuse, node, fsync);
-	PUFFSOP_SET(pops, perfuse, node, seek);
 	PUFFSOP_SET(pops, perfuse, node, remove);
 	PUFFSOP_SET(pops, perfuse, node, link);
 	PUFFSOP_SET(pops, perfuse, node, rename);

Index: src/lib/libperfuse/perfuse_priv.h
diff -u src/lib/libperfuse/perfuse_priv.h:1.33 src/lib/libperfuse/perfuse_priv.h:1.34
--- src/lib/libperfuse/perfuse_priv.h:1.33	Sat Aug 16 16:28:43 2014
+++ src/lib/libperfuse/perfuse_priv.h	Sat Aug 16 16:31:15 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_priv.h,v 1.33 2014/08/16 16:28:43 manu Exp $ */
+/*  $NetBSD: perfuse_priv.h,v 1.34 2014/08/16 16:31:15 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -223,12 +223,8 @@ int perfuse_node_getattr(struct puffs_us
 int perfuse_node_setattr(struct puffs_usermount *,
 puffs_cookie_t, const struct vattr *, const struct puffs_cred *);
 int perfuse_node_poll(struct puffs_usermount *, puffs_cookie_t, int *);
-int perfuse_node_mmap(struct puffs_usermount *,
-puffs_cookie_t, vm_prot_t, const struct puffs_cred *);
 int perfuse_node_fsync(struct puffs_usermount *,
 puffs_cookie_t, const struct puffs_cred *, int, off_t, off_t);
-int perfuse_node_seek(struct puffs_usermount *,
-puffs_cookie_t, off_t, off_t, const struct puffs_cred *);
 int perfuse_node_remove(struct puffs_usermount *,
 puffs_cookie_t, puffs_cookie_t, const struct puffs_cn *);
 int perfuse_node_link(struct puffs_usermount *,



CVS commit: src/lib/libperfuse

2014-08-16 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sat Aug 16 16:28:43 UTC 2014

Modified Files:
src/lib/libperfuse: ops.c perfuse.c perfuse_priv.h

Log Message:
Use just introduced open2 PUFFS method and its PUFFS_OPEN_IO_DIRECT oflag
to implement FUSE's OPEN_IO_DIRECT, by which the filesystem tells the kernel
that read/write to the file should bypass the page cache.

Remove a warning about read beyond EOF which will now normally appear when
page cache is bypassed.


To generate a diff of this commit:
cvs rdiff -u -r1.66 -r1.67 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.31 -r1.32 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.32 -r1.33 src/lib/libperfuse/perfuse_priv.h

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.66 src/lib/libperfuse/ops.c:1.67
--- src/lib/libperfuse/ops.c:1.66	Sun Aug 10 03:22:33 2014
+++ src/lib/libperfuse/ops.c	Sat Aug 16 16:28:43 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.66 2014/08/10 03:22:33 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.67 2014/08/16 16:28:43 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -1338,6 +1338,13 @@ int
 perfuse_node_open(struct puffs_usermount *pu, puffs_cookie_t opc, int mode,
 	const struct puffs_cred *pcr)
 {
+	return perfuse_node_open2(pu, opc, mode, pcr, NULL);
+}
+
+int
+perfuse_node_open2(struct puffs_usermount *pu, puffs_cookie_t opc, int mode,
+	const struct puffs_cred *pcr, int *oflags)
+{
 	struct perfuse_state *ps;
 	struct perfuse_node_data *pnd;
 	perfuse_msg_t *pm;
@@ -1439,6 +1446,12 @@ perfuse_node_open(struct puffs_usermount
 	 */
 	perfuse_new_fh(opc, foo->fh, mode);
 
+	/*
+	 * Set direct I/O if the filesystems forces it
+	 */
+	if ((foo->open_flags & FUSE_FOPEN_DIRECT_IO) && (oflags != NULL))
+		*oflags |= PUFFS_OPEN_IO_DIRECT;
+
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & (PDF_FH|PDF_FILENAME))
 		DPRINTF("%s: opc = %p, file = \"%s\", "
@@ -3031,11 +3044,6 @@ perfuse_node_read(struct puffs_usermount
 	if (vap->va_type == VDIR)
 		return EISDIR;
 
-	if ((u_quad_t)offset + *resid > vap->va_size)
-		DWARNX("%s %p read %lld@%zu beyond EOF %" PRIu64 "\n",
-		   __func__, (void *)opc, (long long)offset,
-		   *resid, vap->va_size);
-
 	do {
 		size_t max_read;
 

Index: src/lib/libperfuse/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.31 src/lib/libperfuse/perfuse.c:1.32
--- src/lib/libperfuse/perfuse.c:1.31	Mon Sep 10 13:56:18 2012
+++ src/lib/libperfuse/perfuse.c	Sat Aug 16 16:28:43 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.31 2012/09/10 13:56:18 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.32 2014/08/16 16:28:43 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -503,6 +503,9 @@ perfuse_init(struct perfuse_callbacks *p
 #ifdef PUFFS_SETATTR_FAF
 	PUFFSOP_SET(pops, perfuse, node, write2);
 #endif /* PUFFS_SETATTR_FAF */
+#ifdef PUFFS_OPEN_IO_DIRECT 
+	PUFFSOP_SET(pops, perfuse, node, open2);
+#endif /* PUFFS_OPEN_IO_DIRECT */
 
 	/*
 	 * PUFFS_KFLAG_NOCACHE_NAME is required so that we can see changes

Index: src/lib/libperfuse/perfuse_priv.h
diff -u src/lib/libperfuse/perfuse_priv.h:1.32 src/lib/libperfuse/perfuse_priv.h:1.33
--- src/lib/libperfuse/perfuse_priv.h:1.32	Sun Aug 10 03:22:33 2014
+++ src/lib/libperfuse/perfuse_priv.h	Sat Aug 16 16:28:43 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_priv.h,v 1.32 2014/08/10 03:22:33 manu Exp $ */
+/*  $NetBSD: perfuse_priv.h,v 1.33 2014/08/16 16:28:43 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -262,6 +262,8 @@ int perfuse_node_write(struct puffs_user
 uint8_t *, off_t, size_t *, const struct puffs_cred *, int);
 int perfuse_node_write2(struct puffs_usermount *, puffs_cookie_t,
 uint8_t *, off_t, size_t *, const struct puffs_cred *, int, int);
+int perfuse_node_open2(struct puffs_usermount *,
+puffs_cookie_t, int, const struct puffs_cred *, int *);
 void perfuse_cache_write(struct puffs_usermount *,
 puffs_cookie_t, size_t, struct puffs_cacherun *);
 int perfuse_node_getextattr(struct puffs_usermount *, puffs_cookie_t,



CVS commit: src/lib/libperfuse

2014-08-09 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sun Aug 10 03:22:33 UTC 2014

Modified Files:
src/lib/libperfuse: ops.c perfuse_priv.h subr.c

Log Message:
- Make sure non root users cannot access system namespace attributes
- honour namespace specification when listing attributes
- Also fix message memory leak introduced by previous commit


To generate a diff of this commit:
cvs rdiff -u -r1.65 -r1.66 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.31 -r1.32 src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.19 -r1.20 src/lib/libperfuse/subr.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.65 src/lib/libperfuse/ops.c:1.66
--- src/lib/libperfuse/ops.c:1.65	Sat Aug  9 19:06:50 2014
+++ src/lib/libperfuse/ops.c	Sun Aug 10 03:22:33 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.65 2014/08/09 19:06:50 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.66 2014/08/10 03:22:33 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -3323,6 +3323,10 @@ perfuse_node_getextattr(struct puffs_use
 	char *np;
 	int error;
 
+	/* system namespace attrs are not accessible to non root users */
+	if (attrns == EXTATTR_NAMESPACE_SYSTEM && !puffs_cred_isjuggernaut(pcr))
+		return EPERM;
+
 	node_ref(opc);
 	ps = puffs_getspecific(pu);
 	attrname = perfuse_native_ns(attrns, attrname, fuse_attrname);
@@ -3367,6 +3371,7 @@ perfuse_node_getextattr(struct puffs_use
 	if (resid != NULL) {
 		if (*resid < len) {
 			error = ERANGE;
+			ps->ps_destroy_msg(pm);
 			goto out;
 		}
 
@@ -3396,6 +3401,10 @@ perfuse_node_setextattr(struct puffs_use
 	char *np;
 	int error;
 	
+	/* system namespace attrs are not accessible to non root users */
+	if (attrns == EXTATTR_NAMESPACE_SYSTEM && !puffs_cred_isjuggernaut(pcr))
+		return EPERM;
+
 	node_ref(opc);
 	ps = puffs_getspecific(pu);
 	attrname = perfuse_native_ns(attrns, attrname, fuse_attrname);
@@ -3436,9 +3445,13 @@ perfuse_node_listextattr(struct puffs_us
 	struct fuse_getxattr_out *fgo;
 	struct fuse_out_header *foh;
 	char *np;
-	size_t len, puffs_len;
+	size_t len, puffs_len, i, attrlen, outlen;
 	int error;
 	
+	/* system namespace attrs are not accessible to non root users */
+	if (attrns == EXTATTR_NAMESPACE_SYSTEM && !puffs_cred_isjuggernaut(pcr))
+		return EPERM;
+
 	node_ref(opc);
 
 	ps = puffs_getspecific(pu);
@@ -3478,28 +3491,44 @@ perfuse_node_listextattr(struct puffs_us
 	np = (char *)(void *)(foh + 1);
 	puffs_len = foh->len - sizeof(*foh);
 
-	if (attrs != NULL) {
-#ifdef PUFFS_EXTATTR_LIST_LENPREFIX
-		/* 
-		 * Convert the FUSE reply to length prefixed strings
-		 * if this is what the kernel wants.
-		 */
-		if (flag & PUFFS_EXTATTR_LIST_LENPREFIX) {
-			size_t i, attrlen;
+	if (attrsize != NULL)
+		*attrsize = puffs_len;
 
-			for (i = 0; i < puffs_len; i += attrlen + 1) {
-attrlen = strlen(np + i);
-(void)memmove(np + i + 1, np + i, attrlen);
-*(np + i) = (uint8_t)attrlen;
-			}	
+	if (attrs != NULL) {
+		if (*resid < puffs_len) {
+			error = ERANGE;
+			ps->ps_destroy_msg(pm);
+			goto out;
 		}
+
+		outlen = 0;
+	
+		for (i = 0; i < puffs_len; i += attrlen + 1) {
+			attrlen = strlen(np + i);
+
+			/*
+			 * Filter attributes per namespace
+			 */
+			if (!perfuse_ns_match(attrns, np + i))
+continue;
+
+#ifdef PUFFS_EXTATTR_LIST_LENPREFIX
+			/* 
+			 * Convert the FUSE reply to length prefixed strings
+			 * if this is what the kernel wants.
+			 */
+			if (flag & PUFFS_EXTATTR_LIST_LENPREFIX) {
+(void)memcpy(attrs + outlen + 1,
+	 np + i, attrlen);
+*(attrs + outlen) = (uint8_t)attrlen;
+			} else 
 #endif /* PUFFS_EXTATTR_LIST_LENPREFIX */
-		(void)memcpy(attrs, np, puffs_len);
-		*resid -= puffs_len;
-	}
+			(void)memcpy(attrs + outlen, np + i, attrlen + 1);
+			outlen += attrlen + 1;
+		}	
 
-	if (attrsize != NULL) 
-		*attrsize = puffs_len;
+		*resid -= outlen;
+	}
 
 	ps->ps_destroy_msg(pm);
 	error = 0;
@@ -3520,6 +3549,10 @@ perfuse_node_deleteextattr(struct puffs_
 	char *np;
 	int error;
 	
+	/* system namespace attrs are not accessible to non root users */
+	if (attrns == EXTATTR_NAMESPACE_SYSTEM && !puffs_cred_isjuggernaut(pcr))
+		return EPERM;
+
 	node_ref(opc);
 
 	ps = puffs_getspecific(pu);

Index: src/lib/libperfuse/perfuse_priv.h
diff -u src/lib/libperfuse/perfuse_priv.h:1.31 src/lib/libperfuse/perfuse_priv.h:1.32
--- src/lib/libperfuse/perfuse_priv.h:1.31	Sat Jul 21 05:49:42 2012
+++ src/lib/libperfuse/perfuse_priv.h	Sun Aug 10 03:22:33 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_priv.h,v 1.31 2012/07/21 05:49:42 manu Exp $ */
+/*  $NetBSD: perfuse_priv.h,v 1.32 2014/08/10 03:22:33 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -186,6 +186,7 @@ uint64_t perfuse_get_fh(puffs_cookie_t, 
 uint64_t perfuse_next_unique(struct puffs_usermount *);
 char *perfuse_node_path(struct perfuse_state *

CVS commit: src/lib/libperfuse

2014-08-09 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sat Aug  9 19:06:50 UTC 2014

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
getextattr: fix attribute length being reported to caller. If buffer
is too small, return ENORANGE.

Caught by glusterFS regression tests


To generate a diff of this commit:
cvs rdiff -u -r1.64 -r1.65 src/lib/libperfuse/ops.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.64 src/lib/libperfuse/ops.c:1.65
--- src/lib/libperfuse/ops.c:1.64	Sat Aug  9 03:17:11 2014
+++ src/lib/libperfuse/ops.c	Sat Aug  9 19:06:50 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.64 2014/08/09 03:17:11 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.65 2014/08/09 19:06:50 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -3359,9 +3359,17 @@ perfuse_node_getextattr(struct puffs_use
 	 */
 	foh = GET_OUTHDR(ps, pm);
 	np = (char *)(void *)(foh + 1);
+	len = foh->len - sizeof(*foh);
+
+	if (attrsize != NULL)
+		*attrsize = len;
 
 	if (resid != NULL) {
-		len = MAX(foh->len - sizeof(*foh), *resid);
+		if (*resid < len) {
+			error = ERANGE;
+			goto out;
+		}
+
 		(void)memcpy(attr, np, len);
 		*resid -= len;
 	}



CVS commit: src/lib/libperfuse

2014-08-08 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sat Aug  9 03:17:11 UTC 2014

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Send GETATTR to filesystem for removed but still-open files, as
it is the expected behavior (bug caught by glusterFS regression tests)


To generate a diff of this commit:
cvs rdiff -u -r1.63 -r1.64 src/lib/libperfuse/ops.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.63 src/lib/libperfuse/ops.c:1.64
--- src/lib/libperfuse/ops.c:1.63	Mon Jan  6 08:56:34 2014
+++ src/lib/libperfuse/ops.c	Sat Aug  9 03:17:11 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.63 2014/01/06 08:56:34 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.64 2014/08/09 03:17:11 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -1554,7 +1554,7 @@ perfuse_node_getattr_ttl(struct puffs_us
 	struct fuse_attr_out *fao;
 	int error = 0;
 	
-	if (pnd->pnd_flags & PND_REMOVED)
+	if ((pnd->pnd_flags & PND_REMOVED) && !(pnd->pnd_flags & PND_OPEN))
 		return ENOENT;
 
 	node_ref(opc);



CVS commit: src/lib/libperfuse

2014-01-06 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon Jan  6 08:56:34 UTC 2014

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
For filesystems mounted without -o use_ino, readdir is not
able to fetch inode number. We perfom an addtional lookup
on each file to get it.

In that case, do not lookup .. from root, as it breaks
out of the filesystem and hits NULL pointers.


To generate a diff of this commit:
cvs rdiff -u -r1.62 -r1.63 src/lib/libperfuse/ops.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.62 src/lib/libperfuse/ops.c:1.63
--- src/lib/libperfuse/ops.c:1.62	Fri Jul 19 07:32:35 2013
+++ src/lib/libperfuse/ops.c	Mon Jan  6 08:56:34 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.62 2013/07/19 07:32:35 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.63 2014/01/06 08:56:34 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -644,13 +644,23 @@ fuse_to_dirent(struct puffs_usermount *p
 		 */
 		if (fd->ino == PERFUSE_UNKNOWN_INO) {
 			struct puffs_node *pn;
+			struct perfuse_node_data *pnd = PERFUSE_NODE_DATA(opc);
 
-			if (node_lookup_common(pu, opc, NULL, fd->name,
-	   NULL, &pn) != 0) {
-DWARNX("node_lookup_common failed");
+			/* 
+			 * Avoid breaking out of fs 
+			 * by lookup to .. on root
+			 */
+			if ((strcmp(fd->name, "..") == 0) && 
+			(pnd->pnd_nodeid == FUSE_ROOT_ID)) {
+fd->ino = FUSE_ROOT_ID;
 			} else {
-fd->ino = pn->pn_va.va_fileid;
-(void)perfuse_node_reclaim(pu, pn);
+if (node_lookup_common(pu, opc, NULL, fd->name,
+		   NULL, &pn) != 0) {
+	DWARNX("node_lookup_common failed");
+} else {
+	fd->ino = pn->pn_va.va_fileid;
+	(void)perfuse_node_reclaim(pu, pn);
+}
 			}
 		}
 



CVS commit: src/lib/libperfuse

2013-07-19 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Fri Jul 19 07:32:35 UTC 2013

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Catch open without FREAD|FWRITE (it should not happen)


To generate a diff of this commit:
cvs rdiff -u -r1.61 -r1.62 src/lib/libperfuse/ops.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.61 src/lib/libperfuse/ops.c:1.62
--- src/lib/libperfuse/ops.c:1.61	Thu Jul 18 09:01:20 2013
+++ src/lib/libperfuse/ops.c	Fri Jul 19 07:32:35 2013
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.61 2013/07/18 09:01:20 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.62 2013/07/19 07:32:35 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -1391,6 +1391,10 @@ perfuse_node_open(struct puffs_usermount
 		if (pnd->pnd_flags & PND_RFH)
 			mode &= ~FREAD;
 		break;
+	default:
+		DWARNX("open without either FREAD nor FWRITE");
+		error = EPERM;
+		goto out;
 	}
 	
 	/*



CVS commit: src/lib/libperfuse

2013-07-18 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Thu Jul 18 09:01:20 UTC 2013

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
One more explicit error log, and two bug fixes
1) with recent FUSE, when lookup returns a null ino, it means ENOENT
2) odd corner case that caused a bug on dd if=test of=test conv=notrunc
   This caused the file to be open first ro, then rw. A logic bug in
   perfuse_node_open caused it to skip the second operation, whereas
   it should open for writing, and store the write FH without touching
   the read FH.


To generate a diff of this commit:
cvs rdiff -u -r1.60 -r1.61 src/lib/libperfuse/ops.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.60 src/lib/libperfuse/ops.c:1.61
--- src/lib/libperfuse/ops.c:1.60	Sat Nov  3 15:43:20 2012
+++ src/lib/libperfuse/ops.c	Thu Jul 18 09:01:20 2013
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.60 2012/11/03 15:43:20 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.61 2013/07/18 09:01:20 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -1369,10 +1369,29 @@ perfuse_node_open(struct puffs_usermount
 	 * Do not open twice, and do not reopen for reading
 	 * if we already have write handle.
 	 */
-	if (((mode & FREAD) && (pnd->pnd_flags & PND_RFH)) ||
-	((mode & FREAD) && (pnd->pnd_flags & PND_WFH)) ||
-	((mode & FWRITE) && (pnd->pnd_flags & PND_WFH)))
-		goto out;
+	switch (mode & (FREAD|FWRITE)) {
+	case FREAD:
+		if (pnd->pnd_flags & (PND_RFH|PND_WFH))
+			goto out;
+		break;
+	case FWRITE:
+		if (pnd->pnd_flags & PND_WFH)
+			goto out;
+		break;
+	case FREAD|FWRITE:
+		if (pnd->pnd_flags & PND_WFH)
+			goto out;
+
+		/*
+		 * Corner case: if already open for reading (PND_RFH)
+		 * and re-opening FREAD|FWRITE, we need to reopen, 
+		 * but only for writing. Note the change on mode 
+		 * will only affect perfuse_new_fh()
+		 */
+		if (pnd->pnd_flags & PND_RFH)
+			mode &= ~FREAD;
+		break;
+	}
 	
 	/*
 	 * Queue open on a node so that we do not open
@@ -2723,8 +2742,8 @@ perfuse_node_reclaim(struct puffs_usermo
 #ifdef PERFUSE_DEBUG
 	if ((pnd->pnd_flags & PND_OPEN) ||
 	   !TAILQ_EMPTY(&pnd->pnd_pcq))
-		DERRX(EX_SOFTWARE, "%s: opc = %p: still open",
-		  __func__, opc);
+		DERRX(EX_SOFTWARE, "%s: opc = %p \"%s\": still open",
+		  __func__, opc, pnd->pnd_name);
 
 	if ((pnd->pnd_flags & PND_BUSY) ||
 	   !TAILQ_EMPTY(&pnd->pnd_pcq))



CVS commit: src/lib/libperfuse

2012-11-03 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sat Nov  3 15:43:20 UTC 2012

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
When lookup returns a node with null inode number, it means the ENOENT,
with negative caching. We do not implement negative caching yet, but
we honour the ENOENT.


To generate a diff of this commit:
cvs rdiff -u -r1.59 -r1.60 src/lib/libperfuse/ops.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.59 src/lib/libperfuse/ops.c:1.60
--- src/lib/libperfuse/ops.c:1.59	Sat Jul 21 05:49:42 2012
+++ src/lib/libperfuse/ops.c	Sat Nov  3 15:43:20 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.59 2012/07/21 05:49:42 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.60 2012/11/03 15:43:20 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -433,6 +433,16 @@ node_lookup_common(struct puffs_usermoun
 
 	feo = GET_OUTPAYLOAD(ps, pm, fuse_entry_out);
 
+	/* 
+	 * Starting with ABI 7.4, inode number 0 means ENOENT, 
+	 * with entry_valid / entry_valid_nsec giving negative
+	 * cache timeout (which we do not implement yet).
+	 */
+	if (feo->attr.ino == 0) {
+		ps->ps_destroy_msg(pm);
+		return ENOENT;
+	}
+
 	/*
 	 * Check for a known node, not reclaimed, with another name.
 	 * It may have been moved, or we can lookup ../



CVS commit: src/lib/libperfuse

2012-09-10 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon Sep 10 13:56:18 UTC 2012

Modified Files:
src/lib/libperfuse: perfuse.c

Log Message:
Turn a fatal error into a warning.


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/lib/libperfuse/perfuse.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/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.30 src/lib/libperfuse/perfuse.c:1.31
--- src/lib/libperfuse/perfuse.c:1.30	Fri Aug 10 16:49:36 2012
+++ src/lib/libperfuse/perfuse.c	Mon Sep 10 13:56:18 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.30 2012/08/10 16:49:36 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.31 2012/09/10 13:56:18 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -682,9 +682,8 @@ perfuse_fsreq(struct puffs_usermount *pu
 		DWARN("operation unique = %"PRId64" failed", foh->unique);
 		break;
 	default:
-		DERRX(EX_SOFTWARE,
-		 "Unexpected frame: unique = %"PRId64", error = %d",
-		 foh->unique, foh->error);
+		DWARNX("Unexpected frame: unique = %"PRId64", error = %d",
+		foh->unique, foh->error);
 		/* NOTREACHED */
 		break;
 	}



CVS commit: src/lib/libperfuse

2012-06-28 Thread David Brownlee
Module Name:src
Committed By:   abs
Date:   Thu Jun 28 13:53:13 UTC 2012

Modified Files:
src/lib/libperfuse: ops.c perfuse_priv.h

Log Message:
Fix the build by adding (unused) flags argument to perfuse_node_setattr_ttl


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.29 -r1.30 src/lib/libperfuse/perfuse_priv.h

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.57 src/lib/libperfuse/ops.c:1.58
--- src/lib/libperfuse/ops.c:1.57	Thu Jun 14 05:58:22 2012
+++ src/lib/libperfuse/ops.c	Thu Jun 28 13:53:13 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.57 2012/06/14 05:58:22 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.58 2012/06/28 13:53:13 abs Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -1680,13 +1680,13 @@ perfuse_node_setattr(struct puffs_usermo
 	const struct vattr *vap, const struct puffs_cred *pcr)
 {
 	return perfuse_node_setattr_ttl(pu, opc, 
-	__UNCONST(vap), pcr, NULL);
+	__UNCONST(vap), pcr, NULL, 0);
 }
 
 int
 perfuse_node_setattr_ttl(struct puffs_usermount *pu, puffs_cookie_t opc,
 	struct vattr *vap, const struct puffs_cred *pcr,
-	struct timespec *va_ttl)
+	struct timespec *va_ttl, int flags)
 {
 	perfuse_msg_t *pm;
 	uint64_t fh;

Index: src/lib/libperfuse/perfuse_priv.h
diff -u src/lib/libperfuse/perfuse_priv.h:1.29 src/lib/libperfuse/perfuse_priv.h:1.30
--- src/lib/libperfuse/perfuse_priv.h:1.29	Wed Apr 18 00:57:22 2012
+++ src/lib/libperfuse/perfuse_priv.h	Thu Jun 28 13:53:13 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_priv.h,v 1.29 2012/04/18 00:57:22 manu Exp $ */
+/*  $NetBSD: perfuse_priv.h,v 1.30 2012/06/28 13:53:13 abs Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -259,7 +259,7 @@ int perfuse_node_getattr_ttl(struct puff
 struct timespec *);
 int perfuse_node_setattr_ttl(struct puffs_usermount *,
 puffs_cookie_t, struct vattr *, const struct puffs_cred *,
-struct timespec *);
+struct timespec *, int flags);
 
 struct perfuse_trace *perfuse_trace_begin(struct perfuse_state *, 
 puffs_cookie_t, perfuse_msg_t *);



CVS commit: src/lib/libperfuse

2012-06-13 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Thu Jun 14 05:58:22 UTC 2012

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Fix memory leak when we discard a voided setattr operation


To generate a diff of this commit:
cvs rdiff -u -r1.56 -r1.57 src/lib/libperfuse/ops.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.56 src/lib/libperfuse/ops.c:1.57
--- src/lib/libperfuse/ops.c:1.56	Wed Jun 13 01:45:56 2012
+++ src/lib/libperfuse/ops.c	Thu Jun 14 05:58:22 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.56 2012/06/13 01:45:56 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.57 2012/06/14 05:58:22 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -1696,6 +1696,7 @@ perfuse_node_setattr_ttl(struct puffs_us
 	struct fuse_attr_out *fao;
 	struct vattr *old_va;
 	int error;
+	int valid;
 #ifdef PERFUSE_DEBUG
 	struct vattr *old_vap;
 	int resize_debug = 0;
@@ -1719,39 +1720,94 @@ perfuse_node_setattr_ttl(struct puffs_us
 	}
 
 	old_va = puffs_pn_getvap((struct puffs_node *)opc);
+	valid = 0;
 
 	/*
 	 * Check for permission to change size
 	 */
-	if ((vap->va_size != (u_quad_t)PUFFS_VNOVAL) &&
-	(error = mode_access(opc, pcr, PUFFS_VWRITE)) != 0)
-		return error;
+	if ((vap->va_size != (u_quad_t)PUFFS_VNOVAL)) {
+		if ((error = mode_access(opc, pcr, PUFFS_VWRITE)) != 0)
+			return error;
+		valid |= FUSE_FATTR_SIZE;
+	}
 
 	/*
-	 * Check for permission to change dates
+	 * Check for permission to change owner and group
 	 */
-	if (((vap->va_atime.tv_sec != (time_t)PUFFS_VNOVAL) ||
-	 (vap->va_mtime.tv_sec != (time_t)PUFFS_VNOVAL)) &&
-	(puffs_access_times(old_va->va_uid, old_va->va_gid,
-old_va->va_mode, 0, pcr) != 0))
-		return EACCES;
+	if ((vap->va_uid != (uid_t)PUFFS_VNOVAL) ||
+	(vap->va_gid != (gid_t)PUFFS_VNOVAL)) {
+		if (puffs_access_chown(old_va->va_uid, old_va->va_gid,
+   vap->va_uid, vap->va_gid, pcr) != 0)
+			return EACCES;
+
+		if (vap->va_uid != (uid_t)PUFFS_VNOVAL)
+			valid |= FUSE_FATTR_UID;
+
+		if (vap->va_gid != (uid_t)PUFFS_VNOVAL)
+			valid |= FUSE_FATTR_GID;
+	}
 
 	/*
-	 * Check for permission to change owner and group
+	 * Check for permission to change permissions
 	 */
-	if (((vap->va_uid != (uid_t)PUFFS_VNOVAL) ||
-	 (vap->va_gid != (gid_t)PUFFS_VNOVAL)) &&
-	(puffs_access_chown(old_va->va_uid, old_va->va_gid,
-vap->va_uid, vap->va_gid, pcr)) != 0)
-		return EACCES;
+	if (vap->va_mode != (mode_t)PUFFS_VNOVAL) {
+		if (puffs_access_chmod(old_va->va_uid, old_va->va_gid,
+old_va->va_type, vap->va_mode, pcr) != 0)
+			return EACCES;
+		valid |= FUSE_FATTR_MODE;
+	}
 
 	/*
-	 * Check for permission to change permissions
+	 * Check for permission to change dates
 	 */
-	if ((vap->va_mode != (mode_t)PUFFS_VNOVAL) &&
-	(puffs_access_chmod(old_va->va_uid, old_va->va_gid,
-old_va->va_type, vap->va_mode, pcr)) != 0)
-		return EACCES;
+	if ((vap->va_atime.tv_sec != (time_t)PUFFS_VNOVAL) ||
+	(vap->va_mtime.tv_sec != (time_t)PUFFS_VNOVAL)) {
+		if (vap->va_atime.tv_sec != (time_t)PUFFS_VNOVAL)
+			valid |= FUSE_FATTR_ATIME;
+
+		if (vap->va_mtime.tv_sec != (time_t)PUFFS_VNOVAL)
+			valid |= FUSE_FATTR_MTIME;
+
+		/*
+		 * ftruncate() sends only va_size, and metadata cache
+		 * flush adds va_atime and va_mtime. Some FUSE
+		 * filesystems will attempt to detect ftruncate by 
+		 * checking for FATTR_SIZE being set without
+		 * FATTR_UID|FATTR_GID|FATTR_ATIME|FATTR_MTIME|FATTR_MODE
+		 * 
+		 * Try to adapt and remove FATTR_ATIME|FATTR_MTIME
+		 * if we suspect a ftruncate().
+		 */ 
+		if ((valid & FUSE_FATTR_SIZE) &&
+		!(valid & (FUSE_FATTR_UID|FUSE_FATTR_GID|FUSE_FATTR_MODE)))
+			valid &= ~(FUSE_FATTR_ATIME|FUSE_FATTR_MTIME);
+
+		/*
+		 * There is the same mess with fchmod()
+		 */
+		if ((valid & FUSE_FATTR_MODE) &&
+		!(valid & (FUSE_FATTR_UID|FUSE_FATTR_GID)))
+			valid &= ~(FUSE_FATTR_ATIME|FUSE_FATTR_MTIME);
+
+		/*
+		 * And if a change on atime/mtime remains, check permissions.
+		 */
+		if ((valid & (FUSE_FATTR_ATIME|FUSE_FATTR_MTIME)) &&
+		(puffs_access_times(old_va->va_uid, old_va->va_gid,
+old_va->va_mode, 0, pcr) != 0))
+			return EACCES;
+	}
+
+	/*
+	 * If nothing remain, discard the operation. This happend when
+	 * only ctime is changed.
+	 */
+	if (!(valid & (FUSE_FATTR_SIZE|FUSE_FATTR_ATIME|FUSE_FATTR_MTIME|
+		   FUSE_FATTR_MODE|FUSE_FATTR_UID|FUSE_FATTR_GID))) {
+		error = 0;
+		goto out;
+	}
+
 	
 	pm = ps->ps_new_msg(pu, opc, FUSE_SETATTR, sizeof(*fsi), pcr);
 	fsi = GET_INPAYLOAD(ps, pm, fuse_setattr_in);
@@ -1766,7 +1822,7 @@ perfuse_node_setattr_ttl(struct puffs_us
 		fsi->valid |= FUSE_FATTR_FH;
 	}
 
-	if (vap->va_size != (u_quad_t)PUFFS_VNOVAL) {
+	if (valid & FUSE_FATTR_SIZE) {
 		fsi->size = vap->va_size;
 		fsi->valid |= FUSE_FATTR_SIZE;
 
@@ -1787,10 +1843,8 @@ perfuse_node

CVS commit: src/lib/libperfuse

2012-06-12 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Wed Jun 13 01:45:56 UTC 2012

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Fix memory leak on setattr


To generate a diff of this commit:
cvs rdiff -u -r1.55 -r1.56 src/lib/libperfuse/ops.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.55 src/lib/libperfuse/ops.c:1.56
--- src/lib/libperfuse/ops.c:1.55	Mon May 28 02:13:32 2012
+++ src/lib/libperfuse/ops.c	Wed Jun 13 01:45:56 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.55 2012/05/28 02:13:32 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.56 2012/06/13 01:45:56 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -1868,6 +1868,7 @@ perfuse_node_setattr_ttl(struct puffs_us
 	 */
 	if (!(fsi->valid & (FUSE_FATTR_SIZE|FUSE_FATTR_ATIME|FUSE_FATTR_MTIME|
 			FUSE_FATTR_MODE|FUSE_FATTR_UID|FUSE_FATTR_GID))) {
+		ps->ps_destroy_msg(pm);
 		error = 0;
 		goto out;
 	}



CVS commit: src/lib/libperfuse

2012-05-27 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon May 28 02:13:33 UTC 2012

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Setting mode by fchmod(2) will break on glusterfs-3.3 is we attempt
to set atime and mtime at the same time. Detect that situation just
like we detected ftruncate(2) and wipe atime and mtime if it occurs.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/lib/libperfuse/ops.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.54 src/lib/libperfuse/ops.c:1.55
--- src/lib/libperfuse/ops.c:1.54	Wed Apr 18 00:57:21 2012
+++ src/lib/libperfuse/ops.c	Mon May 28 02:13:32 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.54 2012/04/18 00:57:21 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.55 2012/05/28 02:13:32 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -1849,6 +1849,19 @@ perfuse_node_setattr_ttl(struct puffs_us
 		fsi->mtimensec = 0;
 		fsi->valid &= ~(FUSE_FATTR_ATIME|FUSE_FATTR_MTIME);
 	}
+
+	/*
+	 * There is the same mess with fchmod()
+	 */
+	if ((vap->va_mode != (mode_t)PUFFS_VNOVAL) &&
+	(vap->va_uid == (uid_t)PUFFS_VNOVAL) &&
+	(vap->va_gid == (gid_t)PUFFS_VNOVAL)) {
+		fsi->atime = 0;
+		fsi->atimensec = 0;
+		fsi->mtime = 0;
+		fsi->mtimensec = 0;
+		fsi->valid &= ~(FUSE_FATTR_ATIME|FUSE_FATTR_MTIME);
+	}
 		
 	/*
 	 * If nothing remain, discard the operation.



CVS commit: src/lib/libperfuse

2012-04-08 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sun Apr  8 15:13:06 UTC 2012

Modified Files:
src/lib/libperfuse: ops.c perfuse.c perfuse_priv.h

Log Message:
Use new PUFFS_KFLAG_CACHE_FS_TTL option to puffs_init(3) so that
FUSE TTL on name and attributes are used. This save many PUFFS
operations and improves performances.

PUFFS_KFLAG_CACHE_FS_TTL is #ifdef'ed in many places for now so that
libperfuse can still be used on netbsd-5.


To generate a diff of this commit:
cvs rdiff -u -r1.52 -r1.53 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.26 -r1.27 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.27 -r1.28 src/lib/libperfuse/perfuse_priv.h

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.52 src/lib/libperfuse/ops.c:1.53
--- src/lib/libperfuse/ops.c:1.52	Wed Mar 21 10:10:36 2012
+++ src/lib/libperfuse/ops.c	Sun Apr  8 15:13:06 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.52 2012/03/21 10:10:36 matt Exp $ */
+/*  $NetBSD: ops.c,v 1.53 2012/04/08 15:13:06 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -49,9 +49,11 @@ extern int perfuse_diagflags;
 static void print_node(const char *, puffs_cookie_t);
 #endif
 static void set_expire(puffs_cookie_t, struct fuse_entry_out *, 
-   struct fuse_attr_out *);
+struct fuse_attr_out *);
+#ifndef PUFFS_KFLAG_CACHE_FS_TTL
 static int attr_expired(puffs_cookie_t);
 static int entry_expired(puffs_cookie_t);
+#endif /* PUFFS_KFLAG_CACHE_FS_TTL */
 static int xchg_msg(struct puffs_usermount *, puffs_cookie_t, 
 perfuse_msg_t *, size_t, enum perfuse_xchg_pb_reply); 
 static int mode_access(puffs_cookie_t, const struct puffs_cred *, mode_t);
@@ -336,23 +338,32 @@ fuse_attr_to_vap(struct perfuse_state *p
 
 static void 
 set_expire(puffs_cookie_t opc, struct fuse_entry_out *feo,
-	struct fuse_attr_out *fao)
+	   struct fuse_attr_out *fao)
 {
+ 	struct puffs_node *pn = (struct puffs_node *)opc;
+#ifndef PUFFS_KFLAG_CACHE_FS_TTL
 	struct perfuse_node_data *pnd = PERFUSE_NODE_DATA(opc);
 	struct timespec entry_ts;
 	struct timespec attr_ts;
 	struct timespec now;
 
+	if (clock_gettime(CLOCK_REALTIME, &now) != 0)
+		DERR(EX_OSERR, "clock_gettime failed");
+#endif /* PUFFS_KFLAG_CACHE_FS_TTL */
+
 	if ((feo == NULL) && (fao == NULL))
 		DERRX(EX_SOFTWARE, "%s: feo and fao NULL", __func__);
 
 	if ((feo != NULL) && (fao != NULL))
 		DERRX(EX_SOFTWARE, "%s: feo and fao != NULL", __func__);
 
-	if (clock_gettime(CLOCK_REALTIME, &now) != 0)
-		DERR(EX_OSERR, "clock_gettime failed");
-
 	if (feo != NULL) {
+#ifdef PUFFS_KFLAG_CACHE_FS_TTL
+		pn->pn_cn_ttl.tv_sec = feo->entry_valid;
+		pn->pn_cn_ttl.tv_nsec = feo->entry_valid_nsec;
+		pn->pn_va_ttl.tv_sec = feo->attr_valid;
+		pn->pn_va_ttl.tv_nsec = feo->attr_valid_nsec;
+#else /* PUFFS_KFLAG_CACHE_FS_TTL */
 		entry_ts.tv_sec = (time_t)feo->entry_valid;
 		entry_ts.tv_nsec = (long)feo->entry_valid_nsec;
 
@@ -362,18 +373,25 @@ set_expire(puffs_cookie_t opc, struct fu
 		attr_ts.tv_nsec = (long)feo->attr_valid_nsec;
 
 		timespecadd(&now, &attr_ts, &pnd->pnd_attr_expire);
+#endif /* PUFFS_KFLAG_CACHE_FS_TTL */
 	} 
 
 	if (fao != NULL) {
+#ifdef PUFFS_KFLAG_CACHE_FS_TTL
+		pn->pn_va_ttl.tv_sec = fao->attr_valid;
+		pn->pn_va_ttl.tv_nsec = fao->attr_valid_nsec;
+#else /* PUFFS_KFLAG_CACHE_FS_TTL */
 		attr_ts.tv_sec = (time_t)fao->attr_valid;
 		attr_ts.tv_nsec = (long)fao->attr_valid_nsec;
 
 		timespecadd(&now, &attr_ts, &pnd->pnd_attr_expire);
+#endif /* PUFFS_KFLAG_CACHE_FS_TTL */
 	} 
 
 	return;
 }
 
+#ifndef PUFFS_KFLAG_CACHE_FS_TTL
 static int
 attr_expired(puffs_cookie_t opc)
 {
@@ -405,6 +423,7 @@ entry_expired(puffs_cookie_t opc)
 
 	return timespeccmp(&expire, &now, <);
 }
+#endif /* PUFFS_KFLAG_CACHE_FS_TTL */
 
 
 /* 
@@ -483,6 +502,7 @@ node_lookup_common(struct puffs_usermoun
 		break;
 	}
 
+#ifndef PUFFS_KFLAG_CACHE_FS_TTL
 	/*
 	 * Check for cached name
 	 */
@@ -491,6 +511,7 @@ node_lookup_common(struct puffs_usermoun
 		*pnp = oldpnd->pnd_pn;
 		return 0;
 	}
+#endif /* PUFFS_KFLAG_CACHE_FS_TTL */
 
 	len = strlen(path) + 1;
 
@@ -1160,7 +1181,9 @@ perfuse_node_lookup(struct puffs_usermou
 	 * itself. If we want to live, hide that!
 	 */
 	if ((opc == (puffs_cookie_t)pn) && (strcmp(pcn->pcn_name, ".") != 0)) {
-		DWARNX("lookup returned parent");
+		DERRX(EX_SOFTWARE, "lookup \"%s\" in \"%s\" returned parent",
+		  pcn->pcn_name, perfuse_node_path(opc));
+		/* NOTREACHED */
 		return ESTALE;
 	}
 
@@ -1457,7 +1480,7 @@ perfuse_node_open(struct puffs_usermount
 	 * so that we can reuse it later
 	 */
 	perfuse_new_fh(opc, foo->fh, mode);
-	 
+
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & (PDF_FH|PDF_FILENAME))
 		DPRINTF("%s: opc = %p, file = \"%s\", "
@@ -1572,6 +1595,7 @@ perfuse_node_getattr(struct puffs_usermo
 
 	ps = puffs_getspecific(pu);
 		
+#ifndef PUFFS_KFLAG_CACHE_FS_TTL
 	/*
 	 * Check for 

CVS commit: src/lib/libperfuse

2012-03-08 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Thu Mar  8 14:58:58 UTC 2012

Modified Files:
src/lib/libperfuse: ops.c perfuse_priv.h subr.c

Log Message:
The kernel can lookup the same node multiple time and will reclaim as
many times it looked up. All reclaims but the last one must be ignored,
otherwise we discard a node which will still get operations. We therefore
have to keep track of lookup/reclaim count and hnour reclaims only when
the count reaches zero.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.25 -r1.26 src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.15 -r1.16 src/lib/libperfuse/subr.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.50 src/lib/libperfuse/ops.c:1.51
--- src/lib/libperfuse/ops.c:1.50	Sun Jan 29 06:22:02 2012
+++ src/lib/libperfuse/ops.c	Thu Mar  8 14:58:57 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.50 2012/01/29 06:22:02 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.51 2012/03/08 14:58:57 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -514,6 +514,7 @@ node_lookup_common(pu, opc, path, pcr, p
 	 * Check for cached name
 	 */
 	if ((oldpnd != NULL) && !entry_expired(oldpnd->pnd_pn)) {
+		oldpnd->pnd_puffs_nlookup++;
 		*pnp = oldpnd->pnd_pn;
 		return 0;
 	}
@@ -550,7 +551,8 @@ node_lookup_common(pu, opc, path, pcr, p
 
 	if (oldpnd != NULL) {
 		if (oldpnd->pnd_nodeid == feo->nodeid) {
-			oldpnd->pnd_nlookup++;
+			oldpnd->pnd_fuse_nlookup++;
+			oldpnd->pnd_puffs_nlookup++;
 			*pnp = oldpnd->pnd_pn;
 
 			ps->ps_destroy_msg(pm);
@@ -2702,6 +2704,7 @@ perfuse_node_reclaim(pu, opc)
 		return 0;
 
 	pnd->pnd_flags |= PND_RECLAIMED;
+	pnd->pnd_puffs_nlookup--;
 
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & PDF_RECLAIM)
@@ -2718,11 +2721,11 @@ perfuse_node_reclaim(pu, opc)
 
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & PDF_RECLAIM)
-		DPRINTF("%s (nodeid %"PRId64") is %sreclaimed, "
+		DPRINTF("%s (nodeid %"PRId64") is %sreclaimed, nlookup = %d "
 			"has childcount %d %s%s%s%s, pending ops:%s%s%s\n", 
 		perfuse_node_path((puffs_cookie_t)pn), pnd->pnd_nodeid,
 		pnd->pnd_flags & PND_RECLAIMED ? "" : "not ",
-		pnd->pnd_childcount,
+			pnd->pnd_puffs_nlookup, pnd->pnd_childcount,
 			pnd->pnd_flags & PND_OPEN ? "open " : "not open",
 			pnd->pnd_flags & PND_RFH ? "r" : "",
 			pnd->pnd_flags & PND_WFH ? "w" : "",
@@ -2731,8 +2734,8 @@ perfuse_node_reclaim(pu, opc)
 			pnd->pnd_flags & PND_INWRITE ? " write" : "",
 			pnd->pnd_flags & PND_INOPEN ? " open" : "");
 #endif
-
 		if (!(pnd->pnd_flags & PND_RECLAIMED) ||
+		(pnd->pnd_puffs_nlookup != 0) ||
 		(pnd->pnd_childcount != 0))
 			return 0;
 
@@ -2758,7 +2761,7 @@ perfuse_node_reclaim(pu, opc)
 		pm = ps->ps_new_msg(pu, (puffs_cookie_t)pn, FUSE_FORGET, 
 			  sizeof(*ffi), NULL);
 		ffi = GET_INPAYLOAD(ps, pm, fuse_forget_in);
-		ffi->nlookup = pnd->pnd_nlookup;
+		ffi->nlookup = pnd->pnd_fuse_nlookup;
 
 		/*
 		 * No reply is expected, pm is freed in xchg_msg

Index: src/lib/libperfuse/perfuse_priv.h
diff -u src/lib/libperfuse/perfuse_priv.h:1.25 src/lib/libperfuse/perfuse_priv.h:1.26
--- src/lib/libperfuse/perfuse_priv.h:1.25	Sun Jan 29 06:22:02 2012
+++ src/lib/libperfuse/perfuse_priv.h	Thu Mar  8 14:58:57 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_priv.h,v 1.25 2012/01/29 06:22:02 manu Exp $ */
+/*  $NetBSD: perfuse_priv.h,v 1.26 2012/03/08 14:58:57 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -108,7 +108,8 @@ struct perfuse_node_data {
 	uint64_t pnd_rfh;
 	uint64_t pnd_wfh;
 	uint64_t pnd_nodeid;			/* nodeid, this is not inode */
-	uint64_t pnd_nlookup;			/* vnode refcount */
+	uint64_t pnd_fuse_nlookup;		/* vnode refcount */
+	int pnd_puffs_nlookup;			/* vnode refcount */
 	uint64_t pnd_lock_owner;
 	struct dirent *pnd_dirent;		/* native buffer for readdir */
 	off_t pnd_dirent_len;

Index: src/lib/libperfuse/subr.c
diff -u src/lib/libperfuse/subr.c:1.15 src/lib/libperfuse/subr.c:1.16
--- src/lib/libperfuse/subr.c:1.15	Sun Jan 29 06:22:02 2012
+++ src/lib/libperfuse/subr.c	Thu Mar  8 14:58:57 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: subr.c,v 1.15 2012/01/29 06:22:02 manu Exp $ */
+/*  $NetBSD: subr.c,v 1.16 2012/03/08 14:58:57 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -67,7 +67,8 @@ perfuse_new_pn(pu, name, parent)
 	pnd->pnd_rfh = FUSE_UNKNOWN_FH;
 	pnd->pnd_wfh = FUSE_UNKNOWN_FH;
 	pnd->pnd_nodeid = PERFUSE_UNKNOWN_NODEID;
-	pnd->pnd_nlookup = 1;
+	pnd->pnd_fuse_nlookup = 1;
+	pnd->pnd_puffs_nlookup = 1;
 	pnd->pnd_parent = parent;
 	pnd->pnd_pn = (puffs_cookie_t)pn;
 	(void)strlcpy(pnd->pnd_name, name, MAXPATHLEN);



CVS commit: src/lib/libperfuse

2012-01-29 Thread David A. Holland
Module Name:src
Committed By:   dholland
Date:   Sun Jan 29 09:01:31 UTC 2012

Modified Files:
src/lib/libperfuse: debug.c

Log Message:
Fix 32-bit build


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libperfuse/debug.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/debug.c
diff -u src/lib/libperfuse/debug.c:1.9 src/lib/libperfuse/debug.c:1.10
--- src/lib/libperfuse/debug.c:1.9	Sun Jan 29 06:22:01 2012
+++ src/lib/libperfuse/debug.c	Sun Jan 29 09:01:31 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: debug.c,v 1.9 2012/01/29 06:22:01 manu Exp $ */
+/*  $NetBSD: debug.c,v 1.10 2012/01/29 09:01:31 dholland Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -220,8 +220,8 @@ perfuse_trace_dump(pu, fp)
 	TAILQ_FOREACH(pt, &ps->ps_trace, pt_list) {
 		const char *quote = pt->pt_path[0] != '\0' ? "\"" : "";
 
-		fprintf(fp, "%ld.%09ld %s %s%s%s %s ",  
-			pt->pt_start.tv_sec, pt->pt_start.tv_nsec,
+		fprintf(fp, "%lld.%09ld %s %s%s%s %s ",  
+			(long long)pt->pt_start.tv_sec, pt->pt_start.tv_nsec,
 			perfuse_opname(pt->pt_opcode),
 			quote, pt->pt_path, quote,
 			pt->pt_extra);
@@ -233,8 +233,9 @@ perfuse_trace_dump(pu, fp)
 			ts.tv_nsec = 0;	/* delint */
 			timespecsub(&pt->pt_end, &pt->pt_start, &ts);
 
-			fprintf(fp, "error = %d elapsed = %ld.%09lu ",
-pt->pt_error, ts.tv_sec, ts.tv_nsec);
+			fprintf(fp, "error = %d elapsed = %lld.%09lu ",
+pt->pt_error, (long long)ts.tv_sec,
+ts.tv_nsec);
 
 			count[pt->pt_opcode]++;
 			timespecadd(&ts_total[pt->pt_opcode],
@@ -267,11 +268,12 @@ perfuse_trace_dump(pu, fp)
 			min = 0;
 		}
 			
-		fprintf(fp, "%s\t%d\t%ld.%09ld\t%ld.%09ld\t%ld.%09ld\t\n",
+		fprintf(fp, "%s\t%d\t%lld.%09ld\t%lld.%09ld\t%lld.%09ld\t\n",
 			perfuse_opname(i), count[i],
-			min, ts_min[i].tv_nsec,
-			(time_t)(avg / 10L), (long)(avg % 10L),
-			ts_max[i].tv_sec, ts_max[i].tv_nsec);
+			(long long)min, ts_min[i].tv_nsec,
+			(long long)(time_t)(avg / 10L),
+			(long)(avg % 10L),
+			(long long)ts_max[i].tv_sec, ts_max[i].tv_nsec);
 	}	
 	
 	(void)fflush(fp);



CVS commit: src/lib/libperfuse

2011-12-28 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Thu Dec 29 04:25:49 UTC 2011

Modified Files:
src/lib/libperfuse: debug.c

Log Message:
Redo previous;  remove all the casts I added, and use PRI* macros instead.
(by popular demand - makes sense, too)


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libperfuse/debug.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/debug.c
diff -u src/lib/libperfuse/debug.c:1.7 src/lib/libperfuse/debug.c:1.8
--- src/lib/libperfuse/debug.c:1.7	Thu Dec 29 01:40:32 2011
+++ src/lib/libperfuse/debug.c	Thu Dec 29 04:25:49 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: debug.c,v 1.7 2011/12/29 01:40:32 riz Exp $ */
+/*  $NetBSD: debug.c,v 1.8 2011/12/29 04:25:49 riz Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -159,9 +159,8 @@ perfuse_trace_dump(pu, fp)
 	TAILQ_FOREACH(pt, &ps->ps_trace, pt_list) {
 		const char *quote = pt->pt_path[0] != '\0' ? "\"" : "";
 
-		fprintf(fp, "%ju.%09jd %s %s%s%s %s ",  
-			(intmax_t)pt->pt_start.tv_sec,
-			(intmax_t)pt->pt_start.tv_nsec,
+		fprintf(fp, "%" PRIu64 ".%09ld %s %s%s%s %s ",  
+			pt->pt_start.tv_sec, pt->pt_start.tv_nsec,
 			perfuse_opname(pt->pt_opcode),
 			quote, pt->pt_path, quote,
 			pt->pt_extra);
@@ -173,8 +172,8 @@ perfuse_trace_dump(pu, fp)
 			ts.tv_nsec = 0;	/* delint */
 			timespecsub(&pt->pt_end, &pt->pt_start, &ts);
 
-			fprintf(fp, "error = %d elapsed = %ju.%09lu ",
-pt->pt_error, (intmax_t)ts.tv_sec, ts.tv_nsec);
+			fprintf(fp, "error = %d elapsed = %" PRIu64 ".%09lu ",
+pt->pt_error, ts.tv_sec, ts.tv_nsec);
 
 			count[pt->pt_opcode]++;
 			timespecadd(&ts_total[pt->pt_opcode],
@@ -207,12 +206,12 @@ perfuse_trace_dump(pu, fp)
 			min = 0;
 		}
 			
-		fprintf(fp, "%s\t%d\t%jd.%09ld\t%jd.%09ld\t%jd.%09ld\t\n",
+		fprintf(fp, "%s\t%d\t%" PRId64 ".%09ld\t%" PRId64 
+		".%09ld\t%" PRId64 ".%09ld\t\n",
 			perfuse_opname(i), count[i],
-			(intmax_t)min, ts_min[i].tv_nsec,
-			(intmax_t)(avg / 10L),
-			(long)(avg % 10L),
-			(intmax_t)ts_max[i].tv_sec, ts_max[i].tv_nsec);
+			min, ts_min[i].tv_nsec,
+			(time_t)(avg / 10L), (long)(avg % 10L),
+			ts_max[i].tv_sec, ts_max[i].tv_nsec);
 	}	
 	
 	(void)fflush(fp);



CVS commit: src/lib/libperfuse

2011-12-28 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Thu Dec 29 01:40:32 UTC 2011

Modified Files:
src/lib/libperfuse: debug.c

Log Message:
Cast time_t to intmax_t for printf purposes, and format with %j.  Fixes
build on amd64 and probably i386 as well.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libperfuse/debug.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/debug.c
diff -u src/lib/libperfuse/debug.c:1.6 src/lib/libperfuse/debug.c:1.7
--- src/lib/libperfuse/debug.c:1.6	Wed Dec 28 17:33:52 2011
+++ src/lib/libperfuse/debug.c	Thu Dec 29 01:40:32 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: debug.c,v 1.6 2011/12/28 17:33:52 manu Exp $ */
+/*  $NetBSD: debug.c,v 1.7 2011/12/29 01:40:32 riz Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -159,8 +159,9 @@ perfuse_trace_dump(pu, fp)
 	TAILQ_FOREACH(pt, &ps->ps_trace, pt_list) {
 		const char *quote = pt->pt_path[0] != '\0' ? "\"" : "";
 
-		fprintf(fp, "%lu.%09ld %s %s%s%s %s ",  
-			pt->pt_start.tv_sec, pt->pt_start.tv_nsec,
+		fprintf(fp, "%ju.%09jd %s %s%s%s %s ",  
+			(intmax_t)pt->pt_start.tv_sec,
+			(intmax_t)pt->pt_start.tv_nsec,
 			perfuse_opname(pt->pt_opcode),
 			quote, pt->pt_path, quote,
 			pt->pt_extra);
@@ -172,8 +173,8 @@ perfuse_trace_dump(pu, fp)
 			ts.tv_nsec = 0;	/* delint */
 			timespecsub(&pt->pt_end, &pt->pt_start, &ts);
 
-			fprintf(fp, "error = %d elapsed = %lu.%09lu ",
-pt->pt_error, ts.tv_sec, ts.tv_nsec);
+			fprintf(fp, "error = %d elapsed = %ju.%09lu ",
+pt->pt_error, (intmax_t)ts.tv_sec, ts.tv_nsec);
 
 			count[pt->pt_opcode]++;
 			timespecadd(&ts_total[pt->pt_opcode],
@@ -206,11 +207,12 @@ perfuse_trace_dump(pu, fp)
 			min = 0;
 		}
 			
-		fprintf(fp, "%s\t%d\t%ld.%09ld\t%ld.%09ld\t%ld.%09ld\t\n",
+		fprintf(fp, "%s\t%d\t%jd.%09ld\t%jd.%09ld\t%jd.%09ld\t\n",
 			perfuse_opname(i), count[i],
-			min, ts_min[i].tv_nsec,
-			(time_t)(avg / 10L), (long)(avg % 10L),
-			ts_max[i].tv_sec, ts_max[i].tv_nsec);
+			(intmax_t)min, ts_min[i].tv_nsec,
+			(intmax_t)(avg / 10L),
+			(long)(avg % 10L),
+			(intmax_t)ts_max[i].tv_sec, ts_max[i].tv_nsec);
 	}	
 	
 	(void)fflush(fp);



CVS commit: src/lib/libperfuse

2011-12-15 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Fri Dec 16 05:34:54 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Rework puffs_framebuf management toremove leaks and abusive reuses. On
exchange error, the puffs_framebuf is now freed immediatly, before
requeuing outstanding requests.


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/lib/libperfuse/ops.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.47 src/lib/libperfuse/ops.c:1.48
--- src/lib/libperfuse/ops.c:1.47	Mon Nov 28 05:33:33 2011
+++ src/lib/libperfuse/ops.c	Fri Dec 16 05:34:54 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.47 2011/11/28 05:33:33 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.48 2011/12/16 05:34:54 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -187,21 +187,14 @@ perfuse_node_close_common(pu, opc, mode)
 
 	if ((error = xchg_msg(pu, opc, pm,
 			  NO_PAYLOAD_REPLY_LEN, wait_reply)) != 0)
-		goto out;
-
-	ps->ps_destroy_msg(pm);
-
-	error = 0;
-
-out:
-	if (error != 0)
 		DERRX(EX_SOFTWARE, "%s: freed fh = 0x%"PRIx64" but filesystem "
 		  "returned error = %d", __func__, fh, error);
 
-	return error;
+	ps->ps_destroy_msg(pm);
+
+	return 0;
 }
 
-/* ARGSUSED1 */
 static int
 xchg_msg(pu, opc, pm, len, wait)
 	struct puffs_usermount *pu;
@@ -229,7 +222,8 @@ xchg_msg(pu, opc, pm, len, wait)
 	if (pnd)
 		pnd->pnd_flags |= PND_INXCHG;
 
-	error = ps->ps_xchg_msg(pu, pm, len, wait);
+	if ((error = ps->ps_xchg_msg(pu, pm, len, wait)) != 0)
+		ps->ps_destroy_msg(pm);
 
 	if (pnd) {
 		pnd->pnd_flags &= ~PND_INXCHG;
@@ -523,7 +517,7 @@ node_lookup_common(pu, opc, path, pcr, p
 		}
 		/* FALLTHROUGH */
 	default:
-		goto out;
+		return error;
 		/* NOTREACHED */
 		break;
 	}
@@ -534,7 +528,9 @@ node_lookup_common(pu, opc, path, pcr, p
 		if (oldpnd->pnd_nodeid == feo->nodeid) {
 			oldpnd->pnd_nlookup++;
 			*pnp = oldpnd->pnd_pn;
-			goto out;
+
+			ps->ps_destroy_msg(pm);
+			return 0;
 		} else {
 			oldpnd->pnd_flags |= PND_REMOVED;
 #ifdef PERFUSE_DEBUG
@@ -563,10 +559,9 @@ node_lookup_common(pu, opc, path, pcr, p
 			(void *)opc, pn, feo->nodeid, path);
 #endif
 	
-out: 
 	ps->ps_destroy_msg(pm);
 
-	return error;
+	return 0;
 }
 
 
@@ -592,7 +587,7 @@ node_mk_common(pu, opc, pni, pcn, pm)
 	ps =  puffs_getspecific(pu);
 
 	if ((error = xchg_msg(pu, opc, pm, sizeof(*feo), wait_reply)) != 0)
-		goto out;
+		return error;
 
 	feo = GET_OUTPAYLOAD(ps, pm, fuse_entry_out);
 	if (feo->nodeid == PERFUSE_UNKNOWN_NODEID)
@@ -617,11 +612,6 @@ node_mk_common(pu, opc, pni, pcn, pm)
 	ps->ps_destroy_msg(pm);
 
 	return node_mk_common_final(pu, opc, pn, pcn);
-
-out:
-	ps->ps_destroy_msg(pm);
-
-	return error;
 }
 
 /*
@@ -664,7 +654,7 @@ node_mk_common_final(pu, opc, pn, pcn)
 
 	if ((error = xchg_msg(pu, (puffs_cookie_t)pn, pm, 
 			  sizeof(*fao), wait_reply)) != 0)
-		goto out;
+		return error;
 
 	fao = GET_OUTPAYLOAD(ps, pm, fuse_attr_out);
 	fuse_attr_to_vap(ps, &pn->pn_va, &fao->attr);
@@ -675,11 +665,9 @@ node_mk_common_final(pu, opc, pn, pcn)
 	 */
 	PERFUSE_NODE_DATA(opc)->pnd_flags |= PND_DIRTY;
 
-out:
-	if (pm != NULL)
-		ps->ps_destroy_msg(pm);
+	ps->ps_destroy_msg(pm);
 
-	return error;
+	return 0;
 }
 
 static uint64_t
@@ -1022,7 +1010,11 @@ perfuse_fs_unmount(pu, flags)
 	if ((error = xchg_msg(pu, opc, pm, UNSPEC_REPLY_LEN, wait_reply)) != 0){
 		DWARN("unmount %s", ps->ps_target);
 		if (!(flags & MNT_FORCE))
-			goto out;
+			return error;
+		else
+			error = 0;
+	} else {
+		ps->ps_destroy_msg(pm);
 	}
 
 	ps->ps_umount(pu);
@@ -1031,10 +1023,6 @@ perfuse_fs_unmount(pu, flags)
 		DPRINTF("%s unmounted, exit\n", ps->ps_target);
 
 	return 0;
-out:
-	ps->ps_destroy_msg(pm);
-	
-	return error;
 }
 
 int
@@ -1058,7 +1046,7 @@ perfuse_fs_statvfs(pu, svfsb)
 	pm = ps->ps_new_msg(pu, opc, FUSE_STATFS, 0, NULL);
 
 	if ((error = xchg_msg(pu, opc, pm, sizeof(*fso), wait_reply)) != 0)
-		goto out;
+		return error;
 
 	fso = GET_OUTPAYLOAD(ps, pm, fuse_statfs_out);
 	svfsb->f_flag = ps->ps_mountflags;
@@ -1097,10 +1085,10 @@ perfuse_fs_statvfs(pu, svfsb)
 		strlcpy(svfsb->f_mntfromname, ps->ps_source, _VFS_NAMELEN);
 	else
 		strlcpy(svfsb->f_mntfromname, _PATH_FUSE, _VFS_NAMELEN);
-out:
+
 	ps->ps_destroy_msg(pm);
-	
-	return error;
+
+	return 0;
 }
 
 int
@@ -1338,8 +1326,18 @@ perfuse_node_create(pu, opc, pni, pcn, v
 	(void)strlcpy((char*)(void *)(fci + 1), name, namelen);
 
 	len = sizeof(*feo) + sizeof(*foo);
-	if ((error = xchg_msg(pu, opc, pm, len, wait_reply)) != 0)
-		goto out;
+	if ((error = xchg_msg(pu, opc, pm, len, wait_reply)) != 0) {
+		/*
+		 * create is unimplmented, remember it for later,
+		 * and start over using mknod and open instead.
+		 */
+		if (error == ENOSYS) {
+			ps->ps_flags |= PS_NO_CREAT;
+			return perfuse_node_create(pu, opc, pni, pcn, vap);
+		}
+
+		re

CVS commit: src/lib/libperfuse

2011-11-27 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon Nov 28 05:33:33 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
- Add missing ENOENT or ESTALL when accessing deleted node
- Fix a warning, fix style (80 chars for a line)


To generate a diff of this commit:
cvs rdiff -u -r1.46 -r1.47 src/lib/libperfuse/ops.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.46 src/lib/libperfuse/ops.c:1.47
--- src/lib/libperfuse/ops.c:1.46	Thu Nov 17 02:28:21 2011
+++ src/lib/libperfuse/ops.c	Mon Nov 28 05:33:33 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.46 2011/11/17 02:28:21 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.47 2011/11/28 05:33:33 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -44,6 +44,9 @@
 
 extern int perfuse_diagflags;
 
+#if 0
+static void print_node(const char *, puffs_cookie_t);
+#endif
 static void set_expire(puffs_cookie_t, struct fuse_entry_out *, 
struct fuse_attr_out *);
 static int attr_expired(puffs_cookie_t);
@@ -102,6 +105,27 @@ const int vttoif_tab[9] = { 
 #define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12])
 #define VTTOIF(indx) (vttoif_tab[(int)(indx)])
 
+#if 0
+static void 
+print_node(func, opc)
+	const char *func;
+	puffs_cookie_t opc;
+{
+	struct puffs_node *pn;
+	struct perfuse_node_data *pnd;
+	struct vattr *vap;
+
+	pn = (struct puffs_node *)opc;
+	pnd = PERFUSE_NODE_DATA(opc);
+	vap = &pn->pn_va;
+
+	printf("%s: \"%s\", opc = %p, nodeid = 0x%"PRIx64" ino = %"PRIu64"\n",
+	   func, pnd->pnd_name, opc, pnd->pnd_nodeid, vap->va_fileid);
+
+	return;
+}
+#endif /* PERFUSE_DEBUG */
+	
 int
 perfuse_node_close_common(pu, opc, mode)
 	struct puffs_usermount *pu;
@@ -432,6 +456,12 @@ node_lookup_common(pu, opc, path, pcr, p
 	size_t len;
 	int error;
 
+	/*
+	 * Prevent further lookups if the parent was removed
+	 */
+	if (PERFUSE_NODE_DATA(opc)->pnd_flags & PND_REMOVED)
+		return ESTALE;
+
 	if (pnp == NULL)
 		DERRX(EX_SOFTWARE, "pnp must be != NULL");
 
@@ -453,8 +483,9 @@ node_lookup_common(pu, opc, path, pcr, p
 #ifdef PERFUSE_DEBUG
 		if (perfuse_diagflags & PDF_FILENAME)
 			DPRINTF("%s: opc = %p, file = \"%s\" found "
-"cookie = %p, nodeid = 0x%"PRIx64" for \"%s\"\n",
-__func__, (void *)opc, perfuse_node_path(opc), 
+"cookie = %p, nodeid = 0x%"PRIx64" "
+"for \"%s\"\n", __func__, 
+(void *)opc, perfuse_node_path(opc), 
 (void *)oldpnd->pnd_pn, oldpnd->pnd_nodeid,	
 path);
 #endif
@@ -1180,6 +1211,15 @@ perfuse_node_lookup(pu, opc, pni, pcn)
 		return error;
 
 	/*
+	 * Kernel would kill us if the filesystem returned the parent
+	 * itself. If we want to live, hide that!
+	 */
+	if ((opc == (puffs_cookie_t)pn) && (strcmp(pcn->pcn_name, ".") != 0)) {
+		DWARNX("lookup returned parent");
+		return ESTALE;
+	}
+
+	/*
 	 * Removed node
 	 */
 	if (PERFUSE_NODE_DATA(pn)->pnd_flags & PND_REMOVED)
@@ -2337,7 +2377,9 @@ perfuse_node_rmdir(pu, opc, targ, pcn)
 	int error;
 	
 	pnd = PERFUSE_NODE_DATA(opc);
-	if (pnd->pnd_flags & PND_REMOVED)
+
+	if ((pnd->pnd_flags & PND_REMOVED) ||
+	(PERFUSE_NODE_DATA(targ)->pnd_flags & PND_REMOVED))
 		return ENOENT;
 
 	/*
@@ -2884,7 +2926,7 @@ perfuse_node_advlock(pu, opc, id, op, fl
 	fli->lk.pid = fl->l_pid;
 	fli->lk_flags = (flags & F_FLOCK) ? FUSE_LK_FLOCK : 0;
 
-	owner = (uint64_t)(vaddr_t)id;
+	owner = (uint32_t)(vaddr_t)id;
 
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & PDF_FH)



CVS commit: src/lib/libperfuse

2011-11-16 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Thu Nov 17 02:28:21 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Copy node expiration date before comparing it, otherwise the comparison
does not work (no idea why) and cached node is never used.


To generate a diff of this commit:
cvs rdiff -u -r1.45 -r1.46 src/lib/libperfuse/ops.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.45 src/lib/libperfuse/ops.c:1.46
--- src/lib/libperfuse/ops.c:1.45	Wed Nov 16 04:52:40 2011
+++ src/lib/libperfuse/ops.c	Thu Nov 17 02:28:21 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.45 2011/11/16 04:52:40 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.46 2011/11/17 02:28:21 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -374,12 +374,13 @@ entry_expired(opc)
 	puffs_cookie_t opc;
 {
 	struct perfuse_node_data *pnd = PERFUSE_NODE_DATA(opc);
+	struct timespec expire = pnd->pnd_entry_expire;
 	struct timespec now;
 
 	if (clock_gettime(CLOCK_REALTIME, &now) != 0)
 		DERR(EX_OSERR, "clock_gettime failed");
 
-	return timespeccmp(&pnd->pnd_entry_expire, &now, <);
+	return timespeccmp(&expire, &now, <);
 }
 
 



CVS commit: src/lib/libperfuse

2011-11-15 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Wed Nov 16 04:52:40 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Correctly pass the advlock owner id from kernel to filesystem, instead of
using process PID.

Allow the usage of the read filehandle for advlock, in order to support
shared locks on read-only files


To generate a diff of this commit:
cvs rdiff -u -r1.44 -r1.45 src/lib/libperfuse/ops.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.44 src/lib/libperfuse/ops.c:1.45
--- src/lib/libperfuse/ops.c:1.44	Thu Nov 10 16:21:09 2011
+++ src/lib/libperfuse/ops.c	Wed Nov 16 04:52:40 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.44 2011/11/10 16:21:09 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.45 2011/11/16 04:52:40 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -2825,8 +2825,6 @@ perfuse_node_pathconf(pu, opc, name, ret
 	return 0;
 }
 
-/* id is unused */
-/* ARGSUSED2 */
 int
 perfuse_node_advlock(pu, opc, id, op, fl, flags)
 	struct puffs_usermount *pu;
@@ -2839,6 +2837,7 @@ perfuse_node_advlock(pu, opc, id, op, fl
 	struct perfuse_state *ps;
 	int fop;
 	perfuse_msg_t *pm;
+	uint64_t fh;
 	struct fuse_lk_in *fli;
 	struct fuse_out_header *foh;
 	struct fuse_lk_out *flo;
@@ -2846,6 +2845,20 @@ perfuse_node_advlock(pu, opc, id, op, fl
 	size_t len;
 	int error;
 	
+	/*
+	 * Make sure we do have a filehandle, as the FUSE filesystem
+	 * expect one. E.g.: if we provide none, GlusterFS logs an error
+	 * "0-glusterfs-fuse: xl is NULL"
+	 *
+	 * We need the read file handle if the file is open read only,
+	 * in order to support shared locks on read-only files.
+	 * NB: The kernel always sends advlock for read-only
+	 * files at exit time when the process used lock, see
+	 * sys_exit -> exit1 -> fd_free -> fd_close -> VOP_ADVLOCK
+	 */
+	if ((fh = perfuse_get_fh(opc, FREAD)) == FUSE_UNKNOWN_FH)
+		return EBADF;
+
 	ps = puffs_getspecific(pu);
 
 	if (op == F_GETLK)
@@ -2862,15 +2875,15 @@ perfuse_node_advlock(pu, opc, id, op, fl
 	 */
 	pm = ps->ps_new_msg(pu, opc, fop, sizeof(*fli), NULL);
 	fli = GET_INPAYLOAD(ps, pm, fuse_lk_in);
-	fli->fh = perfuse_get_fh(opc, FWRITE);
-	fli->owner = fl->l_pid;
+	fli->fh = fh;
+	fli->owner = (uint64_t)(vaddr_t)id;
 	fli->lk.start = fl->l_start;
 	fli->lk.end = fl->l_start + fl->l_len;
 	fli->lk.type = fl->l_type;
 	fli->lk.pid = fl->l_pid;
 	fli->lk_flags = (flags & F_FLOCK) ? FUSE_LK_FLOCK : 0;
 
-	owner = fl->l_pid;
+	owner = (uint64_t)(vaddr_t)id;
 
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & PDF_FH)



CVS commit: src/lib/libperfuse

2011-11-10 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Thu Nov 10 16:21:10 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Return EISDIR for read/write to directories. NetBSD directory read should
instead return a getent(2) output, but is that really used?


To generate a diff of this commit:
cvs rdiff -u -r1.43 -r1.44 src/lib/libperfuse/ops.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.43 src/lib/libperfuse/ops.c:1.44
--- src/lib/libperfuse/ops.c:1.43	Sun Oct 30 05:11:37 2011
+++ src/lib/libperfuse/ops.c	Thu Nov 10 16:21:09 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.43 2011/10/30 05:11:37 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.44 2011/11/10 16:21:09 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -2954,6 +2954,13 @@ perfuse_node_read(pu, opc, buf, offset, 
 	vap = puffs_pn_getvap((struct puffs_node *)opc);
 	pm = NULL;
 
+	/*
+	 * NetBSD turns that into a getdents(2) output
+	 * We just do a EISDIR as this feature is of little use.
+	 */
+	if (vap->va_type == VDIR)
+		return EISDIR;
+
 	if ((u_quad_t)offset + *resid > vap->va_size)
 		DWARNX("%s %p read %lld@%zu beyond EOF %" PRIu64 "\n",
 		   __func__, (void *)opc, (long long)offset,
@@ -3048,7 +3055,7 @@ perfuse_node_write(pu, opc, buf, offset,
 	pm = NULL;
 
 	if (vap->va_type == VDIR) 
-		return EBADF;
+		return EISDIR;
 
 	/*
 	 * We need to queue write requests in order to avoid



CVS commit: src/lib/libperfuse

2011-10-29 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sun Oct 30 05:11:37 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c perfuse.c perfuse_if.h perfuse_priv.h subr.c

Log Message:
- Fix the confusion between fileno (opaque FUSE reference) and inode
  numbers. fileno must be used when exchanging FUSE messages.
- Do not use kernel name cache anymore, as it caused modification from
  other machines to be invisible.
- Honour name and attribute cache directive from FUSE filesystem


To generate a diff of this commit:
cvs rdiff -u -r1.42 -r1.43 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.22 -r1.23 src/lib/libperfuse/perfuse.c \
src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.16 -r1.17 src/lib/libperfuse/perfuse_if.h
cvs rdiff -u -r1.13 -r1.14 src/lib/libperfuse/subr.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.42 src/lib/libperfuse/ops.c:1.43
--- src/lib/libperfuse/ops.c:1.42	Sat Sep 10 10:06:10 2011
+++ src/lib/libperfuse/ops.c	Sun Oct 30 05:11:37 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.42 2011/09/10 10:06:10 tron Exp $ */
+/*  $NetBSD: ops.c,v 1.43 2011/10/30 05:11:37 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -44,6 +44,10 @@
 
 extern int perfuse_diagflags;
 
+static void set_expire(puffs_cookie_t, struct fuse_entry_out *, 
+   struct fuse_attr_out *);
+static int attr_expired(puffs_cookie_t);
+static int entry_expired(puffs_cookie_t);
 static int xchg_msg(struct puffs_usermount *, puffs_cookie_t, 
 perfuse_msg_t *, size_t, enum perfuse_xchg_pb_reply); 
 static int mode_access(puffs_cookie_t, const struct puffs_cred *, mode_t);
@@ -153,8 +157,8 @@ perfuse_node_close_common(pu, opc, mode)
 
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & PDF_FH)
-		DPRINTF("%s: opc = %p, ino = %"PRId64", fh = 0x%"PRIx64"\n",
-			 __func__, (void *)opc, pnd->pnd_ino, fri->fh);
+		DPRINTF("%s: opc = %p, nodeid = 0x%"PRIx64", fh = 0x%"PRIx64"\n",
+			 __func__, (void *)opc, pnd->pnd_nodeid, fri->fh);
 #endif
 
 	if ((error = xchg_msg(pu, opc, pm,
@@ -193,8 +197,9 @@ xchg_msg(pu, opc, pm, len, wait)
 
 #ifdef PERFUSE_DEBUG
 	if ((perfuse_diagflags & PDF_FILENAME) && (opc != 0))
-		DPRINTF("file = \"%s\" flags = 0x%x\n", 
-			perfuse_node_path(opc),
+		DPRINTF("file = \"%s\", ino = %"PRIu64" flags = 0x%x\n", 
+			perfuse_node_path(opc), 
+			((struct puffs_node *)opc)->pn_va.va_fileid,
 			PERFUSE_NODE_DATA(opc)->pnd_flags);
 #endif
 	if (pnd)
@@ -309,6 +314,74 @@ fuse_attr_to_vap(ps, vap, fa)
 	return;
 }
 
+static void 
+set_expire(opc, feo, fao)
+	puffs_cookie_t opc;
+	struct fuse_entry_out *feo;
+	struct fuse_attr_out *fao;
+{
+	struct perfuse_node_data *pnd = PERFUSE_NODE_DATA(opc);
+	struct timespec entry_ts;
+	struct timespec attr_ts;
+	struct timespec now;
+
+	if ((feo == NULL) && (fao == NULL))
+		DERRX(EX_SOFTWARE, "%s: feo and fao NULL", __func__);
+
+	if ((feo != NULL) && (fao != NULL))
+		DERRX(EX_SOFTWARE, "%s: feo and fao != NULL", __func__);
+
+	if (clock_gettime(CLOCK_REALTIME, &now) != 0)
+		DERR(EX_OSERR, "clock_gettime failed");
+
+	if (feo != NULL) {
+		entry_ts.tv_sec = (time_t)feo->entry_valid;
+		entry_ts.tv_nsec = (long)feo->entry_valid_nsec;
+
+		timespecadd(&now, &entry_ts, &pnd->pnd_entry_expire);
+
+		attr_ts.tv_sec = (time_t)feo->attr_valid;
+		attr_ts.tv_nsec = (long)feo->attr_valid_nsec;
+
+		timespecadd(&now, &attr_ts, &pnd->pnd_attr_expire);
+	} 
+
+	if (fao != NULL) {
+		attr_ts.tv_sec = (time_t)fao->attr_valid;
+		attr_ts.tv_nsec = (long)fao->attr_valid_nsec;
+
+		timespecadd(&now, &attr_ts, &pnd->pnd_attr_expire);
+	} 
+
+	return;
+}
+
+static int
+attr_expired(opc)
+	puffs_cookie_t opc;
+{
+	struct perfuse_node_data *pnd = PERFUSE_NODE_DATA(opc);
+	struct timespec now;
+
+	if (clock_gettime(CLOCK_REALTIME, &now) != 0)
+		DERR(EX_OSERR, "clock_gettime failed");
+
+	return timespeccmp(&pnd->pnd_attr_expire, &now, <);
+}
+
+static int
+entry_expired(opc)
+	puffs_cookie_t opc;
+{
+	struct perfuse_node_data *pnd = PERFUSE_NODE_DATA(opc);
+	struct timespec now;
+
+	if (clock_gettime(CLOCK_REALTIME, &now) != 0)
+		DERR(EX_OSERR, "clock_gettime failed");
+
+	return timespeccmp(&pnd->pnd_entry_expire, &now, <);
+}
+
 
 /* 
  * Lookup name in directory opc
@@ -323,12 +396,8 @@ node_lookup_dir_nodot(pu, opc, name, nam
 	size_t namelen;
 	struct puffs_node **pnp;
 {
-	char *path;
-	struct puffs_node *dpn = (struct puffs_node *)opc;
-	int error;
-
 	/*
-	 *  is easy as we already know it
+	 * "dot" is easy as we already know it
 	 */
 	if (strncmp(name, ".", namelen) == 0) {
 		*pnp = (struct puffs_node *)opc;
@@ -336,22 +405,14 @@ node_lookup_dir_nodot(pu, opc, name, nam
 	}
 
 	/*
-	 * For .. we just forget the name part
+	 * "dotdot" is also known
 	 */
-	if (strncmp(name, "..", namelen) == 0)
-		namelen = 0;
-
-	namelen = PNPLEN(dpn) + 1 + namelen + 1;
-	if ((path = malloc(n

CVS commit: src/lib/libperfuse

2011-10-22 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sun Oct 23 05:01:00 UTC 2011

Modified Files:
src/lib/libperfuse: perfuse.c

Log Message:
perfuse memory usage can grow quite large when using a lot of vnodes,
and the amount of data memory involved is not easy to forcast. We therefore
raise the limit to the maximum.

Patch from Manuel Bouyer. It helps completing a cvs update on a glusterfs
colume.


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libperfuse/perfuse.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/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.21 src/lib/libperfuse/perfuse.c:1.22
--- src/lib/libperfuse/perfuse.c:1.21	Tue Oct 18 15:47:32 2011
+++ src/lib/libperfuse/perfuse.c	Sun Oct 23 05:01:00 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.21 2011/10/18 15:47:32 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.22 2011/10/23 05:01:00 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -34,6 +34,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -399,6 +400,22 @@ perfuse_init(pc, pmi)
 	unsigned int puffs_flags;
 	struct puffs_node *pn_root;
 	struct puffs_pathobj *po_root;
+	struct rlimit rl;
+
+	/*
+	 * perfused can grow quite large, let assume there's enough ram ...
+	 */
+	if (getrlimit(RLIMIT_DATA, &rl) < 0) {
+		DERR(EX_OSERR, "%s: getrlimit failed: %s", __func__,
+		strerror(errno));
+	} else {
+		rl.rlim_cur = rl.rlim_max;
+		if (setrlimit(RLIMIT_DATA, &rl) < 0) {
+			DERR(EX_OSERR, "%s: setrlimit failed: %s", __func__,
+			strerror(errno));
+		}
+	}
+		
 
 	ps = init_state();
 	ps->ps_owner_uid = pmi->pmi_uid;



CVS commit: src/lib/libperfuse

2011-10-18 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue Oct 18 15:47:32 UTC 2011

Modified Files:
src/lib/libperfuse: perfuse.c

Log Message:
mlockall is not necessary after all, once we have fixed a kernel bug involving
agedaemon sleeping form memory


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libperfuse/perfuse.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/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.20 src/lib/libperfuse/perfuse.c:1.21
--- src/lib/libperfuse/perfuse.c:1.20	Fri Sep  9 22:51:44 2011
+++ src/lib/libperfuse/perfuse.c	Tue Oct 18 15:47:32 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.20 2011/09/09 22:51:44 christos Exp $ */
+/*  $NetBSD: perfuse.c,v 1.21 2011/10/18 15:47:32 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -400,13 +400,6 @@ perfuse_init(pc, pmi)
 	struct puffs_node *pn_root;
 	struct puffs_pathobj *po_root;
 
-	/*
-	 * perfused needs to remain in memory. If it gets
-	 * swapped out, the kernel will deadlock when trying
-	 * to free memory backed by the PUFFS filesystem
-	 */
-	mlockall(MCL_CURRENT|MCL_FUTURE);
-
 	ps = init_state();
 	ps->ps_owner_uid = pmi->pmi_uid;
 



CVS commit: src/lib/libperfuse

2011-09-10 Thread Matthias Scheler
Module Name:src
Committed By:   tron
Date:   Sat Sep 10 10:06:10 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Avoid comparison between signed and unsigned integer expressions by
casting the offset to a unsigned type. This fixes the NetBSD/i386
and hopefully the NetBSD/amd64 build.


To generate a diff of this commit:
cvs rdiff -u -r1.41 -r1.42 src/lib/libperfuse/ops.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.41 src/lib/libperfuse/ops.c:1.42
--- src/lib/libperfuse/ops.c:1.41	Fri Sep  9 22:51:44 2011
+++ src/lib/libperfuse/ops.c	Sat Sep 10 10:06:10 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.41 2011/09/09 22:51:44 christos Exp $ */
+/*  $NetBSD: ops.c,v 1.42 2011/09/10 10:06:10 tron Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -2835,7 +2835,7 @@
 	vap = puffs_pn_getvap((struct puffs_node *)opc);
 	pm = NULL;
 
-	if (offset + *resid > vap->va_size)
+	if ((u_quad_t)offset + *resid > vap->va_size)
 		DWARNX("%s %p read %lld@%zu beyond EOF %" PRIu64 "\n",
 		   __func__, (void *)opc, (long long)offset,
 		   *resid, vap->va_size);
@@ -2942,7 +2942,7 @@
 	/* 
 	 * Serialize size access, see comment in perfuse_node_setattr().
 	 */
-	if (offset + *resid > vap->va_size) {
+	if ((u_quad_t)offset + *resid > vap->va_size) {
 		while (pnd->pnd_flags & PND_INRESIZE)
 			requeue_request(pu, opc, PCQ_RESIZE);
 		pnd->pnd_flags |= PND_INRESIZE;



CVS commit: src/lib/libperfuse

2011-09-09 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Fri Sep  9 22:51:44 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c perfuse.c

Log Message:
make this build on amd64 and remove redundant and unused code.


To generate a diff of this commit:
cvs rdiff -u -r1.40 -r1.41 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.19 -r1.20 src/lib/libperfuse/perfuse.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.40 src/lib/libperfuse/ops.c:1.41
--- src/lib/libperfuse/ops.c:1.40	Fri Sep  9 11:45:28 2011
+++ src/lib/libperfuse/ops.c	Fri Sep  9 18:51:44 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.40 2011/09/09 15:45:28 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.41 2011/09/09 22:51:44 christos Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -847,7 +847,7 @@
 	fii = GET_INPAYLOAD(ps, pm, fuse_init_in);
 	fii->major = FUSE_KERNEL_VERSION;
 	fii->minor = FUSE_KERNEL_MINOR_VERSION;
-	fii->max_readahead = 32 * sysconf(_SC_PAGESIZE); 
+	fii->max_readahead = (unsigned int)(32 * sysconf(_SC_PAGESIZE));
 	fii->flags = (FUSE_ASYNC_READ|FUSE_POSIX_LOCKS|FUSE_ATOMIC_O_TRUNC);
 
 	if ((error = xchg_msg(pu, 0, pm, sizeof(*fio), wait_reply)) != 0)
@@ -1490,7 +1490,6 @@
 	struct perfuse_node_data *pnd = PERFUSE_NODE_DATA(opc);
 	struct fuse_getattr_in *fgi;
 	struct fuse_attr_out *fao;
-	u_quad_t va_size;
 	int error;
 	
 	if (pnd->pnd_flags & PND_REMOVED)
@@ -1504,7 +1503,6 @@
 	pnd->pnd_flags |= PND_INRESIZE;
 
 	ps = puffs_getspecific(pu);
-	va_size = vap->va_size;
 
 	/*
 	 * FUSE_GETATTR_FH must be set in fgi->flags 
@@ -1523,7 +1521,8 @@
 
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & PDF_RESIZE)
-		DPRINTF(">> %s %p %lld\n", __func__, (void *)opc, va_size);
+		DPRINTF(">> %s %p %" PRIu64 "\n", __func__, (void *)opc,
+		vap->va_size);
 #endif
 
 	if ((error = xchg_msg(pu, opc, pm, sizeof(*fao), wait_reply)) != 0)
@@ -1533,8 +1532,8 @@
 
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & PDF_RESIZE)
-		DPRINTF("<< %s %p %lld -> %lld\n", __func__, (void *)opc, 
-			va_size, fao->attr.size);
+		DPRINTF("<< %s %p %" PRIu64 " -> %" PRIu64 "\n", __func__,
+		(void *)opc, vap->va_size, fao->attr.size);
 #endif
 
 	/* 
@@ -1741,9 +1740,10 @@
 	(old_vap->va_size != (u_quad_t)PUFFS_VNOVAL)) {
 		resize_debug = 1;
 
-		DPRINTF(">> %s %p %lld -> %lld\n", __func__, (void *)opc, 
-			puffs_pn_getvap((struct puffs_node *)opc)->va_size, 
-			fsi->size);
+		DPRINTF(">> %s %p %" PRIu64 " -> %" PRIu64 "\n", __func__,
+		(void *)opc,
+		puffs_pn_getvap((struct puffs_node *)opc)->va_size, 
+		fsi->size);
 	}
 #endif
 
@@ -1757,8 +1757,8 @@
 
 #ifdef PERFUSE_DEBUG
 	if (resize_debug)
-		DPRINTF("<< %s %p %lld -> %lld\n", __func__, (void *)opc, 
-			old_vap->va_size, fao->attr.size);
+		DPRINTF("<< %s %p %" PRIu64 " -> %" PRIu64 "\n", __func__,
+		(void *)opc, old_vap->va_size, fao->attr.size);
 #endif
 
 	fuse_attr_to_vap(ps, old_va, &fao->attr);
@@ -2836,8 +2836,9 @@
 	pm = NULL;
 
 	if (offset + *resid > vap->va_size)
-		DWARNX("%s %p read %lld@%d beyond EOF %lld\n",
-		   __func__, (void *)opc, offset, *resid, vap->va_size);
+		DWARNX("%s %p read %lld@%zu beyond EOF %" PRIu64 "\n",
+		   __func__, (void *)opc, (long long)offset,
+		   *resid, vap->va_size);
 
 	do {
 		size_t max_read;
@@ -2965,7 +2966,7 @@
 
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & PDF_RESIZE)
-		DPRINTF(">> %s %p %lld \n", __func__,
+		DPRINTF(">> %s %p %" PRIu64 "\n", __func__,
 			(void *)opc, vap->va_size);
 #endif
 
@@ -3038,8 +3039,8 @@
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & PDF_RESIZE) {
 		if (offset > (off_t)vap->va_size)
-			DPRINTF("<< %s %p %lld -> %lld\n", __func__, 
-(void *)opc, vap->va_size, offset);
+			DPRINTF("<< %s %p %" PRIu64 " -> %lld\n", __func__, 
+(void *)opc, vap->va_size, (long long)offset);
 		else
 			DPRINTF("<< %s %p \n", __func__, (void *)opc);
 	}
@@ -3135,7 +3136,7 @@
 
 	pm = ps->ps_new_msg(pu, opc, FUSE_GETXATTR, len, pcr);
 	fgi = GET_INPAYLOAD(ps, pm, fuse_getxattr_in);
-	fgi->size = (resid != NULL) ? *resid : 0;
+	fgi->size = (unsigned int)((resid != NULL) ? *resid : 0);
 	np = (char *)(void *)(fgi + 1);
 	(void)strlcpy(np, attrname, attrnamelen);
 	
@@ -3200,7 +3201,7 @@
 
 	pm = ps->ps_new_msg(pu, opc, FUSE_SETXATTR, len, pcr);
 	fsi = GET_INPAYLOAD(ps, pm, fuse_setxattr_in);
-	fsi->size = *resid;
+	fsi->size = (unsigned int)*resid;
 	fsi->flags = 0;
 	np = (char *)(void *)(fsi + 1);
 	(void)strlcpy(np, attrname, attrnamelen);
@@ -3245,7 +3246,7 @@
 	pm = ps->ps_new_msg(pu, opc, FUSE_LISTXATTR, len, pcr);
 	fgi = GET_INPAYLOAD(ps, pm, fuse_getxattr_in);
 	if (resid != NULL)
-		fgi->size = *resid;
+		fgi->size = (unsigned int)*resid;
 	else
 		fgi->size = 0;
 	

Index: src/lib/libperfuse/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.19 src/lib/libperfuse/perfuse.c:1.20
--- src/lib

CVS commit: src/lib/libperfuse

2011-09-09 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Fri Sep  9 15:35:22 UTC 2011

Modified Files:
src/lib/libperfuse: perfuse.c

Log Message:
Make sure perfused remains locked in memory, otherwise we can get
deadlocks in low memory situations, where ioflush waits for perfused
to fsync vnodes, and perfused waits for memory to be freed.


To generate a diff of this commit:
cvs rdiff -u -r1.18 -r1.19 src/lib/libperfuse/perfuse.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/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.18 src/lib/libperfuse/perfuse.c:1.19
--- src/lib/libperfuse/perfuse.c:1.18	Sat Aug 13 23:12:15 2011
+++ src/lib/libperfuse/perfuse.c	Fri Sep  9 15:35:22 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.18 2011/08/13 23:12:15 christos Exp $ */
+/*  $NetBSD: perfuse.c,v 1.19 2011/09/09 15:35:22 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -33,6 +33,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 #include 
 #include 
@@ -407,6 +408,13 @@
 	struct puffs_node *pn_root;
 	struct puffs_pathobj *po_root;
 
+	/*
+	 * perfused needs to remain in memory. If it gets
+	 * swapped out, the kernel will deadlock when trying
+	 * to free memory backed by the PUFFS filesystem
+	 */
+	mlockall(MCL_CURRENT|MCL_FUTURE);
+
 	ps = init_state();
 	ps->ps_owner_uid = pmi->pmi_uid;
 



CVS commit: src/lib/libperfuse

2011-08-14 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sun Aug 14 08:19:04 UTC 2011

Modified Files:
src/lib/libperfuse: Makefile perfuse_if.h

Log Message:
simplify and eliminate non literal string formats.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libperfuse/Makefile
cvs rdiff -u -r1.14 -r1.15 src/lib/libperfuse/perfuse_if.h

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/Makefile
diff -u src/lib/libperfuse/Makefile:1.7 src/lib/libperfuse/Makefile:1.8
--- src/lib/libperfuse/Makefile:1.7	Sat Aug 13 19:12:15 2011
+++ src/lib/libperfuse/Makefile	Sun Aug 14 04:19:04 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.7 2011/08/13 23:12:15 christos Exp $
+# $NetBSD: Makefile,v 1.8 2011/08/14 08:19:04 christos Exp $
 
 LIB=perfuse
 LIBDPLIBS+= puffs	${.CURDIR}/../libpuffs
@@ -16,8 +16,4 @@
 INCS=   perfuse.h
 INCSDIR=	/usr/include
 
-COPTS.ops.c = -Wno-format-nonliteral
-COPTS.perfuse.c = -Wno-format-nonliteral
-COPTS.subr.c = -Wno-format-nonliteral
-
 .include 

Index: src/lib/libperfuse/perfuse_if.h
diff -u src/lib/libperfuse/perfuse_if.h:1.14 src/lib/libperfuse/perfuse_if.h:1.15
--- src/lib/libperfuse/perfuse_if.h:1.14	Sat Aug 13 19:12:15 2011
+++ src/lib/libperfuse/perfuse_if.h	Sun Aug 14 04:19:04 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_if.h,v 1.14 2011/08/13 23:12:15 christos Exp $ */
+/*  $NetBSD: perfuse_if.h,v 1.15 2011/08/14 08:19:04 christos Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -77,18 +77,15 @@
 } while (0 /* CONSTCOND */)
 
 #define DERR(status, fmt, ...) do {	\
-	char fmterr[BUFSIZ];		\
-	char strerrbuf[BUFSIZ];		\
-	\
-	(void)strerror_r(errno, strerrbuf, sizeof(strerrbuf));		\
-	(void)snprintf(fmterr, sizeof(fmterr), "%s: %s\n", fmt, 	\
-	strerrbuf);			\
-	\
 	if (perfuse_diagflags & PDF_SYSLOG)\
-		syslog(LOG_ERR, fmterr, ## __VA_ARGS__);		\
+		syslog(LOG_ERR, fmt ": %m", ## __VA_ARGS__);		\
 	\
 	if (perfuse_diagflags & PDF_FOREGROUND) {			\
-		(void)fprintf(stderr,  fmterr, ## __VA_ARGS__);		\
+		char strerrbuf[BUFSIZ];	\
+	\
+		(void)strerror_r(errno, strerrbuf, sizeof(strerrbuf));	\
+		(void)fprintf(stderr,  fmt ": %s", ## __VA_ARGS__,	\
+		strerrbuf);		\
 		abort();		\
 	} else {			\
 		err(status, fmt, ## __VA_ARGS__);			\
@@ -104,14 +101,8 @@
 
 #define DWARN(fmt, ...) do {		\
 	\
-	if (perfuse_diagflags & PDF_SYSLOG) {\
-		char fmterr[BUFSIZ];	\
-		char strerrbuf[BUFSIZ];	\
-	\
-		(void)strerror_r(errno, strerrbuf, sizeof(strerrbuf));	\
-		(void)sprintf(fmterr, "%s: %s\n", fmt, strerrbuf);	\
-		syslog(LOG_WARNING, fmterr, ## __VA_ARGS__);		\
-	}\
+	if (perfuse_diagflags & PDF_SYSLOG) \
+		syslog(LOG_WARNING, fmt ": %m", ## __VA_ARGS__);	\
 	\
 	warn(fmt, ## __VA_ARGS__);	\
 } while (0 /* CONSTCOND */)



CVS commit: src/lib/libperfuse

2011-08-13 Thread Christos Zoulas
Module Name:src
Committed By:   christos
Date:   Sat Aug 13 23:12:15 UTC 2011

Modified Files:
src/lib/libperfuse: Makefile ops.c perfuse.c perfuse_if.h subr.c

Log Message:
- fix warn/err confusiog
- fix debugging printf
- add func arguments to simple formats


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libperfuse/Makefile
cvs rdiff -u -r1.38 -r1.39 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.17 -r1.18 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.13 -r1.14 src/lib/libperfuse/perfuse_if.h
cvs rdiff -u -r1.12 -r1.13 src/lib/libperfuse/subr.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/Makefile
diff -u src/lib/libperfuse/Makefile:1.6 src/lib/libperfuse/Makefile:1.7
--- src/lib/libperfuse/Makefile:1.6	Tue Jun 28 16:28:48 2011
+++ src/lib/libperfuse/Makefile	Sat Aug 13 19:12:15 2011
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.6 2011/06/28 20:28:48 riz Exp $
+# $NetBSD: Makefile,v 1.7 2011/08/13 23:12:15 christos Exp $
 
 LIB=perfuse
 LIBDPLIBS+= puffs	${.CURDIR}/../libpuffs
@@ -16,4 +16,8 @@
 INCS=   perfuse.h
 INCSDIR=	/usr/include
 
+COPTS.ops.c = -Wno-format-nonliteral
+COPTS.perfuse.c = -Wno-format-nonliteral
+COPTS.subr.c = -Wno-format-nonliteral
+
 .include 

Index: src/lib/libperfuse/ops.c
diff -u src/lib/libperfuse/ops.c:1.38 src/lib/libperfuse/ops.c:1.39
--- src/lib/libperfuse/ops.c:1.38	Tue Aug  9 05:06:52 2011
+++ src/lib/libperfuse/ops.c	Sat Aug 13 19:12:15 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.38 2011/08/09 09:06:52 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.39 2011/08/13 23:12:15 christos Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -343,7 +343,7 @@
 
 	namelen = PNPLEN(dpn) + 1 + namelen + 1;
 	if ((path = malloc(namelen)) == NULL)
-		DERR(EX_OSERR, "malloc failed");
+		DERR(EX_OSERR, "%s: malloc failed", __func__);
 	(void)snprintf(path, namelen, "%s/%s", 
 		   perfuse_node_path((puffs_cookie_t)dpn), name);
 
@@ -609,7 +609,7 @@
 	
 			dents = PERFUSE_NODE_DATA(opc)->pnd_dirent;
 			if ((dents = realloc(dents, dents_len)) == NULL)
-DERR(EX_OSERR, "malloc failed");
+DERR(EX_OSERR, "%s: malloc failed", __func__);
 
 			PERFUSE_NODE_DATA(opc)->pnd_dirent = dents;
 			PERFUSE_NODE_DATA(opc)->pnd_dirent_len = dents_len;
@@ -831,7 +831,7 @@
 	ps = puffs_getspecific(pu);
 	
 if (puffs_mount(pu, ps->ps_target, ps->ps_mountflags, ps->ps_root) != 0)
-DERR(EX_OSERR, "puffs_mount failed");
+DERR(EX_OSERR, "%s: puffs_mount failed", __func__);
 
 	/*
 	 * Linux 2.6.34.1 sends theses flags:
@@ -2388,7 +2388,7 @@
 		pnd->pnd_all_fd = realloc(pnd->pnd_all_fd, 
 	  pnd->pnd_all_fd_len + fd_len);
 		if (pnd->pnd_all_fd  == NULL)
-			DERR(EX_OSERR, "malloc failed");
+			DERR(EX_OSERR, "%s: malloc failed", __func__);
 
 		afdp = (char *)(void *)pnd->pnd_all_fd + pnd->pnd_all_fd_len;
 		(void)memcpy(afdp, fd, fd_len);

Index: src/lib/libperfuse/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.17 src/lib/libperfuse/perfuse.c:1.18
--- src/lib/libperfuse/perfuse.c:1.17	Tue Aug  9 02:58:33 2011
+++ src/lib/libperfuse/perfuse.c	Sat Aug 13 19:12:15 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.17 2011/08/09 06:58:33 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.18 2011/08/13 23:12:15 christos Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -57,7 +57,7 @@
 	char opts[1024];
 
 	if ((ps = malloc(sizeof(*ps))) == NULL)
-		DERR(EX_OSERR, "malloc failed");
+		DERR(EX_OSERR, "%s: malloc failed", __func__);
 
 	(void)memset(ps, 0, sizeof(*ps));
 	ps->ps_max_write = UINT_MAX;
@@ -164,7 +164,7 @@
 
 		if ((sv[0] = socket(PF_LOCAL, SOCK_DGRAM, 0)) == -1) {
 #ifdef PERFUSE_DEBUG
-			DWARN("%s:%d socket failed: %s", __func__, __LINE__);
+			DWARN("%s: %d socket failed", __func__, __LINE__);
 #endif
 			return -1;
 		}
@@ -412,7 +412,7 @@
 
 	if (pmi->pmi_source) {
 		if ((ps->ps_source = strdup(pmi->pmi_source)) == NULL)
-			DERR(EX_OSERR, "strdup failed");
+			DERR(EX_OSERR, "%s: strdup failed", __func__);
 
 		source = ps->ps_source;
 	}
@@ -422,20 +422,20 @@
 
 		ps->ps_filesystemtype = strdup(pmi->pmi_filesystemtype);
 		if (ps->ps_filesystemtype == NULL)
-			DERR(EX_OSERR, "strdup failed");
+			DERR(EX_OSERR, "%s: strdup failed", __func__);
 
 		len = sizeof("perfuse|") + strlen(ps->ps_filesystemtype) + 1;
 		if ((fstype = malloc(len)) == NULL)
-			DERR(EX_OSERR, "malloc failed");
+			DERR(EX_OSERR, "%s: malloc failed", __func__);
 
 		(void)sprintf(fstype, "perfuse|%s", ps->ps_filesystemtype);
 	} else {
 		if ((fstype = strdup("perfuse")) == NULL)
-			DERR(EX_OSERR, "strdup failed");
+			DERR(EX_OSERR, "%s: strdup failed", __func__);
 	}
 
 	if ((ps->ps_target = strdup(pmi->pmi_target)) == NULL)
-		DERR(EX_OSERR, "strdup failed");
+		DERR(EX_OSERR, "%s: strdup failed", __func__);
 
 	ps->ps_mountflags = pmi->pmi_moun

CVS commit: src/lib/libperfuse

2011-08-09 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue Aug  9 09:06:52 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Fix uninitiaized variable usage (never though lint would miss that when
used by return statement) that caused unprivilegied user to fail on
unlink(2) and rename(2) operations.


To generate a diff of this commit:
cvs rdiff -u -r1.37 -r1.38 src/lib/libperfuse/ops.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.37 src/lib/libperfuse/ops.c:1.38
--- src/lib/libperfuse/ops.c:1.37	Tue Aug  2 16:57:16 2011
+++ src/lib/libperfuse/ops.c	Tue Aug  9 09:06:52 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.37 2011/08/02 16:57:16 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.38 2011/08/09 09:06:52 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -241,7 +241,7 @@
 {
 	uid_t uid;
 	struct puffs_node *tdir;
-	int sticky, owner, error;
+	int sticky, owner;
 
 	tdir = PERFUSE_NODE_DATA(targ)->pnd_parent;
 
@@ -264,9 +264,9 @@
 	owner = puffs_pn_getvap(targ)->va_uid == uid;
 
 	if (sticky && !owner)
-		error = EACCES;
+		return EACCES;
 
-	return error;	
+	return 0;
 }
 
 



CVS commit: src/lib/libperfuse

2011-08-08 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue Aug  9 06:58:33 UTC 2011

Modified Files:
src/lib/libperfuse: perfuse.c

Log Message:
Remove PUFFS_KFLAG_WTCACHE, which caused data corruption and slowdown


To generate a diff of this commit:
cvs rdiff -u -r1.16 -r1.17 src/lib/libperfuse/perfuse.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/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.16 src/lib/libperfuse/perfuse.c:1.17
--- src/lib/libperfuse/perfuse.c:1.16	Tue Jun 28 16:19:16 2011
+++ src/lib/libperfuse/perfuse.c	Tue Aug  9 06:58:33 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.16 2011/06/28 16:19:16 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.17 2011/08/09 06:58:33 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -484,7 +484,25 @@
 	PUFFSOP_SET(pops, perfuse, node, deleteextattr);
 #endif /* PUFFS_EXTNAMELEN */
 
-	puffs_flags = PUFFS_KFLAG_WTCACHE;
+	/*
+	 * We used to have PUFFS_KFLAG_WTCACHE here, which uses the
+	 * page cache (highly desirable to get mmap(2)), but still sends
+	 * all writes to the filesystem. In fact it does not send the
+	 * data written, but the pages that contain it. 
+	 *
+	 * There is a nasty bug hidden somewhere, possibly in libpuffs'
+	 * VOP_FSYNC, which sends an asynchronous PUFFS_SETATTR that
+	 * update file size. When writes are in progress, it will cause
+	 * the file to be truncated and we get a zero-filled chunk at the
+	 * beginning of a page. Removing PUFFS_KFLAG_WTCACHE fixes that
+	 * problem. 
+	 * 
+	 * The other consequences are that changes will not be propagated
+	 * immediatly to the filesystem, and we get a huge performance gain
+	 * because much less requests are sent. A test case for the above
+	 * mentioned bug got its execution time slashed by factor 50.
+	 */
+	puffs_flags = 0;
 
 	if (perfuse_diagflags & PDF_PUFFS)
 		puffs_flags |= PUFFS_FLAG_OPDUMP;



CVS commit: src/lib/libperfuse

2011-08-02 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue Aug  2 16:57:17 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Do not reject reads on directory, it raises a useless EBADFD while the
thing can just fail silently.


To generate a diff of this commit:
cvs rdiff -u -r1.36 -r1.37 src/lib/libperfuse/ops.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.36 src/lib/libperfuse/ops.c:1.37
--- src/lib/libperfuse/ops.c:1.36	Tue Aug  2 14:53:38 2011
+++ src/lib/libperfuse/ops.c	Tue Aug  2 16:57:16 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.36 2011/08/02 14:53:38 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.37 2011/08/02 16:57:16 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -2791,9 +2791,6 @@
 	pnd = PERFUSE_NODE_DATA(opc);
 	pm = NULL;
 
-	if (puffs_pn_getvap((struct puffs_node *)opc)->va_type == VDIR) 
-		return EBADF;
-
 	do {
 		size_t max_read;
 



CVS commit: src/lib/libperfuse

2011-07-19 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue Jul 19 07:29:39 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Make sure libperfuse still builds on netbsd-5.1


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/lib/libperfuse/ops.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.34 src/lib/libperfuse/ops.c:1.35
--- src/lib/libperfuse/ops.c:1.34	Mon Jul 18 02:14:01 2011
+++ src/lib/libperfuse/ops.c	Tue Jul 19 07:29:39 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.34 2011/07/18 02:14:01 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.35 2011/07/19 07:29:39 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -3135,6 +3135,7 @@
 	puffs_len = foh->len - sizeof(*foh);
 
 	if (attrs != NULL) {
+#ifdef PUFFS_EXTATTR_LIST_LENPREFIX
 		/* 
 		 * Convert the FUSE reply to length prefixed strings
 		 * if this is what the kernel wants.
@@ -3148,6 +3149,7 @@
 *(np + i) = (uint8_t)attrlen;
 			}	
 		}
+#endif /* PUFFS_EXTATTR_LIST_LENPREFIX */
 		(void)memcpy(attrs, np, puffs_len);
 		*resid -= puffs_len;
 	}



CVS commit: src/lib/libperfuse

2011-07-17 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon Jul 18 02:14:01 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
ftruncate(2) cause a SETATTR with only va_size set, and some filesystems
(e.g.: glusterfs) will do a custom handling in such a situation. This
breaks because libpuffs folds a metadata (va_atime and va_mtime) update
in each SETATTR. We try to identify SETATTR caused by ftruncate(2) and
remove va_atime and va_mtime in such situation.

This fixes a bug with glusterfs, where parts of a file downloaded by
FTP was filled with zeros because of a ftruncate(2) sent out of order
with write(2) requests. glusterfs behavior depends on the undocumented
FUSE rule that ftruncate(2) will only set va_size in SETATTR.


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/lib/libperfuse/ops.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.33 src/lib/libperfuse/ops.c:1.34
--- src/lib/libperfuse/ops.c:1.33	Thu Jul 14 15:37:32 2011
+++ src/lib/libperfuse/ops.c	Mon Jul 18 02:14:01 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.33 2011/07/14 15:37:32 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.34 2011/07/18 02:14:01 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -1652,6 +1652,27 @@
 	}
 
 	/*
+	 * ftruncate() sends only va_size, and metadata cache
+	 * flush adds va_atime and va_mtime. Some FUSE
+	 * filesystems will attempt to detect ftruncate by 
+	 * checking for FATTR_SIZE being set without
+	 * FATTR_UID|FATTR_GID|FATTR_ATIME|FATTR_MTIME|FATTR_MODE
+	 * 
+	 * Try to adapt and remove FATTR_ATIME|FATTR_MTIME
+	 * if we suspect a ftruncate().
+	 */ 
+	if ((va_size != (u_quad_t)PUFFS_VNOVAL) &&
+	((vap->va_mode == (mode_t)PUFFS_VNOVAL) &&
+	 (vap->va_uid == (uid_t)PUFFS_VNOVAL) &&
+	 (vap->va_gid == (gid_t)PUFFS_VNOVAL))) {
+		fsi->atime = 0;
+		fsi->atimensec = 0;
+		fsi->mtime = 0;
+		fsi->mtimensec = 0;
+		fsi->valid &= ~(FUSE_FATTR_ATIME|FUSE_FATTR_MTIME);
+	}
+		
+	/*
 	 * If nothing remain, discard the operation.
 	 */
 	if (!(fsi->valid & (FUSE_FATTR_SIZE|FUSE_FATTR_ATIME|FUSE_FATTR_MTIME|



CVS commit: src/lib/libperfuse

2011-07-14 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Thu Jul 14 15:37:32 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c perfuse_priv.h

Log Message:
FUSE struct dirent's off is not the offset in the buffer, it is an opaque
cookie that the filesystem passes us, and that we need to send back on
the next READDIR. Most filesystem just ignore the value and send the
next chunk of buffer, but not all of them. Fixing this allows glusterfs
distributed volume to work.


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.20 -r1.21 src/lib/libperfuse/perfuse_priv.h

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.32 src/lib/libperfuse/ops.c:1.33
--- src/lib/libperfuse/ops.c:1.32	Mon Jul  4 08:07:29 2011
+++ src/lib/libperfuse/ops.c	Thu Jul 14 15:37:32 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.32 2011/07/04 08:07:29 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.33 2011/07/14 15:37:32 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -58,10 +58,11 @@
 struct puffs_newinfo *, const struct puffs_cn *pcn, perfuse_msg_t *);
 static int node_mk_common_final(struct puffs_usermount *, puffs_cookie_t,
 struct puffs_node *, const struct puffs_cn *pcn);
+static uint64_t readdir_last_cookie(struct fuse_dirent *, size_t); 
 static ssize_t fuse_to_dirent(struct puffs_usermount *, puffs_cookie_t,
 struct fuse_dirent *, size_t);
 static int readdir_buffered(puffs_cookie_t, struct dirent *, off_t *, 
-size_t *, const struct puffs_cred *, int *, off_t *, size_t *);
+size_t *);
 static void requeue_request(struct puffs_usermount *, 
 puffs_cookie_t opc, enum perfuse_qtype);
 static int dequeue_requests(struct perfuse_state *, 
@@ -521,6 +522,28 @@
 	return error;
 }
 
+static uint64_t
+readdir_last_cookie(fd, fd_len)
+	struct fuse_dirent *fd;
+	size_t fd_len;
+{
+	size_t len;
+	size_t seen = 0;
+	char *ndp;
+
+	do {
+		len = FUSE_DIRENT_ALIGN(sizeof(*fd) + fd->namelen);
+		seen += len;
+
+		if (seen >= fd_len)
+			break;
+
+		ndp = (char *)(void *)fd + (size_t)len;
+		fd = (struct fuse_dirent *)(void *)ndp;
+	} while (1 /* CONSTCOND */);
+
+	return fd->off;
+}
 
 static ssize_t
 fuse_to_dirent(pu, opc, fd, fd_len)
@@ -577,8 +600,6 @@
 			dents = (struct dirent *)(void *)ndp;
 		}
 		
-
-
 		/*
 		 * Filesystem was mounted without -o use_ino
 		 * Perform a lookup to find it.
@@ -612,10 +633,10 @@
 
 		/*
 		 * Move to the next record.
-		 * fd->off seems unreliable, for instance, flusterfs 
-		 * does not clear the unused bits, and we get 
-		 * 0xb9b95040 instead of just 0x40. Use 
-		 * record alignement instead.
+		 * fd->off is not the offset, it is an opaque cookie
+		 * given by the filesystem to keep state across multiple
+		 * readdir() operation.
+		 * Use record alignement instead.
 		 */
 		len = FUSE_DIRENT_ALIGN(sizeof(*fd) + fd->namelen);
 #ifdef PERFUSE_DEBUG
@@ -654,18 +675,12 @@
 	return written;
 }
 
-/* ARGSUSED4 */
 static int 
-readdir_buffered(opc, dent, readoff, 
-		 reslen, pcr, eofflag, cookies, ncookies)
+readdir_buffered(opc, dent, readoff, reslen)
 	puffs_cookie_t opc;
 	struct dirent *dent;
 	off_t *readoff;
 	size_t *reslen;
-	const struct puffs_cred *pcr;
-	int *eofflag;
-	off_t *cookies;
-	size_t *ncookies;
 {
 	struct dirent *fromdent;
 	struct perfuse_node_data *pnd;
@@ -700,7 +715,6 @@
 		free(pnd->pnd_dirent);
 		pnd->pnd_dirent = NULL;
 		pnd->pnd_dirent_len = 0;
-		*eofflag = 1;
 	}
 
 	return 0;
@@ -2177,6 +2191,7 @@
 	return node_mk_common(pu, opc, pni, pcn_src, pm);
 }
 
+/* ARGSUSED4 */
 int 
 perfuse_node_readdir(pu, opc, dent, readoff, 
 		 reslen, pcr, eofflag, cookies, ncookies)
@@ -2199,7 +2214,6 @@
 	struct fuse_dirent *fd;
 	size_t foh_len;
 	int error;
-	uint64_t fd_offset;
 	size_t fd_maxlen;
 	
 	pm = NULL;
@@ -2223,6 +2237,12 @@
 			__func__, (void *)opc);
 #endif
 	/*
+	 * Re-initialize pnd->pnd_fd_cookie on the first readdir for a node
+	 */
+	if (*readoff == 0)
+		pnd->pnd_fd_cookie = 0;
+
+	/*
 	 * Do we already have the data bufered?
 	 */
 	if (pnd->pnd_dirent != NULL)
@@ -2249,9 +2269,8 @@
 
 	pnd->pnd_all_fd = NULL;
 	pnd->pnd_all_fd_len = 0;
-	fd_offset = 0;
 	fd_maxlen = ps->ps_max_readahead - sizeof(*foh);
-	
+
 	do {
 		size_t fd_len;
 		char *afdp;
@@ -2263,7 +2282,7 @@
 		 */
 		fri = GET_INPAYLOAD(ps, pm, fuse_read_in);
 		fri->fh = fh;
-		fri->offset = fd_offset;
+		fri->offset = pnd->pnd_fd_cookie;
 		fri->size = (uint32_t)fd_maxlen;
 		fri->read_flags = 0;
 		fri->lock_owner = 0;
@@ -2284,11 +2303,13 @@
 		/*
 		 * Empty read: we reached the end of the buffer.
 		 */
-		if (foh_len == sizeof(*foh))
+		if (foh_len == sizeof(*foh)) {
+			*eofflag = 1;
 			break;
+		}
 
 		/*
-		 * Corrupted message.
+		 * Check for corrupted message.
 		 */
 		if (foh_len < sizeof(*foh) + sizeof(*fd))

CVS commit: src/lib/libperfuse

2011-06-28 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Tue Jun 28 20:28:49 UTC 2011

Modified Files:
src/lib/libperfuse: Makefile

Log Message:
Don't hardcode the libpuffs path to /usr/src/lib/libpuffs.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libperfuse/Makefile

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/Makefile
diff -u src/lib/libperfuse/Makefile:1.5 src/lib/libperfuse/Makefile:1.6
--- src/lib/libperfuse/Makefile:1.5	Tue Jun 28 16:19:16 2011
+++ src/lib/libperfuse/Makefile	Tue Jun 28 20:28:48 2011
@@ -1,7 +1,7 @@
-# $NetBSD: Makefile,v 1.5 2011/06/28 16:19:16 manu Exp $
+# $NetBSD: Makefile,v 1.6 2011/06/28 20:28:48 riz Exp $
 
 LIB=perfuse
-LIBDPLIBS+= puffs	/usr/src/lib/libpuffs
+LIBDPLIBS+= puffs	${.CURDIR}/../libpuffs
 
 PERFUSE_OPT_DEBUG_FLAGS=   -g -DPERFUSE_DEBUG
 



CVS commit: src/lib/libperfuse

2011-06-28 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue Jun 28 16:19:16 UTC 2011

Modified Files:
src/lib/libperfuse: Makefile fuse.h ops.c perfuse.c perfuse_priv.h
subr.c

Log Message:
Add support for extended attributes


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libperfuse/Makefile
cvs rdiff -u -r1.3 -r1.4 src/lib/libperfuse/fuse.h
cvs rdiff -u -r1.30 -r1.31 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.15 -r1.16 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.18 -r1.19 src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.11 -r1.12 src/lib/libperfuse/subr.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/Makefile
diff -u src/lib/libperfuse/Makefile:1.4 src/lib/libperfuse/Makefile:1.5
--- src/lib/libperfuse/Makefile:1.4	Thu May 26 12:56:30 2011
+++ src/lib/libperfuse/Makefile	Tue Jun 28 16:19:16 2011
@@ -1,11 +1,9 @@
-# $NetBSD: Makefile,v 1.4 2011/05/26 12:56:30 joerg Exp $
+# $NetBSD: Makefile,v 1.5 2011/06/28 16:19:16 manu Exp $
 
 LIB=perfuse
-LIBDPLIBS+= puffs	${.CURDIR}/../libpuffs
+LIBDPLIBS+= puffs	/usr/src/lib/libpuffs
 
-.ifdef DEBUG
 PERFUSE_OPT_DEBUG_FLAGS=   -g -DPERFUSE_DEBUG
-.endif
 
 CWARNFLAGS.clang+=	-Wno-format-security
 

Index: src/lib/libperfuse/fuse.h
diff -u src/lib/libperfuse/fuse.h:1.3 src/lib/libperfuse/fuse.h:1.4
--- src/lib/libperfuse/fuse.h:1.3	Wed May 11 14:52:48 2011
+++ src/lib/libperfuse/fuse.h	Tue Jun 28 16:19:16 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: fuse.h,v 1.3 2011/05/11 14:52:48 jakllsch Exp $ */
+/*  $NetBSD: fuse.h,v 1.4 2011/06/28 16:19:16 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -39,6 +39,11 @@
 #define FUSE_BUFSIZE MAX(FUSE_PREF_BUFSIZE /* CONSTCOND */, FUSE_MIN_BUFSIZE)
 #endif /* FUSE_BUFSIZE */
 
+/* From  */
+#define LINUX_XATTR_NAME_MAX   255 
+#define LINUX_XATTR_SIZE_MAX 65536
+#define LINUX_XATTR_LIST_MAX 65536 
+
 struct fuse_attr {
 	uint64_t	ino;
 	uint64_t	size;

Index: src/lib/libperfuse/ops.c
diff -u src/lib/libperfuse/ops.c:1.30 src/lib/libperfuse/ops.c:1.31
--- src/lib/libperfuse/ops.c:1.30	Wed Jun  1 15:54:10 2011
+++ src/lib/libperfuse/ops.c	Tue Jun 28 16:19:16 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.30 2011/06/01 15:54:10 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.31 2011/06/28 16:19:16 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -36,6 +36,7 @@
 #include 
 #include 
 #include 
+#include 
 #include 
 
 #include "perfuse_priv.h"
@@ -2924,3 +2925,213 @@
 	return;
 }
 
+/* ARGSUSED4 */
+int
+perfuse_node_getextattr(pu, opc, attrns, attrname, attrsize, attr, resid, pcr)
+	struct puffs_usermount *pu;
+	puffs_cookie_t opc;
+	int attrns;
+	const char *attrname;
+	size_t *attrsize;
+	uint8_t *attr;
+	size_t *resid;
+	const struct puffs_cred *pcr;
+{
+	struct perfuse_state *ps;
+	char fuse_attrname[LINUX_XATTR_NAME_MAX + 1];
+	perfuse_msg_t *pm;
+	struct fuse_getxattr_in *fgi;
+	struct fuse_getxattr_out *fgo;
+	struct fuse_out_header *foh;
+	size_t attrnamelen;
+	size_t len;
+	char *np;
+	int error;
+
+	ps = puffs_getspecific(pu);
+	attrname = perfuse_native_ns(attrns, attrname, fuse_attrname);
+	attrnamelen = strlen(attrname) + 1;
+	len = sizeof(*fgi) + attrnamelen;
+
+	pm = ps->ps_new_msg(pu, opc, FUSE_GETXATTR, len, pcr);
+	fgi = GET_INPAYLOAD(ps, pm, fuse_getxattr_in);
+	fgi->size = (resid != NULL) ? *resid : 0;
+	np = (char *)(void *)(fgi + 1);
+	(void)strlcpy(np, attrname, attrnamelen);
+	
+	if ((error = xchg_msg(pu, opc, pm, UNSPEC_REPLY_LEN, wait_reply)) != 0)
+		goto out;
+
+	/*
+	 * We just get fuse_getattr_out with list size if we requested
+	 * a null size.
+	 */
+	if (resid == NULL) {
+		fgo = GET_OUTPAYLOAD(ps, pm, fuse_getxattr_out);
+
+		if (attrsize != NULL)
+			*attrsize = fgo->size;
+
+		goto out;
+	}
+
+	/*
+	 * And with a non null requested size, we get the list just 
+	 * after the header
+	 */
+	foh = GET_OUTHDR(ps, pm);
+	np = (char *)(void *)(foh + 1);
+
+	if (resid != NULL) {
+		len = MAX(foh->len - sizeof(*foh), *resid);
+		(void)memcpy(attr, np, len);
+		*resid -= len;
+	}
+	
+out: 
+	ps->ps_destroy_msg(pm);
+
+	return error;
+}
+
+int
+perfuse_node_setextattr(pu, opc, attrns, attrname, attr, resid, pcr)
+	struct puffs_usermount *pu;
+	puffs_cookie_t opc;
+	int attrns;
+	const char *attrname;
+	uint8_t *attr;
+	size_t *resid;
+	const struct puffs_cred *pcr;
+{
+	struct perfuse_state *ps;
+	char fuse_attrname[LINUX_XATTR_NAME_MAX + 1];
+	perfuse_msg_t *pm;
+	struct fuse_setxattr_in *fsi;
+	size_t attrnamelen;
+	size_t len;
+	char *np;
+	int error;
+	
+	ps = puffs_getspecific(pu);
+	attrname = perfuse_native_ns(attrns, attrname, fuse_attrname);
+	attrnamelen = strlen(attrname) + 1;
+	len = sizeof(*fsi) + attrnamelen + *resid;
+
+	pm = ps->ps_new_msg(pu, opc, FUSE_SETXATTR, len, pcr);
+	fsi = GET_INPAYLOAD(ps, pm, fuse_setxattr_in);
+	fsi->size = *resid;
+	fsi->flags = 

CVS commit: src/lib/libperfuse

2011-06-01 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Wed Jun  1 15:54:10 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Fix race conditions between write and getattr/setattr, which lead to
inconsitencies between kernel and filesystem idea of file size during
writes with IO_APPEND.

At mine, this resulted in a configure script producing config.status
with ": clr\n" lines stripped (not 100% reproductible, but always this
specific string. That is of little interest except for my own future
reference).

When a write is in progress, getattr/setattr get/set the maximum size
among kernel idea (grown by write) and filesystem idea (not yet grown).


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/lib/libperfuse/ops.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.29 src/lib/libperfuse/ops.c:1.30
--- src/lib/libperfuse/ops.c:1.29	Wed Jun  1 07:57:24 2011
+++ src/lib/libperfuse/ops.c	Wed Jun  1 15:54:10 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.29 2011/06/01 07:57:24 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.30 2011/06/01 15:54:10 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -1439,12 +1439,14 @@
 	struct perfuse_state *ps;
 	struct fuse_getattr_in *fgi;
 	struct fuse_attr_out *fao;
+	u_quad_t va_size;
 	int error;
 	
 	if (PERFUSE_NODE_DATA(opc)->pnd_flags & PND_REMOVED)
 		return ENOENT;
 
 	ps = puffs_getspecific(pu);
+	va_size = vap->va_size;
 
 	/*
 	 * FUSE_GETATTR_FH must be set in fgi->flags 
@@ -1476,6 +1478,13 @@
 	 */
 	fuse_attr_to_vap(ps, vap, &fao->attr);
 
+	/*
+	 * If a write is in progress, do not trust filesystem opinion 
+	 * of file size, use the one from kernel.
+	 */
+	if ((PERFUSE_NODE_DATA(opc)->pnd_flags & PND_INWRITE) &&
+	(va_size != (u_quad_t)PUFFS_VNOVAL))
+		vap->va_size = MAX(va_size, vap->va_size);;
 out:
 	ps->ps_destroy_msg(pm);
 
@@ -1496,6 +1505,7 @@
 	struct fuse_setattr_in *fsi;
 	struct fuse_attr_out *fao;
 	struct vattr *old_va;
+	u_quad_t va_size;
 	int error;
 
 	ps = puffs_getspecific(pu);
@@ -1552,13 +1562,14 @@
 		return EACCES;
 	
 	/*
-	 * It seems troublesome to resize a file while
-	 * a write is just beeing done. Wait for
-	 * it to finish.
-	 */
-	if (vap->va_size != (u_quad_t)PUFFS_VNOVAL)
-		while (pnd->pnd_flags & PND_INWRITE)
-			requeue_request(pu, opc, PCQ_AFTERWRITE);
+	 * If a write is in progress, set the highest
+	 * value in the filesystem, otherwise we break 
+	 * IO_APPEND.
+	 */
+	va_size = vap->va_size;
+	if ((pnd->pnd_flags & PND_INWRITE) &&
+	(va_size != (u_quad_t)PUFFS_VNOVAL))
+		va_size = MAX(va_size, old_va->va_size);
 
 	pm = ps->ps_new_msg(pu, opc, FUSE_SETATTR, sizeof(*fsi), pcr);
 	fsi = GET_INPAYLOAD(ps, pm, fuse_setattr_in);
@@ -1573,8 +1584,8 @@
 		fsi->valid |= FUSE_FATTR_FH;
 	}
 
-	if (vap->va_size != (u_quad_t)PUFFS_VNOVAL) {
-		fsi->size = vap->va_size;
+	if (va_size != (u_quad_t)PUFFS_VNOVAL) {
+		fsi->size = va_size;
 		fsi->valid |= FUSE_FATTR_SIZE;
 	}
 



CVS commit: src/lib/libperfuse

2011-06-01 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Wed Jun  1 07:57:24 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Remove outdated comment about a fixed bug


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/lib/libperfuse/ops.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.28 src/lib/libperfuse/ops.c:1.29
--- src/lib/libperfuse/ops.c:1.28	Mon May 30 14:50:08 2011
+++ src/lib/libperfuse/ops.c	Wed Jun  1 07:57:24 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.28 2011/05/30 14:50:08 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.29 2011/06/01 07:57:24 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -1370,12 +1370,6 @@
 	return 0;
 }
 
-/*
- * XXX
- * This fails as unprivilegied, it should not: touch testa/testx/a
- * d-wx-wx-wx  2 root  wheel  512 Oct  5 04:32 testa/testx
- * -rwxrwxrwx  1 root  wheel  0   Oct  5 04:39 testa/testx/a
- */
 int
 perfuse_node_access(pu, opc, mode, pcr)
 	struct puffs_usermount *pu;



CVS commit: src/lib/libperfuse

2011-05-18 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Wed May 18 15:28:12 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
- Proper permission checks when doing directory traversal. e.g.: run
rm dir/file while dir was never looked up since the mount. In that
situation, we get lookup with pcn_nameiop NAMEI_DELETE for dir before
we get it for file. But for dir we are just looking for PUFFS_VEXEC.
This is solved by honouring NAMEI_ISLASTCN, which is set for the last
element only

- do not send O_EXCL to FUSE as documentation forbids it.

- fix warning


To generate a diff of this commit:
cvs rdiff -u -r1.26 -r1.27 src/lib/libperfuse/ops.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.26 src/lib/libperfuse/ops.c:1.27
--- src/lib/libperfuse/ops.c:1.26	Wed May 11 14:52:48 2011
+++ src/lib/libperfuse/ops.c	Wed May 18 15:28:12 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.26 2011/05/11 14:52:48 jakllsch Exp $ */
+/*  $NetBSD: ops.c,v 1.27 2011/05/18 15:28:12 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -262,7 +262,7 @@
 	vap->va_nlink = fa->nlink;
 	vap->va_uid = fa->uid;
 	vap->va_gid = fa->gid;
-	vap->va_fsid = ps->ps_fsid;
+	vap->va_fsid = (long)ps->ps_fsid;
 	vap->va_fileid = fa->ino;
 	vap->va_size = fa->size;
 	vap->va_blocksize = fa->blksize;
@@ -996,7 +996,10 @@
 	case NAMEI_DELETE: /* FALLTHROUGH */
 	case NAMEI_RENAME: /* FALLTHROUGH */
 	case NAMEI_CREATE:
-		mode = PUFFS_VEXEC|PUFFS_VWRITE;
+		if (pcn->pcn_flags & NAMEI_ISLASTCN)
+			mode = PUFFS_VEXEC|PUFFS_VWRITE;
+		else
+			mode = PUFFS_VEXEC;
 		break;
 	case NAMEI_LOOKUP: /* FALLTHROUGH */
 	default:
@@ -1271,7 +1274,7 @@
 
 	/*
 	 * libfuse docs says
-	 * - O_CREAT should never be set.
+	 * - O_CREAT and O_EXCL should never be set.
 	 * - O_TRUNC may be used if mount option atomic_o_trunc is used XXX
 	 *
 	 * O_APPEND makes no sense since FUSE always sends
@@ -1279,7 +1282,7 @@
 	 * filesystem uses pwrite(), O_APPEND would cause
 	 * the offset to be ignored and cause file corruption.
 	 */
-	mode &= ~(O_CREAT|O_APPEND);
+	mode &= ~(O_CREAT|O_EXCL|O_APPEND);
 
 	/*
 	 * Do not open twice, and do not reopen for reading



CVS commit: src/lib/libperfuse

2011-05-18 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Wed May 18 15:25:19 UTC 2011

Modified Files:
src/lib/libperfuse: perfuse.c

Log Message:
Set buffer size as big in nomal mode as we do in debug mode, when
perfused stays in foreground. The difference is a mistake and was not
intended.

There is still a bug ready to bite here, since SOCK_STREAM is not reliable.
We just hope that buffers are big enough to hold all packets, but if they
are overflown, we loose a packet and a file operation gets stuck.

We really nee SOCk_SEQPACKET here, but unfortunately it is very broken at
that time.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libperfuse/perfuse.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/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.13 src/lib/libperfuse/perfuse.c:1.14
--- src/lib/libperfuse/perfuse.c:1.13	Thu May 12 10:32:41 2011
+++ src/lib/libperfuse/perfuse.c	Wed May 18 15:25:19 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.13 2011/05/12 10:32:41 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.14 2011/05/18 15:25:19 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -197,22 +197,22 @@
 	 * Set a buffer lentgh large enough so that any FUSE packet
 	 * will fit.
 	 */
-	opt = FUSE_BUFSIZE;
+	opt = 4 * FUSE_BUFSIZE;
 	optlen = sizeof(opt);
 	if (setsockopt(sv[0], SOL_SOCKET, SO_SNDBUF, &opt, optlen) != 0)
 		DWARN("%s: setsockopt SO_SNDBUF to %d failed", __func__, opt);
 
-	opt = FUSE_BUFSIZE;
+	opt = 4 * FUSE_BUFSIZE;
 	optlen = sizeof(opt);
 	if (setsockopt(sv[0], SOL_SOCKET, SO_RCVBUF, &opt, optlen) != 0)
 		DWARN("%s: setsockopt SO_RCVBUF to %d failed", __func__, opt);
 
-	opt = FUSE_BUFSIZE;
+	opt = 4 * FUSE_BUFSIZE;
 	optlen = sizeof(opt);
 	if (setsockopt(sv[1], SOL_SOCKET, SO_SNDBUF, &opt, optlen) != 0)
 		DWARN("%s: setsockopt SO_SNDBUF to %d failed", __func__, opt);
 
-	opt = FUSE_BUFSIZE;
+	opt = 4 * FUSE_BUFSIZE;
 	optlen = sizeof(opt);
 	if (setsockopt(sv[1], SOL_SOCKET, SO_RCVBUF, &opt, optlen) != 0)
 		DWARN("%s: setsockopt SO_RCVBUF to %d failed", __func__, opt);



CVS commit: src/lib/libperfuse

2011-05-18 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Wed May 18 15:22:54 UTC 2011

Modified Files:
src/lib/libperfuse: perfuse_if.h

Log Message:
typos


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libperfuse/perfuse_if.h

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/perfuse_if.h
diff -u src/lib/libperfuse/perfuse_if.h:1.11 src/lib/libperfuse/perfuse_if.h:1.12
--- src/lib/libperfuse/perfuse_if.h:1.11	Wed May 11 14:52:48 2011
+++ src/lib/libperfuse/perfuse_if.h	Wed May 18 15:22:54 2011
@@ -1,7 +1,7 @@
-/*  $NetBSD: perfuse_if.h,v 1.11 2011/05/11 14:52:48 jakllsch Exp $ */
+/*  $NetBSD: perfuse_if.h,v 1.12 2011/05/18 15:22:54 manu Exp $ */
 
 /*-
- *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
+ *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
  * 
  *  Redistribution and use in source and binary forms, with or without
  *  modification, are permitted provided that the following conditions
@@ -25,8 +25,8 @@
  *  POSSIBILITY OF SUCH DAMAGE.
  */ 
 
-#ifndef _REFUSE_PERFUSE_H
-#define _REFUSE_PERFUSE_H
+#ifndef _PERFUSE_IF_H
+#define _PERFUSE_IF_H
 
 #ifndef _PATH_PERFUSED
 #define _PATH_PERFUSED "/usr/sbin/perfused"
@@ -171,7 +171,7 @@
 };
 
 /*
- * Duplicated fro fuse.h to avoid making it public
+ * Duplicated from fuse.h to avoid making it public
  */
 #ifndef FUSE_BUFSIZE
 #define FUSE_MIN_BUFSIZE 0x21000
@@ -210,4 +210,4 @@
 int perfuse_mainloop(struct puffs_usermount *);
 int perfuse_unmount(struct puffs_usermount *);
 
-#endif /* _REFUSE_PERFUSE_H */
+#endif /* _PERFUSE_IF_H */



CVS commit: src/lib/libperfuse

2011-05-12 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Thu May 12 10:32:41 UTC 2011

Modified Files:
src/lib/libperfuse: perfuse.c

Log Message:
Mont FUSE filesystem with proprer source and fstype so that df and mount
display something that makes sense


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libperfuse/perfuse.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/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.12 src/lib/libperfuse/perfuse.c:1.13
--- src/lib/libperfuse/perfuse.c:1.12	Mon Apr 25 04:54:53 2011
+++ src/lib/libperfuse/perfuse.c	Thu May 12 10:32:41 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.12 2011/04/25 04:54:53 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.13 2011/05/12 10:32:41 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -391,7 +391,8 @@
 	struct perfuse_state *ps;
 	struct puffs_usermount *pu;
 	struct puffs_ops *pops;
-	char name[] = "perfuse";
+	const char *source = _PATH_PUFFS;
+	char *fstype;
 	unsigned int puffs_flags;
 	struct puffs_node *pn_root;
 	struct puffs_pathobj *po_root;
@@ -399,11 +400,33 @@
 	ps = init_state();
 	ps->ps_owner_uid = pmi->pmi_uid;
 
-	if (pmi->pmi_source)
-		ps->ps_source = strdup(pmi->pmi_source);
-	if (pmi->pmi_filesystemtype)
+	if (pmi->pmi_source) {
+		if ((ps->ps_source = strdup(pmi->pmi_source)) == NULL)
+			DERR(EX_OSERR, "strdup failed");
+
+		source = ps->ps_source;
+	}
+
+	if (pmi->pmi_filesystemtype) {
+		size_t len;
+
 		ps->ps_filesystemtype = strdup(pmi->pmi_filesystemtype);
-	ps->ps_target = strdup(pmi->pmi_target);
+		if (ps->ps_filesystemtype == NULL)
+			DERR(EX_OSERR, "strdup failed");
+
+		len = sizeof("perfuse|") + strlen(ps->ps_filesystemtype) + 1;
+		if ((fstype = malloc(len)) == NULL)
+			DERR(EX_OSERR, "malloc failed");
+
+		(void)sprintf(fstype, "perfuse|%s", ps->ps_filesystemtype);
+	} else {
+		if ((fstype = strdup("perfuse")) == NULL)
+			DERR(EX_OSERR, "strdup failed");
+	}
+
+	if ((ps->ps_target = strdup(pmi->pmi_target)) == NULL)
+		DERR(EX_OSERR, "strdup failed");
+
 	ps->ps_mountflags = pmi->pmi_mountflags;
 
 	/*
@@ -450,7 +473,7 @@
 	if (perfuse_diagflags & PDF_PUFFS)
 		puffs_flags |= PUFFS_FLAG_OPDUMP;
 
-	if ((pu = puffs_init(pops, _PATH_PUFFS, name, ps, puffs_flags)) == NULL)
+	if ((pu = puffs_init(pops, source, fstype, ps, puffs_flags)) == NULL)
 		DERR(EX_OSERR, "puffs_init failed");
 
 	ps->ps_pu = pu;



CVS commit: src/lib/libperfuse

2011-05-11 Thread Jonathan A. Kollasch
Module Name:src
Committed By:   jakllsch
Date:   Wed May 11 14:52:48 UTC 2011

Modified Files:
src/lib/libperfuse: fuse.h ops.c perfuse_if.h

Log Message:
Use sysconf(_SC_PAGESIZE) instead of PAGE_SIZE.


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libperfuse/fuse.h
cvs rdiff -u -r1.25 -r1.26 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.10 -r1.11 src/lib/libperfuse/perfuse_if.h

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/fuse.h
diff -u src/lib/libperfuse/fuse.h:1.2 src/lib/libperfuse/fuse.h:1.3
--- src/lib/libperfuse/fuse.h:1.2	Wed Sep 15 01:51:43 2010
+++ src/lib/libperfuse/fuse.h	Wed May 11 14:52:48 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: fuse.h,v 1.2 2010/09/15 01:51:43 manu Exp $ */
+/*  $NetBSD: fuse.h,v 1.3 2011/05/11 14:52:48 jakllsch Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -35,7 +35,7 @@
 
 #ifndef FUSE_BUFSIZE
 #define FUSE_MIN_BUFSIZE 0x21000
-#define FUSE_PREF_BUFSIZE (PAGE_SIZE + 0x1000)
+#define FUSE_PREF_BUFSIZE (sysconf(_SC_PAGESIZE) + 0x1000)
 #define FUSE_BUFSIZE MAX(FUSE_PREF_BUFSIZE /* CONSTCOND */, FUSE_MIN_BUFSIZE)
 #endif /* FUSE_BUFSIZE */
 

Index: src/lib/libperfuse/ops.c
diff -u src/lib/libperfuse/ops.c:1.25 src/lib/libperfuse/ops.c:1.26
--- src/lib/libperfuse/ops.c:1.25	Tue May  3 13:19:50 2011
+++ src/lib/libperfuse/ops.c	Wed May 11 14:52:48 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.25 2011/05/03 13:19:50 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.26 2011/05/11 14:52:48 jakllsch Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -808,7 +808,7 @@
 	fii = GET_INPAYLOAD(ps, pm, fuse_init_in);
 	fii->major = FUSE_KERNEL_VERSION;
 	fii->minor = FUSE_KERNEL_MINOR_VERSION;
-	fii->max_readahead = 32 * PAGE_SIZE; 
+	fii->max_readahead = 32 * sysconf(_SC_PAGESIZE); 
 	fii->flags = (FUSE_ASYNC_READ|FUSE_POSIX_LOCKS|FUSE_ATOMIC_O_TRUNC);
 
 	if ((error = xchg_msg(pu, 0, pm, sizeof(*fio), wait_reply)) != 0)
@@ -2801,15 +2801,15 @@
 		size_t max_write;
 		/*
 		 * There is a writepage flag when data
-		 * is PAGE_SIZE-aligned. Use it for
+		 * is aligned to page size. Use it for
 		 * everything but the data after the last
 		 * page boundary.
 		 */
 		max_write = ps->ps_max_write - sizeof(*fwi); 
 
 		data_len = MIN(*resid, max_write);
-		if (data_len > PAGE_SIZE)
-			data_len = data_len & ~(PAGE_SIZE - 1);
+		if (data_len > (size_t)sysconf(_SC_PAGESIZE))
+			data_len = data_len & ~(sysconf(_SC_PAGESIZE) - 1);
 
 		payload_len = data_len + sizeof(*fwi);
 
@@ -2823,7 +2823,7 @@
 		fwi->fh = perfuse_get_fh(opc, FWRITE);
 		fwi->offset = offset;
 		fwi->size = (uint32_t)data_len;
-		fwi->write_flags = (fwi->size % PAGE_SIZE) ? 0 : 1;
+		fwi->write_flags = (fwi->size % sysconf(_SC_PAGESIZE)) ? 0 : 1;
 		fwi->lock_owner = pnd->pnd_lock_owner;
 		fwi->flags = 0;
 		fwi->flags |= (fwi->lock_owner != 0) ? FUSE_WRITE_LOCKOWNER : 0;

Index: src/lib/libperfuse/perfuse_if.h
diff -u src/lib/libperfuse/perfuse_if.h:1.10 src/lib/libperfuse/perfuse_if.h:1.11
--- src/lib/libperfuse/perfuse_if.h:1.10	Mon Oct 11 05:37:58 2010
+++ src/lib/libperfuse/perfuse_if.h	Wed May 11 14:52:48 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_if.h,v 1.10 2010/10/11 05:37:58 manu Exp $ */
+/*  $NetBSD: perfuse_if.h,v 1.11 2011/05/11 14:52:48 jakllsch Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -175,7 +175,7 @@
  */
 #ifndef FUSE_BUFSIZE
 #define FUSE_MIN_BUFSIZE 0x21000
-#define FUSE_PREF_BUFSIZE (PAGE_SIZE + 0x1000)
+#define FUSE_PREF_BUFSIZE (sysconf(_SC_PAGESIZE) + 0x1000)
 #define FUSE_BUFSIZE MAX(FUSE_PREF_BUFSIZE /* CONSTCOND */, FUSE_MIN_BUFSIZE)
 #endif /* FUSE_BUFSIZE */
 



CVS commit: src/lib/libperfuse

2011-05-10 Thread Nicolas Joly
Module Name:src
Committed By:   njoly
Date:   Tue May 10 12:14:37 UTC 2011

Modified Files:
src/lib/libperfuse: libperfuse.3

Log Message:
Small typo in macro (Xd -> Xr).


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libperfuse/libperfuse.3

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/libperfuse.3
diff -u src/lib/libperfuse/libperfuse.3:1.2 src/lib/libperfuse/libperfuse.3:1.3
--- src/lib/libperfuse/libperfuse.3:1.2	Wed Sep  1 13:04:11 2010
+++ src/lib/libperfuse/libperfuse.3	Tue May 10 12:14:37 2011
@@ -1,4 +1,4 @@
-.\" $NetBSD: libperfuse.3,v 1.2 2010/09/01 13:04:11 wiz Exp $
+.\" $NetBSD: libperfuse.3,v 1.3 2011/05/10 12:14:37 njoly Exp $
 .\"
 .\" Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
 .\"
@@ -111,7 +111,7 @@
 .\".Bl -tag -width Er
 .\".El
 .Sh SEE ALSO
-.Xd df 1 ,
+.Xr df 1 ,
 .Xr mount 2 ,
 .Xr open 2 ,
 .Xr mount 8 ,



CVS commit: src/lib/libperfuse

2011-05-03 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue May  3 13:19:50 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Fixes for the advlock method. It can now sustain pkgsrc/devel/locktests
with glusterfs as backend


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/lib/libperfuse/ops.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.24 src/lib/libperfuse/ops.c:1.25
--- src/lib/libperfuse/ops.c:1.24	Mon Apr 25 04:54:53 2011
+++ src/lib/libperfuse/ops.c	Tue May  3 13:19:50 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.24 2011/04/25 04:54:53 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.25 2011/05/03 13:19:50 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -2579,7 +2579,10 @@
 	int fop;
 	perfuse_msg_t *pm;
 	struct fuse_lk_in *fli;
+	struct fuse_out_header *foh;
 	struct fuse_lk_out *flo;
+	uint32_t owner;
+	size_t len;
 	int error;
 	
 	ps = puffs_getspecific(pu);
@@ -2599,6 +2602,8 @@
 	fli->lk.pid = fl->l_pid;
 	fli->lk_flags = (flags & F_FLOCK) ? FUSE_LK_FLOCK : 0;
 
+	owner = fl->l_pid;
+
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & PDF_FH)
 		DPRINTF("%s: opc = %p, ino = %"PRId64", fh = 0x%"PRIx64"\n",
@@ -2606,27 +2611,48 @@
 			PERFUSE_NODE_DATA(opc)->pnd_ino, fli->fh);
 #endif
 
-	if ((error = xchg_msg(pu, opc, pm, sizeof(*flo), wait_reply)) != 0)
+	if ((error = xchg_msg(pu, opc, pm, UNSPEC_REPLY_LEN, wait_reply)) != 0)
 		goto out;
 
-	flo = GET_OUTPAYLOAD(ps, pm, fuse_lk_out);
-	fl->l_start = flo->lk.start;
-	fl->l_len = flo->lk.end - flo->lk.start;
-	fl->l_pid = flo->lk.pid;
-	fl->l_type = flo->lk.type;
-	fl->l_whence = SEEK_SET;	/* libfuse hardcodes it */
+	foh = GET_OUTHDR(ps, pm);
+	len = foh->len - sizeof(*foh);
 
 	/*
 	 * Save or clear the lock
 	 */
 	switch (op) {
-	case F_SETLK:
+	case F_GETLK:
+		if (len != sizeof(*flo))
+			DERRX(EX_SOFTWARE, 
+			  "%s: Unexpected lock reply len %zd",
+			  __func__, len);
+
+		flo = GET_OUTPAYLOAD(ps, pm, fuse_lk_out);
+		fl->l_start = flo->lk.start;
+		fl->l_len = flo->lk.end - flo->lk.start;
+		fl->l_pid = flo->lk.pid;
+		fl->l_type = flo->lk.type;
+		fl->l_whence = SEEK_SET;	/* libfuse hardcodes it */
+
 		PERFUSE_NODE_DATA(opc)->pnd_lock_owner = flo->lk.pid;
 		break;
 	case F_UNLCK:
-		PERFUSE_NODE_DATA(opc)->pnd_lock_owner = 0;
+		owner = 0;
+		/* FALLTHROUGH */
+	case F_SETLK: 
+		/* FALLTHROUGH */
+	case F_SETLKW: 
+		if (error != 0)
+			PERFUSE_NODE_DATA(opc)->pnd_lock_owner = owner;
+
+		if (len != 0)
+			DERRX(EX_SOFTWARE, 
+			  "%s: Unexpected unlock reply len %zd",
+			  __func__, len);
+
 		break;
 	default:
+		DERRX(EX_SOFTWARE, "%s: Unexpected op %d", __func__, op);
 		break;
 	}
 	



CVS commit: src/lib/libperfuse

2011-05-03 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue May  3 13:14:10 UTC 2011

Modified Files:
src/lib/libperfuse: Makefile

Log Message:
Fix build (libperfuse is still not built by default, but time is coming)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libperfuse/Makefile

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/Makefile
diff -u src/lib/libperfuse/Makefile:1.1 src/lib/libperfuse/Makefile:1.2
--- src/lib/libperfuse/Makefile:1.1	Wed Aug 25 07:16:00 2010
+++ src/lib/libperfuse/Makefile	Tue May  3 13:14:09 2011
@@ -1,10 +1,13 @@
 LIB=perfuse
-LIBDPLIBS+= puffs	/usr/src/lib/libpuffs
+LIBDPLIBS+= puffs	${.CURDIR}/../libpuffs
 
 
 PERFUSE_OPT_DEBUG_FLAGS=   -g -DPERFUSE_DEBUG
 
 CFLAGS+=${PERFUSE_OPT_DEBUG_FLAGS}
+CPPFLAGS+=	-I${.CURDIR} 
+CPPFLAGS+=	-I${NETBSDSRCDIR}/lib/libpuffs 
+CPPFLAGS+=	-I${NETBSDSRCDIR}/sys -I${ARCHDIR} 
 SRCS=   perfuse.c ops.c subr.c debug.c
 MAN=		libperfuse.3
 WARNS=  4



CVS commit: src/lib/libperfuse

2011-04-24 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon Apr 25 04:54:53 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c perfuse.c perfuse_priv.h subr.c

Log Message:
- Implement proper unprivilegied user permission verifications
Verification is now done in the lookup method, as it is the way to
go. Of course there are corner cases, such as the sticky bit which
need special handling in the remove method.

- Set full fsidx in vftstat method

- Do not pass O_APPEND to the filesystem. FUSE always sends the
write offset, so setting O_APPEND is useless. If the filesystem
uses it in an open(2) system call, it will even cause file
corruptions, since offsets given to pwrite(2) will be ignored.
This fix allows glusterfs to host a NetBSD ./build.sh -o build

- Do not use the FUSE access method, use getattr and check for
permission on our own. The problem is that a FUSE filesystem will
typically use the Linux-specific setfsuid() to perform access
control. If that is missing, any chack is likely to occur on
behalf of the user running the filesystem (typically root), causing
access method to return wrong information.

- When possible, avoid performing a getattr method call and use
cached value in puffs_node instead. We still retreive the latest
value by calling getattr when performing append write operation,
to minimize the chances that another writer appended since the
last time we did.

- Update puffs_node cached file size in write method

- Remove unused argument to perfuse_destroy_pn()


To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.11 -r1.12 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.16 -r1.17 src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.10 -r1.11 src/lib/libperfuse/subr.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.23 src/lib/libperfuse/ops.c:1.24
--- src/lib/libperfuse/ops.c:1.23	Mon Oct 11 05:37:58 2010
+++ src/lib/libperfuse/ops.c	Mon Apr 25 04:54:53 2011
@@ -1,7 +1,7 @@
-/*  $NetBSD: ops.c,v 1.23 2010/10/11 05:37:58 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.24 2011/04/25 04:54:53 manu Exp $ */
 
 /*-
- *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
+ *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
  * 
  *  Redistribution and use in source and binary forms, with or without
  *  modification, are permitted provided that the following conditions
@@ -34,7 +34,7 @@
 #include 
 #include 
 #include 
-#include 
+#include 
 #include 
 #include 
 
@@ -45,7 +45,8 @@
 
 static int xchg_msg(struct puffs_usermount *, puffs_cookie_t, 
 perfuse_msg_t *, size_t, enum perfuse_xchg_pb_reply); 
-static int no_access(puffs_cookie_t, const struct puffs_cred *, mode_t);
+static int mode_access(puffs_cookie_t, const struct puffs_cred *, mode_t);
+static int sticky_access(struct puffs_node *, const struct puffs_cred *);
 static void fuse_attr_to_vap(struct perfuse_state *,
 struct vattr *, struct fuse_attr *);
 static int node_lookup_dir_nodot(struct puffs_usermount *,
@@ -54,6 +55,8 @@
 const char*, struct puffs_node **);
 static int node_mk_common(struct puffs_usermount *, puffs_cookie_t,
 struct puffs_newinfo *, const struct puffs_cn *pcn, perfuse_msg_t *);
+static int node_mk_common_final(struct puffs_usermount *, puffs_cookie_t,
+struct puffs_node *, const struct puffs_cn *pcn);
 static ssize_t fuse_to_dirent(struct puffs_usermount *, puffs_cookie_t,
 struct fuse_dirent *, size_t);
 static int readdir_buffered(puffs_cookie_t, struct dirent *, off_t *, 
@@ -201,7 +204,7 @@
 }
 
 static int
-no_access(opc, pcr, mode)
+mode_access(opc, pcr, mode)
 	puffs_cookie_t opc;
 	const struct puffs_cred *pcr;
 	mode_t mode;
@@ -217,14 +220,6 @@
 	if (pcr == NULL)
 		return 0;
 
-	/*
-	 * pcr is NULL for self open through fsync or readdir.
-	 * In both case, access control is useless, as it was
-	 * done before, at open time.
-	 */
-	if (pcr == NULL)
-		return 0;
-
 	pn = (struct puffs_node *)opc;
 	va = puffs_pn_getvap(pn);
 	return puffs_access(va->va_type, va->va_mode, 
@@ -232,6 +227,30 @@
 			mode, pcr);
 }
 
+static int 
+sticky_access(targ, pcr)
+	struct puffs_node *targ;
+	const struct puffs_cred *pcr;
+{
+	uid_t uid;
+	struct puffs_node *tdir;
+	int sticky, owner, error;
+
+	tdir = PERFUSE_NODE_DATA(targ)->pnd_parent;
+
+	if ((error = puffs_cred_getuid(pcr, &uid)) != 0)
+		return error;
+
+	sticky = puffs_pn_getvap(tdir)->va_mode & S_ISTXT;
+	owner = puffs_pn_getvap(targ)->va_uid == uid;
+
+	if (sticky && !owner)
+		error = EACCES;
+
+	return error;	
+}
+
+
 static void
 fuse_attr_to_vap(ps, vap, fa)
 	struct perfuse_state *ps;
@@ -239,7 +258,7 @@
 	struct fuse_attr *fa;
 {
 	vap->va_type = IFTOVT(fa->mode);
-	vap->va_mode = fa->mode;
+	vap->va_mode = fa->mode & ALLPERMS;
 	vap->va_nlink = fa->nlink;
 	vap->va_uid = fa->uid;
 	vap->va_gid = fa->g

CVS commit: src/lib/libperfuse

2010-10-10 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon Oct 11 01:52:05 UTC 2010

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
FUSE filesystems' readlink returns a resolved link with a NUL trailing
character, and PUFFS do not want it. This fixes this bug, that returned
stat the informations for x instead of reporting ENOENT:
mkdir x && ln x z && stat -x z/whatever/you/want


To generate a diff of this commit:
cvs rdiff -u -r1.21 -r1.22 src/lib/libperfuse/ops.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.21 src/lib/libperfuse/ops.c:1.22
--- src/lib/libperfuse/ops.c:1.21	Mon Oct 11 01:08:26 2010
+++ src/lib/libperfuse/ops.c	Mon Oct 11 01:52:05 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.21 2010/10/11 01:08:26 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.22 2010/10/11 01:52:05 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -2410,12 +2410,18 @@
 		goto out;
 
 	foh = GET_OUTHDR(ps, pm);
-	len = foh->len - sizeof(*foh) + 1;
+	len = foh->len - sizeof(*foh);
 	if (len > *linklen)
 		DERRX(EX_PROTOCOL, "path len = %zd too long", len);
+	if (len == 0)
+		DERRX(EX_PROTOCOL, "path len = %zd too short", len);
 		
-	*linklen = len;
-	(void)strlcpy(linkname, _GET_OUTPAYLOAD(ps, pm, char *), len);
+	/*
+	 * FUSE filesystems return a NUL terminated string, we 
+	 * do not want to trailing \0
+	 */
+	*linklen = len - 1;
+	(void)memcpy(linkname, _GET_OUTPAYLOAD(ps, pm, char *), len);
 out:
 	ps->ps_destroy_msg(pm);
 



CVS commit: src/lib/libperfuse

2010-10-10 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon Oct 11 01:08:27 UTC 2010

Modified Files:
src/lib/libperfuse: ops.c perfuse_priv.h subr.c

Log Message:
- fix access control: pcn->pcn_cred is not user credentials
- Keep track of file generation
- remove size tracking in pnd_size, we have it in pn_va.va_size


To generate a diff of this commit:
cvs rdiff -u -r1.20 -r1.21 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.14 -r1.15 src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.8 -r1.9 src/lib/libperfuse/subr.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.20 src/lib/libperfuse/ops.c:1.21
--- src/lib/libperfuse/ops.c:1.20	Mon Oct  4 03:56:24 2010
+++ src/lib/libperfuse/ops.c	Mon Oct 11 01:08:26 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.20 2010/10/04 03:56:24 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.21 2010/10/11 01:08:26 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -217,9 +217,16 @@
 	if (pcr == NULL)
 		return 0;
 
+	/*
+	 * pcr is NULL for self open through fsync or readdir.
+	 * In both case, access control is useless, as it was
+	 * done before, at open time.
+	 */
+	if (pcr == NULL)
+		return 0;
+
 	pn = (struct puffs_node *)opc;
 	va = puffs_pn_getvap(pn);
-
 	return puffs_access(va->va_type, va->va_mode, 
 			va->va_uid, va->va_gid,
 			mode, pcr);
@@ -252,13 +259,13 @@
 	vap->va_flags = 0;
 	vap->va_rdev = fa->rdev;
 	vap->va_bytes = fa->size;
-	vap->va_filerev = 0;
+	vap->va_filerev = (u_quad_t)PUFFS_VNOVAL;
 	vap->va_vaflags = 0;
 
 	if (vap->va_blocksize == 0)
 		vap->va_blocksize = DEV_BSIZE;
 
-	if (vap->va_size == (size_t)-1) /* XXX */
+	if (vap->va_size == (size_t)PUFFS_VNOVAL) /* XXX */
 		vap->va_size = 0;
 
 	return;
@@ -369,6 +376,7 @@
 	PERFUSE_NODE_DATA(pn)->pnd_ino = feo->nodeid;
 
 	fuse_attr_to_vap(ps, &pn->pn_va, &feo->attr);
+	pn->pn_va.va_gen = (u_long)(feo->generation);
 
 	if (pnp != NULL)
 		*pnp = pn;
@@ -419,6 +427,8 @@
 	PERFUSE_NODE_DATA(pn)->pnd_ino = feo->nodeid;
 
 	fuse_attr_to_vap(ps, &pn->pn_va, &feo->attr);
+	pn->pn_va.va_gen = (u_long)(feo->generation);
+
 	puffs_newinfo_setcookie(pni, pn);
 
 #ifdef PERFUSE_DEBUG
@@ -927,7 +937,7 @@
 {
 	struct puffs_node *pn;
 	int error;
-	
+
 	error = 0;
 
 	/*
@@ -980,11 +990,14 @@
 	if (PERFUSE_NODE_DATA(opc)->pnd_flags & PND_REMOVED)
 		return ENOENT;
 
+#if notyet
 	/*
-	 * Create an object require -WX permission in the parent directory
+	 * XXX create needs -WX on the parent directory. No pcr is
+ 	 * given here, we cannot enforce this.
 	 */
-	if (no_access(opc, pcn->pcn_cred, PUFFS_VWRITE|PUFFS_VEXEC))
+	if (no_access(opc, pcr, PUFFS_VWRITE|PUFFS_VEXEC))
 		return EACCES;
+#endif
 
 	/*
 	 * If create is unimplemented: Check that it does not
@@ -1004,9 +1017,22 @@
 		if (error != 0)	
 			return error;
 
+		/*
+		 * FUSE does the open at create time, while
+		 * NetBSD will open in a subsequent operation.
+		 * We need to open now, in order to retain FUSE
+		 * semantics, but we have no credentials to use
+		 * since the PUFFS interface gives no pcr here. 
+		 *
+		 * open with NULL pcr will skip permission checks.
+		 * There is no security hole, since we know we
+		 * can open this file: we just created it. The 
+		 * calling process will not get a file descriptor
+		 * before the kernel sends the open operation, 
+		 * which will have a pcr, anyway.
+		 */
 		opc = (puffs_cookie_t)pn;
-
-		error = perfuse_node_open(pu, opc, FWRITE, pcn->pcn_cred);
+		error = perfuse_node_open(pu, opc, FWRITE, NULL);
 		if (error != 0)	
 			return error;
 
@@ -1023,7 +1049,7 @@
 	 * 
 	 * mode must contain file type (ie: S_IFREG), use VTTOIF(vap->va_type)
 	 */
-	pm = ps->ps_new_msg(pu, opc, FUSE_CREATE, len, pcn->pcn_cred);
+	pm = ps->ps_new_msg(pu, opc, FUSE_CREATE, len, NULL);
 	fci = GET_INPAYLOAD(ps, pm, fuse_create_in);
 	fci->flags = O_CREAT | O_TRUNC | O_RDWR;
 	fci->mode = vap->va_mode | VTTOIF(vap->va_type);
@@ -1048,6 +1074,8 @@
 	PERFUSE_NODE_DATA(pn)->pnd_ino = feo->nodeid;
 
 	fuse_attr_to_vap(ps, &pn->pn_va, &feo->attr);
+	pn->pn_va.va_gen = (u_long)(feo->generation);
+		
 	puffs_newinfo_setcookie(pni, pn);
 
 	/*
@@ -1101,19 +1129,25 @@
 	 * directories, files, socks, fifo and links.
 	 *
 	 * Create an object require -WX permission in the parent directory
+	 *
+	 * XXX The PUFFS interface gives us no pcr here, we cannot perfom 
+	 * access control.
 	 */
 	switch (vap->va_type) {
 	case VDIR:	/* FALLTHROUGH */
 	case VREG:	/* FALLTHROUGH */
 	case VFIFO:	/* FALLTHROUGH */
 	case VSOCK:	/* FALLTHROUGH */
-	case VLNK:
-		if (no_access(opc, pcn->pcn_cred, PUFFS_VWRITE|PUFFS_VEXEC))
+#if notyet
+		if (no_access(opc, pcr, PUFFS_VWRITE|PUFFS_VEXEC))
 			return EACCES;
+#endif
 		break;
 	default:	/* VNON, VBLK, VCHR, VBAD */
-		if (!puffs_cred_isjuggernaut(pcn->pcn_cred))
+#if notyet
+		if (!puffs_cred_isjuggernaut(

CVS commit: src/lib/libperfuse

2010-10-03 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon Oct  4 03:56:24 UTC 2010

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
- delete an obsoelte comment about inactive
- remove a test for getattr return field that was never filled
- correctly send filehandle and filehandle flags for getaattr


To generate a diff of this commit:
cvs rdiff -u -r1.19 -r1.20 src/lib/libperfuse/ops.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.19 src/lib/libperfuse/ops.c:1.20
--- src/lib/libperfuse/ops.c:1.19	Sun Oct  3 05:46:47 2010
+++ src/lib/libperfuse/ops.c	Mon Oct  4 03:56:24 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.19 2010/10/03 05:46:47 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.20 2010/10/04 03:56:24 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -1192,10 +1192,7 @@
 
 	/*
 	 * Do not open twice, and do not reopen for reading
-	 * if we already have write handle. Just ask for
-	 * inactive, in case the node was open by a create
-	 * operation (we are not allowed to call puffs_setback
-	 * at create time, puffs interface forbids it)
+	 * if we already have write handle.
 	 */
 	if (((mode & FREAD) && (pnd->pnd_flags & PND_RFH)) ||
 	((mode & FREAD) && (pnd->pnd_flags & PND_WFH)) ||
@@ -1319,7 +1316,12 @@
 		fgi = GET_INPAYLOAD(ps, pm, fuse_getattr_in);
 		fgi->getattr_flags = 0; 
 		fgi->dummy = 0;
-		fgi->fh = perfuse_get_fh(opc, FREAD);
+		fgi->fh = 0;
+
+		if (PERFUSE_NODE_DATA(opc)->pnd_flags & PND_OPEN) {
+			fgi->fh = perfuse_get_fh(opc, FREAD);
+			fgi->getattr_flags |= FUSE_GETATTR_FH; 
+		}
 
 #ifdef PERFUSE_DEBUG
 		if (perfuse_diagflags & PDF_FH)
@@ -1335,12 +1337,6 @@
 
 		fao = GET_OUTPAYLOAD(ps, pm, fuse_attr_out);
 
-#ifdef PERFUSE_DEBUG
-		if (!(fao->attr_valid & (FUSE_FATTR_SIZE|FUSE_FATTR_MODE|
-	 FUSE_FATTR_UID|FUSE_FATTR_GID)))
-			DERRX(EX_SOFTWARE, "%s: fao->attr_valid = 0x%"PRId64"",
-			  __func__, fao->attr_valid);
-#endif
 		error = puffs_access(VREG, fao->attr.mode, fao->attr.uid,
  fao->attr.gid, (mode_t)mode, pcr); 
 
@@ -1392,10 +1388,12 @@
 	fgi = GET_INPAYLOAD(ps, pm, fuse_getattr_in);
 	fgi->getattr_flags = 0; 
 	fgi->dummy = 0;
-	fgi->fh = perfuse_get_fh(opc, FREAD);
+	fgi->fh = 0;
 
-	if (PERFUSE_NODE_DATA(opc)->pnd_flags & PND_OPEN)
+	if (PERFUSE_NODE_DATA(opc)->pnd_flags & PND_OPEN) {
+		fgi->fh = perfuse_get_fh(opc, FREAD);
 		fgi->getattr_flags |= FUSE_GETATTR_FH;
+	}
 
 	if ((error = xchg_msg(pu, opc, pm, sizeof(*fao), wait_reply)) != 0)
 		goto out;
@@ -2760,7 +2758,7 @@
 			pm = ps->ps_new_msg(pu, opc, FUSE_GETATTR, 
 	sizeof(*fgi), NULL);
 			fgi = GET_INPAYLOAD(ps, pm, fuse_getattr_in);
-			fgi->getattr_flags = 0; 
+			fgi->getattr_flags = FUSE_GETATTR_FH; 
 			fgi->dummy = 0;
 			fgi->fh = perfuse_get_fh(opc, FWRITE);
 



CVS commit: src/lib/libperfuse

2010-10-02 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sun Oct  3 05:46:48 UTC 2010

Modified Files:
src/lib/libperfuse: debug.c ops.c perfuse.c perfuse_priv.h subr.c

Log Message:
- Correctly handle rename whith overwritten destination
- Keep track of file name to avoid lookups when we can. This makes sure we
  do not have two cookies for the same inode, a situation that cause wreak
  havoc when we come to remove or rename a node.
- Do not use PUFFS_FLAG_BUILDPATH at all, since we now track file names
- In open, queue requests after checking for access, as there is no merit
  to queue a will-be-denied request while we can deny it immediatly
- request reclaim of removed nodes at inactive stage


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libperfuse/debug.c
cvs rdiff -u -r1.18 -r1.19 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.9 -r1.10 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.13 -r1.14 src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.7 -r1.8 src/lib/libperfuse/subr.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/debug.c
diff -u src/lib/libperfuse/debug.c:1.4 src/lib/libperfuse/debug.c:1.5
--- src/lib/libperfuse/debug.c:1.4	Wed Sep 29 08:01:10 2010
+++ src/lib/libperfuse/debug.c	Sun Oct  3 05:46:47 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: debug.c,v 1.4 2010/09/29 08:01:10 manu Exp $ */
+/*  $NetBSD: debug.c,v 1.5 2010/10/03 05:46:47 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -84,7 +84,7 @@
 	"READ",
 	"WRITE",
 	"AFTERWRITE",
-	"OPEN"
+	"OPEN",
 	"AFTERXCHG"
 };
 

Index: src/lib/libperfuse/ops.c
diff -u src/lib/libperfuse/ops.c:1.18 src/lib/libperfuse/ops.c:1.19
--- src/lib/libperfuse/ops.c:1.18	Wed Sep 29 08:01:10 2010
+++ src/lib/libperfuse/ops.c	Sun Oct  3 05:46:47 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.18 2010/09/29 08:01:10 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.19 2010/10/03 05:46:47 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -184,7 +184,7 @@
 #ifdef PERFUSE_DEBUG
 	if ((perfuse_diagflags & PDF_FILENAME) && (opc != 0))
 		DPRINTF("file = \"%s\" flags = 0x%x\n", 
-			(char *)PNPATH((struct puffs_node *)opc), 
+			perfuse_node_path(opc),
 			PERFUSE_NODE_DATA(opc)->pnd_flags);
 #endif
 	if (pnd)
@@ -209,6 +209,14 @@
 	struct puffs_node *pn;
 	struct vattr *va;
 
+	/*
+	 * pcr is NULL for self open through fsync or readdir.
+	 * In both case, access control is useless, as it was
+	 * done before, at open time.
+	 */
+	if (pcr == NULL)
+		return 0;
+
 	pn = (struct puffs_node *)opc;
 	va = puffs_pn_getvap(pn);
 
@@ -291,7 +299,8 @@
 	namelen = PNPLEN(dpn) + 1 + namelen + 1;
 	if ((path = malloc(namelen)) == NULL)
 		DERR(EX_OSERR, "malloc failed");
-	(void)snprintf(path, namelen, "%s/%s", (char *)PNPATH(dpn), name);
+	(void)snprintf(path, namelen, "%s/%s", 
+		   perfuse_node_path((puffs_cookie_t)dpn), name);
 
 	error = node_lookup_common(pu, opc, path, pnp);
 	
@@ -308,6 +317,7 @@
 	struct puffs_node **pnp;
 {
 	struct perfuse_state *ps;
+	struct perfuse_node_data *pnd;
 	perfuse_msg_t *pm;
 	struct fuse_entry_out *feo;
 	struct puffs_node *pn;
@@ -316,6 +326,35 @@
 
 	ps = puffs_getspecific(pu);
 
+#ifdef PERFUSE_DEBUG
+	if (perfuse_diagflags & PDF_FILENAME)
+		DPRINTF("%s: opc = %p, file = \"%s\" looking up \"%s\"\n",
+			__func__, (void *)opc, perfuse_node_path(opc), path);
+#endif
+	/*
+	 * Is the node already known?
+	 */
+	TAILQ_FOREACH(pnd, &PERFUSE_NODE_DATA(opc)->pnd_children, pnd_next) {
+		if ((pnd->pnd_flags & PND_REMOVED) ||
+		(strcmp(pnd->pnd_name, path) != 0))
+			continue;
+
+		/*
+		 * We have a match
+		 */
+		if (pnp != NULL)
+			*pnp = (struct puffs_node *)(pnd->pnd_pn);
+
+#ifdef PERFUSE_DEBUG
+		if (perfuse_diagflags & PDF_FILENAME)
+			DPRINTF("%s: opc = %p, file = \"%s\" found "
+"cookie = %p, ino = %"PRId64" for \"%s\"\n",
+__func__, (void *)opc, perfuse_node_path(opc), 
+(void *)pnd->pnd_pn, pnd->pnd_ino, path);
+#endif
+		return 0;
+	}
+
 	len = strlen(path) + 1;
 
 	pm = ps->ps_new_msg(pu, opc, FUSE_LOOKUP, len, NULL);
@@ -326,7 +365,7 @@
 
 	feo = GET_OUTPAYLOAD(ps, pm, fuse_entry_out);
 
-	pn = perfuse_new_pn(pu, opc);
+	pn = perfuse_new_pn(pu, path, opc);
 	PERFUSE_NODE_DATA(pn)->pnd_ino = feo->nodeid;
 
 	fuse_attr_to_vap(ps, &pn->pn_va, &feo->attr);
@@ -376,13 +415,21 @@
 	if (feo->nodeid == PERFUSE_UNKNOWN_INO)
 		DERRX(EX_SOFTWARE, "%s: no ino", __func__);
 
-	pn = perfuse_new_pn(pu, opc);
+	pn = perfuse_new_pn(pu, pcn->pcn_name, opc);
 	PERFUSE_NODE_DATA(pn)->pnd_ino = feo->nodeid;
 
 	fuse_attr_to_vap(ps, &pn->pn_va, &feo->attr);
 	puffs_newinfo_setcookie(pni, pn);
+
+#ifdef PERFUSE_DEBUG
+	if (perfuse_diagflags & PDF_FILENAME)
+		DPRINTF("%s: opc = %p, file = \"%s\", flags = 0x%x "
+			"ino = %"PRId64"\n",
+			__func__, (void *)pn, pcn->pcn_name,
+			PERFUSE_NODE_DATA(pn)->pnd_flags, feo->nodeid);
+#endif
 	ps->p

CVS commit: src/lib/libperfuse

2010-09-29 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Wed Sep 29 08:01:11 UTC 2010

Modified Files:
src/lib/libperfuse: debug.c ops.c perfuse.c perfuse_priv.h subr.c

Log Message:
= Open files =
- Restore open on our own in fsycn and readdir, as the node may not already
be open, and FUSE really wants it to be. No need to close immediatly, it
can be done at inactive time.

= Write operations =
- fix a nasty bug that corrupted files on write (written added twice)
- Keep track of file size in order to honour PUFFS_IO_APPEND

= many fixes in rename =
- handler overwritten nodes correctly
- wait for all operations on the node to drain before doing rename, as
filesystems may not cope with operations on a moving file.
- setback PUFFS_SETBACK_INACT_N1 cannot be used from rename, we therefore
miss the inactive time for an overwritten node. This bounds us to give up
PUFFS_KFLAG_IAONDEMAND.

= Removed files =
- forbid most operations on a removed node, return ENOENT
- setback PUFFS_SETBACK_NOREF_N1 at inactive stage to cause removed
file reclaim

= Misc =
- Update outdated ARGSUSED for lint
- Fix a memory leak (puffs_pn_remove instead of puffs_pn_put)
- Do not use PUFFS_FLAG_BUILDPATH except for debug output. It makes the
lookup code much simplier.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libperfuse/debug.c
cvs rdiff -u -r1.17 -r1.18 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.8 -r1.9 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.12 -r1.13 src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.6 -r1.7 src/lib/libperfuse/subr.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/debug.c
diff -u src/lib/libperfuse/debug.c:1.3 src/lib/libperfuse/debug.c:1.4
--- src/lib/libperfuse/debug.c:1.3	Thu Sep 23 16:02:34 2010
+++ src/lib/libperfuse/debug.c	Wed Sep 29 08:01:10 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: debug.c,v 1.3 2010/09/23 16:02:34 manu Exp $ */
+/*  $NetBSD: debug.c,v 1.4 2010/09/29 08:01:10 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -85,6 +85,7 @@
 	"WRITE",
 	"AFTERWRITE",
 	"OPEN"
+	"AFTERXCHG"
 };
 
 const char *

Index: src/lib/libperfuse/ops.c
diff -u src/lib/libperfuse/ops.c:1.17 src/lib/libperfuse/ops.c:1.18
--- src/lib/libperfuse/ops.c:1.17	Thu Sep 23 16:02:34 2010
+++ src/lib/libperfuse/ops.c	Wed Sep 29 08:01:10 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.17 2010/09/23 16:02:34 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.18 2010/09/29 08:01:10 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -54,12 +54,10 @@
 const char*, struct puffs_node **);
 static int node_mk_common(struct puffs_usermount *, puffs_cookie_t,
 struct puffs_newinfo *, const struct puffs_cn *pcn, perfuse_msg_t *);
-static const char *basename_r(const char *);
 static ssize_t fuse_to_dirent(struct puffs_usermount *, puffs_cookie_t,
 struct fuse_dirent *, size_t);
-static int readdir_buffered(struct perfuse_state *, puffs_cookie_t,
-struct dirent *, off_t *, size_t *, const struct puffs_cred *,
-int *, off_t *, size_t *);
+static int readdir_buffered(puffs_cookie_t, struct dirent *, off_t *, 
+size_t *, const struct puffs_cred *, int *, off_t *, size_t *);
 static void requeue_request(struct puffs_usermount *, 
 puffs_cookie_t opc, enum perfuse_qtype);
 static int dequeue_requests(struct perfuse_state *, 
@@ -175,9 +173,13 @@
  	enum perfuse_xchg_pb_reply wait;
 {
 	struct perfuse_state *ps;
+	struct perfuse_node_data *pnd;
 	int error;
 
 	ps = puffs_getspecific(pu);
+	pnd = NULL;
+	if ((struct puffs_node *)opc != NULL)
+		pnd = PERFUSE_NODE_DATA(opc);
 
 #ifdef PERFUSE_DEBUG
 	if ((perfuse_diagflags & PDF_FILENAME) && (opc != 0))
@@ -185,8 +187,16 @@
 			(char *)PNPATH((struct puffs_node *)opc), 
 			PERFUSE_NODE_DATA(opc)->pnd_flags);
 #endif
+	if (pnd)
+		pnd->pnd_flags |= PND_INXCHG;
+
 	error = ps->ps_xchg_msg(pu, pm, len, wait);
 
+	if (pnd) {
+		pnd->pnd_flags &= ~PND_INXCHG;
+		(void)dequeue_requests(ps, opc, PCQ_AFTERXCHG, DEQUEUE_ALL);
+	}
+
 	return error;
 }
 
@@ -306,7 +316,6 @@
 
 	ps = puffs_getspecific(pu);
 
-	path = basename_r(path);
 	len = strlen(path) + 1;
 
 	pm = ps->ps_new_msg(pu, opc, FUSE_LOOKUP, len, NULL);
@@ -327,8 +336,9 @@
 
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & PDF_FILENAME)
-		DPRINTF("%s: opc = %p, looked up opc = %p, file = \"%s\"\n",
-			__func__, (void *)opc, pn, (char *)PNPATH(pn));
+		DPRINTF("%s: opc = %p, looked up opc = %p, ino = %"PRId64" "
+			"file = \"%s\"\n", __func__, (void *)opc, pn, 
+			feo->nodeid, path);
 #endif
 out: 
 	ps->ps_destroy_msg(pm);
@@ -402,41 +412,6 @@
 	return error;
 }
 
-static const char *
-basename_r(string)
-	const char *string;
-{
-	char *result;
-
-	if ((result = rindex(string, '/')) == NULL)
-		return string;
-
-	/*
-	 * We are finished if this is not a trailing /
-	 */
-	if (result[1] != '\0')
-		return result + 1

CVS commit: src/lib/libperfuse

2010-09-20 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon Sep 20 07:00:22 UTC 2010

Modified Files:
src/lib/libperfuse: ops.c perfuse.c perfuse_priv.h subr.c

Log Message:
- performance improvement for read, readdir and write. Now we use
SOCK_DGRAM, we can send many pages at once without hitting any bug

- when creating a file, it is open for FUSE, but not for the kernel.
If the kernel does not do a subsequent open, we have a leak. We fight
against this by trying to close such file that the kernel left unopen
for some time.

- some code refactoring to make message exchange debug easier (more to come)


To generate a diff of this commit:
cvs rdiff -u -r1.15 -r1.16 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.6 -r1.7 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.10 -r1.11 src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.4 -r1.5 src/lib/libperfuse/subr.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.15 src/lib/libperfuse/ops.c:1.16
--- src/lib/libperfuse/ops.c:1.15	Wed Sep 15 01:51:43 2010
+++ src/lib/libperfuse/ops.c	Mon Sep 20 07:00:21 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.15 2010/09/15 01:51:43 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.16 2010/09/20 07:00:21 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -43,7 +43,8 @@
 
 extern int perfuse_diagflags;
 
-static int node_close_common(struct puffs_usermount *, puffs_cookie_t, int);
+static int xchg_msg(struct puffs_usermount *, puffs_cookie_t, 
+perfuse_msg_t *, size_t, enum perfuse_xchg_pb_reply); 
 static int no_access(puffs_cookie_t, const struct puffs_cred *, mode_t);
 static void fuse_attr_to_vap(struct perfuse_state *,
 struct vattr *, struct fuse_attr *);
@@ -94,8 +95,8 @@
 #define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12])
 #define VTTOIF(indx) (vttoif_tab[(int)(indx)])
 
-static int
-node_close_common(pu, opc, mode)
+int
+perfuse_node_close_common(pu, opc, mode)
 	struct puffs_usermount *pu;
 	puffs_cookie_t opc;
 	int mode;
@@ -148,7 +149,8 @@
 			 __func__, (void *)opc, pnd->pnd_ino, fri->fh);
 #endif
 
-	if ((error = XCHG_MSG(ps, pu, pm, NO_PAYLOAD_REPLY_LEN)) != 0)
+	if ((error = xchg_msg(pu, opc, pm,
+			  NO_PAYLOAD_REPLY_LEN, wait_reply)) != 0)
 		goto out;
 
 	ps->ps_destroy_msg(pm);
@@ -163,6 +165,30 @@
 	return error;
 }
 
+/* ARGSUSED1 */
+static int
+xchg_msg(pu, opc, pm, len, wait)
+	struct puffs_usermount *pu;
+	puffs_cookie_t opc;
+	perfuse_msg_t *pm;
+	size_t len;
+ 	enum perfuse_xchg_pb_reply wait;
+{
+	struct perfuse_state *ps;
+	int error;
+
+	ps = puffs_getspecific(pu);
+
+#ifdef PERFUSE_DEBUG
+	if ((perfuse_diagflags & PDF_FUSE) && (opc != 0))
+		DPRINTF("file = \"%s\"\n", 
+			(char *)PNPATH((struct puffs_node *)opc));
+#endif
+	error = ps->ps_xchg_msg(pu, pm, len, wait);
+
+	return error;
+}
+
 static int
 no_access(opc, pcr, mode)
 	puffs_cookie_t opc;
@@ -285,7 +311,7 @@
 	pm = ps->ps_new_msg(pu, opc, FUSE_LOOKUP, len, NULL);
 	(void)strlcpy(_GET_INPAYLOAD(ps, pm, char *), path, len);
 
-	if ((error = XCHG_MSG(ps, pu, pm, sizeof(*feo))) != 0)
+	if ((error = xchg_msg(pu, opc, pm, sizeof(*feo), wait_reply)) != 0)
 		goto out;
 
 	feo = GET_OUTPAYLOAD(ps, pm, fuse_entry_out);
@@ -327,7 +353,7 @@
 
 	ps =  puffs_getspecific(pu);
 
-	if ((error = XCHG_MSG(ps, pu, pm, sizeof(*feo))) != 0)
+	if ((error = xchg_msg(pu, opc, pm, sizeof(*feo), wait_reply)) != 0)
 		goto out;
 
 	feo = GET_OUTPAYLOAD(ps, pm, fuse_entry_out);
@@ -357,7 +383,8 @@
 	/*
 	 * A fuse_attr_out is returned, but we ignore it.
 	 */
-	error = XCHG_MSG(ps, pu, pm, sizeof(struct fuse_attr_out));
+	error = xchg_msg(pu, (puffs_cookie_t)pn, 
+			 pm, sizeof(struct fuse_attr_out), wait_reply);
 
 	/*
 	 * The parent directory needs a sync
@@ -604,9 +631,6 @@
 	ps = perfuse_getspecific(pu);
 #endif
 
-	/*
-	 * XXX Add a lock he day we go multithreaded
-	 */
 	pnd = PERFUSE_NODE_DATA(opc);
 	pcq.pcq_type = type;
 	pcq.pcq_cc = puffs_cc_getcc(pu);
@@ -644,9 +668,6 @@
 	struct perfuse_node_data *pnd;
 	int dequeued;
 
-	/*
-	 * XXX Add a lock he day we go multithreaded
-	 */
 	pnd = PERFUSE_NODE_DATA(opc);
 	dequeued = 0;
 	TAILQ_FOREACH(pcq, &pnd->pnd_pcq, pcq_next) {
@@ -684,7 +705,7 @@
 	int error;
 
 	ps = puffs_getspecific(pu);
-
+	
 if (puffs_mount(pu, ps->ps_target, ps->ps_mountflags, ps->ps_root) != 0)
 DERR(EX_OSERR, "puffs_mount failed");
 
@@ -702,7 +723,7 @@
 	fii->max_readahead = 32 * PAGE_SIZE; 
 	fii->flags = (FUSE_ASYNC_READ|FUSE_POSIX_LOCKS|FUSE_ATOMIC_O_TRUNC);
 
-	if ((error = XCHG_MSG(ps, pu, pm, sizeof(*fio))) != 0)
+	if ((error = xchg_msg(pu, 0, pm, sizeof(*fio), wait_reply)) != 0)
 		DERRX(EX_SOFTWARE, "init message exchange failed (%d)", error);
 
 	fio = GET_OUTPAYLOAD(ps, pm, fuse_init_out);
@@ -729,7 +750,7 @@
 	opc = (puffs_cookie_t)puffs_getroot(pu);
 	pm = ps->ps_new_msg(pu, opc, FUSE_DESTROY, 0,

CVS commit: src/lib/libperfuse

2010-09-09 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Thu Sep  9 09:12:35 UTC 2010

Modified Files:
src/lib/libperfuse: ops.c perfuse_priv.h

Log Message:
- call FSYNCDIR for directories
- directories can be open R/W (for FSYNCDIR)
- do not skip calls to FSYNC or FSYNCDIR if the filesystem returned ENOSYS:
it may change its mind, and it may also actually do something when retunring
ENOSYS
- When FSYNC and FSYNCDIR return ENOSYS, do not report it to kernel (silent
failure)


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.8 -r1.9 src/lib/libperfuse/perfuse_priv.h

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.13 src/lib/libperfuse/ops.c:1.14
--- src/lib/libperfuse/ops.c:1.13	Tue Sep  7 16:58:13 2010
+++ src/lib/libperfuse/ops.c	Thu Sep  9 09:12:35 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.13 2010/09/07 16:58:13 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.14 2010/09/09 09:12:35 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -62,7 +62,7 @@
 static void requeue_request(struct puffs_usermount *, 
 puffs_cookie_t opc, enum perfuse_qtype);
 static int dequeue_requests(struct perfuse_state *, 
- puffs_cookie_t opc, enum perfuse_qtype, int);
+puffs_cookie_t opc, enum perfuse_qtype, int);
 #define DEQUEUE_ALL 0
 
 /* 
@@ -359,6 +359,10 @@
 	 */
 	error = XCHG_MSG(ps, pu, pm, sizeof(struct fuse_attr_out));
 
+	/*
+	 * The parent directory needs a sync
+	 */
+	PERFUSE_NODE_DATA(opc)->pnd_flags |= PND_DIRTY;
 out:
 	ps->ps_destroy_msg(pm);
 
@@ -1010,6 +1014,10 @@
 	fuse_attr_to_vap(ps, &pn->pn_va, &feo->attr);
 	puffs_newinfo_setcookie(pni, pn);
 
+	/*
+	 * The parent directory needs a sync
+	 */
+	PERFUSE_NODE_DATA(opc)->pnd_flags |= PND_DIRTY;
 out: 
 	ps->ps_destroy_msg(pm);
 
@@ -1132,11 +1140,7 @@
 	/*
 	 * Do not open twice, and do not reopen for reading
 	 * if we already have write handle.
-	 * Directories are always open with read access only, 
-	 * whatever flags we get.
 	 */
-	if (op == FUSE_OPENDIR)
-		mode = (mode & ~(FREAD|FWRITE)) | FREAD;
 	if ((mode & FREAD) && (pnd->pnd_flags & PND_RFH))
 		return 0;
 	if ((mode & FWRITE) && (pnd->pnd_flags & PND_WFH))
@@ -1543,6 +1547,7 @@
 	off_t offlo;
 	off_t offhi;
 {
+	int op;
 	perfuse_msg_t *pm;
 	struct perfuse_state *ps;
 	struct perfuse_node_data *pnd;
@@ -1553,18 +1558,16 @@
 	
 	pm = NULL;
 	open_self = 0;	
-
-	/* 
-	 * If we previously detected it as unimplemented,
-	 * skip the call to the filesystem.
-	 */
 	ps = puffs_getspecific(pu);
-	if (ps->ps_flags == PS_NO_FSYNC)
-		return ENOSYS;
+
+	if (puffs_pn_getvap((struct puffs_node *)opc)->va_type == VDIR) 
+		op = FUSE_FSYNCDIR;
+	else 		/* VREG but also other types such as VLNK */
+		op = FUSE_FSYNC;
 
 	/*
 	 * Do not sync if there are no change to sync
-	 * XXX remove that test if we implement mmap
+	 * XXX remove that test on files if we implement mmap
 	 */
 	pnd = PERFUSE_NODE_DATA(opc);
 #ifdef PERFUSE_DEBUG
@@ -1582,7 +1585,7 @@
 	 * glusterfs complain in such a situation:
 	 * "FSYNC() ERR => -1 (Invalid argument)"
 	 */
-	if (!(pnd->pnd_flags & PND_OPEN)) {
+	if (!(pnd->pnd_flags & PND_WFH)) {
 		if ((error = perfuse_node_open(pu, opc, FWRITE, pcr)) != 0)
 			goto out;
 		open_self = 1;
@@ -1593,7 +1596,7 @@
 	/*
 	 * If fsync_flags  is set, meta data should not be flushed.
 	 */
-	pm = ps->ps_new_msg(pu, opc, FUSE_FSYNC, sizeof(*ffi), NULL);
+	pm = ps->ps_new_msg(pu, opc, op, sizeof(*ffi), NULL);
 	ffi = GET_INPAYLOAD(ps, pm, fuse_fsync_in);
 	ffi->fh = fh;
 	ffi->fsync_flags = (flags & FFILESYNC) ? 0 : 1;
@@ -1622,8 +1625,11 @@
 #endif
 
 out:
+	/*
+	 * ENOSYS is not returned to kernel,
+	 */
 	if (error == ENOSYS)
-		ps->ps_flags |= PS_NO_FSYNC;
+		error = 0;
 
 	if (pm != NULL)
 		ps->ps_destroy_msg(pm);
@@ -1683,6 +1689,7 @@
 		DERRX(EX_SOFTWARE, "%s: targ is NULL", __func__);
 
 	ps = puffs_getspecific(pu);
+	pnd = PERFUSE_NODE_DATA(opc);
 	pn = (struct puffs_node *)targ;
 	name = basename_r((char *)PNPATH(pn));
 	len = strlen(name) + 1;
@@ -1704,6 +1711,11 @@
 	/*
 	 * Reclaim should take care of decreasing pnd_childcount
 	 */
+
+	/*
+	 * The parent directory needs a sync
+	 */
+	PERFUSE_NODE_DATA(opc)->pnd_flags |= PND_DIRTY;
 out:
 	ps->ps_destroy_msg(pm);
 
@@ -1890,6 +1902,10 @@
 
 	PERFUSE_NODE_DATA(targ)->pnd_flags |= PND_REMOVED;
 
+	/*
+	 * The parent directory needs a sync
+	 */
+	PERFUSE_NODE_DATA(opc)->pnd_flags |= PND_DIRTY;
 out:
 	ps->ps_destroy_msg(pm);
 

Index: src/lib/libperfuse/perfuse_priv.h
diff -u src/lib/libperfuse/perfuse_priv.h:1.8 src/lib/libperfuse/perfuse_priv.h:1.9
--- src/lib/libperfuse/perfuse_priv.h:1.8	Mon Sep  6 01:40:24 2010
+++ src/lib/libperfuse/perfuse_priv.h	Thu Sep  9 09:12:35 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_priv.h,v 1.8 2010/09/06 01:40:24 manu Exp $ */
+/*  $NetBSD: perf

CVS commit: src/lib/libperfuse

2010-09-07 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue Sep  7 16:58:14 UTC 2010

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Mode argument must contain the file type (S_* items) for create and mknod


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libperfuse/ops.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.12 src/lib/libperfuse/ops.c:1.13
--- src/lib/libperfuse/ops.c:1.12	Tue Sep  7 02:11:04 2010
+++ src/lib/libperfuse/ops.c	Tue Sep  7 16:58:13 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.12 2010/09/07 02:11:04 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.13 2010/09/07 16:58:13 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -972,11 +972,13 @@
 	/*
 	 * flags should use O_WRONLY instead of O_RDWR, but it
 	 * breaks when the caller tries to read from file.
+	 * 
+	 * mode must contain file type (ie: S_IFREG), use VTTOIF(vap->va_type)
 	 */
 	pm = ps->ps_new_msg(pu, opc, FUSE_CREATE, len, pcn->pcn_cred);
 	fci = GET_INPAYLOAD(ps, pm, fuse_create_in);
 	fci->flags = O_CREAT | O_TRUNC | O_RDWR;
-	fci->mode = vap->va_mode;
+	fci->mode = vap->va_mode | VTTOIF(vap->va_type);
 	fci->umask = 0; 	/* Seems unused by libfuse */
 	(void)strlcpy((char*)(void *)(fci + 1), name, namelen);
 
@@ -1065,7 +1067,7 @@
 	len = sizeof(*fmi) + strlen(path) + 1; 
 
 	/*	
-	 * mode can contain file type (ie: S_IFREG), use VTTOIF(vap->va_type)
+	 * mode must contain file type (ie: S_IFREG), use VTTOIF(vap->va_type)
 	 */
 	pm = ps->ps_new_msg(pu, opc, FUSE_MKNOD, len, pcn->pcn_cred);
 	fmi = GET_INPAYLOAD(ps, pm, fuse_mknod_in);



CVS commit: src/lib/libperfuse

2010-09-05 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon Sep  6 01:17:05 UTC 2010

Modified Files:
src/lib/libperfuse: ops.c perfuse_if.h perfuse_priv.h

Log Message:
build fixes for LP64


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.4 -r1.5 src/lib/libperfuse/perfuse_if.h
cvs rdiff -u -r1.6 -r1.7 src/lib/libperfuse/perfuse_priv.h

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.9 src/lib/libperfuse/ops.c:1.10
--- src/lib/libperfuse/ops.c:1.9	Sun Sep  5 06:49:13 2010
+++ src/lib/libperfuse/ops.c	Mon Sep  6 01:17:05 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.9 2010/09/05 06:49:13 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.10 2010/09/06 01:17:05 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -416,7 +416,7 @@
 	fd_offset = 0;
 	written = 0;
 	dents = PERFUSE_NODE_DATA(opc)->pnd_dirent;
-	dents_len = PERFUSE_NODE_DATA(opc)->pnd_dirent_len;
+	dents_len = (size_t)PERFUSE_NODE_DATA(opc)->pnd_dirent_len;
 
 	do {
 		char *ndp;
@@ -569,7 +569,8 @@
 
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & PDF_READDIR)
-		DPRINTF("%s: readoff = %"PRId64",  pnd->pnd_dirent_len = %zd\n",
+		DPRINTF("%s: readoff = %"PRId64",  "
+			"pnd->pnd_dirent_len = %"PRId64"\n",
 			__func__, *readoff, pnd->pnd_dirent_len);
 #endif
 	if (*readoff >=  pnd->pnd_dirent_len) {
@@ -1067,7 +1068,7 @@
 	pm = ps->ps_new_msg(pu, opc, FUSE_MKNOD, len, pcn->pcn_cred);
 	fmi = GET_INPAYLOAD(ps, pm, fuse_mknod_in);
 	fmi->mode = vap->va_mode | VTTOIF(vap->va_type);
-	fmi->rdev = vap->va_rdev;
+	fmi->rdev = (uint32_t)vap->va_rdev;
 	fmi->umask = 0; 	/* Seems unused bu libfuse */
 	(void)strlcpy((char *)(void *)(fmi + 1), path, len - sizeof(*fmi));
 

Index: src/lib/libperfuse/perfuse_if.h
diff -u src/lib/libperfuse/perfuse_if.h:1.4 src/lib/libperfuse/perfuse_if.h:1.5
--- src/lib/libperfuse/perfuse_if.h:1.4	Wed Sep  1 14:57:24 2010
+++ src/lib/libperfuse/perfuse_if.h	Mon Sep  6 01:17:05 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_if.h,v 1.4 2010/09/01 14:57:24 manu Exp $ */
+/*  $NetBSD: perfuse_if.h,v 1.5 2010/09/06 01:17:05 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -153,7 +153,7 @@
 	size_t pmo_source_len;
 	size_t pmo_target_len;
 	size_t pmo_filesystemtype_len;
-	int pmo_mountflags;
+	long pmo_mountflags;
 	size_t pmo_data_len;
 };
 

Index: src/lib/libperfuse/perfuse_priv.h
diff -u src/lib/libperfuse/perfuse_priv.h:1.6 src/lib/libperfuse/perfuse_priv.h:1.7
--- src/lib/libperfuse/perfuse_priv.h:1.6	Sun Sep  5 06:49:13 2010
+++ src/lib/libperfuse/perfuse_priv.h	Mon Sep  6 01:17:05 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_priv.h,v 1.6 2010/09/05 06:49:13 manu Exp $ */
+/*  $NetBSD: perfuse_priv.h,v 1.7 2010/09/06 01:17:05 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -88,7 +88,7 @@
 	uint64_t pnd_offset;			/* seek state */
 	uint64_t pnd_lock_owner;
 	struct dirent *pnd_dirent;		/* native buffer for readdir */
-	size_t pnd_dirent_len;
+	off_t pnd_dirent_len;
 	struct fuse_dirent *pnd_all_fd;		/* FUSE buffer for readdir */
 	size_t pnd_all_fd_len;
 	TAILQ_HEAD(,perfuse_cc_queue) pnd_pcq;	/* queued requests */



CVS commit: src/lib/libperfuse

2010-09-04 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sun Sep  5 06:49:13 UTC 2010

Modified Files:
src/lib/libperfuse: ops.c perfuse_priv.h

Log Message:
- correctly set flags for CREATE

- after a node is deleted, some operations should return ENOENT, some
should be ignored. Fixed it for ACCESS, SETATTR and GETATTR. Other
operation may also need a fix.

- At reclaim time, there is no need to wait for READDIR and READ
completion, since the caller will never close a file before getting
readir() and read() replies. Waiting for WRITE completion is still
mandatory, but we must ensure that no queued WRITE is awaiting to
be scheduled. Once the queue is drained, we must check that the
reclaim operation was not canceled by a new file LOOKUP.

- At reclaim time, fixed a mix up between read and write fh to close

- Fixed permission checks for RENAME (it tested the node itself
instead of the source)

- When seting file mode, only MKNOD needs the filetype (S_* fields).
It is probably a bug to set it for other operations.


To generate a diff of this commit:
cvs rdiff -u -r1.8 -r1.9 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.5 -r1.6 src/lib/libperfuse/perfuse_priv.h

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.8 src/lib/libperfuse/ops.c:1.9
--- src/lib/libperfuse/ops.c:1.8	Fri Sep  3 14:32:50 2010
+++ src/lib/libperfuse/ops.c	Sun Sep  5 06:49:13 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.8 2010/09/03 14:32:50 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.9 2010/09/05 06:49:13 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -59,7 +59,7 @@
 int *, off_t *, size_t *);
 static void requeue_request(struct puffs_usermount *, 
 puffs_cookie_t opc, enum perfuse_qtype);
-static void dequeue_requests(struct perfuse_state *, 
+static int dequeue_requests(struct perfuse_state *, 
  puffs_cookie_t opc, enum perfuse_qtype, int);
 #define DEQUEUE_ALL 0
 
@@ -625,7 +625,7 @@
 }
 
 /* ARGSUSED0 */
-static void
+static int
 dequeue_requests(ps, opc, type, max)
 	struct perfuse_state *ps;
 	puffs_cookie_t opc;
@@ -661,7 +661,7 @@
 		DPRINTF("%s: DONE  opc = %p\n", __func__, (void *)opc);
 #endif
 
-	return;
+	return dequeued;
 }
 	
 void
@@ -966,11 +966,15 @@
 	namelen = strlen(name) + 1;
 	len = sizeof(*fci) + namelen;
 
+	/*
+	 * flags should use O_WRONLY instead of O_RDWR, but it
+	 * breaks when the caller tries to read from file.
+	 */
 	pm = ps->ps_new_msg(pu, opc, FUSE_CREATE, len, pcn->pcn_cred);
 	fci = GET_INPAYLOAD(ps, pm, fuse_create_in);
-	fci->flags = 0; 	/* No flags seems available */
+	fci->flags = O_CREAT | O_TRUNC | O_RDWR;
 	fci->mode = vap->va_mode;
-	fci->umask = 0; 	/* Seems unused bu libfuse */
+	fci->umask = 0; 	/* Seems unused by libfuse */
 	(void)strlcpy((char*)(void *)(fci + 1), name, namelen);
 
 	len = sizeof(*feo) + sizeof(*foo);
@@ -1001,14 +1005,6 @@
 	fuse_attr_to_vap(ps, &pn->pn_va, &feo->attr);
 	puffs_newinfo_setcookie(pni, pn);
 
-	/*
-	 * It seems we need to do this so that glusterfs gets fully
-	 * aware that the file was created. If we do not do it, we 
-	 * get "SETATTR (null) (fuse_loc_fill() failed)"
-	 */
-	(void)puffs_pn_nodewalk(pu, puffs_path_walkcmp,
-		__UNCONST(&pcn->pcn_po_full));
-
 out: 
 	ps->ps_destroy_msg(pm);
 
@@ -1065,6 +1061,9 @@
 	path = basename_r((char *)PCNPATH(pcn));
 	len = sizeof(*fmi) + strlen(path) + 1; 
 
+	/*	
+	 * mode can contain file type (ie: S_IFREG), use VTTOIF(vap->va_type)
+	 */
 	pm = ps->ps_new_msg(pu, opc, FUSE_MKNOD, len, pcn->pcn_cred);
 	fmi = GET_INPAYLOAD(ps, pm, fuse_mknod_in);
 	fmi->mode = vap->va_mode | VTTOIF(vap->va_type);
@@ -1193,15 +1192,6 @@
 	if (!(pnd->pnd_flags & PND_OPEN))
 		return EBADF;
 
-	/*
-	 * Make sure all operation are finished
-	 * There can be an ongoing write, or queued operations
-	 * XXX perhaps deadlock. Use requeue_request
-	 */
-	while ((pnd->pnd_flags & PND_BUSY) ||
-	   !TAILQ_EMPTY(&pnd->pnd_pcq))
-		puffs_cc_yield(puffs_cc_getcc(pu));
-
 	/* 
 	 * The NetBSD kernel will send sync and setattr(mtime, ctime)
 	 * afer a close on a regular file. Some FUSE filesystem will 
@@ -1226,6 +1216,9 @@
 	struct fuse_access_in *fai;
 	int error;
 	
+	if (PERFUSE_NODE_DATA(opc)->pnd_flags & PND_REMOVED)
+		return ENOENT;
+
 	/* 
 	 * If we previously detected the filesystem does not 
 	 * implement access(), short-circuit the call and skip 
@@ -1292,6 +1285,9 @@
 	struct fuse_attr_out *fao;
 	int error;
 	
+	if (PERFUSE_NODE_DATA(opc)->pnd_flags & PND_REMOVED)
+		return ENOENT;
+
 	/*
 	 * getattr requires --X on the parent directory
 	 */
@@ -1345,14 +1341,24 @@
 	struct perfuse_node_data *pnd;
 	struct fuse_setattr_in *fsi;
 	int error;
-	int open_self;
 	struct vattr *old_va;
 
-	open_self = 0;
 	ps = puffs_getspecific(pu);
 	pnd = PERFUSE_NODE_DATA(opc);
 
 	/*
+	 * The only operation we can do once the

CVS commit: src/lib/libperfuse

2010-09-03 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Fri Sep  3 14:32:50 UTC 2010

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
Fix reference count bug introduced by previous commit


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/lib/libperfuse/ops.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.7 src/lib/libperfuse/ops.c:1.8
--- src/lib/libperfuse/ops.c:1.7	Fri Sep  3 07:15:18 2010
+++ src/lib/libperfuse/ops.c	Fri Sep  3 14:32:50 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.7 2010/09/03 07:15:18 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.8 2010/09/03 14:32:50 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -1006,7 +1006,9 @@
 	 * aware that the file was created. If we do not do it, we 
 	 * get "SETATTR (null) (fuse_loc_fill() failed)"
 	 */
-	(void)node_lookup_common(pu, opc, (char*)PCNPATH(pcn), NULL);
+	(void)puffs_pn_nodewalk(pu, puffs_path_walkcmp,
+		__UNCONST(&pcn->pcn_po_full));
+
 out: 
 	ps->ps_destroy_msg(pm);
 
@@ -2489,7 +2491,6 @@
 	if (puffs_pn_getvap((struct puffs_node *)opc)->va_type == VDIR) 
 		return EBADF;
 
-DPRINTF("%s ENTER\n", __func__);
 	pnd->pnd_flags |= PND_INWRITE;
 
 	requested = *resid;



CVS commit: src/lib/libperfuse

2010-09-03 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Fri Sep  3 07:15:18 UTC 2010

Modified Files:
src/lib/libperfuse: ops.c perfuse_priv.h subr.c

Log Message:
- Postpone file close at reclaim time, since NetBSD sends fsync and
setattr(mtime, ctime) after close, while FUSE expects the file
to be open for these operations

- remove unused argument to node_mk_common()

- remove requeued requests when they are executed, not when they
are tagged for schedule

- try to make filehandle management simplier, by keeping track of only
one read and one write filehandle (the latter being really read/write).

- when CREATE is not available, we use the MKNOD/OPEN path. Fix a
bug here where we opened the parent directory instead of the node:
add the missing lookup of the mknod'ed node.

- lookup file we just created: glusterfs does not really see them
otherwise.

- open file when doing setattr(mtime, ctime) on non open files, as
some filesystems seems to require it.

- Do not flush pagecache for removed nodes

- Keep track of read/write operations in progress, and at reclaim
time, make sure they are over before closing and forgeting the file.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.4 -r1.5 src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.3 -r1.4 src/lib/libperfuse/subr.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.6 src/lib/libperfuse/ops.c:1.7
--- src/lib/libperfuse/ops.c:1.6	Thu Sep  2 08:58:06 2010
+++ src/lib/libperfuse/ops.c	Fri Sep  3 07:15:18 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.6 2010/09/02 08:58:06 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.7 2010/09/03 07:15:18 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -41,6 +41,7 @@
 #include "perfuse_priv.h"
 #include "fuse.h"
 
+static int node_close_common(struct puffs_usermount *, puffs_cookie_t, int);
 static int no_access(puffs_cookie_t, const struct puffs_cred *, mode_t);
 static void fuse_attr_to_vap(struct perfuse_state *,
 struct vattr *, struct fuse_attr *);
@@ -74,6 +75,7 @@
  */
 #define F_WAIT		0x010
 #define F_FLOCK		0x020
+#define OFLAGS(fflags)  ((fflags) - 1)
 
 /* 
  * Borrowed from src/sys/kern/vfs_subr.c and src/sys/sys/vnode.h 
@@ -90,6 +92,74 @@
 #define IFTOVT(mode) (iftovt_tab[((mode) & S_IFMT) >> 12])
 #define VTTOIF(indx) (vttoif_tab[(int)(indx)])
 
+static int
+node_close_common(pu, opc, mode)
+	struct puffs_usermount *pu;
+	puffs_cookie_t opc;
+	int mode;
+{
+	struct perfuse_state *ps;
+	perfuse_msg_t *pm;
+	int op;
+	uint64_t fh;
+	struct fuse_release_in *fri;
+	struct perfuse_node_data *pnd;
+	struct puffs_node *pn;
+	int error;
+
+	ps = puffs_getspecific(pu);
+	pn = (struct puffs_node *)opc;
+	pnd = PERFUSE_NODE_DATA(pn);
+
+	if (puffs_pn_getvap(pn)->va_type == VDIR) {
+		op = FUSE_RELEASEDIR;
+		mode = FREAD;
+	} else {
+		op = FUSE_RELEASE;
+	}
+
+	/*
+	 * Destroy the filehandle before sending the 
+	 * request to the FUSE filesystem, otherwise 
+	 * we may get a second close() while we wait
+	 * for the reply, and we would end up closing
+	 * the same fh twice instead of closng both.
+	 */
+	fh = perfuse_get_fh(opc, mode);
+	perfuse_destroy_fh(pn, fh);
+
+	/*
+	 * release_flags may be set to FUSE_RELEASE_FLUSH
+	 * to flush locks. lock_owner must be set in that case
+	 */
+	pm = ps->ps_new_msg(pu, opc, op, sizeof(*fri), NULL);
+	fri = GET_INPAYLOAD(ps, pm, fuse_release_in);
+	fri->fh = fh;
+	fri->flags = 0;
+	fri->release_flags = 0;
+	fri->lock_owner = pnd->pnd_lock_owner;
+	fri->flags = (fri->lock_owner != 0) ? FUSE_RELEASE_FLUSH : 0;
+
+#ifdef PERFUSE_DEBUG
+	if (perfuse_diagflags & PDF_FH)
+		DPRINTF("%s: opc = %p, ino = %"PRId64", fh = 0x%"PRIx64"\n",
+			 __func__, (void *)opc, pnd->pnd_ino, fri->fh);
+#endif
+
+	if ((error = XCHG_MSG(ps, pu, pm, NO_PAYLOAD_REPLY_LEN)) != 0)
+		goto out;
+
+	ps->ps_destroy_msg(pm);
+
+	error = 0;
+
+out:
+	if (error != 0)
+		DERRX(EX_SOFTWARE, "%s: freed fh = 0x%"PRIx64" but filesystem "
+		  "returned error = %d", __func__, fh, error);
+
+	return error;
+}
 
 static int
 no_access(opc, pcr, mode)
@@ -802,6 +872,19 @@
 	int error;
 	
 	/*
+	 * Special case for ..
+	 */
+	if (PCNISDOTDOT(pcn)) {
+		pn = PERFUSE_NODE_DATA(opc)->pnd_parent;
+		PERFUSE_NODE_DATA(pn)->pnd_flags &= ~PND_RECLAIMED;
+		
+		puffs_newinfo_setcookie(pni, pn);
+		puffs_newinfo_setvtype(pni, VDIR);
+
+		return 0;
+	}
+
+	/*
 	 * XXX This is borrowed from librefuse, 
 	 * and __UNCONST is said to be fixed.
 	 */
@@ -866,6 +949,12 @@
 		if (error != 0)
 			return error;
 
+		error = node_lookup_common(pu, opc, (char*)PCNPATH(pcn), &pn);
+		if (error != 0)	
+			return error;
+
+		opc = (puffs_cookie_t)pn;
+
 		error = perfuse_node_open(pu, opc, FREAD|FWRITE, pcn->pcn_cred);
 		if (error != 0)	
 			return error;
@@ -898,12 +987,26 @@
 	 * so that we can r

CVS commit: src/lib/libperfuse

2010-09-02 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Thu Sep  2 08:58:06 UTC 2010

Modified Files:
src/lib/libperfuse: ops.c

Log Message:
- only remove queued requests once they are executed, not when they
are set to be scheduled later
- remove an unused argument to make lint happy


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/lib/libperfuse/ops.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.5 src/lib/libperfuse/ops.c:1.6
--- src/lib/libperfuse/ops.c:1.5	Wed Sep  1 14:57:24 2010
+++ src/lib/libperfuse/ops.c	Thu Sep  2 08:58:06 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.5 2010/09/01 14:57:24 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.6 2010/09/02 08:58:06 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -49,8 +49,7 @@
 static int node_lookup_common(struct puffs_usermount *, puffs_cookie_t, 
 const char*, struct puffs_node **);
 static int node_mk_common(struct puffs_usermount *, puffs_cookie_t,
-struct puffs_newinfo *, const struct puffs_cn *pcn,
-const struct vattr *, perfuse_msg_t *);
+struct puffs_newinfo *, const struct puffs_cn *pcn, perfuse_msg_t *);
 static const char *basename_r(const char *);
 static ssize_t fuse_to_dirent(struct puffs_usermount *, puffs_cookie_t,
 struct fuse_dirent *, size_t);
@@ -241,12 +240,11 @@
  * perfuse_node_symlink
  */
 static int
-node_mk_common(pu, opc, pni, pcn, vap, pm)
+node_mk_common(pu, opc, pni, pcn, pm)
 	struct puffs_usermount *pu;
 	puffs_cookie_t opc;
 	struct puffs_newinfo *pni;
 	const struct puffs_cn *pcn;
-	const struct vattr *vap;
 	perfuse_msg_t *pm;
 {
 	struct perfuse_state *ps;
@@ -545,6 +543,7 @@
 #endif
 
 	puffs_cc_yield(pcq.pcq_cc);
+	TAILQ_REMOVE(&pnd->pnd_pcq, &pcq, pcq_next);
 
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & PDF_REQUEUE)
@@ -576,14 +575,12 @@
 		if (pcq->pcq_type != type)
 			continue;
 	
-		puffs_cc_schedule(pcq->pcq_cc);
-		TAILQ_REMOVE(&pnd->pnd_pcq, pcq, pcq_next);
-
 #ifdef PERFUSE_DEBUG
 		if (perfuse_diagflags & PDF_REQUEUE)
 			DPRINTF("%s: SCHEDULE opc = %p, pcc = %p\n",
 __func__, (void *)opc, pcq->pcq_cc);
 #endif
+		puffs_cc_schedule(pcq->pcq_cc);
 		
 		if (++dequeued == max)
 			break;
@@ -970,7 +967,7 @@
 	fmi->umask = 0; 	/* Seems unused bu libfuse */
 	(void)strlcpy((char *)(void *)(fmi + 1), path, len - sizeof(*fmi));
 
-	return node_mk_common(pu, opc, pni, pcn, vap, pm);
+	return node_mk_common(pu, opc, pni, pcn, pm);
 }
 
 
@@ -1758,7 +1755,7 @@
 	fmi->umask = 0; 	/* Seems unused bu libfuse? */
 	(void)strlcpy((char *)(void *)(fmi + 1), path, len - sizeof(*fmi));
 
-	return node_mk_common(pu, opc, pni, pcn, vap, pm);
+	return node_mk_common(pu, opc, pni, pcn, pm);
 }
 
 
@@ -1848,7 +1845,7 @@
 	np += path_len;
 	(void)strlcpy(np, link_target, linkname_len);
 
-	return node_mk_common(pu, opc, pni, pcn_src, vap, pm);
+	return node_mk_common(pu, opc, pni, pcn_src, pm);
 }
 
 int 



CVS commit: src/lib/libperfuse

2010-09-01 Thread Thomas Klausner
Module Name:src
Committed By:   wiz
Date:   Wed Sep  1 13:04:11 UTC 2010

Modified Files:
src/lib/libperfuse: libperfuse.3

Log Message:
Some fixes. Comment out ERRORS section until it has content.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libperfuse/libperfuse.3

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/libperfuse.3
diff -u src/lib/libperfuse/libperfuse.3:1.1 src/lib/libperfuse/libperfuse.3:1.2
--- src/lib/libperfuse/libperfuse.3:1.1	Wed Aug 25 07:16:00 2010
+++ src/lib/libperfuse/libperfuse.3	Wed Sep  1 13:04:11 2010
@@ -1,4 +1,4 @@
-.\" $NetBSD: libperfuse.3,v 1.1 2010/08/25 07:16:00 manu Exp $
+.\" $NetBSD: libperfuse.3,v 1.2 2010/09/01 13:04:11 wiz Exp $
 .\"
 .\" Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
 .\"
@@ -23,7 +23,6 @@
 .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 .\" POSSIBILITY OF SUCH DAMAGE.
 .\"
-.ds str-Lb-libperfusePUFFS enabled relay to FUSE Library (libperfuse, \-lperfuse)
 .Dd August 12, 2010
 .Dt LIBPERFUSE 2
 .Os
@@ -31,8 +30,9 @@
 .Nm perfuse_mount ,
 .Nm perfuse_open
 .Nd Request a
-.Xr puffs 3 mount from 
-.Xr perfused 8 .
+.Xr puffs 3
+mount from
+.Xr perfused 8
 .Sh LIBRARY
 .Lb libperfuse
 .Sh SYNOPSIS
@@ -43,11 +43,11 @@
 .Fn perfuse_open "const char *path" "int flags"
 .Sh DESCRIPTION
 .Fn perfuse_mount
-sends a mount request to 
+sends a mount request to
 .Xr perfused 8 .
 It is intended as a drop-in replacement for
 .Xr mount 2
-for FUSE filesystems daemons and libraries, so that they can work with
+for FUSE file systems daemons and libraries, so that they can work with
 .Xr perfused 8 .
 .Pp
 The function prototype mimics Linux's
@@ -55,56 +55,61 @@
 with the following arguments:
 .Bl -tag -width indent
 .It Ar source
-The source fileystem that will appear in
-.Xr df 1 ,
+The source file system that will appear in
+.Xr df 1
 and
 .Xr mount 8
-listings. Defaults to
+listings.
+Defaults to
 .Pa /dev/fuse
-if NULL.
+if
+.Dv NULL .
 .It Ar dir
-The filesystem mount point.
+The file system mount point.
 .It Ar filesystemtype
-The gileystem type, as displayed by
-.Xr df 1 ,
+The file system type, as displayed by
+.Xr df 1
 and
 .Xr mount 8 .
-Defaults to "fuse"
-if NULL.
+Defaults to
+.Dq fuse
+if
+.Dv NULL .
 .It Ar mountflags
-This contains the same value as in 
+This contains the same value as a
 .Xr mount 2
 .Ar flags
 argument.
 .It Ar data
-This contains the same value as in 
+This contains the same value as a
 .Xr mount 2
 .Ar data
 argument.
 .El
 .Pp
 .Fn perfuse_open
-is a drop-in replacement for the 
+is a drop-in replacement for the
 .Xr open 2
 system call where
 .Pa /dev/fuse
-is used. If
+is used.
+If
 .Ar path
 is different than
 .Pa /dev/fuse ,
-.Fn perfuse_open 
+.Fn perfuse_open
 handles control to the regular
 .Xr open 2 .
 .Sh RETURN VALUES
 .Fn perfuse_mount
 returns a file descriptor to the
 .Pa /dev/fuse
-socket on success, and cause exit on failure.
-.Sh ERRORS
-.Fn perfuse_mount
-will fail when one of the following occurs:
-.Bl -tag -width Er
-.El
+socket on success, and causes exit on failure.
+.\".Sh ERRORS
+.\".Fn perfuse_mount
+.\"will fail when one of the following occurs:
+.\".Bl -tag -width Er
+.\".El
 .Sh SEE ALSO
 .Xd df 1 ,
 .Xr mount 2 ,
@@ -113,5 +118,5 @@
 .Xr perfused 8
 .Sh AUTHORS
 The program was written by
-.An Emmanuel Dreyfus 
+.An Emmanuel Dreyfus
 .Aq m...@netbsd.org .



CVS commit: src/lib/libperfuse

2010-08-27 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sat Aug 28 03:46:21 UTC 2010

Modified Files:
src/lib/libperfuse: ops.c perfuse.c

Log Message:
- set user/group ownership after object creation.

- enforce permissios checks. This needs to be  reviewed.


To generate a diff of this commit:
cvs rdiff -u -r1.3 -r1.4 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.2 -r1.3 src/lib/libperfuse/perfuse.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.3 src/lib/libperfuse/ops.c:1.4
--- src/lib/libperfuse/ops.c:1.3	Fri Aug 27 09:58:17 2010
+++ src/lib/libperfuse/ops.c	Sat Aug 28 03:46:21 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.3 2010/08/27 09:58:17 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.4 2010/08/28 03:46:21 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -41,6 +41,7 @@
 #include "perfuse_priv.h"
 #include "fuse.h"
 
+static int no_access(puffs_cookie_t, const struct puffs_cred *, mode_t);
 static void fuse_attr_to_vap(struct perfuse_state *,
 struct vattr *, struct fuse_attr *);
 static int node_lookup_dir_nodot(struct puffs_usermount *,
@@ -48,7 +49,8 @@
 static int node_lookup_common(struct puffs_usermount *, puffs_cookie_t, 
 const char*, struct puffs_node **);
 static int node_mk_common(struct puffs_usermount *, puffs_cookie_t,
-struct puffs_newinfo *, perfuse_msg_t *);
+struct puffs_newinfo *, const struct puffs_cn *pcn,
+const struct vattr *, perfuse_msg_t *);
 static const char *basename_r(const char *);
 static ssize_t fuse_to_dirent(struct puffs_usermount *, puffs_cookie_t,
 struct fuse_dirent *, size_t);
@@ -90,6 +92,23 @@
 #define VTTOIF(indx) (vttoif_tab[(int)(indx)])
 
 
+static int
+no_access(opc, pcr, mode)
+	puffs_cookie_t opc;
+	const struct puffs_cred *pcr;
+	mode_t mode;
+{
+	struct puffs_node *pn;
+	struct vattr *va;
+
+	pn = (struct puffs_node *)opc;
+	va = puffs_pn_getvap(pn);
+
+	return puffs_access(va->va_type, va->va_mode, 
+			va->va_uid, va->va_gid,
+			mode, pcr);
+}
+
 static void
 fuse_attr_to_vap(ps, vap, fa)
 	struct perfuse_state *ps;
@@ -222,15 +241,18 @@
  * perfuse_node_symlink
  */
 static int
-node_mk_common(pu, opc, pni, pm)
+node_mk_common(pu, opc, pni, pcn, vap, pm)
 	struct puffs_usermount *pu;
 	puffs_cookie_t opc;
 	struct puffs_newinfo *pni;
+	const struct puffs_cn *pcn;
+	const struct vattr *vap;
 	perfuse_msg_t *pm;
 {
 	struct perfuse_state *ps;
 	struct puffs_node *pn;
 	struct fuse_entry_out *feo;
+	struct fuse_setattr_in *fsi;
 	int error;
 
 	ps =  puffs_getspecific(pu);
@@ -247,6 +269,25 @@
 
 	fuse_attr_to_vap(ps, &pn->pn_va, &feo->attr);
 	puffs_newinfo_setcookie(pni, pn);
+	ps->ps_destroy_msg(pm);
+ 
+	/* 
+	 * Set owner and group
+	 */
+	(void)puffs_cred_getuid(pcn->pcn_cred, &pn->pn_va.va_uid);
+	(void)puffs_cred_getgid(pcn->pcn_cred, &pn->pn_va.va_gid);
+
+	pm = ps->ps_new_msg(pu, (puffs_cookie_t)pn, 
+			FUSE_SETATTR, sizeof(*fsi), NULL);
+	fsi = GET_INPAYLOAD(ps, pm, fuse_setattr_in);
+	fsi->uid = pn->pn_va.va_uid;
+	fsi->gid = pn->pn_va.va_gid;
+	fsi->valid = FUSE_FATTR_UID|FUSE_FATTR_GID;
+
+	/*
+	 * A fuse_attr_out is returned, but we ignore it.
+	 */
+	error = XCHG_MSG(ps, pu, pm, sizeof(struct fuse_attr_out));
 
 out:
 	ps->ps_destroy_msg(pm);
@@ -807,6 +848,12 @@
 	int error;
 	
 	/*
+	 * Create an object require -WX permission in the parent directory
+	 */
+	if (no_access(opc, pcn->pcn_cred, PUFFS_VWRITE|PUFFS_VEXEC))
+		return EACCES;
+
+	/*
 	 * If create is unimplemented: Check that it does not
 	 * already exists, and if not, do mknod and open
 	 */
@@ -888,6 +935,28 @@
 	const char* path;
 	size_t len;
 	
+	/*
+	 * Only superuser can mknod objects other than 
+	 * directories, files, socks, fifo and links.
+	 *
+	 * Create an object require -WX permission in the parent directory
+	 */
+	switch (vap->va_type) {
+	case VDIR:	/* FALLTHROUGH */
+	case VREG:	/* FALLTHROUGH */
+	case VFIFO:	/* FALLTHROUGH */
+	case VSOCK:	/* FALLTHROUGH */
+	case VLNK:
+		if (no_access(opc, pcn->pcn_cred, PUFFS_VWRITE|PUFFS_VEXEC))
+			return EACCES;
+		break;
+	default:	/* VNON, VBLK, VCHR, VBAD */
+		if (!puffs_cred_isjuggernaut(pcn->pcn_cred))
+			return EACCES;
+		break;
+	}
+
+
 	ps = puffs_getspecific(pu);
 	path = basename_r((char *)PCNPATH(pcn));
 	len = sizeof(*fmi) + strlen(path) + 1; 
@@ -899,7 +968,7 @@
 	fmi->umask = 0; 	/* Seems unused bu libfuse */
 	(void)strlcpy((char *)(void *)(fmi + 1), path, len - sizeof(*fmi));
 
-	return node_mk_common(pu, opc, pni, pm);
+	return node_mk_common(pu, opc, pni, pcn, vap, pm);
 }
 
 
@@ -912,6 +981,7 @@
 {
 	struct perfuse_state *ps;
 	perfuse_msg_t *pm;
+	mode_t pmode;
 	int op;
 	struct fuse_open_in *foi;
 	struct fuse_open_out *foo;
@@ -921,10 +991,28 @@
 	ps = puffs_getspecific(pu);
 
 	pn = (struct puffs_node *)opc;
-	if (puffs_pn_getvap(pn)->va_type == VDIR)
+	if (puffs_pn_g