Index: fuse_device.c
===================================================================
RCS file: /cvs/src/sys/miscfs/fuse/fuse_device.c,v
retrieving revision 1.18
diff -u -p -r1.18 fuse_device.c
--- fuse_device.c	10 Feb 2015 22:04:00 -0000	1.18
+++ fuse_device.c	21 Feb 2015 07:26:45 -0000
@@ -29,12 +29,6 @@
 #include "fusefs_node.h"
 #include "fusefs.h"
 
-#ifdef	FUSE_DEBUG
-#define	DPRINTF(fmt, arg...)	printf("%s: " fmt, "fuse", ##arg)
-#else
-#define	DPRINTF(fmt, arg...)
-#endif
-
 SIMPLEQ_HEAD(fusebuf_head, fusebuf);
 
 struct fuse_d {
@@ -84,7 +78,7 @@ const static struct filterops fuse_seltr
 	filt_seltrue
 };
 
-#ifdef FUSE_DEBUG
+#ifdef FUSEBUF_DEBUG
 static void
 fuse_dump_buff(char *buff, int len)
 {
@@ -169,7 +163,8 @@ fuse_device_cleanup(dev_t dev, struct fu
 	lprev = NULL;
 	SIMPLEQ_FOREACH_SAFE(f, &fd->fd_fbufs_in, fb_next, ftmp) {
 		if (fbuf == f || fbuf == NULL) {
-			DPRINTF("cleanup unprocessed msg in sc_fbufs_in\n");
+			DPRINTF("cleanup unprocessed msg in sc_fbufs_in: "
+			    "%llu\n", f->fb_uuid);
 			if (lprev == NULL)
 				SIMPLEQ_REMOVE_HEAD(&fd->fd_fbufs_in, fb_next);
 			else
@@ -189,7 +184,8 @@ fuse_device_cleanup(dev_t dev, struct fu
 	lprev = NULL;
 	SIMPLEQ_FOREACH_SAFE(f, &fd->fd_fbufs_wait, fb_next, ftmp) {
 		if (fbuf == f || fbuf == NULL) {
-			DPRINTF("umount unprocessed msg in sc_fbufs_wait\n");
+			DPRINTF("umount unprocessed msg in sc_fbufs_wait: "
+			    "%llu\n", f->fb_uuid);
 			if (lprev == NULL)
 				SIMPLEQ_REMOVE_HEAD(&fd->fd_fbufs_wait,
 				    fb_next);
@@ -334,7 +330,7 @@ fuseioctl(dev_t dev, u_long cmd, caddr_t
 			return (error);
 		}
 
-#ifdef FUSE_DEBUG
+#ifdef FUSEBUF_DEBUG
 		fuse_dump_buff(ioexch->fbxch_data, ioexch->fbxch_len);
 #endif
 
@@ -379,7 +375,7 @@ fuseioctl(dev_t dev, u_long cmd, caddr_t
 			return (error);
 		}
 
-#ifdef FUSE_DEBUG
+#ifdef FUSEBUF_DEBUG
 		fuse_dump_buff(fbuf->fb_dat, fbuf->fb_len);
 #endif
 
@@ -433,21 +429,20 @@ fuseread(dev_t dev, struct uio *uio, int
 	if (error)
 		goto end;
 
-#ifdef FUSE_DEBUG
+#ifdef FUSEBUF_DEBUG
 	fuse_dump_buff((char *)fbuf, FUSEBUFSIZE);
 #endif
 	/* Restore kernel pointers */
 	memcpy(&fbuf->fb_next, &hdr.fh_next, sizeof(fbuf->fb_next));
 	fbuf->fb_dat = tmpaddr;
 
-	/* Remove the fbuf if it does not contains data */
+	/* Remove the fbuf if it does not contain data */
 	if (fbuf->fb_len == 0) {
 		SIMPLEQ_REMOVE_HEAD(&fd->fd_fbufs_in, fb_next);
 		stat_fbufs_in--;
 		SIMPLEQ_INSERT_TAIL(&fd->fd_fbufs_wait, fbuf, fb_next);
 		stat_fbufs_wait++;
 	}
-
 end:
 	return (error);
 }
@@ -479,8 +474,10 @@ fusewrite(dev_t dev, struct uio *uio, in
 
 		lastfbuf = fbuf;
 	}
-	if (fbuf == NULL)
+	if (fbuf == NULL) {
+		printf("fuse: Cannot find fusebuf\n");
 		return (EINVAL);
+	}
 
 	/* Update fb_hdr */
 	fbuf->fb_len = hdr.fh_len;
@@ -500,7 +497,7 @@ fusewrite(dev_t dev, struct uio *uio, in
 	if (error)
 		return error;
 	fbuf->fb_dat = NULL;
-#ifdef FUSE_DEBUG
+#ifdef FUSEBUF_DEBUG
 	fuse_dump_buff((char *)fbuf, FUSEBUFSIZE);
 #endif
 
@@ -513,7 +510,7 @@ fusewrite(dev_t dev, struct uio *uio, in
 		break ;
 	}
 end:
-	/* Remove the fbuf if it does not contains data */
+	/* Remove the fbuf if it does not contain data */
 	if (fbuf->fb_len == 0) {
 		if (fbuf == SIMPLEQ_FIRST(&fd->fd_fbufs_wait))
 			SIMPLEQ_REMOVE_HEAD(&fd->fd_fbufs_wait, fb_next);
Index: fuse_lookup.c
===================================================================
RCS file: /cvs/src/sys/miscfs/fuse/fuse_lookup.c,v
retrieving revision 1.10
diff -u -p -r1.10 fuse_lookup.c
--- fuse_lookup.c	16 Dec 2014 18:30:04 -0000	1.10
+++ fuse_lookup.c	21 Feb 2015 07:26:45 -0000
@@ -23,6 +23,7 @@
 #include <sys/vnode.h>
 #include <sys/lock.h>
 #include <sys/fusebuf.h>
+#include <sys/proc.h>
 
 #include "fusefs_node.h"
 #include "fusefs.h"
@@ -47,7 +48,7 @@ fusefs_lookup(void *v)
 	int nameiop = cnp->cn_nameiop;
 	int wantparent;
 	int error = 0;
-	uint64_t nid;
+	uint64_t nid = 0;
 
 	flags = cnp->cn_flags;
 	*vpp = NULL;
@@ -60,6 +61,7 @@ fusefs_lookup(void *v)
 	if ((error = VOP_ACCESS(vdp, VEXEC, cred, cnp->cn_proc)) != 0)
 		return (error);
 
+/* XXX What about CREATE? More efficient to check here no? */
 	if ((flags & ISLASTCN) && (vdp->v_mount->mnt_flag & MNT_RDONLY) &&
 	    (cnp->cn_nameiop == DELETE || cnp->cn_nameiop == RENAME))
 		return (EROFS);
@@ -87,16 +89,18 @@ fusefs_lookup(void *v)
 
 		error = fb_queue(fmp->dev, fbuf);
 
-		/* tsleep return */
-		if (error == EWOULDBLOCK)
-			goto out;
-
 		if (error) {
+			/* XXX Didn't we already check for RO above? */
 			if ((nameiop == CREATE || nameiop == RENAME) &&
 			    (flags & ISLASTCN)) {
 				if (vdp->v_mount->mnt_flag & MNT_RDONLY)
 					return (EROFS);
 
+				error = VOP_ACCESS(vdp, VWRITE, cred,
+				    cnp->cn_proc);
+				if (error)
+					goto out;
+
 				cnp->cn_flags |= SAVENAME;
 
 				if (!lockparent) {
@@ -108,7 +112,7 @@ fusefs_lookup(void *v)
 				goto out;
 			}
 
-			error = ENOENT;
+			//error = ENOENT;
 			goto out;
 		}
 
@@ -132,7 +136,7 @@ fusefs_lookup(void *v)
 		/*
 		 * Write access to directory required to delete files.
 		 */
-		if ((error = VOP_ACCESS(vdp, VWRITE, cred, cnp->cn_proc)) != 0) {
+		if ((error = VOP_ACCESS(vdp, VWRITE, cred, cnp->cn_proc))) {
 			fb_delete(fbuf);
 			return (error);
 		}
Index: fuse_vfsops.c
===================================================================
RCS file: /cvs/src/sys/miscfs/fuse/fuse_vfsops.c,v
retrieving revision 1.15
diff -u -p -r1.15 fuse_vfsops.c
--- fuse_vfsops.c	23 Dec 2014 04:54:45 -0000	1.15
+++ fuse_vfsops.c	21 Feb 2015 07:26:45 -0000
@@ -133,19 +133,13 @@ fusefs_unmount(struct mount *mp, int mnt
 {
 	struct fusefs_mnt *fmp;
 	struct fusebuf *fbuf;
-	extern int doforce;
 	int flags = 0;
 	int error;
 
 	fmp = VFSTOFUSEFS(mp);
 
-	if (mntflags & MNT_FORCE) {
-		/* fusefs can never be rootfs so don't check for it */
-		if (!doforce)
-			return (EINVAL);
-
+	if (mntflags & MNT_FORCE)
 		flags |= FORCECLOSE;
-	}
 
 	if ((error = vflush(mp, NULLVP, flags)))
 		return (error);
@@ -176,7 +170,9 @@ fusefs_root(struct mount *mp, struct vno
 	struct fusefs_node *ip;
 	int error;
 
-	if ((error = VFS_VGET(mp, (ino_t)FUSE_ROOTINO, &nvp)) != 0)
+	DPRINTF("fusefs_root:\n");
+
+	if ((error = VFS_VGET(mp, FUSE_ROOTINO, &nvp)))
 		return (error);
 
 	ip = VTOI(nvp);
@@ -201,6 +197,8 @@ fusefs_statfs(struct mount *mp, struct s
 	struct fusebuf *fbuf;
 	int error;
 
+	DPRINTF("fusefs_statfs:\n");
+
 	fmp = VFSTOFUSEFS(mp);
 
 	if (fmp->sess_init) {
@@ -249,6 +247,9 @@ fusefs_vget(struct mount *mp, ino_t ino,
 	struct vnode *nvp;
 	int i;
 	int error;
+
+	DPRINTF("fusefs_vget: %u\n", (unsigned int)ino);
+
 retry:
 	fmp = VFSTOFUSEFS(mp);
 	/*
@@ -260,12 +261,15 @@ retry:
 	/*
 	 * if not create it
 	 */
-	if ((error = getnewvnode(VT_FUSEFS, mp, &fusefs_vops, &nvp)) != 0) {
+	if ((error = getnewvnode(VT_FUSEFS, mp, &fusefs_vops, &nvp))) {
 		printf("fusefs: getnewvnode error\n");
 		*vpp = NULLVP;
 		return (error);
 	}
 
+#ifdef VFSLCKDEBUG
+	nvp->v_flag |= VLOCKSWORK;
+#endif
 	ip = malloc(sizeof(*ip), M_FUSEFS, M_WAITOK | M_ZERO);
 	lockinit(&ip->ufs_ino.i_lock, PINOD, "fuseinode", 0, 0);
 	nvp->v_data = ip;
Index: fuse_vnops.c
===================================================================
RCS file: /cvs/src/sys/miscfs/fuse/fuse_vnops.c,v
retrieving revision 1.23
diff -u -p -r1.23 fuse_vnops.c
--- fuse_vnops.c	19 Feb 2015 10:22:20 -0000	1.23
+++ fuse_vnops.c	21 Feb 2015 07:26:46 -0000
@@ -21,6 +21,7 @@
 #include <sys/fcntl.h>
 #include <sys/file.h>
 #include <sys/lockf.h>
+#include <sys/rwlock.h>
 #include <sys/malloc.h>
 #include <sys/mount.h>
 #include <sys/namei.h>
@@ -227,6 +228,8 @@ fusefs_open(void *v)
 	int error;
 	int isdir;
 
+	DPRINTF("%s:\n", __func__);
+
 	ap = v;
 	ip = VTOI(ap->a_vp);
 	fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump;
@@ -267,6 +270,8 @@ fusefs_close(void *v)
 	enum fufh_type fufh_type = FUFH_RDONLY;
 	int isdir, i;
 
+	DPRINTF("%s:\n", __func__);
+
 	ap = v;
 	ip = VTOI(ap->a_vp);
 	fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump;
@@ -317,6 +322,8 @@ fusefs_access(void *v)
 	uint32_t mask = 0;
 	int error = 0;
 
+	DPRINTF("%s:\n", __func__);
+
 	ap = v;
 	p = ap->a_p;
 	cred = p->p_ucred;
@@ -387,6 +394,8 @@ fusefs_getattr(void *v)
 	struct fusebuf *fbuf;
 	int error = 0;
 
+	DPRINTF("%s:\n", __func__);
+
 	ip = VTOI(vp);
 	fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump;
 
@@ -412,14 +421,18 @@ fusefs_setattr(void *v)
 {
 	struct vop_setattr_args *ap = v;
 	struct vattr *vap = ap->a_vap;
+	struct vattr vattr;
 	struct vnode *vp = ap->a_vp;
 	struct fusefs_node *ip = VTOI(vp);
+	struct ucred *cred = ap->a_cred;
 	struct proc *p = ap->a_p;
 	struct fusefs_mnt *fmp;
 	struct fusebuf *fbuf;
 	struct fb_io *io;
 	int error = 0;
 
+	DPRINTF("%s:\n", __func__);
+
 	fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump;
 	/*
 	 * Check for unsettable attributes.
@@ -436,6 +449,10 @@ fusefs_setattr(void *v)
 	if (fmp->undef_op & UNDEF_SETATTR)
 		return (ENOSYS);
 
+	/* Find out who the current owner is etc. to check perms */
+	if ((error = VOP_GETATTR(vp, &vattr, cred, p)))
+		return (error);
+
 	fbuf = fb_setup(sizeof(*io), ip->ufs_ino.i_number, FBT_SETATTR, p);
 	io = fbtod(fbuf, struct fb_io *);
 	io->fi_flags = 0;
@@ -445,6 +462,16 @@ fusefs_setattr(void *v)
 			error = EROFS;
 			goto out;
 		}
+
+		/*
+		 * If we want to change the owner of the file, the caller must
+		 * be superuser or the call fails.
+		 */
+		if ((vap->va_uid != vattr.va_uid ||
+		     cred->cr_uid != vattr.va_uid) &&
+		    (error = suser_ucred(cred)))
+			goto out;
+
 		fbuf->fb_vattr.va_uid = vap->va_uid;
 		io->fi_flags |= FUSE_FATTR_UID;
 	}
@@ -454,6 +481,18 @@ fusefs_setattr(void *v)
 			error = EROFS;
 			goto out;
 		}
+
+		/*
+		 * If we don't own the file, are trying to change the group of
+		 * the file, or are not a member of the target group, the
+		 * caller must be superuser or the call fails.
+		 */
+		if ((cred->cr_uid != vattr.va_uid ||
+		     (vap->va_gid != vattr.va_gid &&
+		      !groupmember((gid_t)vap->va_gid, cred))) &&
+		    (error = suser_ucred(cred)))
+			goto out;
+
 		fbuf->fb_vattr.va_gid = vap->va_gid;
 		io->fi_flags |= FUSE_FATTR_GID;
 	}
@@ -478,21 +517,26 @@ fusefs_setattr(void *v)
 		io->fi_flags |= FUSE_FATTR_SIZE;
 	}
 
-	if (vap->va_atime.tv_sec != VNOVAL) {
+	if (vap->va_atime.tv_sec != VNOVAL ||
+	    vap->va_mtime.tv_sec != VNOVAL) {
 		if (vp->v_mount->mnt_flag & MNT_RDONLY) {
 			error = EROFS;
 			goto out;
 		}
+		if (cred->cr_uid != vattr.va_uid &&
+		    (error = suser_ucred(cred)) &&
+		    ((vap->va_vaflags & VA_UTIMES_NULL) == 0 || 
+		    (error = VOP_ACCESS(vp, VWRITE, cred, p))))
+			goto out;
+	}
+
+	if (vap->va_atime.tv_sec != VNOVAL) {
 		fbuf->fb_vattr.va_atime.tv_sec = vap->va_atime.tv_sec;
 		fbuf->fb_vattr.va_atime.tv_nsec = vap->va_atime.tv_nsec;
 		io->fi_flags |= FUSE_FATTR_ATIME;
 	}
 
 	if (vap->va_mtime.tv_sec != VNOVAL) {
-		if (vp->v_mount->mnt_flag & MNT_RDONLY) {
-			error = EROFS;
-			goto out;
-		}
 		fbuf->fb_vattr.va_mtime.tv_sec = vap->va_mtime.tv_sec;
 		fbuf->fb_vattr.va_mtime.tv_nsec = vap->va_mtime.tv_nsec;
 		io->fi_flags |= FUSE_FATTR_MTIME;
@@ -503,6 +547,12 @@ fusefs_setattr(void *v)
 			error = EROFS;
 			goto out;
 		}
+
+		/* Only the owner or root can chmod */
+		if (cred->cr_uid != vattr.va_uid &&
+		    (error = suser_ucred(cred)))
+			goto out;
+
 		fbuf->fb_vattr.va_mode = vap->va_mode & ALLPERMS;
 		io->fi_flags |= FUSE_FATTR_MODE;
 	}
@@ -511,11 +561,6 @@ fusefs_setattr(void *v)
 		goto out;
 	}
 
-	if (io->fi_flags & FUSE_FATTR_SIZE && vp->v_type == VDIR) {
-		error = EISDIR;
-		goto out;
-	}
-
 	error = fb_queue(fmp->dev, fbuf);
 
 	if (error) {
@@ -536,6 +581,7 @@ out:
 int
 fusefs_ioctl(void *v)
 {
+	DPRINTF("%s:\n", __func__);
 	return (ENOTTY);
 }
 
@@ -553,6 +599,8 @@ fusefs_link(void *v)
 	struct fusebuf *fbuf;
 	int error = 0;
 
+	DPRINTF("%s:\n", __func__);
+
 	ip = VTOI(vp);
 	dip = VTOI(dvp);
 	fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump;
@@ -627,6 +675,8 @@ fusefs_symlink(void *v)
 	int error = 0;
 	int len;
 
+	DPRINTF("%s:\n", __func__);
+
 	dp = VTOI(dvp);
 	fmp = (struct fusefs_mnt *)dp->ufs_ino.i_ump;
 
@@ -695,6 +745,8 @@ fusefs_readdir(void *v)
 	ip = VTOI(vp);
 	fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump;
 
+	DPRINTF("%s: %lu\n", __func__, (unsigned long)ip->ufs_ino.i_number);
+
 	if (!fmp->sess_init)
 		return (ENXIO);
 
@@ -707,7 +759,7 @@ fusefs_readdir(void *v)
 		if (ip->fufh[FUFH_RDONLY].fh_type == FUFH_INVALID) {
 			/* TODO open the file */
 			fb_delete(fbuf);
-			return (error);
+			return (EBADF);
 		}
 		fbuf->fb_io_fd = ip->fufh[FUFH_RDONLY].fh_id;
 		fbuf->fb_io_off = uio->uio_offset;
@@ -755,6 +807,8 @@ fusefs_inactive(void *v)
 	int error = 0;
 	int type;
 
+	DPRINTF("%s:\n", __func__);
+
 	fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump;
 
 	for (type = 0; type < FUFH_MAXTYPE; type++) {
@@ -786,6 +840,8 @@ fusefs_readlink(void *v)
 	struct proc *p;
 	int error = 0;
 
+	DPRINTF("%s:\n", __func__);
+
 	ip = VTOI(vp);
 	fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump;
 	uio = ap->a_uio;
@@ -826,6 +882,12 @@ fusefs_reclaim(void *v)
 	struct fusebuf *fbuf;
 	int type;
 
+	DPRINTF("%s:\n", __func__);
+
+#ifdef DIAGNOSTIC
+	if (VOP_ISLOCKED(vp))
+		panic("fusefs: reclaim vnode still locked\n");
+#endif
 	fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump;
 
 	/*close opened files*/
@@ -870,10 +932,12 @@ fusefs_print(void *v)
 	struct vop_print_args *ap = v;
 	struct vnode *vp = ap->a_vp;
 	struct fusefs_node *ip = VTOI(vp);
+	struct rrwlock *lck = &(ip->ufs_ino.i_lock.lk_lck);
+	struct proc *p = RWLOCK_OWNER(&lck->rrwl_lock);
 
 	/* Complete the information given by vprint(). */
 	printf("tag VT_FUSE, hash id %u ", ip->ufs_ino.i_number);
-	lockmgr_printinfo(&ip->ufs_ino.i_lock);
+        printf(" %d %u\n", p == NULL ? 0 : p->p_pid, lck->rrwl_wcnt);
 	printf("\n");
 	return (0);
 }
@@ -898,6 +962,9 @@ fusefs_create(void *v)
 	fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump;
 	mode = MAKEIMODE(vap->va_type, vap->va_mode);
 
+	DPRINTF("%s: %u %s %d\n", __func__, ip->ufs_ino.i_number,
+	    cnp->cn_nameptr, p->p_pid);
+
 	if (!fmp->sess_init) {
 		error = ENXIO;
 		goto out;
@@ -960,6 +1027,8 @@ fusefs_mknod(void *v)
 	struct fusebuf *fbuf;
 	int error = 0;
 
+	DPRINTF("%s:\n", __func__);
+
 	ip = VTOI(dvp);
 	fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump;
 
@@ -1035,6 +1104,8 @@ fusefs_read(void *v)
 	size_t size;
 	int error=0;
 
+	DPRINTF("%s:\n", __func__);
+
 	ip = VTOI(vp);
 	fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump;
 
@@ -1089,6 +1160,8 @@ fusefs_write(void *v)
 	size_t len, diff;
 	int error=0;
 
+	DPRINTF("%s:\n", __func__);
+
 	ip = VTOI(vp);
 	fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump;
 
@@ -1144,6 +1217,8 @@ fusefs_poll(void *v)
 {
 	struct vop_poll_args *ap = v;
 
+	DPRINTF("%s:\n", __func__);
+
 	/*
 	 * We should really check to see if I/O is possible.
 	 */
@@ -1166,6 +1241,8 @@ fusefs_rename(void *v)
 	struct fusebuf *fbuf;
 	int error = 0;
 
+	DPRINTF("%s:\n", __func__);
+
 #ifdef DIAGNOSTIC
 	if ((tcnp->cn_flags & HASBUF) == 0 ||
 	    (fcnp->cn_flags & HASBUF) == 0)
@@ -1264,6 +1341,9 @@ abortit:
 	VN_KNOTE(fvp, NOTE_RENAME);
 
 	VOP_UNLOCK(fvp, 0, p);
+	if (tvp)
+		vput(tvp);
+
 	if (tdvp == tvp)
 		vrele(tdvp);
 	else
@@ -1289,6 +1369,8 @@ fusefs_mkdir(void *v)
 	struct fusebuf *fbuf;
 	int error = 0;
 
+	DPRINTF("%s:\n", __func__);
+
 	ip = VTOI(dvp);
 	fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump;
 
@@ -1351,6 +1433,8 @@ fusefs_rmdir(void *v)
 	struct fusebuf *fbuf;
 	int error;
 
+	DPRINTF("%s:\n", __func__);
+
 	ip = VTOI(vp);
 	dp = VTOI(dvp);
 	fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump;
@@ -1421,6 +1505,8 @@ fusefs_remove(void *v)
 	struct fusebuf *fbuf;
 	int error = 0;
 
+	DPRINTF("%s:\n", __func__);
+
 	ip = VTOI(vp);
 	dp = VTOI(dvp);
 	fmp = (struct fusefs_mnt *)ip->ufs_ino.i_ump;
@@ -1435,6 +1521,9 @@ fusefs_remove(void *v)
 		goto out;
 	}
 
+	DPRINTF("%s: %lu %u %u %s:\n", __func__, (unsigned long) 
+	    ip->ufs_ino.i_number, vp->v_usecount, p->p_pid, p->p_comm);
+
 	fbuf = fb_setup(cnp->cn_namelen + 1, dp->ufs_ino.i_number,
 	    FBT_UNLINK, p);
 	memcpy(fbuf->fb_dat, cnp->cn_nameptr, cnp->cn_namelen);
@@ -1464,6 +1553,7 @@ out:
 int
 fusefs_strategy(void *v)
 {
+	DPRINTF("%s:\n", __func__);
 	return (0);
 }
 
@@ -1473,6 +1563,15 @@ fusefs_lock(void *v)
 	struct vop_lock_args *ap = v;
 	struct vnode *vp = ap->a_vp;
 
+#ifdef FUSE_DEBUG
+	struct lock *lckp = &VTOI(vp)->ufs_ino.i_lock;
+	DPRINTF("%s:   %u %u %d %s:\n", __func__, VTOI(vp)->ufs_ino.i_number,
+	    vp->v_usecount, curproc->p_pid, curproc->p_comm);
+	if (lockstatus(lckp)) {
+		DPRINTF("%s: potential deadlock\n", __func__);
+	}
+#endif
+
 	return (lockmgr(&VTOI(vp)->ufs_ino.i_lock, ap->a_flags, NULL));
 }
 
@@ -1482,6 +1581,9 @@ fusefs_unlock(void *v)
 	struct vop_unlock_args *ap = v;
 	struct vnode *vp = ap->a_vp;
 
+	DPRINTF("%s: %u %u %d %s:\n", __func__, VTOI(vp)->ufs_ino.i_number,
+	    vp->v_usecount, curproc->p_pid, curproc->p_comm);
+
 	return (lockmgr(&VTOI(vp)->ufs_ino.i_lock, ap->a_flags | LK_RELEASE,
 	    NULL));
 }
@@ -1491,6 +1593,9 @@ fusefs_islocked(void *v)
 {
 	struct vop_islocked_args *ap = v;
 
+	DPRINTF("%s: %lu\n", __func__,
+	    (unsigned long) VTOI(ap->a_vp)->ufs_ino.i_number);
+
 	return (lockstatus(&VTOI(ap->a_vp)->ufs_ino.i_lock));
 }
 
@@ -1500,6 +1605,7 @@ fusefs_advlock(void *v)
 	struct vop_advlock_args *ap = v;
 	struct fusefs_node *ip = VTOI(ap->a_vp);
 
+	DPRINTF("%s:\n", __func__);
 	return (lf_advlock(&ip->ufs_ino.i_lockf, ip->filesize, ap->a_id,
 	    ap->a_op, ap->a_fl, ap->a_flags));
 }
Index: fusebuf.c
===================================================================
RCS file: /cvs/src/sys/miscfs/fuse/fusebuf.c,v
retrieving revision 1.10
diff -u -p -r1.10 fusebuf.c
--- fusebuf.c	3 Dec 2014 23:00:49 -0000	1.10
+++ fusebuf.c	21 Feb 2015 07:26:46 -0000
@@ -55,7 +55,7 @@ fb_queue(dev_t dev, struct fusebuf *fbuf
 
 	fuse_device_queue_fbuf(dev, fbuf);
 
-	if ((error = tsleep(fbuf, PWAIT, "fuse msg", TSLEEP_TIMEOUT * hz))) {
+	if ((error = tsleep(fbuf, PWAIT, "fuse", 0))) {
 		fuse_device_cleanup(dev, fbuf);
 		return (error);
 	}
Index: fusefs.h
===================================================================
RCS file: /cvs/src/sys/miscfs/fuse/fusefs.h,v
retrieving revision 1.7
diff -u -p -r1.7 fusefs.h
--- fusefs.h	20 May 2014 13:32:22 -0000	1.7
+++ fusefs.h	21 Feb 2015 07:26:46 -0000
@@ -92,5 +92,11 @@ void fuse_device_set_fmp(struct fusefs_m
 #define	FUSE_ROOTINO ((ino_t)1)
 #define VFSTOFUSEFS(mp)	((struct fusefs_mnt *)((mp)->mnt_data))
 
+#ifdef  FUSE_DEBUG
+#define DPRINTF(fmt, arg...)    printf("%s: " fmt, "fuse", ##arg)
+#else
+#define DPRINTF(fmt, arg...)
+#endif
+
 #endif /* _KERNEL */
 #endif /* __FUSEFS_H__ */
