CVS commit: src/sys/ufs/ufs

2011-07-07 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Thu Jul  7 14:56:45 UTC 2011

Modified Files:
src/sys/ufs/ufs: ufs_extattr.c

Log Message:
Fix locking protocol to avoid a panic on extattrctl stop and on umount.


To generate a diff of this commit:
cvs rdiff -u -r1.34 -r1.35 src/sys/ufs/ufs/ufs_extattr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ufs/ufs_extattr.c
diff -u src/sys/ufs/ufs/ufs_extattr.c:1.34 src/sys/ufs/ufs/ufs_extattr.c:1.35
--- src/sys/ufs/ufs/ufs_extattr.c:1.34	Mon Jul  4 08:07:32 2011
+++ src/sys/ufs/ufs/ufs_extattr.c	Thu Jul  7 14:56:45 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_extattr.c,v 1.34 2011/07/04 08:07:32 manu Exp $	*/
+/*	$NetBSD: ufs_extattr.c,v 1.35 2011/07/07 14:56:45 manu Exp $	*/
 
 /*-
  * Copyright (c) 1999-2002 Robert N. M. Watson
@@ -48,7 +48,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_extattr.c,v 1.34 2011/07/04 08:07:32 manu Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_extattr.c,v 1.35 2011/07/07 14:56:45 manu Exp $);
 
 #ifdef _KERNEL_OPT
 #include opt_ffs.h
@@ -133,6 +133,7 @@
 	if (ump-um_extattr.uepm_lockcnt != 0) {
 		KASSERT(mutex_owned(ump-um_extattr.uepm_lock));
 		ump-um_extattr.uepm_lockcnt--;
+		return;
 	}
 	mutex_exit(ump-um_extattr.uepm_lock);
 }



CVS commit: src

2011-07-04 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon Jul  4 07:54:38 UTC 2011

Modified Files:
src/include/rpc: xdr.h
src/lib/libc/include: namespace.h
src/lib/libc/rpc: Makefile.inc
Added Files:
src/lib/libc/rpc: xdr_sizeof.c

Log Message:
Import xdr_sizeof() from FreeBSD


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/include/rpc/xdr.h
cvs rdiff -u -r1.148 -r1.149 src/lib/libc/include/namespace.h
cvs rdiff -u -r1.18 -r1.19 src/lib/libc/rpc/Makefile.inc
cvs rdiff -u -r0 -r1.1 src/lib/libc/rpc/xdr_sizeof.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/include/rpc/xdr.h
diff -u src/include/rpc/xdr.h:1.25 src/include/rpc/xdr.h:1.26
--- src/include/rpc/xdr.h:1.25	Wed Dec 28 15:26:06 2005
+++ src/include/rpc/xdr.h	Mon Jul  4 07:54:38 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: xdr.h,v 1.25 2005/12/28 15:26:06 yamt Exp $	*/
+/*	$NetBSD: xdr.h,v 1.26 2011/07/04 07:54:38 manu Exp $	*/
 
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@@ -313,6 +313,7 @@
 extern bool_t	xdr_u_hyper(XDR *, u_longlong_t *);
 extern bool_t	xdr_longlong_t(XDR *, longlong_t *);
 extern bool_t	xdr_u_longlong_t(XDR *, u_longlong_t *);
+extern unsigned long xdr_sizeof(xdrproc_t, void *);
 __END_DECLS
 
 /*

Index: src/lib/libc/include/namespace.h
diff -u src/lib/libc/include/namespace.h:1.148 src/lib/libc/include/namespace.h:1.149
--- src/lib/libc/include/namespace.h:1.148	Sat Mar 26 19:51:42 2011
+++ src/lib/libc/include/namespace.h	Mon Jul  4 07:54:38 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: namespace.h,v 1.148 2011/03/26 19:51:42 christos Exp $	*/
+/*	$NetBSD: namespace.h,v 1.149 2011/07/04 07:54:38 manu Exp $	*/
 
 /*-
  * Copyright (c) 1997-2004 The NetBSD Foundation, Inc.
@@ -747,6 +747,7 @@
 #define xdr_rpcbs		_xdr_rpcbs
 #define xdr_rpcbs		_xdr_rpcbs
 #define xdr_short		_xdr_short
+#define xdr_sizeof		_xdr_sizeof
 #define xdr_string		_xdr_string
 #define xdr_u_char		_xdr_u_char
 #define	xdr_u_hyper		_xdr_u_hyper

Index: src/lib/libc/rpc/Makefile.inc
diff -u src/lib/libc/rpc/Makefile.inc:1.18 src/lib/libc/rpc/Makefile.inc:1.19
--- src/lib/libc/rpc/Makefile.inc:1.18	Wed Jun 22 02:49:43 2011
+++ src/lib/libc/rpc/Makefile.inc	Mon Jul  4 07:54:38 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.18 2011/06/22 02:49:43 mrg Exp $
+#	$NetBSD: Makefile.inc,v 1.19 2011/07/04 07:54:38 manu Exp $
 
 # librpc sources
 .PATH:	${.CURDIR}/rpc
@@ -14,7 +14,7 @@
 	svc.c svc_auth.c svc_dg.c svc_auth_unix.c svc_generic.c svc_raw.c \
 	svc_run.c svc_simple.c svc_vc.c \
 	xdr.c xdr_array.c xdr_float.c xdr_mem.c xdr_rec.c xdr_reference.c \
-	xdr_stdio.c __rpc_getxid.c
+	xdr_stdio.c xdr_sizeof.c __rpc_getxid.c
 
 CPPFLAGS+=	-DPORTMAP
 

Added files:

Index: src/lib/libc/rpc/xdr_sizeof.c
diff -u /dev/null src/lib/libc/rpc/xdr_sizeof.c:1.1
--- /dev/null	Mon Jul  4 07:54:38 2011
+++ src/lib/libc/rpc/xdr_sizeof.c	Mon Jul  4 07:54:38 2011
@@ -0,0 +1,183 @@
+/*
+ * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
+ * unrestricted use provided that this legend is included on all tape
+ * media and as a part of the software program in whole or part.  Users
+ * may copy or modify Sun RPC without charge, but are not authorized
+ * to license or distribute it to anyone else except as part of a product or
+ * program developed by the user.
+ * 
+ * SUN RPC IS PROVIDED AS IS WITH NO WARRANTIES OF ANY KIND INCLUDING THE
+ * WARRANTIES OF DESIGN, MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE, OR ARISING FROM A COURSE OF DEALING, USAGE OR TRADE PRACTICE.
+ * 
+ * Sun RPC is provided with no support and without any obligation on the
+ * part of Sun Microsystems, Inc. to assist in its use, correction,
+ * modification or enhancement.
+ * 
+ * SUN MICROSYSTEMS, INC. SHALL HAVE NO LIABILITY WITH RESPECT TO THE
+ * INFRINGEMENT OF COPYRIGHTS, TRADE SECRETS OR ANY PATENTS BY SUN RPC
+ * OR ANY PART THEREOF.
+ * 
+ * In no event will Sun Microsystems, Inc. be liable for any lost revenue
+ * or profits or other special, indirect and consequential damages, even if
+ * Sun has been advised of the possibility of such damages.
+ * 
+ * Sun Microsystems, Inc.
+ * 2550 Garcia Avenue
+ * Mountain View, California  94043
+ */
+/*
+ * xdr_sizeof.c
+ *
+ * Copyright 1990 Sun Microsystems, Inc.
+ *
+ * General purpose routine to see how much space something will use
+ * when serialized using XDR.
+ */
+
+#include sys/cdefs.h
+#if 0
+__FBSDID($FreeBSD: src/lib/libc/xdr/xdr_sizeof.c,v 1.5.38.1 2010/12/21 17:10:29 kensmith Exp $);
+#else
+__RCSID($NetBSD: xdr_sizeof.c,v 1.1 2011/07/04 07:54:38 manu Exp $);
+#endif
+
+#include namespace.h
+#include rpc/types.h
+#include rpc/xdr.h
+#include sys/types.h
+#include stdlib.h
+
+#ifdef __weak_alias
+__weak_alias(xdr_sizeof,_xdr_sizeof)
+#endif 
+
+static bool_t x_putlong(XDR *, const long *);
+static bool_t x_putbytes(XDR *, const char *, u_int);
+static 

CVS commit: src

2011-07-04 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon Jul  4 08:07:32 UTC 2011

Modified Files:
src/lib/libp2k: p2k.c
src/lib/libperfuse: ops.c perfuse_priv.h
src/lib/libpuffs: dispatcher.c puffs.h puffs_ops.3
src/sys/fs/puffs: puffs_msgif.h puffs_vnops.c
src/sys/kern: vfs_xattr.c vnode_if.c
src/sys/rump/include/rump: rumpvnode_if.h
src/sys/rump/librump/rumpvfs: rumpvnode_if.c
src/sys/sys: extattr.h vnode_if.h
src/sys/ufs/ufs: ufs_extattr.c
src/usr.bin/extattr: getextattr.c

Log Message:
Add a flag to VOP_LISTEXTATTR(9) so that the vnode interface can tell the
filesystem in which format extended attribute shall be listed.

There are currently two formats:
- NUL-terminated strings, used for listxattr(2), this is the default.
- one byte length-pprefixed, non NUL-terminated strings, used for
  extattr_list_file(2), which is obtanined by setting the
  EXTATTR_LIST_PREFIXLEN flag to VOP_LISTEXTATTR(9)

This approach avoid the need for converting the list back and forth, except
in libperfuse, since FUSE uses NUL-terminated strings, and the kernel may
have requested EXTATTR_LIST_PREFIXLEN.


To generate a diff of this commit:
cvs rdiff -u -r1.54 -r1.55 src/lib/libp2k/p2k.c
cvs rdiff -u -r1.31 -r1.32 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.19 -r1.20 src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.35 -r1.36 src/lib/libpuffs/dispatcher.c
cvs rdiff -u -r1.117 -r1.118 src/lib/libpuffs/puffs.h
cvs rdiff -u -r1.28 -r1.29 src/lib/libpuffs/puffs_ops.3
cvs rdiff -u -r1.75 -r1.76 src/sys/fs/puffs/puffs_msgif.h
cvs rdiff -u -r1.153 -r1.154 src/sys/fs/puffs/puffs_vnops.c
cvs rdiff -u -r1.26 -r1.27 src/sys/kern/vfs_xattr.c
cvs rdiff -u -r1.86 -r1.87 src/sys/kern/vnode_if.c
cvs rdiff -u -r1.9 -r1.10 src/sys/rump/include/rump/rumpvnode_if.h
cvs rdiff -u -r1.8 -r1.9 src/sys/rump/librump/rumpvfs/rumpvnode_if.c
cvs rdiff -u -r1.5 -r1.6 src/sys/sys/extattr.h
cvs rdiff -u -r1.80 -r1.81 src/sys/sys/vnode_if.h
cvs rdiff -u -r1.33 -r1.34 src/sys/ufs/ufs/ufs_extattr.c
cvs rdiff -u -r1.6 -r1.7 src/usr.bin/extattr/getextattr.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/libp2k/p2k.c
diff -u src/lib/libp2k/p2k.c:1.54 src/lib/libp2k/p2k.c:1.55
--- src/lib/libp2k/p2k.c:1.54	Fri Jan  7 16:02:32 2011
+++ src/lib/libp2k/p2k.c	Mon Jul  4 08:07:29 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: p2k.c,v 1.54 2011/01/07 16:02:32 pooka Exp $	*/
+/*	$NetBSD: p2k.c,v 1.55 2011/07/04 08:07:29 manu Exp $	*/
 
 /*
  * Copyright (c) 2007, 2008, 2009  Antti Kantee.  All Rights Reserved.
@@ -1304,8 +1304,8 @@
 /*ARGSUSED*/
 int
 p2k_node_listextattr(struct puffs_usermount *pu, puffs_cookie_t opc,
-	int attrnamespace, size_t *attrsize,
-	uint8_t *attrs, size_t *resid, const struct puffs_cred *pcr)
+	int attrnamespace, size_t *attrsize, uint8_t *attrs,
+	size_t *resid, int flags, const struct puffs_cred *pcr)
 {
 	struct vnode *vp = OPC2VP(opc);
 	struct kauth_cred *cred;
@@ -1319,7 +1319,8 @@
 
 	cred = cred_create(pcr);
 	RUMP_VOP_LOCK(vp, LK_EXCLUSIVE);
-	rv = RUMP_VOP_LISTEXTATTR(vp, attrnamespace, uio, attrsize, cred);
+	rv = RUMP_VOP_LISTEXTATTR(vp, attrnamespace, uio, attrsize,
+	flags, cred);
 	RUMP_VOP_UNLOCK(vp);
 	cred_destroy(cred);
 

Index: src/lib/libperfuse/ops.c
diff -u src/lib/libperfuse/ops.c:1.31 src/lib/libperfuse/ops.c:1.32
--- src/lib/libperfuse/ops.c:1.31	Tue Jun 28 16:19:16 2011
+++ src/lib/libperfuse/ops.c	Mon Jul  4 08:07:29 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.31 2011/06/28 16:19:16 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.32 2011/07/04 08:07:29 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -3040,13 +3040,14 @@
 
 /* ARGSUSED2 */
 int
-perfuse_node_listextattr(pu, opc, attrns, attrsize, attrs, resid, pcr)
+perfuse_node_listextattr(pu, opc, attrns, attrsize, attrs, resid, flag, pcr)
 	struct puffs_usermount *pu;
 	puffs_cookie_t opc;
 	int attrns;
 	size_t *attrsize;
 	uint8_t *attrs;
 	size_t *resid;
+	int flag;
 	const struct puffs_cred *pcr;
 {
 	struct perfuse_state *ps;
@@ -3093,6 +3094,19 @@
 	puffs_len = foh-len - sizeof(*foh);
 
 	if (attrs != NULL) {
+		/* 
+		 * 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;
+
+			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;
+			}	
+		}
 		(void)memcpy(attrs, np, puffs_len);
 		*resid -= puffs_len;
 	}

Index: src/lib/libperfuse/perfuse_priv.h
diff -u src/lib/libperfuse/perfuse_priv.h:1.19 src/lib/libperfuse/perfuse_priv.h:1.20
--- src/lib/libperfuse/perfuse_priv.h:1.19	Tue Jun 28 16:19:16 2011
+++ src/lib/libperfuse/perfuse_priv.h	Mon Jul  4 08:07:30 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_priv.h,v 1.19 2011/06/28 16:19:16

CVS commit: src/lib/libc/rpc

2011-07-04 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon Jul  4 08:19:51 UTC 2011

Modified Files:
src/lib/libc/rpc: xdr.3

Log Message:
Document newly imported xdr_sizeof()


To generate a diff of this commit:
cvs rdiff -u -r1.12 -r1.13 src/lib/libc/rpc/xdr.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/libc/rpc/xdr.3
diff -u src/lib/libc/rpc/xdr.3:1.12 src/lib/libc/rpc/xdr.3:1.13
--- src/lib/libc/rpc/xdr.3:1.12	Tue Oct 13 21:39:55 2009
+++ src/lib/libc/rpc/xdr.3	Mon Jul  4 08:19:51 2011
@@ -1,5 +1,5 @@
 .\	@(#)xdr.3n	2.2 88/08/03 4.0 RPCSRC; from 1.16 88/03/14 SMI
-.\	$NetBSD: xdr.3,v 1.12 2009/10/13 21:39:55 joerg Exp $
+.\	$NetBSD: xdr.3,v 1.13 2011/07/04 08:19:51 manu Exp $
 .\
 .Dd April 17, 2003
 .Dt XDR 3
@@ -31,6 +31,7 @@
 .Nm xdr_reference ,
 .Nm xdr_setpos ,
 .Nm xdr_short ,
+.Nm xdr_sizeof ,
 .Nm xdrstdio_create ,
 .Nm xdr_string ,
 .Nm xdr_u_char ,
@@ -99,6 +100,8 @@
 .Fn xdr_setpos XDR *xdrs u_int pos
 .Ft int
 .Fn xdr_short XDR *xdrs short *sp
+.Ft nsigned long
+.Fn xdr_sizeof xdrproc_t func void *data
 .Ft void
 .Fn xdrstdio_create XDR *xdrs FILE *file enum xdr_op op
 .Ft int
@@ -378,6 +381,11 @@
 A filter primitive that translates between C short integers
 and their external representations.
 This routine returns one if it succeeds, zero otherwise.
+.It Fn xdr_sizeof
+This routine returns the amount of memory required to encode 
+.Fa data
+using filter
+.Fa func .
 .It Fn xdrstdio_create
 This routine initializes the XDR stream object pointed to by
 .Fa xdrs .



CVS commit: src

2011-07-04 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon Jul  4 12:05:02 UTC 2011

Modified Files:
src/distrib/sets/lists/comp: mi
src/lib/libc/rpc: Makefile.inc

Log Message:
Add documentation link xdr_sizeof(3) - xdr(3)


To generate a diff of this commit:
cvs rdiff -u -r1.1637 -r1.1638 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.19 -r1.20 src/lib/libc/rpc/Makefile.inc

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/comp/mi
diff -u src/distrib/sets/lists/comp/mi:1.1637 src/distrib/sets/lists/comp/mi:1.1638
--- src/distrib/sets/lists/comp/mi:1.1637	Fri Jul  1 12:09:34 2011
+++ src/distrib/sets/lists/comp/mi	Mon Jul  4 12:05:00 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: mi,v 1.1637 2011/07/01 12:09:34 njoly Exp $
+#	$NetBSD: mi,v 1.1638 2011/07/04 12:05:00 manu Exp $
 #
 # Note: don't delete entries from here - mark them as obsolete instead.
 #
@@ -9193,6 +9193,7 @@
 ./usr/share/man/cat3/xdr_replymsg.0		comp-c-catman		.cat
 ./usr/share/man/cat3/xdr_setpos.0		comp-c-catman		.cat
 ./usr/share/man/cat3/xdr_short.0		comp-c-catman		.cat
+./usr/share/man/cat3/xdr_sizeof.0		comp-c-catman		.cat
 ./usr/share/man/cat3/xdr_string.0		comp-c-catman		.cat
 ./usr/share/man/cat3/xdr_u_char.0		comp-c-catman		.cat
 ./usr/share/man/cat3/xdr_u_long.0		comp-c-catman		.cat
@@ -15206,6 +15207,7 @@
 ./usr/share/man/html3/xdr_replymsg.html		comp-c-htmlman		html
 ./usr/share/man/html3/xdr_setpos.html		comp-c-htmlman		html
 ./usr/share/man/html3/xdr_short.html		comp-c-htmlman		html
+./usr/share/man/html3/xdr_sizeof.html		comp-c-htmlman		html
 ./usr/share/man/html3/xdr_string.html		comp-c-htmlman		html
 ./usr/share/man/html3/xdr_u_char.html		comp-c-htmlman		html
 ./usr/share/man/html3/xdr_u_long.html		comp-c-htmlman		html
@@ -21294,6 +21296,7 @@
 ./usr/share/man/man3/xdr_replymsg.3		comp-c-man		.man
 ./usr/share/man/man3/xdr_setpos.3		comp-c-man		.man
 ./usr/share/man/man3/xdr_short.3		comp-c-man		.man
+./usr/share/man/man3/xdr_sizeof.3		comp-c-man		.man
 ./usr/share/man/man3/xdr_string.3		comp-c-man		.man
 ./usr/share/man/man3/xdr_u_char.3		comp-c-man		.man
 ./usr/share/man/man3/xdr_u_long.3		comp-c-man		.man

Index: src/lib/libc/rpc/Makefile.inc
diff -u src/lib/libc/rpc/Makefile.inc:1.19 src/lib/libc/rpc/Makefile.inc:1.20
--- src/lib/libc/rpc/Makefile.inc:1.19	Mon Jul  4 07:54:38 2011
+++ src/lib/libc/rpc/Makefile.inc	Mon Jul  4 12:05:00 2011
@@ -1,4 +1,4 @@
-#	$NetBSD: Makefile.inc,v 1.19 2011/07/04 07:54:38 manu Exp $
+#	$NetBSD: Makefile.inc,v 1.20 2011/07/04 12:05:00 manu Exp $
 
 # librpc sources
 .PATH:	${.CURDIR}/rpc
@@ -157,6 +157,7 @@
 		xdr.3 xdr_reference.3 \
 		xdr.3 xdr_setpos.3 \
 		xdr.3 xdr_short.3 \
+		xdr.3 xdr_sizeof.3 \
 		xdr.3 xdrstdio_create.3 \
 		xdr.3 xdr_string.3 \
 		xdr.3 xdr_u_char.3 \



CVS commit: src/sys/kern

2011-06-29 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Wed Jun 29 08:01:14 UTC 2011

Modified Files:
src/sys/kern: vfs_xattr.c

Log Message:
Fix bug introduced in previous commuit: Do not vrele() a vnode we did not
obtained.


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/kern/vfs_xattr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/vfs_xattr.c
diff -u src/sys/kern/vfs_xattr.c:1.25 src/sys/kern/vfs_xattr.c:1.26
--- src/sys/kern/vfs_xattr.c:1.25	Tue Jun 28 07:50:03 2011
+++ src/sys/kern/vfs_xattr.c	Wed Jun 29 08:01:14 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_xattr.c,v 1.25 2011/06/28 07:50:03 manu Exp $	*/
+/*	$NetBSD: vfs_xattr.c,v 1.26 2011/06/29 08:01:14 manu Exp $	*/
 
 /*-
  * Copyright (c) 2005, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: vfs_xattr.c,v 1.25 2011/06/28 07:50:03 manu Exp $);
+__KERNEL_RCSID(0, $NetBSD: vfs_xattr.c,v 1.26 2011/06/29 08:01:14 manu Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -794,7 +794,7 @@
 	error = namei_simple_user(SCARG(uap, path),
 NSM_FOLLOW_NOEMULROOT, vp);
 	if (error)
-		goto out_rele;
+		goto out;
 
 	namespace = xattr_native(attrname);
 
@@ -802,7 +802,6 @@
 	attrname, SCARG(uap, value), SCARG(uap, size), l, 
 	attrlen, SCARG(uap, flags));
 
-out_rele:
 	vrele(vp);
 out:
 	*retval = (error == 0) ? 0 : -1;
@@ -833,7 +832,7 @@
 	error = namei_simple_user(SCARG(uap, path),
 NSM_NOFOLLOW_NOEMULROOT, vp);
 	if (error)
-		goto out_rele;
+		goto out;
 
 	namespace = xattr_native(attrname);
 
@@ -841,7 +840,6 @@
 	attrname, SCARG(uap, value), SCARG(uap, size), l,
 	attrlen, SCARG(uap, flags));
 
-out_rele:
 	vrele(vp);
 out:
 	*retval = (error == 0) ? 0 : -1;



CVS commit: src/usr.bin/extattr

2011-06-28 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue Jun 28 07:24:15 UTC 2011

Modified Files:
src/usr.bin/extattr: getextattr.c

Log Message:
Fix previous broken commit for extended attribute listing.


To generate a diff of this commit:
cvs rdiff -u -r1.5 -r1.6 src/usr.bin/extattr/getextattr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/extattr/getextattr.c
diff -u src/usr.bin/extattr/getextattr.c:1.5 src/usr.bin/extattr/getextattr.c:1.6
--- src/usr.bin/extattr/getextattr.c:1.5	Mon Jun 27 16:34:48 2011
+++ src/usr.bin/extattr/getextattr.c	Tue Jun 28 07:24:14 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: getextattr.c,v 1.5 2011/06/27 16:34:48 manu Exp $	*/
+/*	$NetBSD: getextattr.c,v 1.6 2011/06/28 07:24:14 manu Exp $	*/
 
 /*-
  * Copyright (c) 2002, 2003 Networks Associates Technology, Inc.
@@ -237,8 +237,8 @@
 break;
 			if (!flag_quiet)
 printf(%s\t, argv[arg_counter]);
-			for (i = 0; i  error; i += buf[i] + 1)
-			printf(%s%s, i ? \t : , buf + i + 1);
+			for (i = 0; i  error; i += strlen(buf + i) + 1)
+			printf(%s%s, i ? \t : , buf + i);
 			printf(\n);
 			continue;
 		case EAGET:



CVS commit: src/sys/kern

2011-06-28 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue Jun 28 07:50:03 UTC 2011

Modified Files:
src/sys/kern: vfs_xattr.c

Log Message:
Improve a bit listxattr(2). It attemps to list both system and user
extended attributes, and it faled if calling user did not have privilege
for reading system EA. Now we just lise user EA and skip system EA in
reading them is not allowed.


To generate a diff of this commit:
cvs rdiff -u -r1.24 -r1.25 src/sys/kern/vfs_xattr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/vfs_xattr.c
diff -u src/sys/kern/vfs_xattr.c:1.24 src/sys/kern/vfs_xattr.c:1.25
--- src/sys/kern/vfs_xattr.c:1.24	Mon Jun 27 16:39:43 2011
+++ src/sys/kern/vfs_xattr.c	Tue Jun 28 07:50:03 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: vfs_xattr.c,v 1.24 2011/06/27 16:39:43 manu Exp $	*/
+/*	$NetBSD: vfs_xattr.c,v 1.25 2011/06/28 07:50:03 manu Exp $	*/
 
 /*-
  * Copyright (c) 2005, 2008 The NetBSD Foundation, Inc.
@@ -68,7 +68,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: vfs_xattr.c,v 1.24 2011/06/27 16:39:43 manu Exp $);
+__KERNEL_RCSID(0, $NetBSD: vfs_xattr.c,v 1.25 2011/06/28 07:50:03 manu Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -1021,8 +1021,17 @@
 
 	error = extattr_list_vp(vp, EXTATTR_NAMESPACE_SYSTEM,
 	list, size, l, listsize_sys);
-	if (error)
+	switch (error) {
+	case EPERM:
+		error = 0; /* Ignore and just skip system EA */
+		listsize_sys = 0;
+		break;
+	case 0:
+		break;
+	default: 
 		goto out;
+		break;
+	}
 
 	*retval = listsize_usr + listsize_sys; 	
 
@@ -1065,8 +1074,17 @@
 
 	error = extattr_list_vp(vp, EXTATTR_NAMESPACE_SYSTEM,
 	list, size, l, listsize_sys);
-	if (error)
+	switch (error) {
+	case EPERM:
+		error = 0; /* Ignore and just skip system EA */
+		listsize_sys = 0;
+		break;
+	case 0:
+		break;
+	default: 
 		goto out;
+		break;
+	}
 
 	*retval = listsize_usr + listsize_sys; 	
 out:
@@ -1109,8 +1127,17 @@
 
 	error = extattr_list_vp(vp, EXTATTR_NAMESPACE_SYSTEM,
 	list, size, l, listsize_sys);
-	if (error)
+	switch (error) {
+	case EPERM:
+		error = 0; /* Ignore and just skip system EA */
+		listsize_sys = 0;
+		break;
+	case 0:
+		break;
+	default: 
 		goto out;
+		break;
+	}
 
 	*retval = listsize_usr + listsize_sys; 	
 out:



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 linux/limits.h */
+#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 puffs.h
 #include sys/socket.h
 #include sys/socket.h
+#include sys/extattr.h
 #include machine/vmparam.h
 
 #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

CVS commit: src/lib/libpuffs

2011-06-27 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon Jun 27 12:06:20 UTC 2011

Modified Files:
src/lib/libpuffs: null.c

Log Message:
From Evgeniy Ivanov: puffs_node_readdir() should set eofflag to one, when
end-of-directory is reached.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/lib/libpuffs/null.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/libpuffs/null.c
diff -u src/lib/libpuffs/null.c:1.29 src/lib/libpuffs/null.c:1.30
--- src/lib/libpuffs/null.c:1.29	Fri Jun 24 16:59:29 2011
+++ src/lib/libpuffs/null.c	Mon Jun 27 12:06:19 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: null.c,v 1.29 2011/06/24 16:59:29 manu Exp $	*/
+/*	$NetBSD: null.c,v 1.30 2011/06/27 12:06:19 manu Exp $	*/
 
 /*
  * Copyright (c) 2007  Antti Kantee.  All Rights Reserved.
@@ -27,7 +27,7 @@
 
 #include sys/cdefs.h
 #if !defined(lint)
-__RCSID($NetBSD: null.c,v 1.29 2011/06/24 16:59:29 manu Exp $);
+__RCSID($NetBSD: null.c,v 1.30 2011/06/27 12:06:19 manu Exp $);
 #endif /* !lint */
 
 /*
@@ -578,8 +578,13 @@
 	 */
 	while (i--) {
 		rv = readdir_r(dp, entry, result);
-		if (rv || !result)
+		if (rv != 0)
+			goto out;
+
+		if (!result) {
+			*eofflag = 1;
 			goto out;
+		}
 	}
 
 	for (;;) {



CVS commit: src

2011-06-27 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon Jun 27 16:34:48 UTC 2011

Modified Files:
src/sys/ufs/ffs: ffs_vnops.c
src/sys/ufs/ufs: ufs_extattr.c
src/usr.bin/extattr: getextattr.c

Log Message:
Implement extended attribute listing for UFS1.

Modify lsextattr(8) so that it does not expect each attribute name to be
prefixed by its length. This enable extattr_list_(file|link|fd) to
return a buffer matching its documentation. This also makes the interface
similar to what Linux and FUSE do, which is nice for interoperability.

Note that since we had no EA implementation supporting listing, we do
not break anything.


To generate a diff of this commit:
cvs rdiff -u -r1.119 -r1.120 src/sys/ufs/ffs/ffs_vnops.c
cvs rdiff -u -r1.32 -r1.33 src/sys/ufs/ufs/ufs_extattr.c
cvs rdiff -u -r1.4 -r1.5 src/usr.bin/extattr/getextattr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ffs/ffs_vnops.c
diff -u src/sys/ufs/ffs/ffs_vnops.c:1.119 src/sys/ufs/ffs/ffs_vnops.c:1.120
--- src/sys/ufs/ffs/ffs_vnops.c:1.119	Sun Jun 12 03:36:00 2011
+++ src/sys/ufs/ffs/ffs_vnops.c	Mon Jun 27 16:34:47 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ffs_vnops.c,v 1.119 2011/06/12 03:36:00 rmind Exp $	*/
+/*	$NetBSD: ffs_vnops.c,v 1.120 2011/06/27 16:34:47 manu Exp $	*/
 
 /*-
  * Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ffs_vnops.c,v 1.119 2011/06/12 03:36:00 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: ffs_vnops.c,v 1.120 2011/06/27 16:34:47 manu Exp $);
 
 #if defined(_KERNEL_OPT)
 #include opt_ffs.h
@@ -736,9 +736,19 @@
 	struct inode *ip = VTOI(ap-a_vp);
 	struct fs *fs = ip-i_fs;
 
-	/* Not supported for UFS1 file systems. */
-	if (fs-fs_magic == FS_UFS1_MAGIC)
+	if (fs-fs_magic == FS_UFS1_MAGIC) {
+#ifdef UFS_EXTATTR
+		struct vnode *vp = ap-a_vp;
+		int error;
+
+		fstrans_start(vp-v_mount, FSTRANS_SHARED);
+		error = ufs_listextattr(ap);
+		fstrans_done(vp-v_mount);
+		return error;
+#else
 		return (EOPNOTSUPP);
+#endif
+	}
 
 	/* XXX Not implemented for UFS2 file systems. */
 	return (EOPNOTSUPP);

Index: src/sys/ufs/ufs/ufs_extattr.c
diff -u src/sys/ufs/ufs/ufs_extattr.c:1.32 src/sys/ufs/ufs/ufs_extattr.c:1.33
--- src/sys/ufs/ufs/ufs_extattr.c:1.32	Fri Jun 17 14:23:52 2011
+++ src/sys/ufs/ufs/ufs_extattr.c	Mon Jun 27 16:34:47 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_extattr.c,v 1.32 2011/06/17 14:23:52 manu Exp $	*/
+/*	$NetBSD: ufs_extattr.c,v 1.33 2011/06/27 16:34:47 manu Exp $	*/
 
 /*-
  * Copyright (c) 1999-2002 Robert N. M. Watson
@@ -48,7 +48,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_extattr.c,v 1.32 2011/06/17 14:23:52 manu Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_extattr.c,v 1.33 2011/06/27 16:34:47 manu Exp $);
 
 #ifdef _KERNEL_OPT
 #include opt_ffs.h
@@ -95,6 +95,9 @@
 static int	ufs_extattr_get(struct vnode *vp, int attrnamespace,
 		const char *name, struct uio *uio, size_t *size,
 		kauth_cred_t cred, struct lwp *l);
+static int	ufs_extattr_list(struct vnode *vp, int attrnamespace,
+		struct uio *uio, size_t *size,
+		kauth_cred_t cred, struct lwp *l);
 static int	ufs_extattr_set(struct vnode *vp, int attrnamespace,
 		const char *name, struct uio *uio, kauth_cred_t cred,
 		struct lwp *l);
@@ -102,6 +105,9 @@
 		const char *name, kauth_cred_t cred, struct lwp *l);
 static struct ufs_extattr_list_entry *ufs_extattr_find_attr(struct ufsmount *,
 		int, const char *);
+static int	ufs_extattr_get_header(struct vnode *, 
+		struct ufs_extattr_list_entry *, 
+		struct ufs_extattr_header *, off_t *);
 
 /*
  * Per-FS attribute lock protecting attribute operations.
@@ -925,6 +931,86 @@
 }
 
 /*
+ * Read extended attribute header for a given vnode and attribute.
+ * Backing vnode should be locked and unlocked by caller.
+ */
+static int
+ufs_extattr_get_header(struct vnode *vp, struct ufs_extattr_list_entry *uele,
+struct ufs_extattr_header *ueh, off_t *bap)
+{
+	struct mount *mp = vp-v_mount;
+	struct ufsmount *ump = VFSTOUFS(mp);
+	struct inode *ip = VTOI(vp);
+	off_t base_offset;
+	struct iovec aiov;
+	struct uio aio;
+	int error;
+
+	/*
+	 * Find base offset of header in file based on file header size, and
+	 * data header size + maximum data size, indexed by inode number.
+	 */
+	base_offset = sizeof(struct ufs_extattr_fileheader) +
+	ip-i_number * (sizeof(struct ufs_extattr_header) +
+	uele-uele_fileheader.uef_size);
+
+	/*
+	 * Read in the data header to see if the data is defined, and if so
+	 * how much.
+	 */
+	memset(ueh, 0, sizeof(struct ufs_extattr_header));
+	aiov.iov_base = ueh;
+	aiov.iov_len = sizeof(struct ufs_extattr_header);
+	aio.uio_iov = aiov;
+	aio.uio_iovcnt = 1;
+	aio.uio_rw = UIO_READ;
+	aio.uio_offset = base_offset;
+	aio.uio_resid = sizeof(struct ufs_extattr_header);
+	UIO_SETUP_SYSSPACE(aio);
+
+	error = 

CVS commit: src/lib/libpuffs

2011-06-24 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Fri Jun 24 16:59:29 UTC 2011

Modified Files:
src/lib/libpuffs: null.c

Log Message:
Commit fix for misc/45029.
Approved by pooka@


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/lib/libpuffs/null.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/libpuffs/null.c
diff -u src/lib/libpuffs/null.c:1.28 src/lib/libpuffs/null.c:1.29
--- src/lib/libpuffs/null.c:1.28	Sun Oct 18 20:14:06 2009
+++ src/lib/libpuffs/null.c	Fri Jun 24 16:59:29 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: null.c,v 1.28 2009/10/18 20:14:06 pooka Exp $	*/
+/*	$NetBSD: null.c,v 1.29 2011/06/24 16:59:29 manu Exp $	*/
 
 /*
  * Copyright (c) 2007  Antti Kantee.  All Rights Reserved.
@@ -27,7 +27,7 @@
 
 #include sys/cdefs.h
 #if !defined(lint)
-__RCSID($NetBSD: null.c,v 1.28 2009/10/18 20:14:06 pooka Exp $);
+__RCSID($NetBSD: null.c,v 1.29 2011/06/24 16:59:29 manu Exp $);
 #endif /* !lint */
 
 /*
@@ -410,21 +410,36 @@
 	struct puffs_node *pn = opc;
 	int fd, rv;
 	int fflags;
+	struct stat sb;
 
 	rv = 0;
-	fd = writeableopen(PNPATH(pn));
-	if (fd == -1)
+	if (stat(PNPATH(pn), sb) == -1)
 		return errno;
+	if (S_ISDIR(sb.st_mode)) {
+		DIR *dirp;
+		if ((dirp = opendir(PNPATH(pn))) == 0)
+			return errno;
+		fd = dirfd(dirp);
+		if (fd == -1)
+			return errno;
 
-	if (how  PUFFS_FSYNC_DATAONLY)
-		fflags = FDATASYNC;
-	else
-		fflags = FFILESYNC;
-	if (how  PUFFS_FSYNC_CACHE)
-		fflags |= FDISKSYNC;
+		if (fsync(fd) == -1)
+			rv = errno;
+	} else {
+		fd = writeableopen(PNPATH(pn));
+		if (fd == -1)
+			return errno;
 
-	if (fsync_range(fd, fflags, offlo, offhi - offlo) == -1)
-		rv = errno;
+		if (how  PUFFS_FSYNC_DATAONLY)
+			fflags = FDATASYNC;
+		else
+			fflags = FFILESYNC;
+		if (how  PUFFS_FSYNC_CACHE)
+			fflags |= FDISKSYNC;
+
+		if (fsync_range(fd, fflags, offlo, offhi - offlo) == -1)
+			rv = errno;
+	}
 
 	close(fd);
 



CVS commit: src

2011-06-17 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Fri Jun 17 14:23:52 UTC 2011

Modified Files:
src/include: mntopts.h
src/lib/libc/sys: mount.2
src/sbin/mount: mount.8
src/sbin/mount_ffs: mount_ffs.c
src/share/man/man4: options.4
src/sys/kern: vfs_syscalls.c
src/sys/sys: extattr.h fstypes.h statvfs.h
src/sys/ufs/ffs: ffs_extern.h ffs_vfsops.c
src/sys/ufs/ufs: extattr.h ufs_extattr.c
src/usr.sbin/extattrctl: extattrctl.8

Log Message:
Add mount -o extattr option to enable extended attributs (corrently only
for UFS1).
Remove kernel option for EA backing store autocreation and do it by
default. Add a sysctl so that autocreated attriutr size can be modified.


To generate a diff of this commit:
cvs rdiff -u -r1.13 -r1.14 src/include/mntopts.h
cvs rdiff -u -r1.45 -r1.46 src/lib/libc/sys/mount.2
cvs rdiff -u -r1.70 -r1.71 src/sbin/mount/mount.8
cvs rdiff -u -r1.25 -r1.26 src/sbin/mount_ffs/mount_ffs.c
cvs rdiff -u -r1.406 -r1.407 src/share/man/man4/options.4
cvs rdiff -u -r1.429 -r1.430 src/sys/kern/vfs_syscalls.c
cvs rdiff -u -r1.4 -r1.5 src/sys/sys/extattr.h
cvs rdiff -u -r1.28 -r1.29 src/sys/sys/fstypes.h
cvs rdiff -u -r1.15 -r1.16 src/sys/sys/statvfs.h
cvs rdiff -u -r1.77 -r1.78 src/sys/ufs/ffs/ffs_extern.h
cvs rdiff -u -r1.267 -r1.268 src/sys/ufs/ffs/ffs_vfsops.c
cvs rdiff -u -r1.8 -r1.9 src/sys/ufs/ufs/extattr.h
cvs rdiff -u -r1.31 -r1.32 src/sys/ufs/ufs/ufs_extattr.c
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/extattrctl/extattrctl.8

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/include/mntopts.h
diff -u src/include/mntopts.h:1.13 src/include/mntopts.h:1.14
--- src/include/mntopts.h:1.13	Mon Jan 12 18:14:20 2009
+++ src/include/mntopts.h	Fri Jun 17 14:23:50 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: mntopts.h,v 1.13 2009/01/12 18:14:20 pooka Exp $	*/
+/*	$NetBSD: mntopts.h,v 1.14 2011/06/17 14:23:50 manu Exp $	*/
 
 /*-
  * Copyright (c) 1994
@@ -57,6 +57,7 @@
 #define MOPT_SOFTDEP		{ softdep,	0, MNT_SOFTDEP, 0 }
 #define MOPT_LOG		{ log,	0, MNT_LOG, 0 }
 #define MOPT_IGNORE		{ hidden,	0, MNT_IGNORE, 0 }
+#define MOPT_EXTATTR		{ extattr,	0, MNT_EXTATTR, 0 }
 
 /* Control flags. */
 #define MOPT_FORCE		{ force,	0, MNT_FORCE, 0 }

Index: src/lib/libc/sys/mount.2
diff -u src/lib/libc/sys/mount.2:1.45 src/lib/libc/sys/mount.2:1.46
--- src/lib/libc/sys/mount.2:1.45	Mon May 31 12:16:20 2010
+++ src/lib/libc/sys/mount.2	Fri Jun 17 14:23:50 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: mount.2,v 1.45 2010/05/31 12:16:20 njoly Exp $
+.\	$NetBSD: mount.2,v 1.46 2011/06/17 14:23:50 manu Exp $
 .\
 .\ Copyright (c) 1980, 1989, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -119,6 +119,9 @@
 filesystem, creating a record of meta-data writes to be
 performed, allowing the actual writes to be deferred.
 This improves performance in most cases.
+.It MNT_EXTATTR
+Enable extended attributes, if the filesystem supports them and do not enable
+them by default. Currently this is only the case for UFS1. 
 .El
 .Pp
 The

Index: src/sbin/mount/mount.8
diff -u src/sbin/mount/mount.8:1.70 src/sbin/mount/mount.8:1.71
--- src/sbin/mount/mount.8:1.70	Sun Nov 21 18:33:08 2010
+++ src/sbin/mount/mount.8	Fri Jun 17 14:23:51 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: mount.8,v 1.70 2010/11/21 18:33:08 pooka Exp $
+.\	$NetBSD: mount.8,v 1.71 2011/06/17 14:23:51 manu Exp $
 .\
 .\ Copyright (c) 1980, 1989, 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -190,6 +190,9 @@
 Clear
 .Cm async
 mode.
+.It Cm extattr
+Enable extended attributes, if the filesystem supports them and do not enable
+them by default. Currently this is only the case for UFS1.
 .It Cm force
 The same as
 .Fl f ;

Index: src/sbin/mount_ffs/mount_ffs.c
diff -u src/sbin/mount_ffs/mount_ffs.c:1.25 src/sbin/mount_ffs/mount_ffs.c:1.26
--- src/sbin/mount_ffs/mount_ffs.c:1.25	Tue Aug  5 20:57:45 2008
+++ src/sbin/mount_ffs/mount_ffs.c	Fri Jun 17 14:23:51 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: mount_ffs.c,v 1.25 2008/08/05 20:57:45 pooka Exp $	*/
+/*	$NetBSD: mount_ffs.c,v 1.26 2011/06/17 14:23:51 manu Exp $	*/
 
 /*-
  * Copyright (c) 1993, 1994
@@ -39,7 +39,7 @@
 #if 0
 static char sccsid[] = @(#)mount_ufs.c	8.4 (Berkeley) 4/26/95;
 #else
-__RCSID($NetBSD: mount_ffs.c,v 1.25 2008/08/05 20:57:45 pooka Exp $);
+__RCSID($NetBSD: mount_ffs.c,v 1.26 2011/06/17 14:23:51 manu Exp $);
 #endif
 #endif /* not lint */
 
@@ -74,6 +74,7 @@
 	MOPT_SOFTDEP,
 	MOPT_LOG,
 	MOPT_GETARGS,
+	MOPT_EXTATTR,
 	MOPT_NULL,
 };
 

Index: src/share/man/man4/options.4
diff -u src/share/man/man4/options.4:1.406 src/share/man/man4/options.4:1.407
--- src/share/man/man4/options.4:1.406	Tue Jun  7 20:23:14 2011
+++ src/share/man/man4/options.4	Fri Jun 17 14:23:51 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: options.4,v 1.406 2011/06/07 20:23:14 wiz Exp $
+.\	$NetBSD: options.4,v 1.407 2011/06/17 14:23:51 manu 

CVS commit: src/sys/ufs/ufs

2011-06-15 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Wed Jun 15 12:54:32 UTC 2011

Modified Files:
src/sys/ufs/ufs: ufs_extattr.c

Log Message:
Improve UFS1 extended attributes usability
- autocreate attribute backing file for new attributes
- autoload attributes when issuing extattrctl start
- when autoloading attributes, do not display garbage warning when looking
up entries that got ENOENT


To generate a diff of this commit:
cvs rdiff -u -r1.30 -r1.31 src/sys/ufs/ufs/ufs_extattr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ufs/ufs_extattr.c
diff -u src/sys/ufs/ufs/ufs_extattr.c:1.30 src/sys/ufs/ufs/ufs_extattr.c:1.31
--- src/sys/ufs/ufs/ufs_extattr.c:1.30	Sun Jun 12 03:36:02 2011
+++ src/sys/ufs/ufs/ufs_extattr.c	Wed Jun 15 12:54:32 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_extattr.c,v 1.30 2011/06/12 03:36:02 rmind Exp $	*/
+/*	$NetBSD: ufs_extattr.c,v 1.31 2011/06/15 12:54:32 manu Exp $	*/
 
 /*-
  * Copyright (c) 1999-2002 Robert N. M. Watson
@@ -48,7 +48,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_extattr.c,v 1.30 2011/06/12 03:36:02 rmind Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_extattr.c,v 1.31 2011/06/15 12:54:32 manu Exp $);
 
 #ifdef _KERNEL_OPT
 #include opt_ffs.h
@@ -99,6 +99,8 @@
 		struct lwp *l);
 static int	ufs_extattr_rm(struct vnode *vp, int attrnamespace,
 		const char *name, kauth_cred_t cred, struct lwp *l);
+static struct ufs_extattr_list_entry *ufs_extattr_find_attr(struct ufsmount *,
+		int, const char *);
 
 /*
  * Per-FS attribute lock protecting attribute operations.
@@ -147,6 +149,142 @@
 	return (1);
 }
 
+#ifdef UFS_EXTATTR_AUTOCREATE
+/*
+ * Autocreate an attribute storage
+ */
+static struct ufs_extattr_list_entry *
+ufs_extattr_autocreate_attr(struct vnode *vp, int attrnamespace,
+const char *attrname, struct lwp *l)
+{
+	struct mount *mp = vp-v_mount;
+	struct ufsmount *ump = VFSTOUFS(mp);
+	struct vnode *backing_vp;
+	struct nameidata nd;
+	struct pathbuf *pb;
+	char *path;
+	struct ufs_extattr_fileheader uef;
+	struct ufs_extattr_list_entry *uele;
+	int error;
+
+	path = PNBUF_GET();
+
+	/* 
+	 * We only support system and user namespace autocreation
+	 */ 
+	switch (attrnamespace) {
+	case EXTATTR_NAMESPACE_SYSTEM:
+		(void)snprintf(path, PATH_MAX, %s/%s/%s/%s, 
+			   mp-mnt_stat.f_mntonname,
+			   UFS_EXTATTR_FSROOTSUBDIR,
+			   UFS_EXTATTR_SUBDIR_SYSTEM,
+			   attrname);
+		break;
+	case EXTATTR_NAMESPACE_USER:
+		(void)snprintf(path, PATH_MAX, %s/%s/%s/%s, 
+			   mp-mnt_stat.f_mntonname,
+			   UFS_EXTATTR_FSROOTSUBDIR,
+			   UFS_EXTATTR_SUBDIR_USER,
+			   attrname);
+		break;
+	default:
+		PNBUF_PUT(path);
+		return NULL;
+		break;
+	}
+
+	/*
+	 * When setting attribute on the root vnode, we get it 
+	 * already locked, and vn_open/namei/VFS_ROOT will try to
+	 * look it, causing a panic. Unlock it first.
+	 */ 
+	if (vp-v_vflag  VV_ROOT) {
+		KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
+		VOP_UNLOCK(vp);
+	}
+	KASSERT(VOP_ISLOCKED(vp) == 0);
+
+	pb = pathbuf_create(path);
+	NDINIT(nd, CREATE, LOCKPARENT, pb);
+	
+	error = vn_open(nd, O_CREAT|O_RDWR, 0600);
+
+	/*
+	 * Reacquire the lock on the vnode if it was root.
+	 */
+	KASSERT(VOP_ISLOCKED(vp) == 0);
+	if (vp-v_vflag  VV_ROOT)
+		vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
+	KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
+
+	if (error != 0) {
+		pathbuf_destroy(pb);
+		PNBUF_PUT(path);
+		return NULL;
+	}
+
+	KASSERT(nd.ni_vp != NULL);
+	KASSERT(VOP_ISLOCKED(nd.ni_vp) == LK_EXCLUSIVE);
+	KASSERT(VOP_ISLOCKED(nd.ni_dvp) == 0);
+
+	/*
+ 	 * backing_vp is the backing store. 
+	 */	
+	backing_vp = nd.ni_vp;
+	pathbuf_destroy(pb);
+	PNBUF_PUT(path);
+
+	uef.uef_magic = UFS_EXTATTR_MAGIC;
+	uef.uef_version = UFS_EXTATTR_VERSION;
+	uef.uef_size = UFS_EXTATTR_AUTOCREATE;
+
+	error = vn_rdwr(UIO_WRITE, backing_vp, uef, sizeof(uef), 0,
+		UIO_SYSSPACE, IO_NODELOCKED|IO_APPEND, 
+			l-l_cred, NULL, l);
+
+	VOP_UNLOCK(backing_vp);
+
+	if (error != 0) {
+		printf(%s: write uef header failed for %s, error = %d\n, 
+		   __func__, attrname, error);
+		vn_close(backing_vp, FREAD|FWRITE, l-l_cred);
+		return NULL;
+	}
+
+	/*
+	 * ufs_extattr_enable_with_open increases the vnode reference
+	 * count. Not sure why, but do the same here.
+	 */
+	vref(vp);
+
+	/*
+	 * Now enable attribute. 
+	 */
+	error = ufs_extattr_enable(ump,attrnamespace, attrname, backing_vp, l);
+	KASSERT(VOP_ISLOCKED(backing_vp) == 0);
+
+	if (error != 0) {
+		printf(%s: enable %s failed, error %d\n, 
+		   __func__, attrname, error);
+		vn_close(backing_vp, FREAD|FWRITE, l-l_cred);
+		return NULL;
+	}
+
+	uele = ufs_extattr_find_attr(ump, attrnamespace, attrname);
+	if (uele == NULL) {
+		printf(%s: atttribute %s created but not found!\n,
+		   __func__, attrname);
+		vn_close(backing_vp, FREAD|FWRITE, l-l_cred);
+		return NULL;
+	}
+
+	printf(%s: EA 

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-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

2011-05-30 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon May 30 14:50:08 UTC 2011

Modified Files:
src/lib/libperfuse: ops.c perfuse.c perfuse_if.h perfuse_priv.h
src/usr.sbin/perfused: msg.c perfused.c perfused.h

Log Message:
Use SOCK_SEQPACKET in perfuse if available. This fix file operations hangs
where the FUSE filesyste replied to an operation and got an ENOBUFS it did
not handle.

We now are also able to cleanly unmount


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.14 -r1.15 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.12 -r1.13 src/lib/libperfuse/perfuse_if.h
cvs rdiff -u -r1.17 -r1.18 src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.12 -r1.13 src/usr.sbin/perfused/msg.c \
src/usr.sbin/perfused/perfused.c
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/perfused/perfused.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.27 src/lib/libperfuse/ops.c:1.28
--- src/lib/libperfuse/ops.c:1.27	Wed May 18 15:28:12 2011
+++ src/lib/libperfuse/ops.c	Mon May 30 14:50:08 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.27 2011/05/18 15:28:12 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.28 2011/05/30 14:50:08 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -844,9 +844,12 @@
 			goto out;
 	}
 
-	DPRINTF(%s unmounted, exit\n, ps-ps_target);
+	ps-ps_umount(pu);
 
-	exit(0);
+	if (perfuse_diagflags  PDF_MISC)
+		DPRINTF(%s unmounted, exit\n, ps-ps_target);
+
+	return 0;
 out:
 	ps-ps_destroy_msg(pm);
 	

Index: src/lib/libperfuse/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.14 src/lib/libperfuse/perfuse.c:1.15
--- src/lib/libperfuse/perfuse.c:1.14	Wed May 18 15:25:19 2011
+++ src/lib/libperfuse/perfuse.c	Mon May 30 14:50:08 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.14 2011/05/18 15:25:19 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.15 2011/05/30 14:50:08 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -148,15 +148,25 @@
 	char *const argv[] = { progname, minus_i, fdstr, NULL};
 	uint32_t opt;
 	uint32_t optlen;
+	int sock_type = SOCK_SEQPACKET;
 
 	if (strcmp(path, _PATH_FUSE) != 0)
 		return open(path, flags, mode);
 
-	if ((sv[0] = socket(PF_LOCAL, SOCK_DGRAM, 0)) == -1) {
+	/* 
+	 * Try SOCK_SEQPACKET then SOCK_DGRAM if unavailable
+	 */
+	if ((sv[0] = socket(PF_LOCAL, SOCK_SEQPACKET, 0)) == -1) {
+		sock_type = SOCK_DGRAM;
+DWARNX(SEQPACKET local sockets unavailable, using less 
+		   reliable DGRAM sockets. Expect file operation hangs.);
+
+		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: %s, __func__, __LINE__);
 #endif
-		return -1;
+			return -1;
+		}
 	}
 
 	/*
@@ -178,17 +188,16 @@
 	sun.sun_family = AF_LOCAL;
 	(void)strcpy(sun.sun_path, path);
 
-	if (connect(sv[0], sa, (socklen_t)sun.sun_len) == 0) 
+	if (connect(sv[0], sa, (socklen_t)sun.sun_len) == 0)
 		return sv[0];
 
-
 	/*
 	 * Attempt to run perfused on our own
 	 * if it does not run yet; In that case
 	 * we will talk using a socketpair 
 	 * instead of /dev/fuse.
 	 */
-	if (socketpair(PF_LOCAL, SOCK_DGRAM, 0, sv) != 0) {
+	if (socketpair(PF_LOCAL, sock_type, 0, sv) != 0) {
 		DWARN(%s:%d: socketpair failed, __func__, __LINE__);
 		return -1;
 	}
@@ -510,6 +519,7 @@
 	ps-ps_get_inpayload = pc-pc_get_inpayload;
 	ps-ps_get_outhdr = pc-pc_get_outhdr;
 	ps-ps_get_outpayload = pc-pc_get_outpayload;
+	ps-ps_umount = pc-pc_umount;
 
 	return pu;
 } 
@@ -558,12 +568,15 @@
 	ps = puffs_getspecific(pu);
 
 	ps-ps_flags |= PS_INLOOP;
-	if (puffs_mainloop(ps-ps_pu) != 0)
+	if (puffs_mainloop(ps-ps_pu) != 0) {
 		DERR(EX_OSERR, puffs_mainloop failed);
-	DERR(EX_OSERR, puffs_mainloop exit);
+		return -1;
+	}
 
-	/* NOTREACHED */
-	return -1;
+	/* 
+	 * Normal exit after unmount
+	 */
+	return 0;
 }
 
 /* ARGSUSED0 */

Index: src/lib/libperfuse/perfuse_if.h
diff -u src/lib/libperfuse/perfuse_if.h:1.12 src/lib/libperfuse/perfuse_if.h:1.13
--- src/lib/libperfuse/perfuse_if.h:1.12	Wed May 18 15:22:54 2011
+++ src/lib/libperfuse/perfuse_if.h	Mon May 30 14:50:08 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_if.h,v 1.12 2011/05/18 15:22:54 manu Exp $ */
+/*  $NetBSD: perfuse_if.h,v 1.13 2011/05/30 14:50:08 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -134,6 +134,7 @@
 typedef struct fuse_in_header *(*perfuse_get_inhdr_fn)(perfuse_msg_t *);
 typedef char *(*perfuse_get_inpayload_fn)(perfuse_msg_t *);
 typedef char *(*perfuse_get_outpayload_fn)(perfuse_msg_t *);
+typedef void (*perfuse_umount_fn)(struct puffs_usermount *);
 
 struct perfuse_callbacks {
 	perfuse_new_msg_fn pc_new_msg;
@@ -143,6 +144,7 @@
 	perfuse_get_inpayload_fn pc_get_inpayload;
 	perfuse_get_outhdr_fn

CVS commit: src/sys/kern

2011-05-28 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sun May 29 03:32:46 UTC 2011

Modified Files:
src/sys/kern: uipc_domain.c uipc_proto.c uipc_usrreq.c

Log Message:
Add SOCK_SEQPACKET to PL_LOCAL sockets. Based on patch from Jesse Off,
submitted 8 years ago:
http://mail-index.netbsd.org/tech-kern/2003/04/14/0006.html


To generate a diff of this commit:
cvs rdiff -u -r1.85 -r1.86 src/sys/kern/uipc_domain.c
cvs rdiff -u -r1.21 -r1.22 src/sys/kern/uipc_proto.c
cvs rdiff -u -r1.133 -r1.134 src/sys/kern/uipc_usrreq.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/uipc_domain.c
diff -u src/sys/kern/uipc_domain.c:1.85 src/sys/kern/uipc_domain.c:1.86
--- src/sys/kern/uipc_domain.c:1.85	Sat Oct  3 20:24:39 2009
+++ src/sys/kern/uipc_domain.c	Sun May 29 03:32:46 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_domain.c,v 1.85 2009/10/03 20:24:39 elad Exp $	*/
+/*	$NetBSD: uipc_domain.c,v 1.86 2011/05/29 03:32:46 manu Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: uipc_domain.c,v 1.85 2009/10/03 20:24:39 elad Exp $);
+__KERNEL_RCSID(0, $NetBSD: uipc_domain.c,v 1.86 2011/05/29 03:32:46 manu Exp $);
 
 #include sys/param.h
 #include sys/socket.h
@@ -518,6 +518,12 @@
 		   CTL_NET, PF_LOCAL, SOCK_STREAM, CTL_EOL);
 	sysctl_createv(domain_sysctllog, 0, NULL, NULL,
 		   CTLFLAG_PERMANENT,
+		   CTLTYPE_NODE, seqpacket,
+		   SYSCTL_DESCR(SOCK_SEQPACKET settings),
+		   NULL, 0, NULL, 0,
+		   CTL_NET, PF_LOCAL, SOCK_SEQPACKET, CTL_EOL);
+	sysctl_createv(domain_sysctllog, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT,
 		   CTLTYPE_NODE, dgram,
 		   SYSCTL_DESCR(SOCK_DGRAM settings),
 		   NULL, 0, NULL, 0,
@@ -532,6 +538,13 @@
 	sysctl_createv(domain_sysctllog, 0, NULL, NULL,
 		   CTLFLAG_PERMANENT,
 		   CTLTYPE_STRUCT, pcblist,
+		   SYSCTL_DESCR(SOCK_SEQPACKET protocol control 
+block list),
+		   sysctl_unpcblist, 0, NULL, 0,
+		   CTL_NET, PF_LOCAL, SOCK_SEQPACKET, CTL_CREATE, CTL_EOL);
+	sysctl_createv(domain_sysctllog, 0, NULL, NULL,
+		   CTLFLAG_PERMANENT,
+		   CTLTYPE_STRUCT, pcblist,
 		   SYSCTL_DESCR(SOCK_DGRAM protocol control block list),
 		   sysctl_unpcblist, 0, NULL, 0,
 		   CTL_NET, PF_LOCAL, SOCK_DGRAM, CTL_CREATE, CTL_EOL);

Index: src/sys/kern/uipc_proto.c
diff -u src/sys/kern/uipc_proto.c:1.21 src/sys/kern/uipc_proto.c:1.22
--- src/sys/kern/uipc_proto.c:1.21	Thu Apr 24 11:38:36 2008
+++ src/sys/kern/uipc_proto.c	Sun May 29 03:32:46 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_proto.c,v 1.21 2008/04/24 11:38:36 ad Exp $	*/
+/*	$NetBSD: uipc_proto.c,v 1.22 2011/05/29 03:32:46 manu Exp $	*/
 
 /*-
  * Copyright (c) 1982, 1986, 1993
@@ -32,7 +32,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: uipc_proto.c,v 1.21 2008/04/24 11:38:36 ad Exp $);
+__KERNEL_RCSID(0, $NetBSD: uipc_proto.c,v 1.22 2011/05/29 03:32:46 manu Exp $);
 
 #include sys/param.h
 #include sys/socket.h
@@ -65,6 +65,13 @@
 		.pr_ctloutput = uipc_ctloutput,
 		.pr_usrreq = uipc_usrreq,
 	}, {
+		.pr_type = SOCK_SEQPACKET,
+		.pr_domain = unixdomain,
+		.pr_flags = PR_CONNREQUIRED|PR_WANTRCVD|PR_RIGHTS|PR_LISTEN|
+			PR_ATOMIC,
+		.pr_ctloutput = uipc_ctloutput,
+		.pr_usrreq = uipc_usrreq,
+	}, {
 		.pr_input = raw_input,
 		.pr_ctlinput = raw_ctlinput,
 		.pr_usrreq = raw_usrreq,

Index: src/sys/kern/uipc_usrreq.c
diff -u src/sys/kern/uipc_usrreq.c:1.133 src/sys/kern/uipc_usrreq.c:1.134
--- src/sys/kern/uipc_usrreq.c:1.133	Fri Nov 19 06:44:43 2010
+++ src/sys/kern/uipc_usrreq.c	Sun May 29 03:32:46 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: uipc_usrreq.c,v 1.133 2010/11/19 06:44:43 dholland Exp $	*/
+/*	$NetBSD: uipc_usrreq.c,v 1.134 2011/05/29 03:32:46 manu Exp $	*/
 
 /*-
  * Copyright (c) 1998, 2000, 2004, 2008, 2009 The NetBSD Foundation, Inc.
@@ -96,7 +96,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: uipc_usrreq.c,v 1.133 2010/11/19 06:44:43 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: uipc_usrreq.c,v 1.134 2011/05/29 03:32:46 manu Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -124,7 +124,7 @@
  * Unix communications domain.
  *
  * TODO:
- *	SEQPACKET, RDM
+ *	RDM
  *	rethink name space problems
  *	need a proper out-of-band
  *
@@ -487,6 +487,7 @@
 			panic(uipc 1);
 			/*NOTREACHED*/
 
+		case SOCK_SEQPACKET: /* FALLTHROUGH */
 		case SOCK_STREAM:
 #define	rcv (so-so_rcv)
 #define snd (so2-so_snd)
@@ -567,6 +568,7 @@
 			break;
 		}
 
+		case SOCK_SEQPACKET: /* FALLTHROUGH */
 		case SOCK_STREAM:
 #define	rcv (so2-so_rcv)
 #define	snd (so-so_snd)
@@ -579,7 +581,7 @@
 			if (unp-unp_conn-unp_flags  UNP_WANTCRED) {
 /*
  * Credentials are passed only once on
- * SOCK_STREAM.
+ * SOCK_STREAM and SOCK_SEQPACKET.
  */
 unp-unp_conn-unp_flags = ~UNP_WANTCRED;
 control = unp_addsockcred(l, control);
@@ -592,8 

CVS commit: src/doc

2011-05-28 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sun May 29 03:34:33 UTC 2011

Modified Files:
src/doc: CHANGES

Log Message:
Add SOCK_SEQPACKET for local sockets


To generate a diff of this commit:
cvs rdiff -u -r1.1549 -r1.1550 src/doc/CHANGES

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/doc/CHANGES
diff -u src/doc/CHANGES:1.1549 src/doc/CHANGES:1.1550
--- src/doc/CHANGES:1.1549	Thu May 26 04:29:18 2011
+++ src/doc/CHANGES	Sun May 29 03:34:33 2011
@@ -1,4 +1,4 @@
-# LIST OF CHANGES FROM LAST RELEASE:			$Revision: 1.1549 $
+# LIST OF CHANGES FROM LAST RELEASE:			$Revision: 1.1550 $
 #
 #
 # [Note: This file does not mention every change made to the NetBSD source tree.
@@ -1012,3 +1012,4 @@
 	userconf(4), boot.cfg(5), boot(8), i386, amd64: Support userconf(4)
 		command in boot.cfg(5)/boot(8) on i386/amd64.
 		[uebayasi 20110526]
+	kernel: add SOCK_SEQPACKET for local sockets [manu 20110529]



CVS commit: src/usr.bin

2011-05-28 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sun May 29 04:45:08 UTC 2011

Modified Files:
src/usr.bin/netstat: unix.c
src/usr.bin/sockstat: sockstat.c

Log Message:
Display SOCK_SEQPACKET local sockets in sockstat and netstat


To generate a diff of this commit:
cvs rdiff -u -r1.32 -r1.33 src/usr.bin/netstat/unix.c
cvs rdiff -u -r1.16 -r1.17 src/usr.bin/sockstat/sockstat.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/netstat/unix.c
diff -u src/usr.bin/netstat/unix.c:1.32 src/usr.bin/netstat/unix.c:1.33
--- src/usr.bin/netstat/unix.c:1.32	Wed May  4 01:11:29 2011
+++ src/usr.bin/netstat/unix.c	Sun May 29 04:45:08 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: unix.c,v 1.32 2011/05/04 01:11:29 dyoung Exp $	*/
+/*	$NetBSD: unix.c,v 1.33 2011/05/29 04:45:08 manu Exp $	*/
 
 /*-
  * Copyright (c) 1983, 1988, 1993
@@ -34,7 +34,7 @@
 #if 0
 static char sccsid[] = from: @(#)unix.c	8.1 (Berkeley) 6/6/93;
 #else
-__RCSID($NetBSD: unix.c,v 1.32 2011/05/04 01:11:29 dyoung Exp $);
+__RCSID($NetBSD: unix.c,v 1.33 2011/05/29 04:45:08 manu Exp $);
 #endif
 #endif /* not lint */
 
@@ -152,66 +152,70 @@
 		struct kinfo_pcb *pcblist;
 		int mib[8];
 		size_t namelen = 0, size = 0, i;
-		const char *mibname = net.local.stream.pcblist;
+		const char *mibnames[] = {
+			net.local.stream.pcblist,
+			net.local.dgram.pcblist,
+			net.local.seqpacket.pcblist,
+			NULL,
+		};
+		const char **mibname;
 		static int first = 1;
-		int done = 0;
 
- again:
-		memset(mib, 0, sizeof(mib));
+		for (mibname = mibnames; *mibname; mibname++) {
+			memset(mib, 0, sizeof(mib));
 
-		if (sysctlnametomib(mibname, mib,
-namelen) == -1)
-			err(1, sysctlnametomib: %s, mibname);
-
-		if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib),
-		NULL, size, NULL, 0) == -1)
-			err(1, sysctl (query));
-
-		if ((pcblist = malloc(size)) == NULL)
-			err(1, malloc);
-		memset(pcblist, 0, size);
-
-		mib[6] = sizeof(*pcblist);
-		mib[7] = size / sizeof(*pcblist);
-
-		if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib), pcblist,
-			   size, NULL, 0) == -1)
-			err(1, sysctl (copy));
-
-		for (i = 0; i  size / sizeof(*pcblist); i++) {
-			struct kinfo_pcb *ki = pcblist[i];
-			struct sockaddr_un *sun;
-			int remote = 0;
-
-			if (first) {
-unixdomainprhdr();
-first = 0;
+			if (sysctlnametomib(*mibname, mib,
+	namelen) == -1)
+err(1, sysctlnametomib: %s, *mibname);
+
+			if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib),
+			NULL, size, NULL, 0) == -1)
+err(1, sysctl (query));
+
+			if ((pcblist = malloc(size)) == NULL)
+err(1, malloc);
+			memset(pcblist, 0, size);
+
+			mib[6] = sizeof(*pcblist);
+			mib[7] = size / sizeof(*pcblist);
+
+			if (prog_sysctl(mib, sizeof(mib) / sizeof(*mib), 
+	pcblist, size, NULL, 0) == -1)
+err(1, sysctl (copy));
+
+			for (i = 0; i  size / sizeof(*pcblist); i++) {
+struct kinfo_pcb *ki = pcblist[i];
+struct sockaddr_un *sun;
+int remote = 0;
+
+if (first) {
+	unixdomainprhdr();
+	first = 0;
+}
+
+sun = (struct sockaddr_un *)ki-ki_dst;
+if (sun-sun_path[0] != '\0') {
+	remote = 1;
+} else {
+	sun = (struct sockaddr_un *)ki-ki_src;
+}
+
+unixdomainpr0(ki-ki_pcbaddr, ki-ki_type, 
+	  ki-ki_rcvq, ki-ki_sndq,
+	  ki-ki_vnode, ki-ki_conn, 
+	  ki-ki_refs, ki-ki_nextref, 
+	  ki-ki_sockaddr, sun, remote);
 			}
 
-			sun = (struct sockaddr_un *)ki-ki_dst;
-			if (sun-sun_path[0] != '\0') {
-remote = 1;
-			} else {
-sun = (struct sockaddr_un *)ki-ki_src;
-			}
-
-			unixdomainpr0(ki-ki_pcbaddr, ki-ki_type, 
-  ki-ki_rcvq, ki-ki_sndq,
-  ki-ki_vnode, ki-ki_conn, ki-ki_refs,
-  ki-ki_nextref, ki-ki_sockaddr, sun, remote);
+			free(pcblist);
 		}
 
-		free(pcblist);
-
-		if (!done  mibname) {
-			mibname = net.local.dgram.pcblist;
-			done = 1;
-			goto again;
-		}
 	} else {
-		filebuf = (char *)kvm_getfiles(get_kvmd(), KERN_FILE, 0, ns_nfiles);
+		filebuf = (char *)kvm_getfiles(get_kvmd(), KERN_FILE, 
+	   0, ns_nfiles);
 		if (filebuf == 0) {
-			printf(file table read error: %s, kvm_geterr(get_kvmd()));
+			printf(file table read error: %s, 
+			   kvm_geterr(get_kvmd()));
 			return;
 		}
 		file = (struct file *)(filebuf + sizeof(fp));

Index: src/usr.bin/sockstat/sockstat.c
diff -u src/usr.bin/sockstat/sockstat.c:1.16 src/usr.bin/sockstat/sockstat.c:1.17
--- src/usr.bin/sockstat/sockstat.c:1.16	Fri Jan 28 18:52:49 2011
+++ src/usr.bin/sockstat/sockstat.c	Sun May 29 04:45:08 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: sockstat.c,v 1.16 2011/01/28 18:52:49 pooka Exp $ */
+/*	$NetBSD: sockstat.c,v 1.17 2011/05/29 04:45:08 manu Exp $ */
 
 /*
  * Copyright (c) 2005 The NetBSD Foundation, Inc.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: sockstat.c,v 1.16 2011/01/28 18:52:49 pooka Exp $);
+__RCSID($NetBSD: sockstat.c,v 1.17 

CVS commit: src/share/man/man4

2011-05-28 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sun May 29 04:51:15 UTC 2011

Modified Files:
src/share/man/man4: unix.4

Log Message:
Document that SOCK_SEQPACKET is supported


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/share/man/man4/unix.4

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/share/man/man4/unix.4
diff -u src/share/man/man4/unix.4:1.22 src/share/man/man4/unix.4:1.23
--- src/share/man/man4/unix.4:1.22	Thu May 19 21:16:45 2011
+++ src/share/man/man4/unix.4	Sun May 29 04:51:15 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: unix.4,v 1.22 2011/05/19 21:16:45 riastradh Exp $
+.\	$NetBSD: unix.4,v 1.23 2011/05/29 04:51:15 manu Exp $
 .\
 .\ Copyright (c) 1991, 1993
 .\	The Regents of the University of California.  All rights reserved.
@@ -49,7 +49,8 @@
 The
 .Tn UNIX Ns -domain
 family supports the
-.Dv SOCK_STREAM
+.Dv SOCK_STREAM ,
+.Dv SOCK_SEQPACKET
 and
 .Dv SOCK_DGRAM
 socket types and uses
@@ -125,11 +126,14 @@
 .Tn UNIX Ns -domain
 protocol family comprises simple
 transport protocols that support the
-.Dv SOCK_STREAM
+.Dv SOCK_STREAM ,
+.Dv SOCK_SEQPACKET
 and
 .Dv SOCK_DGRAM
 abstractions.
 .Dv SOCK_STREAM
+and
+.Dv SOCK_SEQPACKET
 sockets also support the communication of
 .Ux
 file descriptors through the use of the
@@ -178,7 +182,8 @@
 The
 .Dv LOCAL_CREDS
 option may be enabled on a
-.Dv SOCK_DGRAM
+.Dv SOCK_DGRAM ,
+.Dv SOCK_SEQPACKET
 or a
 .Dv SOCK_STREAM
 socket.
@@ -208,6 +213,8 @@
 .Xr getsockopt 2
 to get the PID and effective user and group IDs of a
 .Dv SOCK_STREAM
+or
+.Dv SOCK_SEQPACKET
 peer when it did
 .Xr connect 2
 or



CVS commit: src/usr.bin/sockstat

2011-05-28 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sun May 29 04:54:45 UTC 2011

Modified Files:
src/usr.bin/sockstat: sockstat.1

Log Message:
Document that localsocket may be of type SOCK_SEQPACKET


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.bin/sockstat/sockstat.1

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/sockstat/sockstat.1
diff -u src/usr.bin/sockstat/sockstat.1:1.7 src/usr.bin/sockstat/sockstat.1:1.8
--- src/usr.bin/sockstat/sockstat.1:1.7	Sun May  4 19:43:06 2008
+++ src/usr.bin/sockstat/sockstat.1	Sun May 29 04:54:45 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: sockstat.1,v 1.7 2008/05/04 19:43:06 martin Exp $
+.\	$NetBSD: sockstat.1,v 1.8 2011/05/29 04:54:45 manu Exp $
 .\-
 .\ Copyright (c) 2005 The NetBSD Foundation, Inc.
 .\ All rights reserved.
@@ -152,7 +152,7 @@
 The file descriptor number of the socket.
 .It Li PROTO
 The transport protocol associated with the socket for Internet
-sockets, or the type of socket (stream or datagram) for
+sockets, or the type of socket (stream, seqpacket or datagram) for
 .Ux
 sockets.
 .It Li LOCAL ADDRESS



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-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: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-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/sys/ufs/ufs

2011-05-10 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue May 10 08:29:32 UTC 2011

Modified Files:
src/sys/ufs/ufs: ufs_extattr.c

Log Message:
Fix filesystem root leaked lock when using UFS_EXTATTR_AUTOSTART.
This way, statvfs(2) calls obtained by df(1) or umount(8) will no
longer sleep forever in the kernel to acquire the lock.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/ufs/ufs/ufs_extattr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/ufs/ufs/ufs_extattr.c
diff -u src/sys/ufs/ufs/ufs_extattr.c:1.28 src/sys/ufs/ufs/ufs_extattr.c:1.29
--- src/sys/ufs/ufs/ufs_extattr.c:1.28	Tue Nov 30 10:30:04 2010
+++ src/sys/ufs/ufs/ufs_extattr.c	Tue May 10 08:29:32 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: ufs_extattr.c,v 1.28 2010/11/30 10:30:04 dholland Exp $	*/
+/*	$NetBSD: ufs_extattr.c,v 1.29 2011/05/10 08:29:32 manu Exp $	*/
 
 /*-
  * Copyright (c) 1999-2002 Robert N. M. Watson
@@ -48,7 +48,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: ufs_extattr.c,v 1.28 2010/11/30 10:30:04 dholland Exp $);
+__KERNEL_RCSID(0, $NetBSD: ufs_extattr.c,v 1.29 2011/05/10 08:29:32 manu Exp $);
 
 #ifdef _KERNEL_OPT
 #include opt_ffs.h
@@ -287,7 +287,9 @@
 	error = ufs_lookup(vargs);
 	PNBUF_PUT(pnbuf);
 	if (error) {
-		VOP_UNLOCK(start_dvp);
+		if (lockparent == 0) {
+			VOP_UNLOCK(start_dvp);
+		}
 		return (error);
 	}
 #if 0
@@ -295,6 +297,9 @@
 		panic(ufs_extattr_lookup: target_vp == start_dvp);
 #endif
 
+	if ((target_vp != start_dvp)  (lockparent == 0))
+		 VOP_UNLOCK(start_dvp);
+
 	KASSERT(VOP_ISLOCKED(target_vp) == LK_EXCLUSIVE);
 	*vp = target_vp;
 	return (0);



CVS commit: src

2011-05-09 Thread Emmanuel Dreyfus
 08:51:18 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: msg.c,v 1.11 2011/05/06 13:45:35 manu Exp $ */
+/*  $NetBSD: msg.c,v 1.12 2011/05/09 08:51:18 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -617,11 +617,11 @@
 	size_t len;
 
 	len = sizeof(*fih);
-	PUFFS_FRAMEBUF_GETWINDOW(pb1, 0, (void **)fih, len);
+	PUFFS_FRAMEBUF_GETWINDOW(pb1, 0, (void **)(void *)fih, len);
 	unique_in = fih-unique;
 
 	len = sizeof(*foh);
-	PUFFS_FRAMEBUF_GETWINDOW(pb2, 0, (void **)foh, len);
+	PUFFS_FRAMEBUF_GETWINDOW(pb2, 0, (void **)(void *)foh, len);
 	unique_out = foh-unique;
 
 	return unique_in != unique_out;
@@ -637,7 +637,7 @@
 	size_t len;
 
 	len = sizeof(*foh);
-	PUFFS_FRAMEBUF_GETWINDOW(pb, 0, (void **)foh, len);
+	PUFFS_FRAMEBUF_GETWINDOW(pb, 0, (void **)(void *)foh, len);
 
 	DWARNX(Unexpected frame: unique = %PRId64, error = %d, 
 	   foh-unique, foh-error);



CVS commit: src/distrib/sets/lists

2011-05-09 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon May  9 17:13:21 UTC 2011

Modified Files:
src/distrib/sets/lists/base: ad.mips64eb ad.mips64el md.amd64
md.sparc64 mi shl.mi
src/distrib/sets/lists/comp: ad.mips64eb ad.mips64el md.amd64
md.sparc64 mi shl.mi
src/distrib/sets/lists/man: mi

Log Message:
Attempt to fix build after perfuse addition (there is no MKPERFUSE)


To generate a diff of this commit:
cvs rdiff -u -r1.47 -r1.48 src/distrib/sets/lists/base/ad.mips64eb
cvs rdiff -u -r1.45 -r1.46 src/distrib/sets/lists/base/ad.mips64el
cvs rdiff -u -r1.120 -r1.121 src/distrib/sets/lists/base/md.amd64
cvs rdiff -u -r1.113 -r1.114 src/distrib/sets/lists/base/md.sparc64
cvs rdiff -u -r1.937 -r1.938 src/distrib/sets/lists/base/mi
cvs rdiff -u -r1.582 -r1.583 src/distrib/sets/lists/base/shl.mi
cvs rdiff -u -r1.30 -r1.31 src/distrib/sets/lists/comp/ad.mips64eb \
src/distrib/sets/lists/comp/ad.mips64el
cvs rdiff -u -r1.112 -r1.113 src/distrib/sets/lists/comp/md.amd64
cvs rdiff -u -r1.95 -r1.96 src/distrib/sets/lists/comp/md.sparc64
cvs rdiff -u -r1.1622 -r1.1623 src/distrib/sets/lists/comp/mi
cvs rdiff -u -r1.169 -r1.170 src/distrib/sets/lists/comp/shl.mi
cvs rdiff -u -r1.1315 -r1.1316 src/distrib/sets/lists/man/mi

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/distrib/sets/lists/base/ad.mips64eb
diff -u src/distrib/sets/lists/base/ad.mips64eb:1.47 src/distrib/sets/lists/base/ad.mips64eb:1.48
--- src/distrib/sets/lists/base/ad.mips64eb:1.47	Mon May  9 08:51:08 2011
+++ src/distrib/sets/lists/base/ad.mips64eb	Mon May  9 17:13:19 2011
@@ -1,4 +1,4 @@
-# $NetBSD: ad.mips64eb,v 1.47 2011/05/09 08:51:08 manu Exp $
+# $NetBSD: ad.mips64eb,v 1.48 2011/05/09 17:13:19 manu Exp $
 ./libexec/ld.elf_so-64base-compat-shlib	compat,pic
 ./libexec/ld.elf_so-o32base-sysutil-bin	compat,pic
 ./usr/lib/64	base-compat-lib
@@ -179,8 +179,8 @@
 ./usr/lib/64/libpcap.so.4.0			base-compat-shlib	compat,pic
 ./usr/lib/64/libpci.so.2			base-compat-shlib	compat,pic
 ./usr/lib/64/libpci.so.2.0			base-compat-shlib	compat,pic
-./usr/lib/64/libperfuse.so.0			base-compat-shlib	compat,pic,perfuse
-./usr/lib/64/libperfuse.so.0.0			base-compat-shlib	compat,pic,perfuse
+./usr/lib/64/libperfuse.so.0			base-compat-shlib	compat,pic
+./usr/lib/64/libperfuse.so.0.0			base-compat-shlib	compat,pic
 ./usr/lib/64/libposix.so.0			base-compat-shlib	compat,pic
 ./usr/lib/64/libposix.so.0.1			base-compat-shlib	compat,pic
 ./usr/lib/64/libprop.so.1			base-compat-shlib	compat,pic
@@ -456,8 +456,8 @@
 ./usr/lib/o32/libpcap.so.4.0			base-compat-shlib	compat,pic
 ./usr/lib/o32/libpci.so.2			base-compat-shlib	compat,pic
 ./usr/lib/o32/libpci.so.2.0			base-compat-shlib	compat,pic
-./usr/lib/o32/libperfuse.so.0			base-compat-shlib	compat,pic,perfuse
-./usr/lib/o32/libperfuse.so.0.0			base-compat-shlib	compat,pic,perfuse
+./usr/lib/o32/libperfuse.so.0			base-compat-shlib	compat,pic
+./usr/lib/o32/libperfuse.so.0.0			base-compat-shlib	compat,pic
 ./usr/lib/o32/libposix.so.0			base-compat-shlib	compat,pic
 ./usr/lib/o32/libposix.so.0.1			base-compat-shlib	compat,pic
 ./usr/lib/o32/libprop.so.1			base-compat-shlib	compat,pic

Index: src/distrib/sets/lists/base/ad.mips64el
diff -u src/distrib/sets/lists/base/ad.mips64el:1.45 src/distrib/sets/lists/base/ad.mips64el:1.46
--- src/distrib/sets/lists/base/ad.mips64el:1.45	Mon May  9 08:51:08 2011
+++ src/distrib/sets/lists/base/ad.mips64el	Mon May  9 17:13:19 2011
@@ -1,4 +1,4 @@
-# $NetBSD: ad.mips64el,v 1.45 2011/05/09 08:51:08 manu Exp $
+# $NetBSD: ad.mips64el,v 1.46 2011/05/09 17:13:19 manu Exp $
 ./libexec/ld.elf_so-64base-compat-shlib	compat,pic
 ./libexec/ld.elf_so-o32base-sysutil-bin	compat,pic
 ./usr/lib/64	base-compat-lib
@@ -179,8 +179,8 @@
 ./usr/lib/64/libpcap.so.4.0			base-compat-shlib	compat,pic
 ./usr/lib/64/libpci.so.2			base-compat-shlib	compat,pic
 ./usr/lib/64/libpci.so.2.0			base-compat-shlib	compat,pic
-./usr/lib/64/libperfuse.so.0			base-compat-shlib	compat,pic,perfuse
-./usr/lib/64/libperfuse.so.0.0			base-compat-shlib	compat,pic,perfuse
+./usr/lib/64/libperfuse.so.0			base-compat-shlib	compat,pic
+./usr/lib/64/libperfuse.so.0.0			base-compat-shlib	compat,pic
 ./usr/lib/64/libposix.so.0			base-compat-shlib	compat,pic
 ./usr/lib/64/libposix.so.0.1			base-compat-shlib	compat,pic
 ./usr/lib/64/libprop.so.1			base-compat-shlib	compat,pic
@@ -456,8 +456,8 @@
 ./usr/lib/o32/libpcap.so.4.0			base-compat-shlib	compat,pic
 ./usr/lib/o32/libpci.so.2			base-compat-shlib	compat,pic
 ./usr/lib/o32/libpci.so.2.0			base-compat-shlib	compat,pic
-./usr/lib/o32/libperfuse.so.0			base-compat-shlib	compat,pic,perfuse
-./usr/lib/o32/libperfuse.so.0.0			base-compat-shlib	compat,pic,perfuse
+./usr/lib/o32/libperfuse.so.0			base-compat-shlib	compat,pic
+./usr/lib/o32/libperfuse.so.0.0			base-compat-shlib	compat,pic
 ./usr/lib/o32/libposix.so.0			

CVS commit: src/usr.sbin/perfused

2011-05-06 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Fri May  6 13:45:35 UTC 2011

Modified Files:
src/usr.sbin/perfused: msg.c

Log Message:
Display actual error from FUSE on failures


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/perfused/msg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/perfused/msg.c
diff -u src/usr.sbin/perfused/msg.c:1.10 src/usr.sbin/perfused/msg.c:1.11
--- src/usr.sbin/perfused/msg.c:1.10	Mon Apr 25 04:30:59 2011
+++ src/usr.sbin/perfused/msg.c	Fri May  6 13:45:35 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: msg.c,v 1.10 2011/04/25 04:30:59 manu Exp $ */
+/*  $NetBSD: msg.c,v 1.11 2011/05/06 13:45:35 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -314,7 +314,7 @@
 		DPRINTF( unique = %PRId64, nodeid = %PRId64, 
 			opcode = %s (%d), 
 			error = %d\n, unique_out, nodeid, 
-			perfuse_opname(opcode), opcode, error);
+			perfuse_opname(opcode), opcode, foh-error);
 
 	if (perfuse_diagflags  PDF_DUMP)
 		perfuse_hexdump((char *)foh, foh-len);



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

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

Modified Files:
src/lib/libpuffs: puffs.c
src/sys/fs/puffs: puffs_vnops.c

Log Message:
Call advlock method if supplied


To generate a diff of this commit:
cvs rdiff -u -r1.115 -r1.116 src/lib/libpuffs/puffs.c
cvs rdiff -u -r1.150 -r1.151 src/sys/fs/puffs/puffs_vnops.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/lib/libpuffs/puffs.c
diff -u src/lib/libpuffs/puffs.c:1.115 src/lib/libpuffs/puffs.c:1.116
--- src/lib/libpuffs/puffs.c:1.115	Mon Dec  6 14:50:34 2010
+++ src/lib/libpuffs/puffs.c	Tue May  3 13:16:47 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: puffs.c,v 1.115 2010/12/06 14:50:34 pooka Exp $	*/
+/*	$NetBSD: puffs.c,v 1.116 2011/05/03 13:16:47 manu Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006, 2007  Antti Kantee.  All Rights Reserved.
@@ -31,7 +31,7 @@
 
 #include sys/cdefs.h
 #if !defined(lint)
-__RCSID($NetBSD: puffs.c,v 1.115 2010/12/06 14:50:34 pooka Exp $);
+__RCSID($NetBSD: puffs.c,v 1.116 2011/05/03 13:16:47 manu Exp $);
 #endif /* !lint */
 
 #include sys/param.h
@@ -98,6 +98,7 @@
 	FILLOP(print,PRINT);
 	FILLOP(read, READ);
 	FILLOP(write,WRITE);
+	FILLOP(advlock,  ADVLOCK);
 	FILLOP(abortop,  ABORTOP);
 	FILLOP(pathconf, PATHCONF);
 

Index: src/sys/fs/puffs/puffs_vnops.c
diff -u src/sys/fs/puffs/puffs_vnops.c:1.150 src/sys/fs/puffs/puffs_vnops.c:1.151
--- src/sys/fs/puffs/puffs_vnops.c:1.150	Tue Jan 11 14:04:54 2011
+++ src/sys/fs/puffs/puffs_vnops.c	Tue May  3 13:16:47 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: puffs_vnops.c,v 1.150 2011/01/11 14:04:54 kefren Exp $	*/
+/*	$NetBSD: puffs_vnops.c,v 1.151 2011/05/03 13:16:47 manu Exp $	*/
 
 /*
  * Copyright (c) 2005, 2006, 2007  Antti Kantee.  All Rights Reserved.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: puffs_vnops.c,v 1.150 2011/01/11 14:04:54 kefren Exp $);
+__KERNEL_RCSID(0, $NetBSD: puffs_vnops.c,v 1.151 2011/05/03 13:16:47 manu Exp $);
 
 #include sys/param.h
 #include sys/buf.h
@@ -125,7 +125,7 @@
 { vop_getpages_desc, puffs_vnop_checkop },	/* getpages */
 { vop_putpages_desc, genfs_putpages },		/* REAL putpages */
 { vop_pathconf_desc, puffs_vnop_checkop },	/* pathconf */
-{ vop_advlock_desc, puffs_vnop_advlock },	/* REAL advlock */
+{ vop_advlock_desc, puffs_vnop_advlock },	/* advlock */
 { vop_strategy_desc, puffs_vnop_strategy },	/* REAL strategy */
 { vop_revoke_desc, genfs_revoke },		/* REAL revoke */
 { vop_abortop_desc, puffs_vnop_abortop },	/* REAL abortop */
@@ -2108,10 +2108,28 @@
 		struct flock *a_fl;
 		int a_flags;
 	} */ *ap = v;
+	PUFFS_MSG_VARS(vn, advlock);
 	struct vnode *vp = ap-a_vp;
 	struct puffs_node *pn = VPTOPP(vp);
+	struct puffs_mount *pmp = MPTOPUFFSMP(vp-v_mount);
+	int error;
+
+	if (!EXISTSOP(pmp, ADVLOCK))
+		return lf_advlock(ap, pn-pn_lockf, vp-v_size); 
+	
+	PUFFS_MSG_ALLOC(vn, advlock);
+	(void)memcpy(advlock_msg-pvnr_fl, ap-a_fl, 
+		 sizeof(advlock_msg-pvnr_fl));
+	advlock_msg-pvnr_id = ap-a_id;
+	advlock_msg-pvnr_op = ap-a_op;
+	advlock_msg-pvnr_flags = ap-a_flags;
+	puffs_msg_setinfo(park_advlock, PUFFSOP_VN,
+	PUFFS_VN_ADVLOCK, VPTOPNC(vp));
+	PUFFS_MSG_ENQUEUEWAIT2(pmp, park_advlock, vp-v_data, NULL, error);
+	error = checkerr(pmp, error, __func__);
+	PUFFS_MSG_RELEASE(advlock);
 
-	return lf_advlock(ap, pn-pn_lockf, vp-v_size);
+	return error;
 }
 
 int



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/sys/dev/pci

2011-05-02 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon May  2 14:00:09 UTC 2011

Modified Files:
src/sys/dev/pci: pcidevs pucdata.c

Log Message:
Add new PCI vendor Id for Sunix, and the corresponding device Id.


To generate a diff of this commit:
cvs rdiff -u -r1.1071 -r1.1072 src/sys/dev/pci/pcidevs
cvs rdiff -u -r1.71 -r1.72 src/sys/dev/pci/pucdata.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/pcidevs
diff -u src/sys/dev/pci/pcidevs:1.1071 src/sys/dev/pci/pcidevs:1.1072
--- src/sys/dev/pci/pcidevs:1.1071	Wed Apr 13 22:24:12 2011
+++ src/sys/dev/pci/pcidevs	Mon May  2 14:00:09 2011
@@ -1,4 +1,4 @@
-$NetBSD: pcidevs,v 1.1071 2011/04/13 22:24:12 wiz Exp $
+$NetBSD: pcidevs,v 1.1072 2011/05/02 14:00:09 manu Exp $
 
 /*
  * Copyright (c) 1995, 1996 Christopher G. Demetriou
@@ -626,6 +626,7 @@
 vendor QUMRANET		0x1af4	Qumranet
 vendor SYMPHONY2	0x1c1c	Symphony Labs (2nd PCI Vendor ID)
 vendor TEKRAM2		0x1de1	Tekram Technology (2nd PCI Vendor ID)
+vendor SUNIX		0x1fd4	SUNIX Co
 vendor HINT		0x3388	HiNT
 vendor 3DLABS		0x3d3d	3D Labs
 vendor AVANCE2		0x4005	Avance Logic (2nd PCI Vendor ID)
@@ -4239,6 +4240,10 @@
 product SUNDANCETI ST1023	0x1023	ST1023 Gigabit Ethernet
 product SUNDANCETI ST2021	0x2021	ST2021 Gigabit Ethernet
 
+/* SUNIX products */
+product SUNIX 0001	0x0001	Matrix serial adapter
+product SUNIX 1999	0x1999	1999 multiport adapter
+
 /* Surecom Technology products */
 product SURECOM NE34	0x0e34	NE-34 Ethernet
 

Index: src/sys/dev/pci/pucdata.c
diff -u src/sys/dev/pci/pucdata.c:1.71 src/sys/dev/pci/pucdata.c:1.72
--- src/sys/dev/pci/pucdata.c:1.71	Fri Mar 11 20:22:53 2011
+++ src/sys/dev/pci/pucdata.c	Mon May  2 14:00:09 2011
@@ -1,4 +1,4 @@
-/*	$NetBSD: pucdata.c,v 1.71 2011/03/11 20:22:53 he Exp $	*/
+/*	$NetBSD: pucdata.c,v 1.72 2011/05/02 14:00:09 manu Exp $	*/
 
 /*
  * Copyright (c) 1998, 1999 Christopher G. Demetriou.  All rights reserved.
@@ -36,7 +36,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: pucdata.c,v 1.71 2011/03/11 20:22:53 he Exp $);
+__KERNEL_RCSID(0, $NetBSD: pucdata.c,v 1.72 2011/05/02 14:00:09 manu Exp $);
 
 #include sys/param.h
 #include sys/systm.h
@@ -1144,6 +1144,116 @@
 	},
 	},
 
+	{   SUNIX 5008 1P,
+	{	0x1fd4,	0x1999,	0x1fd4,	0x0100 },
+	{	0x,	0x,	0x,	0xeff0 },
+	{
+		{ PUC_PORT_TYPE_LPT, 0x14, 0x00, 0x00 },
+	},
+	},
+
+	{   SUNIX 5016 8S,
+	{	0x1fd4,	0x1999,	0x1fd4,	0x0010 },
+	{	0x,	0x,	0x,	0x },
+	{
+		{ PUC_PORT_TYPE_COM, 0x10, 0x00, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x10, 0x08, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x10, 0x10, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x10, 0x18, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x14, 0x00, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x14, 0x08, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x14, 0x10, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x14, 0x18, COM_FREQ * 8},
+/*
+ * PUC_MAX_PORTS needs to be raised in order to reach these ports
+ */
+#if PUC_MAX_PORTS = 16
+		{ PUC_PORT_TYPE_COM, 0x14, 0x20, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x14, 0x28, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x14, 0x30, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x14, 0x38, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x14, 0x40, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x14, 0x48, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x14, 0x50, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x14, 0x58, COM_FREQ * 8},
+#endif /* PUC_MAX_PORTS = 16 */
+	},
+	},
+
+	{   SUNIX 5027 1S,
+	{	0x1fd4,	0x1999,	0x1fd4,	0x0001 },
+	{	0x,	0x,	0x,	0x },
+	{
+		{ PUC_PORT_TYPE_COM, 0x10, 0x00, COM_FREQ * 8},
+	},
+	},
+
+	{   SUNIX 5037 2S,
+	{	0x1fd4,	0x1999,	0x1fd4,	0x0002 },
+	{	0x,	0x,	0x,	0x },
+	{
+		{ PUC_PORT_TYPE_COM, 0x10, 0x00, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x10, 0x08, COM_FREQ * 8},
+	},
+	},
+
+	{   SUNIX 5056 4S,
+	{	0x1fd4,	0x1999,	0x1fd4,	0x0004 },
+	{	0x,	0x,	0x,	0x },
+	{
+		{ PUC_PORT_TYPE_COM, 0x10, 0x00, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x10, 0x08, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x10, 0x10, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x10, 0x18, COM_FREQ * 8},
+	},
+	},
+
+	{   SUNIX 5066 8S,
+	{	0x1fd4,	0x1999,	0x1fd4,	0x0008 },
+	{	0x,	0x,	0x,	0x },
+	{
+		{ PUC_PORT_TYPE_COM, 0x10, 0x00, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x10, 0x08, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x10, 0x10, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x10, 0x18, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x14, 0x00, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x14, 0x08, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x14, 0x10, COM_FREQ * 8},
+		{ PUC_PORT_TYPE_COM, 0x14, 0x18, COM_FREQ * 8},
+	},
+	},
+
+	{   SUNIX 5069 1S / 1P,
+	{	0x1fd4,	0x1999,	0x1fd4,	0x0101 },
+	{	0x,	0x,	0x,	0xeff0 },
+	{
+		{ PUC_PORT_TYPE_COM, 0x10, 0x00, COM_FREQ * 

CVS commit: src/sys/dev/pci

2011-05-02 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon May  2 14:06:50 UTC 2011

Modified Files:
src/sys/dev/pci: pcidevs

Log Message:
Don't conflict SUNIX new vendor Id with the previous one


To generate a diff of this commit:
cvs rdiff -u -r1.1072 -r1.1073 src/sys/dev/pci/pcidevs

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/pci/pcidevs
diff -u src/sys/dev/pci/pcidevs:1.1072 src/sys/dev/pci/pcidevs:1.1073
--- src/sys/dev/pci/pcidevs:1.1072	Mon May  2 14:00:09 2011
+++ src/sys/dev/pci/pcidevs	Mon May  2 14:06:50 2011
@@ -1,4 +1,4 @@
-$NetBSD: pcidevs,v 1.1072 2011/05/02 14:00:09 manu Exp $
+$NetBSD: pcidevs,v 1.1073 2011/05/02 14:06:50 manu Exp $
 
 /*
  * Copyright (c) 1995, 1996 Christopher G. Demetriou
@@ -626,7 +626,7 @@
 vendor QUMRANET		0x1af4	Qumranet
 vendor SYMPHONY2	0x1c1c	Symphony Labs (2nd PCI Vendor ID)
 vendor TEKRAM2		0x1de1	Tekram Technology (2nd PCI Vendor ID)
-vendor SUNIX		0x1fd4	SUNIX Co
+vendor SUNIX2		0x1fd4	SUNIX Co
 vendor HINT		0x3388	HiNT
 vendor 3DLABS		0x3d3d	3D Labs
 vendor AVANCE2		0x4005	Avance Logic (2nd PCI Vendor ID)



CVS commit: src/usr.sbin/perfused

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

Modified Files:
src/usr.sbin/perfused: msg.c perfused.c

Log Message:
- fix warnings
- try to handle ENOBUFS in a nicer way
- use errx() for usage message, not err(), as we do not waht strerror(errno)


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/perfused/msg.c
cvs rdiff -u -r1.11 -r1.12 src/usr.sbin/perfused/perfused.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/perfused/msg.c
diff -u src/usr.sbin/perfused/msg.c:1.9 src/usr.sbin/perfused/msg.c:1.10
--- src/usr.sbin/perfused/msg.c:1.9	Mon Oct 11 05:37:58 2010
+++ src/usr.sbin/perfused/msg.c	Mon Apr 25 04:30:59 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: msg.c,v 1.9 2010/10/11 05:37:58 manu Exp $ */
+/*  $NetBSD: msg.c,v 1.10 2011/04/25 04:30:59 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -498,7 +498,7 @@
 	}
 
 #ifdef PERFUSE_DEBUG
-	if (readen != len)
+	if (readen != (ssize_t)len)
 		DERRX(EX_SOFTWARE, %s: short recv %zd/%zd,
 		  __func__, readen, len);
 #endif
@@ -513,7 +513,7 @@
 
 #ifdef PERFUSE_DEBUG
 	if (len  FUSE_BUFSIZE)
-		DERRX(EX_SOFTWARE, %s: foh.len = %d, __func__, len);
+		DERRX(EX_SOFTWARE, %s: foh.len = %zu, __func__, len);
 #endif
 
 	/*
@@ -545,7 +545,7 @@
 	}
 
 #ifdef PERFUSE_DEBUG
-	if (readen != len)
+	if (readen != (ssize_t)len)
 		DERRX(EX_SOFTWARE, %s: short recv %zd/%zd,
 		  __func__, readen, len);
 #endif
@@ -576,10 +576,16 @@
 		/* NOTREACHED */
 		break;
 	case -1:
-		if (errno == EAGAIN)
+		DWARN(%s: send retunred -1, errno = %d, __func__, errno);
+		switch(errno) {
+		case EAGAIN:
+		case ENOBUFS:
 			return 0;
-		DWARN(%s: send retunred -1, __func__);
-		return errno;
+			break;
+		default:
+			return errno;
+			break;
+		}
 		/* NOTREACHED */
 		break;
 	default:
@@ -587,7 +593,7 @@
 	}
 
 #ifdef PERFUSE_DEBUG
-	if (written != len)
+	if (written != (ssize_t)len)
 		DERRX(EX_SOFTWARE, %s: short send %zd/%zd,
 		  __func__, written, len);
 #endif

Index: src/usr.sbin/perfused/perfused.c
diff -u src/usr.sbin/perfused/perfused.c:1.11 src/usr.sbin/perfused/perfused.c:1.12
--- src/usr.sbin/perfused/perfused.c:1.11	Mon Oct 11 05:37:58 2010
+++ src/usr.sbin/perfused/perfused.c	Mon Apr 25 04:30:59 2011
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfused.c,v 1.11 2010/10/11 05:37:58 manu Exp $ */
+/*  $NetBSD: perfused.c,v 1.12 2011/04/25 04:30:59 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -365,7 +365,7 @@
 			foreground = 1;
 			break;
 		default:
-			DERR(EX_USAGE, %s [-fs] [-d level] [-i fd], argv[0]);
+			DERRX(EX_USAGE, %s [-fs] [-d classes] [-i fd], argv[0]);
 			break;
 		}
 	}



CVS commit: src/lib/libpuffs

2011-04-19 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue Apr 19 10:35:24 UTC 2011

Modified Files:
src/lib/libpuffs: puffs_ops.3

Log Message:
In node_lookup() ops, pcn-pcn_nameiop contains a NAMEI_* constant, not
PUFFSLOOKUP_*


To generate a diff of this commit:
cvs rdiff -u -r1.27 -r1.28 src/lib/libpuffs/puffs_ops.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/libpuffs/puffs_ops.3
diff -u src/lib/libpuffs/puffs_ops.3:1.27 src/lib/libpuffs/puffs_ops.3:1.28
--- src/lib/libpuffs/puffs_ops.3:1.27	Mon Dec 13 09:06:51 2010
+++ src/lib/libpuffs/puffs_ops.3	Tue Apr 19 10:35:24 2011
@@ -1,4 +1,4 @@
-.\	$NetBSD: puffs_ops.3,v 1.27 2010/12/13 09:06:51 pooka Exp $
+.\	$NetBSD: puffs_ops.3,v 1.28 2011/04/19 10:35:24 manu Exp $
 .\
 .\ Copyright (c) 2007 Antti Kantee.  All rights reserved.
 .\
@@ -372,17 +372,17 @@
 .Pp
 The type of operation is found from
 .Va pcn-\*[Gt]pcn_nameiop :
-.Bl -tag -width XPUFFSLOOKUP_LOOKUPX
-.It Dv PUFFSLOOKUP_LOOKUP
+.Bl -tag -width XNAMEI_LOOKUPX
+.It Dv NAMEI_LOOKUP
 Normal lookup operation.
-.It Dv PUFFSLOOKUP_CREATE
+.It Dv NAMEI_CREATE
 Lookup to create a node.
-.It Dv PUFFSLOOKUP_DELETE
+.It Dv NAMEI_DELETE
 Lookup for node deletion.
-.It Dv PUFFSLOOKUP_RENAME
+.It Dv NAMEI_RENAME
 Lookup for the target of a rename operation (source will be looked
 up using
-.Dv PUFFSLOOKUP_DELETE ) .
+.Dv NAMEI_DELETE ) .
 .El
 .Pp
 The final component from a pathname lookup usually requires special
@@ -400,9 +400,9 @@
 As a special case,
 .Er ENOENT
 signals success for cases where the lookup operation is
-.Dv PUFFSLOOKUP_CREATE
+.Dv NAMEI_CREATE
 or
-.Dv PUFFSLOOKUP_RENAME .
+.Dv NAMEI_RENAME .
 Failure in these cases can be signalled by returning another appropriate
 error code, for example
 .Er EACCESS .



CVS commit: src/usr.sbin/perfused

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

Modified Files:
src/usr.sbin/perfused: msg.c

Log Message:
Interm hack raising buffers for /dev/fuse socket used in the filesystem.
This works around read(2) system callsfailing with ENOBUFS.

This is a hack bedause there is no way to know that 4 * FUSE_BUFSIZE
will be enough to hold queued FUSE frames. It seems good enough at
mine.


To generate a diff of this commit:
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/perfused/msg.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/perfused/msg.c
diff -u src/usr.sbin/perfused/msg.c:1.7 src/usr.sbin/perfused/msg.c:1.8
--- src/usr.sbin/perfused/msg.c:1.7	Mon Sep 20 06:45:38 2010
+++ src/usr.sbin/perfused/msg.c	Mon Oct 11 01:12:25 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: msg.c,v 1.7 2010/09/20 06:45:38 manu Exp $ */
+/*  $NetBSD: msg.c,v 1.8 2010/10/11 01:12:25 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -68,14 +68,15 @@
 	(void)strcpy(sun.sun_path, _PATH_FUSE); 
 
 	/*
-	 * Set a buffer lentgh large enough so that any FUSE packet
-	 * will fit.
+	 * Set a buffer lentgh large enough so that a few FUSE packets
+	 * will fit. 
+	 * XXX We will have to find how many packets we need
 	 */
-	opt = FUSE_BUFSIZE;
+	opt = 4 * FUSE_BUFSIZE;
 	if (setsockopt(s, SOL_SOCKET, SO_SNDBUF, opt, sizeof(opt)) != 0)
 		DWARN(%s: setsockopt SO_SNDBUF to %d failed, __func__, opt);
 
-	opt = FUSE_BUFSIZE;
+	opt = 4 * FUSE_BUFSIZE;
 	if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, opt, sizeof(opt)) != 0)
 		DWARN(%s: setsockopt SO_RCVBUF to %d failed, __func__, opt);
 



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

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

Modified Files:
src/lib/libperfuse: ops.c perfuse.c perfuse_if.h perfuse_priv.h subr.c
src/usr.sbin/perfused: msg.c perfused.c

Log Message:
Remove code supporting SOCK_STREAM, as SOCK_DGRAM works fine


To generate a diff of this commit:
cvs rdiff -u -r1.22 -r1.23 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.10 -r1.11 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.9 -r1.10 src/lib/libperfuse/perfuse_if.h \
src/lib/libperfuse/subr.c
cvs rdiff -u -r1.15 -r1.16 src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/perfused/msg.c
cvs rdiff -u -r1.10 -r1.11 src/usr.sbin/perfused/perfused.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.22 src/lib/libperfuse/ops.c:1.23
--- src/lib/libperfuse/ops.c:1.22	Mon Oct 11 01:52:05 2010
+++ src/lib/libperfuse/ops.c	Mon Oct 11 05:37:58 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.22 2010/10/11 01:52:05 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.23 2010/10/11 05:37:58 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.

Index: src/lib/libperfuse/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.10 src/lib/libperfuse/perfuse.c:1.11
--- src/lib/libperfuse/perfuse.c:1.10	Sun Oct  3 05:46:47 2010
+++ src/lib/libperfuse/perfuse.c	Mon Oct 11 05:37:58 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.10 2010/10/03 05:46:47 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.11 2010/10/11 05:37:58 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -115,7 +115,7 @@
 	if (strcmp(path, _PATH_FUSE) != 0)
 		return open(path, flags, mode);
 
-	if ((sv[0] = socket(PF_LOCAL, PERFUSE_SOCKTYPE, 0)) == -1) {
+	if ((sv[0] = socket(PF_LOCAL, SOCK_DGRAM, 0)) == -1) {
 #ifdef PERFUSE_DEBUG
 		DWARN(%s:%d socket failed: %s, __func__, __LINE__);
 #endif
@@ -149,7 +149,7 @@
 	 * we will talk using a socketpair 
 	 * instead of /dev/fuse.
 	 */
-	if (socketpair(PF_LOCAL, PERFUSE_SOCKTYPE, 0, sv) != 0) {
+	if (socketpair(PF_LOCAL, SOCK_DGRAM, 0, sv) != 0) {
 		DWARN(%s:%d: socketpair failed, __func__, __LINE__);
 		return -1;
 	}
@@ -218,12 +218,10 @@
 	int s;
 	size_t len;
 	struct perfuse_mount_out *pmo;
-#if (PERFUSE_SOCKTYPE == SOCK_DGRAM)
 	struct sockaddr_storage ss;
 	struct sockaddr_un *sun;
 	struct sockaddr *sa;
 	socklen_t sa_len;
-#endif
 	size_t sock_len;
 	char *frame;
 	char *cp;
@@ -244,7 +242,6 @@
 	 * XXX This socket is not removed at exit time yet
 	 */
 	sock_len = 0;
-#if (PERFUSE_SOCKTYPE == SOCK_DGRAM)
 	sa = (struct sockaddr *)(void *)ss;
 	sun = (struct sockaddr_un *)(void *)ss;
 	sa_len = sizeof(ss);
@@ -263,7 +260,6 @@
 
 		sock_len = strlen(sun-sun_path) + 1;
 	}
-#endif /* PERFUSE_SOCKTYPE */
 		
 	len = sizeof(*pmo);
 	len += source ? (uint32_t)strlen(source) + 1 : 0;

Index: src/lib/libperfuse/perfuse_if.h
diff -u src/lib/libperfuse/perfuse_if.h:1.9 src/lib/libperfuse/perfuse_if.h:1.10
--- src/lib/libperfuse/perfuse_if.h:1.9	Thu Sep 23 16:02:34 2010
+++ src/lib/libperfuse/perfuse_if.h	Mon Oct 11 05:37:58 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_if.h,v 1.9 2010/09/23 16:02:34 manu Exp $ */
+/*  $NetBSD: perfuse_if.h,v 1.10 2010/10/11 05:37:58 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -36,7 +36,6 @@
 #define PERFUSE_MOUNT_MAGIC noFuseRq
 #define PERFUSE_UNKNOWN_INO 0x
 
-#define PERFUSE_SOCKTYPE SOCK_DGRAM
 /* 
  * Diagnostic flags. This global is used only for DPRINTF/DERR/DWARN
  */
Index: src/lib/libperfuse/subr.c
diff -u src/lib/libperfuse/subr.c:1.9 src/lib/libperfuse/subr.c:1.10
--- src/lib/libperfuse/subr.c:1.9	Mon Oct 11 01:08:26 2010
+++ src/lib/libperfuse/subr.c	Mon Oct 11 05:37:58 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: subr.c,v 1.9 2010/10/11 01:08:26 manu Exp $ */
+/*  $NetBSD: subr.c,v 1.10 2010/10/11 05:37:58 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -44,12 +44,9 @@
 	const char *name;
 	struct puffs_node *parent;
 {
-	struct perfuse_state *ps;
 	struct puffs_node *pn;
 	struct perfuse_node_data *pnd;
 
-	ps = puffs_getspecific(pu);
-
 	if ((pnd = malloc(sizeof(*pnd))) == NULL)
 		DERR(EX_OSERR, malloc failed);
 
@@ -84,10 +81,8 @@
 	struct puffs_usermount *pu;
 	struct puffs_node *pn;
 {
-	struct perfuse_state *ps;
 	struct perfuse_node_data *pnd;
 
-	ps = puffs_getspecific(pu);
 	pnd = PERFUSE_NODE_DATA(pn);
 
 	if (pnd-pnd_parent != NULL) {

Index: src/lib/libperfuse/perfuse_priv.h
diff -u src/lib/libperfuse/perfuse_priv.h:1.15 src/lib/libperfuse/perfuse_priv.h:1.16
--- src/lib/libperfuse/perfuse_priv.h:1.15	Mon Oct 11 01:08:26 2010
+++ src/lib/libperfuse/perfuse_priv.h	Mon Oct 11 05:37:58 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_priv.h,v 1.15 2010/10/11 01:08:26 manu Exp $ */
+/*  $NetBSD: perfuse_priv.h,v 1.16 2010/10/11 05:37:58 manu Exp

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-ps_destroy_msg(pm);
- 
+
 	/* 
 	 * Set owner and group
 	 */
@@ -406,6 +453,7

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;
-
-	
-	/*
-	 * Go back until

CVS commit: src

2010-09-23 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Thu Sep 23 16:02:34 UTC 2010

Modified Files:
src/lib/libperfuse: debug.c ops.c perfuse.c perfuse_if.h perfuse_priv.h
subr.c
src/usr.sbin/perfused: perfused.c

Log Message:
== file close operations ==
- use PUFFS_KFLAG_WTCACHE to puffs_init so that all writes are
immediatly send to the filesystem, and we do not have anymore write
after inactive. As a consequence, we can close files at inactive
stage, and there is not any concern left with files opened at
create time. We also do not have anymore to open ourselves in readdir and
fsync.

- Fsync on close (inactive stage). That makes sure we will not need to
do these operations once the file is closed (FUSE want an open file).
short sircuit the request that come after the close, bu not fsinc'ing
closed files,

- Use PUFFS_KFLAG_IAONDEMAND to get less inactive calls

== Removed nodes ==
- more ENOENT retunred for operations on removed node (but there
are probably some still missing): getattr, ooen, setattr, fsync

- set PND_REMOVE before sending the UNLINK/RMDIR operations so that we avoid
races during UNLINK completion. Also set PND_REMOVED on node we overwirte
in rename

== Filehandle fixes ==
- queue open operation to avoid getting two fh for one file

- set FH in getattr, if the file is open

- Just requires a read FH for fsyncdir, as we always opendir in read
mode. Ok, this is misleading :-)

== Misc ==
- do not set FUSE_FATTR_ATIME_NOW in setattr, as we provide the time

- short circuit nilpotent operations in setattr

- add a filename diagnostic flag to dump file names


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libperfuse/debug.c
cvs rdiff -u -r1.16 -r1.17 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.7 -r1.8 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.8 -r1.9 src/lib/libperfuse/perfuse_if.h
cvs rdiff -u -r1.11 -r1.12 src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.5 -r1.6 src/lib/libperfuse/subr.c
cvs rdiff -u -r1.9 -r1.10 src/usr.sbin/perfused/perfused.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.2 src/lib/libperfuse/debug.c:1.3
--- src/lib/libperfuse/debug.c:1.2	Wed Sep 15 01:51:43 2010
+++ src/lib/libperfuse/debug.c	Thu Sep 23 16:02:34 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: debug.c,v 1.2 2010/09/15 01:51:43 manu Exp $ */
+/*  $NetBSD: debug.c,v 1.3 2010/09/23 16:02:34 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -79,7 +79,13 @@
 	{ 0, UNKNOWN },
 };
 
-const char *perfuse_qtypestr[] = { READDIR, READ, WRITE, AFTERWRITE };
+const char *perfuse_qtypestr[] = { 
+	READDIR,
+	READ,
+	WRITE,
+	AFTERWRITE,
+	OPEN
+};
 
 const char *
 perfuse_opname(opcode)

Index: src/lib/libperfuse/ops.c
diff -u src/lib/libperfuse/ops.c:1.16 src/lib/libperfuse/ops.c:1.17
--- src/lib/libperfuse/ops.c:1.16	Mon Sep 20 07:00:21 2010
+++ src/lib/libperfuse/ops.c	Thu Sep 23 16:02:34 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.16 2010/09/20 07:00:21 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.17 2010/09/23 16:02:34 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -180,9 +180,10 @@
 	ps = puffs_getspecific(pu);
 
 #ifdef PERFUSE_DEBUG
-	if ((perfuse_diagflags  PDF_FUSE)  (opc != 0))
-		DPRINTF(file = \%s\\n, 
-			(char *)PNPATH((struct puffs_node *)opc));
+	if ((perfuse_diagflags  PDF_FILENAME)  (opc != 0))
+		DPRINTF(file = \%s\ flags = 0x%x\n, 
+			(char *)PNPATH((struct puffs_node *)opc), 
+			PERFUSE_NODE_DATA(opc)-pnd_flags);
 #endif
 	error = ps-ps_xchg_msg(pu, pm, len, wait);
 
@@ -324,6 +325,11 @@
 	if (pnp != NULL)
 		*pnp = pn;
 
+#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));
+#endif
 out: 
 	ps-ps_destroy_msg(pm);
 
@@ -989,13 +995,6 @@
 		if (error != 0)	
 			return error;
 
-		/*
-		 * This node has been open in the filesystem,
-		 * but not by the kernel. We will have to close
-		 * it on our own to avoid a leak
-		 */
-		PERFUSE_NODE_DATA(opc)-pnd_flags |= PND_OPENFS;
-
 		return 0;
 	}
 
@@ -1030,17 +1029,9 @@
 	 * so that we can reuse it later
 	 */
 	pn = perfuse_new_pn(pu, opc);
-	perfuse_new_fh(pu, (puffs_cookie_t)pn, foo-fh, FWRITE);
+	perfuse_new_fh((puffs_cookie_t)pn, foo-fh, FWRITE);
 	PERFUSE_NODE_DATA(pn)-pnd_ino = feo-nodeid;
 
-#ifdef PERFUSE_DEBUG
-	if (perfuse_diagflags  PDF_FH)
-		DPRINTF(%s: opc = %p, file = \%s\, 
-			ino = %PRId64, rfh = 0x%PRIx64\n,
-			__func__, (void *)pn, (char *)PCNPATH(pcn),
-			feo-nodeid, foo-fh);
-#endif
-
 	fuse_attr_to_vap(ps, pn-pn_va, feo-attr);
 	puffs_newinfo_setcookie(pni, pn);
 
@@ -1049,12 +1040,13 @@
 	 */
 	PERFUSE_NODE_DATA(opc)-pnd_flags |= PND_DIRTY;
 
-	/*
-	 * This node has been open in the filesystem,
-	 * but not by the kernel. We will have

CVS commit: src/usr.sbin/perfused

2010-09-20 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon Sep 20 06:45:38 UTC 2010

Modified Files:
src/usr.sbin/perfused: msg.c perfused.c

Log Message:
- Add debug santity checks
- Do not request peer creds anymore once we have them.


To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/perfused/msg.c
cvs rdiff -u -r1.8 -r1.9 src/usr.sbin/perfused/perfused.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.sbin/perfused/msg.c
diff -u src/usr.sbin/perfused/msg.c:1.6 src/usr.sbin/perfused/msg.c:1.7
--- src/usr.sbin/perfused/msg.c:1.6	Wed Sep 15 01:51:44 2010
+++ src/usr.sbin/perfused/msg.c	Mon Sep 20 06:45:38 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: msg.c,v 1.6 2010/09/15 01:51:44 manu Exp $ */
+/*  $NetBSD: msg.c,v 1.7 2010/09/20 06:45:38 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -483,7 +483,6 @@
 #if (PERFUSE_SOCKTYPE == SOCK_DGRAM)
 	peek = MSG_PEEK;
 #endif
-
 	offset = puffs_framebuf_telloff(pufbuf);
 
 	/*
@@ -509,6 +508,11 @@
 			/* NOTREACHED */
 			break;
 		default:
+#if defined(PERFUSE_DEBUG)  (PERFUSE_SOCKTYPE == SOCK_DGRAM)
+			if (readen != remain)
+DERRX(EX_SOFTWARE, %s: short recv %zd/%zd,
+  __func__, readen, remain);
+#endif
 			break;
 		}
 
@@ -566,6 +570,11 @@
 			/* NOTREACHED */
 			break;
 		default:
+#if defined(PERFUSE_DEBUG)  (PERFUSE_SOCKTYPE == SOCK_DGRAM)
+			if (readen != remain)
+DERRX(EX_SOFTWARE, %s: short recv %zd/%zd,
+  __func__, readen, remain);
+#endif
 			break;
 		}
 
@@ -615,6 +624,11 @@
 			/* NOTREACHED */
 			break;
 		default:
+#if defined(PERFUSE_DEBUG)  (PERFUSE_SOCKTYPE == SOCK_DGRAM)
+			if (written != remain)
+DERRX(EX_SOFTWARE, %s: short send %zd/%zd,
+  __func__, written, remain);
+#endif
 			break;
 		}
 

Index: src/usr.sbin/perfused/perfused.c
diff -u src/usr.sbin/perfused/perfused.c:1.8 src/usr.sbin/perfused/perfused.c:1.9
--- src/usr.sbin/perfused/perfused.c:1.8	Wed Sep 15 01:51:44 2010
+++ src/usr.sbin/perfused/perfused.c	Mon Sep 20 06:45:38 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfused.c,v 1.8 2010/09/15 01:51:44 manu Exp $ */
+/*  $NetBSD: perfused.c,v 1.9 2010/09/20 06:45:38 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -100,6 +100,7 @@
 {
 	struct perfuse_mount_out *pmo;
 	struct sockcred cred;
+	int opt;
 	char *cp;
 	char *source = NULL;
 	char *target = NULL;
@@ -117,6 +118,13 @@
 		exit(EX_PROTOCOL);
 	}
 
+	/*
+	 * We do not need peer creds beyond this point
+	 */
+	opt = 0;
+	if (setsockopt(fd, 0, LOCAL_CREDS, opt, sizeof(opt)) != 0)
+		DWARN(%s: setsockopt LOCAL_CREDS failed, __func__);
+	
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags  PDF_MISC)
 		DPRINTF(perfuse lengths: source = %PRId32, 



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, NULL);
 
-	if ((error

CVS commit: src

2010-09-14 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Wed Sep 15 01:51:44 UTC 2010

Modified Files:
src/lib/libperfuse: debug.c fuse.h ops.c perfuse.c perfuse_if.h
perfuse_priv.h
src/usr.sbin/perfused: debug.c msg.c perfused.c perfused.h

Log Message:
- Use SOCK_DGRAM instead of SOCK_STREAM, as the filesystem seems to
assume datagram semantics: when using SOCK_STREAM, if perfused sends
frames faster than the filesystem consumes them, it will grab multiple
frames at once and discard anything beyond the first one. For now the
code can work both with SOCK_DGRAM and SOCK_STREAM, but SOCK_STREAM
support will probably have to be removed for the sake of readability.

- Remeber to sync parent directories when moving a node

- In debug output, display the requeue type (readdir, write, etc...)


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libperfuse/debug.c src/lib/libperfuse/fuse.h
cvs rdiff -u -r1.14 -r1.15 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.5 -r1.6 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.7 -r1.8 src/lib/libperfuse/perfuse_if.h
cvs rdiff -u -r1.9 -r1.10 src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/perfused/debug.c \
src/usr.sbin/perfused/perfused.h
cvs rdiff -u -r1.5 -r1.6 src/usr.sbin/perfused/msg.c
cvs rdiff -u -r1.7 -r1.8 src/usr.sbin/perfused/perfused.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.1 src/lib/libperfuse/debug.c:1.2
--- src/lib/libperfuse/debug.c:1.1	Wed Aug 25 07:16:00 2010
+++ src/lib/libperfuse/debug.c	Wed Sep 15 01:51:43 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: debug.c,v 1.1 2010/08/25 07:16:00 manu Exp $ */
+/*  $NetBSD: debug.c,v 1.2 2010/09/15 01:51:43 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -79,6 +79,8 @@
 	{ 0, UNKNOWN },
 };
 
+const char *perfuse_qtypestr[] = { READDIR, READ, WRITE, AFTERWRITE };
+
 const char *
 perfuse_opname(opcode)
 	int opcode;
Index: src/lib/libperfuse/fuse.h
diff -u src/lib/libperfuse/fuse.h:1.1 src/lib/libperfuse/fuse.h:1.2
--- src/lib/libperfuse/fuse.h:1.1	Wed Aug 25 07:16:00 2010
+++ src/lib/libperfuse/fuse.h	Wed Sep 15 01:51:43 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: fuse.h,v 1.1 2010/08/25 07:16:00 manu Exp $ */
+/*  $NetBSD: fuse.h,v 1.2 2010/09/15 01:51:43 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -33,9 +33,11 @@
 #define FUSE_ROOT_ID 1
 #define FUSE_UNKNOWN_FH (uint64_t)0
 
+#ifndef FUSE_BUFSIZE
 #define FUSE_MIN_BUFSIZE 0x21000
 #define FUSE_PREF_BUFSIZE (PAGE_SIZE + 0x1000)
-#define FUSE_BUFSIZE MAX(FUSE_PREF_BUFSIZE, FUSE_MIN_BUFSIZE)
+#define FUSE_BUFSIZE MAX(FUSE_PREF_BUFSIZE /* CONSTCOND */, FUSE_MIN_BUFSIZE)
+#endif /* FUSE_BUFSIZE */
 
 struct fuse_attr {
 	uint64_t	ino;

Index: src/lib/libperfuse/ops.c
diff -u src/lib/libperfuse/ops.c:1.14 src/lib/libperfuse/ops.c:1.15
--- src/lib/libperfuse/ops.c:1.14	Thu Sep  9 09:12:35 2010
+++ src/lib/libperfuse/ops.c	Wed Sep 15 01:51:43 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.14 2010/09/09 09:12:35 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.15 2010/09/15 01:51:43 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -613,10 +613,10 @@
 	TAILQ_INSERT_TAIL(pnd-pnd_pcq, pcq, pcq_next);
 
 #ifdef PERFUSE_DEBUG
-
 	if (perfuse_diagflags  PDF_REQUEUE)
-		DPRINTF(%s: REQUEUE opc = %p, pcc = %p\n, 
-		   __func__, (void *)opc, pcq.pcq_cc);
+		DPRINTF(%s: REQUEUE opc = %p, pcc = %p (%s)\n, 
+		__func__, (void *)opc, pcq.pcq_cc,
+			perfuse_qtypestr[type]);
 #endif
 
 	puffs_cc_yield(pcq.pcq_cc);
@@ -624,8 +624,9 @@
 
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags  PDF_REQUEUE)
-		DPRINTF(%s: RESUME opc = %p, pcc = %p\n,
-		__func__, (void *)opc, pcq.pcq_cc);
+		DPRINTF(%s: RESUME opc = %p, pcc = %p (%s)\n,
+		__func__, (void *)opc, pcq.pcq_cc,
+			perfuse_qtypestr[type]);
 #endif
 
 	return;
@@ -654,8 +655,9 @@
 	
 #ifdef PERFUSE_DEBUG
 		if (perfuse_diagflags  PDF_REQUEUE)
-			DPRINTF(%s: SCHEDULE opc = %p, pcc = %p\n,
-__func__, (void *)opc, pcq-pcq_cc);
+			DPRINTF(%s: SCHEDULE opc = %p, pcc = %p (%s)\n,
+__func__, (void *)opc, pcq-pcq_cc,
+ perfuse_qtypestr[type]);
 #endif
 		puffs_cc_schedule(pcq-pcq_cc);
 		
@@ -1812,11 +1814,15 @@
 	/*
 	 * Update source and destination directories child count
 	 * Update moved object parent directory
+	 * Set dirty flag for source and parent
 	 */
 	PERFUSE_NODE_DATA(opc)-pnd_childcount--;
 	PERFUSE_NODE_DATA(targ_dir)-pnd_childcount++;
+
 	PERFUSE_NODE_DATA(src)-pnd_parent = targ_dir;
 
+	PERFUSE_NODE_DATA(opc)-pnd_flags |= PND_DIRTY;
+	PERFUSE_NODE_DATA(targ_dir)-pnd_flags |= PND_DIRTY;
 out:
 	ps-ps_destroy_msg(pm);
 
@@ -2219,13 +2225,14 @@
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags  PDF_RECLAIM)
 		DPRINTF(%s (nodeid %PRId64) is %sreclaimed, 
-			has childcount %d

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: perfuse_priv.h,v 1.9 2010/09/09 09:12:35 manu

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

2010-09-06 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Tue Sep  7 02:11:04 UTC 2010

Modified Files:
src/lib/libperfuse: ops.c perfuse.c perfuse_if.h
src/usr.sbin/perfused: msg.c perfused.c

Log Message:
- Do not checkfor peer credentials when perfused is autostarted and
therefore runs with filesystem privileges

- shut up warnings and debug messages when perfused is autostarted

- make perfused patch modifiable with CFLAGS for easier pkgsrc integration

- Fix build warnings


To generate a diff of this commit:
cvs rdiff -u -r1.11 -r1.12 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.4 -r1.5 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.6 -r1.7 src/lib/libperfuse/perfuse_if.h
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/perfused/msg.c
cvs rdiff -u -r1.6 -r1.7 src/usr.sbin/perfused/perfused.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.11 src/lib/libperfuse/ops.c:1.12
--- src/lib/libperfuse/ops.c:1.11	Mon Sep  6 01:40:24 2010
+++ src/lib/libperfuse/ops.c	Tue Sep  7 02:11:04 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.11 2010/09/06 01:40:24 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.12 2010/09/07 02:11:04 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -41,6 +41,8 @@
 #include perfuse_priv.h
 #include fuse.h
 
+extern int perfuse_diagflags;
+
 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 *,

Index: src/lib/libperfuse/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.4 src/lib/libperfuse/perfuse.c:1.5
--- src/lib/libperfuse/perfuse.c:1.4	Mon Sep  6 01:40:24 2010
+++ src/lib/libperfuse/perfuse.c	Tue Sep  7 02:11:04 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.4 2010/09/06 01:40:24 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.5 2010/09/07 02:11:04 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -115,8 +115,7 @@
 
 	if ((sv[0] = socket(PF_LOCAL, SOCK_STREAM, 0)) == -1) {
 #ifdef PERFUSE_DEBUG
-		printf(%s:%d socket failed: %s\n, 
-		   __func__, __LINE__, strerror(errno));
+		DWARN(%s:%d socket failed: %s, __func__, __LINE__);
 #endif
 		return -1;
 	}
@@ -138,8 +137,7 @@
 	 */
 	if (socketpair(PF_LOCAL, SOCK_STREAM, 0, sv) != 0) {
 #ifdef PERFUSE_DEBUG
-		printf(%s:%d: socketpair failed: %s\n,
-		   __func__, __LINE__, strerror(errno));
+		DWARN(%s:%d: socketpair failed, __func__, __LINE__);
 #endif
 		return -1;
 	}
@@ -149,8 +147,7 @@
 	switch(fork()) {
 	case -1:
 #ifdef PERFUSE_DEBUG
-		printf(%s:%d: fork failed: %s\n,
-		   __func__, __LINE__, strerror(errno));
+		DWARN(%s:%d: fork failed, __func__, __LINE__);
 #endif
 		return -1;
 		/* NOTREACHED */
@@ -158,8 +155,7 @@
 	case 0:
 		(void)execve(argv[0], argv, envp);
 #ifdef PERFUSE_DEBUG
-		printf(%s:%d: execve failed: %s\n,
-		   __func__, __LINE__, strerror(errno));
+		DWARN(%s:%d: execve failed, __func__, __LINE__);
 #endif
 		return -1;
 		/* NOTREACHED */
@@ -181,32 +177,19 @@
 	const void *data;
 {
 	int s;
-#if 0
-	struct sockaddr_un sun;
-#endif
 	size_t len;
 	struct perfuse_mount_out pmo;
 
 #ifdef PERFUSE_DEBUG
-	printf(%s(\%s\, \%s\, \%s\, 0x%lx, \%s\)\n, __func__,
-	   source, target, filesystemtype, mountflags, (const char *)data);
+	if (perfuse_diagflags  PDF_MISC)
+		DPRINTF(%s(\%s\, \%s\, \%s\, 0x%lx, \%s\)\n,
+			__func__, source, target, filesystemtype, 
+			mountflags, (const char *)data);
 #endif
 
-#if 0
-	if ((s = socket(PF_LOCAL, SOCK_STREAM, 0)) == -1)
-		err(EX_OSERR, socket failed);
-
-	sun.sun_len = sizeof(sun);
-	sun.sun_family = AF_LOCAL;
-	(void)strcpy(sun.sun_path, _PATH_FUSE);
-
-	if (connect(s, (struct sockaddr *)sun, sun.sun_len) == -1)
-		err(EX_UNAVAILABLE, cannot connect to \%s\, _PATH_FUSE);
-#endif
 	if ((s = get_fd(data)) == -1)
 		return -1;
 	
-
 	pmo.pmo_len = sizeof(pmo);
 	pmo.pmo_len += source ? (uint32_t)strlen(source) : 0;
 	pmo.pmo_len += target ? (uint32_t)strlen(target) : 0;
@@ -226,7 +209,8 @@
 
 	if (write(s, pmo, sizeof(pmo)) != sizeof(pmo)) {
 #ifdef PERFUSE_DEBUG
-		printf(%s:%d short write\n, __func__, __LINE__);
+		if (perfuse_diagflags  PDF_MISC)
+			DPRINTF(%s:%d short write\n, __func__, __LINE__);
 #endif
 		return -1;
 	}
@@ -235,7 +219,7 @@
 		len = pmo.pmo_source_len;
 		if (write(s, source, len) != (ssize_t)len) {
 #ifdef PERFUSE_DEBUG
-			printf(%s:%d short write\n, __func__, __LINE__);
+			DWARNX(%s:%d short write\n, __func__, __LINE__);
 #endif
 			return -1;
 		}
@@ -245,7 +229,7 @@
 		len = pmo.pmo_target_len;
 		if (write(s, target, len) != (ssize_t)len) {
 #ifdef PERFUSE_DEBUG
-			printf(%s:%d short write\n, __func__, __LINE__);
+			DWARNX(%s:%d short write\n, __func__, __LINE__);
 #endif
 			return -1;
 		}
@@ -255,7 +239,7 @@
 		len = pmo.pmo_filesystemtype_len;
 		if (write(s

CVS commit: src/lib/libperfuse

2010-09-05 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 file is removed

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

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

Modified Files:
src/lib/libperfuse: ops.c perfuse.c perfuse_if.h perfuse_priv.h
src/usr.sbin/perfused: msg.c perfused.c

Log Message:
More LP64 fixes


To generate a diff of this commit:
cvs rdiff -u -r1.10 -r1.11 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.3 -r1.4 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.5 -r1.6 src/lib/libperfuse/perfuse_if.h
cvs rdiff -u -r1.7 -r1.8 src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/perfused/msg.c
cvs rdiff -u -r1.4 -r1.5 src/usr.sbin/perfused/perfused.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.10 src/lib/libperfuse/ops.c:1.11
--- src/lib/libperfuse/ops.c:1.10	Mon Sep  6 01:17:05 2010
+++ src/lib/libperfuse/ops.c	Mon Sep  6 01:40:24 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.10 2010/09/06 01:17:05 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.11 2010/09/06 01:40:24 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.

Index: src/lib/libperfuse/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.3 src/lib/libperfuse/perfuse.c:1.4
--- src/lib/libperfuse/perfuse.c:1.3	Sat Aug 28 03:46:21 2010
+++ src/lib/libperfuse/perfuse.c	Mon Sep  6 01:40:24 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.3 2010/08/28 03:46:21 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.4 2010/09/06 01:40:24 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -208,20 +208,20 @@
 	
 
 	pmo.pmo_len = sizeof(pmo);
-	pmo.pmo_len += source ? strlen(source) : 0;
-	pmo.pmo_len += target ? strlen(target) : 0;
-	pmo.pmo_len += filesystemtype ? strlen(filesystemtype) : 0;
-	pmo.pmo_len += data ? strlen(data) : 0;
+	pmo.pmo_len += source ? (uint32_t)strlen(source) : 0;
+	pmo.pmo_len += target ? (uint32_t)strlen(target) : 0;
+	pmo.pmo_len += filesystemtype ? (uint32_t)strlen(filesystemtype) : 0;
+	pmo.pmo_len += data ? (uint32_t)strlen(data) : 0;
 	pmo.pmo_error = 0;
 	pmo.pmo_unique = (uint64_t)-1;
 
 	(void)strcpy(pmo.pmo_magic, PERFUSE_MOUNT_MAGIC);
-	pmo.pmo_source_len = source ? strlen(source) : 0;
-	pmo.pmo_target_len = target ? strlen(target) : 0;
+	pmo.pmo_source_len = source ? (uint32_t)strlen(source) : 0;
+	pmo.pmo_target_len = target ? (uint32_t)strlen(target) : 0;
 	pmo.pmo_filesystemtype_len = 
-	filesystemtype ? strlen(filesystemtype) : 0;
-	pmo.pmo_mountflags = mountflags;
-	pmo.pmo_data_len = data ? strlen(data) : 0;
+	filesystemtype ? (uint32_t)strlen(filesystemtype) : 0;
+	pmo.pmo_mountflags = (uint32_t)mountflags;
+	pmo.pmo_data_len = data ? (uint32_t)strlen(data) : 0;
 	
 
 	if (write(s, pmo, sizeof(pmo)) != sizeof(pmo)) {

Index: src/lib/libperfuse/perfuse_if.h
diff -u src/lib/libperfuse/perfuse_if.h:1.5 src/lib/libperfuse/perfuse_if.h:1.6
--- src/lib/libperfuse/perfuse_if.h:1.5	Mon Sep  6 01:17:05 2010
+++ src/lib/libperfuse/perfuse_if.h	Mon Sep  6 01:40:24 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_if.h,v 1.5 2010/09/06 01:17:05 manu Exp $ */
+/*  $NetBSD: perfuse_if.h,v 1.6 2010/09/06 01:40:24 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -146,15 +146,15 @@
  * mount request
  */
 struct perfuse_mount_out {
-size_t pmo_len;
+uint32_t pmo_len;
 int32_t pmo_error;  
 uint64_t pmo_unique;
 	char pmo_magic[sizeof(PERFUSE_MOUNT_MAGIC)];
-	size_t pmo_source_len;
-	size_t pmo_target_len;
-	size_t pmo_filesystemtype_len;
-	long pmo_mountflags;
-	size_t pmo_data_len;
+	uint32_t pmo_source_len;
+	uint32_t pmo_target_len;
+	uint32_t pmo_filesystemtype_len;
+	uint32_t pmo_mountflags;
+	uint32_t pmo_data_len;
 };
 
 struct perfuse_mount_info {

Index: src/lib/libperfuse/perfuse_priv.h
diff -u src/lib/libperfuse/perfuse_priv.h:1.7 src/lib/libperfuse/perfuse_priv.h:1.8
--- src/lib/libperfuse/perfuse_priv.h:1.7	Mon Sep  6 01:17:05 2010
+++ src/lib/libperfuse/perfuse_priv.h	Mon Sep  6 01:40:24 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_priv.h,v 1.7 2010/09/06 01:17:05 manu Exp $ */
+/*  $NetBSD: perfuse_priv.h,v 1.8 2010/09/06 01:40:24 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.

Index: src/usr.sbin/perfused/msg.c
diff -u src/usr.sbin/perfused/msg.c:1.3 src/usr.sbin/perfused/msg.c:1.4
--- src/usr.sbin/perfused/msg.c:1.3	Wed Sep  1 14:57:24 2010
+++ src/usr.sbin/perfused/msg.c	Mon Sep  6 01:40:24 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: msg.c,v 1.3 2010/09/01 14:57:24 manu Exp $ */
+/*  $NetBSD: msg.c,v 1.4 2010/09/06 01:40:24 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -128,7 +128,7 @@
 
 	(void)memset(data, 0, len);
 	fih = (struct fuse_in_header *)data;
-	fih-len = len;
+	fih-len = (uint32_t)len;
 	fih-opcode = opcode;
 	fih-unique = perfuse_next_unique(pu);
 	fih-nodeid = nodeid;
@@ -606,7 +606,7 @@
 	int fd;
 	int

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 reuse it later
 	 */
 	pn

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-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

2010-09-01 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Wed Sep  1 14:57:24 UTC 2010

Modified Files:
src/lib/libperfuse: ops.c perfuse_if.h perfuse_priv.h subr.c
src/usr.sbin/perfused: msg.c perfused.c

Log Message:
Build fixes for LP64


To generate a diff of this commit:
cvs rdiff -u -r1.4 -r1.5 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.3 -r1.4 src/lib/libperfuse/perfuse_if.h \
src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.2 -r1.3 src/lib/libperfuse/subr.c
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/perfused/msg.c
cvs rdiff -u -r1.3 -r1.4 src/usr.sbin/perfused/perfused.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.4 src/lib/libperfuse/ops.c:1.5
--- src/lib/libperfuse/ops.c:1.4	Sat Aug 28 03:46:21 2010
+++ src/lib/libperfuse/ops.c	Wed Sep  1 14:57:24 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.4 2010/08/28 03:46:21 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.5 2010/09/01 14:57:24 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -124,12 +124,12 @@
 	vap-va_fileid = fa-ino;
 	vap-va_size = fa-size;
 	vap-va_blocksize = fa-blksize;
-	vap-va_atime.tv_sec = (long)fa-atime;
-	vap-va_atime.tv_nsec = fa-atimensec;
-	vap-va_mtime.tv_sec = (long)fa-mtime;
-	vap-va_mtime.tv_nsec = fa-mtimensec;
-	vap-va_ctime.tv_sec = (long)fa-ctime;
-	vap-va_ctime.tv_nsec = fa-ctimensec;
+	vap-va_atime.tv_sec = (time_t)fa-atime;
+	vap-va_atime.tv_nsec = (long) fa-atimensec;
+	vap-va_mtime.tv_sec = (time_t)fa-mtime;
+	vap-va_mtime.tv_nsec = (long)fa-mtimensec;
+	vap-va_ctime.tv_sec = (time_t)fa-ctime;
+	vap-va_ctime.tv_nsec = (long)fa-ctimensec;
 	vap-va_birthtime.tv_sec = 0;
 	vap-va_birthtime.tv_nsec = 0;
 	vap-va_gen = 0; 
@@ -404,14 +404,14 @@
 		}
 
 		dents-d_fileno = fd-ino;
-		dents-d_reclen = reclen;
+		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);
 
 #ifdef PERFUSE_DEBUG
 		if (perfuse_diagflags  PDF_READDIR)
-			DPRINTF(%s: translated \%s\ ino = %lld\n,
+			DPRINTF(%s: translated \%s\ ino = %PRId64\n,
 __func__, dents-d_name, dents-d_fileno);
 #endif
 
@@ -428,8 +428,10 @@
 		len = FUSE_DIRENT_ALIGN(sizeof(*fd) + fd-namelen);
 #ifdef PERFUSE_DEBUG
 		if (perfuse_diagflags  PDF_READDIR)
-			DPRINTF(%s: record at %lld/0x%llx length = %d/0x%x. 
-next record at %lld/0x%llx, max %d/0x%x\n,
+			DPRINTF(%s: record at %PRId64/0x%PRIx64 
+length = %zd/0x%zx. 
+next record at %PRId64/0x%PRIx64 
+max %zd/0x%zx\n,
 __func__, fd_offset, fd_offset, len, len,
 fd_offset + len, fd_offset + len, 
 fd_len, fd_len);
@@ -499,7 +501,7 @@
 
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags  PDF_READDIR)
-		DPRINTF(%s: readoff = %lld,  pnd-pnd_dirent_len = %d\n, 
+		DPRINTF(%s: readoff = %PRId64,  pnd-pnd_dirent_len = %zd\n,
 			__func__, *readoff, pnd-pnd_dirent_len);
 #endif
 	if (*readoff =  pnd-pnd_dirent_len) {
@@ -704,7 +706,7 @@
 	svfsb-f_asyncreads = ps-ps_asyncreads;
 	svfsb-f_asyncwrites = ps-ps_asyncwrites;
 
-	svfsb-f_fsidx.__fsid_val[0] = ps-ps_fsid;
+	svfsb-f_fsidx.__fsid_val[0] = (int32_t)ps-ps_fsid;
 	svfsb-f_fsidx.__fsid_val[1] = 0;
 	svfsb-f_fsid = ps-ps_fsid;
 	svfsb-f_namemax = MAXPATHLEN;	/* XXX */
@@ -1051,7 +1053,7 @@
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags  PDF_FH)
 		DPRINTF(%s: opc = %p, file = \%s\, 
-			ino = %lld, fh = 0x%llx\n,
+			ino = %PRId64, fh = 0x%PRIx64\n,
 			__func__, (void *)opc, 
 			(char *)PNPATH((struct puffs_node *)opc),
 			PERFUSE_NODE_DATA(opc)-pnd_ino, foo-fh);
@@ -1125,7 +1127,7 @@
 
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags  PDF_FH)
-		DPRINTF(%s: opc = %p, ino = %lld, fh = 0x%llx\n,
+		DPRINTF(%s: opc = %p, ino = %PRId64, fh = 0x%PRIx64\n,
 			__func__, (void *)opc, pnd-pnd_ino, fh);
 #endif
 
@@ -1143,7 +1145,7 @@
 
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags  PDF_FH)
-		DPRINTF(%s: opc = %p, ino = %lld, fh = 0x%llx\n,
+		DPRINTF(%s: opc = %p, ino = %PRId64, fh = 0x%PRIx64\n,
 			 __func__, (void *)opc, pnd-pnd_ino, fri-fh);
 #endif
 
@@ -1152,7 +1154,8 @@
 
 out:
 	if (error != 0)
-		DWARNX(%s: freed fh = 0x%llx but filesystem returned error = %d,
+		DWARNX(%s: freed fh = 0x%PRIx64 but filesystem 
+		   returned error = %d,
 		   __func__, fh, error);
 
 	ps-ps_destroy_msg(pm);
@@ -1204,8 +1207,8 @@
 
 #ifdef PERFUSE_DEBUG
 		if (perfuse_diagflags  PDF_FH)
-			DPRINTF(%s: opc = %p, ino = %lld, fh = 0x%llx\n,
-__func__, (void *)opc,
+			DPRINTF(%s: opc = %p, ino = %PRId64, 
+fh = 0x%PRIx64\n, __func__, (void *)opc,
 PERFUSE_NODE_DATA(opc)-pnd_ino, fgi-fh);
 #endif
 		if ((error = XCHG_MSG(ps, pu, pm, sizeof(*fao))) != 0) {
@@ -1355,13 +1358,13 @@
 
 	if (vap-va_atime.tv_sec != (time_t)PUFFS_VNOVAL) {
 		fsi-atime = vap-va_atime.tv_sec;;
-		fsi-atimensec = vap-va_atime.tv_nsec;;
+		fsi-atimensec = (uint32_t)vap

CVS commit: src

2010-08-27 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Fri Aug 27 09:58:17 UTC 2010

Modified Files:
src/lib/libperfuse: ops.c perfuse.c perfuse_if.h perfuse_priv.h
src/usr.sbin/perfused: msg.c perfused.8 perfused.c perfused.h

Log Message:
- if perfused is not already started (cannot connect to /dev/fuse),
FUSE filesystems will attempt to start it on their own, and will
communicate using a socketpair

- do not advertise NULL file handle as being valid when sending themback to the 
FUSE filesystem.

- unmount if we cannot talk to the FUSE process anymore

- set calling process gid properly

- debug message cleanup


To generate a diff of this commit:
cvs rdiff -u -r1.2 -r1.3 src/lib/libperfuse/ops.c \
src/lib/libperfuse/perfuse_if.h src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.1 -r1.2 src/lib/libperfuse/perfuse.c
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/perfused/msg.c \
src/usr.sbin/perfused/perfused.h
cvs rdiff -u -r1.2 -r1.3 src/usr.sbin/perfused/perfused.8 \
src/usr.sbin/perfused/perfused.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.2 src/lib/libperfuse/ops.c:1.3
--- src/lib/libperfuse/ops.c:1.2	Thu Aug 26 13:29:01 2010
+++ src/lib/libperfuse/ops.c	Fri Aug 27 09:58:17 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.2 2010/08/26 13:29:01 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.3 2010/08/27 09:58:17 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -667,7 +667,7 @@
 	svfsb-f_fsidx.__fsid_val[1] = 0;
 	svfsb-f_fsid = ps-ps_fsid;
 	svfsb-f_namemax = MAXPATHLEN;	/* XXX */
-	svfsb-f_owner = ps-ps_uid;
+	svfsb-f_owner = ps-ps_owner_uid;
 
 	(void)strlcpy(svfsb-f_mntonname, ps-ps_target, _VFS_NAMELEN);
 
@@ -1206,7 +1206,8 @@
 	if (PERFUSE_NODE_DATA(opc)-pnd_flags  PND_OPEN) {
 		fh = perfuse_get_fh(opc);
 		fsi-fh = fh;
-		fsi-valid |= FUSE_FATTR_FH;
+		if (fh != FUSE_UNKNOWN_FH)
+			fsi-valid |= FUSE_FATTR_FH;
 	}
 
 	if (vap-va_size != (u_quad_t)PUFFS_VNOVAL) {
Index: src/lib/libperfuse/perfuse_if.h
diff -u src/lib/libperfuse/perfuse_if.h:1.2 src/lib/libperfuse/perfuse_if.h:1.3
--- src/lib/libperfuse/perfuse_if.h:1.2	Thu Aug 26 13:29:01 2010
+++ src/lib/libperfuse/perfuse_if.h	Fri Aug 27 09:58:17 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_if.h,v 1.2 2010/08/26 13:29:01 manu Exp $ */
+/*  $NetBSD: perfuse_if.h,v 1.3 2010/08/27 09:58:17 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -29,6 +29,7 @@
 #define _REFUSE_PERFUSE_H
 
 #define _PATH_FUSE /dev/fuse
+#define _PATH_PERFUSED /usr/sbin/perfused
 #define FUSE_COMMFD_ENV _FUSE_COMMFD 
 #define PERFUSE_MOUNT_MAGIC noFuseRq
 #define PERFUSE_UNKNOWN_INO 0x
@@ -201,5 +202,6 @@
 const char *perfuse_opname(int);
 void perfuse_fs_init(struct puffs_usermount *);
 int perfuse_mainloop(struct puffs_usermount *);
+int perfuse_unmount(struct puffs_usermount *);
 
 #endif /* _REFUSE_PERFUSE_H */
Index: src/lib/libperfuse/perfuse_priv.h
diff -u src/lib/libperfuse/perfuse_priv.h:1.2 src/lib/libperfuse/perfuse_priv.h:1.3
--- src/lib/libperfuse/perfuse_priv.h:1.2	Thu Aug 26 13:29:01 2010
+++ src/lib/libperfuse/perfuse_priv.h	Fri Aug 27 09:58:17 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_priv.h,v 1.2 2010/08/26 13:29:01 manu Exp $ */
+/*  $NetBSD: perfuse_priv.h,v 1.3 2010/08/27 09:58:17 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -41,9 +41,7 @@
 	void *ps_private;	/* Private field for libperfuse user */
 	struct puffs_usermount *ps_pu;
 	struct puffs_node *ps_root;
-	uid_t ps_uid;
-	gid_t ps_gid;
-	pid_t ps_pid;
+	uid_t ps_owner_uid;
 	int ps_flags;
 #define PS_NO_ACCESS	0x0001	/* access is unimplemented; */
 #define PS_NO_FSYNC	0x0002	/* fsync is unimplemented */

Index: src/lib/libperfuse/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.1 src/lib/libperfuse/perfuse.c:1.2
--- src/lib/libperfuse/perfuse.c:1.1	Wed Aug 25 07:16:00 2010
+++ src/lib/libperfuse/perfuse.c	Fri Aug 27 09:58:17 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.1 2010/08/25 07:16:00 manu Exp $ */
+/*  $NetBSD: perfuse.c,v 1.2 2010/08/27 09:58:17 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -101,16 +101,21 @@
 	int flags;
 	mode_t mode;
 {
-	int s;
+	int sv[2];
 	struct sockaddr_un sun;
 	struct sockaddr *sa;
+	char progname[] = _PATH_PERFUSED;
+	char minus_i[] = -i;
+	char fdstr[16];
+	char *const argv[] = { progname, minus_i, fdstr, NULL};
+	char *const envp[] = { NULL };
 
 	if (strcmp(path, _PATH_FUSE) != 0)
 		return open(path, flags, mode);
 
-	if ((s = socket(PF_LOCAL, SOCK_STREAM, 0)) == -1) {
+	if ((sv[0] = socket(PF_LOCAL, SOCK_STREAM, 0)) == -1) {
 #ifdef PERFUSE_DEBUG
-		printf(%s:%d socket failed: %s, 
+		printf(%s:%d socket failed: %s\n, 
 		   __func__, __LINE__, strerror(errno));
 #endif
 		return -1;
@@ -121,16 +126,49

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_getvap(pn)-va_type == VDIR

CVS commit: src

2010-08-26 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Thu Aug 26 13:29:02 UTC 2010

Modified Files:
src/lib/libperfuse: ops.c perfuse_if.h perfuse_priv.h subr.c
src/usr.sbin/perfused: debug.c perfused.8 perfused.c

Log Message:
- open the file before doing fsync: glusterfs wants that.

- Automatically call fsync on close for files. If we just close, fsync
will come later and we will have to reopen

- Add a PND_DIRTY flag to keep track of files that really need a sync.
perfuse_node_fsync only calls the FUSE fsync method if there are data
to push.

- Add a PND_OPEN flag to keep track of open files. Checking non NULL
fh is not enough, as some filesystems will always set fh to 0.

- Add a sync diagnostic flag, to watch fsync and dirty flag activity.
Make the fh diagnostic flag more verbose

- Send the fh in setattr (it was hardcoded to 0)

I am now able to build libperfuse in a glusterfs mounted filesystem. Yeah!


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/lib/libperfuse/ops.c \
src/lib/libperfuse/perfuse_if.h src/lib/libperfuse/perfuse_priv.h \
src/lib/libperfuse/subr.c
cvs rdiff -u -r1.1 -r1.2 src/usr.sbin/perfused/debug.c \
src/usr.sbin/perfused/perfused.8 src/usr.sbin/perfused/perfused.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.1 src/lib/libperfuse/ops.c:1.2
--- src/lib/libperfuse/ops.c:1.1	Wed Aug 25 07:16:00 2010
+++ src/lib/libperfuse/ops.c	Thu Aug 26 13:29:01 2010
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.1 2010/08/25 07:16:00 manu Exp $ */
+/*  $NetBSD: ops.c,v 1.2 2010/08/26 13:29:01 manu Exp $ */
 
 /*-
  *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
@@ -824,7 +824,6 @@
 		if (error != 0)	
 			return error;
 
-
 		return 0;
 	}
 
@@ -960,9 +959,14 @@
 	 * so that we can reuse it later
 	 */
 	perfuse_new_fh((puffs_cookie_t)pn, foo-fh);
+
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags  PDF_FH)
-		DPRINTF(%s: fh = %lld\n, __func__, foo-fh);
+		DPRINTF(%s: opc = %p, file = \%s\, 
+			ino = %lld, fh = 0x%llx\n,
+			__func__, (void *)opc, 
+			(char *)PNPATH((struct puffs_node *)opc),
+			PERFUSE_NODE_DATA(opc)-pnd_ino, foo-fh);
 #endif
 out:
 	ps-ps_destroy_msg(pm);
@@ -982,17 +986,47 @@
 	perfuse_msg_t *pm;
 	int op;
 	uint64_t fh;
+	struct perfuse_node_data *pnd;
 	struct fuse_release_in *fri;
 	struct puffs_node *pn;
 	int error;
 	
 	ps = puffs_getspecific(pu);
-
 	pn = (struct puffs_node *)opc;
+	pnd = PERFUSE_NODE_DATA(pn);
 
-	if ((fh = perfuse_get_fh((puffs_cookie_t)pn)) == FUSE_UNKNOWN_FH)
+	if (puffs_pn_getvap(pn)-va_type == VDIR)
+		op = FUSE_RELEASEDIR;
+	else
+		op = FUSE_RELEASE;
+
+	if (!(pnd-pnd_flags  PND_OPEN))
 		return EBADF;
 
+	fh = perfuse_get_fh(opc);
+
+	/*
+	 * Sync before close for files
+	 * XXX no pcr argument to pass
+	 */
+	if ((op == FUSE_RELEASE)  (pnd-pnd_flags  PND_DIRTY)) {
+#ifdef PERFUSE_DEBUG
+		if (perfuse_diagflags  PDF_SYNC)
+			DPRINTF(%s: SYNC opc = %p, file = \%s\\n, 
+__func__, (void*)opc, (char *)PNPATH(pn));
+#endif
+		if ((error = perfuse_node_fsync(pu, opc, NULL, 0, 0, 0)) != 0)
+			return error;
+
+		pnd-pnd_flags = ~PND_DIRTY;
+
+#ifdef PERFUSE_DEBUG
+		if (perfuse_diagflags  PDF_SYNC)
+			DPRINTF(%s: CLEAR opc = %p, file = \%s\\n, 
+__func__, (void*)opc, (char *)PNPATH((pn)));
+#endif
+	}
+
 	/*
 	 * Destroy the filehandle before sending the 
 	 * request to the FUSE filesystem, otherwise 
@@ -1004,14 +1038,10 @@
 
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags  PDF_FH)
-		DPRINTF(%s: fh = %lld\n, __func__, fh);
+		DPRINTF(%s: opc = %p, ino = %lld, fh = 0x%llx\n,
+			__func__, (void *)opc, pnd-pnd_ino, fh);
 #endif
 
-	if (puffs_pn_getvap(pn)-va_type == VDIR)
-		op = FUSE_RELEASEDIR;
-	else
-		op = FUSE_RELEASE;
-
 	/*
 	 * release_flags may be set to FUSE_RELEASE_FLUSH
 	 * to flush locks. lock_owner must be set in that case
@@ -1024,12 +1054,18 @@
 	fri-lock_owner = PERFUSE_NODE_DATA(pn)-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 = %lld, fh = 0x%llx\n,
+			 __func__, (void *)opc, pnd-pnd_ino, fri-fh);
+#endif
+
 	if ((error = XCHG_MSG(ps, pu, pm, NO_PAYLOAD_REPLY_LEN)) != 0)
 		goto out;
 
 out:
 	if (error != 0)
-		DWARNX(%s: freed fh = %lld but filesystem returned error = %d,
+		DWARNX(%s: freed fh = 0x%llx but filesystem returned error = %d,
 		   __func__, fh, error);
 
 	ps-ps_destroy_msg(pm);
@@ -1077,8 +1113,14 @@
 		fgi = GET_INPAYLOAD(ps, pm, fuse_getattr_in);
 		fgi-getattr_flags = 0; 
 		fgi-dummy = 0;
-		fgi-fh = 0;
+		fgi-fh = perfuse_get_fh(opc);
 
+#ifdef PERFUSE_DEBUG
+		if (perfuse_diagflags  PDF_FH)
+			DPRINTF(%s: opc = %p, ino = %lld, fh = 0x%llx\n,
+__func__, (void *)opc,
+PERFUSE_NODE_DATA(opc)-pnd_ino, fgi-fh);
+#endif
 		if ((error = XCHG_MSG(ps, pu, pm, sizeof(*fao

CVS commit: src/usr.sbin/perfused

2010-08-25 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Wed Aug 25 07:18:01 UTC 2010

Added Files:
src/usr.sbin/perfused: Makefile debug.c msg.c perfused.8 perfused.c
perfused.h

Log Message:
perfused(8) creates a /dev/fuse socket and performs PUFFS to FUSE relaying.
This is still a work in progress.


To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 src/usr.sbin/perfused/Makefile \
src/usr.sbin/perfused/debug.c src/usr.sbin/perfused/msg.c \
src/usr.sbin/perfused/perfused.8 src/usr.sbin/perfused/perfused.c \
src/usr.sbin/perfused/perfused.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Added files:

Index: src/usr.sbin/perfused/Makefile
diff -u /dev/null src/usr.sbin/perfused/Makefile:1.1
--- /dev/null	Wed Aug 25 07:18:01 2010
+++ src/usr.sbin/perfused/Makefile	Wed Aug 25 07:18:01 2010
@@ -0,0 +1,13 @@
+PROG=perfused
+
+PERFUSE_OPT_DEBUG_FLAGS=   -g -DPERFUSE_DEBUG
+
+CFLAGS=${PERFUSE_OPT_DEBUG_FLAGS}
+SRCS=   perfused.c msg.c debug.c
+MAN=		perfused.8
+WARNS=  4
+
+LDADD+= -lperfuse -lpuffs #-L/usr/pkg/lib -lefence
+DPADD+= ${LIBPUFFS}
+
+.include bsd.prog.mk
Index: src/usr.sbin/perfused/debug.c
diff -u /dev/null src/usr.sbin/perfused/debug.c:1.1
--- /dev/null	Wed Aug 25 07:18:01 2010
+++ src/usr.sbin/perfused/debug.c	Wed Aug 25 07:18:01 2010
@@ -0,0 +1,74 @@
+/*  $NetBSD: debug.c,v 1.1 2010/08/25 07:18:01 manu Exp $ */
+
+/*-
+ *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
+ * 
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *  1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *  2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 
+ *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ *  POSSIBILITY OF SUCH DAMAGE.
+ */ 
+#include stdio.h
+#include errno.h
+#include string.h
+#include ctype.h
+
+#include perfused.h
+
+#ifdef PERFUSE_DEBUG
+void
+perfuse_hexdump(addr, len)
+	char *addr;
+	size_t len;
+{
+	unsigned int i, j, k;
+
+	for (i = 0; i  len; i += 16) {
+		DPRINTF(%p  , addr[i]);
+		for (j = 0; j  16; j += 4) {
+			for (k = 0; k  4; k++) {
+if (i + j + k  len) {
+	DPRINTF(%02x , 
+	   *(addr + i + j + k)  0xff);
+} else {
+	DPRINTF(   );
+}
+			}
+		}
+
+		DPRINTF(  );
+		for (j = 0; j  16; j++) {
+			char c;
+
+			if (i + j  len) {
+c = *(addr + i + j);
+DPRINTF(%c, isprint((int)c) ? c : '.');
+			} else {
+DPRINTF( );
+			}
+		}
+		DPRINTF(\n);
+	}
+
+	return;
+}
+
+
+
+#endif /* PERFUSE_DEBUG */
Index: src/usr.sbin/perfused/msg.c
diff -u /dev/null src/usr.sbin/perfused/msg.c:1.1
--- /dev/null	Wed Aug 25 07:18:01 2010
+++ src/usr.sbin/perfused/msg.c	Wed Aug 25 07:18:01 2010
@@ -0,0 +1,599 @@
+/*  $NetBSD: msg.c,v 1.1 2010/08/25 07:18:01 manu Exp $ */
+
+/*-
+ *  Copyright (c) 2010 Emmanuel Dreyfus. All rights reserved.
+ * 
+ *  Redistribution and use in source and binary forms, with or without
+ *  modification, are permitted provided that the following conditions
+ *  are met:
+ *  1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *  2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 
+ *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT

CVS commit: src/sys/kern

2009-08-23 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sun Aug 23 12:10:50 UTC 2009

Modified Files:
src/sys/kern: subr_tftproot.c

Log Message:
Back out previous change: do not skip the test on rootspec, but make it
a simple attempt instead of an authoritative answer. The failure of the
rootspec test could me machine-dependant. Thanks to martin@ for pointing
that out.


To generate a diff of this commit:
cvs rdiff -u -r1.9 -r1.10 src/sys/kern/subr_tftproot.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/subr_tftproot.c
diff -u src/sys/kern/subr_tftproot.c:1.9 src/sys/kern/subr_tftproot.c:1.10
--- src/sys/kern/subr_tftproot.c:1.9	Fri Aug 21 09:20:47 2009
+++ src/sys/kern/subr_tftproot.c	Sun Aug 23 12:10:50 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: subr_tftproot.c,v 1.9 2009/08/21 09:20:47 manu Exp $ */
+/*	$NetBSD: subr_tftproot.c,v 1.10 2009/08/23 12:10:50 manu Exp $ */
 
 /*-
  * Copyright (c) 2007 Emmanuel Dreyfus, all rights reserved.
@@ -39,7 +39,7 @@
 #include opt_md.h
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: subr_tftproot.c,v 1.9 2009/08/21 09:20:47 manu Exp $);
+__KERNEL_RCSID(0, $NetBSD: subr_tftproot.c,v 1.10 2009/08/23 12:10:50 manu Exp $);
 
 #include sys/param.h
 #include sys/types.h
@@ -129,7 +129,14 @@
 	struct device *dv;
 	int error = -1;
 
-	if ((bootdv != NULL  device_class(bootdv) == DV_IFNET)) {
+	if (rootspec != NULL) {
+		IFNET_FOREACH(ifp)
+			if (strcmp(rootspec, ifp-if_xname) == 0)
+break;
+	} 
+
+	if ((ifp == NULL) 
+	(bootdv != NULL  device_class(bootdv) == DV_IFNET)) {
 		IFNET_FOREACH(ifp)
 			if (strcmp(device_xname(bootdv), ifp-if_xname) == 0)
 break;



CVS commit: src/usr.bin/newsyslog

2009-08-21 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Fri Aug 21 08:20:19 UTC 2009

Modified Files:
src/usr.bin/newsyslog: newsyslog.c

Log Message:
Reset ziptype on each line. Failure to do this caused any log file to
be compressed if it was listed after a line using Z or J flag. For
instance, we compressed log2 with the config file below:
/var/log/log1600  5100  *Z
/var/log/log2600  7100  *-


To generate a diff of this commit:
cvs rdiff -u -r1.58 -r1.59 src/usr.bin/newsyslog/newsyslog.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/newsyslog/newsyslog.c
diff -u src/usr.bin/newsyslog/newsyslog.c:1.58 src/usr.bin/newsyslog/newsyslog.c:1.59
--- src/usr.bin/newsyslog/newsyslog.c:1.58	Sat Jun 20 19:34:19 2009
+++ src/usr.bin/newsyslog/newsyslog.c	Fri Aug 21 08:20:19 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: newsyslog.c,v 1.58 2009/06/20 19:34:19 christos Exp $	*/
+/*	$NetBSD: newsyslog.c,v 1.59 2009/08/21 08:20:19 manu Exp $	*/
 
 /*
  * Copyright (c) 1999, 2000 Andrew Doran a...@netbsd.org
@@ -55,7 +55,7 @@
 
 #include sys/cdefs.h
 #ifndef lint
-__RCSID($NetBSD: newsyslog.c,v 1.58 2009/06/20 19:34:19 christos Exp $);
+__RCSID($NetBSD: newsyslog.c,v 1.59 2009/08/21 08:20:19 manu Exp $);
 #endif /* not lint */
 
 #include sys/types.h
@@ -244,6 +244,7 @@
 
 	rv = -1;
 	line = NULL;
+	ziptype = 0;
 
 	/* Place the white-space separated fields into an array. */
 	do {



CVS commit: src/sys

2009-08-16 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Sun Aug 16 15:35:53 UTC 2009

Modified Files:
src/sys/arch/xen/conf: files.xen
src/sys/compat/darwin: darwin_exec.c darwin_ioframebuffer.c

Log Message:
Build COMPAT_DARWIN and COMPAT_MACH as a Xen domU too


To generate a diff of this commit:
cvs rdiff -u -r1.103 -r1.104 src/sys/arch/xen/conf/files.xen
cvs rdiff -u -r1.58 -r1.59 src/sys/compat/darwin/darwin_exec.c
cvs rdiff -u -r1.42 -r1.43 src/sys/compat/darwin/darwin_ioframebuffer.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/arch/xen/conf/files.xen
diff -u src/sys/arch/xen/conf/files.xen:1.103 src/sys/arch/xen/conf/files.xen:1.104
--- src/sys/arch/xen/conf/files.xen:1.103	Wed Aug  5 20:15:37 2009
+++ src/sys/arch/xen/conf/files.xen	Sun Aug 16 15:35:52 2009
@@ -1,4 +1,4 @@
-#	$NetBSD: files.xen,v 1.103 2009/08/05 20:15:37 jym Exp $
+#	$NetBSD: files.xen,v 1.104 2009/08/16 15:35:52 manu Exp $
 #	NetBSD: files.x86,v 1.10 2003/10/08 17:30:00 bouyer Exp 
 #	NetBSD: files.i386,v 1.254 2004/03/25 23:32:10 jmc Exp 
 
@@ -322,6 +322,7 @@
 file	arch/i386/i386/mach_machdep.c		compat_mach | compat_darwin
 file	arch/i386/i386/mach_sigcode.S		compat_mach | compat_darwin
 file	arch/i386/i386/mach_syscall.c		compat_mach | compat_darwin
+filearch/i386/i386/darwin_commpage_machdep.S compat_darwin
 file	arch/i386/i386/macho_machdep.c		exec_macho
 
 # DARWIN binary compatibility (COMPAT_DARWIN)

Index: src/sys/compat/darwin/darwin_exec.c
diff -u src/sys/compat/darwin/darwin_exec.c:1.58 src/sys/compat/darwin/darwin_exec.c:1.59
--- src/sys/compat/darwin/darwin_exec.c:1.58	Tue Mar 31 06:03:31 2009
+++ src/sys/compat/darwin/darwin_exec.c	Sun Aug 16 15:35:52 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: darwin_exec.c,v 1.58 2009/03/31 06:03:31 cegger Exp $ */
+/*	$NetBSD: darwin_exec.c,v 1.59 2009/08/16 15:35:52 manu Exp $ */
 
 /*-
  * Copyright (c) 2002 The NetBSD Foundation, Inc.
@@ -31,9 +31,10 @@
 
 #include opt_compat_darwin.h /* For COMPAT_DARWIN in mach_port.h */
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: darwin_exec.c,v 1.58 2009/03/31 06:03:31 cegger Exp $);
+__KERNEL_RCSID(0, $NetBSD: darwin_exec.c,v 1.59 2009/08/16 15:35:52 manu Exp $);
 
 #include opt_syscall_debug.h
+#include wsdisplay.h
 
 #include sys/param.h
 #include sys/systm.h
@@ -69,8 +70,10 @@
 
 #include machine/darwin_machdep.h
 
+#if defined(NWSDISPLAY)  NWSDISPLAY  0
 /* Redefined from sys/dev/wscons/wsdisplay.c */
 extern const struct cdevsw wsdisplay_cdevsw;
+#endif
 
 static void darwin_e_proc_exec(struct proc *, struct exec_package *);
 static void darwin_e_proc_fork(struct proc *, struct proc *, int);
@@ -308,7 +311,6 @@
 darwin_e_proc_exit(struct proc *p)
 {
 	struct darwin_emuldata *ded;
-	int error, mode;
 	struct lwp *l;
 
 	ded = p-p_emuldata;
@@ -332,10 +334,13 @@
 		wakeup(ded-ded_hidsystem_finished);
 	}
 
+#if defined(NWSDISPLAY)  NWSDISPLAY  0
 	/*
 	 * Restore text mode and black and white colormap
 	 */
 	if (ded-ded_wsdev != NODEV) {
+		int error, mode;
+
 		mode = WSDISPLAYIO_MODE_EMUL;
 		error = (*wsdisplay_cdevsw.d_ioctl)(ded-ded_wsdev,
 		WSDISPLAYIO_SMODE, (void *)mode, 0, l);
@@ -381,9 +386,9 @@
 			printf(Cannot revert colormap (error %d)\n, error);
 #endif
 	}
-#endif
-
+#endif /* 0 */
 	}
+#endif /* defined(NWSDISPLAY)  NWSDISPLAY  0 */
 
 	/*
 	 * Cleanup mach_emuldata part of darwin_emuldata

Index: src/sys/compat/darwin/darwin_ioframebuffer.c
diff -u src/sys/compat/darwin/darwin_ioframebuffer.c:1.42 src/sys/compat/darwin/darwin_ioframebuffer.c:1.43
--- src/sys/compat/darwin/darwin_ioframebuffer.c:1.42	Sat Mar 14 21:04:18 2009
+++ src/sys/compat/darwin/darwin_ioframebuffer.c	Sun Aug 16 15:35:52 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: darwin_ioframebuffer.c,v 1.42 2009/03/14 21:04:18 dsl Exp $ */
+/*	$NetBSD: darwin_ioframebuffer.c,v 1.43 2009/08/16 15:35:52 manu Exp $ */
 
 /*-
  * Copyright (c) 2003 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: darwin_ioframebuffer.c,v 1.42 2009/03/14 21:04:18 dsl Exp $);
+__KERNEL_RCSID(0, $NetBSD: darwin_ioframebuffer.c,v 1.43 2009/08/16 15:35:52 manu Exp $);
 
 #include sys/types.h
 #include sys/param.h
@@ -72,6 +72,7 @@
 #include compat/darwin/darwin_ioframebuffer.h
 
 #include ioconf.h
+#include wsdisplay.h
 
 /* Redefined from sys/dev/wscons/wsdisplay.c */
 extern const struct cdevsw wsdisplay_cdevsw;
@@ -803,6 +804,7 @@
 static int
 darwin_findscreen(dev_t *dev, int unit, int screen)
 {
+#if defined(NWSDISPLAY)  NWSDISPLAY  0
 	struct device *dv;
 	struct wsdisplay_softc *sc;
 	int major, minor;
@@ -820,6 +822,9 @@
 
 #ifdef DEBUG_DARWIN
 	printf(ioframebuffer uses major = %d, minor = %d\n, major, minor);
-#endif
+#endif /* DEBUG_DARWIN */
 	return 0;
+#else /* defined(NWSDISPLAY)  NWSDISPLAY  0 */
+	return ENODEV;
+#endif /* defined(NWSDISPLAY)  NWSDISPLAY  0 */
 }



CVS commit: src/sys/dev

2009-05-04 Thread Emmanuel Dreyfus
Module Name:src
Committed By:   manu
Date:   Mon May  4 16:20:41 UTC 2009

Modified Files:
src/sys/dev: md.c

Log Message:
TFTPROOT loads the RAMdisk through TFTP at boot time. It needs the
network to be functionnal, and therefore must be called after
config_finalize(). Unfortunately, config_finalize() attaches md0
through mdattach(), and when tftproot_getfile() attempts to attach it
later by calling mdattach() again, it gets a failure.

This change checks for the RAMdisk size in mdattach(). If it is zero, then
the RAMdisk has not been loaded yet, and nothing is done. It will be
attached later when tftproot_getfile() will call mdattach()


To generate a diff of this commit:
cvs rdiff -u -r1.57 -r1.58 src/sys/dev/md.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/md.c
diff -u src/sys/dev/md.c:1.57 src/sys/dev/md.c:1.58
--- src/sys/dev/md.c:1.57	Tue Jan 13 13:35:52 2009
+++ src/sys/dev/md.c	Mon May  4 16:20:41 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: md.c,v 1.57 2009/01/13 13:35:52 yamt Exp $	*/
+/*	$NetBSD: md.c,v 1.58 2009/05/04 16:20:41 manu Exp $	*/
 
 /*
  * Copyright (c) 1995 Gordon W. Ross, Leo Weppelman.
@@ -46,9 +46,10 @@
  */
 
 #include sys/cdefs.h
-__KERNEL_RCSID(0, $NetBSD: md.c,v 1.57 2009/01/13 13:35:52 yamt Exp $);
+__KERNEL_RCSID(0, $NetBSD: md.c,v 1.58 2009/05/04 16:20:41 manu Exp $);
 
 #include opt_md.h
+#include opt_tftproot.h
 
 #include sys/param.h
 #include sys/kernel.h
@@ -118,6 +119,8 @@
 CFATTACH_DECL_NEW(md, sizeof(struct md_softc),
 	0, md_attach, 0, NULL);
 
+extern size_t md_root_size;
+
 /*
  * This is called if we are configured as a pseudo-device
  */
@@ -127,6 +130,14 @@
 	int i;
 	cfdata_t cf;
 
+#ifdef TFTPROOT
+	/* 
+	 * Attachement of md0 must be done after md_root_setconf(), 
+	 * because the RAMdisk is not loaded yet.
+	 */
+	if (md_root_size == 0)
+		return;
+#endif
 	if (config_cfattach_attach(md, md_ca)) {
 		printf(md: cfattach_attach failed\n);
 		return;



<    1   2   3