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