Home | History | Annotate | Line # | Download | only in libpuffs
dispatcher.c revision 1.41
      1 /*	$NetBSD: dispatcher.c,v 1.41 2012/06/27 13:25:23 manu Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2006, 2007, 2008 Antti Kantee.  All Rights Reserved.
      5  *
      6  * Development of this software was supported by the
      7  * Ulla Tuominen Foundation, the Finnish Cultural Foundation and
      8  * Research Foundation of Helsinki University of Technology.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     20  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     21  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     22  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     23  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     25  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29  * SUCH DAMAGE.
     30  */
     31 
     32 #include <sys/cdefs.h>
     33 #if !defined(lint)
     34 __RCSID("$NetBSD: dispatcher.c,v 1.41 2012/06/27 13:25:23 manu Exp $");
     35 #endif /* !lint */
     36 
     37 #include <sys/types.h>
     38 #include <sys/poll.h>
     39 
     40 #include <assert.h>
     41 #include <errno.h>
     42 #include <pthread.h>
     43 #include <puffs.h>
     44 #include <puffsdump.h>
     45 #include <stdio.h>
     46 #include <stdlib.h>
     47 #include <unistd.h>
     48 
     49 #include "puffs_priv.h"
     50 
     51 #define PUFFS_USE_FS_TTL(pu) (pu->pu_flags & PUFFS_KFLAG_CACHE_FS_TTL)
     52 
     53 static void dispatch(struct puffs_cc *);
     54 
     55 /* for our eyes only */
     56 void
     57 puffs__ml_dispatch(struct puffs_usermount *pu, struct puffs_framebuf *pb)
     58 {
     59 	struct puffs_cc *pcc = puffs_cc_getcc(pu);
     60 	struct puffs_req *preq;
     61 
     62 	pcc->pcc_pb = pb;
     63 	pcc->pcc_flags |= PCC_MLCONT;
     64 	dispatch(pcc);
     65 
     66 	/* Put result to kernel sendqueue if necessary */
     67 	preq = puffs__framebuf_getdataptr(pcc->pcc_pb);
     68 	if (PUFFSOP_WANTREPLY(preq->preq_opclass)) {
     69 		if (pu->pu_flags & PUFFS_FLAG_OPDUMP)
     70 			puffsdump_rv(preq);
     71 
     72 		puffs_framev_enqueue_justsend(pu, pu->pu_fd,
     73 		    pcc->pcc_pb, 0, 0);
     74 	} else {
     75 		puffs_framebuf_destroy(pcc->pcc_pb);
     76 	}
     77 
     78 	/* who needs information when you're living on borrowed time? */
     79 	if (pcc->pcc_flags & PCC_BORROWED) {
     80 		puffs_cc_yield(pcc); /* back to borrow source */
     81 	}
     82 	pcc->pcc_flags = 0;
     83 }
     84 
     85 /* public, but not really tested and only semi-supported */
     86 int
     87 puffs_dispatch_create(struct puffs_usermount *pu, struct puffs_framebuf *pb,
     88 	struct puffs_cc **pccp)
     89 {
     90 	struct puffs_cc *pcc;
     91 
     92 	if (puffs__cc_create(pu, dispatch, &pcc) == -1)
     93 		return -1;
     94 
     95 	pcc->pcc_pb = pb;
     96 	*pccp = pcc;
     97 
     98 	return 0;
     99 }
    100 
    101 int
    102 puffs_dispatch_exec(struct puffs_cc *pcc, struct puffs_framebuf **pbp)
    103 {
    104 	int rv;
    105 
    106 	puffs_cc_continue(pcc);
    107 
    108 	if (pcc->pcc_flags & PCC_DONE) {
    109 		rv = 1;
    110 		*pbp = pcc->pcc_pb;
    111 		pcc->pcc_flags = 0;
    112 		puffs__cc_destroy(pcc, 0);
    113 	} else {
    114 		rv = 0;
    115 	}
    116 
    117 	return rv;
    118 }
    119 
    120 static void
    121 dispatch(struct puffs_cc *pcc)
    122 {
    123 	struct puffs_usermount *pu = pcc->pcc_pu;
    124 	struct puffs_ops *pops = &pu->pu_ops;
    125 	struct puffs_req *preq = puffs__framebuf_getdataptr(pcc->pcc_pb);
    126 	void *auxbuf; /* help with typecasting */
    127 	puffs_cookie_t opcookie;
    128 	int error = 0, buildpath;
    129 
    130 	/* XXX: smaller hammer, please */
    131 	if ((PUFFSOP_OPCLASS(preq->preq_opclass == PUFFSOP_VFS &&
    132 	    preq->preq_optype == PUFFS_VFS_VPTOFH)) ||
    133 	    (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN &&
    134 	    (preq->preq_optype == PUFFS_VN_READDIR
    135 	    || preq->preq_optype == PUFFS_VN_READ))) {
    136 		if (puffs_framebuf_reserve_space(pcc->pcc_pb,
    137 		    PUFFS_MSG_MAXSIZE) == -1)
    138 			error = errno;
    139 		preq = puffs__framebuf_getdataptr(pcc->pcc_pb);
    140 	}
    141 
    142 	auxbuf = preq;
    143 	opcookie = preq->preq_cookie;
    144 
    145 	assert((pcc->pcc_flags & PCC_DONE) == 0);
    146 
    147 	buildpath = pu->pu_flags & PUFFS_FLAG_BUILDPATH;
    148 	preq->preq_setbacks = 0;
    149 
    150 	if (pu->pu_flags & PUFFS_FLAG_OPDUMP)
    151 		puffsdump_req(preq);
    152 
    153 	puffs__cc_setcaller(pcc, preq->preq_pid, preq->preq_lid);
    154 
    155 	/* pre-operation */
    156 	if (pu->pu_oppre)
    157 		pu->pu_oppre(pu);
    158 
    159 	if (error)
    160 		goto out;
    161 
    162 	/* Execute actual operation */
    163 	if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VFS) {
    164 		switch (preq->preq_optype) {
    165 		case PUFFS_VFS_UNMOUNT:
    166 		{
    167 			struct puffs_vfsmsg_unmount *auxt = auxbuf;
    168 
    169 			PU_SETSTATE(pu, PUFFS_STATE_UNMOUNTING);
    170 			error = pops->puffs_fs_unmount(pu, auxt->pvfsr_flags);
    171 			if (!error)
    172 				PU_SETSTATE(pu, PUFFS_STATE_UNMOUNTED);
    173 			else
    174 				PU_SETSTATE(pu, PUFFS_STATE_RUNNING);
    175 			break;
    176 		}
    177 
    178 		case PUFFS_VFS_STATVFS:
    179 		{
    180 			struct puffs_vfsmsg_statvfs *auxt = auxbuf;
    181 
    182 			error = pops->puffs_fs_statvfs(pu, &auxt->pvfsr_sb);
    183 			break;
    184 		}
    185 
    186 		case PUFFS_VFS_SYNC:
    187 		{
    188 			struct puffs_vfsmsg_sync *auxt = auxbuf;
    189 			PUFFS_MAKECRED(pcr, &auxt->pvfsr_cred);
    190 
    191 			error = pops->puffs_fs_sync(pu,
    192 			    auxt->pvfsr_waitfor, pcr);
    193 			break;
    194 		}
    195 
    196 		case PUFFS_VFS_FHTOVP:
    197 		{
    198 			struct puffs_vfsmsg_fhtonode *auxt = auxbuf;
    199 			struct puffs_newinfo pni;
    200 
    201 			pni.pni_cookie = &auxt->pvfsr_fhcookie;
    202 			pni.pni_vtype = &auxt->pvfsr_vtype;
    203 			pni.pni_size = &auxt->pvfsr_size;
    204 			pni.pni_rdev = &auxt->pvfsr_rdev;
    205 			pni.pni_va = NULL;
    206 			pni.pni_va_ttl = NULL;
    207 			pni.pni_cn_ttl = NULL;
    208 
    209 			error = pops->puffs_fs_fhtonode(pu, auxt->pvfsr_data,
    210 			    auxt->pvfsr_dsize, &pni);
    211 
    212 			break;
    213 		}
    214 
    215 		case PUFFS_VFS_VPTOFH:
    216 		{
    217 			struct puffs_vfsmsg_nodetofh *auxt = auxbuf;
    218 
    219 			error = pops->puffs_fs_nodetofh(pu,
    220 			    auxt->pvfsr_fhcookie, auxt->pvfsr_data,
    221 			    &auxt->pvfsr_dsize);
    222 
    223 			break;
    224 		}
    225 
    226 		case PUFFS_VFS_EXTATTRCTL:
    227 		{
    228 			struct puffs_vfsmsg_extattrctl *auxt = auxbuf;
    229 			const char *attrname;
    230 			int flags;
    231 
    232 			if (pops->puffs_fs_extattrctl == NULL) {
    233 				error = EOPNOTSUPP;
    234 				break;
    235 			}
    236 
    237 			if (auxt->pvfsr_flags & PUFFS_EXTATTRCTL_HASATTRNAME)
    238 				attrname = auxt->pvfsr_attrname;
    239 			else
    240 				attrname = NULL;
    241 
    242 			flags = auxt->pvfsr_flags & PUFFS_EXTATTRCTL_HASNODE;
    243 			error = pops->puffs_fs_extattrctl(pu, auxt->pvfsr_cmd,
    244 			    opcookie, flags,
    245 			    auxt->pvfsr_attrnamespace, attrname);
    246 			break;
    247 		}
    248 
    249 		default:
    250 			/*
    251 			 * I guess the kernel sees this one coming
    252 			 */
    253 			error = EINVAL;
    254 			break;
    255 		}
    256 
    257 	/* XXX: audit return values */
    258 	/* XXX: sync with kernel */
    259 	} else if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN) {
    260 		switch (preq->preq_optype) {
    261 		case PUFFS_VN_LOOKUP:
    262 		{
    263 			struct puffs_vnmsg_lookup *auxt = auxbuf;
    264 			struct puffs_newinfo pni;
    265 			struct puffs_cn pcn;
    266 			struct puffs_node *pn = NULL;
    267 
    268 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    269 			PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
    270 			pni.pni_cookie = &auxt->pvnr_newnode;
    271 			pni.pni_vtype = &auxt->pvnr_vtype;
    272 			pni.pni_size = &auxt->pvnr_size;
    273 			pni.pni_rdev = &auxt->pvnr_rdev;
    274 			pni.pni_va = &auxt->pvnr_va;
    275 			pni.pni_va_ttl = &auxt->pvnr_va_ttl;
    276 			pni.pni_cn_ttl = &auxt->pvnr_cn_ttl;
    277 
    278 			if (buildpath) {
    279 				error = puffs_path_pcnbuild(pu, &pcn, opcookie);
    280 				if (error)
    281 					break;
    282 			}
    283 
    284 			/* lookup *must* be present */
    285 			error = pops->puffs_node_lookup(pu, opcookie,
    286 			    &pni, &pcn);
    287 
    288 			if (buildpath) {
    289 				if (error) {
    290 					pu->pu_pathfree(pu, &pcn.pcn_po_full);
    291 				} else {
    292 					/*
    293 					 * did we get a new node or a
    294 					 * recycled node?
    295 					 */
    296 					pn = PU_CMAP(pu, auxt->pvnr_newnode);
    297 					if (pn->pn_po.po_path == NULL)
    298 						pn->pn_po = pcn.pcn_po_full;
    299 					else
    300 						pu->pu_pathfree(pu,
    301 						    &pcn.pcn_po_full);
    302 				}
    303 			}
    304 			break;
    305 		}
    306 
    307 		case PUFFS_VN_CREATE:
    308 		{
    309 			struct puffs_vnmsg_create *auxt = auxbuf;
    310 			struct puffs_newinfo pni;
    311 			struct puffs_cn pcn;
    312 
    313 			if (pops->puffs_node_create == NULL) {
    314 				error = 0;
    315 				break;
    316 			}
    317 
    318 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    319 			PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
    320 
    321 			memset(&pni, 0, sizeof(pni));
    322 			pni.pni_cookie = &auxt->pvnr_newnode;
    323 			pni.pni_va = &auxt->pvnr_va;
    324 			pni.pni_va_ttl = &auxt->pvnr_va_ttl;
    325 			pni.pni_cn_ttl = &auxt->pvnr_cn_ttl;
    326 
    327 			if (buildpath) {
    328 				error = puffs_path_pcnbuild(pu, &pcn, opcookie);
    329 				if (error)
    330 					break;
    331 			}
    332 
    333 			error = pops->puffs_node_create(pu,
    334 			    opcookie, &pni, &pcn, &auxt->pvnr_va);
    335 
    336 			if (buildpath) {
    337 				if (error) {
    338 					pu->pu_pathfree(pu, &pcn.pcn_po_full);
    339 				} else {
    340 					struct puffs_node *pn;
    341 
    342 					pn = PU_CMAP(pu, auxt->pvnr_newnode);
    343 					pn->pn_po = pcn.pcn_po_full;
    344 				}
    345 			}
    346 
    347 			break;
    348 		}
    349 
    350 		case PUFFS_VN_MKNOD:
    351 		{
    352 			struct puffs_vnmsg_mknod *auxt = auxbuf;
    353 			struct puffs_newinfo pni;
    354 			struct puffs_cn pcn;
    355 
    356 			if (pops->puffs_node_mknod == NULL) {
    357 				error = 0;
    358 				break;
    359 			}
    360 
    361 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    362 			PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
    363 
    364 			memset(&pni, 0, sizeof(pni));
    365 			pni.pni_cookie = &auxt->pvnr_newnode;
    366 			pni.pni_va = &auxt->pvnr_va;
    367 			pni.pni_va_ttl = &auxt->pvnr_va_ttl;
    368 			pni.pni_cn_ttl = &auxt->pvnr_cn_ttl;
    369 
    370 			if (buildpath) {
    371 				error = puffs_path_pcnbuild(pu, &pcn, opcookie);
    372 				if (error)
    373 					break;
    374 			}
    375 
    376 			error = pops->puffs_node_mknod(pu,
    377 			    opcookie, &pni, &pcn, &auxt->pvnr_va);
    378 
    379 			if (buildpath) {
    380 				if (error) {
    381 					pu->pu_pathfree(pu, &pcn.pcn_po_full);
    382 				} else {
    383 					struct puffs_node *pn;
    384 
    385 					pn = PU_CMAP(pu, auxt->pvnr_newnode);
    386 					pn->pn_po = pcn.pcn_po_full;
    387 				}
    388 			}
    389 
    390 			break;
    391 		}
    392 
    393 		case PUFFS_VN_OPEN:
    394 		{
    395 			struct puffs_vnmsg_open *auxt = auxbuf;
    396 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    397 
    398 			if (pops->puffs_node_open == NULL) {
    399 				error = 0;
    400 				break;
    401 			}
    402 
    403 			error = pops->puffs_node_open(pu,
    404 			    opcookie, auxt->pvnr_mode, pcr);
    405 			break;
    406 		}
    407 
    408 		case PUFFS_VN_CLOSE:
    409 		{
    410 			struct puffs_vnmsg_close *auxt = auxbuf;
    411 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    412 
    413 			if (pops->puffs_node_close == NULL) {
    414 				error = 0;
    415 				break;
    416 			}
    417 
    418 			error = pops->puffs_node_close(pu,
    419 			    opcookie, auxt->pvnr_fflag, pcr);
    420 			break;
    421 		}
    422 
    423 		case PUFFS_VN_ACCESS:
    424 		{
    425 			struct puffs_vnmsg_access *auxt = auxbuf;
    426 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    427 
    428 			if (pops->puffs_node_access == NULL) {
    429 				error = 0;
    430 				break;
    431 			}
    432 
    433 			error = pops->puffs_node_access(pu,
    434 			    opcookie, auxt->pvnr_mode, pcr);
    435 			break;
    436 		}
    437 
    438 		case PUFFS_VN_GETATTR:
    439 		{
    440 			struct puffs_vnmsg_getattr *auxt = auxbuf;
    441 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    442 
    443 			if (PUFFS_USE_FS_TTL(pu)) {
    444 				if (pops->puffs_node_getattr_ttl == NULL) {
    445 					error = EOPNOTSUPP;
    446 					break;
    447 				}
    448 
    449 				error = pops->puffs_node_getattr_ttl(pu,
    450 				    opcookie, &auxt->pvnr_va, pcr,
    451 				    &auxt->pvnr_va_ttl);
    452 			} else {
    453 				if (pops->puffs_node_getattr == NULL) {
    454 					error = EOPNOTSUPP;
    455 					break;
    456 				}
    457 
    458 				error = pops->puffs_node_getattr(pu,
    459 				    opcookie, &auxt->pvnr_va, pcr);
    460 			}
    461 			break;
    462 		}
    463 
    464 		case PUFFS_VN_SETATTR:
    465 		{
    466 			struct puffs_vnmsg_setattr *auxt = auxbuf;
    467 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    468 
    469 			if (PUFFS_USE_FS_TTL(pu)) {
    470 				int xflag = 0;
    471 
    472 				if (pops->puffs_node_setattr_ttl == NULL) {
    473 					error = EOPNOTSUPP;
    474 					break;
    475 				}
    476 
    477 				if (!PUFFSOP_WANTREPLY(preq->preq_opclass))
    478 					xflag |= PUFFS_SETATTR_FAF;
    479 
    480 				error = pops->puffs_node_setattr_ttl(pu,
    481 				    opcookie, &auxt->pvnr_va, pcr,
    482 				    &auxt->pvnr_va_ttl, xflag);
    483 			} else {
    484 				if (pops->puffs_node_setattr == NULL) {
    485 					error = EOPNOTSUPP;
    486 					break;
    487 				}
    488 
    489 				error = pops->puffs_node_setattr(pu,
    490 				    opcookie, &auxt->pvnr_va, pcr);
    491 			}
    492 			break;
    493 		}
    494 
    495 		case PUFFS_VN_MMAP:
    496 		{
    497 			struct puffs_vnmsg_mmap *auxt = auxbuf;
    498 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    499 
    500 			if (pops->puffs_node_mmap == NULL) {
    501 				error = 0;
    502 				break;
    503 			}
    504 
    505 			error = pops->puffs_node_mmap(pu,
    506 			    opcookie, auxt->pvnr_prot, pcr);
    507 			break;
    508 		}
    509 
    510 		case PUFFS_VN_FSYNC:
    511 		{
    512 			struct puffs_vnmsg_fsync *auxt = auxbuf;
    513 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    514 
    515 			if (pops->puffs_node_fsync == NULL) {
    516 				error = 0;
    517 				break;
    518 			}
    519 
    520 			error = pops->puffs_node_fsync(pu, opcookie, pcr,
    521 			    auxt->pvnr_flags, auxt->pvnr_offlo,
    522 			    auxt->pvnr_offhi);
    523 			break;
    524 		}
    525 
    526 		case PUFFS_VN_SEEK:
    527 		{
    528 			struct puffs_vnmsg_seek *auxt = auxbuf;
    529 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    530 
    531 			if (pops->puffs_node_seek == NULL) {
    532 				error = 0;
    533 				break;
    534 			}
    535 
    536 			error = pops->puffs_node_seek(pu,
    537 			    opcookie, auxt->pvnr_oldoff,
    538 			    auxt->pvnr_newoff, pcr);
    539 			break;
    540 		}
    541 
    542 		case PUFFS_VN_REMOVE:
    543 		{
    544 			struct puffs_vnmsg_remove *auxt = auxbuf;
    545 			struct puffs_cn pcn;
    546 			if (pops->puffs_node_remove == NULL) {
    547 				error = 0;
    548 				break;
    549 			}
    550 
    551 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    552 			PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
    553 
    554 			error = pops->puffs_node_remove(pu,
    555 			    opcookie, auxt->pvnr_cookie_targ, &pcn);
    556 			break;
    557 		}
    558 
    559 		case PUFFS_VN_LINK:
    560 		{
    561 			struct puffs_vnmsg_link *auxt = auxbuf;
    562 			struct puffs_cn pcn;
    563 			if (pops->puffs_node_link == NULL) {
    564 				error = 0;
    565 				break;
    566 			}
    567 
    568 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    569 			PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
    570 
    571 			if (buildpath) {
    572 				error = puffs_path_pcnbuild(pu, &pcn, opcookie);
    573 				if (error)
    574 					break;
    575 			}
    576 
    577 			error = pops->puffs_node_link(pu,
    578 			    opcookie, auxt->pvnr_cookie_targ, &pcn);
    579 			if (buildpath)
    580 				pu->pu_pathfree(pu, &pcn.pcn_po_full);
    581 
    582 			break;
    583 		}
    584 
    585 		case PUFFS_VN_RENAME:
    586 		{
    587 			struct puffs_vnmsg_rename *auxt = auxbuf;
    588 			struct puffs_cn pcn_src, pcn_targ;
    589 			struct puffs_node *pn_src;
    590 
    591 			if (pops->puffs_node_rename == NULL) {
    592 				error = 0;
    593 				break;
    594 			}
    595 
    596 			pcn_src.pcn_pkcnp = &auxt->pvnr_cn_src;
    597 			PUFFS_KCREDTOCRED(pcn_src.pcn_cred,
    598 			    &auxt->pvnr_cn_src_cred);
    599 
    600 			pcn_targ.pcn_pkcnp = &auxt->pvnr_cn_targ;
    601 			PUFFS_KCREDTOCRED(pcn_targ.pcn_cred,
    602 			    &auxt->pvnr_cn_targ_cred);
    603 
    604 			if (buildpath) {
    605 				pn_src = auxt->pvnr_cookie_src;
    606 				pcn_src.pcn_po_full = pn_src->pn_po;
    607 
    608 				error = puffs_path_pcnbuild(pu, &pcn_targ,
    609 				    auxt->pvnr_cookie_targdir);
    610 				if (error)
    611 					break;
    612 			}
    613 
    614 			error = pops->puffs_node_rename(pu,
    615 			    opcookie, auxt->pvnr_cookie_src,
    616 			    &pcn_src, auxt->pvnr_cookie_targdir,
    617 			    auxt->pvnr_cookie_targ, &pcn_targ);
    618 
    619 			if (buildpath) {
    620 				if (error) {
    621 					pu->pu_pathfree(pu,
    622 					    &pcn_targ.pcn_po_full);
    623 				} else {
    624 					struct puffs_pathinfo pi;
    625 					struct puffs_pathobj po_old;
    626 
    627 					/* handle this node */
    628 					po_old = pn_src->pn_po;
    629 					pn_src->pn_po = pcn_targ.pcn_po_full;
    630 
    631 					if (pn_src->pn_va.va_type != VDIR) {
    632 						pu->pu_pathfree(pu, &po_old);
    633 						break;
    634 					}
    635 
    636 					/* handle all child nodes for DIRs */
    637 					pi.pi_old = &pcn_src.pcn_po_full;
    638 					pi.pi_new = &pcn_targ.pcn_po_full;
    639 
    640 					PU_LOCK();
    641 					if (puffs_pn_nodewalk(pu,
    642 					    puffs_path_prefixadj, &pi) != NULL)
    643 						error = ENOMEM;
    644 					PU_UNLOCK();
    645 					pu->pu_pathfree(pu, &po_old);
    646 				}
    647 			}
    648 			break;
    649 		}
    650 
    651 		case PUFFS_VN_MKDIR:
    652 		{
    653 			struct puffs_vnmsg_mkdir *auxt = auxbuf;
    654 			struct puffs_newinfo pni;
    655 			struct puffs_cn pcn;
    656 
    657 			if (pops->puffs_node_mkdir == NULL) {
    658 				error = 0;
    659 				break;
    660 			}
    661 
    662 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    663 			PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
    664 
    665 			memset(&pni, 0, sizeof(pni));
    666 			pni.pni_cookie = &auxt->pvnr_newnode;
    667 			pni.pni_va = &auxt->pvnr_va;
    668 			pni.pni_va_ttl = &auxt->pvnr_va_ttl;
    669 			pni.pni_cn_ttl = &auxt->pvnr_cn_ttl;
    670 
    671 			if (buildpath) {
    672 				error = puffs_path_pcnbuild(pu, &pcn, opcookie);
    673 				if (error)
    674 					break;
    675 			}
    676 
    677 			error = pops->puffs_node_mkdir(pu,
    678 			    opcookie, &pni, &pcn, &auxt->pvnr_va);
    679 
    680 			if (buildpath) {
    681 				if (error) {
    682 					pu->pu_pathfree(pu, &pcn.pcn_po_full);
    683 				} else {
    684 					struct puffs_node *pn;
    685 
    686 					pn = PU_CMAP(pu, auxt->pvnr_newnode);
    687 					pn->pn_po = pcn.pcn_po_full;
    688 				}
    689 			}
    690 
    691 			break;
    692 		}
    693 
    694 		case PUFFS_VN_RMDIR:
    695 		{
    696 			struct puffs_vnmsg_rmdir *auxt = auxbuf;
    697 			struct puffs_cn pcn;
    698 			if (pops->puffs_node_rmdir == NULL) {
    699 				error = 0;
    700 				break;
    701 			}
    702 
    703 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    704 			PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
    705 
    706 			error = pops->puffs_node_rmdir(pu,
    707 			    opcookie, auxt->pvnr_cookie_targ, &pcn);
    708 			break;
    709 		}
    710 
    711 		case PUFFS_VN_SYMLINK:
    712 		{
    713 			struct puffs_vnmsg_symlink *auxt = auxbuf;
    714 			struct puffs_newinfo pni;
    715 			struct puffs_cn pcn;
    716 
    717 			if (pops->puffs_node_symlink == NULL) {
    718 				error = 0;
    719 				break;
    720 			}
    721 
    722 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    723 			PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
    724 
    725 			memset(&pni, 0, sizeof(pni));
    726 			pni.pni_cookie = &auxt->pvnr_newnode;
    727 			pni.pni_va = &auxt->pvnr_va;
    728 			pni.pni_va_ttl = &auxt->pvnr_va_ttl;
    729 			pni.pni_cn_ttl = &auxt->pvnr_cn_ttl;
    730 
    731 			if (buildpath) {
    732 				error = puffs_path_pcnbuild(pu, &pcn, opcookie);
    733 				if (error)
    734 					break;
    735 			}
    736 
    737 			error = pops->puffs_node_symlink(pu,
    738 			    opcookie, &pni, &pcn,
    739 			    &auxt->pvnr_va, auxt->pvnr_link);
    740 
    741 			if (buildpath) {
    742 				if (error) {
    743 					pu->pu_pathfree(pu, &pcn.pcn_po_full);
    744 				} else {
    745 					struct puffs_node *pn;
    746 
    747 					pn = PU_CMAP(pu, auxt->pvnr_newnode);
    748 					pn->pn_po = pcn.pcn_po_full;
    749 				}
    750 			}
    751 
    752 			break;
    753 		}
    754 
    755 		case PUFFS_VN_READDIR:
    756 		{
    757 			struct puffs_vnmsg_readdir *auxt = auxbuf;
    758 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    759 			struct dirent *dent;
    760 			off_t *cookies;
    761 			size_t res, origcookies;
    762 
    763 			if (pops->puffs_node_readdir == NULL) {
    764 				error = 0;
    765 				break;
    766 			}
    767 
    768 			if (auxt->pvnr_ncookies) {
    769 				/* LINTED: pvnr_data is __aligned() */
    770 				cookies = (off_t *)auxt->pvnr_data;
    771 				origcookies = auxt->pvnr_ncookies;
    772 			} else {
    773 				cookies = NULL;
    774 				origcookies = 0;
    775 			}
    776 			/* LINTED: dentoff is aligned in the kernel */
    777 			dent = (struct dirent *)
    778 			    (auxt->pvnr_data + auxt->pvnr_dentoff);
    779 
    780 			res = auxt->pvnr_resid;
    781 			error = pops->puffs_node_readdir(pu,
    782 			    opcookie, dent, &auxt->pvnr_offset,
    783 			    &auxt->pvnr_resid, pcr, &auxt->pvnr_eofflag,
    784 			    cookies, &auxt->pvnr_ncookies);
    785 
    786 			/* much easier to track non-working NFS */
    787 			assert(auxt->pvnr_ncookies <= origcookies);
    788 
    789 			/* need to move a bit more */
    790 			preq->preq_buflen = sizeof(struct puffs_vnmsg_readdir)
    791 			    + auxt->pvnr_dentoff + (res - auxt->pvnr_resid);
    792 			break;
    793 		}
    794 
    795 		case PUFFS_VN_READLINK:
    796 		{
    797 			struct puffs_vnmsg_readlink *auxt = auxbuf;
    798 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    799 
    800 			if (pops->puffs_node_readlink == NULL) {
    801 				error = EOPNOTSUPP;
    802 				break;
    803 			}
    804 
    805 			/*LINTED*/
    806 			error = pops->puffs_node_readlink(pu, opcookie, pcr,
    807 			    auxt->pvnr_link, &auxt->pvnr_linklen);
    808 			break;
    809 		}
    810 
    811 		case PUFFS_VN_RECLAIM:
    812 		{
    813 
    814 			if (pops->puffs_node_reclaim == NULL) {
    815 				error = 0;
    816 				break;
    817 			}
    818 
    819 			error = pops->puffs_node_reclaim(pu, opcookie);
    820 			break;
    821 		}
    822 
    823 		case PUFFS_VN_INACTIVE:
    824 		{
    825 
    826 			if (pops->puffs_node_inactive == NULL) {
    827 				error = EOPNOTSUPP;
    828 				break;
    829 			}
    830 
    831 			error = pops->puffs_node_inactive(pu, opcookie);
    832 			break;
    833 		}
    834 
    835 		case PUFFS_VN_PATHCONF:
    836 		{
    837 			struct puffs_vnmsg_pathconf *auxt = auxbuf;
    838 			if (pops->puffs_node_pathconf == NULL) {
    839 				error = 0;
    840 				break;
    841 			}
    842 
    843 			error = pops->puffs_node_pathconf(pu,
    844 			    opcookie, auxt->pvnr_name,
    845 			    &auxt->pvnr_retval);
    846 			break;
    847 		}
    848 
    849 		case PUFFS_VN_ADVLOCK:
    850 		{
    851 			struct puffs_vnmsg_advlock *auxt = auxbuf;
    852 			if (pops->puffs_node_advlock == NULL) {
    853 				error = 0;
    854 				break;
    855 			}
    856 
    857 			error = pops->puffs_node_advlock(pu,
    858 			    opcookie, auxt->pvnr_id, auxt->pvnr_op,
    859 			    &auxt->pvnr_fl, auxt->pvnr_flags);
    860 			break;
    861 		}
    862 
    863 		case PUFFS_VN_PRINT:
    864 		{
    865 			if (pops->puffs_node_print == NULL) {
    866 				error = 0;
    867 				break;
    868 			}
    869 
    870 			error = pops->puffs_node_print(pu,
    871 			    opcookie);
    872 			break;
    873 		}
    874 
    875 		case PUFFS_VN_ABORTOP:
    876 		{
    877 			struct puffs_vnmsg_abortop *auxt = auxbuf;
    878 			struct puffs_cn pcn;
    879 
    880 			if (pops->puffs_node_abortop == NULL) {
    881 				error = 0;
    882 				break;
    883 			}
    884 
    885 			pcn.pcn_pkcnp = &auxt->pvnr_cn;
    886 			PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
    887 
    888 			error = pops->puffs_node_abortop(pu, opcookie, &pcn);
    889 
    890 			break;
    891 		}
    892 
    893 		case PUFFS_VN_READ:
    894 		{
    895 			struct puffs_vnmsg_read *auxt = auxbuf;
    896 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    897 			size_t res;
    898 
    899 			if (pops->puffs_node_read == NULL) {
    900 				error = EIO;
    901 				break;
    902 			}
    903 
    904 			res = auxt->pvnr_resid;
    905 			error = pops->puffs_node_read(pu,
    906 			    opcookie, auxt->pvnr_data,
    907 			    auxt->pvnr_offset, &auxt->pvnr_resid,
    908 			    pcr, auxt->pvnr_ioflag);
    909 
    910 			/* need to move a bit more */
    911 			preq->preq_buflen = sizeof(struct puffs_vnmsg_read)
    912 			    + (res - auxt->pvnr_resid);
    913 			break;
    914 		}
    915 
    916 		case PUFFS_VN_WRITE:
    917 		{
    918 			struct puffs_vnmsg_write *auxt = auxbuf;
    919 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    920 
    921 			if (pops->puffs_node_write2 != NULL) {
    922 				int xflag = 0;
    923 
    924 				if (!PUFFSOP_WANTREPLY(preq->preq_opclass))
    925 					xflag |= PUFFS_SETATTR_FAF;
    926 
    927 				error = pops->puffs_node_write2(pu,
    928 				    opcookie, auxt->pvnr_data,
    929 				    auxt->pvnr_offset, &auxt->pvnr_resid,
    930 				    pcr, auxt->pvnr_ioflag, xflag);
    931 
    932 			} else if (pops->puffs_node_write != NULL) {
    933 				error = pops->puffs_node_write(pu,
    934 				    opcookie, auxt->pvnr_data,
    935 				    auxt->pvnr_offset, &auxt->pvnr_resid,
    936 				    pcr, auxt->pvnr_ioflag);
    937 			} else {
    938 				error = EIO;
    939 				break;
    940 			}
    941 
    942 
    943 			/* don't need to move data back to the kernel */
    944 			preq->preq_buflen = sizeof(struct puffs_vnmsg_write);
    945 			break;
    946 		}
    947 
    948 		case PUFFS_VN_POLL:
    949 		{
    950 			struct puffs_vnmsg_poll *auxt = auxbuf;
    951 
    952 			if (pops->puffs_node_poll == NULL) {
    953 				error = 0;
    954 
    955 				/* emulate genfs_poll() */
    956 				auxt->pvnr_events &= (POLLIN | POLLOUT
    957 						    | POLLRDNORM | POLLWRNORM);
    958 
    959 				break;
    960 			}
    961 
    962 			error = pops->puffs_node_poll(pu,
    963 			    opcookie, &auxt->pvnr_events);
    964 			break;
    965 		}
    966 
    967 		case PUFFS_VN_GETEXTATTR:
    968 		{
    969 			struct puffs_vnmsg_getextattr *auxt = auxbuf;
    970 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
    971 			size_t res, *resp, *sizep;
    972 			uint8_t *data;
    973 
    974 			if (pops->puffs_node_getextattr == NULL) {
    975 				error = EOPNOTSUPP;
    976 				break;
    977 			}
    978 
    979 			if (auxt->pvnr_datasize)
    980 				sizep = &auxt->pvnr_datasize;
    981 			else
    982 				sizep = NULL;
    983 
    984 			res = auxt->pvnr_resid;
    985 			if (res > 0) {
    986 				data = auxt->pvnr_data;
    987 				resp = &auxt->pvnr_resid;
    988 			} else {
    989 				data = NULL;
    990 				resp = NULL;
    991 			}
    992 
    993 			error = pops->puffs_node_getextattr(pu,
    994 			    opcookie, auxt->pvnr_attrnamespace,
    995 			    auxt->pvnr_attrname, sizep, data, resp, pcr);
    996 
    997 			/* need to move a bit more? */
    998 			preq->preq_buflen =
    999 			    sizeof(struct puffs_vnmsg_getextattr)
   1000 			    + (res - auxt->pvnr_resid);
   1001 			break;
   1002 		}
   1003 
   1004 		case PUFFS_VN_SETEXTATTR:
   1005 		{
   1006 			struct puffs_vnmsg_setextattr *auxt = auxbuf;
   1007 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
   1008 			size_t *resp;
   1009 			uint8_t *data;
   1010 
   1011 			if (pops->puffs_node_setextattr == NULL) {
   1012 				error = EOPNOTSUPP;
   1013 				break;
   1014 			}
   1015 
   1016 			if (auxt->pvnr_resid > 0) {
   1017 				data = auxt->pvnr_data;
   1018 				resp = &auxt->pvnr_resid;
   1019 			} else {
   1020 				data = NULL;
   1021 				resp = NULL;
   1022 			}
   1023 
   1024 			error = pops->puffs_node_setextattr(pu,
   1025 			    opcookie, auxt->pvnr_attrnamespace,
   1026 			    auxt->pvnr_attrname, data, resp, pcr);
   1027 			break;
   1028 		}
   1029 
   1030 		case PUFFS_VN_LISTEXTATTR:
   1031 		{
   1032 			struct puffs_vnmsg_listextattr *auxt = auxbuf;
   1033 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
   1034 			size_t res, *resp, *sizep;
   1035 			int flag;
   1036 			uint8_t *data;
   1037 
   1038 			if (pops->puffs_node_listextattr == NULL) {
   1039 				error = EOPNOTSUPP;
   1040 				break;
   1041 			}
   1042 
   1043 			if (auxt->pvnr_datasize)
   1044 				sizep = &auxt->pvnr_datasize;
   1045 			else
   1046 				sizep = NULL;
   1047 
   1048 			res = auxt->pvnr_resid;
   1049 			if (res > 0) {
   1050 				data = auxt->pvnr_data;
   1051 				resp = &auxt->pvnr_resid;
   1052 			} else {
   1053 				data = NULL;
   1054 				resp = NULL;
   1055 			}
   1056 
   1057 			res = auxt->pvnr_resid;
   1058 			flag = auxt->pvnr_flag;
   1059 			error = pops->puffs_node_listextattr(pu,
   1060 			    opcookie, auxt->pvnr_attrnamespace,
   1061 			    sizep, data, resp, flag, pcr);
   1062 
   1063 			/* need to move a bit more? */
   1064 			preq->preq_buflen =
   1065 			    sizeof(struct puffs_vnmsg_listextattr)
   1066 			    + (res - auxt->pvnr_resid);
   1067 			break;
   1068 		}
   1069 
   1070 		case PUFFS_VN_DELETEEXTATTR:
   1071 		{
   1072 			struct puffs_vnmsg_deleteextattr *auxt = auxbuf;
   1073 			PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
   1074 
   1075 			if (pops->puffs_node_deleteextattr == NULL) {
   1076 				error = EOPNOTSUPP;
   1077 				break;
   1078 			}
   1079 
   1080 			error = pops->puffs_node_deleteextattr(pu,
   1081 			    opcookie, auxt->pvnr_attrnamespace,
   1082 			    auxt->pvnr_attrname, pcr);
   1083 			break;
   1084 		}
   1085 
   1086 		default:
   1087 			printf("inval op %d\n", preq->preq_optype);
   1088 			error = EINVAL;
   1089 			break;
   1090 		}
   1091 
   1092 #if 0
   1093 	/* not issued by kernel currently */
   1094 	} else if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_CACHE) {
   1095 		struct puffs_cacheinfo *pci = (void *)preq;
   1096 
   1097 		if (pu->pu_ops.puffs_cache_write) {
   1098 			pu->pu_ops.puffs_cache_write(pu, preq->preq_cookie,
   1099 			    pci->pcache_nruns, pci->pcache_runs);
   1100 		}
   1101 		error = 0;
   1102 #endif
   1103 
   1104 	} else if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_ERROR) {
   1105 		struct puffs_error *perr = (void *)preq;
   1106 
   1107 		pu->pu_errnotify(pu, preq->preq_optype,
   1108 		    perr->perr_error, perr->perr_str, preq->preq_cookie);
   1109 		error = 0;
   1110 	} else {
   1111 		/*
   1112 		 * I guess the kernel sees this one coming also
   1113 		 */
   1114 		error = EINVAL;
   1115 	}
   1116 
   1117  out:
   1118 	preq->preq_rv = error;
   1119 
   1120 	if (pu->pu_oppost)
   1121 		pu->pu_oppost(pu);
   1122 
   1123 	pcc->pcc_flags |= PCC_DONE;
   1124 }
   1125