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