puffs_msgif.c revision 1.45 1 1.45 pooka /* $NetBSD: puffs_msgif.c,v 1.45 2007/10/09 15:49:34 pooka Exp $ */
2 1.1 pooka
3 1.1 pooka /*
4 1.16 pooka * Copyright (c) 2005, 2006, 2007 Antti Kantee. All Rights Reserved.
5 1.1 pooka *
6 1.1 pooka * Development of this software was supported by the
7 1.1 pooka * Google Summer of Code program and the Ulla Tuominen Foundation.
8 1.1 pooka * The Google SoC project was mentored by Bill Studenmund.
9 1.1 pooka *
10 1.1 pooka * Redistribution and use in source and binary forms, with or without
11 1.1 pooka * modification, are permitted provided that the following conditions
12 1.1 pooka * are met:
13 1.1 pooka * 1. Redistributions of source code must retain the above copyright
14 1.1 pooka * notice, this list of conditions and the following disclaimer.
15 1.1 pooka * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 pooka * notice, this list of conditions and the following disclaimer in the
17 1.1 pooka * documentation and/or other materials provided with the distribution.
18 1.1 pooka *
19 1.1 pooka * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20 1.1 pooka * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 1.1 pooka * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 1.1 pooka * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 1.1 pooka * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 1.1 pooka * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 1.1 pooka * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 1.1 pooka * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 1.1 pooka * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 1.1 pooka * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1 pooka * SUCH DAMAGE.
30 1.1 pooka */
31 1.1 pooka
32 1.1 pooka #include <sys/cdefs.h>
33 1.45 pooka __KERNEL_RCSID(0, "$NetBSD: puffs_msgif.c,v 1.45 2007/10/09 15:49:34 pooka Exp $");
34 1.1 pooka
35 1.1 pooka #include <sys/param.h>
36 1.16 pooka #include <sys/fstrans.h>
37 1.1 pooka #include <sys/malloc.h>
38 1.1 pooka #include <sys/mount.h>
39 1.1 pooka #include <sys/vnode.h>
40 1.1 pooka #include <sys/lock.h>
41 1.39 ad #include <sys/proc.h>
42 1.1 pooka
43 1.1 pooka #include <fs/puffs/puffs_msgif.h>
44 1.1 pooka #include <fs/puffs/puffs_sys.h>
45 1.1 pooka
46 1.22 pooka /*
47 1.22 pooka * waitq data structures
48 1.22 pooka */
49 1.22 pooka
50 1.22 pooka /*
51 1.22 pooka * While a request is going to userspace, park the caller within the
52 1.22 pooka * kernel. This is the kernel counterpart of "struct puffs_req".
53 1.22 pooka */
54 1.22 pooka struct puffs_park {
55 1.22 pooka struct puffs_req *park_preq; /* req followed by buf */
56 1.22 pooka uint64_t park_id; /* duplicate of preq_id */
57 1.22 pooka
58 1.22 pooka size_t park_copylen; /* userspace copylength */
59 1.22 pooka size_t park_maxlen; /* max size in comeback */
60 1.24 pooka
61 1.24 pooka parkdone_fn park_done;
62 1.24 pooka void *park_donearg;
63 1.22 pooka
64 1.22 pooka int park_flags;
65 1.26 pooka int park_refcount;
66 1.22 pooka
67 1.22 pooka kcondvar_t park_cv;
68 1.26 pooka kmutex_t park_mtx;
69 1.26 pooka
70 1.22 pooka TAILQ_ENTRY(puffs_park) park_entries;
71 1.22 pooka };
72 1.22 pooka #define PARKFLAG_WAITERGONE 0x01
73 1.26 pooka #define PARKFLAG_DONE 0x02
74 1.26 pooka #define PARKFLAG_ONQUEUE1 0x04
75 1.26 pooka #define PARKFLAG_ONQUEUE2 0x08
76 1.26 pooka #define PARKFLAG_CALL 0x10
77 1.31 pooka #define PARKFLAG_WANTREPLY 0x20
78 1.22 pooka
79 1.22 pooka static struct pool_cache parkpc;
80 1.22 pooka static struct pool parkpool;
81 1.22 pooka
82 1.22 pooka static int
83 1.22 pooka makepark(void *arg, void *obj, int flags)
84 1.22 pooka {
85 1.22 pooka struct puffs_park *park = obj;
86 1.22 pooka
87 1.26 pooka mutex_init(&park->park_mtx, MUTEX_DEFAULT, IPL_NONE);
88 1.22 pooka cv_init(&park->park_cv, "puffsrpl");
89 1.22 pooka
90 1.22 pooka return 0;
91 1.22 pooka }
92 1.22 pooka
93 1.22 pooka static void
94 1.22 pooka nukepark(void *arg, void *obj)
95 1.22 pooka {
96 1.22 pooka struct puffs_park *park = obj;
97 1.22 pooka
98 1.22 pooka cv_destroy(&park->park_cv);
99 1.26 pooka mutex_destroy(&park->park_mtx);
100 1.22 pooka }
101 1.22 pooka
102 1.22 pooka void
103 1.22 pooka puffs_msgif_init()
104 1.22 pooka {
105 1.22 pooka
106 1.22 pooka pool_init(&parkpool, sizeof(struct puffs_park), 0, 0, 0,
107 1.22 pooka "puffprkl", &pool_allocator_nointr, IPL_NONE);
108 1.22 pooka pool_cache_init(&parkpc, &parkpool, makepark, nukepark, NULL);
109 1.22 pooka }
110 1.22 pooka
111 1.22 pooka void
112 1.22 pooka puffs_msgif_destroy()
113 1.22 pooka {
114 1.22 pooka
115 1.22 pooka pool_cache_destroy(&parkpc);
116 1.22 pooka pool_destroy(&parkpool);
117 1.22 pooka }
118 1.22 pooka
119 1.22 pooka void *
120 1.26 pooka puffs_park_alloc(int waitok)
121 1.26 pooka {
122 1.26 pooka struct puffs_park *park;
123 1.26 pooka
124 1.26 pooka park = pool_cache_get(&parkpc, waitok ? PR_WAITOK : PR_NOWAIT);
125 1.26 pooka if (park) {
126 1.26 pooka park->park_refcount = 1;
127 1.26 pooka mutex_enter(&park->park_mtx);
128 1.26 pooka }
129 1.26 pooka
130 1.26 pooka return park;
131 1.26 pooka }
132 1.26 pooka
133 1.26 pooka static void
134 1.26 pooka puffs_park_reference(struct puffs_park *park)
135 1.22 pooka {
136 1.22 pooka
137 1.26 pooka mutex_enter(&park->park_mtx);
138 1.26 pooka park->park_refcount++;
139 1.22 pooka }
140 1.22 pooka
141 1.22 pooka void
142 1.26 pooka puffs_park_release(void *arg, int fullnuke)
143 1.22 pooka {
144 1.26 pooka struct puffs_park *park = arg;
145 1.22 pooka
146 1.26 pooka KASSERT(mutex_owned(&park->park_mtx));
147 1.26 pooka --park->park_refcount;
148 1.26 pooka
149 1.26 pooka mutex_exit(&park->park_mtx);
150 1.26 pooka if (park->park_refcount == 0 || fullnuke)
151 1.26 pooka pool_cache_put(&parkpc, park);
152 1.22 pooka }
153 1.22 pooka
154 1.26 pooka #ifdef PUFFSDEBUG
155 1.26 pooka static void
156 1.26 pooka parkdump(struct puffs_park *park)
157 1.26 pooka {
158 1.26 pooka
159 1.26 pooka DPRINTF(("park %p, preq %p, id %" PRIu64 "\n"
160 1.26 pooka "\tcopy %zu, max %zu - done: %p/%p\n"
161 1.26 pooka "\tflags 0x%08x, refcount %d, cv/mtx: %p/%p\n",
162 1.26 pooka park, park->park_preq, park->park_id,
163 1.26 pooka park->park_copylen, park->park_maxlen,
164 1.26 pooka park->park_done, park->park_donearg,
165 1.26 pooka park->park_flags, park->park_refcount,
166 1.26 pooka &park->park_cv, &park->park_mtx));
167 1.26 pooka }
168 1.26 pooka
169 1.26 pooka static void
170 1.26 pooka parkqdump(struct puffs_wq *q, int dumpall)
171 1.26 pooka {
172 1.26 pooka struct puffs_park *park;
173 1.26 pooka int total = 0;
174 1.26 pooka
175 1.26 pooka TAILQ_FOREACH(park, q, park_entries) {
176 1.26 pooka if (dumpall)
177 1.26 pooka parkdump(park);
178 1.26 pooka total++;
179 1.26 pooka }
180 1.29 pooka DPRINTF(("puffs waitqueue at %p dumped, %d total\n", q, total));
181 1.26 pooka
182 1.26 pooka }
183 1.26 pooka #endif /* PUFFSDEBUG */
184 1.22 pooka
185 1.22 pooka /*
186 1.22 pooka * Converts a non-FAF op to a FAF. This simply involves making copies
187 1.22 pooka * of the park and request structures and tagging the request as a FAF.
188 1.22 pooka * It is safe to block here, since the original op is not a FAF.
189 1.22 pooka */
190 1.22 pooka static void
191 1.25 pooka puffs_reqtofaf(struct puffs_park *park)
192 1.22 pooka {
193 1.22 pooka struct puffs_req *newpreq;
194 1.22 pooka
195 1.25 pooka KASSERT((park->park_preq->preq_opclass & PUFFSOPFLAG_FAF) == 0);
196 1.22 pooka
197 1.25 pooka MALLOC(newpreq, struct puffs_req *, park->park_copylen,
198 1.22 pooka M_PUFFS, M_ZERO | M_WAITOK);
199 1.22 pooka
200 1.25 pooka memcpy(newpreq, park->park_preq, park->park_copylen);
201 1.22 pooka
202 1.25 pooka park->park_preq = newpreq;
203 1.25 pooka park->park_preq->preq_opclass |= PUFFSOPFLAG_FAF;
204 1.36 pooka park->park_flags &= ~PARKFLAG_WANTREPLY;
205 1.22 pooka }
206 1.22 pooka
207 1.1 pooka
208 1.1 pooka /*
209 1.1 pooka * kernel-user-kernel waitqueues
210 1.1 pooka */
211 1.1 pooka
212 1.45 pooka static int touser(struct puffs_mount *, struct puffs_park *);
213 1.1 pooka
214 1.4 pooka uint64_t
215 1.1 pooka puffs_getreqid(struct puffs_mount *pmp)
216 1.1 pooka {
217 1.14 pooka uint64_t rv;
218 1.1 pooka
219 1.22 pooka mutex_enter(&pmp->pmp_lock);
220 1.1 pooka rv = pmp->pmp_nextreq++;
221 1.22 pooka mutex_exit(&pmp->pmp_lock);
222 1.1 pooka
223 1.1 pooka return rv;
224 1.1 pooka }
225 1.1 pooka
226 1.1 pooka /* vfs request */
227 1.1 pooka int
228 1.1 pooka puffs_vfstouser(struct puffs_mount *pmp, int optype, void *kbuf, size_t buflen)
229 1.1 pooka {
230 1.25 pooka struct puffs_park *park;
231 1.1 pooka
232 1.26 pooka park = puffs_park_alloc(1);
233 1.25 pooka park->park_preq = kbuf;
234 1.1 pooka
235 1.25 pooka park->park_preq->preq_opclass = PUFFSOP_VFS;
236 1.25 pooka park->park_preq->preq_optype = optype;
237 1.1 pooka
238 1.25 pooka park->park_maxlen = park->park_copylen = buflen;
239 1.25 pooka park->park_flags = 0;
240 1.1 pooka
241 1.45 pooka return touser(pmp, park);
242 1.1 pooka }
243 1.1 pooka
244 1.16 pooka void
245 1.16 pooka puffs_suspendtouser(struct puffs_mount *pmp, int status)
246 1.16 pooka {
247 1.16 pooka struct puffs_vfsreq_suspend *pvfsr_susp;
248 1.25 pooka struct puffs_park *park;
249 1.16 pooka
250 1.16 pooka pvfsr_susp = malloc(sizeof(struct puffs_vfsreq_suspend),
251 1.16 pooka M_PUFFS, M_WAITOK | M_ZERO);
252 1.26 pooka park = puffs_park_alloc(1);
253 1.16 pooka
254 1.16 pooka pvfsr_susp->pvfsr_status = status;
255 1.25 pooka park->park_preq = (struct puffs_req *)pvfsr_susp;
256 1.16 pooka
257 1.25 pooka park->park_preq->preq_opclass = PUFFSOP_VFS | PUFFSOPFLAG_FAF;
258 1.25 pooka park->park_preq->preq_optype = PUFFS_VFS_SUSPEND;
259 1.16 pooka
260 1.25 pooka park->park_maxlen = park->park_copylen
261 1.16 pooka = sizeof(struct puffs_vfsreq_suspend);
262 1.25 pooka park->park_flags = 0;
263 1.16 pooka
264 1.45 pooka (void)touser(pmp, park);
265 1.16 pooka }
266 1.16 pooka
267 1.1 pooka /*
268 1.1 pooka * vnode level request
269 1.1 pooka */
270 1.1 pooka int
271 1.1 pooka puffs_vntouser(struct puffs_mount *pmp, int optype,
272 1.35 pooka void *kbuf, size_t buflen, size_t maxdelta,
273 1.35 pooka struct vnode *vp_opc, struct vnode *vp_aux)
274 1.1 pooka {
275 1.25 pooka struct puffs_park *park;
276 1.35 pooka struct puffs_req *preq;
277 1.35 pooka void *cookie = VPTOPNC(vp_opc);
278 1.35 pooka struct puffs_node *pnode;
279 1.35 pooka int rv;
280 1.1 pooka
281 1.26 pooka park = puffs_park_alloc(1);
282 1.25 pooka park->park_preq = kbuf;
283 1.9 pooka
284 1.25 pooka park->park_preq->preq_opclass = PUFFSOP_VN;
285 1.25 pooka park->park_preq->preq_optype = optype;
286 1.25 pooka park->park_preq->preq_cookie = cookie;
287 1.25 pooka
288 1.25 pooka park->park_copylen = buflen;
289 1.25 pooka park->park_maxlen = buflen + maxdelta;
290 1.25 pooka park->park_flags = 0;
291 1.1 pooka
292 1.45 pooka rv = touser(pmp, park);
293 1.35 pooka
294 1.35 pooka /*
295 1.35 pooka * Check if the user server requests that inactive be called
296 1.35 pooka * when the time is right.
297 1.35 pooka */
298 1.35 pooka preq = park->park_preq;
299 1.35 pooka if (preq->preq_setbacks & PUFFS_SETBACK_INACT_N1) {
300 1.35 pooka pnode = vp_opc->v_data;
301 1.35 pooka pnode->pn_stat |= PNODE_DOINACT;
302 1.35 pooka }
303 1.35 pooka if (preq->preq_setbacks & PUFFS_SETBACK_INACT_N2) {
304 1.35 pooka /* if no vp_aux, just ignore */
305 1.35 pooka if (vp_aux) {
306 1.35 pooka pnode = vp_aux->v_data;
307 1.35 pooka pnode->pn_stat |= PNODE_DOINACT;
308 1.35 pooka }
309 1.35 pooka }
310 1.37 pooka if (preq->preq_setbacks & PUFFS_SETBACK_NOREF_N1) {
311 1.37 pooka pnode = vp_opc->v_data;
312 1.37 pooka pnode->pn_stat |= PNODE_NOREFS;
313 1.37 pooka }
314 1.37 pooka if (preq->preq_setbacks & PUFFS_SETBACK_NOREF_N2) {
315 1.37 pooka /* if no vp_aux, just ignore */
316 1.37 pooka if (vp_aux) {
317 1.37 pooka pnode = vp_aux->v_data;
318 1.37 pooka pnode->pn_stat |= PNODE_NOREFS;
319 1.37 pooka }
320 1.37 pooka }
321 1.35 pooka
322 1.35 pooka return rv;
323 1.1 pooka }
324 1.1 pooka
325 1.43 pooka int
326 1.43 pooka puffs_cookietouser(struct puffs_mount *pmp, int optype,
327 1.43 pooka void *kbuf, size_t buflen, void *cookie, int faf)
328 1.43 pooka {
329 1.43 pooka struct puffs_park *park;
330 1.43 pooka
331 1.43 pooka park = puffs_park_alloc(1);
332 1.43 pooka park->park_preq = kbuf;
333 1.43 pooka
334 1.43 pooka park->park_preq->preq_opclass = PUFFSOP_VN |(faf ? PUFFSOPFLAG_FAF : 0);
335 1.43 pooka park->park_preq->preq_optype = optype;
336 1.43 pooka park->park_preq->preq_cookie = cookie;
337 1.43 pooka
338 1.43 pooka park->park_copylen = park->park_maxlen = buflen;
339 1.43 pooka park->park_flags = 0;
340 1.43 pooka
341 1.45 pooka return touser(pmp, park);
342 1.1 pooka }
343 1.1 pooka
344 1.24 pooka void
345 1.24 pooka puffs_vntouser_call(struct puffs_mount *pmp, int optype,
346 1.35 pooka void *kbuf, size_t buflen, size_t maxdelta,
347 1.24 pooka parkdone_fn donefn, void *donearg,
348 1.35 pooka struct vnode *vp_opc, struct vnode *vp_aux)
349 1.1 pooka {
350 1.25 pooka struct puffs_park *park;
351 1.35 pooka void *cookie = VPTOPNC(vp_opc);
352 1.1 pooka
353 1.26 pooka park = puffs_park_alloc(1);
354 1.25 pooka park->park_preq = kbuf;
355 1.1 pooka
356 1.25 pooka park->park_preq->preq_opclass = PUFFSOP_VN;
357 1.25 pooka park->park_preq->preq_optype = optype;
358 1.25 pooka park->park_preq->preq_cookie = cookie;
359 1.25 pooka
360 1.25 pooka park->park_copylen = buflen;
361 1.25 pooka park->park_maxlen = buflen + maxdelta;
362 1.25 pooka park->park_done = donefn;
363 1.25 pooka park->park_donearg = donearg;
364 1.25 pooka park->park_flags = PARKFLAG_CALL;
365 1.1 pooka
366 1.45 pooka (void) touser(pmp, park);
367 1.20 pooka }
368 1.20 pooka
369 1.20 pooka /*
370 1.4 pooka * Notice: kbuf will be free'd later. I must be allocated from the
371 1.4 pooka * kernel heap and it's ownership is shifted to this function from
372 1.4 pooka * now on, i.e. the caller is not allowed to use it anymore!
373 1.4 pooka */
374 1.4 pooka void
375 1.4 pooka puffs_vntouser_faf(struct puffs_mount *pmp, int optype,
376 1.35 pooka void *kbuf, size_t buflen, struct vnode *vp_opc)
377 1.4 pooka {
378 1.25 pooka struct puffs_park *park;
379 1.35 pooka void *cookie = VPTOPNC(vp_opc);
380 1.4 pooka
381 1.4 pooka /* XXX: is it allowable to sleep here? */
382 1.26 pooka park = puffs_park_alloc(0);
383 1.25 pooka if (park == NULL)
384 1.4 pooka return; /* 2bad */
385 1.4 pooka
386 1.25 pooka park->park_preq = kbuf;
387 1.9 pooka
388 1.25 pooka park->park_preq->preq_opclass = PUFFSOP_VN | PUFFSOPFLAG_FAF;
389 1.25 pooka park->park_preq->preq_optype = optype;
390 1.25 pooka park->park_preq->preq_cookie = cookie;
391 1.9 pooka
392 1.25 pooka park->park_maxlen = park->park_copylen = buflen;
393 1.25 pooka park->park_flags = 0;
394 1.4 pooka
395 1.45 pooka (void)touser(pmp, park);
396 1.4 pooka }
397 1.4 pooka
398 1.21 pooka void
399 1.25 pooka puffs_cacheop(struct puffs_mount *pmp, struct puffs_park *park,
400 1.21 pooka struct puffs_cacheinfo *pcinfo, size_t pcilen, void *cookie)
401 1.21 pooka {
402 1.21 pooka
403 1.25 pooka park->park_preq = (struct puffs_req *)pcinfo;
404 1.25 pooka park->park_preq->preq_opclass = PUFFSOP_CACHE | PUFFSOPFLAG_FAF;
405 1.25 pooka park->park_preq->preq_optype = PCACHE_TYPE_WRITE; /* XXX */
406 1.25 pooka park->park_preq->preq_cookie = cookie;
407 1.21 pooka
408 1.25 pooka park->park_maxlen = park->park_copylen = pcilen;
409 1.26 pooka park->park_flags = 0;
410 1.21 pooka
411 1.45 pooka (void)touser(pmp, park);
412 1.21 pooka }
413 1.21 pooka
414 1.41 pooka void
415 1.42 pooka puffs_errnotify(struct puffs_mount *pmp, uint8_t type, int error,
416 1.42 pooka const char *str, void *cookie)
417 1.41 pooka {
418 1.41 pooka struct puffs_park *park;
419 1.41 pooka struct puffs_error *perr;
420 1.41 pooka
421 1.41 pooka park = puffs_park_alloc(1);
422 1.41 pooka MALLOC(perr, struct puffs_error *, sizeof(struct puffs_error),
423 1.41 pooka M_PUFFS, M_ZERO | M_WAITOK);
424 1.41 pooka
425 1.41 pooka perr->perr_error = error;
426 1.42 pooka strlcpy(perr->perr_str, str, sizeof(perr->perr_str));
427 1.41 pooka
428 1.41 pooka park->park_preq = (struct puffs_req *)perr;
429 1.41 pooka park->park_preq->preq_opclass = PUFFSOP_ERROR | PUFFSOPFLAG_FAF;
430 1.41 pooka park->park_preq->preq_optype = type;
431 1.41 pooka park->park_preq->preq_cookie = cookie;
432 1.41 pooka
433 1.41 pooka park->park_maxlen = park->park_copylen = sizeof(struct puffs_error);
434 1.41 pooka park->park_flags = 0;
435 1.41 pooka
436 1.45 pooka (void)touser(pmp, park);
437 1.41 pooka }
438 1.41 pooka
439 1.4 pooka /*
440 1.1 pooka * Wait for the userspace ping-pong game in calling process context.
441 1.1 pooka *
442 1.1 pooka * This unlocks vnodes if they are supplied. vp1 is the vnode
443 1.1 pooka * before in the locking order, i.e. the one which must be locked
444 1.1 pooka * before accessing vp2. This is done here so that operations are
445 1.1 pooka * already ordered in the queue when vnodes are unlocked (I'm not
446 1.1 pooka * sure if that's really necessary, but it can't hurt). Okok, maybe
447 1.1 pooka * there's a slight ugly-factor also, but let's not worry about that.
448 1.1 pooka */
449 1.1 pooka static int
450 1.45 pooka touser(struct puffs_mount *pmp, struct puffs_park *park)
451 1.1 pooka {
452 1.26 pooka struct lwp *l = curlwp;
453 1.16 pooka struct mount *mp;
454 1.9 pooka struct puffs_req *preq;
455 1.19 pooka int rv = 0;
456 1.1 pooka
457 1.16 pooka mp = PMPTOMP(pmp);
458 1.25 pooka preq = park->park_preq;
459 1.25 pooka preq->preq_buflen = ALIGN(park->park_maxlen);
460 1.45 pooka KASSERT(preq->preq_id == 0);
461 1.45 pooka if (PUFFSOP_WANTREPLY(preq->preq_opclass)) {
462 1.31 pooka park->park_flags |= PARKFLAG_WANTREPLY;
463 1.45 pooka preq->preq_id = park->park_id = puffs_getreqid(pmp);
464 1.45 pooka }
465 1.31 pooka
466 1.19 pooka /*
467 1.19 pooka * To support PCATCH, yet another movie: check if there are signals
468 1.19 pooka * pending and we are issueing a non-FAF. If so, return an error
469 1.19 pooka * directly UNLESS we are issueing INACTIVE. In that case, convert
470 1.19 pooka * it to a FAF, fire off to the file server and return an error.
471 1.19 pooka * Yes, this is bordering disgusting. Barfbags are on me.
472 1.19 pooka */
473 1.31 pooka if ((park->park_flags & PARKFLAG_WANTREPLY)
474 1.25 pooka && (park->park_flags & PARKFLAG_CALL) == 0
475 1.19 pooka && (l->l_flag & LW_PENDSIG) != 0 && sigispending(l, 0)) {
476 1.19 pooka if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN
477 1.19 pooka && preq->preq_optype == PUFFS_VN_INACTIVE) {
478 1.25 pooka puffs_reqtofaf(park);
479 1.25 pooka DPRINTF(("puffs touser: converted to FAF %p\n", park));
480 1.19 pooka rv = EINTR;
481 1.19 pooka } else {
482 1.26 pooka puffs_park_release(park, 0);
483 1.19 pooka return EINTR;
484 1.19 pooka }
485 1.19 pooka }
486 1.16 pooka
487 1.16 pooka /*
488 1.16 pooka * test for suspension lock.
489 1.16 pooka *
490 1.16 pooka * Note that we *DO NOT* keep the lock, since that might block
491 1.16 pooka * lock acquiring PLUS it would give userlandia control over
492 1.16 pooka * the lock. The operation queue enforces a strict ordering:
493 1.16 pooka * when the fs server gets in the op stream, it knows things
494 1.16 pooka * are in order. The kernel locks can't guarantee that for
495 1.16 pooka * userspace, in any case.
496 1.16 pooka *
497 1.16 pooka * BUT: this presents a problem for ops which have a consistency
498 1.16 pooka * clause based on more than one operation. Unfortunately such
499 1.16 pooka * operations (read, write) do not reliably work yet.
500 1.16 pooka *
501 1.16 pooka * Ya, Ya, it's wrong wong wrong, me be fixink this someday.
502 1.18 pooka *
503 1.18 pooka * XXX: and there is one more problem. We sometimes need to
504 1.18 pooka * take a lazy lock in case the fs is suspending and we are
505 1.18 pooka * executing as the fs server context. This might happen
506 1.18 pooka * e.g. in the case that the user server triggers a reclaim
507 1.18 pooka * in the kernel while the fs is suspending. It's not a very
508 1.18 pooka * likely event, but it needs to be fixed some day.
509 1.16 pooka */
510 1.22 pooka
511 1.22 pooka /*
512 1.22 pooka * MOREXXX: once PUFFS_WCACHEINFO is enabled, we can't take
513 1.22 pooka * the mutex here, since getpages() might be called locked.
514 1.22 pooka */
515 1.18 pooka fstrans_start(mp, FSTRANS_NORMAL);
516 1.22 pooka mutex_enter(&pmp->pmp_lock);
517 1.16 pooka fstrans_done(mp);
518 1.16 pooka
519 1.13 pooka if (pmp->pmp_status != PUFFSTAT_RUNNING) {
520 1.22 pooka mutex_exit(&pmp->pmp_lock);
521 1.26 pooka puffs_park_release(park, 0);
522 1.1 pooka return ENXIO;
523 1.1 pooka }
524 1.1 pooka
525 1.26 pooka #ifdef PUFFSDEBUG
526 1.26 pooka parkqdump(&pmp->pmp_req_touser, puffsdebug > 1);
527 1.26 pooka parkqdump(&pmp->pmp_req_replywait, puffsdebug > 1);
528 1.26 pooka #endif
529 1.26 pooka
530 1.25 pooka TAILQ_INSERT_TAIL(&pmp->pmp_req_touser, park, park_entries);
531 1.26 pooka park->park_flags |= PARKFLAG_ONQUEUE1;
532 1.34 pooka puffs_mp_reference(pmp);
533 1.34 pooka pmp->pmp_req_touser_count++;
534 1.26 pooka mutex_exit(&pmp->pmp_lock);
535 1.1 pooka
536 1.20 pooka DPRINTF(("touser: req %" PRIu64 ", preq: %p, park: %p, "
537 1.25 pooka "c/t: 0x%x/0x%x, f: 0x%x\n", preq->preq_id, preq, park,
538 1.25 pooka preq->preq_opclass, preq->preq_optype, park->park_flags));
539 1.15 pooka
540 1.22 pooka cv_broadcast(&pmp->pmp_req_waiter_cv);
541 1.1 pooka selnotify(pmp->pmp_sel, 0);
542 1.1 pooka
543 1.31 pooka if ((park->park_flags & PARKFLAG_WANTREPLY)
544 1.25 pooka && (park->park_flags & PARKFLAG_CALL) == 0) {
545 1.19 pooka int error;
546 1.19 pooka
547 1.26 pooka error = cv_wait_sig(&park->park_cv, &park->park_mtx);
548 1.19 pooka if (error) {
549 1.25 pooka park->park_flags |= PARKFLAG_WAITERGONE;
550 1.26 pooka if (park->park_flags & PARKFLAG_DONE) {
551 1.22 pooka rv = preq->preq_rv;
552 1.26 pooka puffs_park_release(park, 0);
553 1.19 pooka } else {
554 1.26 pooka /*
555 1.26 pooka * ok, we marked it as going away, but
556 1.26 pooka * still need to do queue ops. take locks
557 1.26 pooka * in correct order.
558 1.26 pooka *
559 1.26 pooka * We don't want to release our reference
560 1.26 pooka * if it's on replywait queue to avoid error
561 1.26 pooka * to file server. putop() code will DTRT.
562 1.26 pooka */
563 1.26 pooka KASSERT(park->park_flags &
564 1.26 pooka (PARKFLAG_ONQUEUE1 | PARKFLAG_ONQUEUE2));
565 1.26 pooka mutex_exit(&park->park_mtx);
566 1.26 pooka
567 1.26 pooka mutex_enter(&pmp->pmp_lock);
568 1.26 pooka mutex_enter(&park->park_mtx);
569 1.36 pooka if (park->park_flags & PARKFLAG_ONQUEUE1) {
570 1.26 pooka TAILQ_REMOVE(&pmp->pmp_req_touser,
571 1.26 pooka park, park_entries);
572 1.36 pooka pmp->pmp_req_touser_count--;
573 1.36 pooka park->park_flags &= ~PARKFLAG_ONQUEUE1;
574 1.36 pooka }
575 1.26 pooka if ((park->park_flags & PARKFLAG_ONQUEUE2) == 0)
576 1.26 pooka puffs_park_release(park, 0);
577 1.26 pooka else
578 1.26 pooka mutex_exit(&park->park_mtx);
579 1.26 pooka mutex_exit(&pmp->pmp_lock);
580 1.26 pooka
581 1.22 pooka rv = error;
582 1.19 pooka }
583 1.22 pooka } else {
584 1.22 pooka rv = preq->preq_rv;
585 1.26 pooka puffs_park_release(park, 0);
586 1.19 pooka }
587 1.22 pooka
588 1.16 pooka /*
589 1.16 pooka * retake the lock and release. This makes sure (haha,
590 1.16 pooka * I'm humorous) that we don't process the same vnode in
591 1.16 pooka * multiple threads due to the locks hacks we have in
592 1.16 pooka * puffs_lock(). In reality this is well protected by
593 1.16 pooka * the biglock, but once that's gone, well, hopefully
594 1.16 pooka * this will be fixed for real. (and when you read this
595 1.16 pooka * comment in 2017 and subsequently barf, my condolences ;).
596 1.16 pooka */
597 1.19 pooka if (rv == 0 && !fstrans_is_owner(mp)) {
598 1.17 hannken fstrans_start(mp, FSTRANS_NORMAL);
599 1.16 pooka fstrans_done(mp);
600 1.16 pooka }
601 1.22 pooka } else {
602 1.26 pooka mutex_exit(&park->park_mtx);
603 1.16 pooka }
604 1.16 pooka
605 1.22 pooka mutex_enter(&pmp->pmp_lock);
606 1.34 pooka puffs_mp_release(pmp);
607 1.22 pooka mutex_exit(&pmp->pmp_lock);
608 1.16 pooka
609 1.19 pooka return rv;
610 1.1 pooka }
611 1.1 pooka
612 1.1 pooka
613 1.9 pooka /*
614 1.9 pooka * getop: scan through queued requests until:
615 1.9 pooka * 1) max number of requests satisfied
616 1.9 pooka * OR
617 1.9 pooka * 2) buffer runs out of space
618 1.9 pooka * OR
619 1.9 pooka * 3) nonblocking is set AND there are no operations available
620 1.9 pooka * OR
621 1.9 pooka * 4) at least one operation was transferred AND there are no more waiting
622 1.9 pooka */
623 1.10 pooka int
624 1.10 pooka puffs_getop(struct puffs_mount *pmp, struct puffs_reqh_get *phg, int nonblock)
625 1.1 pooka {
626 1.1 pooka struct puffs_park *park;
627 1.9 pooka struct puffs_req *preq;
628 1.9 pooka uint8_t *bufpos;
629 1.9 pooka int error, donesome;
630 1.9 pooka
631 1.9 pooka donesome = error = 0;
632 1.9 pooka bufpos = phg->phg_buf;
633 1.1 pooka
634 1.22 pooka mutex_enter(&pmp->pmp_lock);
635 1.9 pooka while (phg->phg_nops == 0 || donesome != phg->phg_nops) {
636 1.1 pooka again:
637 1.9 pooka if (pmp->pmp_status != PUFFSTAT_RUNNING) {
638 1.9 pooka /* if we got some, they don't really matter anymore */
639 1.9 pooka error = ENXIO;
640 1.9 pooka goto out;
641 1.9 pooka }
642 1.9 pooka if (TAILQ_EMPTY(&pmp->pmp_req_touser)) {
643 1.12 pooka if (donesome)
644 1.12 pooka goto out;
645 1.12 pooka
646 1.12 pooka if (nonblock) {
647 1.12 pooka error = EWOULDBLOCK;
648 1.9 pooka goto out;
649 1.9 pooka }
650 1.9 pooka
651 1.22 pooka error = cv_wait_sig(&pmp->pmp_req_waiter_cv,
652 1.22 pooka &pmp->pmp_lock);
653 1.11 pooka if (error)
654 1.11 pooka goto out;
655 1.11 pooka else
656 1.11 pooka goto again;
657 1.9 pooka }
658 1.9 pooka
659 1.9 pooka park = TAILQ_FIRST(&pmp->pmp_req_touser);
660 1.26 pooka puffs_park_reference(park);
661 1.22 pooka
662 1.22 pooka /* If it's a goner, don't process any furher */
663 1.22 pooka if (park->park_flags & PARKFLAG_WAITERGONE) {
664 1.26 pooka puffs_park_release(park, 0);
665 1.22 pooka continue;
666 1.22 pooka }
667 1.22 pooka
668 1.26 pooka preq = park->park_preq;
669 1.26 pooka if (phg->phg_buflen < preq->preq_buflen) {
670 1.26 pooka if (!donesome)
671 1.26 pooka error = E2BIG;
672 1.26 pooka puffs_park_release(park, 0);
673 1.26 pooka goto out;
674 1.26 pooka }
675 1.28 pooka
676 1.28 pooka TAILQ_REMOVE(&pmp->pmp_req_touser, park, park_entries);
677 1.28 pooka KASSERT(park->park_flags & PARKFLAG_ONQUEUE1);
678 1.28 pooka park->park_flags &= ~PARKFLAG_ONQUEUE1;
679 1.34 pooka pmp->pmp_req_touser_count--;
680 1.34 pooka KASSERT(pmp->pmp_req_touser_count >= 0);
681 1.27 pooka mutex_exit(&pmp->pmp_lock);
682 1.26 pooka
683 1.9 pooka DPRINTF(("puffsgetop: get op %" PRIu64 " (%d.), from %p "
684 1.9 pooka "len %zu (buflen %zu), target %p\n", preq->preq_id,
685 1.9 pooka donesome, preq, park->park_copylen, preq->preq_buflen,
686 1.9 pooka bufpos));
687 1.9 pooka
688 1.9 pooka if ((error = copyout(preq, bufpos, park->park_copylen)) != 0) {
689 1.26 pooka DPRINTF(("puffs_getop: copyout failed: %d\n", error));
690 1.9 pooka /*
691 1.9 pooka * ok, user server is probably trying to cheat.
692 1.26 pooka * stuff op back & return error to user. We need
693 1.26 pooka * to take locks in the correct order.
694 1.9 pooka */
695 1.26 pooka mutex_exit(&park->park_mtx);
696 1.33 pooka
697 1.33 pooka /*
698 1.33 pooka * XXX: ONQUEUE1 | ONQUEUE2 invariant doesn't
699 1.33 pooka * hold here
700 1.33 pooka */
701 1.33 pooka
702 1.26 pooka mutex_enter(&pmp->pmp_lock);
703 1.26 pooka mutex_enter(&park->park_mtx);
704 1.26 pooka if ((park->park_flags & PARKFLAG_WAITERGONE) == 0) {
705 1.26 pooka TAILQ_INSERT_HEAD(&pmp->pmp_req_touser, park,
706 1.26 pooka park_entries);
707 1.26 pooka park->park_flags |= PARKFLAG_ONQUEUE1;
708 1.34 pooka pmp->pmp_req_touser_count++;
709 1.26 pooka }
710 1.9 pooka
711 1.26 pooka if (donesome)
712 1.9 pooka error = 0;
713 1.26 pooka puffs_park_release(park, 0);
714 1.26 pooka goto out;
715 1.9 pooka }
716 1.9 pooka bufpos += preq->preq_buflen;
717 1.9 pooka phg->phg_buflen -= preq->preq_buflen;
718 1.9 pooka donesome++;
719 1.9 pooka
720 1.32 pooka /* XXXfixme: taking this lock in the wrong order */
721 1.22 pooka mutex_enter(&pmp->pmp_lock);
722 1.32 pooka
723 1.31 pooka if (park->park_flags & PARKFLAG_WANTREPLY) {
724 1.22 pooka TAILQ_INSERT_TAIL(&pmp->pmp_req_replywait, park,
725 1.22 pooka park_entries);
726 1.26 pooka park->park_flags |= PARKFLAG_ONQUEUE2;
727 1.26 pooka puffs_park_release(park, 0);
728 1.9 pooka } else {
729 1.9 pooka free(preq, M_PUFFS);
730 1.26 pooka puffs_park_release(park, 1);
731 1.1 pooka }
732 1.1 pooka }
733 1.1 pooka
734 1.9 pooka out:
735 1.34 pooka phg->phg_more = pmp->pmp_req_touser_count;
736 1.22 pooka mutex_exit(&pmp->pmp_lock);
737 1.1 pooka
738 1.9 pooka phg->phg_nops = donesome;
739 1.4 pooka
740 1.9 pooka return error;
741 1.1 pooka }
742 1.1 pooka
743 1.10 pooka int
744 1.10 pooka puffs_putop(struct puffs_mount *pmp, struct puffs_reqh_put *php)
745 1.1 pooka {
746 1.1 pooka struct puffs_park *park;
747 1.19 pooka struct puffs_req tmpreq;
748 1.19 pooka struct puffs_req *nextpreq;
749 1.9 pooka void *userbuf;
750 1.9 pooka uint64_t id;
751 1.9 pooka size_t reqlen;
752 1.26 pooka int donesome, error, wgone, release;
753 1.9 pooka
754 1.19 pooka donesome = error = wgone = 0;
755 1.9 pooka
756 1.9 pooka id = php->php_id;
757 1.9 pooka userbuf = php->php_buf;
758 1.9 pooka reqlen = php->php_buflen;
759 1.1 pooka
760 1.22 pooka mutex_enter(&pmp->pmp_lock);
761 1.9 pooka while (donesome != php->php_nops) {
762 1.26 pooka release = 0;
763 1.19 pooka #ifdef PUFFSDEBUG
764 1.9 pooka DPRINTF(("puffsputop: searching for %" PRIu64 ", ubuf: %p, "
765 1.9 pooka "len %zu\n", id, userbuf, reqlen));
766 1.9 pooka #endif
767 1.9 pooka TAILQ_FOREACH(park, &pmp->pmp_req_replywait, park_entries) {
768 1.19 pooka if (park->park_id == id)
769 1.9 pooka break;
770 1.9 pooka }
771 1.9 pooka
772 1.9 pooka if (park == NULL) {
773 1.24 pooka DPRINTF(("puffsputop: no request: %" PRIu64 "\n", id));
774 1.9 pooka error = EINVAL;
775 1.1 pooka break;
776 1.1 pooka }
777 1.24 pooka
778 1.26 pooka puffs_park_reference(park);
779 1.24 pooka if (reqlen == 0 || reqlen > park->park_maxlen) {
780 1.24 pooka DPRINTF(("puffsputop: invalid buffer length: "
781 1.24 pooka "%zu\n", reqlen));
782 1.24 pooka error = E2BIG;
783 1.26 pooka puffs_park_release(park, 0);
784 1.24 pooka break;
785 1.24 pooka }
786 1.22 pooka wgone = park->park_flags & PARKFLAG_WAITERGONE;
787 1.26 pooka
788 1.26 pooka /* check if it's still on the queue after acquiring lock */
789 1.26 pooka if (park->park_flags & PARKFLAG_ONQUEUE2) {
790 1.26 pooka TAILQ_REMOVE(&pmp->pmp_req_replywait, park,
791 1.26 pooka park_entries);
792 1.26 pooka park->park_flags &= ~PARKFLAG_ONQUEUE2;
793 1.26 pooka }
794 1.26 pooka
795 1.22 pooka mutex_exit(&pmp->pmp_lock);
796 1.9 pooka
797 1.19 pooka /*
798 1.19 pooka * If the caller has gone south, go to next, collect
799 1.19 pooka * $200 and free the structure there instead of wakeup.
800 1.26 pooka * We also need to copyin the header info. Flag structure
801 1.26 pooka * release to mode total and utter destruction.
802 1.19 pooka */
803 1.22 pooka if (wgone) {
804 1.19 pooka DPRINTF(("puffs_putop: bad service - waiter gone for "
805 1.19 pooka "park %p\n", park));
806 1.19 pooka error = copyin(userbuf, &tmpreq,
807 1.19 pooka sizeof(struct puffs_req));
808 1.26 pooka release = 1;
809 1.19 pooka if (error)
810 1.19 pooka goto loopout;
811 1.19 pooka nextpreq = &tmpreq;
812 1.19 pooka goto next;
813 1.19 pooka }
814 1.19 pooka
815 1.9 pooka DPRINTF(("puffsputpop: copyin from %p to %p, len %zu\n",
816 1.9 pooka userbuf, park->park_preq, reqlen));
817 1.9 pooka error = copyin(userbuf, park->park_preq, reqlen);
818 1.9 pooka if (error)
819 1.9 pooka goto loopout;
820 1.19 pooka nextpreq = park->park_preq;
821 1.9 pooka
822 1.19 pooka next:
823 1.9 pooka /* all's well, prepare for next op */
824 1.19 pooka id = nextpreq->preq_id;
825 1.19 pooka reqlen = nextpreq->preq_buflen;
826 1.19 pooka userbuf = nextpreq->preq_nextbuf;
827 1.9 pooka donesome++;
828 1.9 pooka
829 1.9 pooka loopout:
830 1.31 pooka if (error && !wgone)
831 1.9 pooka park->park_preq->preq_rv = error;
832 1.24 pooka
833 1.24 pooka if (park->park_flags & PARKFLAG_CALL) {
834 1.40 pooka DPRINTF(("puffsputopt: call for %p, arg %p\n",
835 1.40 pooka park->park_preq, park->park_donearg));
836 1.42 pooka park->park_done(pmp,park->park_preq,park->park_donearg);
837 1.26 pooka release = 1;
838 1.20 pooka }
839 1.1 pooka
840 1.22 pooka if (!wgone) {
841 1.24 pooka DPRINTF(("puffs_putop: flagging done for "
842 1.24 pooka "park %p\n", park));
843 1.22 pooka
844 1.24 pooka cv_signal(&park->park_cv);
845 1.19 pooka }
846 1.33 pooka park->park_flags |= PARKFLAG_DONE;
847 1.26 pooka puffs_park_release(park, release);
848 1.19 pooka
849 1.26 pooka mutex_enter(&pmp->pmp_lock);
850 1.9 pooka if (error)
851 1.9 pooka break;
852 1.19 pooka wgone = 0;
853 1.1 pooka }
854 1.1 pooka
855 1.22 pooka mutex_exit(&pmp->pmp_lock);
856 1.9 pooka php->php_nops -= donesome;
857 1.1 pooka
858 1.1 pooka return error;
859 1.1 pooka }
860 1.1 pooka
861 1.22 pooka /*
862 1.22 pooka * We're dead, kaput, RIP, slightly more than merely pining for the
863 1.22 pooka * fjords, belly-up, fallen, lifeless, finished, expired, gone to meet
864 1.22 pooka * our maker, ceased to be, etcetc. YASD. It's a dead FS!
865 1.22 pooka *
866 1.22 pooka * Caller must hold puffs mutex.
867 1.22 pooka */
868 1.22 pooka void
869 1.22 pooka puffs_userdead(struct puffs_mount *pmp)
870 1.22 pooka {
871 1.32 pooka struct puffs_park *park, *park_next;
872 1.22 pooka
873 1.22 pooka /*
874 1.22 pooka * Mark filesystem status as dying so that operations don't
875 1.22 pooka * attempt to march to userspace any longer.
876 1.22 pooka */
877 1.22 pooka pmp->pmp_status = PUFFSTAT_DYING;
878 1.22 pooka
879 1.22 pooka /* signal waiters on REQUEST TO file server queue */
880 1.32 pooka for (park = TAILQ_FIRST(&pmp->pmp_req_touser); park; park = park_next) {
881 1.24 pooka uint8_t opclass;
882 1.24 pooka
883 1.26 pooka puffs_park_reference(park);
884 1.32 pooka park_next = TAILQ_NEXT(park, park_entries);
885 1.26 pooka
886 1.26 pooka KASSERT(park->park_flags & PARKFLAG_ONQUEUE1);
887 1.22 pooka TAILQ_REMOVE(&pmp->pmp_req_touser, park, park_entries);
888 1.26 pooka park->park_flags &= ~PARKFLAG_ONQUEUE1;
889 1.34 pooka pmp->pmp_req_touser_count--;
890 1.22 pooka
891 1.31 pooka /*
892 1.31 pooka * If the waiter is gone, we may *NOT* access preq anymore.
893 1.31 pooka */
894 1.31 pooka if (park->park_flags & PARKFLAG_WAITERGONE) {
895 1.31 pooka KASSERT((park->park_flags & PARKFLAG_CALL) == 0);
896 1.31 pooka KASSERT(park->park_flags & PARKFLAG_WANTREPLY);
897 1.31 pooka puffs_park_release(park, 0);
898 1.22 pooka } else {
899 1.31 pooka opclass = park->park_preq->preq_opclass;
900 1.23 pooka park->park_preq->preq_rv = ENXIO;
901 1.31 pooka
902 1.31 pooka if (park->park_flags & PARKFLAG_CALL) {
903 1.42 pooka park->park_done(pmp, park->park_preq,
904 1.31 pooka park->park_donearg);
905 1.31 pooka puffs_park_release(park, 1);
906 1.31 pooka } else if ((park->park_flags & PARKFLAG_WANTREPLY)==0) {
907 1.31 pooka free(park->park_preq, M_PUFFS);
908 1.31 pooka puffs_park_release(park, 1);
909 1.31 pooka } else {
910 1.31 pooka park->park_preq->preq_rv = ENXIO;
911 1.31 pooka cv_signal(&park->park_cv);
912 1.31 pooka puffs_park_release(park, 0);
913 1.31 pooka }
914 1.22 pooka }
915 1.22 pooka }
916 1.22 pooka
917 1.22 pooka /* signal waiters on RESPONSE FROM file server queue */
918 1.32 pooka for (park=TAILQ_FIRST(&pmp->pmp_req_replywait); park; park=park_next) {
919 1.26 pooka puffs_park_reference(park);
920 1.32 pooka park_next = TAILQ_NEXT(park, park_entries);
921 1.26 pooka
922 1.26 pooka KASSERT(park->park_flags & PARKFLAG_ONQUEUE2);
923 1.31 pooka KASSERT(park->park_flags & PARKFLAG_WANTREPLY);
924 1.26 pooka
925 1.23 pooka TAILQ_REMOVE(&pmp->pmp_req_replywait, park, park_entries);
926 1.26 pooka park->park_flags &= ~PARKFLAG_ONQUEUE2;
927 1.26 pooka
928 1.31 pooka /*
929 1.31 pooka * If the waiter is gone, we may *NOT* access preq anymore.
930 1.31 pooka */
931 1.31 pooka if (park->park_flags & PARKFLAG_WAITERGONE) {
932 1.31 pooka KASSERT((park->park_flags & PARKFLAG_CALL) == 0);
933 1.31 pooka puffs_park_release(park, 0);
934 1.22 pooka } else {
935 1.31 pooka park->park_preq->preq_rv = ENXIO;
936 1.31 pooka if (park->park_flags & PARKFLAG_CALL) {
937 1.42 pooka park->park_done(pmp, park->park_preq,
938 1.31 pooka park->park_donearg);
939 1.31 pooka puffs_park_release(park, 1);
940 1.31 pooka } else {
941 1.31 pooka cv_signal(&park->park_cv);
942 1.31 pooka puffs_park_release(park, 0);
943 1.31 pooka }
944 1.22 pooka }
945 1.22 pooka }
946 1.22 pooka }
947