Home | History | Annotate | Line # | Download | only in puffs
puffs_msgif.c revision 1.51
      1  1.51    pooka /*	$NetBSD: puffs_msgif.c,v 1.51 2007/11/04 17:32:34 pooka Exp $	*/
      2   1.1    pooka 
      3   1.1    pooka /*
      4  1.16    pooka  * Copyright (c) 2005, 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.1    pooka  * Google Summer of Code program and the Ulla Tuominen Foundation.
      8   1.1    pooka  * The Google SoC project was mentored by Bill Studenmund.
      9   1.1    pooka  *
     10   1.1    pooka  * Redistribution and use in source and binary forms, with or without
     11   1.1    pooka  * modification, are permitted provided that the following conditions
     12   1.1    pooka  * are met:
     13   1.1    pooka  * 1. Redistributions of source code must retain the above copyright
     14   1.1    pooka  *    notice, this list of conditions and the following disclaimer.
     15   1.1    pooka  * 2. Redistributions in binary form must reproduce the above copyright
     16   1.1    pooka  *    notice, this list of conditions and the following disclaimer in the
     17   1.1    pooka  *    documentation and/or other materials provided with the distribution.
     18   1.1    pooka  *
     19   1.1    pooka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     20   1.1    pooka  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     21   1.1    pooka  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     22   1.1    pooka  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     23   1.1    pooka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     24   1.1    pooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     25   1.1    pooka  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     26   1.1    pooka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     27   1.1    pooka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     28   1.1    pooka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     29   1.1    pooka  * SUCH DAMAGE.
     30   1.1    pooka  */
     31   1.1    pooka 
     32   1.1    pooka #include <sys/cdefs.h>
     33  1.51    pooka __KERNEL_RCSID(0, "$NetBSD: puffs_msgif.c,v 1.51 2007/11/04 17:32:34 pooka Exp $");
     34   1.1    pooka 
     35   1.1    pooka #include <sys/param.h>
     36  1.16    pooka #include <sys/fstrans.h>
     37  1.46    pooka #include <sys/kmem.h>
     38   1.1    pooka #include <sys/malloc.h>
     39   1.1    pooka #include <sys/mount.h>
     40   1.1    pooka #include <sys/vnode.h>
     41   1.1    pooka #include <sys/lock.h>
     42  1.39       ad #include <sys/proc.h>
     43   1.1    pooka 
     44   1.1    pooka #include <fs/puffs/puffs_msgif.h>
     45   1.1    pooka #include <fs/puffs/puffs_sys.h>
     46   1.1    pooka 
     47  1.22    pooka /*
     48  1.22    pooka  * waitq data structures
     49  1.22    pooka  */
     50  1.22    pooka 
     51  1.22    pooka /*
     52  1.22    pooka  * While a request is going to userspace, park the caller within the
     53  1.22    pooka  * kernel.  This is the kernel counterpart of "struct puffs_req".
     54  1.22    pooka  */
     55  1.46    pooka struct puffs_msgpark {
     56  1.22    pooka 	struct puffs_req	*park_preq;	/* req followed by buf	*/
     57  1.22    pooka 
     58  1.22    pooka 	size_t			park_copylen;	/* userspace copylength	*/
     59  1.22    pooka 	size_t			park_maxlen;	/* max size in comeback */
     60  1.24    pooka 
     61  1.46    pooka 	parkdone_fn		park_done;	/* "biodone" a'la puffs	*/
     62  1.24    pooka 	void			*park_donearg;
     63  1.22    pooka 
     64  1.22    pooka 	int			park_flags;
     65  1.26    pooka 	int			park_refcount;
     66  1.22    pooka 
     67  1.22    pooka 	kcondvar_t		park_cv;
     68  1.26    pooka 	kmutex_t		park_mtx;
     69  1.26    pooka 
     70  1.46    pooka 	TAILQ_ENTRY(puffs_msgpark) park_entries;
     71  1.22    pooka };
     72  1.22    pooka #define PARKFLAG_WAITERGONE	0x01
     73  1.26    pooka #define PARKFLAG_DONE		0x02
     74  1.26    pooka #define PARKFLAG_ONQUEUE1	0x04
     75  1.26    pooka #define PARKFLAG_ONQUEUE2	0x08
     76  1.26    pooka #define PARKFLAG_CALL		0x10
     77  1.31    pooka #define PARKFLAG_WANTREPLY	0x20
     78  1.22    pooka 
     79  1.22    pooka static struct pool_cache parkpc;
     80  1.22    pooka static struct pool parkpool;
     81  1.22    pooka 
     82  1.22    pooka static int
     83  1.22    pooka makepark(void *arg, void *obj, int flags)
     84  1.22    pooka {
     85  1.46    pooka 	struct puffs_msgpark *park = obj;
     86  1.22    pooka 
     87  1.26    pooka 	mutex_init(&park->park_mtx, MUTEX_DEFAULT, IPL_NONE);
     88  1.22    pooka 	cv_init(&park->park_cv, "puffsrpl");
     89  1.22    pooka 
     90  1.22    pooka 	return 0;
     91  1.22    pooka }
     92  1.22    pooka 
     93  1.22    pooka static void
     94  1.22    pooka nukepark(void *arg, void *obj)
     95  1.22    pooka {
     96  1.46    pooka 	struct puffs_msgpark *park = obj;
     97  1.22    pooka 
     98  1.22    pooka 	cv_destroy(&park->park_cv);
     99  1.26    pooka 	mutex_destroy(&park->park_mtx);
    100  1.22    pooka }
    101  1.22    pooka 
    102  1.22    pooka void
    103  1.22    pooka puffs_msgif_init()
    104  1.22    pooka {
    105  1.22    pooka 
    106  1.46    pooka 	pool_init(&parkpool, sizeof(struct puffs_msgpark), 0, 0, 0,
    107  1.22    pooka 	    "puffprkl", &pool_allocator_nointr, IPL_NONE);
    108  1.22    pooka 	pool_cache_init(&parkpc, &parkpool, makepark, nukepark, NULL);
    109  1.22    pooka }
    110  1.22    pooka 
    111  1.22    pooka void
    112  1.22    pooka puffs_msgif_destroy()
    113  1.22    pooka {
    114  1.22    pooka 
    115  1.22    pooka 	pool_cache_destroy(&parkpc);
    116  1.22    pooka 	pool_destroy(&parkpool);
    117  1.22    pooka }
    118  1.22    pooka 
    119  1.46    pooka static int alloced;
    120  1.46    pooka 
    121  1.46    pooka static struct puffs_msgpark *
    122  1.46    pooka puffs_msgpark_alloc(int waitok)
    123  1.26    pooka {
    124  1.46    pooka 	struct puffs_msgpark *park;
    125  1.26    pooka 
    126  1.26    pooka 	park = pool_cache_get(&parkpc, waitok ? PR_WAITOK : PR_NOWAIT);
    127  1.46    pooka 	if (park == NULL)
    128  1.46    pooka 		return park;
    129  1.46    pooka 
    130  1.46    pooka 	park->park_refcount = 1;
    131  1.46    pooka 	park->park_preq = NULL;
    132  1.46    pooka 	park->park_flags = PARKFLAG_WANTREPLY;
    133  1.26    pooka 
    134  1.26    pooka 	return park;
    135  1.26    pooka }
    136  1.26    pooka 
    137  1.26    pooka static void
    138  1.46    pooka puffs_msgpark_reference(struct puffs_msgpark *park)
    139  1.22    pooka {
    140  1.22    pooka 
    141  1.46    pooka 	KASSERT(mutex_owned(&park->park_mtx));
    142  1.26    pooka 	park->park_refcount++;
    143  1.22    pooka }
    144  1.22    pooka 
    145  1.46    pooka /*
    146  1.46    pooka  * Release reference to park structure.
    147  1.46    pooka  */
    148  1.46    pooka static void
    149  1.46    pooka puffs_msgpark_release1(struct puffs_msgpark *park, int howmany)
    150  1.22    pooka {
    151  1.46    pooka 	struct puffs_req *preq = park->park_preq;
    152  1.46    pooka 	int refcnt;
    153  1.22    pooka 
    154  1.26    pooka 	KASSERT(mutex_owned(&park->park_mtx));
    155  1.46    pooka 	refcnt = park->park_refcount -= howmany;
    156  1.46    pooka 	mutex_exit(&park->park_mtx);
    157  1.46    pooka 
    158  1.46    pooka 	KASSERT(refcnt >= 0);
    159  1.26    pooka 
    160  1.46    pooka 	if (refcnt == 0) {
    161  1.46    pooka 		alloced--;
    162  1.46    pooka 		if (preq)
    163  1.46    pooka 			kmem_free(preq, park->park_maxlen);
    164  1.26    pooka 		pool_cache_put(&parkpc, park);
    165  1.46    pooka 	}
    166  1.22    pooka }
    167  1.46    pooka #define puffs_msgpark_release(a) puffs_msgpark_release1(a, 1)
    168  1.22    pooka 
    169  1.26    pooka #ifdef PUFFSDEBUG
    170  1.26    pooka static void
    171  1.46    pooka parkdump(struct puffs_msgpark *park)
    172  1.26    pooka {
    173  1.26    pooka 
    174  1.26    pooka 	DPRINTF(("park %p, preq %p, id %" PRIu64 "\n"
    175  1.26    pooka 	    "\tcopy %zu, max %zu - done: %p/%p\n"
    176  1.26    pooka 	    "\tflags 0x%08x, refcount %d, cv/mtx: %p/%p\n",
    177  1.46    pooka 	    park, park->park_preq, park->park_preq->preq_id,
    178  1.26    pooka 	    park->park_copylen, park->park_maxlen,
    179  1.26    pooka 	    park->park_done, park->park_donearg,
    180  1.26    pooka 	    park->park_flags, park->park_refcount,
    181  1.26    pooka 	    &park->park_cv, &park->park_mtx));
    182  1.26    pooka }
    183  1.26    pooka 
    184  1.26    pooka static void
    185  1.26    pooka parkqdump(struct puffs_wq *q, int dumpall)
    186  1.26    pooka {
    187  1.46    pooka 	struct puffs_msgpark *park;
    188  1.26    pooka 	int total = 0;
    189  1.26    pooka 
    190  1.26    pooka 	TAILQ_FOREACH(park, q, park_entries) {
    191  1.26    pooka 		if (dumpall)
    192  1.26    pooka 			parkdump(park);
    193  1.26    pooka 		total++;
    194  1.26    pooka 	}
    195  1.29    pooka 	DPRINTF(("puffs waitqueue at %p dumped, %d total\n", q, total));
    196  1.26    pooka 
    197  1.26    pooka }
    198  1.26    pooka #endif /* PUFFSDEBUG */
    199  1.22    pooka 
    200  1.22    pooka /*
    201  1.46    pooka  * A word about locking in the park structures: the lock protects the
    202  1.46    pooka  * fields of the *park* structure (not preq) and acts as an interlock
    203  1.46    pooka  * in cv operations.  The lock is always internal to this module and
    204  1.46    pooka  * callers do not need to worry about it.
    205  1.22    pooka  */
    206  1.46    pooka 
    207  1.46    pooka int
    208  1.46    pooka puffs_msgmem_alloc(size_t len, struct puffs_msgpark **ppark, void **mem,
    209  1.46    pooka 	int cansleep)
    210  1.46    pooka {
    211  1.46    pooka 	struct puffs_msgpark *park;
    212  1.46    pooka 	void *m;
    213  1.46    pooka 
    214  1.46    pooka 	m = kmem_zalloc(len, cansleep ? KM_SLEEP : KM_NOSLEEP);
    215  1.46    pooka 	if (m == NULL) {
    216  1.46    pooka 		KASSERT(cansleep == 0);
    217  1.46    pooka 		return ENOMEM;
    218  1.46    pooka 	}
    219  1.46    pooka 
    220  1.46    pooka 	park = puffs_msgpark_alloc(cansleep);
    221  1.46    pooka 	if (park == NULL) {
    222  1.46    pooka 		KASSERT(cansleep == 0);
    223  1.46    pooka 		kmem_free(m, len);
    224  1.46    pooka 		return ENOMEM;
    225  1.46    pooka 	}
    226  1.46    pooka 
    227  1.46    pooka 	park->park_preq = m;
    228  1.46    pooka 	park->park_maxlen = len;
    229  1.46    pooka 
    230  1.46    pooka 	*ppark = park;
    231  1.46    pooka 	*mem = m;
    232  1.46    pooka 
    233  1.46    pooka 	return 0;
    234  1.46    pooka }
    235  1.46    pooka 
    236  1.46    pooka void
    237  1.46    pooka puffs_msgmem_release(struct puffs_msgpark *park)
    238  1.22    pooka {
    239  1.22    pooka 
    240  1.46    pooka 	if (park == NULL)
    241  1.46    pooka 		return;
    242  1.22    pooka 
    243  1.46    pooka 	mutex_enter(&park->park_mtx);
    244  1.46    pooka 	puffs_msgpark_release(park);
    245  1.46    pooka }
    246  1.22    pooka 
    247  1.46    pooka void
    248  1.46    pooka puffs_msg_setfaf(struct puffs_msgpark *park)
    249  1.46    pooka {
    250  1.22    pooka 
    251  1.36    pooka 	park->park_flags &= ~PARKFLAG_WANTREPLY;
    252  1.22    pooka }
    253  1.22    pooka 
    254   1.1    pooka /*
    255   1.1    pooka  * kernel-user-kernel waitqueues
    256   1.1    pooka  */
    257   1.1    pooka 
    258  1.46    pooka static int touser(struct puffs_mount *, struct puffs_msgpark *);
    259   1.1    pooka 
    260  1.46    pooka static uint64_t
    261  1.46    pooka puffs_getmsgid(struct puffs_mount *pmp)
    262   1.1    pooka {
    263  1.14    pooka 	uint64_t rv;
    264   1.1    pooka 
    265  1.22    pooka 	mutex_enter(&pmp->pmp_lock);
    266  1.46    pooka 	rv = pmp->pmp_nextmsgid++;
    267  1.22    pooka 	mutex_exit(&pmp->pmp_lock);
    268   1.1    pooka 
    269   1.1    pooka 	return rv;
    270   1.1    pooka }
    271   1.1    pooka 
    272   1.1    pooka /* vfs request */
    273   1.1    pooka int
    274  1.46    pooka puffs_msg_vfs(struct puffs_mount *pmp, struct puffs_msgpark *park, int optype)
    275   1.1    pooka {
    276   1.1    pooka 
    277  1.25    pooka 	park->park_preq->preq_opclass = PUFFSOP_VFS;
    278  1.25    pooka 	park->park_preq->preq_optype = optype;
    279   1.1    pooka 
    280  1.46    pooka 	park->park_copylen = park->park_maxlen;
    281   1.1    pooka 
    282  1.45    pooka 	return touser(pmp, park);
    283   1.1    pooka }
    284   1.1    pooka 
    285   1.1    pooka /*
    286   1.1    pooka  * vnode level request
    287   1.1    pooka  */
    288   1.1    pooka int
    289  1.46    pooka puffs_msg_vn(struct puffs_mount *pmp, struct puffs_msgpark *park,
    290  1.46    pooka 	int optype, size_t delta, struct vnode *vp_opc, struct vnode *vp_aux)
    291   1.1    pooka {
    292  1.35    pooka 	struct puffs_req *preq;
    293  1.35    pooka 	void *cookie = VPTOPNC(vp_opc);
    294  1.35    pooka 	struct puffs_node *pnode;
    295  1.35    pooka 	int rv;
    296   1.1    pooka 
    297  1.25    pooka 	park->park_preq->preq_opclass = PUFFSOP_VN;
    298  1.25    pooka 	park->park_preq->preq_optype = optype;
    299  1.25    pooka 	park->park_preq->preq_cookie = cookie;
    300  1.25    pooka 
    301  1.46    pooka 	KASSERT(delta < park->park_maxlen); /* "<=" wouldn't make sense */
    302  1.46    pooka 	park->park_copylen = park->park_maxlen - delta;
    303   1.1    pooka 
    304  1.45    pooka 	rv = touser(pmp, park);
    305  1.35    pooka 
    306  1.35    pooka 	/*
    307  1.35    pooka 	 * Check if the user server requests that inactive be called
    308  1.35    pooka 	 * when the time is right.
    309  1.35    pooka 	 */
    310  1.35    pooka 	preq = park->park_preq;
    311  1.35    pooka 	if (preq->preq_setbacks & PUFFS_SETBACK_INACT_N1) {
    312  1.35    pooka 		pnode = vp_opc->v_data;
    313  1.35    pooka 		pnode->pn_stat |= PNODE_DOINACT;
    314  1.35    pooka 	}
    315  1.35    pooka 	if (preq->preq_setbacks & PUFFS_SETBACK_INACT_N2) {
    316  1.35    pooka 		/* if no vp_aux, just ignore */
    317  1.35    pooka 		if (vp_aux) {
    318  1.35    pooka 			pnode = vp_aux->v_data;
    319  1.35    pooka 			pnode->pn_stat |= PNODE_DOINACT;
    320  1.35    pooka 		}
    321  1.35    pooka 	}
    322  1.37    pooka 	if (preq->preq_setbacks & PUFFS_SETBACK_NOREF_N1) {
    323  1.37    pooka 		pnode = vp_opc->v_data;
    324  1.37    pooka 		pnode->pn_stat |= PNODE_NOREFS;
    325  1.37    pooka 	}
    326  1.37    pooka 	if (preq->preq_setbacks & PUFFS_SETBACK_NOREF_N2) {
    327  1.37    pooka 		/* if no vp_aux, just ignore */
    328  1.37    pooka 		if (vp_aux) {
    329  1.37    pooka 			pnode = vp_aux->v_data;
    330  1.37    pooka 			pnode->pn_stat |= PNODE_NOREFS;
    331  1.37    pooka 		}
    332  1.37    pooka 	}
    333  1.35    pooka 
    334  1.35    pooka 	return rv;
    335   1.1    pooka }
    336   1.1    pooka 
    337  1.24    pooka void
    338  1.46    pooka puffs_msg_vncall(struct puffs_mount *pmp, struct puffs_msgpark *park,
    339  1.46    pooka 	int optype, size_t delta, parkdone_fn donefn, void *donearg,
    340  1.46    pooka 	struct vnode *vp_opc)
    341   1.1    pooka {
    342  1.35    pooka 	void *cookie = VPTOPNC(vp_opc);
    343   1.1    pooka 
    344  1.25    pooka 	park->park_preq->preq_opclass = PUFFSOP_VN;
    345  1.25    pooka 	park->park_preq->preq_optype = optype;
    346  1.25    pooka 	park->park_preq->preq_cookie = cookie;
    347  1.25    pooka 
    348  1.46    pooka 	KASSERT(delta < park->park_maxlen);
    349  1.46    pooka 	park->park_copylen = park->park_maxlen - delta;
    350  1.25    pooka 	park->park_done = donefn;
    351  1.25    pooka 	park->park_donearg = donearg;
    352  1.46    pooka 	park->park_flags |= PARKFLAG_CALL;
    353   1.1    pooka 
    354  1.45    pooka 	(void) touser(pmp, park);
    355  1.20    pooka }
    356  1.20    pooka 
    357  1.46    pooka int
    358  1.46    pooka puffs_msg_raw(struct puffs_mount *pmp, struct puffs_msgpark *park)
    359   1.4    pooka {
    360   1.4    pooka 
    361  1.46    pooka 	park->park_copylen = park->park_maxlen;
    362   1.4    pooka 
    363  1.46    pooka 	return touser(pmp, park);
    364   1.4    pooka }
    365   1.4    pooka 
    366  1.21    pooka void
    367  1.46    pooka puffs_msg_errnotify(struct puffs_mount *pmp, uint8_t type, int error,
    368  1.42    pooka 	const char *str, void *cookie)
    369  1.41    pooka {
    370  1.46    pooka 	struct puffs_msgpark *park;
    371  1.41    pooka 	struct puffs_error *perr;
    372  1.41    pooka 
    373  1.46    pooka 	puffs_msgmem_alloc(sizeof(struct puffs_error), &park, (void **)&perr,1);
    374  1.41    pooka 
    375  1.41    pooka 	perr->perr_error = error;
    376  1.42    pooka 	strlcpy(perr->perr_str, str, sizeof(perr->perr_str));
    377  1.41    pooka 
    378  1.46    pooka 	park->park_preq->preq_opclass |= PUFFSOP_ERROR | PUFFSOPFLAG_FAF;
    379  1.41    pooka 	park->park_preq->preq_optype = type;
    380  1.41    pooka 	park->park_preq->preq_cookie = cookie;
    381  1.41    pooka 
    382  1.46    pooka 	park->park_copylen = park->park_maxlen;
    383  1.41    pooka 
    384  1.45    pooka 	(void)touser(pmp, park);
    385  1.41    pooka }
    386  1.41    pooka 
    387   1.4    pooka /*
    388  1.51    pooka  * Wait for the userspace ping-pong game in calling process context,
    389  1.51    pooka  * unless a FAF / async call, in which case just enqueues the request
    390  1.51    pooka  * and return immediately.
    391   1.1    pooka  */
    392   1.1    pooka static int
    393  1.46    pooka touser(struct puffs_mount *pmp, struct puffs_msgpark *park)
    394   1.1    pooka {
    395  1.26    pooka 	struct lwp *l = curlwp;
    396  1.16    pooka 	struct mount *mp;
    397   1.9    pooka 	struct puffs_req *preq;
    398  1.19    pooka 	int rv = 0;
    399   1.1    pooka 
    400  1.16    pooka 	mp = PMPTOMP(pmp);
    401  1.25    pooka 	preq = park->park_preq;
    402  1.46    pooka 	preq->preq_buflen = park->park_maxlen;
    403  1.45    pooka 	KASSERT(preq->preq_id == 0);
    404  1.46    pooka 
    405  1.46    pooka 	if ((park->park_flags & PARKFLAG_WANTREPLY) == 0)
    406  1.46    pooka 		preq->preq_opclass |= PUFFSOPFLAG_FAF;
    407  1.46    pooka 	else
    408  1.46    pooka 		preq->preq_id = puffs_getmsgid(pmp);
    409  1.31    pooka 
    410  1.49    pooka 	/* fill in caller information */
    411  1.49    pooka 	preq->preq_pid = l->l_proc->p_pid;
    412  1.49    pooka 	preq->preq_lid = l->l_lid;
    413  1.49    pooka 
    414  1.19    pooka 	/*
    415  1.51    pooka 	 * To support cv_sig, yet another movie: check if there are signals
    416  1.19    pooka 	 * pending and we are issueing a non-FAF.  If so, return an error
    417  1.19    pooka 	 * directly UNLESS we are issueing INACTIVE.  In that case, convert
    418  1.19    pooka 	 * it to a FAF, fire off to the file server and return an error.
    419  1.19    pooka 	 * Yes, this is bordering disgusting.  Barfbags are on me.
    420  1.19    pooka 	 */
    421  1.31    pooka 	if ((park->park_flags & PARKFLAG_WANTREPLY)
    422  1.25    pooka 	   && (park->park_flags & PARKFLAG_CALL) == 0
    423  1.19    pooka 	   && (l->l_flag & LW_PENDSIG) != 0 && sigispending(l, 0)) {
    424  1.19    pooka 		if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN
    425  1.19    pooka 		    && preq->preq_optype == PUFFS_VN_INACTIVE) {
    426  1.46    pooka 			park->park_preq->preq_opclass |= PUFFSOPFLAG_FAF;
    427  1.46    pooka 			park->park_flags &= ~PARKFLAG_WANTREPLY;
    428  1.25    pooka 			DPRINTF(("puffs touser: converted to FAF %p\n", park));
    429  1.19    pooka 			rv = EINTR;
    430  1.19    pooka 		} else {
    431  1.19    pooka 			return EINTR;
    432  1.19    pooka 		}
    433  1.19    pooka 	}
    434  1.16    pooka 
    435  1.16    pooka 	/*
    436  1.16    pooka 	 * test for suspension lock.
    437  1.16    pooka 	 *
    438  1.16    pooka 	 * Note that we *DO NOT* keep the lock, since that might block
    439  1.16    pooka 	 * lock acquiring PLUS it would give userlandia control over
    440  1.16    pooka 	 * the lock.  The operation queue enforces a strict ordering:
    441  1.16    pooka 	 * when the fs server gets in the op stream, it knows things
    442  1.16    pooka 	 * are in order.  The kernel locks can't guarantee that for
    443  1.16    pooka 	 * userspace, in any case.
    444  1.16    pooka 	 *
    445  1.16    pooka 	 * BUT: this presents a problem for ops which have a consistency
    446  1.16    pooka 	 * clause based on more than one operation.  Unfortunately such
    447  1.16    pooka 	 * operations (read, write) do not reliably work yet.
    448  1.16    pooka 	 *
    449  1.16    pooka 	 * Ya, Ya, it's wrong wong wrong, me be fixink this someday.
    450  1.18    pooka 	 *
    451  1.18    pooka 	 * XXX: and there is one more problem.  We sometimes need to
    452  1.18    pooka 	 * take a lazy lock in case the fs is suspending and we are
    453  1.18    pooka 	 * executing as the fs server context.  This might happen
    454  1.18    pooka 	 * e.g. in the case that the user server triggers a reclaim
    455  1.18    pooka 	 * in the kernel while the fs is suspending.  It's not a very
    456  1.18    pooka 	 * likely event, but it needs to be fixed some day.
    457  1.16    pooka 	 */
    458  1.22    pooka 
    459  1.22    pooka 	/*
    460  1.22    pooka 	 * MOREXXX: once PUFFS_WCACHEINFO is enabled, we can't take
    461  1.22    pooka 	 * the mutex here, since getpages() might be called locked.
    462  1.22    pooka 	 */
    463  1.18    pooka 	fstrans_start(mp, FSTRANS_NORMAL);
    464  1.22    pooka 	mutex_enter(&pmp->pmp_lock);
    465  1.16    pooka 	fstrans_done(mp);
    466  1.16    pooka 
    467  1.13    pooka 	if (pmp->pmp_status != PUFFSTAT_RUNNING) {
    468  1.22    pooka 		mutex_exit(&pmp->pmp_lock);
    469   1.1    pooka 		return ENXIO;
    470   1.1    pooka 	}
    471   1.1    pooka 
    472  1.26    pooka #ifdef PUFFSDEBUG
    473  1.46    pooka 	parkqdump(&pmp->pmp_msg_touser, puffsdebug > 1);
    474  1.46    pooka 	parkqdump(&pmp->pmp_msg_replywait, puffsdebug > 1);
    475  1.26    pooka #endif
    476  1.26    pooka 
    477  1.46    pooka 	mutex_enter(&park->park_mtx);
    478  1.46    pooka 	TAILQ_INSERT_TAIL(&pmp->pmp_msg_touser, park, park_entries);
    479  1.26    pooka 	park->park_flags |= PARKFLAG_ONQUEUE1;
    480  1.34    pooka 	puffs_mp_reference(pmp);
    481  1.46    pooka 	pmp->pmp_msg_touser_count++;
    482  1.26    pooka 	mutex_exit(&pmp->pmp_lock);
    483   1.1    pooka 
    484  1.20    pooka 	DPRINTF(("touser: req %" PRIu64 ", preq: %p, park: %p, "
    485  1.25    pooka 	    "c/t: 0x%x/0x%x, f: 0x%x\n", preq->preq_id, preq, park,
    486  1.25    pooka 	    preq->preq_opclass, preq->preq_optype, park->park_flags));
    487  1.15    pooka 
    488  1.46    pooka 	cv_broadcast(&pmp->pmp_msg_waiter_cv);
    489   1.1    pooka 	selnotify(pmp->pmp_sel, 0);
    490   1.1    pooka 
    491  1.31    pooka 	if ((park->park_flags & PARKFLAG_WANTREPLY)
    492  1.25    pooka 	    && (park->park_flags & PARKFLAG_CALL) == 0) {
    493  1.19    pooka 		int error;
    494  1.19    pooka 
    495  1.26    pooka 		error = cv_wait_sig(&park->park_cv, &park->park_mtx);
    496  1.46    pooka 		DPRINTF(("puffs_touser: waiter for %p woke up with %d\n",
    497  1.46    pooka 		    park, error));
    498  1.19    pooka 		if (error) {
    499  1.25    pooka 			park->park_flags |= PARKFLAG_WAITERGONE;
    500  1.26    pooka 			if (park->park_flags & PARKFLAG_DONE) {
    501  1.22    pooka 				rv = preq->preq_rv;
    502  1.19    pooka 			} else {
    503  1.26    pooka 				/*
    504  1.26    pooka 				 * ok, we marked it as going away, but
    505  1.26    pooka 				 * still need to do queue ops.  take locks
    506  1.26    pooka 				 * in correct order.
    507  1.26    pooka 				 *
    508  1.26    pooka 				 * We don't want to release our reference
    509  1.26    pooka 				 * if it's on replywait queue to avoid error
    510  1.26    pooka 				 * to file server.  putop() code will DTRT.
    511  1.26    pooka 				 */
    512  1.26    pooka 				mutex_exit(&park->park_mtx);
    513  1.26    pooka 				mutex_enter(&pmp->pmp_lock);
    514  1.26    pooka 				mutex_enter(&park->park_mtx);
    515  1.46    pooka 
    516  1.46    pooka 				/* remove from queue1 */
    517  1.36    pooka 				if (park->park_flags & PARKFLAG_ONQUEUE1) {
    518  1.46    pooka 					TAILQ_REMOVE(&pmp->pmp_msg_touser,
    519  1.26    pooka 					    park, park_entries);
    520  1.46    pooka 					pmp->pmp_msg_touser_count--;
    521  1.36    pooka 					park->park_flags &= ~PARKFLAG_ONQUEUE1;
    522  1.36    pooka 				}
    523  1.46    pooka 
    524  1.46    pooka 				/*
    525  1.46    pooka 				 * If it's waiting for a response already,
    526  1.46    pooka 				 * boost reference count.  Park will get
    527  1.46    pooka 				 * nuked once the response arrives from
    528  1.46    pooka 				 * the file server.
    529  1.46    pooka 				 */
    530  1.46    pooka 				if (park->park_flags & PARKFLAG_ONQUEUE2)
    531  1.46    pooka 					puffs_msgpark_reference(park);
    532  1.46    pooka 
    533  1.26    pooka 				mutex_exit(&pmp->pmp_lock);
    534  1.26    pooka 
    535  1.22    pooka 				rv = error;
    536  1.19    pooka 			}
    537  1.22    pooka 		} else {
    538  1.22    pooka 			rv = preq->preq_rv;
    539  1.19    pooka 		}
    540  1.22    pooka 
    541  1.16    pooka 		/*
    542  1.16    pooka 		 * retake the lock and release.  This makes sure (haha,
    543  1.16    pooka 		 * I'm humorous) that we don't process the same vnode in
    544  1.16    pooka 		 * multiple threads due to the locks hacks we have in
    545  1.16    pooka 		 * puffs_lock().  In reality this is well protected by
    546  1.16    pooka 		 * the biglock, but once that's gone, well, hopefully
    547  1.16    pooka 		 * this will be fixed for real.  (and when you read this
    548  1.16    pooka 		 * comment in 2017 and subsequently barf, my condolences ;).
    549  1.16    pooka 		 */
    550  1.19    pooka 		if (rv == 0 && !fstrans_is_owner(mp)) {
    551  1.17  hannken 			fstrans_start(mp, FSTRANS_NORMAL);
    552  1.16    pooka 			fstrans_done(mp);
    553  1.16    pooka 		}
    554  1.51    pooka 
    555  1.22    pooka 	} else {
    556  1.46    pooka 		/*
    557  1.46    pooka 		 * Take extra reference for FAF, i.e. don't free us
    558  1.46    pooka 		 * immediately upon return to the caller, but rather
    559  1.46    pooka 		 * only when the message has been transported.
    560  1.46    pooka 		 */
    561  1.46    pooka 		puffs_msgpark_reference(park);
    562  1.16    pooka 	}
    563  1.16    pooka 
    564  1.46    pooka 	mutex_exit(&park->park_mtx);
    565  1.46    pooka 
    566  1.22    pooka 	mutex_enter(&pmp->pmp_lock);
    567  1.34    pooka 	puffs_mp_release(pmp);
    568  1.22    pooka 	mutex_exit(&pmp->pmp_lock);
    569  1.16    pooka 
    570  1.19    pooka 	return rv;
    571   1.1    pooka }
    572   1.1    pooka 
    573   1.9    pooka /*
    574  1.46    pooka  * Get next request in the outgoing queue.  "maxsize" controls the
    575  1.46    pooka  * size the caller can accommodate and "nonblock" signals if this
    576  1.46    pooka  * should block while waiting for input.  Handles all locking internally.
    577   1.9    pooka  */
    578  1.10    pooka int
    579  1.46    pooka puffs_msgif_getout(void *this, size_t maxsize, int nonblock,
    580  1.46    pooka 	uint8_t **data, size_t *dlen, void **parkptr)
    581   1.1    pooka {
    582  1.46    pooka 	struct puffs_mount *pmp = this;
    583  1.46    pooka 	struct puffs_msgpark *park;
    584   1.9    pooka 	struct puffs_req *preq;
    585  1.46    pooka 	int error;
    586   1.1    pooka 
    587  1.46    pooka 	error = 0;
    588  1.22    pooka 	mutex_enter(&pmp->pmp_lock);
    589  1.50    pooka 	puffs_mp_reference(pmp);
    590  1.46    pooka 	for (;;) {
    591  1.46    pooka 		/* RIP? */
    592   1.9    pooka 		if (pmp->pmp_status != PUFFSTAT_RUNNING) {
    593   1.9    pooka 			error = ENXIO;
    594  1.46    pooka 			break;
    595   1.9    pooka 		}
    596  1.12    pooka 
    597  1.46    pooka 		/* need platinum yendorian express card? */
    598  1.46    pooka 		if (TAILQ_EMPTY(&pmp->pmp_msg_touser)) {
    599  1.46    pooka 			DPRINTF(("puffs_getout: no outgoing op, "));
    600  1.12    pooka 			if (nonblock) {
    601  1.46    pooka 				DPRINTF(("returning EWOULDBLOCK\n"));
    602  1.12    pooka 				error = EWOULDBLOCK;
    603  1.46    pooka 				break;
    604   1.9    pooka 			}
    605  1.46    pooka 			DPRINTF(("waiting ...\n"));
    606   1.9    pooka 
    607  1.46    pooka 			error = cv_wait_sig(&pmp->pmp_msg_waiter_cv,
    608  1.22    pooka 			    &pmp->pmp_lock);
    609  1.11    pooka 			if (error)
    610  1.46    pooka 				break;
    611  1.11    pooka 			else
    612  1.46    pooka 				continue;
    613   1.9    pooka 		}
    614   1.9    pooka 
    615  1.46    pooka 		park = TAILQ_FIRST(&pmp->pmp_msg_touser);
    616  1.50    pooka 		if (park == NULL)
    617  1.50    pooka 			continue;
    618  1.50    pooka 
    619  1.46    pooka 		mutex_enter(&park->park_mtx);
    620  1.46    pooka 		puffs_msgpark_reference(park);
    621  1.46    pooka 
    622  1.46    pooka 		DPRINTF(("puffs_getout: found park at %p, ", park));
    623  1.22    pooka 
    624  1.22    pooka 		/* If it's a goner, don't process any furher */
    625  1.22    pooka 		if (park->park_flags & PARKFLAG_WAITERGONE) {
    626  1.46    pooka 			DPRINTF(("waitergone!\n"));
    627  1.46    pooka 			puffs_msgpark_release(park);
    628  1.22    pooka 			continue;
    629  1.22    pooka 		}
    630  1.22    pooka 
    631  1.46    pooka 		/* check size */
    632  1.26    pooka 		preq = park->park_preq;
    633  1.46    pooka 		if (maxsize < preq->preq_frhdr.pfr_len) {
    634  1.46    pooka 			DPRINTF(("buffer too small\n"));
    635  1.46    pooka 			puffs_msgpark_release(park);
    636  1.46    pooka 			error = E2BIG;
    637  1.46    pooka 			break;
    638  1.26    pooka 		}
    639  1.28    pooka 
    640  1.46    pooka 		DPRINTF(("returning\n"));
    641  1.46    pooka 
    642  1.46    pooka 		/*
    643  1.46    pooka 		 * Ok, we found what we came for.  Release it from the
    644  1.46    pooka 		 * outgoing queue but do not unlock.  We will unlock
    645  1.46    pooka 		 * only after we "releaseout" it to avoid complications:
    646  1.46    pooka 		 * otherwise it is (theoretically) possible for userland
    647  1.46    pooka 		 * to race us into "put" before we have a change to put
    648  1.46    pooka 		 * this baby on the receiving queue.
    649  1.46    pooka 		 */
    650  1.46    pooka 		TAILQ_REMOVE(&pmp->pmp_msg_touser, park, park_entries);
    651  1.28    pooka 		KASSERT(park->park_flags & PARKFLAG_ONQUEUE1);
    652  1.28    pooka 		park->park_flags &= ~PARKFLAG_ONQUEUE1;
    653  1.46    pooka 		mutex_exit(&park->park_mtx);
    654  1.46    pooka 
    655  1.46    pooka 		pmp->pmp_msg_touser_count--;
    656  1.46    pooka 		KASSERT(pmp->pmp_msg_touser_count >= 0);
    657  1.26    pooka 
    658  1.46    pooka 		break;
    659  1.46    pooka 	}
    660  1.50    pooka 	puffs_mp_release(pmp);
    661  1.46    pooka 	mutex_exit(&pmp->pmp_lock);
    662   1.9    pooka 
    663  1.46    pooka 	if (error == 0) {
    664  1.46    pooka 		*data = (uint8_t *)preq;
    665  1.48    pooka 		preq->preq_frhdr.pfr_len = park->park_copylen;
    666  1.48    pooka 		preq->preq_frhdr.pfr_alloclen = park->park_maxlen;
    667  1.47    pooka 		preq->preq_frhdr.pfr_type = preq->preq_opclass; /* yay! */
    668  1.46    pooka 		*dlen = preq->preq_frhdr.pfr_len;
    669  1.46    pooka 		*parkptr = park;
    670  1.46    pooka 	}
    671  1.51    pooka 
    672  1.46    pooka 	return error;
    673  1.46    pooka }
    674   1.9    pooka 
    675  1.46    pooka /*
    676  1.46    pooka  * Release outgoing structure.  Now, depending on the success of the
    677  1.46    pooka  * outgoing send, it is either going onto the result waiting queue
    678  1.46    pooka  * or the death chamber.
    679  1.46    pooka  */
    680  1.46    pooka void
    681  1.46    pooka puffs_msgif_releaseout(void *this, void *parkptr, int status)
    682  1.46    pooka {
    683  1.46    pooka 	struct puffs_mount *pmp = this;
    684  1.46    pooka 	struct puffs_msgpark *park = parkptr;
    685  1.32    pooka 
    686  1.46    pooka 	DPRINTF(("puffs_releaseout: returning park %p, errno %d: " ,
    687  1.46    pooka 	    park, status));
    688  1.46    pooka 	mutex_enter(&pmp->pmp_lock);
    689  1.46    pooka 	mutex_enter(&park->park_mtx);
    690  1.46    pooka 	if (park->park_flags & PARKFLAG_WANTREPLY) {
    691  1.46    pooka 		if (status == 0) {
    692  1.46    pooka 			DPRINTF(("enqueue replywait\n"));
    693  1.46    pooka 			TAILQ_INSERT_TAIL(&pmp->pmp_msg_replywait, park,
    694  1.22    pooka 			    park_entries);
    695  1.26    pooka 			park->park_flags |= PARKFLAG_ONQUEUE2;
    696   1.9    pooka 		} else {
    697  1.46    pooka 			DPRINTF(("error path!\n"));
    698  1.46    pooka 			park->park_preq->preq_rv = status;
    699  1.46    pooka 			park->park_flags |= PARKFLAG_DONE;
    700  1.46    pooka 			cv_signal(&park->park_cv);
    701   1.1    pooka 		}
    702  1.46    pooka 		puffs_msgpark_release(park);
    703  1.46    pooka 	} else {
    704  1.46    pooka 		DPRINTF(("release\n"));
    705  1.46    pooka 		puffs_msgpark_release1(park, 2);
    706   1.1    pooka 	}
    707  1.22    pooka 	mutex_exit(&pmp->pmp_lock);
    708   1.1    pooka }
    709   1.1    pooka 
    710  1.50    pooka /*
    711  1.50    pooka  * XXX: locking with this one?
    712  1.50    pooka  */
    713  1.46    pooka void
    714  1.46    pooka puffs_msgif_incoming(void *this, void *buf)
    715   1.1    pooka {
    716  1.46    pooka 	struct puffs_mount *pmp = this;
    717  1.46    pooka 	struct puffs_req *preq = buf;
    718  1.46    pooka 	struct puffs_frame *pfr = &preq->preq_frhdr;
    719  1.46    pooka 	struct puffs_msgpark *park;
    720  1.46    pooka 	int release, wgone;
    721  1.46    pooka 
    722  1.46    pooka 	/* XXX */
    723  1.46    pooka 	if (PUFFSOP_OPCLASS(preq->preq_opclass) != PUFFSOP_VN
    724  1.46    pooka 	    && PUFFSOP_OPCLASS(preq->preq_opclass) != PUFFSOP_VFS)
    725  1.46    pooka 		return;
    726   1.1    pooka 
    727  1.22    pooka 	mutex_enter(&pmp->pmp_lock);
    728   1.9    pooka 
    729  1.46    pooka 	/* Locate waiter */
    730  1.46    pooka 	TAILQ_FOREACH(park, &pmp->pmp_msg_replywait, park_entries) {
    731  1.46    pooka 		if (park->park_preq->preq_id == preq->preq_id)
    732   1.1    pooka 			break;
    733  1.46    pooka 	}
    734  1.46    pooka 	if (park == NULL) {
    735  1.46    pooka 		DPRINTF(("puffs_msgif_income: no request: %" PRIu64 "\n",
    736  1.46    pooka 		    preq->preq_id));
    737  1.46    pooka 		mutex_exit(&pmp->pmp_lock);
    738  1.46    pooka 		return; /* XXX send error */
    739  1.46    pooka 	}
    740  1.26    pooka 
    741  1.46    pooka 	mutex_enter(&park->park_mtx);
    742  1.46    pooka 	puffs_msgpark_reference(park);
    743  1.46    pooka 	if (pfr->pfr_len > park->park_maxlen) {
    744  1.46    pooka 		DPRINTF(("puffs_msgif_income: invalid buffer length: "
    745  1.46    pooka 		    "%zu (req %" PRIu64 ", \n", pfr->pfr_len, preq->preq_id));
    746  1.46    pooka 		park->park_preq->preq_rv = EPROTO;
    747  1.46    pooka 		cv_signal(&park->park_cv);
    748  1.46    pooka 		puffs_msgpark_release(park);
    749  1.22    pooka 		mutex_exit(&pmp->pmp_lock);
    750  1.46    pooka 		return; /* XXX: error */
    751  1.46    pooka 	}
    752  1.46    pooka 	wgone = park->park_flags & PARKFLAG_WAITERGONE;
    753   1.9    pooka 
    754  1.46    pooka 	KASSERT(park->park_flags & PARKFLAG_ONQUEUE2);
    755  1.46    pooka 	TAILQ_REMOVE(&pmp->pmp_msg_replywait, park, park_entries);
    756  1.46    pooka 	park->park_flags &= ~PARKFLAG_ONQUEUE2;
    757  1.46    pooka 	mutex_exit(&pmp->pmp_lock);
    758  1.24    pooka 
    759  1.46    pooka 	if (wgone) {
    760  1.46    pooka 		DPRINTF(("puffs_putop: bad service - waiter gone for "
    761  1.46    pooka 		    "park %p\n", park));
    762  1.46    pooka 		release = 2;
    763  1.46    pooka 	} else {
    764  1.24    pooka 		if (park->park_flags & PARKFLAG_CALL) {
    765  1.46    pooka 			DPRINTF(("puffs_msgif_income: call for %p, arg %p\n",
    766  1.40    pooka 			    park->park_preq, park->park_donearg));
    767  1.46    pooka 			park->park_done(pmp, buf, park->park_donearg);
    768  1.46    pooka 			release = 2;
    769  1.46    pooka 		} else {
    770  1.46    pooka 			/* XXX: yes, I know */
    771  1.46    pooka 			memcpy(park->park_preq, buf, pfr->pfr_len);
    772  1.26    pooka 			release = 1;
    773  1.20    pooka 		}
    774  1.46    pooka 	}
    775   1.1    pooka 
    776  1.46    pooka 	if (!wgone) {
    777  1.46    pooka 		DPRINTF(("puffs_putop: flagging done for "
    778  1.46    pooka 		    "park %p\n", park));
    779  1.46    pooka 		cv_signal(&park->park_cv);
    780   1.1    pooka 	}
    781   1.1    pooka 
    782  1.46    pooka 	park->park_flags |= PARKFLAG_DONE;
    783  1.46    pooka 	puffs_msgpark_release1(park, release);
    784   1.1    pooka }
    785   1.1    pooka 
    786  1.22    pooka /*
    787  1.22    pooka  * We're dead, kaput, RIP, slightly more than merely pining for the
    788  1.22    pooka  * fjords, belly-up, fallen, lifeless, finished, expired, gone to meet
    789  1.22    pooka  * our maker, ceased to be, etcetc.  YASD.  It's a dead FS!
    790  1.22    pooka  *
    791  1.22    pooka  * Caller must hold puffs mutex.
    792  1.22    pooka  */
    793  1.22    pooka void
    794  1.22    pooka puffs_userdead(struct puffs_mount *pmp)
    795  1.22    pooka {
    796  1.46    pooka 	struct puffs_msgpark *park, *park_next;
    797  1.22    pooka 
    798  1.22    pooka 	/*
    799  1.22    pooka 	 * Mark filesystem status as dying so that operations don't
    800  1.22    pooka 	 * attempt to march to userspace any longer.
    801  1.22    pooka 	 */
    802  1.22    pooka 	pmp->pmp_status = PUFFSTAT_DYING;
    803  1.22    pooka 
    804  1.22    pooka 	/* signal waiters on REQUEST TO file server queue */
    805  1.46    pooka 	for (park = TAILQ_FIRST(&pmp->pmp_msg_touser); park; park = park_next) {
    806  1.24    pooka 		uint8_t opclass;
    807  1.24    pooka 
    808  1.46    pooka 		mutex_enter(&park->park_mtx);
    809  1.46    pooka 		puffs_msgpark_reference(park);
    810  1.32    pooka 		park_next = TAILQ_NEXT(park, park_entries);
    811  1.26    pooka 
    812  1.26    pooka 		KASSERT(park->park_flags & PARKFLAG_ONQUEUE1);
    813  1.46    pooka 		TAILQ_REMOVE(&pmp->pmp_msg_touser, park, park_entries);
    814  1.26    pooka 		park->park_flags &= ~PARKFLAG_ONQUEUE1;
    815  1.46    pooka 		pmp->pmp_msg_touser_count--;
    816  1.22    pooka 
    817  1.31    pooka 		/*
    818  1.51    pooka 		 * Even though waiters on QUEUE1 are removed in touser()
    819  1.51    pooka 		 * in case of WAITERGONE, it is still possible for us to
    820  1.51    pooka 		 * get raced here due to having to retake locks in said
    821  1.51    pooka 		 * touser().  In the race case simply "ignore" the item
    822  1.51    pooka 		 * on the queue and move on to the next one.
    823  1.31    pooka 		 */
    824  1.31    pooka 		if (park->park_flags & PARKFLAG_WAITERGONE) {
    825  1.31    pooka 			KASSERT((park->park_flags & PARKFLAG_CALL) == 0);
    826  1.31    pooka 			KASSERT(park->park_flags & PARKFLAG_WANTREPLY);
    827  1.46    pooka 			puffs_msgpark_release(park);
    828  1.51    pooka 
    829  1.22    pooka 		} else {
    830  1.31    pooka 			opclass = park->park_preq->preq_opclass;
    831  1.23    pooka 			park->park_preq->preq_rv = ENXIO;
    832  1.31    pooka 
    833  1.31    pooka 			if (park->park_flags & PARKFLAG_CALL) {
    834  1.42    pooka 				park->park_done(pmp, park->park_preq,
    835  1.31    pooka 				    park->park_donearg);
    836  1.46    pooka 				puffs_msgpark_release1(park, 2);
    837  1.31    pooka 			} else if ((park->park_flags & PARKFLAG_WANTREPLY)==0) {
    838  1.46    pooka 				puffs_msgpark_release1(park, 2);
    839  1.31    pooka 			} else {
    840  1.31    pooka 				park->park_preq->preq_rv = ENXIO;
    841  1.31    pooka 				cv_signal(&park->park_cv);
    842  1.46    pooka 				puffs_msgpark_release(park);
    843  1.31    pooka 			}
    844  1.22    pooka 		}
    845  1.22    pooka 	}
    846  1.22    pooka 
    847  1.22    pooka 	/* signal waiters on RESPONSE FROM file server queue */
    848  1.46    pooka 	for (park=TAILQ_FIRST(&pmp->pmp_msg_replywait); park; park=park_next) {
    849  1.46    pooka 		mutex_enter(&park->park_mtx);
    850  1.46    pooka 		puffs_msgpark_reference(park);
    851  1.32    pooka 		park_next = TAILQ_NEXT(park, park_entries);
    852  1.26    pooka 
    853  1.26    pooka 		KASSERT(park->park_flags & PARKFLAG_ONQUEUE2);
    854  1.31    pooka 		KASSERT(park->park_flags & PARKFLAG_WANTREPLY);
    855  1.26    pooka 
    856  1.46    pooka 		TAILQ_REMOVE(&pmp->pmp_msg_replywait, park, park_entries);
    857  1.26    pooka 		park->park_flags &= ~PARKFLAG_ONQUEUE2;
    858  1.26    pooka 
    859  1.31    pooka 		if (park->park_flags & PARKFLAG_WAITERGONE) {
    860  1.31    pooka 			KASSERT((park->park_flags & PARKFLAG_CALL) == 0);
    861  1.46    pooka 			puffs_msgpark_release(park);
    862  1.22    pooka 		} else {
    863  1.31    pooka 			park->park_preq->preq_rv = ENXIO;
    864  1.31    pooka 			if (park->park_flags & PARKFLAG_CALL) {
    865  1.42    pooka 				park->park_done(pmp, park->park_preq,
    866  1.31    pooka 				    park->park_donearg);
    867  1.46    pooka 				puffs_msgpark_release1(park, 2);
    868  1.31    pooka 			} else {
    869  1.31    pooka 				cv_signal(&park->park_cv);
    870  1.46    pooka 				puffs_msgpark_release(park);
    871  1.31    pooka 			}
    872  1.22    pooka 		}
    873  1.22    pooka 	}
    874  1.50    pooka 
    875  1.50    pooka 	cv_broadcast(&pmp->pmp_msg_waiter_cv);
    876  1.22    pooka }
    877