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