dispatcher.c revision 1.5 1 /* $NetBSD: dispatcher.c,v 1.5 2007/05/18 18:01:55 pooka Exp $ */
2
3 /*
4 * Copyright (c) 2006, 2007 Antti Kantee. All Rights Reserved.
5 *
6 * Development of this software was supported by the
7 * Ulla Tuominen Foundation.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the company nor the name of the author may be used to
18 * endorse or promote products derived from this software without specific
19 * prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
22 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
27 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
34 #include <sys/cdefs.h>
35 #if !defined(lint)
36 __RCSID("$NetBSD: dispatcher.c,v 1.5 2007/05/18 18:01:55 pooka Exp $");
37 #endif /* !lint */
38
39 #include <sys/types.h>
40 #include <sys/poll.h>
41
42 #include <assert.h>
43 #include <errno.h>
44 #include <puffs.h>
45 #include <puffsdump.h>
46 #include <stdio.h>
47 #include <stdlib.h>
48 #include <unistd.h>
49
50 #include "puffs_priv.h"
51
52 static void processresult(struct puffs_cc *, struct puffs_putreq *, int);
53
54 /*
55 * Set the following to 1 to not handle each request on a separate
56 * stack. This is highly volatile kludge, therefore no external
57 * interface.
58 */
59 int puffs_fakecc;
60
61 /* user-visible point to handle a request from */
62 int
63 puffs_dopreq(struct puffs_usermount *pu, struct puffs_req *preq,
64 struct puffs_putreq *ppr)
65 {
66 struct puffs_cc fakecc;
67 struct puffs_cc *pcc;
68
69 /*
70 * XXX: the structure is currently a mess. anyway, trap
71 * the cacheops here already, since they don't need a cc.
72 * I really should get around to revamping the operation
73 * dispatching code one of these days.
74 */
75 if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_CACHE) {
76 struct puffs_cacheinfo *pci = (void *)preq;
77
78 if (pu->pu_ops.puffs_cache_write == NULL)
79 return 0;
80
81 pu->pu_ops.puffs_cache_write(pu, preq->preq_cookie,
82 pci->pcache_nruns, pci->pcache_runs);
83 }
84
85 if (pu->pu_flags & PUFFS_FLAG_OPDUMP)
86 puffsdump_req(preq);
87
88 if (puffs_fakecc) {
89 pcc = &fakecc;
90 pcc_init_local(pcc);
91
92 pcc->pcc_pu = pu;
93 pcc->pcc_preq = preq;
94 pcc->pcc_flags = PCC_FAKECC;
95 } else {
96 pcc = puffs_cc_create(pu);
97
98 /* XXX: temporary kludging */
99 pcc->pcc_preq = malloc(preq->preq_buflen);
100 if (pcc->pcc_preq == NULL)
101 return -1;
102 (void) memcpy(pcc->pcc_preq, preq, preq->preq_buflen);
103 }
104
105 puffs_docc(pcc, ppr);
106 return 0;
107 }
108
109 enum {PUFFCALL_ANSWER, PUFFCALL_IGNORE, PUFFCALL_AGAIN};
110
111 /* user-visible continuation point */
112 void
113 puffs_docc(struct puffs_cc *pcc, struct puffs_putreq *ppr)
114 {
115 struct puffs_usermount *pu = pcc->pcc_pu;
116 struct puffs_cc *pcc_iter;
117
118 assert((pcc->pcc_flags & PCC_DONE) == 0);
119 pcc->pcc_ppr = ppr;
120
121 if (pcc->pcc_flags & PCC_REALCC)
122 puffs_cc_continue(pcc);
123 else
124 puffs_calldispatcher(pcc);
125
126 /* can't do this above due to PCC_BORROWED */
127 while ((pcc_iter = LIST_FIRST(&pu->pu_ccnukelst)) != NULL) {
128 LIST_REMOVE(pcc_iter, nlst_entries);
129 puffs_cc_destroy(pcc_iter);
130 }
131 }
132
133 /* library private, but linked from callcontext.c */
134
135 void
136 puffs_calldispatcher(struct puffs_cc *pcc)
137 {
138 struct puffs_usermount *pu = pcc->pcc_pu;
139 struct puffs_ops *pops = &pu->pu_ops;
140 struct puffs_req *preq = pcc->pcc_preq;
141 void *auxbuf = preq; /* help with typecasting */
142 void *opcookie = preq->preq_cookie;
143 int error, rv, buildpath;
144
145 assert(pcc->pcc_flags & (PCC_FAKECC | PCC_REALCC));
146
147 if (PUFFSOP_WANTREPLY(preq->preq_opclass))
148 rv = PUFFCALL_ANSWER;
149 else
150 rv = PUFFCALL_IGNORE;
151
152 buildpath = pu->pu_flags & PUFFS_FLAG_BUILDPATH;
153 preq->preq_setbacks = 0;
154
155 if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VFS) {
156 switch (preq->preq_optype) {
157 case PUFFS_VFS_UNMOUNT:
158 {
159 struct puffs_vfsreq_unmount *auxt = auxbuf;
160
161 PU_SETSTATE(pu, PUFFS_STATE_UNMOUNTING);
162 error = pops->puffs_fs_unmount(pcc,
163 auxt->pvfsr_flags, auxt->pvfsr_pid);
164 if (!error)
165 PU_SETSTATE(pu, PUFFS_STATE_UNMOUNTED);
166 else
167 PU_SETSTATE(pu, PUFFS_STATE_RUNNING);
168 break;
169 }
170
171 case PUFFS_VFS_STATVFS:
172 {
173 struct puffs_vfsreq_statvfs *auxt = auxbuf;
174
175 error = pops->puffs_fs_statvfs(pcc,
176 &auxt->pvfsr_sb, auxt->pvfsr_pid);
177 break;
178 }
179
180 case PUFFS_VFS_SYNC:
181 {
182 struct puffs_vfsreq_sync *auxt = auxbuf;
183
184 error = pops->puffs_fs_sync(pcc,
185 auxt->pvfsr_waitfor, &auxt->pvfsr_cred,
186 auxt->pvfsr_pid);
187 break;
188 }
189
190 case PUFFS_VFS_FHTOVP:
191 {
192 struct puffs_vfsreq_fhtonode *auxt = auxbuf;
193
194 error = pops->puffs_fs_fhtonode(pcc, auxt->pvfsr_data,
195 auxt->pvfsr_dsize, &auxt->pvfsr_fhcookie,
196 &auxt->pvfsr_vtype, &auxt->pvfsr_size,
197 &auxt->pvfsr_rdev);
198
199 break;
200 }
201
202 case PUFFS_VFS_VPTOFH:
203 {
204 struct puffs_vfsreq_nodetofh *auxt = auxbuf;
205
206 error = pops->puffs_fs_nodetofh(pcc,
207 auxt->pvfsr_fhcookie, auxt->pvfsr_data,
208 &auxt->pvfsr_dsize);
209
210 break;
211 }
212
213 case PUFFS_VFS_SUSPEND:
214 {
215 struct puffs_vfsreq_suspend *auxt = auxbuf;
216
217 error = 0;
218 if (pops->puffs_fs_suspend == NULL)
219 break;
220
221 pops->puffs_fs_suspend(pcc, auxt->pvfsr_status);
222 break;
223 }
224
225 default:
226 /*
227 * I guess the kernel sees this one coming
228 */
229 error = EINVAL;
230 break;
231 }
232
233 /* XXX: audit return values */
234 /* XXX: sync with kernel */
235 } else if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN) {
236 switch (preq->preq_optype) {
237 case PUFFS_VN_LOOKUP:
238 {
239 struct puffs_vnreq_lookup *auxt = auxbuf;
240 struct puffs_cn pcn;
241
242 pcn.pcn_pkcnp = &auxt->pvnr_cn;
243 if (buildpath) {
244 error = puffs_path_pcnbuild(pu, &pcn, opcookie);
245 if (error)
246 break;
247 }
248
249 /* lookup *must* be present */
250 error = pops->puffs_node_lookup(pcc, opcookie,
251 &auxt->pvnr_newnode, &auxt->pvnr_vtype,
252 &auxt->pvnr_size, &auxt->pvnr_rdev, &pcn);
253
254 if (buildpath) {
255 if (error) {
256 pu->pu_pathfree(pu, &pcn.pcn_po_full);
257 } else {
258 struct puffs_node *pn;
259
260 /*
261 * did we get a new node or a
262 * recycled node?
263 */
264 pn = PU_CMAP(pu, auxt->pvnr_newnode);
265 if (pn->pn_po.po_path == NULL)
266 pn->pn_po = pcn.pcn_po_full;
267 else
268 pu->pu_pathfree(pu,
269 &pcn.pcn_po_full);
270 }
271 }
272
273 break;
274 }
275
276 case PUFFS_VN_CREATE:
277 {
278 struct puffs_vnreq_create *auxt = auxbuf;
279 struct puffs_cn pcn;
280 if (pops->puffs_node_create == NULL) {
281 error = 0;
282 break;
283 }
284
285 pcn.pcn_pkcnp = &auxt->pvnr_cn;
286 if (buildpath) {
287 error = puffs_path_pcnbuild(pu, &pcn, opcookie);
288 if (error)
289 break;
290 }
291
292 error = pops->puffs_node_create(pcc,
293 opcookie, &auxt->pvnr_newnode,
294 &pcn, &auxt->pvnr_va);
295
296 if (buildpath) {
297 if (error) {
298 pu->pu_pathfree(pu, &pcn.pcn_po_full);
299 } else {
300 struct puffs_node *pn;
301
302 pn = PU_CMAP(pu, auxt->pvnr_newnode);
303 pn->pn_po = pcn.pcn_po_full;
304 }
305 }
306
307 break;
308 }
309
310 case PUFFS_VN_MKNOD:
311 {
312 struct puffs_vnreq_mknod *auxt = auxbuf;
313 struct puffs_cn pcn;
314 if (pops->puffs_node_mknod == NULL) {
315 error = 0;
316 break;
317 }
318
319 pcn.pcn_pkcnp = &auxt->pvnr_cn;
320 if (buildpath) {
321 error = puffs_path_pcnbuild(pu, &pcn, opcookie);
322 if (error)
323 break;
324 }
325
326 error = pops->puffs_node_mknod(pcc,
327 opcookie, &auxt->pvnr_newnode,
328 &pcn, &auxt->pvnr_va);
329
330 if (buildpath) {
331 if (error) {
332 pu->pu_pathfree(pu, &pcn.pcn_po_full);
333 } else {
334 struct puffs_node *pn;
335
336 pn = PU_CMAP(pu, auxt->pvnr_newnode);
337 pn->pn_po = pcn.pcn_po_full;
338 }
339 }
340
341 break;
342 }
343
344 case PUFFS_VN_OPEN:
345 {
346 struct puffs_vnreq_open *auxt = auxbuf;
347 if (pops->puffs_node_open == NULL) {
348 error = 0;
349 break;
350 }
351
352 error = pops->puffs_node_open(pcc,
353 opcookie, auxt->pvnr_mode,
354 &auxt->pvnr_cred, auxt->pvnr_pid);
355 break;
356 }
357
358 case PUFFS_VN_CLOSE:
359 {
360 struct puffs_vnreq_close *auxt = auxbuf;
361 if (pops->puffs_node_close == NULL) {
362 error = 0;
363 break;
364 }
365
366 error = pops->puffs_node_close(pcc,
367 opcookie, auxt->pvnr_fflag,
368 &auxt->pvnr_cred, auxt->pvnr_pid);
369 break;
370 }
371
372 case PUFFS_VN_ACCESS:
373 {
374 struct puffs_vnreq_access *auxt = auxbuf;
375 if (pops->puffs_node_access == NULL) {
376 error = 0;
377 break;
378 }
379
380 error = pops->puffs_node_access(pcc,
381 opcookie, auxt->pvnr_mode,
382 &auxt->pvnr_cred, auxt->pvnr_pid);
383 break;
384 }
385
386 case PUFFS_VN_GETATTR:
387 {
388 struct puffs_vnreq_getattr *auxt = auxbuf;
389 if (pops->puffs_node_getattr == NULL) {
390 error = EOPNOTSUPP;
391 break;
392 }
393
394 error = pops->puffs_node_getattr(pcc,
395 opcookie, &auxt->pvnr_va,
396 &auxt->pvnr_cred, auxt->pvnr_pid);
397 break;
398 }
399
400 case PUFFS_VN_SETATTR:
401 {
402 struct puffs_vnreq_setattr *auxt = auxbuf;
403 if (pops->puffs_node_setattr == NULL) {
404 error = EOPNOTSUPP;
405 break;
406 }
407
408 error = pops->puffs_node_setattr(pcc,
409 opcookie, &auxt->pvnr_va,
410 &auxt->pvnr_cred, auxt->pvnr_pid);
411 break;
412 }
413
414 case PUFFS_VN_MMAP:
415 {
416 struct puffs_vnreq_mmap *auxt = auxbuf;
417 if (pops->puffs_node_mmap == NULL) {
418 error = 0;
419 break;
420 }
421
422 error = pops->puffs_node_mmap(pcc,
423 opcookie, auxt->pvnr_fflags,
424 &auxt->pvnr_cred, auxt->pvnr_pid);
425 break;
426 }
427
428 case PUFFS_VN_FSYNC:
429 {
430 struct puffs_vnreq_fsync *auxt = auxbuf;
431 if (pops->puffs_node_fsync == NULL) {
432 error = 0;
433 break;
434 }
435
436 error = pops->puffs_node_fsync(pcc,
437 opcookie, &auxt->pvnr_cred,
438 auxt->pvnr_flags, auxt->pvnr_offlo,
439 auxt->pvnr_offhi, auxt->pvnr_pid);
440 break;
441 }
442
443 case PUFFS_VN_SEEK:
444 {
445 struct puffs_vnreq_seek *auxt = auxbuf;
446 if (pops->puffs_node_seek == NULL) {
447 error = 0;
448 break;
449 }
450
451 error = pops->puffs_node_seek(pcc,
452 opcookie, auxt->pvnr_oldoff,
453 auxt->pvnr_newoff, &auxt->pvnr_cred);
454 break;
455 }
456
457 case PUFFS_VN_REMOVE:
458 {
459 struct puffs_vnreq_remove *auxt = auxbuf;
460 struct puffs_cn pcn;
461 if (pops->puffs_node_remove == NULL) {
462 error = 0;
463 break;
464 }
465
466 pcn.pcn_pkcnp = &auxt->pvnr_cn;
467
468 error = pops->puffs_node_remove(pcc,
469 opcookie, auxt->pvnr_cookie_targ, &pcn);
470 break;
471 }
472
473 case PUFFS_VN_LINK:
474 {
475 struct puffs_vnreq_link *auxt = auxbuf;
476 struct puffs_cn pcn;
477 if (pops->puffs_node_link == NULL) {
478 error = 0;
479 break;
480 }
481
482 pcn.pcn_pkcnp = &auxt->pvnr_cn;
483 if (buildpath) {
484 error = puffs_path_pcnbuild(pu, &pcn, opcookie);
485 if (error)
486 break;
487 }
488
489 error = pops->puffs_node_link(pcc,
490 opcookie, auxt->pvnr_cookie_targ, &pcn);
491 if (buildpath)
492 pu->pu_pathfree(pu, &pcn.pcn_po_full);
493
494 break;
495 }
496
497 case PUFFS_VN_RENAME:
498 {
499 struct puffs_vnreq_rename *auxt = auxbuf;
500 struct puffs_cn pcn_src, pcn_targ;
501 struct puffs_node *pn_src;
502
503 if (pops->puffs_node_rename == NULL) {
504 error = 0;
505 break;
506 }
507
508 pcn_src.pcn_pkcnp = &auxt->pvnr_cn_src;
509 pcn_targ.pcn_pkcnp = &auxt->pvnr_cn_targ;
510 if (buildpath) {
511 pn_src = auxt->pvnr_cookie_src;
512 pcn_src.pcn_po_full = pn_src->pn_po;
513
514 error = puffs_path_pcnbuild(pu, &pcn_targ,
515 auxt->pvnr_cookie_targdir);
516 if (error)
517 break;
518 }
519
520 error = pops->puffs_node_rename(pcc,
521 opcookie, auxt->pvnr_cookie_src,
522 &pcn_src, auxt->pvnr_cookie_targdir,
523 auxt->pvnr_cookie_targ, &pcn_targ);
524
525 if (buildpath) {
526 if (error) {
527 pu->pu_pathfree(pu,
528 &pcn_targ.pcn_po_full);
529 } else {
530 struct puffs_pathinfo pi;
531 struct puffs_pathobj po_old;
532
533 /* handle this node */
534 po_old = pn_src->pn_po;
535 pn_src->pn_po = pcn_targ.pcn_po_full;
536
537 if (pn_src->pn_va.va_type != VDIR) {
538 pu->pu_pathfree(pu, &po_old);
539 break;
540 }
541
542 /* handle all child nodes for DIRs */
543 pi.pi_old = &pcn_src.pcn_po_full;
544 pi.pi_new = &pcn_targ.pcn_po_full;
545
546 if (puffs_pn_nodewalk(pu,
547 puffs_path_prefixadj, &pi) != NULL)
548 error = ENOMEM;
549 pu->pu_pathfree(pu, &po_old);
550 }
551 }
552 break;
553 }
554
555 case PUFFS_VN_MKDIR:
556 {
557 struct puffs_vnreq_mkdir *auxt = auxbuf;
558 struct puffs_cn pcn;
559 if (pops->puffs_node_mkdir == NULL) {
560 error = 0;
561 break;
562 }
563
564 pcn.pcn_pkcnp = &auxt->pvnr_cn;
565 if (buildpath) {
566 error = puffs_path_pcnbuild(pu, &pcn, opcookie);
567 if (error)
568 break;
569 }
570
571 error = pops->puffs_node_mkdir(pcc,
572 opcookie, &auxt->pvnr_newnode,
573 &pcn, &auxt->pvnr_va);
574
575 if (buildpath) {
576 if (error) {
577 pu->pu_pathfree(pu, &pcn.pcn_po_full);
578 } else {
579 struct puffs_node *pn;
580
581 pn = PU_CMAP(pu, auxt->pvnr_newnode);
582 pn->pn_po = pcn.pcn_po_full;
583 }
584 }
585
586 break;
587 }
588
589 case PUFFS_VN_RMDIR:
590 {
591 struct puffs_vnreq_rmdir *auxt = auxbuf;
592 struct puffs_cn pcn;
593 if (pops->puffs_node_rmdir == NULL) {
594 error = 0;
595 break;
596 }
597
598 pcn.pcn_pkcnp = &auxt->pvnr_cn;
599
600 error = pops->puffs_node_rmdir(pcc,
601 opcookie, auxt->pvnr_cookie_targ, &pcn);
602 break;
603 }
604
605 case PUFFS_VN_SYMLINK:
606 {
607 struct puffs_vnreq_symlink *auxt = auxbuf;
608 struct puffs_cn pcn;
609 if (pops->puffs_node_symlink == NULL) {
610 error = 0;
611 break;
612 }
613
614 pcn.pcn_pkcnp = &auxt->pvnr_cn;
615 if (buildpath) {
616 error = puffs_path_pcnbuild(pu, &pcn, opcookie);
617 if (error)
618 break;
619 }
620
621 error = pops->puffs_node_symlink(pcc,
622 opcookie, &auxt->pvnr_newnode,
623 &pcn, &auxt->pvnr_va, auxt->pvnr_link);
624
625 if (buildpath) {
626 if (error) {
627 pu->pu_pathfree(pu, &pcn.pcn_po_full);
628 } else {
629 struct puffs_node *pn;
630
631 pn = PU_CMAP(pu, auxt->pvnr_newnode);
632 pn->pn_po = pcn.pcn_po_full;
633 }
634 }
635
636 break;
637 }
638
639 case PUFFS_VN_READDIR:
640 {
641 struct puffs_vnreq_readdir *auxt = auxbuf;
642 struct dirent *dent;
643 off_t *cookies;
644 size_t res, origcookies;
645
646 if (pops->puffs_node_readdir == NULL) {
647 error = 0;
648 break;
649 }
650
651 if (auxt->pvnr_ncookies) {
652 /* LINTED: pvnr_data is __aligned() */
653 cookies = (off_t *)auxt->pvnr_data;
654 origcookies = auxt->pvnr_ncookies;
655 } else {
656 cookies = NULL;
657 origcookies = 0;
658 }
659 /* LINTED: dentoff is aligned in the kernel */
660 dent = (struct dirent *)
661 (auxt->pvnr_data + auxt->pvnr_dentoff);
662
663 res = auxt->pvnr_resid;
664 error = pops->puffs_node_readdir(pcc,
665 opcookie, dent, &auxt->pvnr_offset,
666 &auxt->pvnr_resid, &auxt->pvnr_cred,
667 &auxt->pvnr_eofflag, cookies, &auxt->pvnr_ncookies);
668
669 /* much easier to track non-working NFS */
670 assert(auxt->pvnr_ncookies <= origcookies);
671
672 /* need to move a bit more */
673 preq->preq_buflen = sizeof(struct puffs_vnreq_readdir)
674 + auxt->pvnr_dentoff + (res - auxt->pvnr_resid);
675 break;
676 }
677
678 case PUFFS_VN_READLINK:
679 {
680 struct puffs_vnreq_readlink *auxt = auxbuf;
681 if (pops->puffs_node_readlink == NULL) {
682 error = EOPNOTSUPP;
683 break;
684 }
685
686 error = pops->puffs_node_readlink(pcc,
687 opcookie, &auxt->pvnr_cred,
688 auxt->pvnr_link, &auxt->pvnr_linklen);
689 break;
690 }
691
692 case PUFFS_VN_RECLAIM:
693 {
694 struct puffs_vnreq_reclaim *auxt = auxbuf;
695 if (pops->puffs_node_reclaim == NULL) {
696 error = 0;
697 break;
698 }
699
700 error = pops->puffs_node_reclaim(pcc,
701 opcookie, auxt->pvnr_pid);
702 break;
703 }
704
705 case PUFFS_VN_INACTIVE:
706 {
707 struct puffs_vnreq_inactive *auxt = auxbuf;
708 if (pops->puffs_node_inactive == NULL) {
709 error = EOPNOTSUPP;
710 break;
711 }
712
713 auxt->pvnr_backendrefs = 1; /* safe default */
714 error = pops->puffs_node_inactive(pcc,
715 opcookie, auxt->pvnr_pid,
716 &auxt->pvnr_backendrefs);
717 break;
718 }
719
720 case PUFFS_VN_PATHCONF:
721 {
722 struct puffs_vnreq_pathconf *auxt = auxbuf;
723 if (pops->puffs_node_pathconf == NULL) {
724 error = 0;
725 break;
726 }
727
728 error = pops->puffs_node_pathconf(pcc,
729 opcookie, auxt->pvnr_name,
730 &auxt->pvnr_retval);
731 break;
732 }
733
734 case PUFFS_VN_ADVLOCK:
735 {
736 struct puffs_vnreq_advlock *auxt = auxbuf;
737 if (pops->puffs_node_advlock == NULL) {
738 error = 0;
739 break;
740 }
741
742 error = pops->puffs_node_advlock(pcc,
743 opcookie, auxt->pvnr_id, auxt->pvnr_op,
744 &auxt->pvnr_fl, auxt->pvnr_flags);
745 break;
746 }
747
748 case PUFFS_VN_PRINT:
749 {
750 if (pops->puffs_node_print == NULL) {
751 error = 0;
752 break;
753 }
754
755 error = pops->puffs_node_print(pcc,
756 opcookie);
757 break;
758 }
759
760 case PUFFS_VN_READ:
761 {
762 struct puffs_vnreq_read *auxt = auxbuf;
763 size_t res;
764
765 if (pops->puffs_node_read == NULL) {
766 error = EIO;
767 break;
768 }
769
770 res = auxt->pvnr_resid;
771 error = pops->puffs_node_read(pcc,
772 opcookie, auxt->pvnr_data,
773 auxt->pvnr_offset, &auxt->pvnr_resid,
774 &auxt->pvnr_cred, auxt->pvnr_ioflag);
775
776 /* need to move a bit more */
777 preq->preq_buflen = sizeof(struct puffs_vnreq_read)
778 + (res - auxt->pvnr_resid);
779 break;
780 }
781
782 case PUFFS_VN_WRITE:
783 {
784 struct puffs_vnreq_write *auxt = auxbuf;
785
786 if (pops->puffs_node_write == NULL) {
787 error = EIO;
788 break;
789 }
790
791 error = pops->puffs_node_write(pcc,
792 opcookie, auxt->pvnr_data,
793 auxt->pvnr_offset, &auxt->pvnr_resid,
794 &auxt->pvnr_cred, auxt->pvnr_ioflag);
795
796 /* don't need to move data back to the kernel */
797 preq->preq_buflen = sizeof(struct puffs_vnreq_write);
798 break;
799 }
800
801 case PUFFS_VN_POLL:
802 {
803 struct puffs_vnreq_poll *auxt = auxbuf;
804 if (pops->puffs_node_poll == NULL) {
805 error = 0;
806
807 /* emulate genfs_poll() */
808 auxt->pvnr_events &= (POLLIN | POLLOUT
809 | POLLRDNORM | POLLWRNORM);
810
811 break;
812 }
813
814 error = pops->puffs_node_poll(pcc,
815 opcookie, &auxt->pvnr_events, auxt->pvnr_pid);
816 break;
817 }
818
819 /* holy bitrot, ryydman! */
820 #if 0
821 case PUFFS_VN_IOCTL:
822 error = pops->puffs_node_ioctl1(pcc, opcookie,
823 (struct puffs_vnreq_ioctl *)auxbuf, &pop);
824 if (error != 0)
825 break;
826 pop.pso_reqid = preq->preq_id;
827
828 /* let the kernel do it's intermediate duty */
829 error = ioctl(pu->pu_kargs.pa_fd, PUFFSSIZEOP, &pop);
830 /*
831 * XXX: I don't actually know what the correct
832 * thing to do in case of an error is, so I'll
833 * just ignore it for the time being.
834 */
835 error = pops->puffs_node_ioctl2(pcc, opcookie,
836 (struct puffs_vnreq_ioctl *)auxbuf, &pop);
837 break;
838
839 case PUFFS_VN_FCNTL:
840 error = pops->puffs_node_fcntl1(pcc, opcookie,
841 (struct puffs_vnreq_fcntl *)auxbuf, &pop);
842 if (error != 0)
843 break;
844 pop.pso_reqid = preq->preq_id;
845
846 /* let the kernel do it's intermediate duty */
847 error = ioctl(pu->pu_kargs.pa_fd, PUFFSSIZEOP, &pop);
848 /*
849 * XXX: I don't actually know what the correct
850 * thing to do in case of an error is, so I'll
851 * just ignore it for the time being.
852 */
853 error = pops->puffs_node_fcntl2(pcc, opcookie,
854 (struct puffs_vnreq_fcntl *)auxbuf, &pop);
855 break;
856 #endif
857
858 default:
859 printf("inval op %d\n", preq->preq_optype);
860 error = EINVAL;
861 break;
862 }
863 } else {
864 /*
865 * this one also
866 */
867 error = EINVAL;
868 }
869
870 preq->preq_rv = error;
871 pcc->pcc_flags |= PCC_DONE;
872
873 /*
874 * Note, we are calling this from here so that we can run it
875 * off of the continuation stack. Otherwise puffs_goto() would
876 * not work.
877 */
878 processresult(pcc, pcc->pcc_ppr, rv);
879 }
880
881 static void
882 processresult(struct puffs_cc *pcc, struct puffs_putreq *ppr, int how)
883 {
884 struct puffs_usermount *pu = puffs_cc_getusermount(pcc);
885
886 /* check if we need to store this reply */
887 switch (how) {
888 case PUFFCALL_ANSWER:
889 if (pu->pu_flags & PUFFS_FLAG_OPDUMP)
890 puffsdump_rv(pcc->pcc_preq);
891
892 if (pcc->pcc_flags & PCC_REALCC)
893 puffs_req_putcc(ppr, pcc);
894 else
895 puffs_req_put(ppr, pcc->pcc_preq);
896 break;
897 case PUFFCALL_IGNORE:
898 if (pcc->pcc_flags & PCC_REALCC)
899 LIST_INSERT_HEAD(&pu->pu_ccnukelst, pcc, nlst_entries);
900 break;
901 case PUFFCALL_AGAIN:
902 if (pcc->pcc_flags & PCC_FAKECC)
903 assert(pcc->pcc_flags & PCC_DONE);
904 break;
905 default:
906 assert(/*CONSTCOND*/0);
907 }
908
909 /* who needs information when you're living on borrowed time? */
910 if (pcc->pcc_flags & PCC_BORROWED)
911 puffs_cc_yield(pcc); /* back to borrow source */
912 }
913
914
915 #if 0
916 case PUFFS_VN_KQFILTER:
917 {
918 struct puffs_vnreq_kqfilter *auxt = auxbuf;
919 if (pops->puffs_node_kqfilter == NULL) {
920 error = 0;
921 break;
922 }
923
924 error = pops->puffs_node_kqfilter(pcc,
925 opcookie, );
926 break;
927 }
928
929 case PUFFS_VN_CLOSEEXTATTR:
930 {
931 struct puffs_vnreq_closeextattr *auxt = auxbuf;
932 if (pops->puffs_closeextattr == NULL) {
933 error = 0;
934 break;
935 }
936
937 error = pops->puffs_closeextattr(pcc,
938 opcookie, );
939 break;
940 }
941
942 case PUFFS_VN_GETEXTATTR:
943 {
944 struct puffs_vnreq_getextattr *auxt = auxbuf;
945 if (pops->puffs_getextattr == NULL) {
946 error = 0;
947 break;
948 }
949
950 error = pops->puffs_getextattr(pcc,
951 opcookie, );
952 break;
953 }
954
955 case PUFFS_VN_LISTEXTATTR:
956 {
957 struct puffs_vnreq_listextattr *auxt = auxbuf;
958 if (pops->puffs_listextattr == NULL) {
959 error = 0;
960 break;
961 }
962
963 error = pops->puffs_listextattr(pcc,
964 opcookie, );
965 break;
966 }
967
968 case PUFFS_VN_OPENEXTATTR:
969 {
970 struct puffs_vnreq_openextattr *auxt = auxbuf;
971 if (pops->puffs_openextattr == NULL) {
972 error = 0;
973 break;
974 }
975
976 error = pops->puffs_openextattr(pcc,
977 opcookie, );
978 break;
979 }
980
981 case PUFFS_VN_DELETEEXTATTR:
982 {
983 struct puffs_vnreq_deleteextattr *auxt = auxbuf;
984 if (pops->puffs_deleteextattr == NULL) {
985 error = 0;
986 break;
987 }
988
989 error = pops->puffs_deleteextattr(pcc,
990 opcookie, );
991 break;
992 }
993
994 case PUFFS_VN_SETEXTATTR:
995 {
996 struct puffs_vnreq_setextattr *auxt = auxbuf;
997 if (pops->puffs_setextattr == NULL) {
998 error = 0;
999 break;
1000 }
1001
1002 error = pops->puffs_setextattr(pcc,
1003 opcookie, );
1004 break;
1005 }
1006
1007 #endif
1008