Date: Tue, 10 Apr 2007 11:29:20 GMT From: Robert Watson <rwatson@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 117827 for review Message-ID: <200704101129.l3ABTKur076418@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=117827 Change 117827 by rwatson@rwatson_cinnamon_afs on 2007/04/10 11:29:12 Integrate 2007/04/07 Arla CVS export into Arla project work branch. Brings in many adaptations of Arla by tol@ for more recent FreeBSD versions. Affected files ... .. //depot/projects/arla/sys/fs/nnpfs/Makefile.in#2 integrate .. //depot/projects/arla/sys/fs/nnpfs/arla-pioctl.h#2 integrate .. //depot/projects/arla/sys/fs/nnpfs/nnpfs/nnpfs_blocks.h#2 integrate .. //depot/projects/arla/sys/fs/nnpfs/nnpfs_blocks.c#2 integrate .. //depot/projects/arla/sys/fs/nnpfs/nnpfs_dev-bsd.c#2 integrate .. //depot/projects/arla/sys/fs/nnpfs/nnpfs_dev-common.c#2 integrate .. //depot/projects/arla/sys/fs/nnpfs/nnpfs_dev-freebsd.c#2 integrate .. //depot/projects/arla/sys/fs/nnpfs/nnpfs_dev-netbsd.c#2 integrate .. //depot/projects/arla/sys/fs/nnpfs/nnpfs_dev-openbsd.c#2 integrate .. //depot/projects/arla/sys/fs/nnpfs/nnpfs_message.c#3 integrate .. //depot/projects/arla/sys/fs/nnpfs/nnpfs_node-bsd.c#3 integrate .. //depot/projects/arla/sys/fs/nnpfs/nnpfs_syscalls-common.c#2 integrate .. //depot/projects/arla/sys/fs/nnpfs/nnpfs_vfsops-bsd.c#3 integrate .. //depot/projects/arla/sys/fs/nnpfs/nnpfs_vfsops-common.c#2 integrate .. //depot/projects/arla/sys/fs/nnpfs/nnpfs_vfsops-freebsd.c#3 integrate .. //depot/projects/arla/sys/fs/nnpfs/nnpfs_vnodeops-bsd.c#3 integrate .. //depot/projects/arla/sys/fs/nnpfs/nnpfs_vnodeops-common.c#3 integrate .. //depot/projects/arla/sys/fs/nnpfs/nnpfs_wrap-bsd.c#3 integrate Differences ... ==== //depot/projects/arla/sys/fs/nnpfs/Makefile.in#2 (text+ko) ==== @@ -1,4 +1,4 @@ -# $Id: Makefile.in,v 1.75 2006/10/24 16:33:00 tol Exp $ +# $Id: Makefile.in,v 1.76 2007/03/27 13:24:25 tol Exp $ SHELL = /bin/sh @@ -39,7 +39,7 @@ -I../../include -I$(srcdir)/../../include \ -I$(srcdir)/../include -DEFS = @DEFS@ $(INCDEFS) -DNNPFS_DEBUG @ARLA_KNFS@ +DEFS = @DEFS@ $(INCDEFS) -DNNPFS_DEBUG CFLAGS = @CFLAGS@ @KERNEL_CFLAGS@ @KERNEL_CPPFLAGS@ -Wno-unused @BSD_WERROR@ SYS = @SYS@ ==== //depot/projects/arla/sys/fs/nnpfs/arla-pioctl.h#2 (text+ko) ==== @@ -31,7 +31,7 @@ * SUCH DAMAGE. */ -/* $Id: arla-pioctl.h,v 1.6 2005/11/17 09:49:22 tol Exp $ */ +/* $Id: arla-pioctl.h,v 1.8 2007/01/24 22:44:15 lha Exp $ */ #ifndef __ARLA_PIOCT_H #define __ARLA_PIOCT_H @@ -157,6 +157,16 @@ #define ARLA_AFSCOMMONIOC_NEWALIAS arla_AFSCOMMONIOCTL(1) /* common: ... */ #define ARLA_AFSCOMMONIOC_LISTALIAS arla_AFSCOMMONIOCTL(2) /* common: ... */ +#define ARLA_VIOCGETTOK2 arla_AFSCOMMONIOCTL(7) +#define ARLA_VIOCSETTOK2 arla_AFSCOMMONIOCTL(8) + +#define ARLA_TOKEN_TYPE_NULL 0 +/* secindex 1 was used for vab */ +#define ARLA_TOKEN_TYPE_KAD 2 +/* secindex 3 was used for broken rxkad cryptall */ +#define ARLA_TOKEN_TYPE_K5 4 +#define ARLA_TOKEN_TYPE_GK 5 + /* * GETCELLSTATUS flags */ ==== //depot/projects/arla/sys/fs/nnpfs/nnpfs/nnpfs_blocks.h#2 (text+ko) ==== @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005-2006, Stockholms Universitet + * Copyright (c) 2005-2007, Stockholms Universitet * (Stockholm University, Stockholm Sweden) * All rights reserved. * @@ -31,11 +31,15 @@ * POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: nnpfs_blocks.h,v 1.2 2006/10/24 16:33:31 tol Exp $ */ +/* $Id: nnpfs_blocks.h,v 1.3 2007/01/24 17:09:17 tol Exp $ */ #define NNPFS_NO_INDEX 0 /* dummy cache index */ #define NNPFS_NO_OFFSET ((uint64_t)-1) /* dummy offset, no block */ -#define NNPFS_CACHE_FILE_PATH "%02X/%02X/%02llX" -#define NNPFS_CACHE_DIR_PATH "%02X/%02X@" -#define NNPFS_CACHE_PATH_SIZE ( 6 +1 +2+1 +16 +1) +#define NNPFS_CACHE_FILE_DIR1 "%02x" +#define NNPFS_CACHE_FILE_DIR_PATH NNPFS_CACHE_FILE_DIR1 "/" NNPFS_CACHE_FILE_DIR1 +#define NNPFS_CACHE_FILE_BLOCK_PATH "%02llx" + +#define NNPFS_CACHE_FILE_PATH NNPFS_CACHE_FILE_DIR_PATH "/" NNPFS_CACHE_FILE_BLOCK_PATH +#define NNPFS_CACHE_DIR_PATH NNPFS_CACHE_FILE_DIR_PATH "@" +#define NNPFS_CACHE_PATH_SIZE ( 6 +1 +2+1 +16 +1 ) ==== //depot/projects/arla/sys/fs/nnpfs/nnpfs_blocks.c#2 (text+ko) ==== @@ -1,5 +1,5 @@ /* - * Copyright (c) 2005-2006, Stockholms Universitet + * Copyright (c) 2005-2007, Stockholms Universitet * (Stockholm University, Stockholm Sweden) * All rights reserved. * @@ -31,13 +31,17 @@ * POSSIBILITY OF SUCH DAMAGE. */ -/* $Id: nnpfs_blocks.c,v 1.4 2007/01/08 13:10:29 tol Exp $ */ +/* $Id: nnpfs_blocks.c,v 1.10 2007/03/28 12:05:45 tol Exp $ */ #include <nnpfs/nnpfs_locl.h> #include <nnpfs/nnpfs_fs.h> #include <nnpfs/nnpfs_dev.h> #include <nnpfs/nnpfs_deb.h> +#include <nnpfs/nnpfs_vnodeops.h> +#include <nnpfs/nnpfs_common.h> +#include <nnpfs/nnpfs_node.h> + /* * return true if block is in cache */ @@ -259,14 +263,18 @@ } static int -nnpfs_block_extend_int(struct nnpfs_node *node, struct vnode *vp) +nnpfs_block_extend_int(struct nnpfs_node *node, struct vnode *vp, d_thread_t *p) { struct nnpfs_vfs_vattr va; int ret; VATTR_INIT(&va); nnpfs_set_va_size(&va, nnpfs_blocksize); + nnpfs_vfs_writelock(vp, p); + + /* printf("nnpfs extend_int(%p)\n", vp); */ ret = nnpfs_vnode_setattr(vp, &va, NNPFS_FROM_XNODE(node)->ctx); + nnpfs_vfs_unlock(vp, p); nnpfs_debug_assert(!ret); return ret; } @@ -278,16 +286,35 @@ static int nnpfs_block_extend(struct nnpfs_node *node, uint64_t offset) { + d_thread_t *p = nnpfs_curproc(); struct vnode *vp; int ret; nnpfs_assert(nnpfs_block_have_p(node, offset)); - - ret = nnpfs_block_open(node, offset, O_RDWR|FWRITE, &vp); + + ret = nnpfs_block_open(node, offset, FREAD|FWRITE, &vp); if (!ret) { nnpfs_assert(vp); - ret = nnpfs_block_extend_int(node, vp); - nnpfs_block_close(vp, 1); + +#ifdef __FreeBSD__ + { + struct mount *mp; + + (void)vn_start_write(vp, &mp, V_WAIT); + VOP_LEASE(vp, p, + nnpfs_vfs_context_ucred(NNPFS_FROM_XNODE(node)->ctx), + LEASE_WRITE); + + ret = nnpfs_block_extend_int(node, vp, p); + + VOP_UNLOCK(vp, 0, p); + vn_finished_write(mp); + } +#else + ret = nnpfs_block_extend_int(node, vp, p); +#endif + + nnpfs_block_close(node, vp, 1); } if (ret) @@ -297,6 +324,61 @@ return ret; } +#ifndef __APPLE__ +/* + * namei() compatible alloc/free + */ + +static long nnpfs_namei_allocs, nnpfs_namei_frees; +static void +nnpfs_namei_alloc(struct componentname *cnp) +{ + void *p = NULL; + + if (cnp->cn_flags & HASBUF) { + printf("nnpfs_namei_alloc: cnp flags 0x%lx\n", cnp->cn_flags); + return; + } + +#ifdef __FreeBSD__ + p = uma_zalloc(namei_zone, M_WAITOK); +#endif +#ifdef __OpenBSD__ + p = pool_get(&namei_pool, PR_WAITOK); +#endif +#ifdef __NetBSD__ + p = PNBUF_GET(); +#endif + if (p) { + cnp->cn_pnbuf = p; + cnp->cn_flags |= HASBUF; + nnpfs_namei_allocs++; + } +} + +static void +nnpfs_namei_free(struct componentname *cnp) +{ + if ((cnp->cn_flags & HASBUF) == 0) + return; + +#ifdef __FreeBSD__ + uma_zfree(namei_zone, cnp->cn_pnbuf); +#endif +#ifdef __NetBSD__ + PNBUF_PUT(cnp->cn_pnbuf); +#endif +#ifdef __OpenBSD__ + pool_put(&namei_pool, cnp->cn_pnbuf); +#endif + + cnp->cn_flags &= ~HASBUF; + nnpfs_namei_frees++; +} + +#endif /* !__APPLE__ */ + + /* * a handy implementation of open() * @@ -304,38 +386,139 @@ */ static int -open_file(const char *name, int fmode, - nnpfs_vfs_context ctx, struct vnode **vp) +open_file(struct vnode *cachedir, char *name, int fmode, + nnpfs_vfs_context ctx, struct vnode **vpp) { int error; #ifdef __APPLE__ /* XXX */ - error = vnode_open(name, fmode, S_IRUSR|S_IWUSR, 0, vp, ctx); + error = vnode_open(name, fmode, S_IRUSR|S_IWUSR, 0, vpp, ctx); #else { - struct nameidata nd, *ndp = &nd; d_thread_t *p = nnpfs_curproc(); - nnpfs_kernel_cred cred = nnpfs_proc_to_cred(p); + nnpfs_kernel_cred cred = nnpfs_vfs_context_ucred(ctx); + /* nnpfs_kernel_cred cred = nnpfs_proc_to_cred(p); */ + struct nameidata nd; + + memset(&nd, 0, sizeof(nd)); + + if (fmode & O_CREAT) { + NDINIT(&nd, CREATE, + FOLLOW | LOCKLEAF | LOCKPARENT | SAVENAME | NNPFS_MPSAFE, + UIO_SYSSPACE, name, p); + } else { + NDINIT(&nd, LOOKUP, FOLLOW | LOCKLEAF | NNPFS_MPSAFE, UIO_SYSSPACE, name, p); + } + + nd.ni_cnd.cn_cred = cred; + nd.ni_startdir = cachedir; + + nnpfs_namei_alloc(&nd.ni_cnd); + nd.ni_cnd.cn_nameptr = nd.ni_cnd.cn_pnbuf; + + error = copystr(name, nd.ni_cnd.cn_pnbuf, MAXPATHLEN, &nd.ni_pathlen); + if (error == 0 && nd.ni_pathlen == 1) + error = ENOENT; - NDINIT(ndp, LOOKUP, 0, UIO_SYSSPACE, name, - nnpfs_vfs_context_proc(ctx)); - - error = namei(ndp); - if (error != 0) + if (error) { + nnpfs_namei_free(&nd.ni_cnd); + printf("nnpfs open_file(%p, %s) copystr -> %d\n", + cachedir, name, error); + return error; + } + +#ifdef __FreeBSD__ + if ((fmode & O_ACCMODE) != FREAD) + bwillwrite(); /* do this before getting devlock? */ +#endif + /* XXX vn_start_write() etc? */ + + nnpfs_vref(cachedir); + + error = lookup(&nd); + if (error) { + nnpfs_namei_free(&nd.ni_cnd); + printf("lookup(%s) -> %d\n", name, error); return error; + } + + if (fmode & O_CREAT && nd.ni_vp) { + fmode &= ~O_CREAT; + + nnpfs_vfs_unlock(cachedir, p); + } - *vp = ndp->ni_vp; + if (fmode & O_CREAT) { + struct vattr vat; + struct mount *mp; + + if ((nd.ni_cnd.cn_flags & SAVENAME) == 0) { + nnpfs_namei_free(&nd.ni_cnd); + printf("lookup: not SAVENAME, flags 0x%lx\n", nd.ni_cnd.cn_flags); + return EINVAL; + } + + VATTR_NULL(&vat); + vat.va_type = VREG; + vat.va_mode = S_IRUSR|S_IWUSR; + if ((nd.ni_cnd.cn_flags & HASBUF) == 0) + panic("HASBUF was cleared\n"); + + /* nd.ni_cnd.cn_flags |= HASBUF; */ + +#ifdef __FreeBSD__ + (void)vn_start_write(cachedir, &mp, V_WAIT); /* V_NOWAIT? */ +#endif + VOP_LEASE(cachedir, p, cred, LEASE_WRITE); + error = VOP_CREATE(cachedir, vpp, &nd.ni_cnd, &vat); + +#ifdef __FreeBSD__ + nnpfs_namei_free(&nd.ni_cnd); + nnpfs_vfs_unlock(cachedir, p); + vn_finished_write(mp); +#else + /* NetBSD and OpenBSD releases buf w/o clearing HASBUF */ + nd.ni_cnd.cn_flags &= ~HASBUF; + nnpfs_namei_frees++; +#endif + + if (error) { + printf("nnpfs open_file(%p, %s) create -> %d\n", + cachedir, name, error); + return error; + } + } else { + *vpp = nd.ni_vp; + nnpfs_namei_free(&nd.ni_cnd); + } -#if defined(__FreeBSD__) && __FreeBSD_version >= 502000 - error = VOP_OPEN(*vp, fmode & (FWRITE|FREAD), cred, p, -1); +#if defined(__FreeBSD__) && 0 + if (nd.ni_vp + && vn_canvmio(nd.ni_vp) == TRUE + && ((nd.ni_cnd.cn_flags & (NOOBJ|LOCKLEAF)) == LOCKLEAF)) + vfs_object_create(nd.ni_vp, p, cred); +#endif + +#ifdef __FreeBSD__ + error = VOP_OPEN(*vpp, fmode, cred, p, -1); #else - error = VOP_OPEN(*vp, fmode & (FWRITE|FREAD), cred, p); + error = VOP_OPEN(*vpp, fmode, cred, p); #endif - if (error) - nnpfs_vletgo(*vp); + + if (error) { + nnpfs_vput(*vpp); + } else { + if (fmode & FWRITE) + (*vpp)->v_writecount++; + + nnpfs_vfs_unlock(*vpp, p); + } } -#endif + +#endif /* !__APPLE__! */ + NNPFSDEB(XDEBNODE, ("nnpfs open_file(%p, %s) -> %d (%p)\n", + cachedir, name, error, *vpp)); return error; } @@ -349,52 +532,88 @@ { char cachename[NNPFS_CACHE_PATH_SIZE]; uint64_t blockindex = nnpfs_block_index(offset); - uint32_t id = node->index; struct nnpfs *nnpfsp = NNPFS_FROM_XNODE(node); off_t eof = nnpfs_vattr_get_size(&node->attr); int ret; + NNPFSDEB(XDEBNODE, ("nnpfs_block_open(0x%llx)\n", (unsigned long long)offset)); + nnpfs_assert(nnpfsp); nnpfs_assert(nnpfs_block_have_p(node, offset) || (flags & O_CREAT)); - if (nnpfs_vnode_isdir(XNODE_TO_VNODE(node))) + if (nnpfs_vnode_isdir(XNODE_TO_VNODE(node))) { + nnpfs_assert((flags & O_CREAT) == 0); + *vpp = node->cache_vn; + ret = 0; + } else { +#ifdef __APPLE__ ret = snprintf(cachename, sizeof(cachename), - NNPFS_CACHE_DIR_PATH, - id / 0x100, id % 0x100); - else + NNPFS_CACHE_FILE_PATH, + node->index / 0x100, node->index % 0x100, + (unsigned long long)blockindex); +#else ret = snprintf(cachename, sizeof(cachename), - NNPFS_CACHE_FILE_PATH, - id / 0x100, id % 0x100, + NNPFS_CACHE_FILE_BLOCK_PATH, (unsigned long long)blockindex); +#endif - nnpfs_assert(ret > 0 && ret < sizeof(cachename)); + nnpfs_assert(ret > 0 && ret < sizeof(cachename)); /* XXX */ + + ret = open_file(node->cache_vn, cachename, flags, nnpfsp->ctx, vpp); + nnpfs_debug_assert(!ret); + if (ret) + return ret; + } + + /* blocks in the middle of the file should be of full length */ + if ((flags & O_CREAT) && offset < nnpfs_offset(eof)) { + ret = nnpfs_block_extend_int(node, *vpp, nnpfs_curproc()); + nnpfs_debug_assert(!ret); + if (ret) + nnpfs_block_close(node, *vpp, + ((flags & FWRITE) == FWRITE) ? 1 : 0); + } - ret = open_file(cachename, flags, nnpfsp->ctx, vpp); - nnpfs_debug_assert(!ret); - if (ret) - return ret; + NNPFSDEB(XDEBNODE, ("nnpfs_block_open -> %d\n", ret)); - /* blocks in the middle of the file should be of full length */ - if ((flags & O_CREAT) && offset < nnpfs_offset(eof)) - ret = nnpfs_block_extend_int(node, *vpp); +#if 0 + nnpfs_assert(node->cache_vn); + if (VOP_ISLOCKED(node->cache_vn, nnpfs_curproc())) { + printf("%p is locked at %d\n", node->cache_vn, __LINE__); + panic("locked at block_open:exit"); + } +#endif return ret; } void -nnpfs_block_close(struct vnode *vp, int rw) +nnpfs_block_close(struct nnpfs_node *node, struct vnode *vp, int rw) { + NNPFSDEB(XDEBNODE, ("nnpfs_block_close(%p)\n", vp)); + + if (nnpfs_vnode_isdir(XNODE_TO_VNODE(node))) + return; + #ifdef __APPLE__ vnode_close(vp, 0, NULL); #else - d_thread_t *p = nnpfs_curproc(); - struct ucred *cred = NULL; + { + d_thread_t *p = nnpfs_curproc(); + + nnpfs_vfs_writelock(vp, p); + + if (rw) + vp->v_writecount--; + + VOP_CLOSE(vp, rw ? FWRITE : FREAD, NULL, p); + nnpfs_vput(vp); + } +#endif /* !__APPLE__ */ - VOP_CLOSE(vp, rw ? FWRITE : FREAD, cred, p); - nnpfs_vletgo(vp); -#endif + NNPFSDEB(XDEBNODE, ("nnpfs_block_close done\n")); } /* @@ -415,6 +634,8 @@ nnpfs_assert(!nnpfs_block_have_p(node, offset)); nnpfs_assert(!nnpfs_vnode_isdir(XNODE_TO_VNODE(node))); + /* printf("nnpfs_block_create @0x%llx\n", (unsigned long long)offset);*/ + NNPFSDEB(XDEBNODE, ("nnpfs_block_create: %lx @0x%llx\n", (unsigned long)node, (unsigned long long )offset)); @@ -427,7 +648,7 @@ ret = nnpfs_block_open(node, offset, O_CREAT|FWRITE, &vp); if (!ret) { nnpfs_assert(vp); - nnpfs_block_close(vp, 1); + nnpfs_block_close(node, vp, 1); } /* extend previously last block to full length */ @@ -467,5 +688,5 @@ msg.offset = offset; /* XXX currently no cleanup on failed send, hope it's just a devclose */ - return nnpfs_message_send(nnpfsp->fd, &msg.header, sizeof(msg)); + return nnpfs_message_send(nnpfsp, &msg.header, sizeof(msg)); } ==== //depot/projects/arla/sys/fs/nnpfs/nnpfs_dev-bsd.c#2 (text+ko) ==== @@ -38,13 +38,12 @@ #include <nnpfs/nnpfs_dev.h> #include <nnpfs/nnpfs_deb.h> -RCSID("$Id: nnpfs_dev-bsd.c,v 1.51 2006/10/24 16:33:02 tol Exp $"); +RCSID("$Id: nnpfs_dev-bsd.c,v 1.53 2007/03/28 12:05:45 tol Exp $"); int nnpfs_devopen(nnpfs_dev_t dev, int flag, int devtype, d_thread_t *proc) { - NNPFSDEB(XDEBDEV, ("nnpfsopen dev = %d.%d, flag = %d, devtype = %d\n", - major(dev), minor(dev), flag, devtype)); + NNPFSDEB(XDEBDEV, ("nnpfsopen flag = %d, devtype = %d\n", flag, devtype)); return nnpfs_devopen_common(dev); } @@ -72,10 +71,10 @@ int flags, d_thread_t *p) { - NNPFSDEB(XDEBDEV, ("nnpfs_devioctl dev = %d.%d, cmd = %lu, " - "data = %lx, flags = %x\n", - major(dev), minor(dev), (unsigned long)cmd, - (unsigned long)data, flags)); + NNPFSDEB(XDEBDEV, ("nnpfs_devioctl dev = %d, cmd = %lu, " + "data = %lx, flags = %x\n", + minor(dev), (unsigned long)cmd, + (unsigned long)data, flags)); return ENOTTY; } @@ -240,8 +239,8 @@ if (chan->status & CHANNEL_OPENED) { #if defined(__DragonFly__) nnpfs_devclose(make_adhoc_dev(&nnpfs_cdev, i), 0, 0, NULL); -#elif defined(__FreeBSD__) && __FreeBSD_version >= 502103 - nnpfs_devclose(findcdev(makedev(0, i)), 0, 0, NULL); +#elif defined(__FreeBSD__) + nnpfs_devclose(chan->dev, 0, 0, NULL); #else nnpfs_devclose(makedev(0, i), 0, 0, NULL); #endif ==== //depot/projects/arla/sys/fs/nnpfs/nnpfs_dev-common.c#2 (text+ko) ==== @@ -39,7 +39,7 @@ #include <nnpfs/nnpfs_dev.h> #include <nnpfs/nnpfs_deb.h> -RCSID("$Id: nnpfs_dev-common.c,v 1.80 2006/11/03 09:53:41 tol Exp $"); +RCSID("$Id: nnpfs_dev-common.c,v 1.81 2007/03/28 12:05:45 tol Exp $"); struct nnpfs nnpfs_dev[NNNPFS]; @@ -340,7 +340,7 @@ error = EINVAL; break; } - ret = nnpfs_message_receive (minor(dev), + ret = nnpfs_message_receive(chan, msg_buf, msg_buf->size, pp); @@ -361,9 +361,9 @@ * Send a message to user space. */ int -nnpfs_message_send(int fd, struct nnpfs_message_header * message, u_int size) +nnpfs_message_send(struct nnpfs *chan, + struct nnpfs_message_header *message, u_int size) { - struct nnpfs *chan = &nnpfs_dev[fd]; struct async_link *t; NNPFSDEB(XDEBMSG, ("nnpfs_message_send opcode = %d\n", message->opcode)); @@ -429,11 +429,11 @@ */ static int -nnpfs_message_rpc_int(int fd, struct nnpfs_message_header * message, u_int size, +nnpfs_message_rpc_int(struct nnpfs *chan, + struct nnpfs_message_header *message, u_int size, d_thread_t *proc, int async) { int ret; - struct nnpfs *chan = &nnpfs_dev[fd]; struct nnpfs_link *this_message; struct nnpfs_link *this_process; struct nnpfs_message_header *msg; @@ -636,17 +636,19 @@ } int -nnpfs_message_rpc(int fd, struct nnpfs_message_header * message, u_int size, +nnpfs_message_rpc(struct nnpfs *nnpfsp, + struct nnpfs_message_header *message, u_int size, d_thread_t *proc) { - return nnpfs_message_rpc_int(fd, message, size, proc, FALSE); + return nnpfs_message_rpc_int(nnpfsp, message, size, proc, FALSE); } int -nnpfs_message_rpc_async(int fd, struct nnpfs_message_header * message, u_int size, +nnpfs_message_rpc_async(struct nnpfs *nnpfsp, + struct nnpfs_message_header *message, u_int size, d_thread_t *proc) { - return nnpfs_message_rpc_int(fd, message, size, proc, TRUE); + return nnpfs_message_rpc_int(nnpfsp, message, size, proc, TRUE); } /* @@ -655,7 +657,7 @@ * invokes the correct function. */ int -nnpfs_message_receive(int fd, +nnpfs_message_receive(struct nnpfs *nnpfsp, struct nnpfs_message_header *message, u_int size, d_thread_t *p) @@ -665,58 +667,58 @@ /* Dispatch and coerce message type */ switch (message->opcode) { case NNPFS_MSG_WAKEUP: - return nnpfs_message_wakeup(fd, + return nnpfs_message_wakeup(nnpfsp, (struct nnpfs_message_wakeup *) message, message->size, p); case NNPFS_MSG_INSTALLROOT: - return nnpfs_message_installroot(fd, + return nnpfs_message_installroot(nnpfsp, (struct nnpfs_message_installroot *) message, message->size, p); case NNPFS_MSG_INSTALLNODE: - return nnpfs_message_installnode(fd, + return nnpfs_message_installnode(nnpfsp, (struct nnpfs_message_installnode *) message, message->size, p); case NNPFS_MSG_INSTALLATTR: - return nnpfs_message_installattr(fd, + return nnpfs_message_installattr(nnpfsp, (struct nnpfs_message_installattr *) message, message->size, p); case NNPFS_MSG_INSTALLDATA: - return nnpfs_message_installdata(fd, + return nnpfs_message_installdata(nnpfsp, (struct nnpfs_message_installdata *) message, message->size, p); case NNPFS_MSG_INVALIDNODE: - return nnpfs_message_invalidnode(fd, + return nnpfs_message_invalidnode(nnpfsp, (struct nnpfs_message_invalidnode *) message, message->size, p); case NNPFS_MSG_UPDATEFID: - return nnpfs_message_updatefid(fd, + return nnpfs_message_updatefid(nnpfsp, (struct nnpfs_message_updatefid *)message, message->size, p); case NNPFS_MSG_GC: - return nnpfs_message_gc(fd, + return nnpfs_message_gc(nnpfsp, (struct nnpfs_message_gc *)message, message->size, p); case NNPFS_MSG_DELETE_NODE: - return nnpfs_message_delete_node(fd, + return nnpfs_message_delete_node(nnpfsp, (struct nnpfs_message_delete_node *)message, message->size, p); case NNPFS_MSG_INSTALLQUOTA: - return nnpfs_message_installquota(fd, + return nnpfs_message_installquota(nnpfsp, (struct nnpfs_message_installquota *)message, message->size, p); case NNPFS_MSG_VERSION: - return nnpfs_message_version(fd, + return nnpfs_message_version(nnpfsp, (struct nnpfs_message_version *)message, message->size, p); @@ -766,12 +768,11 @@ } int -nnpfs_message_wakeup(int fd, +nnpfs_message_wakeup(struct nnpfs *chan, struct nnpfs_message_wakeup *message, u_int size, d_thread_t *p) { - struct nnpfs *chan = &nnpfs_dev[fd]; struct nnpfs_link *t; NNPFSDEB(XDEBMSG, ("nnpfs_message_wakeup error: %d\n", message->error)); ==== //depot/projects/arla/sys/fs/nnpfs/nnpfs_dev-freebsd.c#2 (text+ko) ==== @@ -1,5 +1,5 @@ /* - * Copyright (c) 1995 - 2006 Kungliga Tekniska Högskolan + * Copyright (c) 1995 - 2007 Kungliga Tekniska Högskolan * (Royal Institute of Technology, Stockholm, Sweden). * All rights reserved. * @@ -39,62 +39,195 @@ #include <nnpfs/nnpfs_dev.h> #include <nnpfs/nnpfs_deb.h> -RCSID("$Id: nnpfs_dev-freebsd.c,v 1.7 2006/10/31 12:40:02 tol Exp $"); +RCSID("$Id: nnpfs_dev-freebsd.c,v 1.9 2007/03/06 13:19:03 tol Exp $"); #define NNPFS_FBSD_DEVLOCK +#if 1 void nnpfs_dev_lock(struct nnpfs *chan) { -#ifdef NNPFS_FBSD_DEVLOCK - NNPFSDEB(XDEBDEV, ("nnpfs_dev_lock\n")); - mtx_lock(&chan->dev_lock); + d_thread_t *me = curthread; + + NNPFSDEB(XDEBDEV, ("nnpfs_dev_lock, me=%p\n", me)); + + mtx_lock(&chan->lock.lock); + + while (chan->lock.recurse > 0 && chan->lock.locker != me) { + /* XXX PCATCH */ +#if 1 + (void)nnpfs_msleep(&chan->lock, &chan->lock.lock, (PZERO + 1), "nnpfslock"); +#else + int ret = 0; + while msleep(&chan->lock, &chan->lock.lock, (PZERO + 1), "nnpfslock", 7 * hz); + #endif + } + + chan->lock.locker = me; + nnpfs_assert(chan->lock.recurse >= 0); + chan->lock.recurse++; + + NNPFSDEB(XDEBDEV, ("nnpfs_dev_lock, locker %p\n", chan->lock.locker)); + + mtx_unlock(&chan->lock.lock); } void nnpfs_dev_unlock(struct nnpfs *chan) { -#ifdef NNPFS_FBSD_DEVLOCK - NNPFSDEB(XDEBDEV, ("nnpfs_dev_unlock\n")); - mtx_unlock(&chan->dev_lock); -#endif + d_thread_t *me = curthread; + + NNPFSDEB(XDEBDEV, ("nnpfs_dev_unlock, me=%p locker=%p r=%d\n", me, + chan->lock.locker, chan->lock.recurse)); + + mtx_lock(&chan->lock.lock); + + chan->lock.recurse--; + nnpfs_assert(chan->lock.recurse >= 0); + nnpfs_assert(chan->lock.locker == me); + + if (chan->lock.recurse == 0) { + chan->lock.locker = NULL; + wakeup(&chan->lock); + } + + mtx_unlock(&chan->lock.lock); } int nnpfs_dev_msleep(struct nnpfs *chan, caddr_t waitobj, int flags, const char *msg) { - int ret; -#ifdef NNPFS_FBSD_DEVLOCK - ret = nnpfs_msleep(waitobj, &chan->dev_lock, flags, msg); -#endif + d_thread_t *me = curthread; + int ret, nlocks; + + NNPFSDEB(XDEBDEV, ("nnpfs_dev_msleep %p %x %s, me %p\n", waitobj, flags, msg, me)); + + mtx_lock(&chan->lock.lock); + nlocks = chan->lock.recurse; + nnpfs_assert(chan->lock.recurse >= 0); + nnpfs_assert(chan->lock.locker == me); + + chan->lock.recurse = 0; + chan->lock.locker = NULL; + wakeup(&chan->lock); + + ret = nnpfs_msleep(waitobj, &chan->lock.lock, flags, msg); + + while (chan->lock.recurse > 0) + /* XXX PCATCH, flags, ret? */ + (void)nnpfs_msleep(&chan->lock, &chan->lock.lock, (PZERO + 1), "nnpfslock"); + + nnpfs_assert(chan->lock.recurse == 0); + chan->lock.locker = me; + chan->lock.recurse = nlocks; + + mtx_unlock(&chan->lock.lock); return ret; } int nnpfs_dev_initlock(struct nnpfs *chan) { -#ifdef NNPFS_FBSD_DEVLOCK + d_thread_t *me = curthread; + NNPFSDEB(XDEBDEV, ("nnpfs_dev_initlock\n")); - mtx_init(&chan->dev_lock, "nnpfsdevlock", NULL, MTX_DEF); - mtx_lock(&chan->dev_lock); + + if (mtx_initialized(&chan->lock.lock)) + panic("nnpfs_dev_initlock: already inited!"); + + mtx_init(&chan->lock.lock, "nnpfsdevlock", NULL, MTX_DEF); + + mtx_lock(&chan->lock.lock); + chan->lock.locker = me; + chan->lock.recurse = 1; + mtx_unlock(&chan->lock.lock); + return 0; -#endif } void nnpfs_dev_uninitlock(struct nnpfs *chan) { -#ifdef NNPFS_FBSD_DEVLOCK + d_thread_t *me = curthread; + NNPFSDEB(XDEBDEV, ("nnpfs_dev_uninitlock\n")); + if (!mtx_initialized(&chan->lock.lock)) + printf("nnpfs_dev_uninitlock: not inited!\n"); + + mtx_lock(&chan->lock.lock); + nnpfs_assert(chan->lock.recurse == 1); + nnpfs_assert(chan->lock.locker == me); + + chan->lock.recurse = 0; + chan->lock.locker = NULL; + /* * contrary to man page, it seems we need to unlock the mutex before * destroying it if we use spinlocks. Default mutexes are ok. */ - mtx_destroy(&chan->dev_lock); + + mtx_destroy(&chan->lock.lock); +} +#else + +void +nnpfs_dev_lock(struct nnpfs *chan) +{ + int ret; + NNPFSDEB(XDEBDEV, ("nnpfs_dev_lock\n")); + ret = lockmgr(&chan->dev_lock, LK_EXCLUSIVE | LK_CANRECURSE, NULL); + nnpfs_assert(!ret); +} + +void +nnpfs_dev_unlock(struct nnpfs *chan) +{ + int ret; + NNPFSDEB(XDEBDEV, ("nnpfs_dev_unlock\n")); + ret = lockmgr(&chan->dev_lock, LK_RELEASE, NULL); + nnpfs_assert(!ret); +} + +int +nnpfs_dev_msleep(struct nnpfs *chan, caddr_t waitobj, int flags, const char *msg) +{ + d_thread_t *td = curthread; + int nlocks, i, ret; + + NNPFSDEB(XDEBDEV, ("nnpfs_dev_msleep %p %x %s\n", waitobj, flags, msg)); + + ret = lockstatus(&chan->dev_lock, td); + nnpfs_assert(ret == LK_EXCLUSIVE); + + nlocks = lockcount(&chan->dev_lock); + + for (i = nlocks; i > 0 ; i--) { + ret = lockmgr(&chan->dev_lock, LK_RELEASE, NULL); + nnpfs_assert(!ret); + } + + ret = nnpfs_msleep(waitobj, &chan->dev_lock, flags, msg); + return ret; +} + +int +nnpfs_dev_initlock(struct nnpfs *chan) +{ + NNPFSDEB(XDEBDEV, ("nnpfs_dev_initlock\n")); + lockinit(&chan->dev_lock, PRIBIO /* XXX */, "nnpfsdevlock", NULL, LK_CANRECURSE | LK_NOSHARE); + return lockmgr(&chan->dev_lock, LK_EXCLUSIVE, NULL); +} + +void +nnpfs_dev_uninitlock(struct nnpfs *chan) +{ + NNPFSDEB(XDEBDEV, ("nnpfs_dev_uninitlock\n")); + lockdestroy(&chan->dev_lock); +} + #endif -} #ifndef NNPFS_FBSD_DEVLOCK @@ -155,7 +288,9 @@ #ifdef HAVE_STRUCT_CDEVSW_D_SPARE d_spare: NULL, #endif +#if __FreeBSD_version < 600007 d_maj: 128, /* XXX */ +#endif #ifdef HAVE_STRUCT_CDEVSW_D_DUMP d_dump: nodump, #endif ==== //depot/projects/arla/sys/fs/nnpfs/nnpfs_dev-netbsd.c#2 (text+ko) ==== @@ -39,7 +39,7 @@ #include <nnpfs/nnpfs_dev.h> #include <nnpfs/nnpfs_deb.h> -RCSID("$Id: nnpfs_dev-netbsd.c,v 1.3 2005/11/22 18:19:53 lha Exp $"); >>> TRUNCATED FOR MAIL (1000 lines) <<<
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200704101129.l3ABTKur076418>