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