CVS commit: [netbsd-6] src/lib/libperfuse

2015-06-19 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Fri Jun 19 17:40:47 UTC 2015

Modified Files:
src/lib/libperfuse [netbsd-6]: ops.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #1306):
lib/libperfuse/ops.c: revision 1.84
Fix dot-lookup when readdir does not provide inodes
Some filesystems do not provide inode numbers through readdir (FUSE
mounts
without -o use_ino). We therefore have to lookup each directory entry to
get the missing numbers.
dot and double-dot are exceptions, as we already know the values.
Moreover,
the lookup code does not expect to get requests for dot and will abort
perfused(8) when it gets some. In order to fix that, we just check for
dot and double-dot special case and use the known values instead of
sending
a lookup.


To generate a diff of this commit:
cvs rdiff -u -r1.50.2.22 -r1.50.2.23 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.50.2.22 src/lib/libperfuse/ops.c:1.50.2.23
--- src/lib/libperfuse/ops.c:1.50.2.22	Fri Jun 19 17:35:48 2015
+++ src/lib/libperfuse/ops.c	Fri Jun 19 17:40:47 2015
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.50.2.22 2015/06/19 17:35:48 snj Exp $ */
+/*  $NetBSD: ops.c,v 1.50.2.23 2015/06/19 17:40:47 snj Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -651,13 +651,17 @@ fuse_to_dirent(struct puffs_usermount *p
 			struct puffs_node *pn;
 			struct perfuse_node_data *pnd = PERFUSE_NODE_DATA(opc);
 
-			/* 
-			 * Avoid breaking out of fs 
-			 * by lookup to .. on root
-			 */
-			if ((strcmp(name, "..") == 0) && 
-			(pnd->pnd_nodeid == FUSE_ROOT_ID)) {
-fd->ino = FUSE_ROOT_ID;
+			if (strcmp(name, "..") == 0) {
+/* 
+ * Avoid breaking out of fs 
+ * by lookup to .. on root
+ */
+if (pnd->pnd_nodeid == FUSE_ROOT_ID)
+	fd->ino = FUSE_ROOT_ID;
+else
+	fd->ino = pnd->pnd_parent_nodeid;
+			} else if (strcmp(name, ".") == 0 ) {
+fd->ino = pnd->pnd_nodeid;
 			} else {
 int error;
 



CVS commit: [netbsd-6] src/lib/libperfuse

2015-06-19 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Fri Jun 19 17:35:48 UTC 2015

Modified Files:
src/lib/libperfuse [netbsd-6]: ops.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #1305):
lib/libperfuse/ops.c: revision 1.60
When lookup returns a node with null inode number, it means the ENOENT,
with negative caching. We do not implement negative caching yet, but
we honour the ENOENT.


To generate a diff of this commit:
cvs rdiff -u -r1.50.2.21 -r1.50.2.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.50.2.21 src/lib/libperfuse/ops.c:1.50.2.22
--- src/lib/libperfuse/ops.c:1.50.2.21	Fri Feb 27 20:21:02 2015
+++ src/lib/libperfuse/ops.c	Fri Jun 19 17:35:48 2015
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.50.2.21 2015/02/27 20:21:02 martin Exp $ */
+/*  $NetBSD: ops.c,v 1.50.2.22 2015/06/19 17:35:48 snj Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -434,6 +434,16 @@ node_lookup_common(struct puffs_usermoun
 
 	feo = GET_OUTPAYLOAD(ps, pm, fuse_entry_out);
 
+	/* 
+	 * Starting with ABI 7.4, inode number 0 means ENOENT, 
+	 * with entry_valid / entry_valid_nsec giving negative
+	 * cache timeout (which we do not implement yet).
+	 */
+	if (feo->attr.ino == 0) {
+		ps->ps_destroy_msg(pm);
+		return ENOENT;
+	}
+
 	/*
 	 * Check for a known node, not reclaimed, with another name.
 	 * It may have been moved, or we can lookup ../



CVS commit: [netbsd-6] src/lib/libperfuse

2015-01-16 Thread Martin Husemann
Module Name:src
Committed By:   martin
Date:   Fri Jan 16 19:42:54 UTC 2015

Modified Files:
src/lib/libperfuse [netbsd-6]: ops.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #1235):
lib/libperfuse/ops.c: revision 1.82
Fix atime update
FUSE filesystems assume that SETATTR with atime is the result of utiimes()
being called. As a result, atime and mtime will be updated.  This happens
with MooseFS and glusterFS. atime is supposed to be updated by the
filesystem itself when it gets read operations.
We fix the problem in SETATTR operations by
1) do not create a mtime update when we have an atime update (and vice
   versa), just fill the fields to avoid the filesystem restting the
   missing field to Epoch, but do not pretend we want to update it.
2) If the change is limited to atime, iscard it, as updates should be
   done by READ operations
3) Kernel part of PUFFS has been fixed to make sure reads on empty file
   are sent to the filesystem:
   http://mail-index.netbsd.org/source-changes/2015/01/13/msg062364.html
Thanks to Tom Ivar Helbekkmo for reporting this issue.


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



CVS commit: [netbsd-6] src/lib/libperfuse

2014-12-02 Thread Soren Jacobsen
Module Name:src
Committed By:   snj
Date:   Tue Dec  2 22:01:37 UTC 2014

Modified Files:
src/lib/libperfuse [netbsd-6]: ops.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #1193):
lib/libperfuse/ops.c: revision 1.81
Allow setxattr to be called with a NULL value, instead of crashing.


To generate a diff of this commit:
cvs rdiff -u -r1.50.2.18 -r1.50.2.19 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.50.2.18 src/lib/libperfuse/ops.c:1.50.2.19
--- src/lib/libperfuse/ops.c:1.50.2.18	Sun Nov  9 11:03:41 2014
+++ src/lib/libperfuse/ops.c	Tue Dec  2 22:01:37 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.50.2.18 2014/11/09 11:03:41 msaitoh Exp $ */
+/*  $NetBSD: ops.c,v 1.50.2.19 2014/12/02 22:01:37 snj Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -3450,6 +3450,7 @@ perfuse_node_setextattr(struct puffs_use
 	perfuse_msg_t *pm;
 	struct fuse_setxattr_in *fsi;
 	size_t attrnamelen;
+	size_t datalen;
 	size_t len;
 	char *np;
 	int error;
@@ -3462,23 +3463,27 @@ perfuse_node_setextattr(struct puffs_use
 	ps = puffs_getspecific(pu);
 	attrname = perfuse_native_ns(attrns, attrname, fuse_attrname);
 	attrnamelen = strlen(attrname) + 1;
-	len = sizeof(*fsi) + attrnamelen + *resid;
+
+	datalen = (resid != NULL) ? *resid : 0;
+	len = sizeof(*fsi) + attrnamelen + datalen;
 
 	pm = ps->ps_new_msg(pu, opc, FUSE_SETXATTR, len, pcr);
 	fsi = GET_INPAYLOAD(ps, pm, fuse_setxattr_in);
-	fsi->size = (unsigned int)*resid;
+	fsi->size = (unsigned int)datalen;
 	fsi->flags = 0;
 	np = (char *)(void *)(fsi + 1);
 	(void)strlcpy(np, attrname, attrnamelen);
 	np += attrnamelen;
-	(void)memcpy(np, (char *)attr, *resid);
+	if (datalen)
+		(void)memcpy(np, (char *)attr, datalen);
 
 	if ((error = xchg_msg(pu, opc, pm, 
 			  NO_PAYLOAD_REPLY_LEN, wait_reply)) != 0)
 		goto out;
 
 	ps->ps_destroy_msg(pm);
-	*resid = 0;
+	if (resid)
+		*resid = 0;
 	error = 0;
 
 out:



CVS commit: [netbsd-6] src/lib/libperfuse

2014-11-09 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Sun Nov  9 11:03:41 UTC 2014

Modified Files:
src/lib/libperfuse [netbsd-6]: ops.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #1186):
lib/libperfuse/ops.c: revision 1.80
Restore build with -DDEBUG, and avoid a spurious diagnostic error with
-DDEBUG


To generate a diff of this commit:
cvs rdiff -u -r1.50.2.17 -r1.50.2.18 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.50.2.17 src/lib/libperfuse/ops.c:1.50.2.18
--- src/lib/libperfuse/ops.c:1.50.2.17	Sun Nov  9 07:53:39 2014
+++ src/lib/libperfuse/ops.c	Sun Nov  9 11:03:41 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.50.2.17 2014/11/09 07:53:39 msaitoh Exp $ */
+/*  $NetBSD: ops.c,v 1.50.2.18 2014/11/09 11:03:41 msaitoh Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -803,11 +803,6 @@ requeue_request(struct puffs_usermount *
 {
 	struct perfuse_cc_queue pcq;
 	struct perfuse_node_data *pnd;
-#ifdef PERFUSE_DEBUG
-	struct perfuse_state *ps;
-
-	ps = perfuse_getspecific(pu);
-#endif
 
 	pnd = PERFUSE_NODE_DATA(opc);
 	pcq.pcq_type = type;
@@ -2811,11 +2806,11 @@ perfuse_node_inactive(struct puffs_userm
 	if (opc == 0)
 		return 0;
 
-	node_ref(opc);
 	pnd = PERFUSE_NODE_DATA(opc);
-
 	if (!(pnd->pnd_flags & (PND_OPEN|PND_REMOVED)))
-		goto out;
+		return 0;
+
+	node_ref(opc);
 
 	/*
 	 * Make sure all operation are finished



CVS commit: [netbsd-6] src/lib/libperfuse

2014-11-08 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Sun Nov  9 07:53:39 UTC 2014

Modified Files:
src/lib/libperfuse [netbsd-6]: ops.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #1185):
lib/libperfuse/ops.c: revision 1.79
Avoid deadlocks on write errors
On write errors, we failed to dequeue some operations, leading to
rare but unpleasant deadlocks


To generate a diff of this commit:
cvs rdiff -u -r1.50.2.16 -r1.50.2.17 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.50.2.16 src/lib/libperfuse/ops.c:1.50.2.17
--- src/lib/libperfuse/ops.c:1.50.2.16	Sun Nov  9 07:02:57 2014
+++ src/lib/libperfuse/ops.c	Sun Nov  9 07:53:39 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.50.2.16 2014/11/09 07:02:57 msaitoh Exp $ */
+/*  $NetBSD: ops.c,v 1.50.2.17 2014/11/09 07:53:39 msaitoh Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -3289,6 +3289,7 @@ perfuse_node_write2(struct puffs_usermou
 	if (*resid != 0)
 		error = EFBIG;
 
+out:
 #ifdef PERFUSE_DEBUG
 	if (perfuse_diagflags & PDF_RESIZE) {
 		if (offset > (off_t)vap->va_size)
@@ -3305,16 +3306,6 @@ perfuse_node_write2(struct puffs_usermou
 	if (offset > (off_t)vap->va_size) 
 		vap->va_size = offset;
 
-	if (inresize) {
-#ifdef PERFUSE_DEBUG
-		if (!(pnd->pnd_flags & PND_INRESIZE))
-			DERRX(EX_SOFTWARE, "file write grow without resize");
-#endif
-		pnd->pnd_flags &= ~PND_INRESIZE;
-		(void)dequeue_requests(opc, PCQ_RESIZE, DEQUEUE_ALL);
-	}
-
-
 	/*
 	 * Statistics
 	 */
@@ -3334,7 +3325,15 @@ perfuse_node_write2(struct puffs_usermou
 			__func__, (void*)opc, perfuse_node_path(ps, opc));
 #endif
 
-out:
+	if (inresize) {
+#ifdef PERFUSE_DEBUG
+		if (!(pnd->pnd_flags & PND_INRESIZE))
+			DERRX(EX_SOFTWARE, "file write grow without resize");
+#endif
+		pnd->pnd_flags &= ~PND_INRESIZE;
+		(void)dequeue_requests(opc, PCQ_RESIZE, DEQUEUE_ALL);
+	}
+
 	/*
 	 * VOP_PUTPAGE causes FAF write where kernel does not 
 	 * check operation result. At least warn if it failed.



CVS commit: [netbsd-6] src/lib/libperfuse

2014-11-08 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Sun Nov  9 07:02:57 UTC 2014

Modified Files:
src/lib/libperfuse [netbsd-6]: ops.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #1177):
lib/libperfuse/ops.c: revision 1.77
Fix invalid free in deletextattr FUSE handler
Do not free FUSE message on error as it was not allocated.


To generate a diff of this commit:
cvs rdiff -u -r1.50.2.15 -r1.50.2.16 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.50.2.15 src/lib/libperfuse/ops.c:1.50.2.16
--- src/lib/libperfuse/ops.c:1.50.2.15	Sun Nov  9 06:29:22 2014
+++ src/lib/libperfuse/ops.c	Sun Nov  9 07:02:57 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.50.2.15 2014/11/09 06:29:22 msaitoh Exp $ */
+/*  $NetBSD: ops.c,v 1.50.2.16 2014/11/09 07:02:57 msaitoh Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -3623,9 +3623,11 @@ perfuse_node_deleteextattr(struct puffs_
 	(void)strlcpy(np, attrname, attrnamelen);
 	
 	error = xchg_msg(pu, opc, pm, NO_PAYLOAD_REPLY_LEN, wait_reply);
+	if (error != 0)
+		goto out;
 	
 	ps->ps_destroy_msg(pm);
-
+out:
 	node_rele(opc);
 	return error;
 }



CVS commit: [netbsd-6] src/lib/libperfuse

2014-11-08 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Sun Nov  9 06:29:22 UTC 2014

Modified Files:
src/lib/libperfuse [netbsd-6]: ops.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #1167):
lib/libperfuse/ops.c: revision 1.76
Report allocated bytes on FS correctly, instead of using file size
(which is wrong for sparse files)


To generate a diff of this commit:
cvs rdiff -u -r1.50.2.14 -r1.50.2.15 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.50.2.14 src/lib/libperfuse/ops.c:1.50.2.15
--- src/lib/libperfuse/ops.c:1.50.2.14	Sun Nov  9 06:16:50 2014
+++ src/lib/libperfuse/ops.c	Sun Nov  9 06:29:22 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.50.2.14 2014/11/09 06:16:50 msaitoh Exp $ */
+/*  $NetBSD: ops.c,v 1.50.2.15 2014/11/09 06:29:22 msaitoh Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -321,7 +321,7 @@ fuse_attr_to_vap(struct perfuse_state *p
 	vap->va_gen = 0; 
 	vap->va_flags = 0;
 	vap->va_rdev = fa->rdev;
-	vap->va_bytes = fa->size;
+	vap->va_bytes = fa->blocks * S_BLKSIZE;
 	vap->va_filerev = (u_quad_t)PUFFS_VNOVAL;
 	vap->va_vaflags = 0;
 



CVS commit: [netbsd-6] src/lib/libperfuse

2014-11-08 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Sun Nov  9 06:16:50 UTC 2014

Modified Files:
src/lib/libperfuse [netbsd-6]: ops.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #1165):
lib/libperfuse/ops.c: revision 1.75
Do not trust the filesystem's readdir to give us nul-terminated file
names


To generate a diff of this commit:
cvs rdiff -u -r1.50.2.13 -r1.50.2.14 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.50.2.13 src/lib/libperfuse/ops.c:1.50.2.14
--- src/lib/libperfuse/ops.c:1.50.2.13	Tue Nov  4 01:52:53 2014
+++ src/lib/libperfuse/ops.c	Sun Nov  9 06:16:50 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.50.2.13 2014/11/04 01:52:53 msaitoh Exp $ */
+/*  $NetBSD: ops.c,v 1.50.2.14 2014/11/09 06:16:50 msaitoh Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -597,6 +597,7 @@ fuse_to_dirent(struct puffs_usermount *p
 	do {
 		char *ndp;
 		size_t reclen;
+		char name[MAXPATHLEN];
 
 		reclen = _DIRENT_RECLEN(dents, fd->namelen);
 
@@ -629,6 +630,9 @@ fuse_to_dirent(struct puffs_usermount *p
 			dents = (struct dirent *)(void *)ndp;
 		}
 		
+		strncpy(name, fd->name, fd->namelen);
+		name[fd->namelen] = '\0';
+
 		/*
 		 * Filesystem was mounted without -o use_ino
 		 * Perform a lookup to find it.
@@ -641,13 +645,17 @@ fuse_to_dirent(struct puffs_usermount *p
 			 * Avoid breaking out of fs 
 			 * by lookup to .. on root
 			 */
-			if ((strcmp(fd->name, "..") == 0) && 
+			if ((strcmp(name, "..") == 0) && 
 			(pnd->pnd_nodeid == FUSE_ROOT_ID)) {
 fd->ino = FUSE_ROOT_ID;
 			} else {
-if (node_lookup_common(pu, opc, NULL, fd->name,
-		   NULL, &pn) != 0) {
-	DWARNX("node_lookup_common failed");
+int error;
+
+error = node_lookup_common(pu, opc, NULL, 
+			   name, NULL, &pn);
+if (error != 0) {
+	DWARNX("node_lookup_common %s "
+	   "failed: %d", name, error);
 } else {
 	fd->ino = pn->pn_va.va_fileid;
 	(void)perfuse_node_reclaim(pu, pn);
@@ -659,7 +667,7 @@ fuse_to_dirent(struct puffs_usermount *p
 		dents->d_reclen = (unsigned short)reclen;
 		dents->d_namlen = fd->namelen;
 		dents->d_type = fd->type;
-		strlcpy(dents->d_name, fd->name, fd->namelen + 1);
+		strlcpy(dents->d_name, name, fd->namelen + 1);
 
 #ifdef PERFUSE_DEBUG
 		if (perfuse_diagflags & PDF_READDIR)
@@ -710,7 +718,7 @@ fuse_to_dirent(struct puffs_usermount *p
 	 */
 	if (written != -1)
 		PERFUSE_NODE_DATA(opc)->pnd_dirent_len = written;
-	
+
 	return written;
 }
 



CVS commit: [netbsd-6] src/lib/libperfuse

2014-11-03 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Nov  4 01:52:53 UTC 2014

Modified Files:
src/lib/libperfuse [netbsd-6]: ops.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #1151):
lib/libperfuse/ops.c: revision 1.74
Avoid a file resize serialization deadlock when writing with
PUFFS_IO_APPEND flag. The symptom was a hang when appending to
a file with a null size.


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



CVS commit: [netbsd-6] src/lib/libperfuse

2014-11-03 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Nov  4 01:50:42 UTC 2014

Modified Files:
src/lib/libperfuse [netbsd-6]: ops.c perfuse_priv.h

Log Message:
Pull up following revision(s) (requested by manu in ticket #1153):
lib/libperfuse/ops.c1.72
lib/libperfuse/perfuse_priv.h   1.35

Fix build failure on amd64.


To generate a diff of this commit:
cvs rdiff -u -r1.50.2.11 -r1.50.2.12 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.25.2.5 -r1.25.2.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.50.2.11 src/lib/libperfuse/ops.c:1.50.2.12
--- src/lib/libperfuse/ops.c:1.50.2.11	Mon Nov  3 19:40:10 2014
+++ src/lib/libperfuse/ops.c	Tue Nov  4 01:50:42 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.50.2.11 2014/11/03 19:40:10 msaitoh Exp $ */
+/*  $NetBSD: ops.c,v 1.50.2.12 2014/11/04 01:50:42 msaitoh Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -2884,7 +2884,7 @@ perfuse_node_print(struct puffs_usermoun
 
 int
 perfuse_node_pathconf(struct puffs_usermount *pu, puffs_cookie_t opc,
-	int name, int *retval)
+	int name, register_t *retval)
 {
 	perfuse_msg_t *pm;
 	struct perfuse_state *ps;

Index: src/lib/libperfuse/perfuse_priv.h
diff -u src/lib/libperfuse/perfuse_priv.h:1.25.2.5 src/lib/libperfuse/perfuse_priv.h:1.25.2.6
--- src/lib/libperfuse/perfuse_priv.h:1.25.2.5	Mon Nov  3 19:18:09 2014
+++ src/lib/libperfuse/perfuse_priv.h	Tue Nov  4 01:50:42 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse_priv.h,v 1.25.2.5 2014/11/03 19:18:09 msaitoh Exp $ */
+/*  $NetBSD: perfuse_priv.h,v 1.25.2.6 2014/11/04 01:50:42 msaitoh Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -249,7 +249,7 @@ int perfuse_node_reclaim(struct puffs_us
 int perfuse_node_inactive(struct puffs_usermount *, puffs_cookie_t);
 int perfuse_node_print(struct puffs_usermount *, puffs_cookie_t);
 int perfuse_node_pathconf(struct puffs_usermount *,
-puffs_cookie_t, int, int *);
+puffs_cookie_t, int, register_t *);
 int perfuse_node_advlock(struct puffs_usermount *,
 puffs_cookie_t, void *, int, struct flock *, int);
 int perfuse_node_read(struct puffs_usermount *, puffs_cookie_t,



CVS commit: [netbsd-6] src/lib/libperfuse

2014-11-03 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Nov  3 19:40:10 UTC 2014

Modified Files:
src/lib/libperfuse [netbsd-6]: ops.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #1148):
lib/libperfuse/ops.c: revision 1.73
rmdir dir/.. must return an error. Use ENOTEMPTY like FFS does.


To generate a diff of this commit:
cvs rdiff -u -r1.50.2.10 -r1.50.2.11 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.50.2.10 src/lib/libperfuse/ops.c:1.50.2.11
--- src/lib/libperfuse/ops.c:1.50.2.10	Mon Nov  3 19:37:58 2014
+++ src/lib/libperfuse/ops.c	Mon Nov  3 19:40:10 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.50.2.10 2014/11/03 19:37:58 msaitoh Exp $ */
+/*  $NetBSD: ops.c,v 1.50.2.11 2014/11/03 19:40:10 msaitoh Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -2342,6 +2342,12 @@ perfuse_node_rmdir(struct puffs_usermoun
 	(PERFUSE_NODE_DATA(targ)->pnd_flags & PND_REMOVED))
 		return ENOENT;
 
+	/*
+	 * Attempt to rmdir dir/.. shoud raise ENOTEMPTY
+	 */
+	if (PERFUSE_NODE_DATA(targ)->pnd_nodeid == pnd->pnd_parent_nodeid)
+		return ENOTEMPTY;
+
 	node_ref(opc);
 	node_ref(targ);
 



CVS commit: [netbsd-6] src/lib/libperfuse

2014-11-03 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Nov  3 19:37:58 UTC 2014

Modified Files:
src/lib/libperfuse [netbsd-6]: ops.c perfuse.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #1147):
lib/libperfuse/perfuse.c: revision 1.34
lib/libperfuse/ops.c: revision 1.71
Improve POSIX compliance of FUSE filesystems through PERUSE
- access denied is EPERM and not EACCES
- access to file owned by someone else in a sticy-bit directory should
  be allowed for the sticy-bit directory owner
- setting sticky-bit on a non directory should produce EFTYPE
- implement PATHCONF method as much as we can.


To generate a diff of this commit:
cvs rdiff -u -r1.50.2.9 -r1.50.2.10 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.25.2.4 -r1.25.2.5 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.50.2.9 src/lib/libperfuse/ops.c:1.50.2.10
--- src/lib/libperfuse/ops.c:1.50.2.9	Mon Nov  3 19:31:39 2014
+++ src/lib/libperfuse/ops.c	Mon Nov  3 19:37:58 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.50.2.9 2014/11/03 19:31:39 msaitoh Exp $ */
+/*  $NetBSD: ops.c,v 1.50.2.10 2014/11/03 19:37:58 msaitoh Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -269,7 +269,7 @@ sticky_access(puffs_cookie_t opc, struct
 	  const struct puffs_cred *pcr)
 {
 	uid_t uid;
-	int sticky, owner;
+	int sticky, owner, parent_owner;
 
 	/*
 	 * This covers the case where the kernel requests a DELETE
@@ -288,9 +288,10 @@ sticky_access(puffs_cookie_t opc, struct
 
 	sticky = puffs_pn_getvap(opc)->va_mode & S_ISTXT;
 	owner = puffs_pn_getvap(targ)->va_uid == uid;
+	parent_owner = puffs_pn_getvap(opc)->va_uid == uid;
 
-	if (sticky && !owner)
-		return EACCES;
+	if (sticky && !owner && !parent_owner)
+		return EPERM;
 
 	return 0;
 }
@@ -1295,7 +1296,7 @@ perfuse_node_mknod(struct puffs_usermoun
 		break;
 	default:	/* VNON, VBLK, VCHR, VBAD */
 		if (!puffs_cred_isjuggernaut(pcn->pcn_cred)) {
-			error = EACCES;
+			error = EPERM;
 			goto out;
 		}
 		break;
@@ -1686,7 +1687,7 @@ perfuse_node_setattr_ttl(struct puffs_us
 	 (vap->va_mtime.tv_sec != (time_t)PUFFS_VNOVAL)) &&
 	(puffs_access_times(old_va->va_uid, old_va->va_gid,
 old_va->va_mode, 0, pcr) != 0))
-		return EACCES;
+		return EPERM;
 
 	/*
 	 * Check for permission to change owner and group
@@ -1695,7 +1696,15 @@ perfuse_node_setattr_ttl(struct puffs_us
 	 (vap->va_gid != (gid_t)PUFFS_VNOVAL)) &&
 	(puffs_access_chown(old_va->va_uid, old_va->va_gid,
 vap->va_uid, vap->va_gid, pcr)) != 0)
-		return EACCES;
+		return EPERM;
+
+	/*
+	 * Check for sticky bit on non-directory by non root user
+	 */
+	if ((vap->va_mode != (mode_t)PUFFS_VNOVAL) &&
+	(vap->va_mode & S_ISTXT) && (old_va->va_type != VDIR) &&
+	!puffs_cred_isjuggernaut(pcr))
+		return EFTYPE;
 
 	/*
 	 * Check for permission to change permissions
@@ -1703,7 +1712,7 @@ perfuse_node_setattr_ttl(struct puffs_us
 	if ((vap->va_mode != (mode_t)PUFFS_VNOVAL) &&
 	(puffs_access_chmod(old_va->va_uid, old_va->va_gid,
 old_va->va_type, vap->va_mode, pcr)) != 0)
-		return EACCES;
+		return EPERM;
 	
 	node_ref(opc);
 	
@@ -2867,13 +2876,68 @@ perfuse_node_print(struct puffs_usermoun
 	return 0;
 }
 
-/* ARGSUSED0 */
 int
 perfuse_node_pathconf(struct puffs_usermount *pu, puffs_cookie_t opc,
 	int name, int *retval)
 {
-	DERRX(EX_SOFTWARE, "%s: UNIMPLEMENTED (FATAL)", __func__);
-	return 0;
+	perfuse_msg_t *pm;
+	struct perfuse_state *ps;
+	struct fuse_statfs_out *fso;
+	int error = 0;
+
+	/*
+	 * Static values copied from UFS 
+	 * in src/sys/ufs/ufs/ufs_vnops.c
+	 */
+	switch (name) {
+	case _PC_LINK_MAX:
+		*retval = LINK_MAX;
+		break;
+	case _PC_PATH_MAX:
+		*retval = PATH_MAX;
+		break;
+	case _PC_PIPE_BUF:
+		*retval = PIPE_BUF;
+		break;
+	case _PC_CHOWN_RESTRICTED:
+		*retval = 1;
+		break;
+	case _PC_NO_TRUNC:
+		*retval = 1;
+		break;
+	case _PC_SYNC_IO:
+		*retval = 1;
+		break;
+	case _PC_FILESIZEBITS:
+		*retval = 42;
+		break;
+	case _PC_SYMLINK_MAX:
+		*retval = MAXPATHLEN;
+		break;
+	case _PC_2_SYMLINKS:
+		*retval = 1;
+		break;
+	case _PC_NAME_MAX:
+		ps = puffs_getspecific(pu);
+		pm = ps->ps_new_msg(pu, opc, FUSE_STATFS, 0, NULL);
+
+		error = xchg_msg(pu, opc, pm, sizeof(*fso), wait_reply);
+		if (error != 0)
+			return error;
+
+		fso = GET_OUTPAYLOAD(ps, pm, fuse_statfs_out);
+		*retval = fso->st.namelen;
+
+		ps->ps_destroy_msg(pm);
+	
+		break;
+	default:
+		DWARN("Unimplemented pathconf for name = %d", name);
+		error = ENOSYS;
+		break;
+	}
+
+	return error;
 }
 
 int

Index: src/lib/libperfuse/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.25.2.4 src/lib/libperfuse/perfuse.c:1.25.2.5
--- src/lib/libperfuse/perfuse.c:1.25.2.4	Mon Nov  3 19:18:09 2014
+++ src/lib/libperfuse/perfuse.c	Mon Nov  3 19:37:58 2014
@@ -1,4 

CVS commit: [netbsd-6] src/lib/libperfuse

2014-11-03 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Mon Nov  3 19:31:39 UTC 2014

Modified Files:
src/lib/libperfuse [netbsd-6]: ops.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #1144):
lib/libperfuse/ops.c: revision 1.70
We used to remove the trailing zeros in FUSE readlink replies, but
it seems it does not always happen. Just remove them if present.


To generate a diff of this commit:
cvs rdiff -u -r1.50.2.8 -r1.50.2.9 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.50.2.8 src/lib/libperfuse/ops.c:1.50.2.9
--- src/lib/libperfuse/ops.c:1.50.2.8	Mon Nov  3 19:18:09 2014
+++ src/lib/libperfuse/ops.c	Mon Nov  3 19:31:39 2014
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.50.2.8 2014/11/03 19:18:09 msaitoh Exp $ */
+/*  $NetBSD: ops.c,v 1.50.2.9 2014/11/03 19:31:39 msaitoh Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -2623,12 +2623,16 @@ perfuse_node_readlink(struct puffs_userm
 	if (len == 0)
 		DERRX(EX_PROTOCOL, "path len = %zd too short", len);
 		
+	(void)memcpy(linkname, _GET_OUTPAYLOAD(ps, pm, char *), len);
+
 	/*
 	 * FUSE filesystems return a NUL terminated string, we 
-	 * do not want to trailing \0
+	 * do not want the trailing \0
 	 */
-	*linklen = len - 1;
-	(void)memcpy(linkname, _GET_OUTPAYLOAD(ps, pm, char *), len);
+	while (len > 0 && linkname[len - 1] == '\0')
+		len--;
+
+	*linklen = len;
 
 	ps->ps_destroy_msg(pm);
 	error = 0;



CVS commit: [netbsd-6] src/lib/libperfuse

2013-07-29 Thread SAITOH Masanobu
Module Name:src
Committed By:   msaitoh
Date:   Tue Jul 30 04:05:32 UTC 2013

Modified Files:
src/lib/libperfuse [netbsd-6]: ops.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #923):
lib/libperfuse/ops.c: revision 1.61
lib/libperfuse/ops.c: revision 1.62
One more explicit error log, and two bug fixes
1) with recent FUSE, when lookup returns a null ino, it means ENOENT
2) odd corner case that caused a bug on dd if=test of=test conv=notrunc
   This caused the file to be open first ro, then rw. A logic bug in
   perfuse_node_open caused it to skip the second operation, whereas
   it should open for writing, and store the write FH without touching
   the read FH.
Catch open without FREAD|FWRITE (it should not happen)


To generate a diff of this commit:
cvs rdiff -u -r1.50.2.6 -r1.50.2.7 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.50.2.6 src/lib/libperfuse/ops.c:1.50.2.7
--- src/lib/libperfuse/ops.c:1.50.2.6	Sun Aug 12 13:13:20 2012
+++ src/lib/libperfuse/ops.c	Tue Jul 30 04:05:32 2013
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.50.2.6 2012/08/12 13:13:20 martin Exp $ */
+/*  $NetBSD: ops.c,v 1.50.2.7 2013/07/30 04:05:32 msaitoh Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -1359,10 +1359,33 @@ perfuse_node_open(struct puffs_usermount
 	 * Do not open twice, and do not reopen for reading
 	 * if we already have write handle.
 	 */
-	if (((mode & FREAD) && (pnd->pnd_flags & PND_RFH)) ||
-	((mode & FREAD) && (pnd->pnd_flags & PND_WFH)) ||
-	((mode & FWRITE) && (pnd->pnd_flags & PND_WFH)))
+	switch (mode & (FREAD|FWRITE)) {
+	case FREAD:
+		if (pnd->pnd_flags & (PND_RFH|PND_WFH))
+			goto out;
+		break;
+	case FWRITE:
+		if (pnd->pnd_flags & PND_WFH)
+			goto out;
+		break;
+	case FREAD|FWRITE:
+		if (pnd->pnd_flags & PND_WFH)
+			goto out;
+
+		/*
+		 * Corner case: if already open for reading (PND_RFH)
+		 * and re-opening FREAD|FWRITE, we need to reopen, 
+		 * but only for writing. Note the change on mode 
+		 * will only affect perfuse_new_fh()
+		 */
+		if (pnd->pnd_flags & PND_RFH)
+			mode &= ~FREAD;
+		break;
+	default:
+		DWARNX("open without either FREAD nor FWRITE");
+		error = EPERM;
 		goto out;
+	}
 	
 	/*
 	 * Queue open on a node so that we do not open
@@ -2713,8 +2736,8 @@ perfuse_node_reclaim(struct puffs_usermo
 #ifdef PERFUSE_DEBUG
 	if ((pnd->pnd_flags & PND_OPEN) ||
 	   !TAILQ_EMPTY(&pnd->pnd_pcq))
-		DERRX(EX_SOFTWARE, "%s: opc = %p: still open",
-		  __func__, opc);
+		DERRX(EX_SOFTWARE, "%s: opc = %p \"%s\": still open",
+		  __func__, opc, pnd->pnd_name);
 
 	if ((pnd->pnd_flags & PND_BUSY) ||
 	   !TAILQ_EMPTY(&pnd->pnd_pcq))



CVS commit: [netbsd-6] src/lib/libperfuse

2012-09-13 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Thu Sep 13 22:31:03 UTC 2012

Modified Files:
src/lib/libperfuse [netbsd-6]: perfuse.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #554):
lib/libperfuse/perfuse.c: revision 1.31
Turn a fatal error into a warning.


To generate a diff of this commit:
cvs rdiff -u -r1.25.2.2 -r1.25.2.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/perfuse.c
diff -u src/lib/libperfuse/perfuse.c:1.25.2.2 src/lib/libperfuse/perfuse.c:1.25.2.3
--- src/lib/libperfuse/perfuse.c:1.25.2.2	Sun Aug 12 13:13:20 2012
+++ src/lib/libperfuse/perfuse.c	Thu Sep 13 22:31:03 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: perfuse.c,v 1.25.2.2 2012/08/12 13:13:20 martin Exp $ */
+/*  $NetBSD: perfuse.c,v 1.25.2.3 2012/09/13 22:31:03 riz Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -682,9 +682,8 @@ perfuse_fsreq(struct puffs_usermount *pu
 		DWARN("operation unique = %"PRId64" failed", foh->unique);
 		break;
 	default:
-		DERRX(EX_SOFTWARE,
-		 "Unexpected frame: unique = %"PRId64", error = %d",
-		 foh->unique, foh->error);
+		DWARNX("Unexpected frame: unique = %"PRId64", error = %d",
+		foh->unique, foh->error);
 		/* NOTREACHED */
 		break;
 	}



CVS commit: [netbsd-6] src/lib/libperfuse

2012-06-24 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Sun Jun 24 16:07:12 UTC 2012

Modified Files:
src/lib/libperfuse [netbsd-6]: ops.c

Log Message:
Pull up revisions:
  src/lib/libperfuse/ops.c revisions 1.56,1.57
(requested by manu in ticket #347).


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

CVS commit: [netbsd-6] src/lib/libperfuse

2012-06-05 Thread Julian Coleman
Module Name:src
Committed By:   jdc
Date:   Tue Jun  5 16:25:24 UTC 2012

Modified Files:
src/lib/libperfuse [netbsd-6]: ops.c

Log Message:
Pull up revision 1.55 (requested by manu in ticket #290).

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


To generate a diff of this commit:
cvs rdiff -u -r1.50.2.2 -r1.50.2.3 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.50.2.2 src/lib/libperfuse/ops.c:1.50.2.3
--- src/lib/libperfuse/ops.c:1.50.2.2	Mon Apr 23 16:48:59 2012
+++ src/lib/libperfuse/ops.c	Tue Jun  5 16:25:24 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: ops.c,v 1.50.2.2 2012/04/23 16:48:59 riz Exp $ */
+/*  $NetBSD: ops.c,v 1.50.2.3 2012/06/05 16:25:24 jdc Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -1849,6 +1849,19 @@ perfuse_node_setattr_ttl(struct puffs_us
 		fsi->mtimensec = 0;
 		fsi->valid &= ~(FUSE_FATTR_ATIME|FUSE_FATTR_MTIME);
 	}
+
+	/*
+	 * There is the same mess with fchmod()
+	 */
+	if ((vap->va_mode != (mode_t)PUFFS_VNOVAL) &&
+	(vap->va_uid == (uid_t)PUFFS_VNOVAL) &&
+	(vap->va_gid == (gid_t)PUFFS_VNOVAL)) {
+		fsi->atime = 0;
+		fsi->atimensec = 0;
+		fsi->mtime = 0;
+		fsi->mtimensec = 0;
+		fsi->valid &= ~(FUSE_FATTR_ATIME|FUSE_FATTR_MTIME);
+	}
 		
 	/*
 	 * If nothing remain, discard the operation.



CVS commit: [netbsd-6] src/lib/libperfuse

2012-03-10 Thread Jeff Rizzo
Module Name:src
Committed By:   riz
Date:   Sat Mar 10 16:42:30 UTC 2012

Modified Files:
src/lib/libperfuse [netbsd-6]: ops.c perfuse_priv.h subr.c

Log Message:
Pull up following revision(s) (requested by manu in ticket #104):
lib/libperfuse/subr.c: revision 1.16
lib/libperfuse/ops.c: revision 1.51
lib/libperfuse/perfuse_priv.h: revision 1.26
The kernel can lookup the same node multiple time and will reclaim as
many times it looked up. All reclaims but the last one must be ignored,
otherwise we discard a node which will still get operations. We therefore
have to keep track of lookup/reclaim count and hnour reclaims only when
the count reaches zero.


To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.50.2.1 src/lib/libperfuse/ops.c
cvs rdiff -u -r1.25 -r1.25.2.1 src/lib/libperfuse/perfuse_priv.h
cvs rdiff -u -r1.15 -r1.15.2.1 src/lib/libperfuse/subr.c

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

Modified files:

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

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

Index: src/lib/libperfuse/subr.c
diff -u src/lib/libperfuse/subr.c:1.15 src/lib/libperfuse/subr.c:1.15.2.1
--- src/lib/libperfuse/subr.c:1.15	Sun Jan 29 06:22:02 2012
+++ src/lib/libperfuse/subr.c	Sat Mar 10 16:42:30 2012
@@ -1,4 +1,4 @@
-/*  $NetBSD: subr.c,v 1.15 2012/01/29 06:22:02 manu Exp $ */
+/*  $NetBSD: subr.c,v 1.15.2.1 2012/03/10 16:42:30 riz Exp $ */
 
 /*-
  *  Copyright (c) 2010-2011 Emmanuel Dreyfus. All rights reserved.
@@ -67,7 +67,8 @@ perfuse_new_pn(pu, name, parent)
 	pnd->pnd_rfh = FUSE_UNKNOWN_FH;
 	pnd->pnd_wfh = FUSE_UNKNOWN_FH;
 	pnd->pnd_nodeid = PERFUSE_UNKNOWN_NODEID;
-	pnd->pnd_nlookup = 1;
+	pnd->pnd_fuse_nlookup = 1;
+