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