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