puffs_msgif.c revision 1.40.4.6       1  1.40.4.6     joerg /*	$NetBSD: puffs_msgif.c,v 1.40.4.6 2007/11/11 16:47:50 joerg 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.40.4.6     joerg __KERNEL_RCSID(0, "$NetBSD: puffs_msgif.c,v 1.40.4.6 2007/11/11 16:47:50 joerg Exp $");
     34       1.1     pooka 
     35       1.1     pooka #include <sys/param.h>
     36      1.16     pooka #include <sys/fstrans.h>
     37  1.40.4.3     joerg #include <sys/kmem.h>
     38  1.40.4.6     joerg #include <sys/kthread.h>
     39  1.40.4.6     joerg #include <sys/lock.h>
     40       1.1     pooka #include <sys/malloc.h>
     41       1.1     pooka #include <sys/mount.h>
     42  1.40.4.6     joerg #include <sys/namei.h>
     43      1.39        ad #include <sys/proc.h>
     44  1.40.4.6     joerg #include <sys/vnode.h>
     45  1.40.4.6     joerg 
     46  1.40.4.6     joerg #include <dev/puttervar.h>
     47       1.1     pooka 
     48       1.1     pooka #include <fs/puffs/puffs_msgif.h>
     49       1.1     pooka #include <fs/puffs/puffs_sys.h>
     50       1.1     pooka 
     51  1.40.4.6     joerg #include <miscfs/syncfs/syncfs.h> /* XXX: for syncer_mutex reference */
     52  1.40.4.6     joerg 
     53      1.22     pooka /*
     54      1.22     pooka  * waitq data structures
     55      1.22     pooka  */
     56      1.22     pooka 
     57      1.22     pooka /*
     58      1.22     pooka  * While a request is going to userspace, park the caller within the
     59      1.22     pooka  * kernel.  This is the kernel counterpart of "struct puffs_req".
     60      1.22     pooka  */
     61  1.40.4.3     joerg struct puffs_msgpark {
     62      1.22     pooka 	struct puffs_req	*park_preq;	/* req followed by buf	*/
     63      1.22     pooka 
     64      1.22     pooka 	size_t			park_copylen;	/* userspace copylength	*/
     65      1.22     pooka 	size_t			park_maxlen;	/* max size in comeback */
     66      1.24     pooka 
     67  1.40.4.3     joerg 	parkdone_fn		park_done;	/* "biodone" a'la puffs	*/
     68      1.24     pooka 	void			*park_donearg;
     69      1.22     pooka 
     70      1.22     pooka 	int			park_flags;
     71      1.26     pooka 	int			park_refcount;
     72      1.22     pooka 
     73      1.22     pooka 	kcondvar_t		park_cv;
     74      1.26     pooka 	kmutex_t		park_mtx;
     75      1.26     pooka 
     76  1.40.4.3     joerg 	TAILQ_ENTRY(puffs_msgpark) park_entries;
     77      1.22     pooka };
     78      1.22     pooka #define PARKFLAG_WAITERGONE	0x01
     79      1.26     pooka #define PARKFLAG_DONE		0x02
     80      1.26     pooka #define PARKFLAG_ONQUEUE1	0x04
     81      1.26     pooka #define PARKFLAG_ONQUEUE2	0x08
     82      1.26     pooka #define PARKFLAG_CALL		0x10
     83      1.31     pooka #define PARKFLAG_WANTREPLY	0x20
     84      1.22     pooka 
     85  1.40.4.6     joerg static pool_cache_t parkpc;
     86      1.22     pooka 
     87      1.22     pooka static int
     88      1.22     pooka makepark(void *arg, void *obj, int flags)
     89      1.22     pooka {
     90  1.40.4.3     joerg 	struct puffs_msgpark *park = obj;
     91      1.22     pooka 
     92      1.26     pooka 	mutex_init(&park->park_mtx, MUTEX_DEFAULT, IPL_NONE);
     93      1.22     pooka 	cv_init(&park->park_cv, "puffsrpl");
     94      1.22     pooka 
     95      1.22     pooka 	return 0;
     96      1.22     pooka }
     97      1.22     pooka 
     98      1.22     pooka static void
     99      1.22     pooka nukepark(void *arg, void *obj)
    100      1.22     pooka {
    101  1.40.4.3     joerg 	struct puffs_msgpark *park = obj;
    102      1.22     pooka 
    103      1.22     pooka 	cv_destroy(&park->park_cv);
    104      1.26     pooka 	mutex_destroy(&park->park_mtx);
    105      1.22     pooka }
    106      1.22     pooka 
    107      1.22     pooka void
    108      1.22     pooka puffs_msgif_init()
    109      1.22     pooka {
    110      1.22     pooka 
    111  1.40.4.6     joerg 	parkpc = pool_cache_init(sizeof(struct puffs_msgpark), 0, 0, 0,
    112  1.40.4.6     joerg 	    "puffprkl", NULL, IPL_NONE, makepark, nukepark, NULL);
    113      1.22     pooka }
    114      1.22     pooka 
    115      1.22     pooka void
    116      1.22     pooka puffs_msgif_destroy()
    117      1.22     pooka {
    118      1.22     pooka 
    119  1.40.4.6     joerg 	pool_cache_destroy(parkpc);
    120      1.22     pooka }
    121      1.22     pooka 
    122  1.40.4.3     joerg static int alloced;
    123  1.40.4.3     joerg 
    124  1.40.4.3     joerg static struct puffs_msgpark *
    125  1.40.4.3     joerg puffs_msgpark_alloc(int waitok)
    126      1.26     pooka {
    127  1.40.4.3     joerg 	struct puffs_msgpark *park;
    128      1.26     pooka 
    129  1.40.4.6     joerg 	park = pool_cache_get(parkpc, waitok ? PR_WAITOK : PR_NOWAIT);
    130  1.40.4.3     joerg 	if (park == NULL)
    131  1.40.4.3     joerg 		return park;
    132  1.40.4.3     joerg 
    133  1.40.4.3     joerg 	park->park_refcount = 1;
    134  1.40.4.3     joerg 	park->park_preq = NULL;
    135  1.40.4.3     joerg 	park->park_flags = PARKFLAG_WANTREPLY;
    136      1.26     pooka 
    137      1.26     pooka 	return park;
    138      1.26     pooka }
    139      1.26     pooka 
    140      1.26     pooka static void
    141  1.40.4.3     joerg puffs_msgpark_reference(struct puffs_msgpark *park)
    142      1.22     pooka {
    143      1.22     pooka 
    144  1.40.4.3     joerg 	KASSERT(mutex_owned(&park->park_mtx));
    145      1.26     pooka 	park->park_refcount++;
    146      1.22     pooka }
    147      1.22     pooka 
    148  1.40.4.3     joerg /*
    149  1.40.4.3     joerg  * Release reference to park structure.
    150  1.40.4.3     joerg  */
    151  1.40.4.3     joerg static void
    152  1.40.4.3     joerg puffs_msgpark_release1(struct puffs_msgpark *park, int howmany)
    153      1.22     pooka {
    154  1.40.4.3     joerg 	struct puffs_req *preq = park->park_preq;
    155  1.40.4.3     joerg 	int refcnt;
    156      1.22     pooka 
    157      1.26     pooka 	KASSERT(mutex_owned(&park->park_mtx));
    158  1.40.4.3     joerg 	refcnt = park->park_refcount -= howmany;
    159      1.26     pooka 	mutex_exit(&park->park_mtx);
    160  1.40.4.3     joerg 
    161  1.40.4.3     joerg 	KASSERT(refcnt >= 0);
    162  1.40.4.3     joerg 
    163  1.40.4.3     joerg 	if (refcnt == 0) {
    164  1.40.4.3     joerg 		alloced--;
    165  1.40.4.3     joerg 		if (preq)
    166  1.40.4.3     joerg 			kmem_free(preq, park->park_maxlen);
    167  1.40.4.6     joerg 		pool_cache_put(parkpc, park);
    168  1.40.4.3     joerg 	}
    169      1.22     pooka }
    170  1.40.4.3     joerg #define puffs_msgpark_release(a) puffs_msgpark_release1(a, 1)
    171      1.22     pooka 
    172      1.26     pooka #ifdef PUFFSDEBUG
    173      1.26     pooka static void
    174  1.40.4.3     joerg parkdump(struct puffs_msgpark *park)
    175      1.26     pooka {
    176      1.26     pooka 
    177      1.26     pooka 	DPRINTF(("park %p, preq %p, id %" PRIu64 "\n"
    178      1.26     pooka 	    "\tcopy %zu, max %zu - done: %p/%p\n"
    179      1.26     pooka 	    "\tflags 0x%08x, refcount %d, cv/mtx: %p/%p\n",
    180  1.40.4.3     joerg 	    park, park->park_preq, park->park_preq->preq_id,
    181      1.26     pooka 	    park->park_copylen, park->park_maxlen,
    182      1.26     pooka 	    park->park_done, park->park_donearg,
    183      1.26     pooka 	    park->park_flags, park->park_refcount,
    184      1.26     pooka 	    &park->park_cv, &park->park_mtx));
    185      1.26     pooka }
    186      1.26     pooka 
    187      1.26     pooka static void
    188      1.26     pooka parkqdump(struct puffs_wq *q, int dumpall)
    189      1.26     pooka {
    190  1.40.4.3     joerg 	struct puffs_msgpark *park;
    191      1.26     pooka 	int total = 0;
    192      1.26     pooka 
    193      1.26     pooka 	TAILQ_FOREACH(park, q, park_entries) {
    194      1.26     pooka 		if (dumpall)
    195      1.26     pooka 			parkdump(park);
    196      1.26     pooka 		total++;
    197      1.26     pooka 	}
    198      1.29     pooka 	DPRINTF(("puffs waitqueue at %p dumped, %d total\n", q, total));
    199      1.26     pooka 
    200      1.26     pooka }
    201      1.26     pooka #endif /* PUFFSDEBUG */
    202      1.22     pooka 
    203      1.22     pooka /*
    204  1.40.4.3     joerg  * A word about locking in the park structures: the lock protects the
    205  1.40.4.3     joerg  * fields of the *park* structure (not preq) and acts as an interlock
    206  1.40.4.3     joerg  * in cv operations.  The lock is always internal to this module and
    207  1.40.4.3     joerg  * callers do not need to worry about it.
    208      1.22     pooka  */
    209  1.40.4.3     joerg 
    210  1.40.4.3     joerg int
    211  1.40.4.3     joerg puffs_msgmem_alloc(size_t len, struct puffs_msgpark **ppark, void **mem,
    212  1.40.4.3     joerg 	int cansleep)
    213      1.22     pooka {
    214  1.40.4.3     joerg 	struct puffs_msgpark *park;
    215  1.40.4.3     joerg 	void *m;
    216      1.22     pooka 
    217  1.40.4.3     joerg 	m = kmem_zalloc(len, cansleep ? KM_SLEEP : KM_NOSLEEP);
    218  1.40.4.3     joerg 	if (m == NULL) {
    219  1.40.4.3     joerg 		KASSERT(cansleep == 0);
    220  1.40.4.3     joerg 		return ENOMEM;
    221  1.40.4.3     joerg 	}
    222      1.22     pooka 
    223  1.40.4.3     joerg 	park = puffs_msgpark_alloc(cansleep);
    224  1.40.4.3     joerg 	if (park == NULL) {
    225  1.40.4.3     joerg 		KASSERT(cansleep == 0);
    226  1.40.4.3     joerg 		kmem_free(m, len);
    227  1.40.4.3     joerg 		return ENOMEM;
    228  1.40.4.3     joerg 	}
    229      1.22     pooka 
    230  1.40.4.3     joerg 	park->park_preq = m;
    231  1.40.4.3     joerg 	park->park_maxlen = len;
    232      1.22     pooka 
    233  1.40.4.3     joerg 	*ppark = park;
    234  1.40.4.3     joerg 	*mem = m;
    235  1.40.4.3     joerg 
    236  1.40.4.3     joerg 	return 0;
    237      1.22     pooka }
    238      1.22     pooka 
    239  1.40.4.3     joerg void
    240  1.40.4.3     joerg puffs_msgmem_release(struct puffs_msgpark *park)
    241  1.40.4.3     joerg {
    242  1.40.4.3     joerg 
    243  1.40.4.3     joerg 	if (park == NULL)
    244  1.40.4.3     joerg 		return;
    245  1.40.4.3     joerg 
    246  1.40.4.3     joerg 	mutex_enter(&park->park_mtx);
    247  1.40.4.3     joerg 	puffs_msgpark_release(park);
    248  1.40.4.3     joerg }
    249  1.40.4.3     joerg 
    250  1.40.4.3     joerg void
    251  1.40.4.3     joerg puffs_msg_setfaf(struct puffs_msgpark *park)
    252  1.40.4.3     joerg {
    253  1.40.4.3     joerg 
    254  1.40.4.3     joerg 	park->park_flags &= ~PARKFLAG_WANTREPLY;
    255  1.40.4.3     joerg }
    256       1.1     pooka 
    257       1.1     pooka /*
    258       1.1     pooka  * kernel-user-kernel waitqueues
    259       1.1     pooka  */
    260       1.1     pooka 
    261  1.40.4.3     joerg static int touser(struct puffs_mount *, struct puffs_msgpark *);
    262       1.1     pooka 
    263  1.40.4.3     joerg static uint64_t
    264  1.40.4.3     joerg puffs_getmsgid(struct puffs_mount *pmp)
    265       1.1     pooka {
    266      1.14     pooka 	uint64_t rv;
    267       1.1     pooka 
    268      1.22     pooka 	mutex_enter(&pmp->pmp_lock);
    269  1.40.4.3     joerg 	rv = pmp->pmp_nextmsgid++;
    270      1.22     pooka 	mutex_exit(&pmp->pmp_lock);
    271       1.1     pooka 
    272       1.1     pooka 	return rv;
    273       1.1     pooka }
    274       1.1     pooka 
    275       1.1     pooka /* vfs request */
    276       1.1     pooka int
    277  1.40.4.3     joerg puffs_msg_vfs(struct puffs_mount *pmp, struct puffs_msgpark *park, int optype)
    278       1.1     pooka {
    279       1.1     pooka 
    280      1.25     pooka 	park->park_preq->preq_opclass = PUFFSOP_VFS;
    281      1.25     pooka 	park->park_preq->preq_optype = optype;
    282       1.1     pooka 
    283  1.40.4.3     joerg 	park->park_copylen = park->park_maxlen;
    284       1.1     pooka 
    285  1.40.4.3     joerg 	return touser(pmp, park);
    286      1.16     pooka }
    287      1.16     pooka 
    288       1.1     pooka /*
    289       1.1     pooka  * vnode level request
    290       1.1     pooka  */
    291       1.1     pooka int
    292  1.40.4.3     joerg puffs_msg_vn(struct puffs_mount *pmp, struct puffs_msgpark *park,
    293  1.40.4.3     joerg 	int optype, size_t delta, struct vnode *vp_opc, struct vnode *vp_aux)
    294       1.1     pooka {
    295      1.35     pooka 	struct puffs_req *preq;
    296      1.35     pooka 	void *cookie = VPTOPNC(vp_opc);
    297      1.35     pooka 	struct puffs_node *pnode;
    298      1.35     pooka 	int rv;
    299       1.1     pooka 
    300      1.25     pooka 	park->park_preq->preq_opclass = PUFFSOP_VN;
    301      1.25     pooka 	park->park_preq->preq_optype = optype;
    302      1.25     pooka 	park->park_preq->preq_cookie = cookie;
    303      1.25     pooka 
    304  1.40.4.3     joerg 	KASSERT(delta < park->park_maxlen); /* "<=" wouldn't make sense */
    305  1.40.4.3     joerg 	park->park_copylen = park->park_maxlen - delta;
    306       1.1     pooka 
    307  1.40.4.3     joerg 	rv = touser(pmp, park);
    308      1.35     pooka 
    309      1.35     pooka 	/*
    310      1.35     pooka 	 * Check if the user server requests that inactive be called
    311      1.35     pooka 	 * when the time is right.
    312      1.35     pooka 	 */
    313      1.35     pooka 	preq = park->park_preq;
    314      1.35     pooka 	if (preq->preq_setbacks & PUFFS_SETBACK_INACT_N1) {
    315      1.35     pooka 		pnode = vp_opc->v_data;
    316      1.35     pooka 		pnode->pn_stat |= PNODE_DOINACT;
    317      1.35     pooka 	}
    318      1.35     pooka 	if (preq->preq_setbacks & PUFFS_SETBACK_INACT_N2) {
    319      1.35     pooka 		/* if no vp_aux, just ignore */
    320      1.35     pooka 		if (vp_aux) {
    321      1.35     pooka 			pnode = vp_aux->v_data;
    322      1.35     pooka 			pnode->pn_stat |= PNODE_DOINACT;
    323      1.35     pooka 		}
    324      1.35     pooka 	}
    325      1.37     pooka 	if (preq->preq_setbacks & PUFFS_SETBACK_NOREF_N1) {
    326      1.37     pooka 		pnode = vp_opc->v_data;
    327      1.37     pooka 		pnode->pn_stat |= PNODE_NOREFS;
    328      1.37     pooka 	}
    329      1.37     pooka 	if (preq->preq_setbacks & PUFFS_SETBACK_NOREF_N2) {
    330      1.37     pooka 		/* if no vp_aux, just ignore */
    331      1.37     pooka 		if (vp_aux) {
    332      1.37     pooka 			pnode = vp_aux->v_data;
    333      1.37     pooka 			pnode->pn_stat |= PNODE_NOREFS;
    334      1.37     pooka 		}
    335      1.37     pooka 	}
    336      1.35     pooka 
    337      1.35     pooka 	return rv;
    338       1.1     pooka }
    339       1.1     pooka 
    340      1.24     pooka void
    341  1.40.4.3     joerg puffs_msg_vncall(struct puffs_mount *pmp, struct puffs_msgpark *park,
    342  1.40.4.3     joerg 	int optype, size_t delta, parkdone_fn donefn, void *donearg,
    343  1.40.4.3     joerg 	struct vnode *vp_opc)
    344       1.1     pooka {
    345      1.35     pooka 	void *cookie = VPTOPNC(vp_opc);
    346       1.1     pooka 
    347      1.25     pooka 	park->park_preq->preq_opclass = PUFFSOP_VN;
    348      1.25     pooka 	park->park_preq->preq_optype = optype;
    349      1.25     pooka 	park->park_preq->preq_cookie = cookie;
    350      1.25     pooka 
    351  1.40.4.3     joerg 	KASSERT(delta < park->park_maxlen);
    352  1.40.4.3     joerg 	park->park_copylen = park->park_maxlen - delta;
    353      1.25     pooka 	park->park_done = donefn;
    354      1.25     pooka 	park->park_donearg = donearg;
    355  1.40.4.3     joerg 	park->park_flags |= PARKFLAG_CALL;
    356       1.4     pooka 
    357  1.40.4.3     joerg 	(void) touser(pmp, park);
    358       1.4     pooka }
    359       1.4     pooka 
    360  1.40.4.3     joerg int
    361  1.40.4.3     joerg puffs_msg_raw(struct puffs_mount *pmp, struct puffs_msgpark *park)
    362      1.21     pooka {
    363      1.21     pooka 
    364  1.40.4.3     joerg 	park->park_copylen = park->park_maxlen;
    365      1.21     pooka 
    366  1.40.4.3     joerg 	return touser(pmp, park);
    367      1.21     pooka }
    368      1.21     pooka 
    369  1.40.4.1     joerg void
    370  1.40.4.3     joerg puffs_msg_errnotify(struct puffs_mount *pmp, uint8_t type, int error,
    371  1.40.4.1     joerg 	const char *str, void *cookie)
    372  1.40.4.1     joerg {
    373  1.40.4.3     joerg 	struct puffs_msgpark *park;
    374  1.40.4.1     joerg 	struct puffs_error *perr;
    375  1.40.4.1     joerg 
    376  1.40.4.3     joerg 	puffs_msgmem_alloc(sizeof(struct puffs_error), &park, (void **)&perr,1);
    377  1.40.4.1     joerg 
    378  1.40.4.1     joerg 	perr->perr_error = error;
    379  1.40.4.1     joerg 	strlcpy(perr->perr_str, str, sizeof(perr->perr_str));
    380  1.40.4.1     joerg 
    381  1.40.4.3     joerg 	park->park_preq->preq_opclass |= PUFFSOP_ERROR | PUFFSOPFLAG_FAF;
    382  1.40.4.1     joerg 	park->park_preq->preq_optype = type;
    383  1.40.4.1     joerg 	park->park_preq->preq_cookie = cookie;
    384  1.40.4.1     joerg 
    385  1.40.4.3     joerg 	park->park_copylen = park->park_maxlen;
    386  1.40.4.1     joerg 
    387  1.40.4.3     joerg 	(void)touser(pmp, park);
    388  1.40.4.1     joerg }
    389  1.40.4.1     joerg 
    390       1.4     pooka /*
    391  1.40.4.5  jmcneill  * Wait for the userspace ping-pong game in calling process context,
    392  1.40.4.5  jmcneill  * unless a FAF / async call, in which case just enqueues the request
    393  1.40.4.5  jmcneill  * and return immediately.
    394       1.1     pooka  */
    395       1.1     pooka static int
    396  1.40.4.3     joerg touser(struct puffs_mount *pmp, struct puffs_msgpark *park)
    397       1.1     pooka {
    398      1.26     pooka 	struct lwp *l = curlwp;
    399      1.16     pooka 	struct mount *mp;
    400       1.9     pooka 	struct puffs_req *preq;
    401      1.19     pooka 	int rv = 0;
    402       1.1     pooka 
    403      1.16     pooka 	mp = PMPTOMP(pmp);
    404      1.25     pooka 	preq = park->park_preq;
    405  1.40.4.3     joerg 	preq->preq_buflen = park->park_maxlen;
    406  1.40.4.3     joerg 	KASSERT(preq->preq_id == 0);
    407      1.19     pooka 
    408  1.40.4.3     joerg 	if ((park->park_flags & PARKFLAG_WANTREPLY) == 0)
    409  1.40.4.3     joerg 		preq->preq_opclass |= PUFFSOPFLAG_FAF;
    410  1.40.4.3     joerg 	else
    411  1.40.4.3     joerg 		preq->preq_id = puffs_getmsgid(pmp);
    412  1.40.4.3     joerg 
    413  1.40.4.3     joerg 	/* fill in caller information */
    414  1.40.4.3     joerg 	preq->preq_pid = l->l_proc->p_pid;
    415  1.40.4.3     joerg 	preq->preq_lid = l->l_lid;
    416      1.31     pooka 
    417      1.19     pooka 	/*
    418  1.40.4.5  jmcneill 	 * To support cv_sig, yet another movie: check if there are signals
    419      1.19     pooka 	 * pending and we are issueing a non-FAF.  If so, return an error
    420      1.19     pooka 	 * directly UNLESS we are issueing INACTIVE.  In that case, convert
    421      1.19     pooka 	 * it to a FAF, fire off to the file server and return an error.
    422      1.19     pooka 	 * Yes, this is bordering disgusting.  Barfbags are on me.
    423      1.19     pooka 	 */
    424      1.31     pooka 	if ((park->park_flags & PARKFLAG_WANTREPLY)
    425      1.25     pooka 	   && (park->park_flags & PARKFLAG_CALL) == 0
    426      1.19     pooka 	   && (l->l_flag & LW_PENDSIG) != 0 && sigispending(l, 0)) {
    427      1.19     pooka 		if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN
    428      1.19     pooka 		    && preq->preq_optype == PUFFS_VN_INACTIVE) {
    429  1.40.4.3     joerg 			park->park_preq->preq_opclass |= PUFFSOPFLAG_FAF;
    430  1.40.4.3     joerg 			park->park_flags &= ~PARKFLAG_WANTREPLY;
    431      1.25     pooka 			DPRINTF(("puffs touser: converted to FAF %p\n", park));
    432      1.19     pooka 			rv = EINTR;
    433      1.19     pooka 		} else {
    434      1.19     pooka 			return EINTR;
    435      1.19     pooka 		}
    436      1.19     pooka 	}
    437      1.16     pooka 
    438      1.16     pooka 	/*
    439      1.16     pooka 	 * test for suspension lock.
    440      1.16     pooka 	 *
    441      1.16     pooka 	 * Note that we *DO NOT* keep the lock, since that might block
    442      1.16     pooka 	 * lock acquiring PLUS it would give userlandia control over
    443      1.16     pooka 	 * the lock.  The operation queue enforces a strict ordering:
    444      1.16     pooka 	 * when the fs server gets in the op stream, it knows things
    445      1.16     pooka 	 * are in order.  The kernel locks can't guarantee that for
    446      1.16     pooka 	 * userspace, in any case.
    447      1.16     pooka 	 *
    448      1.16     pooka 	 * BUT: this presents a problem for ops which have a consistency
    449      1.16     pooka 	 * clause based on more than one operation.  Unfortunately such
    450      1.16     pooka 	 * operations (read, write) do not reliably work yet.
    451      1.16     pooka 	 *
    452      1.16     pooka 	 * Ya, Ya, it's wrong wong wrong, me be fixink this someday.
    453      1.18     pooka 	 *
    454      1.18     pooka 	 * XXX: and there is one more problem.  We sometimes need to
    455      1.18     pooka 	 * take a lazy lock in case the fs is suspending and we are
    456      1.18     pooka 	 * executing as the fs server context.  This might happen
    457      1.18     pooka 	 * e.g. in the case that the user server triggers a reclaim
    458      1.18     pooka 	 * in the kernel while the fs is suspending.  It's not a very
    459      1.18     pooka 	 * likely event, but it needs to be fixed some day.
    460      1.16     pooka 	 */
    461      1.22     pooka 
    462      1.22     pooka 	/*
    463      1.22     pooka 	 * MOREXXX: once PUFFS_WCACHEINFO is enabled, we can't take
    464      1.22     pooka 	 * the mutex here, since getpages() might be called locked.
    465      1.22     pooka 	 */
    466      1.18     pooka 	fstrans_start(mp, FSTRANS_NORMAL);
    467      1.22     pooka 	mutex_enter(&pmp->pmp_lock);
    468      1.16     pooka 	fstrans_done(mp);
    469      1.16     pooka 
    470      1.13     pooka 	if (pmp->pmp_status != PUFFSTAT_RUNNING) {
    471      1.22     pooka 		mutex_exit(&pmp->pmp_lock);
    472       1.1     pooka 		return ENXIO;
    473       1.1     pooka 	}
    474       1.1     pooka 
    475      1.26     pooka #ifdef PUFFSDEBUG
    476  1.40.4.3     joerg 	parkqdump(&pmp->pmp_msg_touser, puffsdebug > 1);
    477  1.40.4.3     joerg 	parkqdump(&pmp->pmp_msg_replywait, puffsdebug > 1);
    478      1.26     pooka #endif
    479      1.26     pooka 
    480  1.40.4.3     joerg 	mutex_enter(&park->park_mtx);
    481  1.40.4.3     joerg 	TAILQ_INSERT_TAIL(&pmp->pmp_msg_touser, park, park_entries);
    482      1.26     pooka 	park->park_flags |= PARKFLAG_ONQUEUE1;
    483      1.34     pooka 	puffs_mp_reference(pmp);
    484  1.40.4.3     joerg 	pmp->pmp_msg_touser_count++;
    485      1.26     pooka 	mutex_exit(&pmp->pmp_lock);
    486       1.1     pooka 
    487      1.20     pooka 	DPRINTF(("touser: req %" PRIu64 ", preq: %p, park: %p, "
    488      1.25     pooka 	    "c/t: 0x%x/0x%x, f: 0x%x\n", preq->preq_id, preq, park,
    489      1.25     pooka 	    preq->preq_opclass, preq->preq_optype, park->park_flags));
    490      1.15     pooka 
    491  1.40.4.3     joerg 	cv_broadcast(&pmp->pmp_msg_waiter_cv);
    492  1.40.4.6     joerg 	putter_notify(pmp->pmp_pi);
    493       1.1     pooka 
    494      1.31     pooka 	if ((park->park_flags & PARKFLAG_WANTREPLY)
    495      1.25     pooka 	    && (park->park_flags & PARKFLAG_CALL) == 0) {
    496      1.19     pooka 		int error;
    497      1.19     pooka 
    498      1.26     pooka 		error = cv_wait_sig(&park->park_cv, &park->park_mtx);
    499  1.40.4.3     joerg 		DPRINTF(("puffs_touser: waiter for %p woke up with %d\n",
    500  1.40.4.3     joerg 		    park, error));
    501      1.19     pooka 		if (error) {
    502      1.25     pooka 			park->park_flags |= PARKFLAG_WAITERGONE;
    503      1.26     pooka 			if (park->park_flags & PARKFLAG_DONE) {
    504      1.22     pooka 				rv = preq->preq_rv;
    505      1.19     pooka 			} else {
    506      1.26     pooka 				/*
    507      1.26     pooka 				 * ok, we marked it as going away, but
    508      1.26     pooka 				 * still need to do queue ops.  take locks
    509      1.26     pooka 				 * in correct order.
    510      1.26     pooka 				 *
    511      1.26     pooka 				 * We don't want to release our reference
    512      1.26     pooka 				 * if it's on replywait queue to avoid error
    513      1.26     pooka 				 * to file server.  putop() code will DTRT.
    514      1.26     pooka 				 */
    515      1.26     pooka 				mutex_exit(&park->park_mtx);
    516      1.26     pooka 				mutex_enter(&pmp->pmp_lock);
    517      1.26     pooka 				mutex_enter(&park->park_mtx);
    518  1.40.4.3     joerg 
    519  1.40.4.3     joerg 				/* remove from queue1 */
    520      1.36     pooka 				if (park->park_flags & PARKFLAG_ONQUEUE1) {
    521  1.40.4.3     joerg 					TAILQ_REMOVE(&pmp->pmp_msg_touser,
    522      1.26     pooka 					    park, park_entries);
    523  1.40.4.3     joerg 					pmp->pmp_msg_touser_count--;
    524      1.36     pooka 					park->park_flags &= ~PARKFLAG_ONQUEUE1;
    525      1.36     pooka 				}
    526  1.40.4.3     joerg 
    527  1.40.4.3     joerg 				/*
    528  1.40.4.3     joerg 				 * If it's waiting for a response already,
    529  1.40.4.3     joerg 				 * boost reference count.  Park will get
    530  1.40.4.3     joerg 				 * nuked once the response arrives from
    531  1.40.4.3     joerg 				 * the file server.
    532  1.40.4.3     joerg 				 */
    533  1.40.4.3     joerg 				if (park->park_flags & PARKFLAG_ONQUEUE2)
    534  1.40.4.3     joerg 					puffs_msgpark_reference(park);
    535  1.40.4.3     joerg 
    536      1.26     pooka 				mutex_exit(&pmp->pmp_lock);
    537      1.26     pooka 
    538      1.22     pooka 				rv = error;
    539      1.19     pooka 			}
    540      1.22     pooka 		} else {
    541      1.22     pooka 			rv = preq->preq_rv;
    542      1.19     pooka 		}
    543      1.22     pooka 
    544      1.16     pooka 		/*
    545      1.16     pooka 		 * retake the lock and release.  This makes sure (haha,
    546      1.16     pooka 		 * I'm humorous) that we don't process the same vnode in
    547      1.16     pooka 		 * multiple threads due to the locks hacks we have in
    548      1.16     pooka 		 * puffs_lock().  In reality this is well protected by
    549      1.16     pooka 		 * the biglock, but once that's gone, well, hopefully
    550      1.16     pooka 		 * this will be fixed for real.  (and when you read this
    551      1.16     pooka 		 * comment in 2017 and subsequently barf, my condolences ;).
    552      1.16     pooka 		 */
    553      1.19     pooka 		if (rv == 0 && !fstrans_is_owner(mp)) {
    554      1.17   hannken 			fstrans_start(mp, FSTRANS_NORMAL);
    555      1.16     pooka 			fstrans_done(mp);
    556      1.16     pooka 		}
    557  1.40.4.5  jmcneill 
    558      1.22     pooka 	} else {
    559  1.40.4.3     joerg 		/*
    560  1.40.4.3     joerg 		 * Take extra reference for FAF, i.e. don't free us
    561  1.40.4.3     joerg 		 * immediately upon return to the caller, but rather
    562  1.40.4.3     joerg 		 * only when the message has been transported.
    563  1.40.4.3     joerg 		 */
    564  1.40.4.3     joerg 		puffs_msgpark_reference(park);
    565      1.16     pooka 	}
    566      1.16     pooka 
    567  1.40.4.3     joerg 	mutex_exit(&park->park_mtx);
    568  1.40.4.3     joerg 
    569      1.22     pooka 	mutex_enter(&pmp->pmp_lock);
    570      1.34     pooka 	puffs_mp_release(pmp);
    571      1.22     pooka 	mutex_exit(&pmp->pmp_lock);
    572      1.16     pooka 
    573      1.19     pooka 	return rv;
    574       1.1     pooka }
    575       1.1     pooka 
    576       1.9     pooka /*
    577  1.40.4.3     joerg  * Get next request in the outgoing queue.  "maxsize" controls the
    578  1.40.4.3     joerg  * size the caller can accommodate and "nonblock" signals if this
    579  1.40.4.3     joerg  * should block while waiting for input.  Handles all locking internally.
    580       1.9     pooka  */
    581      1.10     pooka int
    582  1.40.4.3     joerg puffs_msgif_getout(void *this, size_t maxsize, int nonblock,
    583  1.40.4.3     joerg 	uint8_t **data, size_t *dlen, void **parkptr)
    584       1.1     pooka {
    585  1.40.4.3     joerg 	struct puffs_mount *pmp = this;
    586  1.40.4.3     joerg 	struct puffs_msgpark *park;
    587       1.9     pooka 	struct puffs_req *preq;
    588  1.40.4.3     joerg 	int error;
    589       1.1     pooka 
    590  1.40.4.3     joerg 	error = 0;
    591      1.22     pooka 	mutex_enter(&pmp->pmp_lock);
    592  1.40.4.4     joerg 	puffs_mp_reference(pmp);
    593  1.40.4.3     joerg 	for (;;) {
    594  1.40.4.3     joerg 		/* RIP? */
    595       1.9     pooka 		if (pmp->pmp_status != PUFFSTAT_RUNNING) {
    596       1.9     pooka 			error = ENXIO;
    597  1.40.4.3     joerg 			break;
    598       1.9     pooka 		}
    599      1.12     pooka 
    600  1.40.4.3     joerg 		/* need platinum yendorian express card? */
    601  1.40.4.3     joerg 		if (TAILQ_EMPTY(&pmp->pmp_msg_touser)) {
    602  1.40.4.3     joerg 			DPRINTF(("puffs_getout: no outgoing op, "));
    603      1.12     pooka 			if (nonblock) {
    604  1.40.4.3     joerg 				DPRINTF(("returning EWOULDBLOCK\n"));
    605      1.12     pooka 				error = EWOULDBLOCK;
    606  1.40.4.3     joerg 				break;
    607       1.9     pooka 			}
    608  1.40.4.3     joerg 			DPRINTF(("waiting ...\n"));
    609       1.9     pooka 
    610  1.40.4.3     joerg 			error = cv_wait_sig(&pmp->pmp_msg_waiter_cv,
    611      1.22     pooka 			    &pmp->pmp_lock);
    612      1.11     pooka 			if (error)
    613  1.40.4.3     joerg 				break;
    614      1.11     pooka 			else
    615  1.40.4.3     joerg 				continue;
    616       1.9     pooka 		}
    617       1.9     pooka 
    618  1.40.4.3     joerg 		park = TAILQ_FIRST(&pmp->pmp_msg_touser);
    619  1.40.4.4     joerg 		if (park == NULL)
    620  1.40.4.4     joerg 			continue;
    621  1.40.4.4     joerg 
    622  1.40.4.3     joerg 		mutex_enter(&park->park_mtx);
    623  1.40.4.3     joerg 		puffs_msgpark_reference(park);
    624  1.40.4.3     joerg 
    625  1.40.4.3     joerg 		DPRINTF(("puffs_getout: found park at %p, ", park));
    626      1.22     pooka 
    627      1.22     pooka 		/* If it's a goner, don't process any furher */
    628      1.22     pooka 		if (park->park_flags & PARKFLAG_WAITERGONE) {
    629  1.40.4.3     joerg 			DPRINTF(("waitergone!\n"));
    630  1.40.4.3     joerg 			puffs_msgpark_release(park);
    631      1.22     pooka 			continue;
    632      1.22     pooka 		}
    633      1.22     pooka 
    634  1.40.4.3     joerg 		/* check size */
    635      1.26     pooka 		preq = park->park_preq;
    636  1.40.4.3     joerg 		if (maxsize < preq->preq_frhdr.pfr_len) {
    637  1.40.4.3     joerg 			DPRINTF(("buffer too small\n"));
    638  1.40.4.3     joerg 			puffs_msgpark_release(park);
    639  1.40.4.3     joerg 			error = E2BIG;
    640  1.40.4.3     joerg 			break;
    641      1.26     pooka 		}
    642      1.28     pooka 
    643  1.40.4.3     joerg 		DPRINTF(("returning\n"));
    644  1.40.4.3     joerg 
    645  1.40.4.3     joerg 		/*
    646  1.40.4.3     joerg 		 * Ok, we found what we came for.  Release it from the
    647  1.40.4.3     joerg 		 * outgoing queue but do not unlock.  We will unlock
    648  1.40.4.3     joerg 		 * only after we "releaseout" it to avoid complications:
    649  1.40.4.3     joerg 		 * otherwise it is (theoretically) possible for userland
    650  1.40.4.3     joerg 		 * to race us into "put" before we have a change to put
    651  1.40.4.3     joerg 		 * this baby on the receiving queue.
    652  1.40.4.3     joerg 		 */
    653  1.40.4.3     joerg 		TAILQ_REMOVE(&pmp->pmp_msg_touser, park, park_entries);
    654      1.28     pooka 		KASSERT(park->park_flags & PARKFLAG_ONQUEUE1);
    655      1.28     pooka 		park->park_flags &= ~PARKFLAG_ONQUEUE1;
    656  1.40.4.3     joerg 		mutex_exit(&park->park_mtx);
    657      1.26     pooka 
    658  1.40.4.3     joerg 		pmp->pmp_msg_touser_count--;
    659  1.40.4.3     joerg 		KASSERT(pmp->pmp_msg_touser_count >= 0);
    660       1.9     pooka 
    661  1.40.4.3     joerg 		break;
    662  1.40.4.3     joerg 	}
    663  1.40.4.4     joerg 	puffs_mp_release(pmp);
    664  1.40.4.3     joerg 	mutex_exit(&pmp->pmp_lock);
    665       1.9     pooka 
    666  1.40.4.3     joerg 	if (error == 0) {
    667  1.40.4.3     joerg 		*data = (uint8_t *)preq;
    668  1.40.4.3     joerg 		preq->preq_frhdr.pfr_len = park->park_copylen;
    669  1.40.4.3     joerg 		preq->preq_frhdr.pfr_alloclen = park->park_maxlen;
    670  1.40.4.3     joerg 		preq->preq_frhdr.pfr_type = preq->preq_opclass; /* yay! */
    671  1.40.4.3     joerg 		*dlen = preq->preq_frhdr.pfr_len;
    672  1.40.4.3     joerg 		*parkptr = park;
    673  1.40.4.3     joerg 	}
    674  1.40.4.5  jmcneill 
    675  1.40.4.3     joerg 	return error;
    676  1.40.4.3     joerg }
    677  1.40.4.3     joerg 
    678  1.40.4.3     joerg /*
    679  1.40.4.3     joerg  * Release outgoing structure.  Now, depending on the success of the
    680  1.40.4.3     joerg  * outgoing send, it is either going onto the result waiting queue
    681  1.40.4.3     joerg  * or the death chamber.
    682  1.40.4.3     joerg  */
    683  1.40.4.3     joerg void
    684  1.40.4.3     joerg puffs_msgif_releaseout(void *this, void *parkptr, int status)
    685  1.40.4.3     joerg {
    686  1.40.4.3     joerg 	struct puffs_mount *pmp = this;
    687  1.40.4.3     joerg 	struct puffs_msgpark *park = parkptr;
    688      1.32     pooka 
    689  1.40.4.3     joerg 	DPRINTF(("puffs_releaseout: returning park %p, errno %d: " ,
    690  1.40.4.3     joerg 	    park, status));
    691  1.40.4.3     joerg 	mutex_enter(&pmp->pmp_lock);
    692  1.40.4.3     joerg 	mutex_enter(&park->park_mtx);
    693  1.40.4.3     joerg 	if (park->park_flags & PARKFLAG_WANTREPLY) {
    694  1.40.4.3     joerg 		if (status == 0) {
    695  1.40.4.3     joerg 			DPRINTF(("enqueue replywait\n"));
    696  1.40.4.3     joerg 			TAILQ_INSERT_TAIL(&pmp->pmp_msg_replywait, park,
    697      1.22     pooka 			    park_entries);
    698      1.26     pooka 			park->park_flags |= PARKFLAG_ONQUEUE2;
    699       1.9     pooka 		} else {
    700  1.40.4.3     joerg 			DPRINTF(("error path!\n"));
    701  1.40.4.3     joerg 			park->park_preq->preq_rv = status;
    702  1.40.4.3     joerg 			park->park_flags |= PARKFLAG_DONE;
    703  1.40.4.3     joerg 			cv_signal(&park->park_cv);
    704       1.1     pooka 		}
    705  1.40.4.3     joerg 		puffs_msgpark_release(park);
    706  1.40.4.3     joerg 	} else {
    707  1.40.4.3     joerg 		DPRINTF(("release\n"));
    708  1.40.4.3     joerg 		puffs_msgpark_release1(park, 2);
    709       1.1     pooka 	}
    710      1.22     pooka 	mutex_exit(&pmp->pmp_lock);
    711       1.1     pooka }
    712       1.1     pooka 
    713  1.40.4.6     joerg size_t
    714  1.40.4.6     joerg puffs_msgif_waitcount(void *this)
    715  1.40.4.6     joerg {
    716  1.40.4.6     joerg 	struct puffs_mount *pmp = this;
    717  1.40.4.6     joerg 	size_t rv;
    718  1.40.4.6     joerg 
    719  1.40.4.6     joerg 	mutex_enter(&pmp->pmp_lock);
    720  1.40.4.6     joerg 	rv = pmp->pmp_msg_touser_count;
    721  1.40.4.6     joerg 	mutex_exit(&pmp->pmp_lock);
    722  1.40.4.6     joerg 
    723  1.40.4.6     joerg 	return rv;
    724  1.40.4.6     joerg }
    725  1.40.4.6     joerg 
    726  1.40.4.4     joerg /*
    727  1.40.4.4     joerg  * XXX: locking with this one?
    728  1.40.4.4     joerg  */
    729  1.40.4.6     joerg static void
    730  1.40.4.3     joerg puffs_msgif_incoming(void *this, void *buf)
    731       1.1     pooka {
    732  1.40.4.3     joerg 	struct puffs_mount *pmp = this;
    733  1.40.4.3     joerg 	struct puffs_req *preq = buf;
    734  1.40.4.3     joerg 	struct puffs_frame *pfr = &preq->preq_frhdr;
    735  1.40.4.3     joerg 	struct puffs_msgpark *park;
    736  1.40.4.3     joerg 	int release, wgone;
    737  1.40.4.3     joerg 
    738  1.40.4.3     joerg 	/* XXX */
    739  1.40.4.3     joerg 	if (PUFFSOP_OPCLASS(preq->preq_opclass) != PUFFSOP_VN
    740  1.40.4.3     joerg 	    && PUFFSOP_OPCLASS(preq->preq_opclass) != PUFFSOP_VFS)
    741  1.40.4.3     joerg 		return;
    742       1.1     pooka 
    743      1.22     pooka 	mutex_enter(&pmp->pmp_lock);
    744      1.24     pooka 
    745  1.40.4.3     joerg 	/* Locate waiter */
    746  1.40.4.3     joerg 	TAILQ_FOREACH(park, &pmp->pmp_msg_replywait, park_entries) {
    747  1.40.4.3     joerg 		if (park->park_preq->preq_id == preq->preq_id)
    748      1.24     pooka 			break;
    749  1.40.4.3     joerg 	}
    750  1.40.4.3     joerg 	if (park == NULL) {
    751  1.40.4.3     joerg 		DPRINTF(("puffs_msgif_income: no request: %" PRIu64 "\n",
    752  1.40.4.3     joerg 		    preq->preq_id));
    753  1.40.4.3     joerg 		mutex_exit(&pmp->pmp_lock);
    754  1.40.4.3     joerg 		return; /* XXX send error */
    755  1.40.4.3     joerg 	}
    756      1.26     pooka 
    757  1.40.4.3     joerg 	mutex_enter(&park->park_mtx);
    758  1.40.4.3     joerg 	puffs_msgpark_reference(park);
    759  1.40.4.3     joerg 	if (pfr->pfr_len > park->park_maxlen) {
    760  1.40.4.3     joerg 		DPRINTF(("puffs_msgif_income: invalid buffer length: "
    761  1.40.4.3     joerg 		    "%zu (req %" PRIu64 ", \n", pfr->pfr_len, preq->preq_id));
    762  1.40.4.3     joerg 		park->park_preq->preq_rv = EPROTO;
    763  1.40.4.3     joerg 		cv_signal(&park->park_cv);
    764  1.40.4.3     joerg 		puffs_msgpark_release(park);
    765      1.22     pooka 		mutex_exit(&pmp->pmp_lock);
    766  1.40.4.3     joerg 		return; /* XXX: error */
    767  1.40.4.3     joerg 	}
    768  1.40.4.3     joerg 	wgone = park->park_flags & PARKFLAG_WAITERGONE;
    769       1.9     pooka 
    770  1.40.4.3     joerg 	KASSERT(park->park_flags & PARKFLAG_ONQUEUE2);
    771  1.40.4.3     joerg 	TAILQ_REMOVE(&pmp->pmp_msg_replywait, park, park_entries);
    772  1.40.4.3     joerg 	park->park_flags &= ~PARKFLAG_ONQUEUE2;
    773  1.40.4.3     joerg 	mutex_exit(&pmp->pmp_lock);
    774      1.24     pooka 
    775  1.40.4.3     joerg 	if (wgone) {
    776  1.40.4.3     joerg 		DPRINTF(("puffs_putop: bad service - waiter gone for "
    777  1.40.4.3     joerg 		    "park %p\n", park));
    778  1.40.4.3     joerg 		release = 2;
    779  1.40.4.3     joerg 	} else {
    780      1.24     pooka 		if (park->park_flags & PARKFLAG_CALL) {
    781  1.40.4.3     joerg 			DPRINTF(("puffs_msgif_income: call for %p, arg %p\n",
    782      1.40     pooka 			    park->park_preq, park->park_donearg));
    783  1.40.4.3     joerg 			park->park_done(pmp, buf, park->park_donearg);
    784  1.40.4.3     joerg 			release = 2;
    785  1.40.4.3     joerg 		} else {
    786  1.40.4.3     joerg 			/* XXX: yes, I know */
    787  1.40.4.3     joerg 			memcpy(park->park_preq, buf, pfr->pfr_len);
    788      1.26     pooka 			release = 1;
    789      1.20     pooka 		}
    790       1.1     pooka 	}
    791       1.1     pooka 
    792  1.40.4.3     joerg 	if (!wgone) {
    793  1.40.4.3     joerg 		DPRINTF(("puffs_putop: flagging done for "
    794  1.40.4.3     joerg 		    "park %p\n", park));
    795  1.40.4.3     joerg 		cv_signal(&park->park_cv);
    796  1.40.4.3     joerg 	}
    797       1.1     pooka 
    798  1.40.4.3     joerg 	park->park_flags |= PARKFLAG_DONE;
    799  1.40.4.3     joerg 	puffs_msgpark_release1(park, release);
    800       1.1     pooka }
    801       1.1     pooka 
    802      1.22     pooka /*
    803  1.40.4.6     joerg  * helpers
    804  1.40.4.6     joerg  */
    805  1.40.4.6     joerg static void
    806  1.40.4.6     joerg dosuspendresume(void *arg)
    807  1.40.4.6     joerg {
    808  1.40.4.6     joerg 	struct puffs_mount *pmp = arg;
    809  1.40.4.6     joerg 	struct mount *mp;
    810  1.40.4.6     joerg 	int rv;
    811  1.40.4.6     joerg 
    812  1.40.4.6     joerg 	mp = PMPTOMP(pmp);
    813  1.40.4.6     joerg 	/*
    814  1.40.4.6     joerg 	 * XXX?  does this really do any good or is it just
    815  1.40.4.6     joerg 	 * paranoid stupidity?  or stupid paranoia?
    816  1.40.4.6     joerg 	 */
    817  1.40.4.6     joerg 	if (mp->mnt_iflag & IMNT_UNMOUNT) {
    818  1.40.4.6     joerg 		printf("puffs dosuspendresume(): detected suspend on "
    819  1.40.4.6     joerg 		    "unmounting fs\n");
    820  1.40.4.6     joerg 		goto out;
    821  1.40.4.6     joerg 	}
    822  1.40.4.6     joerg 
    823  1.40.4.6     joerg 	/* Do the dance.  Allow only one concurrent suspend */
    824  1.40.4.6     joerg 	rv = vfs_suspend(PMPTOMP(pmp), 1);
    825  1.40.4.6     joerg 	if (rv == 0)
    826  1.40.4.6     joerg 		vfs_resume(PMPTOMP(pmp));
    827  1.40.4.6     joerg 
    828  1.40.4.6     joerg  out:
    829  1.40.4.6     joerg 	mutex_enter(&pmp->pmp_lock);
    830  1.40.4.6     joerg 	KASSERT(pmp->pmp_suspend == 1);
    831  1.40.4.6     joerg 	pmp->pmp_suspend = 0;
    832  1.40.4.6     joerg 	puffs_mp_release(pmp);
    833  1.40.4.6     joerg 	mutex_exit(&pmp->pmp_lock);
    834  1.40.4.6     joerg 
    835  1.40.4.6     joerg 	kthread_exit(0);
    836  1.40.4.6     joerg }
    837  1.40.4.6     joerg 
    838  1.40.4.6     joerg static void
    839  1.40.4.6     joerg puffsop_suspend(struct puffs_mount *pmp)
    840  1.40.4.6     joerg {
    841  1.40.4.6     joerg 	int rv = 0;
    842  1.40.4.6     joerg 
    843  1.40.4.6     joerg 	mutex_enter(&pmp->pmp_lock);
    844  1.40.4.6     joerg 	if (pmp->pmp_suspend || pmp->pmp_status != PUFFSTAT_RUNNING) {
    845  1.40.4.6     joerg 		rv = EBUSY;
    846  1.40.4.6     joerg 	} else {
    847  1.40.4.6     joerg 		puffs_mp_reference(pmp);
    848  1.40.4.6     joerg 		pmp->pmp_suspend = 1;
    849  1.40.4.6     joerg 	}
    850  1.40.4.6     joerg 	mutex_exit(&pmp->pmp_lock);
    851  1.40.4.6     joerg 	if (rv)
    852  1.40.4.6     joerg 		return;
    853  1.40.4.6     joerg 	rv = kthread_create(PRI_NONE, 0, NULL, dosuspendresume,
    854  1.40.4.6     joerg 	    pmp, NULL, "puffsusp");
    855  1.40.4.6     joerg 
    856  1.40.4.6     joerg 	/* XXX: "return" rv */
    857  1.40.4.6     joerg }
    858  1.40.4.6     joerg 
    859  1.40.4.6     joerg static int
    860  1.40.4.6     joerg puffsop_flush(struct puffs_mount *pmp, struct puffs_flush *pf)
    861  1.40.4.6     joerg {
    862  1.40.4.6     joerg 	struct vnode *vp;
    863  1.40.4.6     joerg 	voff_t offlo, offhi;
    864  1.40.4.6     joerg 	int rv, flags = 0;
    865  1.40.4.6     joerg 
    866  1.40.4.6     joerg 	/* XXX: slurry */
    867  1.40.4.6     joerg 	if (pf->pf_op == PUFFS_INVAL_NAMECACHE_ALL) {
    868  1.40.4.6     joerg 		cache_purgevfs(PMPTOMP(pmp));
    869  1.40.4.6     joerg 		return 0;
    870  1.40.4.6     joerg 	}
    871  1.40.4.6     joerg 
    872  1.40.4.6     joerg 	/*
    873  1.40.4.6     joerg 	 * Get vnode, don't lock it.  Namecache is protected by its own lock
    874  1.40.4.6     joerg 	 * and we have a reference to protect against premature harvesting.
    875  1.40.4.6     joerg 	 *
    876  1.40.4.6     joerg 	 * The node we want here might be locked and the op is in
    877  1.40.4.6     joerg 	 * userspace waiting for us to complete ==> deadlock.  Another
    878  1.40.4.6     joerg 	 * reason we need to eventually bump locking to userspace, as we
    879  1.40.4.6     joerg 	 * will need to lock the node if we wish to do flushes.
    880  1.40.4.6     joerg 	 */
    881  1.40.4.6     joerg 	rv = puffs_cookie2vnode(pmp, pf->pf_cookie, 0, 0, &vp);
    882  1.40.4.6     joerg 	if (rv) {
    883  1.40.4.6     joerg 		if (rv == PUFFS_NOSUCHCOOKIE)
    884  1.40.4.6     joerg 			return ENOENT;
    885  1.40.4.6     joerg 		return rv;
    886  1.40.4.6     joerg 	}
    887  1.40.4.6     joerg 
    888  1.40.4.6     joerg 	switch (pf->pf_op) {
    889  1.40.4.6     joerg #if 0
    890  1.40.4.6     joerg 	/* not quite ready, yet */
    891  1.40.4.6     joerg 	case PUFFS_INVAL_NAMECACHE_NODE:
    892  1.40.4.6     joerg 	struct componentname *pf_cn;
    893  1.40.4.6     joerg 	char *name;
    894  1.40.4.6     joerg 		/* get comfortab^Wcomponentname */
    895  1.40.4.6     joerg 		MALLOC(pf_cn, struct componentname *,
    896  1.40.4.6     joerg 		    sizeof(struct componentname), M_PUFFS, M_WAITOK | M_ZERO);
    897  1.40.4.6     joerg 		memset(pf_cn, 0, sizeof(struct componentname));
    898  1.40.4.6     joerg 		break;
    899  1.40.4.6     joerg 
    900  1.40.4.6     joerg #endif
    901  1.40.4.6     joerg 	case PUFFS_INVAL_NAMECACHE_DIR:
    902  1.40.4.6     joerg 		if (vp->v_type != VDIR) {
    903  1.40.4.6     joerg 			rv = EINVAL;
    904  1.40.4.6     joerg 			break;
    905  1.40.4.6     joerg 		}
    906  1.40.4.6     joerg 		cache_purge1(vp, NULL, PURGE_CHILDREN);
    907  1.40.4.6     joerg 		break;
    908  1.40.4.6     joerg 
    909  1.40.4.6     joerg 	case PUFFS_INVAL_PAGECACHE_NODE_RANGE:
    910  1.40.4.6     joerg 		flags = PGO_FREE;
    911  1.40.4.6     joerg 		/*FALLTHROUGH*/
    912  1.40.4.6     joerg 	case PUFFS_FLUSH_PAGECACHE_NODE_RANGE:
    913  1.40.4.6     joerg 		if (flags == 0)
    914  1.40.4.6     joerg 			flags = PGO_CLEANIT;
    915  1.40.4.6     joerg 
    916  1.40.4.6     joerg 		if (pf->pf_end > vp->v_size || vp->v_type != VREG) {
    917  1.40.4.6     joerg 			rv = EINVAL;
    918  1.40.4.6     joerg 			break;
    919  1.40.4.6     joerg 		}
    920  1.40.4.6     joerg 
    921  1.40.4.6     joerg 		offlo = trunc_page(pf->pf_start);
    922  1.40.4.6     joerg 		offhi = round_page(pf->pf_end);
    923  1.40.4.6     joerg 		if (offhi != 0 && offlo >= offhi) {
    924  1.40.4.6     joerg 			rv = EINVAL;
    925  1.40.4.6     joerg 			break;
    926  1.40.4.6     joerg 		}
    927  1.40.4.6     joerg 
    928  1.40.4.6     joerg 		simple_lock(&vp->v_uobj.vmobjlock);
    929  1.40.4.6     joerg 		rv = VOP_PUTPAGES(vp, offlo, offhi, flags);
    930  1.40.4.6     joerg 		break;
    931  1.40.4.6     joerg 
    932  1.40.4.6     joerg 	default:
    933  1.40.4.6     joerg 		rv = EINVAL;
    934  1.40.4.6     joerg 	}
    935  1.40.4.6     joerg 
    936  1.40.4.6     joerg 	vrele(vp);
    937  1.40.4.6     joerg 
    938  1.40.4.6     joerg 	return rv;
    939  1.40.4.6     joerg }
    940  1.40.4.6     joerg 
    941  1.40.4.6     joerg int
    942  1.40.4.6     joerg puffs_msgif_dispatch(void *this, uint8_t *buf)
    943  1.40.4.6     joerg {
    944  1.40.4.6     joerg 	struct puffs_mount *pmp = this;
    945  1.40.4.6     joerg 	struct puffs_frame *pfr = (struct puffs_frame *)buf;
    946  1.40.4.6     joerg 
    947  1.40.4.6     joerg 	switch (PUFFSOP_OPCLASS(pfr->pfr_type)) {
    948  1.40.4.6     joerg 	case PUFFSOP_VN:
    949  1.40.4.6     joerg 	case PUFFSOP_VFS:
    950  1.40.4.6     joerg 		puffs_msgif_incoming(pmp, buf);
    951  1.40.4.6     joerg 		break;
    952  1.40.4.6     joerg 	case PUFFSOP_FLUSH:
    953  1.40.4.6     joerg 		puffsop_flush(pmp, (void *)buf);
    954  1.40.4.6     joerg 		break;
    955  1.40.4.6     joerg 	case PUFFSOP_SUSPEND:
    956  1.40.4.6     joerg 		puffsop_suspend(pmp);
    957  1.40.4.6     joerg 		break;
    958  1.40.4.6     joerg 	default:
    959  1.40.4.6     joerg 		/* XXX: send error */
    960  1.40.4.6     joerg 		break;
    961  1.40.4.6     joerg 	}
    962  1.40.4.6     joerg 
    963  1.40.4.6     joerg 	return 0;
    964  1.40.4.6     joerg }
    965  1.40.4.6     joerg 
    966  1.40.4.6     joerg int
    967  1.40.4.6     joerg puffs_msgif_close(void *this)
    968  1.40.4.6     joerg {
    969  1.40.4.6     joerg 	struct puffs_mount *pmp = this;
    970  1.40.4.6     joerg 	struct mount *mp = PMPTOMP(pmp);
    971  1.40.4.6     joerg 	int gone, rv;
    972  1.40.4.6     joerg 
    973  1.40.4.6     joerg 	mutex_enter(&pmp->pmp_lock);
    974  1.40.4.6     joerg 	puffs_mp_reference(pmp);
    975  1.40.4.6     joerg 
    976  1.40.4.6     joerg 	/*
    977  1.40.4.6     joerg 	 * Free the waiting callers before proceeding any further.
    978  1.40.4.6     joerg 	 * The syncer might be jogging around in this file system
    979  1.40.4.6     joerg 	 * currently.  If we allow it to go to the userspace of no
    980  1.40.4.6     joerg 	 * return while trying to get the syncer lock, well ...
    981  1.40.4.6     joerg 	 * synclk: I feel happy, I feel fine.
    982  1.40.4.6     joerg 	 * lockmgr: You're not fooling anyone, you know.
    983  1.40.4.6     joerg 	 */
    984  1.40.4.6     joerg 	puffs_userdead(pmp);
    985  1.40.4.6     joerg 
    986  1.40.4.6     joerg 	/*
    987  1.40.4.6     joerg 	 * Make sure someone from puffs_unmount() isn't currently in
    988  1.40.4.6     joerg 	 * userspace.  If we don't take this precautionary step,
    989  1.40.4.6     joerg 	 * they might notice that the mountpoint has disappeared
    990  1.40.4.6     joerg 	 * from under them once they return.  Especially note that we
    991  1.40.4.6     joerg 	 * cannot simply test for an unmounter before calling
    992  1.40.4.6     joerg 	 * dounmount(), since it might be possible that that particular
    993  1.40.4.6     joerg 	 * invocation of unmount was called without MNT_FORCE.  Here we
    994  1.40.4.6     joerg 	 * *must* make sure unmount succeeds.  Also, restart is necessary
    995  1.40.4.6     joerg 	 * since pmp isn't locked.  We might end up with PUTTER_DEAD after
    996  1.40.4.6     joerg 	 * restart and exit from there.
    997  1.40.4.6     joerg 	 */
    998  1.40.4.6     joerg 	if (pmp->pmp_unmounting) {
    999  1.40.4.6     joerg 		cv_wait(&pmp->pmp_unmounting_cv, &pmp->pmp_lock);
   1000  1.40.4.6     joerg 		puffs_mp_release(pmp);
   1001  1.40.4.6     joerg 		mutex_exit(&pmp->pmp_lock);
   1002  1.40.4.6     joerg 		DPRINTF(("puffs_fop_close: unmount was in progress for pmp %p, "
   1003  1.40.4.6     joerg 		    "restart\n", pmp));
   1004  1.40.4.6     joerg 		return ERESTART;
   1005  1.40.4.6     joerg 	}
   1006  1.40.4.6     joerg 
   1007  1.40.4.6     joerg 	/* Won't access pmp from here anymore */
   1008  1.40.4.6     joerg 	puffs_mp_release(pmp);
   1009  1.40.4.6     joerg 	mutex_exit(&pmp->pmp_lock);
   1010  1.40.4.6     joerg 
   1011  1.40.4.6     joerg 	/*
   1012  1.40.4.6     joerg 	 * Detach from VFS.  First do necessary XXX-dance (from
   1013  1.40.4.6     joerg 	 * sys_unmount() & other callers of dounmount()
   1014  1.40.4.6     joerg 	 *
   1015  1.40.4.6     joerg 	 * XXX Freeze syncer.  Must do this before locking the
   1016  1.40.4.6     joerg 	 * mount point.  See dounmount() for details.
   1017  1.40.4.6     joerg 	 *
   1018  1.40.4.6     joerg 	 * XXX2: take a reference to the mountpoint before starting to
   1019  1.40.4.6     joerg 	 * wait for syncer_mutex.  Otherwise the mointpoint can be
   1020  1.40.4.6     joerg 	 * wiped out while we wait.
   1021  1.40.4.6     joerg 	 */
   1022  1.40.4.6     joerg 	simple_lock(&mp->mnt_slock);
   1023  1.40.4.6     joerg 	mp->mnt_wcnt++;
   1024  1.40.4.6     joerg 	simple_unlock(&mp->mnt_slock);
   1025  1.40.4.6     joerg 
   1026  1.40.4.6     joerg 	mutex_enter(&syncer_mutex);
   1027  1.40.4.6     joerg 
   1028  1.40.4.6     joerg 	simple_lock(&mp->mnt_slock);
   1029  1.40.4.6     joerg 	mp->mnt_wcnt--;
   1030  1.40.4.6     joerg 	if (mp->mnt_wcnt == 0)
   1031  1.40.4.6     joerg 		wakeup(&mp->mnt_wcnt);
   1032  1.40.4.6     joerg 	gone = mp->mnt_iflag & IMNT_GONE;
   1033  1.40.4.6     joerg 	simple_unlock(&mp->mnt_slock);
   1034  1.40.4.6     joerg 	if (gone) {
   1035  1.40.4.6     joerg 		mutex_exit(&syncer_mutex);
   1036  1.40.4.6     joerg 		return 0;
   1037  1.40.4.6     joerg 	}
   1038  1.40.4.6     joerg 
   1039  1.40.4.6     joerg 	/*
   1040  1.40.4.6     joerg 	 * microscopic race condition here (although not with the current
   1041  1.40.4.6     joerg 	 * kernel), but can't really fix it without starting a crusade
   1042  1.40.4.6     joerg 	 * against vfs_busy(), so let it be, let it be, let it be
   1043  1.40.4.6     joerg 	 */
   1044  1.40.4.6     joerg 
   1045  1.40.4.6     joerg 	/*
   1046  1.40.4.6     joerg 	 * The only way vfs_busy() will fail for us is if the filesystem
   1047  1.40.4.6     joerg 	 * is already a goner.
   1048  1.40.4.6     joerg 	 * XXX: skating on the thin ice of modern calling conventions ...
   1049  1.40.4.6     joerg 	 */
   1050  1.40.4.6     joerg 	if (vfs_busy(mp, 0, 0)) {
   1051  1.40.4.6     joerg 		mutex_exit(&syncer_mutex);
   1052  1.40.4.6     joerg 		return 0;
   1053  1.40.4.6     joerg 	}
   1054  1.40.4.6     joerg 
   1055  1.40.4.6     joerg 	/*
   1056  1.40.4.6     joerg 	 * Once we have the mount point, unmount() can't interfere..
   1057  1.40.4.6     joerg 	 * or at least in theory it shouldn't.  dounmount() reentracy
   1058  1.40.4.6     joerg 	 * might require some visiting at some point.
   1059  1.40.4.6     joerg 	 */
   1060  1.40.4.6     joerg 	rv = dounmount(mp, MNT_FORCE, curlwp);
   1061  1.40.4.6     joerg 	KASSERT(rv == 0);
   1062  1.40.4.6     joerg 
   1063  1.40.4.6     joerg 	return 0;
   1064  1.40.4.6     joerg }
   1065  1.40.4.6     joerg 
   1066  1.40.4.6     joerg /*
   1067      1.22     pooka  * We're dead, kaput, RIP, slightly more than merely pining for the
   1068      1.22     pooka  * fjords, belly-up, fallen, lifeless, finished, expired, gone to meet
   1069      1.22     pooka  * our maker, ceased to be, etcetc.  YASD.  It's a dead FS!
   1070      1.22     pooka  *
   1071      1.22     pooka  * Caller must hold puffs mutex.
   1072      1.22     pooka  */
   1073      1.22     pooka void
   1074      1.22     pooka puffs_userdead(struct puffs_mount *pmp)
   1075      1.22     pooka {
   1076  1.40.4.3     joerg 	struct puffs_msgpark *park, *park_next;
   1077      1.22     pooka 
   1078      1.22     pooka 	/*
   1079      1.22     pooka 	 * Mark filesystem status as dying so that operations don't
   1080      1.22     pooka 	 * attempt to march to userspace any longer.
   1081      1.22     pooka 	 */
   1082      1.22     pooka 	pmp->pmp_status = PUFFSTAT_DYING;
   1083      1.22     pooka 
   1084      1.22     pooka 	/* signal waiters on REQUEST TO file server queue */
   1085  1.40.4.3     joerg 	for (park = TAILQ_FIRST(&pmp->pmp_msg_touser); park; park = park_next) {
   1086      1.24     pooka 		uint8_t opclass;
   1087      1.24     pooka 
   1088  1.40.4.3     joerg 		mutex_enter(&park->park_mtx);
   1089  1.40.4.3     joerg 		puffs_msgpark_reference(park);
   1090      1.32     pooka 		park_next = TAILQ_NEXT(park, park_entries);
   1091      1.26     pooka 
   1092      1.26     pooka 		KASSERT(park->park_flags & PARKFLAG_ONQUEUE1);
   1093  1.40.4.3     joerg 		TAILQ_REMOVE(&pmp->pmp_msg_touser, park, park_entries);
   1094      1.26     pooka 		park->park_flags &= ~PARKFLAG_ONQUEUE1;
   1095  1.40.4.3     joerg 		pmp->pmp_msg_touser_count--;
   1096      1.22     pooka 
   1097      1.31     pooka 		/*
   1098  1.40.4.5  jmcneill 		 * Even though waiters on QUEUE1 are removed in touser()
   1099  1.40.4.5  jmcneill 		 * in case of WAITERGONE, it is still possible for us to
   1100  1.40.4.5  jmcneill 		 * get raced here due to having to retake locks in said
   1101  1.40.4.5  jmcneill 		 * touser().  In the race case simply "ignore" the item
   1102  1.40.4.5  jmcneill 		 * on the queue and move on to the next one.
   1103      1.31     pooka 		 */
   1104      1.31     pooka 		if (park->park_flags & PARKFLAG_WAITERGONE) {
   1105      1.31     pooka 			KASSERT((park->park_flags & PARKFLAG_CALL) == 0);
   1106      1.31     pooka 			KASSERT(park->park_flags & PARKFLAG_WANTREPLY);
   1107  1.40.4.3     joerg 			puffs_msgpark_release(park);
   1108  1.40.4.5  jmcneill 
   1109      1.22     pooka 		} else {
   1110      1.31     pooka 			opclass = park->park_preq->preq_opclass;
   1111      1.23     pooka 			park->park_preq->preq_rv = ENXIO;
   1112      1.31     pooka 
   1113      1.31     pooka 			if (park->park_flags & PARKFLAG_CALL) {
   1114  1.40.4.1     joerg 				park->park_done(pmp, park->park_preq,
   1115      1.31     pooka 				    park->park_donearg);
   1116  1.40.4.3     joerg 				puffs_msgpark_release1(park, 2);
   1117      1.31     pooka 			} else if ((park->park_flags & PARKFLAG_WANTREPLY)==0) {
   1118  1.40.4.3     joerg 				puffs_msgpark_release1(park, 2);
   1119      1.31     pooka 			} else {
   1120      1.31     pooka 				park->park_preq->preq_rv = ENXIO;
   1121      1.31     pooka 				cv_signal(&park->park_cv);
   1122  1.40.4.3     joerg 				puffs_msgpark_release(park);
   1123      1.31     pooka 			}
   1124      1.22     pooka 		}
   1125      1.22     pooka 	}
   1126      1.22     pooka 
   1127      1.22     pooka 	/* signal waiters on RESPONSE FROM file server queue */
   1128  1.40.4.3     joerg 	for (park=TAILQ_FIRST(&pmp->pmp_msg_replywait); park; park=park_next) {
   1129  1.40.4.3     joerg 		mutex_enter(&park->park_mtx);
   1130  1.40.4.3     joerg 		puffs_msgpark_reference(park);
   1131      1.32     pooka 		park_next = TAILQ_NEXT(park, park_entries);
   1132      1.26     pooka 
   1133      1.26     pooka 		KASSERT(park->park_flags & PARKFLAG_ONQUEUE2);
   1134      1.31     pooka 		KASSERT(park->park_flags & PARKFLAG_WANTREPLY);
   1135      1.26     pooka 
   1136  1.40.4.3     joerg 		TAILQ_REMOVE(&pmp->pmp_msg_replywait, park, park_entries);
   1137      1.26     pooka 		park->park_flags &= ~PARKFLAG_ONQUEUE2;
   1138      1.26     pooka 
   1139      1.31     pooka 		if (park->park_flags & PARKFLAG_WAITERGONE) {
   1140      1.31     pooka 			KASSERT((park->park_flags & PARKFLAG_CALL) == 0);
   1141  1.40.4.3     joerg 			puffs_msgpark_release(park);
   1142      1.22     pooka 		} else {
   1143      1.31     pooka 			park->park_preq->preq_rv = ENXIO;
   1144      1.31     pooka 			if (park->park_flags & PARKFLAG_CALL) {
   1145  1.40.4.1     joerg 				park->park_done(pmp, park->park_preq,
   1146      1.31     pooka 				    park->park_donearg);
   1147  1.40.4.3     joerg 				puffs_msgpark_release1(park, 2);
   1148      1.31     pooka 			} else {
   1149      1.31     pooka 				cv_signal(&park->park_cv);
   1150  1.40.4.3     joerg 				puffs_msgpark_release(park);
   1151      1.31     pooka 			}
   1152      1.22     pooka 		}
   1153      1.22     pooka 	}
   1154  1.40.4.4     joerg 
   1155  1.40.4.4     joerg 	cv_broadcast(&pmp->pmp_msg_waiter_cv);
   1156      1.22     pooka }
   1157