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