Home | History | Annotate | Line # | Download | only in puffs
puffs_msgif.c revision 1.18.2.2
      1  1.18.2.2     yamt /*	$NetBSD: puffs_msgif.c,v 1.18.2.2 2007/03/24 14:55:57 yamt 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  * 3. The name of the company nor the name of the author may be used to
     19       1.1    pooka  *    endorse or promote products derived from this software without specific
     20       1.1    pooka  *    prior written permission.
     21       1.1    pooka  *
     22       1.1    pooka  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
     23       1.1    pooka  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     24       1.1    pooka  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     25       1.1    pooka  * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     26       1.1    pooka  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     27       1.1    pooka  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
     28       1.1    pooka  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     29       1.1    pooka  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     30       1.1    pooka  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     31       1.1    pooka  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     32       1.1    pooka  * SUCH DAMAGE.
     33       1.1    pooka  */
     34       1.1    pooka 
     35       1.1    pooka #include <sys/cdefs.h>
     36  1.18.2.2     yamt __KERNEL_RCSID(0, "$NetBSD: puffs_msgif.c,v 1.18.2.2 2007/03/24 14:55:57 yamt Exp $");
     37       1.1    pooka 
     38       1.1    pooka #include <sys/param.h>
     39      1.16    pooka #include <sys/fstrans.h>
     40       1.1    pooka #include <sys/malloc.h>
     41       1.1    pooka #include <sys/mount.h>
     42       1.1    pooka #include <sys/vnode.h>
     43       1.1    pooka #include <sys/lock.h>
     44       1.1    pooka 
     45       1.1    pooka #include <fs/puffs/puffs_msgif.h>
     46       1.1    pooka #include <fs/puffs/puffs_sys.h>
     47       1.1    pooka 
     48       1.1    pooka 
     49       1.1    pooka /*
     50       1.1    pooka  * kernel-user-kernel waitqueues
     51       1.1    pooka  */
     52       1.1    pooka 
     53       1.4    pooka static int touser(struct puffs_mount *, struct puffs_park *, uint64_t,
     54       1.1    pooka 		  struct vnode *, struct vnode *);
     55       1.1    pooka 
     56       1.4    pooka uint64_t
     57       1.1    pooka puffs_getreqid(struct puffs_mount *pmp)
     58       1.1    pooka {
     59      1.14    pooka 	uint64_t rv;
     60       1.1    pooka 
     61       1.1    pooka 	simple_lock(&pmp->pmp_lock);
     62       1.1    pooka 	rv = pmp->pmp_nextreq++;
     63       1.1    pooka 	simple_unlock(&pmp->pmp_lock);
     64       1.1    pooka 
     65       1.1    pooka 	return rv;
     66       1.1    pooka }
     67       1.1    pooka 
     68       1.1    pooka /* vfs request */
     69       1.1    pooka int
     70       1.1    pooka puffs_vfstouser(struct puffs_mount *pmp, int optype, void *kbuf, size_t buflen)
     71       1.1    pooka {
     72       1.1    pooka 	struct puffs_park park;
     73       1.1    pooka 
     74       1.9    pooka 	park.park_preq = kbuf;
     75       1.1    pooka 
     76       1.9    pooka 	park.park_preq->preq_opclass = PUFFSOP_VFS;
     77       1.9    pooka 	park.park_preq->preq_optype = optype;
     78       1.1    pooka 
     79       1.9    pooka 	park.park_maxlen = park.park_copylen = buflen;
     80  1.18.2.1    rmind 	park.park_flags = 0;
     81       1.1    pooka 
     82       1.1    pooka 	return touser(pmp, &park, puffs_getreqid(pmp), NULL, NULL);
     83       1.1    pooka }
     84       1.1    pooka 
     85      1.16    pooka void
     86      1.16    pooka puffs_suspendtouser(struct puffs_mount *pmp, int status)
     87      1.16    pooka {
     88      1.16    pooka 	struct puffs_vfsreq_suspend *pvfsr_susp;
     89      1.16    pooka 	struct puffs_park *ppark;
     90      1.16    pooka 
     91      1.16    pooka 	pvfsr_susp = malloc(sizeof(struct puffs_vfsreq_suspend),
     92      1.16    pooka 	    M_PUFFS, M_WAITOK | M_ZERO);
     93      1.16    pooka 	ppark = malloc(sizeof(struct puffs_park), M_PUFFS, M_WAITOK | M_ZERO);
     94      1.16    pooka 
     95      1.16    pooka 	pvfsr_susp->pvfsr_status = status;
     96      1.16    pooka 	ppark->park_preq = (struct puffs_req *)pvfsr_susp;
     97      1.16    pooka 
     98      1.16    pooka 	ppark->park_preq->preq_opclass = PUFFSOP_VFS | PUFFSOPFLAG_FAF;
     99      1.16    pooka 	ppark->park_preq->preq_optype = PUFFS_VFS_SUSPEND;
    100      1.16    pooka 
    101      1.16    pooka 	ppark->park_maxlen = ppark->park_copylen
    102      1.16    pooka 	    = sizeof(struct puffs_vfsreq_suspend);
    103  1.18.2.1    rmind 	ppark->park_flags = 0;
    104      1.16    pooka 
    105      1.16    pooka 	(void)touser(pmp, ppark, 0, NULL, NULL);
    106      1.16    pooka }
    107      1.16    pooka 
    108       1.1    pooka /*
    109       1.1    pooka  * vnode level request
    110       1.1    pooka  */
    111       1.1    pooka int
    112       1.1    pooka puffs_vntouser(struct puffs_mount *pmp, int optype,
    113       1.1    pooka 	void *kbuf, size_t buflen, void *cookie,
    114       1.1    pooka 	struct vnode *vp1, struct vnode *vp2)
    115       1.1    pooka {
    116       1.1    pooka 	struct puffs_park park;
    117       1.1    pooka 
    118       1.9    pooka 	park.park_preq = kbuf;
    119       1.1    pooka 
    120       1.9    pooka 	park.park_preq->preq_opclass = PUFFSOP_VN;
    121       1.9    pooka 	park.park_preq->preq_optype = optype;
    122       1.9    pooka 	park.park_preq->preq_cookie = cookie;
    123       1.9    pooka 
    124       1.9    pooka 	park.park_maxlen = park.park_copylen = buflen;
    125  1.18.2.1    rmind 	park.park_flags = 0;
    126       1.1    pooka 
    127       1.1    pooka 	return touser(pmp, &park, puffs_getreqid(pmp), vp1, vp2);
    128       1.1    pooka }
    129       1.1    pooka 
    130       1.1    pooka /*
    131       1.1    pooka  * vnode level request, caller-controller req id
    132       1.1    pooka  */
    133       1.1    pooka int
    134       1.1    pooka puffs_vntouser_req(struct puffs_mount *pmp, int optype,
    135       1.4    pooka 	void *kbuf, size_t buflen, void *cookie, uint64_t reqid,
    136       1.1    pooka 	struct vnode *vp1, struct vnode *vp2)
    137       1.1    pooka {
    138       1.1    pooka 	struct puffs_park park;
    139       1.1    pooka 
    140       1.9    pooka 	park.park_preq = kbuf;
    141       1.9    pooka 
    142       1.9    pooka 	park.park_preq->preq_opclass = PUFFSOP_VN;
    143       1.9    pooka 	park.park_preq->preq_optype = optype;
    144       1.9    pooka 	park.park_preq->preq_cookie = cookie;
    145       1.1    pooka 
    146       1.9    pooka 	park.park_maxlen = park.park_copylen = buflen;
    147  1.18.2.1    rmind 	park.park_flags = 0;
    148       1.1    pooka 
    149       1.1    pooka 	return touser(pmp, &park, reqid, vp1, vp2);
    150       1.1    pooka }
    151       1.1    pooka 
    152       1.1    pooka /*
    153       1.9    pooka  * vnode level request, copy routines can adjust "kernbuf".
    154       1.1    pooka  */
    155       1.1    pooka int
    156       1.1    pooka puffs_vntouser_adjbuf(struct puffs_mount *pmp, int optype,
    157       1.9    pooka 	void **kbuf, size_t *buflen, size_t maxdelta,
    158       1.9    pooka 	void *cookie, struct vnode *vp1, struct vnode *vp2)
    159       1.1    pooka {
    160       1.1    pooka 	struct puffs_park park;
    161       1.1    pooka 	int error;
    162       1.1    pooka 
    163       1.9    pooka 	park.park_preq = *kbuf;
    164       1.1    pooka 
    165       1.9    pooka 	park.park_preq->preq_opclass = PUFFSOP_VN;
    166       1.9    pooka 	park.park_preq->preq_optype = optype;
    167       1.9    pooka 	park.park_preq->preq_cookie = cookie;
    168       1.9    pooka 
    169       1.9    pooka 	park.park_copylen = *buflen;
    170       1.9    pooka 	park.park_maxlen = maxdelta + *buflen;
    171  1.18.2.1    rmind 	park.park_flags = PUFFS_PARKFLAG_ADJUSTABLE;
    172       1.1    pooka 
    173       1.1    pooka 	error = touser(pmp, &park, puffs_getreqid(pmp), vp1, vp2);
    174       1.9    pooka 
    175       1.9    pooka 	*kbuf = park.park_preq;
    176       1.9    pooka 	*buflen = park.park_copylen;
    177       1.1    pooka 
    178       1.1    pooka 	return error;
    179       1.1    pooka }
    180       1.1    pooka 
    181       1.1    pooka /*
    182  1.18.2.2     yamt  * File server interaction is async from caller perspective.
    183  1.18.2.2     yamt  * biodone(bp)J is signalled in putop.
    184  1.18.2.2     yamt  */
    185  1.18.2.2     yamt void
    186  1.18.2.2     yamt puffs_vntouser_bioread_async(struct puffs_mount *pmp, void *cookie,
    187  1.18.2.2     yamt 	size_t tomove, off_t offset, struct buf *bp,
    188  1.18.2.2     yamt 	struct vnode *vp1, struct vnode *vp2)
    189  1.18.2.2     yamt {
    190  1.18.2.2     yamt 	struct puffs_park *ppark;
    191  1.18.2.2     yamt 	struct puffs_vnreq_read *read_argp;
    192  1.18.2.2     yamt 
    193  1.18.2.2     yamt 	MALLOC(ppark, struct puffs_park *, sizeof(struct puffs_park),
    194  1.18.2.2     yamt 	    M_PUFFS, M_WAITOK);
    195  1.18.2.2     yamt 	MALLOC(read_argp, struct puffs_vnreq_read *,
    196  1.18.2.2     yamt 	    sizeof(struct puffs_vnreq_read), M_PUFFS, M_WAITOK | M_ZERO);
    197  1.18.2.2     yamt 
    198  1.18.2.2     yamt 	read_argp->pvnr_ioflag = 0;
    199  1.18.2.2     yamt 	read_argp->pvnr_resid = tomove;
    200  1.18.2.2     yamt 	read_argp->pvnr_offset = offset;
    201  1.18.2.2     yamt 	puffs_credcvt(&read_argp->pvnr_cred, FSCRED);
    202  1.18.2.2     yamt 
    203  1.18.2.2     yamt 	ppark->park_preq = (void *)read_argp;
    204  1.18.2.2     yamt 	ppark->park_preq->preq_opclass = PUFFSOP_VN;
    205  1.18.2.2     yamt 	ppark->park_preq->preq_optype = PUFFS_VN_READ;
    206  1.18.2.2     yamt 	ppark->park_preq->preq_cookie = cookie;
    207  1.18.2.2     yamt 
    208  1.18.2.2     yamt 	ppark->park_copylen = sizeof(struct puffs_vnreq_read);
    209  1.18.2.2     yamt 	ppark->park_maxlen = sizeof(struct puffs_vnreq_read) + tomove;
    210  1.18.2.2     yamt 	ppark->park_bp = bp;
    211  1.18.2.2     yamt 	ppark->park_flags
    212  1.18.2.2     yamt 	    = PUFFS_PARKFLAG_ADJUSTABLE | PUFFS_PARKFLAG_ASYNCBIOREAD;
    213  1.18.2.2     yamt 
    214  1.18.2.2     yamt 	(void)touser(pmp, ppark, puffs_getreqid(pmp), vp1, vp2);
    215  1.18.2.2     yamt }
    216  1.18.2.2     yamt 
    217  1.18.2.2     yamt /*
    218       1.4    pooka  * Notice: kbuf will be free'd later.  I must be allocated from the
    219       1.4    pooka  * kernel heap and it's ownership is shifted to this function from
    220       1.4    pooka  * now on, i.e. the caller is not allowed to use it anymore!
    221       1.4    pooka  */
    222       1.4    pooka void
    223       1.4    pooka puffs_vntouser_faf(struct puffs_mount *pmp, int optype,
    224       1.4    pooka 	void *kbuf, size_t buflen, void *cookie)
    225       1.4    pooka {
    226       1.4    pooka 	struct puffs_park *ppark;
    227       1.4    pooka 
    228       1.4    pooka 	/* XXX: is it allowable to sleep here? */
    229       1.4    pooka 	ppark = malloc(sizeof(struct puffs_park), M_PUFFS, M_NOWAIT | M_ZERO);
    230       1.4    pooka 	if (ppark == NULL)
    231       1.4    pooka 		return; /* 2bad */
    232       1.4    pooka 
    233       1.9    pooka 	ppark->park_preq = kbuf;
    234       1.9    pooka 
    235       1.9    pooka 	ppark->park_preq->preq_opclass = PUFFSOP_VN | PUFFSOPFLAG_FAF;
    236       1.9    pooka 	ppark->park_preq->preq_optype = optype;
    237       1.9    pooka 	ppark->park_preq->preq_cookie = cookie;
    238       1.9    pooka 
    239       1.9    pooka 	ppark->park_maxlen = ppark->park_copylen = buflen;
    240  1.18.2.1    rmind 	ppark->park_flags = 0;
    241       1.4    pooka 
    242       1.4    pooka 	(void)touser(pmp, ppark, 0, NULL, NULL);
    243       1.4    pooka }
    244       1.4    pooka 
    245  1.18.2.2     yamt void
    246  1.18.2.2     yamt puffs_cacheop(struct puffs_mount *pmp, struct puffs_park *ppark,
    247  1.18.2.2     yamt 	struct puffs_cacheinfo *pcinfo, size_t pcilen, void *cookie)
    248  1.18.2.2     yamt {
    249  1.18.2.2     yamt 
    250  1.18.2.2     yamt 	ppark->park_preq = (struct puffs_req *)pcinfo;
    251  1.18.2.2     yamt 	ppark->park_preq->preq_opclass = PUFFSOP_CACHE | PUFFSOPFLAG_FAF;
    252  1.18.2.2     yamt 	ppark->park_preq->preq_optype = PCACHE_TYPE_WRITE; /* XXX */
    253  1.18.2.2     yamt 	ppark->park_preq->preq_cookie = cookie;
    254  1.18.2.2     yamt 
    255  1.18.2.2     yamt 	ppark->park_maxlen = ppark->park_copylen = pcilen;
    256  1.18.2.2     yamt 
    257  1.18.2.2     yamt 	(void)touser(pmp, ppark, 0, NULL, NULL);
    258  1.18.2.2     yamt }
    259  1.18.2.2     yamt 
    260       1.4    pooka /*
    261       1.1    pooka  * Wait for the userspace ping-pong game in calling process context.
    262       1.1    pooka  *
    263       1.1    pooka  * This unlocks vnodes if they are supplied.  vp1 is the vnode
    264       1.1    pooka  * before in the locking order, i.e. the one which must be locked
    265       1.1    pooka  * before accessing vp2.  This is done here so that operations are
    266       1.1    pooka  * already ordered in the queue when vnodes are unlocked (I'm not
    267       1.1    pooka  * sure if that's really necessary, but it can't hurt).  Okok, maybe
    268       1.1    pooka  * there's a slight ugly-factor also, but let's not worry about that.
    269       1.1    pooka  */
    270       1.1    pooka static int
    271       1.4    pooka touser(struct puffs_mount *pmp, struct puffs_park *ppark, uint64_t reqid,
    272       1.1    pooka 	struct vnode *vp1, struct vnode *vp2)
    273       1.1    pooka {
    274  1.18.2.1    rmind 	struct lwp *l = curlwp;
    275      1.16    pooka 	struct mount *mp;
    276       1.9    pooka 	struct puffs_req *preq;
    277  1.18.2.1    rmind 	int rv = 0;
    278       1.1    pooka 
    279      1.16    pooka 	mp = PMPTOMP(pmp);
    280  1.18.2.1    rmind 	preq = ppark->park_preq;
    281  1.18.2.1    rmind 	preq->preq_id = ppark->park_id = reqid;
    282  1.18.2.1    rmind 	preq->preq_buflen = ALIGN(ppark->park_maxlen);
    283  1.18.2.1    rmind 
    284  1.18.2.1    rmind 	/*
    285  1.18.2.1    rmind 	 * To support PCATCH, yet another movie: check if there are signals
    286  1.18.2.1    rmind 	 * pending and we are issueing a non-FAF.  If so, return an error
    287  1.18.2.1    rmind 	 * directly UNLESS we are issueing INACTIVE.  In that case, convert
    288  1.18.2.1    rmind 	 * it to a FAF, fire off to the file server and return an error.
    289  1.18.2.1    rmind 	 * Yes, this is bordering disgusting.  Barfbags are on me.
    290  1.18.2.1    rmind 	 */
    291  1.18.2.1    rmind 	if (PUFFSOP_WANTREPLY(ppark->park_preq->preq_opclass)
    292  1.18.2.2     yamt 	   && (ppark->park_flags & PUFFS_PARKFLAG_ASYNCBIOREAD) == 0
    293  1.18.2.1    rmind 	   && (l->l_flag & LW_PENDSIG) != 0 && sigispending(l, 0)) {
    294  1.18.2.1    rmind 		if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN
    295  1.18.2.1    rmind 		    && preq->preq_optype == PUFFS_VN_INACTIVE) {
    296  1.18.2.1    rmind 			struct puffs_park *newpark;
    297  1.18.2.1    rmind 
    298  1.18.2.1    rmind 			newpark = puffs_reqtofaf(ppark);
    299  1.18.2.1    rmind 			DPRINTF(("puffs touser: converted to FAF, old %p, "
    300  1.18.2.1    rmind 			    "new %p\n", ppark, newpark));
    301  1.18.2.1    rmind 			ppark = newpark;
    302  1.18.2.1    rmind 			rv = EINTR;
    303  1.18.2.1    rmind 		} else {
    304  1.18.2.1    rmind 			return EINTR;
    305  1.18.2.1    rmind 		}
    306  1.18.2.1    rmind 	}
    307      1.16    pooka 
    308      1.16    pooka 	/*
    309      1.16    pooka 	 * test for suspension lock.
    310      1.16    pooka 	 *
    311      1.16    pooka 	 * Note that we *DO NOT* keep the lock, since that might block
    312      1.16    pooka 	 * lock acquiring PLUS it would give userlandia control over
    313      1.16    pooka 	 * the lock.  The operation queue enforces a strict ordering:
    314      1.16    pooka 	 * when the fs server gets in the op stream, it knows things
    315      1.16    pooka 	 * are in order.  The kernel locks can't guarantee that for
    316      1.16    pooka 	 * userspace, in any case.
    317      1.16    pooka 	 *
    318      1.16    pooka 	 * BUT: this presents a problem for ops which have a consistency
    319      1.16    pooka 	 * clause based on more than one operation.  Unfortunately such
    320      1.16    pooka 	 * operations (read, write) do not reliably work yet.
    321      1.16    pooka 	 *
    322      1.16    pooka 	 * Ya, Ya, it's wrong wong wrong, me be fixink this someday.
    323      1.18    pooka 	 *
    324      1.18    pooka 	 * XXX: and there is one more problem.  We sometimes need to
    325      1.18    pooka 	 * take a lazy lock in case the fs is suspending and we are
    326      1.18    pooka 	 * executing as the fs server context.  This might happen
    327      1.18    pooka 	 * e.g. in the case that the user server triggers a reclaim
    328      1.18    pooka 	 * in the kernel while the fs is suspending.  It's not a very
    329      1.18    pooka 	 * likely event, but it needs to be fixed some day.
    330      1.16    pooka 	 */
    331      1.18    pooka 	fstrans_start(mp, FSTRANS_NORMAL);
    332       1.1    pooka 	simple_lock(&pmp->pmp_lock);
    333      1.16    pooka 	fstrans_done(mp);
    334      1.16    pooka 
    335      1.13    pooka 	if (pmp->pmp_status != PUFFSTAT_RUNNING) {
    336       1.1    pooka 		simple_unlock(&pmp->pmp_lock);
    337       1.1    pooka 		return ENXIO;
    338       1.1    pooka 	}
    339       1.1    pooka 
    340       1.4    pooka 	TAILQ_INSERT_TAIL(&pmp->pmp_req_touser, ppark, park_entries);
    341       1.1    pooka 	pmp->pmp_req_touser_waiters++;
    342       1.1    pooka 
    343       1.1    pooka 	/*
    344       1.1    pooka 	 * Don't do unlock-relock dance yet.  There are a couple of
    345       1.1    pooka 	 * unsolved issues with it.  If we don't unlock, we can have
    346       1.1    pooka 	 * processes wanting vn_lock in case userspace hangs.  But
    347       1.1    pooka 	 * that can be "solved" by killing the userspace process.  It
    348       1.1    pooka 	 * would of course be nicer to have antilocking in the userspace
    349       1.1    pooka 	 * interface protocol itself.. your patience will be rewarded.
    350       1.1    pooka 	 */
    351       1.1    pooka #if 0
    352       1.1    pooka 	/* unlock */
    353       1.1    pooka 	if (vp2)
    354       1.1    pooka 		VOP_UNLOCK(vp2, 0);
    355       1.1    pooka 	if (vp1)
    356       1.1    pooka 		VOP_UNLOCK(vp1, 0);
    357       1.1    pooka #endif
    358       1.1    pooka 
    359       1.1    pooka 	/*
    360       1.1    pooka 	 * XXX: does releasing the lock here cause trouble?  Can't hold
    361       1.1    pooka 	 * it, because otherwise the below would cause locking against
    362       1.4    pooka 	 * oneself-problems in the kqueue stuff.  yes, it is a
    363       1.4    pooka 	 * theoretical race, so it must be solved
    364       1.1    pooka 	 */
    365       1.1    pooka 	simple_unlock(&pmp->pmp_lock);
    366       1.1    pooka 
    367  1.18.2.2     yamt 	DPRINTF(("touser: req %" PRIu64 ", preq: %p, park: %p, "
    368  1.18.2.2     yamt 	    "c/t: 0x%x/0x%x, f: 0x%x\n", preq->preq_id, preq, ppark,
    369  1.18.2.2     yamt 	    preq->preq_opclass, preq->preq_optype, ppark->park_flags));
    370      1.15    pooka 
    371       1.1    pooka 	wakeup(&pmp->pmp_req_touser);
    372       1.1    pooka 	selnotify(pmp->pmp_sel, 0);
    373       1.1    pooka 
    374  1.18.2.2     yamt 	if (PUFFSOP_WANTREPLY(ppark->park_preq->preq_opclass)
    375  1.18.2.2     yamt 	    && (ppark->park_flags & PUFFS_PARKFLAG_ASYNCBIOREAD) == 0) {
    376  1.18.2.1    rmind 		struct puffs_park *valetpark = NULL;
    377  1.18.2.1    rmind 		int error;
    378  1.18.2.1    rmind 
    379  1.18.2.1    rmind 		error = ltsleep(ppark, PUSER | PCATCH, "puffs1", 0, NULL);
    380  1.18.2.1    rmind 		rv = ppark->park_preq->preq_rv;
    381  1.18.2.1    rmind 
    382  1.18.2.1    rmind 		/*
    383  1.18.2.1    rmind 		 * Ok, so it gets a bit tricky around here once again.
    384  1.18.2.1    rmind 		 * We want to give interruptibility to the sleep to work
    385  1.18.2.1    rmind 		 * around all kinds of locking-against-oneself problems
    386  1.18.2.1    rmind 		 * and the file system recursing into itself and so forth.
    387  1.18.2.1    rmind 		 * So if we break out of the ltsleep() for anything except
    388  1.18.2.1    rmind 		 * natural causes, we need to caution ourselves.
    389  1.18.2.1    rmind 		 *
    390  1.18.2.1    rmind 		 * The stages at which we can break out are:
    391  1.18.2.1    rmind 		 *  1) operation waiting to be fetched by file server
    392  1.18.2.1    rmind 		 *  2) operation being copied to userspace, not on either queue
    393  1.18.2.1    rmind 		 *  3) file server operating on .. err .. operation
    394  1.18.2.1    rmind 		 *  4) putop: locate the correct park structure from the queue
    395  1.18.2.1    rmind 		 *  5) putop: copy response from userspace
    396  1.18.2.1    rmind 		 *  6) putop: wakeup waiter
    397  1.18.2.1    rmind 		 *
    398  1.18.2.1    rmind 		 * If we are still at stage 1, no problem, just remove
    399  1.18.2.1    rmind 		 * ourselves from the queue to userspace.  If we are at
    400  1.18.2.1    rmind 		 * the stage before 4 has completed, replace the park structure
    401  1.18.2.1    rmind 		 * with a park structure indicating that the caller is
    402  1.18.2.1    rmind 		 * no more and no proper reply is required.  If the server
    403  1.18.2.1    rmind 		 * is already copying data from userspace to the kernel,
    404  1.18.2.1    rmind 		 * wait for it to finish and return the real return value to
    405  1.18.2.1    rmind 		 * the caller.
    406  1.18.2.1    rmind 		 */
    407  1.18.2.1    rmind  checkagain:
    408  1.18.2.1    rmind 		if (valetpark) {
    409  1.18.2.1    rmind 			FREE(valetpark, M_PUFFS);
    410  1.18.2.1    rmind 			valetpark = NULL;
    411  1.18.2.1    rmind 		}
    412  1.18.2.1    rmind 
    413  1.18.2.1    rmind 		if (error) {
    414  1.18.2.1    rmind 			DPRINTF(("puffs touser: got %d from ltsleep, "
    415  1.18.2.1    rmind 			    "(unlocked) flags 0x%x (park %p)\n",
    416  1.18.2.1    rmind 			    error, ppark->park_flags, ppark));
    417  1.18.2.1    rmind 			rv = error;
    418  1.18.2.1    rmind 
    419  1.18.2.1    rmind 			MALLOC(valetpark, struct puffs_park *,
    420  1.18.2.1    rmind 			    sizeof(struct puffs_park), M_PUFFS,
    421  1.18.2.1    rmind 			    M_ZERO | M_WAITOK);
    422  1.18.2.1    rmind 
    423  1.18.2.1    rmind 			simple_lock(&pmp->pmp_lock);
    424  1.18.2.1    rmind 
    425  1.18.2.1    rmind 			/*
    426  1.18.2.1    rmind 			 * The order here for the clauses, per description
    427  1.18.2.1    rmind 			 * in comment above, is:
    428  1.18.2.1    rmind 			 *   1, after 6, after 4, 2-3.
    429  1.18.2.1    rmind 			 */
    430  1.18.2.1    rmind 			if ((ppark->park_flags&PUFFS_PARKFLAG_PROCESSING)==0) {
    431  1.18.2.1    rmind 				TAILQ_REMOVE(&pmp->pmp_req_touser, ppark,
    432  1.18.2.1    rmind 				    park_entries);
    433  1.18.2.1    rmind 				simple_unlock(&pmp->pmp_lock);
    434  1.18.2.1    rmind 				FREE(valetpark, M_PUFFS);
    435  1.18.2.1    rmind 				DPRINTF(("puffs touser: park %p removed "
    436  1.18.2.1    rmind 				    "from queue one\n", ppark));
    437  1.18.2.1    rmind 			} else if
    438  1.18.2.1    rmind 			   (ppark->park_flags & PUFFS_PARKFLAG_RECVREPLY) {
    439  1.18.2.1    rmind 				if (ppark->park_flags & PUFFS_PARKFLAG_DONE) {
    440  1.18.2.1    rmind 					rv = ppark->park_preq->preq_rv;
    441  1.18.2.1    rmind 					simple_unlock(&pmp->pmp_lock);
    442  1.18.2.1    rmind 					FREE(valetpark, M_PUFFS);
    443  1.18.2.1    rmind 				} else {
    444  1.18.2.1    rmind 					error = ltsleep(ppark,
    445  1.18.2.1    rmind 					    PUSER | PCATCH | PNORELOCK,
    446  1.18.2.1    rmind 					    "puffsre1", 0, &pmp->pmp_lock);
    447  1.18.2.1    rmind 					goto checkagain;
    448  1.18.2.1    rmind 				}
    449  1.18.2.1    rmind 			} else {
    450  1.18.2.1    rmind 				valetpark->park_flags
    451  1.18.2.1    rmind 				    = PUFFS_PARKFLAG_WAITERGONE;
    452  1.18.2.1    rmind 				ppark->park_flags |= PUFFS_PARKFLAG_WAITERGONE;
    453  1.18.2.1    rmind 				valetpark->park_id = ppark->park_id;
    454  1.18.2.1    rmind 
    455  1.18.2.1    rmind 				if (ppark->park_flags & PUFFS_PARKFLAG_RQUEUE) {
    456  1.18.2.1    rmind 					TAILQ_INSERT_BEFORE(ppark, valetpark,
    457  1.18.2.1    rmind 					    park_entries);
    458  1.18.2.1    rmind 					TAILQ_REMOVE(&pmp->pmp_req_replywait,
    459  1.18.2.1    rmind 					    ppark, park_entries);
    460  1.18.2.1    rmind 				} else {
    461  1.18.2.1    rmind 					TAILQ_INSERT_TAIL(
    462  1.18.2.1    rmind 					    &pmp->pmp_req_replywait,
    463  1.18.2.1    rmind 					    valetpark, park_entries);
    464  1.18.2.1    rmind 				}
    465       1.1    pooka 
    466  1.18.2.1    rmind 				simple_unlock(&pmp->pmp_lock);
    467  1.18.2.1    rmind 				DPRINTF(("puffs touser: replaced park %p "
    468  1.18.2.1    rmind 				    "with valet park %p\n", ppark, valetpark));
    469  1.18.2.1    rmind 			}
    470  1.18.2.1    rmind 		}
    471  1.18.2.1    rmind 
    472      1.16    pooka 		/*
    473      1.16    pooka 		 * retake the lock and release.  This makes sure (haha,
    474      1.16    pooka 		 * I'm humorous) that we don't process the same vnode in
    475      1.16    pooka 		 * multiple threads due to the locks hacks we have in
    476      1.16    pooka 		 * puffs_lock().  In reality this is well protected by
    477      1.16    pooka 		 * the biglock, but once that's gone, well, hopefully
    478      1.16    pooka 		 * this will be fixed for real.  (and when you read this
    479      1.16    pooka 		 * comment in 2017 and subsequently barf, my condolences ;).
    480      1.16    pooka 		 */
    481  1.18.2.1    rmind 		if (rv == 0 && !fstrans_is_owner(mp)) {
    482      1.17  hannken 			fstrans_start(mp, FSTRANS_NORMAL);
    483      1.16    pooka 			fstrans_done(mp);
    484      1.16    pooka 		}
    485      1.16    pooka 	}
    486      1.16    pooka 
    487       1.1    pooka #if 0
    488       1.1    pooka 	/* relock */
    489       1.1    pooka 	if (vp1)
    490       1.1    pooka 		KASSERT(vn_lock(vp1, LK_EXCLUSIVE | LK_RETRY) == 0);
    491       1.1    pooka 	if (vp2)
    492       1.1    pooka 		KASSERT(vn_lock(vp2, LK_EXCLUSIVE | LK_RETRY) == 0);
    493       1.1    pooka #endif
    494       1.1    pooka 
    495      1.16    pooka 	simple_lock(&pmp->pmp_lock);
    496      1.16    pooka 	if (--pmp->pmp_req_touser_waiters == 0)
    497      1.16    pooka 		wakeup(&pmp->pmp_req_touser_waiters);
    498      1.16    pooka 	simple_unlock(&pmp->pmp_lock);
    499      1.16    pooka 
    500  1.18.2.1    rmind 	return rv;
    501       1.1    pooka }
    502       1.1    pooka 
    503       1.1    pooka 
    504       1.9    pooka /*
    505       1.9    pooka  * getop: scan through queued requests until:
    506       1.9    pooka  *  1) max number of requests satisfied
    507       1.9    pooka  *     OR
    508       1.9    pooka  *  2) buffer runs out of space
    509       1.9    pooka  *     OR
    510       1.9    pooka  *  3) nonblocking is set AND there are no operations available
    511       1.9    pooka  *     OR
    512       1.9    pooka  *  4) at least one operation was transferred AND there are no more waiting
    513       1.9    pooka  */
    514      1.10    pooka int
    515      1.10    pooka puffs_getop(struct puffs_mount *pmp, struct puffs_reqh_get *phg, int nonblock)
    516       1.1    pooka {
    517       1.1    pooka 	struct puffs_park *park;
    518       1.9    pooka 	struct puffs_req *preq;
    519       1.9    pooka 	uint8_t *bufpos;
    520       1.9    pooka 	int error, donesome;
    521       1.9    pooka 
    522       1.9    pooka 	donesome = error = 0;
    523       1.9    pooka 	bufpos = phg->phg_buf;
    524       1.1    pooka 
    525       1.1    pooka 	simple_lock(&pmp->pmp_lock);
    526       1.9    pooka 	while (phg->phg_nops == 0 || donesome != phg->phg_nops) {
    527       1.1    pooka  again:
    528       1.9    pooka 		if (pmp->pmp_status != PUFFSTAT_RUNNING) {
    529       1.9    pooka 			/* if we got some, they don't really matter anymore */
    530       1.9    pooka 			error = ENXIO;
    531       1.9    pooka 			goto out;
    532       1.9    pooka 		}
    533       1.9    pooka 		if (TAILQ_EMPTY(&pmp->pmp_req_touser)) {
    534      1.12    pooka 			if (donesome)
    535      1.12    pooka 				goto out;
    536      1.12    pooka 
    537      1.12    pooka 			if (nonblock) {
    538      1.12    pooka 				error = EWOULDBLOCK;
    539       1.9    pooka 				goto out;
    540       1.9    pooka 			}
    541       1.9    pooka 
    542      1.11    pooka 			error = ltsleep(&pmp->pmp_req_touser, PUSER | PCATCH,
    543      1.11    pooka 			    "puffs2", 0, &pmp->pmp_lock);
    544      1.11    pooka 			if (error)
    545      1.11    pooka 				goto out;
    546      1.11    pooka 			else
    547      1.11    pooka 				goto again;
    548       1.9    pooka 		}
    549       1.9    pooka 
    550       1.9    pooka 		park = TAILQ_FIRST(&pmp->pmp_req_touser);
    551       1.9    pooka 		preq = park->park_preq;
    552       1.9    pooka 
    553       1.9    pooka 		if (phg->phg_buflen < preq->preq_buflen) {
    554       1.9    pooka 			if (!donesome)
    555       1.9    pooka 				error = E2BIG;
    556       1.9    pooka 			goto out;
    557       1.9    pooka 		}
    558       1.9    pooka 		TAILQ_REMOVE(&pmp->pmp_req_touser, park, park_entries);
    559  1.18.2.1    rmind 		park->park_flags |= PUFFS_PARKFLAG_PROCESSING;
    560       1.1    pooka 		simple_unlock(&pmp->pmp_lock);
    561  1.18.2.1    rmind 
    562       1.9    pooka 		DPRINTF(("puffsgetop: get op %" PRIu64 " (%d.), from %p "
    563       1.9    pooka 		    "len %zu (buflen %zu), target %p\n", preq->preq_id,
    564       1.9    pooka 		    donesome, preq, park->park_copylen, preq->preq_buflen,
    565       1.9    pooka 		    bufpos));
    566       1.9    pooka 
    567       1.9    pooka 		if ((error = copyout(preq, bufpos, park->park_copylen)) != 0) {
    568       1.9    pooka 			DPRINTF(("    FAILED %d\n", error));
    569       1.9    pooka 			/*
    570       1.9    pooka 			 * ok, user server is probably trying to cheat.
    571       1.9    pooka 			 * stuff op back & return error to user
    572       1.9    pooka 			 */
    573       1.9    pooka 			 simple_lock(&pmp->pmp_lock);
    574       1.9    pooka 			 TAILQ_INSERT_HEAD(&pmp->pmp_req_touser, park,
    575       1.9    pooka 			     park_entries);
    576       1.9    pooka 
    577       1.9    pooka 			 if (donesome)
    578       1.9    pooka 				error = 0;
    579       1.9    pooka 			 goto out;
    580       1.9    pooka 		}
    581       1.9    pooka 		bufpos += preq->preq_buflen;
    582       1.9    pooka 		phg->phg_buflen -= preq->preq_buflen;
    583       1.9    pooka 		donesome++;
    584       1.9    pooka 
    585       1.9    pooka 		simple_lock(&pmp->pmp_lock);
    586       1.9    pooka 		if (PUFFSOP_WANTREPLY(preq->preq_opclass)) {
    587  1.18.2.1    rmind 			if ((park->park_flags & PUFFS_PARKFLAG_WAITERGONE)==0) {
    588  1.18.2.1    rmind 				TAILQ_INSERT_TAIL(&pmp->pmp_req_replywait, park,
    589  1.18.2.1    rmind 				    park_entries);
    590  1.18.2.1    rmind 				park->park_flags |= PUFFS_PARKFLAG_RQUEUE;
    591  1.18.2.1    rmind 			}
    592       1.9    pooka 		} else {
    593       1.1    pooka 			simple_unlock(&pmp->pmp_lock);
    594       1.9    pooka 			free(preq, M_PUFFS);
    595       1.9    pooka 			free(park, M_PUFFS);
    596       1.9    pooka 			simple_lock(&pmp->pmp_lock);
    597       1.1    pooka 		}
    598       1.1    pooka 	}
    599       1.1    pooka 
    600       1.9    pooka  out:
    601       1.9    pooka 	phg->phg_more = pmp->pmp_req_touser_waiters;
    602       1.1    pooka 	simple_unlock(&pmp->pmp_lock);
    603       1.1    pooka 
    604       1.9    pooka 	phg->phg_nops = donesome;
    605       1.4    pooka 
    606       1.9    pooka 	return error;
    607       1.1    pooka }
    608       1.1    pooka 
    609  1.18.2.2     yamt /*
    610  1.18.2.2     yamt  * urgh, too complex, be very very careful while editing, i.e. NEEDS CLEANUP
    611  1.18.2.2     yamt  */
    612      1.10    pooka int
    613      1.10    pooka puffs_putop(struct puffs_mount *pmp, struct puffs_reqh_put *php)
    614       1.1    pooka {
    615       1.1    pooka 	struct puffs_park *park;
    616  1.18.2.1    rmind 	struct puffs_req tmpreq;
    617  1.18.2.1    rmind 	struct puffs_req *nextpreq;
    618  1.18.2.2     yamt 	struct buf *bp;
    619       1.9    pooka 	void *userbuf;
    620       1.9    pooka 	uint64_t id;
    621       1.9    pooka 	size_t reqlen;
    622  1.18.2.1    rmind 	int donesome, error, wgone;
    623       1.9    pooka 
    624  1.18.2.1    rmind 	donesome = error = wgone = 0;
    625       1.9    pooka 
    626       1.9    pooka 	id = php->php_id;
    627       1.9    pooka 	userbuf = php->php_buf;
    628       1.9    pooka 	reqlen = php->php_buflen;
    629       1.1    pooka 
    630       1.1    pooka 	simple_lock(&pmp->pmp_lock);
    631       1.9    pooka 	while (donesome != php->php_nops) {
    632  1.18.2.1    rmind #ifdef PUFFSDEBUG
    633       1.9    pooka 		simple_unlock(&pmp->pmp_lock);
    634       1.9    pooka 		DPRINTF(("puffsputop: searching for %" PRIu64 ", ubuf: %p, "
    635       1.9    pooka 		    "len %zu\n", id, userbuf, reqlen));
    636       1.9    pooka 		simple_lock(&pmp->pmp_lock);
    637       1.9    pooka #endif
    638       1.9    pooka 		TAILQ_FOREACH(park, &pmp->pmp_req_replywait, park_entries) {
    639  1.18.2.1    rmind 			if (park->park_id == id)
    640       1.9    pooka 				break;
    641       1.9    pooka 		}
    642       1.9    pooka 
    643       1.9    pooka 		if (park == NULL) {
    644       1.9    pooka 			error = EINVAL;
    645       1.1    pooka 			break;
    646       1.1    pooka 		}
    647       1.9    pooka 		TAILQ_REMOVE(&pmp->pmp_req_replywait, park, park_entries);
    648  1.18.2.1    rmind 		park->park_flags |= PUFFS_PARKFLAG_RECVREPLY;
    649       1.9    pooka 		simple_unlock(&pmp->pmp_lock);
    650       1.9    pooka 
    651  1.18.2.1    rmind 		/*
    652  1.18.2.1    rmind 		 * If the caller has gone south, go to next, collect
    653  1.18.2.1    rmind 		 * $200 and free the structure there instead of wakeup.
    654  1.18.2.1    rmind 		 * We also need to copyin the
    655  1.18.2.1    rmind 		 */
    656  1.18.2.1    rmind 		if (park->park_flags & PUFFS_PARKFLAG_WAITERGONE) {
    657  1.18.2.1    rmind 			DPRINTF(("puffs_putop: bad service - waiter gone for "
    658  1.18.2.1    rmind 			    "park %p\n", park));
    659  1.18.2.1    rmind 			wgone = 1;
    660  1.18.2.1    rmind 			error = copyin(userbuf, &tmpreq,
    661  1.18.2.1    rmind 			    sizeof(struct puffs_req));
    662  1.18.2.1    rmind 			if (error)
    663  1.18.2.1    rmind 				goto loopout;
    664  1.18.2.1    rmind 			nextpreq = &tmpreq;
    665  1.18.2.1    rmind 			goto next;
    666  1.18.2.1    rmind 		}
    667  1.18.2.1    rmind 
    668  1.18.2.1    rmind 		if (park->park_flags & PUFFS_PARKFLAG_ADJUSTABLE) {
    669       1.9    pooka 			/* sanitycheck size of incoming transmission. */
    670       1.9    pooka 			if (reqlen > pmp->pmp_req_maxsize) {
    671       1.9    pooka 				DPRINTF(("puffsputop: outrageous user buf "
    672       1.9    pooka 				    "size: %zu\n", reqlen));
    673       1.9    pooka 				error = EINVAL;
    674       1.9    pooka 				goto loopout;
    675       1.9    pooka 			}
    676       1.1    pooka 
    677       1.9    pooka 			if (reqlen > park->park_copylen) {
    678       1.9    pooka 				if (reqlen > park->park_maxlen) {
    679       1.9    pooka 					DPRINTF(("puffsputop: adj copysize "
    680       1.9    pooka 					    "> max size, %zu vs %zu\n",
    681       1.9    pooka 					    reqlen, park->park_maxlen));
    682       1.9    pooka 					error = EINVAL;
    683       1.9    pooka 					goto loopout;
    684       1.9    pooka 				}
    685       1.9    pooka 				free(park->park_preq, M_PUFFS);
    686       1.9    pooka 				park->park_preq = malloc(reqlen,
    687       1.9    pooka 				    M_PUFFS, M_WAITOK);
    688       1.9    pooka 
    689       1.9    pooka 				park->park_copylen = reqlen;
    690       1.9    pooka 				DPRINTF(("puffsputop: adjbuf, new addr %p, "
    691       1.9    pooka 				    "len %zu\n", park->park_preq, reqlen));
    692       1.9    pooka 			}
    693       1.9    pooka 		} else {
    694       1.9    pooka 			if (reqlen == 0 || reqlen > park->park_copylen) {
    695       1.9    pooka 				reqlen = park->park_copylen;
    696       1.9    pooka 				DPRINTF(("puffsputop: kernel bufsize override: "
    697       1.9    pooka 				    "%zu\n", reqlen));
    698       1.9    pooka 			}
    699       1.9    pooka 		}
    700       1.1    pooka 
    701       1.9    pooka 		DPRINTF(("puffsputpop: copyin from %p to %p, len %zu\n",
    702       1.9    pooka 		    userbuf, park->park_preq, reqlen));
    703       1.9    pooka 		error = copyin(userbuf, park->park_preq, reqlen);
    704       1.9    pooka 		if (error)
    705       1.9    pooka 			goto loopout;
    706  1.18.2.1    rmind 		nextpreq = park->park_preq;
    707  1.18.2.2     yamt 		bp = park->park_bp;
    708  1.18.2.2     yamt 
    709  1.18.2.2     yamt 		if (park->park_flags & PUFFS_PARKFLAG_ASYNCBIOREAD) {
    710  1.18.2.2     yamt 			struct puffs_vnreq_read *read_argp;
    711  1.18.2.2     yamt 			size_t moved;
    712  1.18.2.2     yamt 
    713  1.18.2.2     yamt 			bp->b_error = park->park_preq->preq_rv;
    714  1.18.2.2     yamt 
    715  1.18.2.2     yamt 			DPRINTF(("puffs_putop: async bioread for park %p, "
    716  1.18.2.2     yamt 			    "bp %p, error %d\n", park, bp, bp->b_error));
    717  1.18.2.2     yamt 
    718  1.18.2.2     yamt 			if (bp->b_error == 0) {
    719  1.18.2.2     yamt 				read_argp = (void *)park->park_preq;
    720  1.18.2.2     yamt 				moved = park->park_maxlen
    721  1.18.2.2     yamt 				    - sizeof(struct puffs_vnreq_read)
    722  1.18.2.2     yamt 				    - read_argp->pvnr_resid;
    723  1.18.2.2     yamt 				memcpy(bp->b_data, read_argp->pvnr_data, moved);
    724  1.18.2.2     yamt 				bp->b_resid = bp->b_bcount - moved;
    725  1.18.2.2     yamt 				biodone(bp);
    726  1.18.2.2     yamt 			}
    727  1.18.2.2     yamt 		}
    728       1.9    pooka 
    729  1.18.2.1    rmind  next:
    730       1.9    pooka 		/* all's well, prepare for next op */
    731  1.18.2.1    rmind 		id = nextpreq->preq_id;
    732  1.18.2.1    rmind 		reqlen = nextpreq->preq_buflen;
    733  1.18.2.1    rmind 		userbuf = nextpreq->preq_nextbuf;
    734       1.9    pooka 		donesome++;
    735       1.9    pooka 
    736       1.9    pooka  loopout:
    737  1.18.2.2     yamt 		if (error && park->park_preq) {
    738       1.9    pooka 			park->park_preq->preq_rv = error;
    739  1.18.2.2     yamt 			if (park->park_flags & PUFFS_PARKFLAG_ASYNCBIOREAD) {
    740  1.18.2.2     yamt 				bp = park->park_bp;
    741  1.18.2.2     yamt 				bp->b_error = error;
    742  1.18.2.2     yamt 				bp->b_flags |= B_ERROR;
    743  1.18.2.2     yamt 				biodone(bp);
    744  1.18.2.2     yamt 			}
    745  1.18.2.2     yamt 		}
    746       1.1    pooka 
    747  1.18.2.1    rmind 		if (wgone) {
    748  1.18.2.1    rmind 			FREE(park, M_PUFFS);
    749  1.18.2.1    rmind 			simple_lock(&pmp->pmp_lock);
    750  1.18.2.2     yamt 		} else if (park->park_flags & PUFFS_PARKFLAG_ASYNCBIOREAD) {
    751  1.18.2.2     yamt 			free(park->park_preq, M_PUFFS);
    752  1.18.2.2     yamt 			FREE(park, M_PUFFS);
    753  1.18.2.2     yamt 			simple_lock(&pmp->pmp_lock);
    754  1.18.2.1    rmind 		} else {
    755  1.18.2.1    rmind 			DPRINTF(("puffs_putop: flagging done for park %p\n",
    756  1.18.2.1    rmind 			    park));
    757  1.18.2.1    rmind 			simple_lock(&pmp->pmp_lock);
    758  1.18.2.1    rmind 			park->park_flags |= PUFFS_PARKFLAG_DONE;
    759  1.18.2.1    rmind 			wakeup(park);
    760  1.18.2.1    rmind 		}
    761  1.18.2.1    rmind 
    762       1.9    pooka 		if (error)
    763       1.9    pooka 			break;
    764  1.18.2.1    rmind 		wgone = 0;
    765       1.1    pooka 	}
    766       1.1    pooka 
    767       1.9    pooka 	simple_unlock(&pmp->pmp_lock);
    768       1.9    pooka 	php->php_nops -= donesome;
    769       1.1    pooka 
    770       1.1    pooka 	return error;
    771       1.1    pooka }
    772       1.1    pooka 
    773       1.1    pooka /* this is probably going to die away at some point? */
    774       1.9    pooka /*
    775       1.9    pooka  * XXX: currently bitrotted
    776       1.9    pooka  */
    777       1.9    pooka #if 0
    778       1.1    pooka static int
    779       1.1    pooka puffssizeop(struct puffs_mount *pmp, struct puffs_sizeop *psop_user)
    780       1.1    pooka {
    781       1.1    pooka 	struct puffs_sizepark *pspark;
    782       1.1    pooka 	void *kernbuf;
    783       1.1    pooka 	size_t copylen;
    784       1.1    pooka 	int error;
    785       1.1    pooka 
    786       1.1    pooka 	/* locate correct op */
    787       1.1    pooka 	simple_lock(&pmp->pmp_lock);
    788       1.1    pooka 	TAILQ_FOREACH(pspark, &pmp->pmp_req_sizepark, pkso_entries) {
    789       1.1    pooka 		if (pspark->pkso_reqid == psop_user->pso_reqid) {
    790       1.1    pooka 			TAILQ_REMOVE(&pmp->pmp_req_sizepark, pspark,
    791       1.1    pooka 			    pkso_entries);
    792       1.1    pooka 			break;
    793       1.1    pooka 		}
    794       1.1    pooka 	}
    795       1.1    pooka 	simple_unlock(&pmp->pmp_lock);
    796       1.1    pooka 
    797       1.1    pooka 	if (pspark == NULL)
    798       1.1    pooka 		return EINVAL;
    799       1.1    pooka 
    800       1.1    pooka 	error = 0;
    801       1.1    pooka 	copylen = MIN(pspark->pkso_bufsize, psop_user->pso_bufsize);
    802       1.1    pooka 
    803       1.1    pooka 	/*
    804       1.1    pooka 	 * XXX: uvm stuff to avoid bouncy-bouncy copying?
    805       1.1    pooka 	 */
    806       1.1    pooka 	if (PUFFS_SIZEOP_UIO(pspark->pkso_reqtype)) {
    807       1.1    pooka 		kernbuf = malloc(copylen, M_PUFFS, M_WAITOK | M_ZERO);
    808       1.1    pooka 		if (pspark->pkso_reqtype == PUFFS_SIZEOPREQ_UIO_IN) {
    809       1.1    pooka 			error = copyin(psop_user->pso_userbuf,
    810       1.1    pooka 			    kernbuf, copylen);
    811       1.1    pooka 			if (error) {
    812       1.1    pooka 				printf("psop ERROR1 %d\n", error);
    813       1.1    pooka 				goto escape;
    814       1.1    pooka 			}
    815       1.1    pooka 		}
    816       1.1    pooka 		error = uiomove(kernbuf, copylen, pspark->pkso_uio);
    817       1.1    pooka 		if (error) {
    818       1.1    pooka 			printf("uiomove from kernel %p, len %d failed: %d\n",
    819       1.1    pooka 			    kernbuf, (int)copylen, error);
    820       1.1    pooka 			goto escape;
    821       1.1    pooka 		}
    822       1.1    pooka 
    823       1.1    pooka 		if (pspark->pkso_reqtype == PUFFS_SIZEOPREQ_UIO_OUT) {
    824       1.1    pooka 			error = copyout(kernbuf,
    825       1.1    pooka 			    psop_user->pso_userbuf, copylen);
    826       1.1    pooka 			if (error) {
    827       1.1    pooka 				printf("psop ERROR2 %d\n", error);
    828       1.1    pooka 				goto escape;
    829       1.1    pooka 			}
    830       1.1    pooka 		}
    831       1.1    pooka  escape:
    832       1.1    pooka 		free(kernbuf, M_PUFFS);
    833       1.1    pooka 	} else if (PUFFS_SIZEOP_BUF(pspark->pkso_reqtype)) {
    834       1.1    pooka 		copylen = MAX(pspark->pkso_bufsize, psop_user->pso_bufsize);
    835       1.1    pooka 		if (pspark->pkso_reqtype == PUFFS_SIZEOPREQ_BUF_IN) {
    836       1.1    pooka 			error = copyin(psop_user->pso_userbuf,
    837       1.1    pooka 			pspark->pkso_copybuf, copylen);
    838       1.1    pooka 		} else {
    839       1.1    pooka 			error = copyout(pspark->pkso_copybuf,
    840       1.1    pooka 			    psop_user->pso_userbuf, copylen);
    841       1.1    pooka 		}
    842       1.1    pooka 	}
    843       1.1    pooka #ifdef DIAGNOSTIC
    844       1.1    pooka 	else
    845       1.1    pooka 		panic("puffssizeop: invalid reqtype %d\n",
    846       1.1    pooka 		    pspark->pkso_reqtype);
    847       1.1    pooka #endif /* DIAGNOSTIC */
    848       1.1    pooka 
    849       1.1    pooka 	return error;
    850       1.1    pooka }
    851       1.9    pooka #endif
    852