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