dispatcher.c revision 1.40 1 /* $NetBSD: dispatcher.c,v 1.40 2012/04/18 00:57:22 manu Exp $ */
2
3 /*
4 * Copyright (c) 2006, 2007, 2008 Antti Kantee. All Rights Reserved.
5 *
6 * Development of this software was supported by the
7 * Ulla Tuominen Foundation, the Finnish Cultural Foundation and
8 * Research Foundation of Helsinki University of Technology.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
20 * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
21 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
22 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
25 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32 #include <sys/cdefs.h>
33 #if !defined(lint)
34 __RCSID("$NetBSD: dispatcher.c,v 1.40 2012/04/18 00:57:22 manu Exp $");
35 #endif /* !lint */
36
37 #include <sys/types.h>
38 #include <sys/poll.h>
39
40 #include <assert.h>
41 #include <errno.h>
42 #include <pthread.h>
43 #include <puffs.h>
44 #include <puffsdump.h>
45 #include <stdio.h>
46 #include <stdlib.h>
47 #include <unistd.h>
48
49 #include "puffs_priv.h"
50
51 #define PUFFS_USE_FS_TTL(pu) (pu->pu_flags & PUFFS_KFLAG_CACHE_FS_TTL)
52
53 static void dispatch(struct puffs_cc *);
54
55 /* for our eyes only */
56 void
57 puffs__ml_dispatch(struct puffs_usermount *pu, struct puffs_framebuf *pb)
58 {
59 struct puffs_cc *pcc = puffs_cc_getcc(pu);
60 struct puffs_req *preq;
61
62 pcc->pcc_pb = pb;
63 pcc->pcc_flags |= PCC_MLCONT;
64 dispatch(pcc);
65
66 /* Put result to kernel sendqueue if necessary */
67 preq = puffs__framebuf_getdataptr(pcc->pcc_pb);
68 if (PUFFSOP_WANTREPLY(preq->preq_opclass)) {
69 if (pu->pu_flags & PUFFS_FLAG_OPDUMP)
70 puffsdump_rv(preq);
71
72 puffs_framev_enqueue_justsend(pu, pu->pu_fd,
73 pcc->pcc_pb, 0, 0);
74 } else {
75 puffs_framebuf_destroy(pcc->pcc_pb);
76 }
77
78 /* who needs information when you're living on borrowed time? */
79 if (pcc->pcc_flags & PCC_BORROWED) {
80 puffs_cc_yield(pcc); /* back to borrow source */
81 }
82 pcc->pcc_flags = 0;
83 }
84
85 /* public, but not really tested and only semi-supported */
86 int
87 puffs_dispatch_create(struct puffs_usermount *pu, struct puffs_framebuf *pb,
88 struct puffs_cc **pccp)
89 {
90 struct puffs_cc *pcc;
91
92 if (puffs__cc_create(pu, dispatch, &pcc) == -1)
93 return -1;
94
95 pcc->pcc_pb = pb;
96 *pccp = pcc;
97
98 return 0;
99 }
100
101 int
102 puffs_dispatch_exec(struct puffs_cc *pcc, struct puffs_framebuf **pbp)
103 {
104 int rv;
105
106 puffs_cc_continue(pcc);
107
108 if (pcc->pcc_flags & PCC_DONE) {
109 rv = 1;
110 *pbp = pcc->pcc_pb;
111 pcc->pcc_flags = 0;
112 puffs__cc_destroy(pcc, 0);
113 } else {
114 rv = 0;
115 }
116
117 return rv;
118 }
119
120 static void
121 dispatch(struct puffs_cc *pcc)
122 {
123 struct puffs_usermount *pu = pcc->pcc_pu;
124 struct puffs_ops *pops = &pu->pu_ops;
125 struct puffs_req *preq = puffs__framebuf_getdataptr(pcc->pcc_pb);
126 void *auxbuf; /* help with typecasting */
127 puffs_cookie_t opcookie;
128 int error = 0, buildpath;
129
130 /* XXX: smaller hammer, please */
131 if ((PUFFSOP_OPCLASS(preq->preq_opclass == PUFFSOP_VFS &&
132 preq->preq_optype == PUFFS_VFS_VPTOFH)) ||
133 (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN &&
134 (preq->preq_optype == PUFFS_VN_READDIR
135 || preq->preq_optype == PUFFS_VN_READ))) {
136 if (puffs_framebuf_reserve_space(pcc->pcc_pb,
137 PUFFS_MSG_MAXSIZE) == -1)
138 error = errno;
139 preq = puffs__framebuf_getdataptr(pcc->pcc_pb);
140 }
141
142 auxbuf = preq;
143 opcookie = preq->preq_cookie;
144
145 assert((pcc->pcc_flags & PCC_DONE) == 0);
146
147 buildpath = pu->pu_flags & PUFFS_FLAG_BUILDPATH;
148 preq->preq_setbacks = 0;
149
150 if (pu->pu_flags & PUFFS_FLAG_OPDUMP)
151 puffsdump_req(preq);
152
153 puffs__cc_setcaller(pcc, preq->preq_pid, preq->preq_lid);
154
155 /* pre-operation */
156 if (pu->pu_oppre)
157 pu->pu_oppre(pu);
158
159 if (error)
160 goto out;
161
162 /* Execute actual operation */
163 if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VFS) {
164 switch (preq->preq_optype) {
165 case PUFFS_VFS_UNMOUNT:
166 {
167 struct puffs_vfsmsg_unmount *auxt = auxbuf;
168
169 PU_SETSTATE(pu, PUFFS_STATE_UNMOUNTING);
170 error = pops->puffs_fs_unmount(pu, auxt->pvfsr_flags);
171 if (!error)
172 PU_SETSTATE(pu, PUFFS_STATE_UNMOUNTED);
173 else
174 PU_SETSTATE(pu, PUFFS_STATE_RUNNING);
175 break;
176 }
177
178 case PUFFS_VFS_STATVFS:
179 {
180 struct puffs_vfsmsg_statvfs *auxt = auxbuf;
181
182 error = pops->puffs_fs_statvfs(pu, &auxt->pvfsr_sb);
183 break;
184 }
185
186 case PUFFS_VFS_SYNC:
187 {
188 struct puffs_vfsmsg_sync *auxt = auxbuf;
189 PUFFS_MAKECRED(pcr, &auxt->pvfsr_cred);
190
191 error = pops->puffs_fs_sync(pu,
192 auxt->pvfsr_waitfor, pcr);
193 break;
194 }
195
196 case PUFFS_VFS_FHTOVP:
197 {
198 struct puffs_vfsmsg_fhtonode *auxt = auxbuf;
199 struct puffs_newinfo pni;
200
201 pni.pni_cookie = &auxt->pvfsr_fhcookie;
202 pni.pni_vtype = &auxt->pvfsr_vtype;
203 pni.pni_size = &auxt->pvfsr_size;
204 pni.pni_rdev = &auxt->pvfsr_rdev;
205 pni.pni_va = NULL;
206 pni.pni_va_ttl = NULL;
207 pni.pni_cn_ttl = NULL;
208
209 error = pops->puffs_fs_fhtonode(pu, auxt->pvfsr_data,
210 auxt->pvfsr_dsize, &pni);
211
212 break;
213 }
214
215 case PUFFS_VFS_VPTOFH:
216 {
217 struct puffs_vfsmsg_nodetofh *auxt = auxbuf;
218
219 error = pops->puffs_fs_nodetofh(pu,
220 auxt->pvfsr_fhcookie, auxt->pvfsr_data,
221 &auxt->pvfsr_dsize);
222
223 break;
224 }
225
226 case PUFFS_VFS_EXTATTRCTL:
227 {
228 struct puffs_vfsmsg_extattrctl *auxt = auxbuf;
229 const char *attrname;
230 int flags;
231
232 if (pops->puffs_fs_extattrctl == NULL) {
233 error = EOPNOTSUPP;
234 break;
235 }
236
237 if (auxt->pvfsr_flags & PUFFS_EXTATTRCTL_HASATTRNAME)
238 attrname = auxt->pvfsr_attrname;
239 else
240 attrname = NULL;
241
242 flags = auxt->pvfsr_flags & PUFFS_EXTATTRCTL_HASNODE;
243 error = pops->puffs_fs_extattrctl(pu, auxt->pvfsr_cmd,
244 opcookie, flags,
245 auxt->pvfsr_attrnamespace, attrname);
246 break;
247 }
248
249 default:
250 /*
251 * I guess the kernel sees this one coming
252 */
253 error = EINVAL;
254 break;
255 }
256
257 /* XXX: audit return values */
258 /* XXX: sync with kernel */
259 } else if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_VN) {
260 switch (preq->preq_optype) {
261 case PUFFS_VN_LOOKUP:
262 {
263 struct puffs_vnmsg_lookup *auxt = auxbuf;
264 struct puffs_newinfo pni;
265 struct puffs_cn pcn;
266 struct puffs_node *pn = NULL;
267
268 pcn.pcn_pkcnp = &auxt->pvnr_cn;
269 PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
270 pni.pni_cookie = &auxt->pvnr_newnode;
271 pni.pni_vtype = &auxt->pvnr_vtype;
272 pni.pni_size = &auxt->pvnr_size;
273 pni.pni_rdev = &auxt->pvnr_rdev;
274 pni.pni_va = &auxt->pvnr_va;
275 pni.pni_va_ttl = &auxt->pvnr_va_ttl;
276 pni.pni_cn_ttl = &auxt->pvnr_cn_ttl;
277
278 if (buildpath) {
279 error = puffs_path_pcnbuild(pu, &pcn, opcookie);
280 if (error)
281 break;
282 }
283
284 /* lookup *must* be present */
285 error = pops->puffs_node_lookup(pu, opcookie,
286 &pni, &pcn);
287
288 if (buildpath) {
289 if (error) {
290 pu->pu_pathfree(pu, &pcn.pcn_po_full);
291 } else {
292 /*
293 * did we get a new node or a
294 * recycled node?
295 */
296 pn = PU_CMAP(pu, auxt->pvnr_newnode);
297 if (pn->pn_po.po_path == NULL)
298 pn->pn_po = pcn.pcn_po_full;
299 else
300 pu->pu_pathfree(pu,
301 &pcn.pcn_po_full);
302 }
303 }
304 break;
305 }
306
307 case PUFFS_VN_CREATE:
308 {
309 struct puffs_vnmsg_create *auxt = auxbuf;
310 struct puffs_newinfo pni;
311 struct puffs_cn pcn;
312
313 if (pops->puffs_node_create == NULL) {
314 error = 0;
315 break;
316 }
317
318 pcn.pcn_pkcnp = &auxt->pvnr_cn;
319 PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
320
321 memset(&pni, 0, sizeof(pni));
322 pni.pni_cookie = &auxt->pvnr_newnode;
323 pni.pni_va = &auxt->pvnr_va;
324 pni.pni_va_ttl = &auxt->pvnr_va_ttl;
325 pni.pni_cn_ttl = &auxt->pvnr_cn_ttl;
326
327 if (buildpath) {
328 error = puffs_path_pcnbuild(pu, &pcn, opcookie);
329 if (error)
330 break;
331 }
332
333 error = pops->puffs_node_create(pu,
334 opcookie, &pni, &pcn, &auxt->pvnr_va);
335
336 if (buildpath) {
337 if (error) {
338 pu->pu_pathfree(pu, &pcn.pcn_po_full);
339 } else {
340 struct puffs_node *pn;
341
342 pn = PU_CMAP(pu, auxt->pvnr_newnode);
343 pn->pn_po = pcn.pcn_po_full;
344 }
345 }
346
347 break;
348 }
349
350 case PUFFS_VN_MKNOD:
351 {
352 struct puffs_vnmsg_mknod *auxt = auxbuf;
353 struct puffs_newinfo pni;
354 struct puffs_cn pcn;
355
356 if (pops->puffs_node_mknod == NULL) {
357 error = 0;
358 break;
359 }
360
361 pcn.pcn_pkcnp = &auxt->pvnr_cn;
362 PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
363
364 memset(&pni, 0, sizeof(pni));
365 pni.pni_cookie = &auxt->pvnr_newnode;
366 pni.pni_va = &auxt->pvnr_va;
367 pni.pni_va_ttl = &auxt->pvnr_va_ttl;
368 pni.pni_cn_ttl = &auxt->pvnr_cn_ttl;
369
370 if (buildpath) {
371 error = puffs_path_pcnbuild(pu, &pcn, opcookie);
372 if (error)
373 break;
374 }
375
376 error = pops->puffs_node_mknod(pu,
377 opcookie, &pni, &pcn, &auxt->pvnr_va);
378
379 if (buildpath) {
380 if (error) {
381 pu->pu_pathfree(pu, &pcn.pcn_po_full);
382 } else {
383 struct puffs_node *pn;
384
385 pn = PU_CMAP(pu, auxt->pvnr_newnode);
386 pn->pn_po = pcn.pcn_po_full;
387 }
388 }
389
390 break;
391 }
392
393 case PUFFS_VN_OPEN:
394 {
395 struct puffs_vnmsg_open *auxt = auxbuf;
396 PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
397
398 if (pops->puffs_node_open == NULL) {
399 error = 0;
400 break;
401 }
402
403 error = pops->puffs_node_open(pu,
404 opcookie, auxt->pvnr_mode, pcr);
405 break;
406 }
407
408 case PUFFS_VN_CLOSE:
409 {
410 struct puffs_vnmsg_close *auxt = auxbuf;
411 PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
412
413 if (pops->puffs_node_close == NULL) {
414 error = 0;
415 break;
416 }
417
418 error = pops->puffs_node_close(pu,
419 opcookie, auxt->pvnr_fflag, pcr);
420 break;
421 }
422
423 case PUFFS_VN_ACCESS:
424 {
425 struct puffs_vnmsg_access *auxt = auxbuf;
426 PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
427
428 if (pops->puffs_node_access == NULL) {
429 error = 0;
430 break;
431 }
432
433 error = pops->puffs_node_access(pu,
434 opcookie, auxt->pvnr_mode, pcr);
435 break;
436 }
437
438 case PUFFS_VN_GETATTR:
439 {
440 struct puffs_vnmsg_getattr *auxt = auxbuf;
441 PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
442
443 if (PUFFS_USE_FS_TTL(pu)) {
444 if (pops->puffs_node_getattr_ttl == NULL) {
445 error = EOPNOTSUPP;
446 break;
447 }
448
449 error = pops->puffs_node_getattr_ttl(pu,
450 opcookie, &auxt->pvnr_va, pcr,
451 &auxt->pvnr_va_ttl);
452 } else {
453 if (pops->puffs_node_getattr == NULL) {
454 error = EOPNOTSUPP;
455 break;
456 }
457
458 error = pops->puffs_node_getattr(pu,
459 opcookie, &auxt->pvnr_va, pcr);
460 }
461 break;
462 }
463
464 case PUFFS_VN_SETATTR:
465 {
466 struct puffs_vnmsg_setattr *auxt = auxbuf;
467 PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
468
469 if (PUFFS_USE_FS_TTL(pu)) {
470 if (pops->puffs_node_setattr_ttl == NULL) {
471 error = EOPNOTSUPP;
472 break;
473 }
474
475 error = pops->puffs_node_setattr_ttl(pu,
476 opcookie, &auxt->pvnr_va, pcr,
477 &auxt->pvnr_va_ttl);
478 } else {
479 if (pops->puffs_node_setattr == NULL) {
480 error = EOPNOTSUPP;
481 break;
482 }
483
484 error = pops->puffs_node_setattr(pu,
485 opcookie, &auxt->pvnr_va, pcr);
486 }
487 break;
488 }
489
490 case PUFFS_VN_MMAP:
491 {
492 struct puffs_vnmsg_mmap *auxt = auxbuf;
493 PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
494
495 if (pops->puffs_node_mmap == NULL) {
496 error = 0;
497 break;
498 }
499
500 error = pops->puffs_node_mmap(pu,
501 opcookie, auxt->pvnr_prot, pcr);
502 break;
503 }
504
505 case PUFFS_VN_FSYNC:
506 {
507 struct puffs_vnmsg_fsync *auxt = auxbuf;
508 PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
509
510 if (pops->puffs_node_fsync == NULL) {
511 error = 0;
512 break;
513 }
514
515 error = pops->puffs_node_fsync(pu, opcookie, pcr,
516 auxt->pvnr_flags, auxt->pvnr_offlo,
517 auxt->pvnr_offhi);
518 break;
519 }
520
521 case PUFFS_VN_SEEK:
522 {
523 struct puffs_vnmsg_seek *auxt = auxbuf;
524 PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
525
526 if (pops->puffs_node_seek == NULL) {
527 error = 0;
528 break;
529 }
530
531 error = pops->puffs_node_seek(pu,
532 opcookie, auxt->pvnr_oldoff,
533 auxt->pvnr_newoff, pcr);
534 break;
535 }
536
537 case PUFFS_VN_REMOVE:
538 {
539 struct puffs_vnmsg_remove *auxt = auxbuf;
540 struct puffs_cn pcn;
541 if (pops->puffs_node_remove == NULL) {
542 error = 0;
543 break;
544 }
545
546 pcn.pcn_pkcnp = &auxt->pvnr_cn;
547 PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
548
549 error = pops->puffs_node_remove(pu,
550 opcookie, auxt->pvnr_cookie_targ, &pcn);
551 break;
552 }
553
554 case PUFFS_VN_LINK:
555 {
556 struct puffs_vnmsg_link *auxt = auxbuf;
557 struct puffs_cn pcn;
558 if (pops->puffs_node_link == NULL) {
559 error = 0;
560 break;
561 }
562
563 pcn.pcn_pkcnp = &auxt->pvnr_cn;
564 PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
565
566 if (buildpath) {
567 error = puffs_path_pcnbuild(pu, &pcn, opcookie);
568 if (error)
569 break;
570 }
571
572 error = pops->puffs_node_link(pu,
573 opcookie, auxt->pvnr_cookie_targ, &pcn);
574 if (buildpath)
575 pu->pu_pathfree(pu, &pcn.pcn_po_full);
576
577 break;
578 }
579
580 case PUFFS_VN_RENAME:
581 {
582 struct puffs_vnmsg_rename *auxt = auxbuf;
583 struct puffs_cn pcn_src, pcn_targ;
584 struct puffs_node *pn_src;
585
586 if (pops->puffs_node_rename == NULL) {
587 error = 0;
588 break;
589 }
590
591 pcn_src.pcn_pkcnp = &auxt->pvnr_cn_src;
592 PUFFS_KCREDTOCRED(pcn_src.pcn_cred,
593 &auxt->pvnr_cn_src_cred);
594
595 pcn_targ.pcn_pkcnp = &auxt->pvnr_cn_targ;
596 PUFFS_KCREDTOCRED(pcn_targ.pcn_cred,
597 &auxt->pvnr_cn_targ_cred);
598
599 if (buildpath) {
600 pn_src = auxt->pvnr_cookie_src;
601 pcn_src.pcn_po_full = pn_src->pn_po;
602
603 error = puffs_path_pcnbuild(pu, &pcn_targ,
604 auxt->pvnr_cookie_targdir);
605 if (error)
606 break;
607 }
608
609 error = pops->puffs_node_rename(pu,
610 opcookie, auxt->pvnr_cookie_src,
611 &pcn_src, auxt->pvnr_cookie_targdir,
612 auxt->pvnr_cookie_targ, &pcn_targ);
613
614 if (buildpath) {
615 if (error) {
616 pu->pu_pathfree(pu,
617 &pcn_targ.pcn_po_full);
618 } else {
619 struct puffs_pathinfo pi;
620 struct puffs_pathobj po_old;
621
622 /* handle this node */
623 po_old = pn_src->pn_po;
624 pn_src->pn_po = pcn_targ.pcn_po_full;
625
626 if (pn_src->pn_va.va_type != VDIR) {
627 pu->pu_pathfree(pu, &po_old);
628 break;
629 }
630
631 /* handle all child nodes for DIRs */
632 pi.pi_old = &pcn_src.pcn_po_full;
633 pi.pi_new = &pcn_targ.pcn_po_full;
634
635 PU_LOCK();
636 if (puffs_pn_nodewalk(pu,
637 puffs_path_prefixadj, &pi) != NULL)
638 error = ENOMEM;
639 PU_UNLOCK();
640 pu->pu_pathfree(pu, &po_old);
641 }
642 }
643 break;
644 }
645
646 case PUFFS_VN_MKDIR:
647 {
648 struct puffs_vnmsg_mkdir *auxt = auxbuf;
649 struct puffs_newinfo pni;
650 struct puffs_cn pcn;
651
652 if (pops->puffs_node_mkdir == NULL) {
653 error = 0;
654 break;
655 }
656
657 pcn.pcn_pkcnp = &auxt->pvnr_cn;
658 PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
659
660 memset(&pni, 0, sizeof(pni));
661 pni.pni_cookie = &auxt->pvnr_newnode;
662 pni.pni_va = &auxt->pvnr_va;
663 pni.pni_va_ttl = &auxt->pvnr_va_ttl;
664 pni.pni_cn_ttl = &auxt->pvnr_cn_ttl;
665
666 if (buildpath) {
667 error = puffs_path_pcnbuild(pu, &pcn, opcookie);
668 if (error)
669 break;
670 }
671
672 error = pops->puffs_node_mkdir(pu,
673 opcookie, &pni, &pcn, &auxt->pvnr_va);
674
675 if (buildpath) {
676 if (error) {
677 pu->pu_pathfree(pu, &pcn.pcn_po_full);
678 } else {
679 struct puffs_node *pn;
680
681 pn = PU_CMAP(pu, auxt->pvnr_newnode);
682 pn->pn_po = pcn.pcn_po_full;
683 }
684 }
685
686 break;
687 }
688
689 case PUFFS_VN_RMDIR:
690 {
691 struct puffs_vnmsg_rmdir *auxt = auxbuf;
692 struct puffs_cn pcn;
693 if (pops->puffs_node_rmdir == NULL) {
694 error = 0;
695 break;
696 }
697
698 pcn.pcn_pkcnp = &auxt->pvnr_cn;
699 PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
700
701 error = pops->puffs_node_rmdir(pu,
702 opcookie, auxt->pvnr_cookie_targ, &pcn);
703 break;
704 }
705
706 case PUFFS_VN_SYMLINK:
707 {
708 struct puffs_vnmsg_symlink *auxt = auxbuf;
709 struct puffs_newinfo pni;
710 struct puffs_cn pcn;
711
712 if (pops->puffs_node_symlink == NULL) {
713 error = 0;
714 break;
715 }
716
717 pcn.pcn_pkcnp = &auxt->pvnr_cn;
718 PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
719
720 memset(&pni, 0, sizeof(pni));
721 pni.pni_cookie = &auxt->pvnr_newnode;
722 pni.pni_va = &auxt->pvnr_va;
723 pni.pni_va_ttl = &auxt->pvnr_va_ttl;
724 pni.pni_cn_ttl = &auxt->pvnr_cn_ttl;
725
726 if (buildpath) {
727 error = puffs_path_pcnbuild(pu, &pcn, opcookie);
728 if (error)
729 break;
730 }
731
732 error = pops->puffs_node_symlink(pu,
733 opcookie, &pni, &pcn,
734 &auxt->pvnr_va, auxt->pvnr_link);
735
736 if (buildpath) {
737 if (error) {
738 pu->pu_pathfree(pu, &pcn.pcn_po_full);
739 } else {
740 struct puffs_node *pn;
741
742 pn = PU_CMAP(pu, auxt->pvnr_newnode);
743 pn->pn_po = pcn.pcn_po_full;
744 }
745 }
746
747 break;
748 }
749
750 case PUFFS_VN_READDIR:
751 {
752 struct puffs_vnmsg_readdir *auxt = auxbuf;
753 PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
754 struct dirent *dent;
755 off_t *cookies;
756 size_t res, origcookies;
757
758 if (pops->puffs_node_readdir == NULL) {
759 error = 0;
760 break;
761 }
762
763 if (auxt->pvnr_ncookies) {
764 /* LINTED: pvnr_data is __aligned() */
765 cookies = (off_t *)auxt->pvnr_data;
766 origcookies = auxt->pvnr_ncookies;
767 } else {
768 cookies = NULL;
769 origcookies = 0;
770 }
771 /* LINTED: dentoff is aligned in the kernel */
772 dent = (struct dirent *)
773 (auxt->pvnr_data + auxt->pvnr_dentoff);
774
775 res = auxt->pvnr_resid;
776 error = pops->puffs_node_readdir(pu,
777 opcookie, dent, &auxt->pvnr_offset,
778 &auxt->pvnr_resid, pcr, &auxt->pvnr_eofflag,
779 cookies, &auxt->pvnr_ncookies);
780
781 /* much easier to track non-working NFS */
782 assert(auxt->pvnr_ncookies <= origcookies);
783
784 /* need to move a bit more */
785 preq->preq_buflen = sizeof(struct puffs_vnmsg_readdir)
786 + auxt->pvnr_dentoff + (res - auxt->pvnr_resid);
787 break;
788 }
789
790 case PUFFS_VN_READLINK:
791 {
792 struct puffs_vnmsg_readlink *auxt = auxbuf;
793 PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
794
795 if (pops->puffs_node_readlink == NULL) {
796 error = EOPNOTSUPP;
797 break;
798 }
799
800 /*LINTED*/
801 error = pops->puffs_node_readlink(pu, opcookie, pcr,
802 auxt->pvnr_link, &auxt->pvnr_linklen);
803 break;
804 }
805
806 case PUFFS_VN_RECLAIM:
807 {
808
809 if (pops->puffs_node_reclaim == NULL) {
810 error = 0;
811 break;
812 }
813
814 error = pops->puffs_node_reclaim(pu, opcookie);
815 break;
816 }
817
818 case PUFFS_VN_INACTIVE:
819 {
820
821 if (pops->puffs_node_inactive == NULL) {
822 error = EOPNOTSUPP;
823 break;
824 }
825
826 error = pops->puffs_node_inactive(pu, opcookie);
827 break;
828 }
829
830 case PUFFS_VN_PATHCONF:
831 {
832 struct puffs_vnmsg_pathconf *auxt = auxbuf;
833 if (pops->puffs_node_pathconf == NULL) {
834 error = 0;
835 break;
836 }
837
838 error = pops->puffs_node_pathconf(pu,
839 opcookie, auxt->pvnr_name,
840 &auxt->pvnr_retval);
841 break;
842 }
843
844 case PUFFS_VN_ADVLOCK:
845 {
846 struct puffs_vnmsg_advlock *auxt = auxbuf;
847 if (pops->puffs_node_advlock == NULL) {
848 error = 0;
849 break;
850 }
851
852 error = pops->puffs_node_advlock(pu,
853 opcookie, auxt->pvnr_id, auxt->pvnr_op,
854 &auxt->pvnr_fl, auxt->pvnr_flags);
855 break;
856 }
857
858 case PUFFS_VN_PRINT:
859 {
860 if (pops->puffs_node_print == NULL) {
861 error = 0;
862 break;
863 }
864
865 error = pops->puffs_node_print(pu,
866 opcookie);
867 break;
868 }
869
870 case PUFFS_VN_ABORTOP:
871 {
872 struct puffs_vnmsg_abortop *auxt = auxbuf;
873 struct puffs_cn pcn;
874
875 if (pops->puffs_node_abortop == NULL) {
876 error = 0;
877 break;
878 }
879
880 pcn.pcn_pkcnp = &auxt->pvnr_cn;
881 PUFFS_KCREDTOCRED(pcn.pcn_cred, &auxt->pvnr_cn_cred);
882
883 error = pops->puffs_node_abortop(pu, opcookie, &pcn);
884
885 break;
886 }
887
888 case PUFFS_VN_READ:
889 {
890 struct puffs_vnmsg_read *auxt = auxbuf;
891 PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
892 size_t res;
893
894 if (pops->puffs_node_read == NULL) {
895 error = EIO;
896 break;
897 }
898
899 res = auxt->pvnr_resid;
900 error = pops->puffs_node_read(pu,
901 opcookie, auxt->pvnr_data,
902 auxt->pvnr_offset, &auxt->pvnr_resid,
903 pcr, auxt->pvnr_ioflag);
904
905 /* need to move a bit more */
906 preq->preq_buflen = sizeof(struct puffs_vnmsg_read)
907 + (res - auxt->pvnr_resid);
908 break;
909 }
910
911 case PUFFS_VN_WRITE:
912 {
913 struct puffs_vnmsg_write *auxt = auxbuf;
914 PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
915
916 if (pops->puffs_node_write == NULL) {
917 error = EIO;
918 break;
919 }
920
921 error = pops->puffs_node_write(pu,
922 opcookie, auxt->pvnr_data,
923 auxt->pvnr_offset, &auxt->pvnr_resid,
924 pcr, auxt->pvnr_ioflag);
925
926 /* don't need to move data back to the kernel */
927 preq->preq_buflen = sizeof(struct puffs_vnmsg_write);
928 break;
929 }
930
931 case PUFFS_VN_POLL:
932 {
933 struct puffs_vnmsg_poll *auxt = auxbuf;
934
935 if (pops->puffs_node_poll == NULL) {
936 error = 0;
937
938 /* emulate genfs_poll() */
939 auxt->pvnr_events &= (POLLIN | POLLOUT
940 | POLLRDNORM | POLLWRNORM);
941
942 break;
943 }
944
945 error = pops->puffs_node_poll(pu,
946 opcookie, &auxt->pvnr_events);
947 break;
948 }
949
950 case PUFFS_VN_GETEXTATTR:
951 {
952 struct puffs_vnmsg_getextattr *auxt = auxbuf;
953 PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
954 size_t res, *resp, *sizep;
955 uint8_t *data;
956
957 if (pops->puffs_node_getextattr == NULL) {
958 error = EOPNOTSUPP;
959 break;
960 }
961
962 if (auxt->pvnr_datasize)
963 sizep = &auxt->pvnr_datasize;
964 else
965 sizep = NULL;
966
967 res = auxt->pvnr_resid;
968 if (res > 0) {
969 data = auxt->pvnr_data;
970 resp = &auxt->pvnr_resid;
971 } else {
972 data = NULL;
973 resp = NULL;
974 }
975
976 error = pops->puffs_node_getextattr(pu,
977 opcookie, auxt->pvnr_attrnamespace,
978 auxt->pvnr_attrname, sizep, data, resp, pcr);
979
980 /* need to move a bit more? */
981 preq->preq_buflen =
982 sizeof(struct puffs_vnmsg_getextattr)
983 + (res - auxt->pvnr_resid);
984 break;
985 }
986
987 case PUFFS_VN_SETEXTATTR:
988 {
989 struct puffs_vnmsg_setextattr *auxt = auxbuf;
990 PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
991 size_t *resp;
992 uint8_t *data;
993
994 if (pops->puffs_node_setextattr == NULL) {
995 error = EOPNOTSUPP;
996 break;
997 }
998
999 if (auxt->pvnr_resid > 0) {
1000 data = auxt->pvnr_data;
1001 resp = &auxt->pvnr_resid;
1002 } else {
1003 data = NULL;
1004 resp = NULL;
1005 }
1006
1007 error = pops->puffs_node_setextattr(pu,
1008 opcookie, auxt->pvnr_attrnamespace,
1009 auxt->pvnr_attrname, data, resp, pcr);
1010 break;
1011 }
1012
1013 case PUFFS_VN_LISTEXTATTR:
1014 {
1015 struct puffs_vnmsg_listextattr *auxt = auxbuf;
1016 PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
1017 size_t res, *resp, *sizep;
1018 int flag;
1019 uint8_t *data;
1020
1021 if (pops->puffs_node_listextattr == NULL) {
1022 error = EOPNOTSUPP;
1023 break;
1024 }
1025
1026 if (auxt->pvnr_datasize)
1027 sizep = &auxt->pvnr_datasize;
1028 else
1029 sizep = NULL;
1030
1031 res = auxt->pvnr_resid;
1032 if (res > 0) {
1033 data = auxt->pvnr_data;
1034 resp = &auxt->pvnr_resid;
1035 } else {
1036 data = NULL;
1037 resp = NULL;
1038 }
1039
1040 res = auxt->pvnr_resid;
1041 flag = auxt->pvnr_flag;
1042 error = pops->puffs_node_listextattr(pu,
1043 opcookie, auxt->pvnr_attrnamespace,
1044 sizep, data, resp, flag, pcr);
1045
1046 /* need to move a bit more? */
1047 preq->preq_buflen =
1048 sizeof(struct puffs_vnmsg_listextattr)
1049 + (res - auxt->pvnr_resid);
1050 break;
1051 }
1052
1053 case PUFFS_VN_DELETEEXTATTR:
1054 {
1055 struct puffs_vnmsg_deleteextattr *auxt = auxbuf;
1056 PUFFS_MAKECRED(pcr, &auxt->pvnr_cred);
1057
1058 if (pops->puffs_node_deleteextattr == NULL) {
1059 error = EOPNOTSUPP;
1060 break;
1061 }
1062
1063 error = pops->puffs_node_deleteextattr(pu,
1064 opcookie, auxt->pvnr_attrnamespace,
1065 auxt->pvnr_attrname, pcr);
1066 break;
1067 }
1068
1069 default:
1070 printf("inval op %d\n", preq->preq_optype);
1071 error = EINVAL;
1072 break;
1073 }
1074
1075 #if 0
1076 /* not issued by kernel currently */
1077 } else if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_CACHE) {
1078 struct puffs_cacheinfo *pci = (void *)preq;
1079
1080 if (pu->pu_ops.puffs_cache_write) {
1081 pu->pu_ops.puffs_cache_write(pu, preq->preq_cookie,
1082 pci->pcache_nruns, pci->pcache_runs);
1083 }
1084 error = 0;
1085 #endif
1086
1087 } else if (PUFFSOP_OPCLASS(preq->preq_opclass) == PUFFSOP_ERROR) {
1088 struct puffs_error *perr = (void *)preq;
1089
1090 pu->pu_errnotify(pu, preq->preq_optype,
1091 perr->perr_error, perr->perr_str, preq->preq_cookie);
1092 error = 0;
1093 } else {
1094 /*
1095 * I guess the kernel sees this one coming also
1096 */
1097 error = EINVAL;
1098 }
1099
1100 out:
1101 preq->preq_rv = error;
1102
1103 if (pu->pu_oppost)
1104 pu->pu_oppost(pu);
1105
1106 pcc->pcc_flags |= PCC_DONE;
1107 }
1108