kernel - slab allocator - Refactor struct kmemusage
[dragonfly.git] / sys / kern / vfs_vopops.c
1 /*
2  * Copyright (c) 2004,2009 The DragonFly Project.  All rights reserved.
3  * 
4  * This code is derived from software contributed to The DragonFly Project
5  * by Matthew Dillon <dillon@backplane.com>
6  * 
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in
15  *    the documentation and/or other materials provided with the
16  *    distribution.
17  * 3. Neither the name of The DragonFly Project nor the names of its
18  *    contributors may be used to endorse or promote products derived
19  *    from this software without specific, prior written permission.
20  * 
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32  * SUCH DAMAGE.
33  */
34 /*
35  * Implement vnode ops wrappers.  All vnode ops are wrapped through
36  * these functions.
37  *
38  * These wrappers are responsible for hanlding all MPSAFE issues related
39  * to a vnode operation.
40  */
41
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/buf.h>
45 #include <sys/conf.h>
46 #include <sys/dirent.h>
47 #include <sys/domain.h>
48 #include <sys/eventhandler.h>
49 #include <sys/fcntl.h>
50 #include <sys/kernel.h>
51 #include <sys/kthread.h>
52 #include <sys/malloc.h>
53 #include <sys/mbuf.h>
54 #include <sys/mount.h>
55 #include <sys/proc.h>
56 #include <sys/namei.h>
57 #include <sys/reboot.h>
58 #include <sys/socket.h>
59 #include <sys/stat.h>
60 #include <sys/sysctl.h>
61 #include <sys/syslog.h>
62 #include <sys/vmmeter.h>
63 #include <sys/vnode.h>
64 #include <sys/vfsops.h>
65 #include <sys/sysmsg.h>
66
67 #include <machine/limits.h>
68
69 #include <vm/vm.h>
70 #include <vm/vm_object.h>
71 #include <vm/vm_extern.h>
72 #include <vm/vm_kern.h>
73 #include <vm/pmap.h>
74 #include <vm/vm_map.h>
75 #include <vm/vm_page.h>
76 #include <vm/vm_pager.h>
77 #include <vm/vnode_pager.h>
78 #include <vm/vm_zone.h>
79
80 #include <sys/buf2.h>
81 #include <sys/thread2.h>
82 #include <sys/mplock2.h>
83
84 #define VDESCNAME(name) __CONCAT(__CONCAT(vop_,name),_desc)
85
86 #define VNODEOP_DESC_INIT(name)                                         \
87         struct syslink_desc VDESCNAME(name) = {                         \
88                 __offsetof(struct vop_ops, __CONCAT(vop_, name)),       \
89                 #name }
90
91 VNODEOP_DESC_INIT(default);
92 VNODEOP_DESC_INIT(old_lookup);
93 VNODEOP_DESC_INIT(old_create);
94 VNODEOP_DESC_INIT(old_whiteout);
95 VNODEOP_DESC_INIT(old_mknod);
96 VNODEOP_DESC_INIT(open);
97 VNODEOP_DESC_INIT(close);
98 VNODEOP_DESC_INIT(access);
99 VNODEOP_DESC_INIT(getattr);
100 VNODEOP_DESC_INIT(setattr);
101 VNODEOP_DESC_INIT(read);
102 VNODEOP_DESC_INIT(write);
103 VNODEOP_DESC_INIT(ioctl);
104 VNODEOP_DESC_INIT(poll);
105 VNODEOP_DESC_INIT(kqfilter);
106 VNODEOP_DESC_INIT(mmap);
107 VNODEOP_DESC_INIT(fsync);
108 VNODEOP_DESC_INIT(old_remove);
109 VNODEOP_DESC_INIT(old_link);
110 VNODEOP_DESC_INIT(old_rename);
111
112 VNODEOP_DESC_INIT(old_mkdir);
113 VNODEOP_DESC_INIT(old_rmdir);
114 VNODEOP_DESC_INIT(old_symlink);
115 VNODEOP_DESC_INIT(readdir);
116 VNODEOP_DESC_INIT(readlink);
117 VNODEOP_DESC_INIT(inactive);
118 VNODEOP_DESC_INIT(reclaim);
119 VNODEOP_DESC_INIT(bmap);
120 VNODEOP_DESC_INIT(strategy);
121 VNODEOP_DESC_INIT(print);
122 VNODEOP_DESC_INIT(pathconf);
123 VNODEOP_DESC_INIT(advlock);
124 VNODEOP_DESC_INIT(balloc);
125 VNODEOP_DESC_INIT(reallocblks);
126 VNODEOP_DESC_INIT(getpages);
127 VNODEOP_DESC_INIT(putpages);
128 VNODEOP_DESC_INIT(freeblks);
129 VNODEOP_DESC_INIT(getacl);
130 VNODEOP_DESC_INIT(setacl);
131 VNODEOP_DESC_INIT(aclcheck);
132 VNODEOP_DESC_INIT(getextattr);
133 VNODEOP_DESC_INIT(setextattr);
134 VNODEOP_DESC_INIT(mountctl);
135 VNODEOP_DESC_INIT(markatime);
136
137 VNODEOP_DESC_INIT(nresolve);
138 VNODEOP_DESC_INIT(nlookupdotdot);
139 VNODEOP_DESC_INIT(ncreate);
140 VNODEOP_DESC_INIT(nmkdir);
141 VNODEOP_DESC_INIT(nmknod);
142 VNODEOP_DESC_INIT(nlink);
143 VNODEOP_DESC_INIT(nsymlink);
144 VNODEOP_DESC_INIT(nwhiteout);
145 VNODEOP_DESC_INIT(nremove);
146 VNODEOP_DESC_INIT(nrmdir);
147 VNODEOP_DESC_INIT(nrename);
148
149 #define DO_OPS(ops, error, ap, vop_field)       \
150         error = ops->vop_field(ap);
151
152 /************************************************************************
153  *              PRIMARY HIGH LEVEL VNODE OPERATIONS CALLS               *
154  ************************************************************************
155  *
156  * These procedures are called directly from the kernel and/or fileops 
157  * code to perform file/device operations on the system.
158  *
159  * NOTE: The old namespace api functions such as vop_rename() are no
160  *       longer available for general use and have been renamed to
161  *       vop_old_*().  Only the code in vfs_default.c is allowed to call
162  *       those ops.
163  *
164  * NOTE: The VFS_MPLOCK*() macros handle mounts which do not set
165  *       MNTK_MPSAFE or MNTK_xx_MPSAFE.
166  *
167  * MPSAFE
168  */
169
170 int
171 vop_old_lookup(struct vop_ops *ops, struct vnode *dvp,
172         struct vnode **vpp, struct componentname *cnp)
173 {
174         struct vop_old_lookup_args ap;
175         VFS_MPLOCK_DECLARE;
176         int error;
177
178         ap.a_head.a_desc = &vop_old_lookup_desc;
179         ap.a_head.a_ops = ops;
180         ap.a_dvp = dvp;
181         ap.a_vpp = vpp;
182         ap.a_cnp = cnp;
183         VFS_MPLOCK1(dvp->v_mount);
184         DO_OPS(ops, error, &ap, vop_old_lookup);
185         VFS_MPUNLOCK(dvp->v_mount);
186         return(error);
187 }
188
189 /*
190  * MPSAFE
191  */
192 int
193 vop_old_create(struct vop_ops *ops, struct vnode *dvp,
194         struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
195 {
196         struct vop_old_create_args ap;
197         VFS_MPLOCK_DECLARE;
198         int error;
199
200         ap.a_head.a_desc = &vop_old_create_desc;
201         ap.a_head.a_ops = ops;
202         ap.a_dvp = dvp;
203         ap.a_vpp = vpp;
204         ap.a_cnp = cnp;
205         ap.a_vap = vap;
206
207         VFS_MPLOCK1(dvp->v_mount);
208         DO_OPS(ops, error, &ap, vop_old_create);
209         VFS_MPUNLOCK(dvp->v_mount);
210         return(error);
211 }
212
213 /*
214  * MPSAFE
215  */
216 int
217 vop_old_whiteout(struct vop_ops *ops, struct vnode *dvp,
218         struct componentname *cnp, int flags)
219 {
220         struct vop_old_whiteout_args ap;
221         VFS_MPLOCK_DECLARE;
222         int error;
223
224         ap.a_head.a_desc = &vop_old_whiteout_desc;
225         ap.a_head.a_ops = ops;
226         ap.a_dvp = dvp;
227         ap.a_cnp = cnp;
228         ap.a_flags = flags;
229
230         VFS_MPLOCK1(dvp->v_mount);
231         DO_OPS(ops, error, &ap, vop_old_whiteout);
232         VFS_MPUNLOCK(dvp->v_mount);
233         return(error);
234 }
235
236 /*
237  * MPSAFE
238  */
239 int
240 vop_old_mknod(struct vop_ops *ops, struct vnode *dvp, 
241         struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
242 {
243         struct vop_old_mknod_args ap;
244         VFS_MPLOCK_DECLARE;
245         int error;
246
247         ap.a_head.a_desc = &vop_old_mknod_desc;
248         ap.a_head.a_ops = ops;
249         ap.a_dvp = dvp;
250         ap.a_vpp = vpp;
251         ap.a_cnp = cnp;
252         ap.a_vap = vap;
253
254         VFS_MPLOCK1(dvp->v_mount);
255         DO_OPS(ops, error, &ap, vop_old_mknod);
256         VFS_MPUNLOCK(dvp->v_mount);
257         return(error);
258 }
259
260 /*
261  * NOTE: VAGE is always cleared when calling VOP_OPEN().
262  */
263 int
264 vop_open(struct vop_ops *ops, struct vnode *vp, int mode, struct ucred *cred,
265         struct file *fp)
266 {
267         struct vop_open_args ap;
268         VFS_MPLOCK_DECLARE;
269         int error;
270
271         /*
272          * Decrement 3-2-1-0.  Does not decrement beyond 0
273          */
274         if (vp->v_flag & VAGE0) {
275                 vclrflags(vp, VAGE0);
276         } else if (vp->v_flag & VAGE1) {
277                 vclrflags(vp, VAGE1);
278                 vsetflags(vp, VAGE0);
279         }
280
281         ap.a_head.a_desc = &vop_open_desc;
282         ap.a_head.a_ops = ops;
283         ap.a_vp = vp;
284         ap.a_fp = fp;
285         ap.a_mode = mode;
286         ap.a_cred = cred;
287
288         VFS_MPLOCK1(vp->v_mount);
289         DO_OPS(ops, error, &ap, vop_open);
290         VFS_MPUNLOCK(vp->v_mount);
291         return(error);
292 }
293
294 /*
295  * MPSAFE
296  */
297 int
298 vop_close(struct vop_ops *ops, struct vnode *vp, int fflag)
299 {
300         struct vop_close_args ap;
301         VFS_MPLOCK_DECLARE;
302         int error;
303
304         ap.a_head.a_desc = &vop_close_desc;
305         ap.a_head.a_ops = ops;
306         ap.a_vp = vp;
307         ap.a_fflag = fflag;
308
309         VFS_MPLOCK1(vp->v_mount);
310         DO_OPS(ops, error, &ap, vop_close);
311         VFS_MPUNLOCK(vp->v_mount);
312         return(error);
313 }
314
315 /*
316  * MPSAFE
317  */
318 int
319 vop_access(struct vop_ops *ops, struct vnode *vp, int mode, int flags,
320            struct ucred *cred)
321 {
322         struct vop_access_args ap;
323         VFS_MPLOCK_DECLARE;
324         int error;
325
326         ap.a_head.a_desc = &vop_access_desc;
327         ap.a_head.a_ops = ops;
328         ap.a_vp = vp;
329         ap.a_mode = mode;
330         ap.a_flags = flags;
331         ap.a_cred = cred;
332
333         VFS_MPLOCK1(vp->v_mount);
334         DO_OPS(ops, error, &ap, vop_access);
335         VFS_MPUNLOCK(vp->v_mount);
336         return(error);
337 }
338
339 /*
340  * MPSAFE
341  */
342 int
343 vop_getattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap)
344 {
345         struct vop_getattr_args ap;
346         VFS_MPLOCK_DECLARE;
347         int error;
348
349         ap.a_head.a_desc = &vop_getattr_desc;
350         ap.a_head.a_ops = ops;
351         ap.a_vp = vp;
352         ap.a_vap = vap;
353
354         VFS_MPLOCK_FLAG(vp->v_mount, MNTK_GA_MPSAFE);
355         DO_OPS(ops, error, &ap, vop_getattr);
356         VFS_MPUNLOCK(vp->v_mount);
357
358         return(error);
359 }
360
361 /*
362  * MPSAFE
363  */
364 int
365 vop_setattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap,
366         struct ucred *cred)
367 {
368         struct vop_setattr_args ap;
369         VFS_MPLOCK_DECLARE;
370         int error;
371
372         ap.a_head.a_desc = &vop_setattr_desc;
373         ap.a_head.a_ops = ops;
374         ap.a_vp = vp;
375         ap.a_vap = vap;
376         ap.a_cred = cred;
377
378         VFS_MPLOCK1(vp->v_mount);
379         DO_OPS(ops, error, &ap, vop_setattr);
380         VFS_MPUNLOCK(vp->v_mount);
381         return(error);
382 }
383
384 /*
385  * MPSAFE
386  */
387 int
388 vop_read(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
389         struct ucred *cred)
390 {
391         struct vop_read_args ap;
392         VFS_MPLOCK_DECLARE;
393         int error;
394
395         ap.a_head.a_desc = &vop_read_desc;
396         ap.a_head.a_ops = ops;
397         ap.a_vp = vp;
398         ap.a_uio = uio;
399         ap.a_ioflag = ioflag;
400         ap.a_cred = cred;
401
402         VFS_MPLOCK_FLAG(vp->v_mount, MNTK_RD_MPSAFE);
403         DO_OPS(ops, error, &ap, vop_read);
404         VFS_MPUNLOCK(vp->v_mount);
405         return(error);
406 }
407
408 /*
409  * MPSAFE
410  */
411 int
412 vop_write(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
413         struct ucred *cred)
414 {
415         struct vop_write_args ap;
416         VFS_MPLOCK_DECLARE;
417         int error;
418
419         ap.a_head.a_desc = &vop_write_desc;
420         ap.a_head.a_ops = ops;
421         ap.a_vp = vp;
422         ap.a_uio = uio;
423         ap.a_ioflag = ioflag;
424         ap.a_cred = cred;
425
426         VFS_MPLOCK_FLAG(vp->v_mount, MNTK_WR_MPSAFE);
427         DO_OPS(ops, error, &ap, vop_write);
428         VFS_MPUNLOCK(vp->v_mount);
429         return(error);
430 }
431
432 /*
433  * MPSAFE
434  */
435 int
436 vop_ioctl(struct vop_ops *ops, struct vnode *vp, u_long command, caddr_t data,
437         int fflag, struct ucred *cred, struct sysmsg *msg)
438 {
439         struct vop_ioctl_args ap;
440         VFS_MPLOCK_DECLARE;
441         int error;
442
443         ap.a_head.a_desc = &vop_ioctl_desc;
444         ap.a_head.a_ops = ops;
445         ap.a_vp = vp;
446         ap.a_command = command;
447         ap.a_data = data;
448         ap.a_fflag = fflag;
449         ap.a_cred = cred;
450         ap.a_sysmsg = msg;
451
452         VFS_MPLOCK1(vp->v_mount);
453         DO_OPS(ops, error, &ap, vop_ioctl);
454         VFS_MPUNLOCK(vp->v_mount);
455         return(error);
456 }
457
458 /*
459  * MPSAFE
460  */
461 int
462 vop_poll(struct vop_ops *ops, struct vnode *vp, int events, struct ucred *cred)
463 {
464         struct vop_poll_args ap;
465         VFS_MPLOCK_DECLARE;
466         int error;
467
468         ap.a_head.a_desc = &vop_poll_desc;
469         ap.a_head.a_ops = ops;
470         ap.a_vp = vp;
471         ap.a_events = events;
472         ap.a_cred = cred;
473
474         VFS_MPLOCK1(vp->v_mount);
475         DO_OPS(ops, error, &ap, vop_poll);
476         VFS_MPUNLOCK(vp->v_mount);
477         return(error);
478 }
479
480 /*
481  * MPSAFE
482  */
483 int
484 vop_kqfilter(struct vop_ops *ops, struct vnode *vp, struct knote *kn)
485 {
486         struct vop_kqfilter_args ap;
487         VFS_MPLOCK_DECLARE;
488         int error;
489
490         ap.a_head.a_desc = &vop_kqfilter_desc;
491         ap.a_head.a_ops = ops;
492         ap.a_vp = vp;
493         ap.a_kn = kn;
494
495         VFS_MPLOCK1(vp->v_mount);
496         DO_OPS(ops, error, &ap, vop_kqfilter);
497         VFS_MPUNLOCK(vp->v_mount);
498         return(error);
499 }
500
501 /*
502  * MPSAFE
503  */
504 int
505 vop_mmap(struct vop_ops *ops, struct vnode *vp, int fflags, struct ucred *cred)
506 {
507         struct vop_mmap_args ap;
508         VFS_MPLOCK_DECLARE;
509         int error;
510
511         ap.a_head.a_desc = &vop_mmap_desc;
512         ap.a_head.a_ops = ops;
513         ap.a_vp = vp;
514         ap.a_fflags = fflags;
515         ap.a_cred = cred;
516
517         VFS_MPLOCK1(vp->v_mount);
518         DO_OPS(ops, error, &ap, vop_mmap);
519         VFS_MPUNLOCK(vp->v_mount);
520         return(error);
521 }
522
523 /*
524  * MPSAFE
525  */
526 int
527 vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor, int flags)
528 {
529         struct vop_fsync_args ap;
530         VFS_MPLOCK_DECLARE;
531         int error;
532
533         ap.a_head.a_desc = &vop_fsync_desc;
534         ap.a_head.a_ops = ops;
535         ap.a_vp = vp;
536         ap.a_waitfor = waitfor;
537         ap.a_flags = flags;
538
539         VFS_MPLOCK1(vp->v_mount);
540         DO_OPS(ops, error, &ap, vop_fsync);
541         VFS_MPUNLOCK(vp->v_mount);
542         return(error);
543 }
544
545 /*
546  * MPSAFE
547  */
548 int
549 vop_old_remove(struct vop_ops *ops, struct vnode *dvp, 
550         struct vnode *vp, struct componentname *cnp)
551 {
552         struct vop_old_remove_args ap;
553         VFS_MPLOCK_DECLARE;
554         int error;
555
556         ap.a_head.a_desc = &vop_old_remove_desc;
557         ap.a_head.a_ops = ops;
558         ap.a_dvp = dvp;
559         ap.a_vp = vp;
560         ap.a_cnp = cnp;
561
562         VFS_MPLOCK1(dvp->v_mount);
563         DO_OPS(ops, error, &ap, vop_old_remove);
564         VFS_MPUNLOCK(dvp->v_mount);
565         return(error);
566 }
567
568 /*
569  * MPSAFE
570  */
571 int
572 vop_old_link(struct vop_ops *ops, struct vnode *tdvp, 
573         struct vnode *vp, struct componentname *cnp)
574 {
575         struct vop_old_link_args ap;
576         VFS_MPLOCK_DECLARE;
577         int error;
578
579         ap.a_head.a_desc = &vop_old_link_desc;
580         ap.a_head.a_ops = ops;
581         ap.a_tdvp = tdvp;
582         ap.a_vp = vp;
583         ap.a_cnp = cnp;
584
585         VFS_MPLOCK1(tdvp->v_mount);
586         DO_OPS(ops, error, &ap, vop_old_link);
587         VFS_MPUNLOCK(tdvp->v_mount);
588         return(error);
589 }
590
591 /*
592  * MPSAFE
593  */
594 int
595 vop_old_rename(struct vop_ops *ops, 
596            struct vnode *fdvp, struct vnode *fvp, struct componentname *fcnp,
597            struct vnode *tdvp, struct vnode *tvp, struct componentname *tcnp)
598 {
599         struct vop_old_rename_args ap;
600         VFS_MPLOCK_DECLARE;
601         int error;
602
603         ap.a_head.a_desc = &vop_old_rename_desc;
604         ap.a_head.a_ops = ops;
605         ap.a_fdvp = fdvp;
606         ap.a_fvp = fvp;
607         ap.a_fcnp = fcnp;
608         ap.a_tdvp = tdvp;
609         ap.a_tvp = tvp;
610         ap.a_tcnp = tcnp;
611
612         VFS_MPLOCK1(tdvp->v_mount);
613         DO_OPS(ops, error, &ap, vop_old_rename);
614         VFS_MPUNLOCK(tdvp->v_mount);
615         return(error);
616 }
617
618 /*
619  * MPSAFE
620  */
621 int
622 vop_old_mkdir(struct vop_ops *ops, struct vnode *dvp, 
623         struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
624 {
625         struct vop_old_mkdir_args ap;
626         VFS_MPLOCK_DECLARE;
627         int error;
628
629         ap.a_head.a_desc = &vop_old_mkdir_desc;
630         ap.a_head.a_ops = ops;
631         ap.a_dvp = dvp;
632         ap.a_vpp = vpp;
633         ap.a_cnp = cnp;
634         ap.a_vap = vap;
635
636         VFS_MPLOCK1(dvp->v_mount);
637         DO_OPS(ops, error, &ap, vop_old_mkdir);
638         VFS_MPUNLOCK(dvp->v_mount);
639         return(error);
640 }
641
642 /*
643  * MPSAFE
644  */
645 int
646 vop_old_rmdir(struct vop_ops *ops, struct vnode *dvp, 
647         struct vnode *vp, struct componentname *cnp)
648 {
649         struct vop_old_rmdir_args ap;
650         VFS_MPLOCK_DECLARE;
651         int error;
652
653         ap.a_head.a_desc = &vop_old_rmdir_desc;
654         ap.a_head.a_ops = ops;
655         ap.a_dvp = dvp;
656         ap.a_vp = vp;
657         ap.a_cnp = cnp;
658
659         VFS_MPLOCK1(dvp->v_mount);
660         DO_OPS(ops, error, &ap, vop_old_rmdir);
661         VFS_MPUNLOCK(dvp->v_mount);
662         return(error);
663 }
664
665 /*
666  * MPSAFE
667  */
668 int
669 vop_old_symlink(struct vop_ops *ops, struct vnode *dvp,
670         struct vnode **vpp, struct componentname *cnp,
671         struct vattr *vap, char *target)
672 {
673         struct vop_old_symlink_args ap;
674         VFS_MPLOCK_DECLARE;
675         int error;
676
677         ap.a_head.a_desc = &vop_old_symlink_desc;
678         ap.a_head.a_ops = ops;
679         ap.a_dvp = dvp;
680         ap.a_vpp = vpp;
681         ap.a_cnp = cnp;
682         ap.a_vap = vap;
683         ap.a_target = target;
684
685         VFS_MPLOCK1(dvp->v_mount);
686         DO_OPS(ops, error, &ap, vop_old_symlink);
687         VFS_MPUNLOCK(dvp->v_mount);
688         return(error);
689 }
690
691 /*
692  * MPSAFE
693  */
694 int
695 vop_readdir(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
696         struct ucred *cred, int *eofflag, int *ncookies, off_t **cookies)
697 {
698         struct vop_readdir_args ap;
699         VFS_MPLOCK_DECLARE;
700         int error;
701
702         ap.a_head.a_desc = &vop_readdir_desc;
703         ap.a_head.a_ops = ops;
704         ap.a_vp = vp;
705         ap.a_uio = uio;
706         ap.a_cred = cred;
707         ap.a_eofflag = eofflag;
708         ap.a_ncookies = ncookies;
709         ap.a_cookies = cookies;
710
711         VFS_MPLOCK1(vp->v_mount);
712         DO_OPS(ops, error, &ap, vop_readdir);
713         VFS_MPUNLOCK(vp->v_mount);
714         return(error);
715 }
716
717 /*
718  * MPSAFE
719  */
720 int
721 vop_readlink(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
722         struct ucred *cred)
723 {
724         struct vop_readlink_args ap;
725         VFS_MPLOCK_DECLARE;
726         int error;
727
728         ap.a_head.a_desc = &vop_readlink_desc;
729         ap.a_head.a_ops = ops;
730         ap.a_vp = vp;
731         ap.a_uio = uio;
732         ap.a_cred = cred;
733
734         VFS_MPLOCK1(vp->v_mount);
735         DO_OPS(ops, error, &ap, vop_readlink);
736         VFS_MPUNLOCK(vp->v_mount);
737         return(error);
738 }
739
740 /*
741  * MPSAFE
742  */
743 int
744 vop_inactive(struct vop_ops *ops, struct vnode *vp)
745 {
746         struct vop_inactive_args ap;
747         VFS_MPLOCK_DECLARE;
748         int error;
749
750         ap.a_head.a_desc = &vop_inactive_desc;
751         ap.a_head.a_ops = ops;
752         ap.a_vp = vp;
753
754         VFS_MPLOCK_FLAG(vp->v_mount, MNTK_IN_MPSAFE);
755         DO_OPS(ops, error, &ap, vop_inactive);
756         VFS_MPUNLOCK(vp->v_mount);
757         return(error);
758 }
759
760 /*
761  * MPSAFE
762  */
763 int
764 vop_reclaim(struct vop_ops *ops, struct vnode *vp)
765 {
766         struct vop_reclaim_args ap;
767         VFS_MPLOCK_DECLARE;
768         int error;
769
770         ap.a_head.a_desc = &vop_reclaim_desc;
771         ap.a_head.a_ops = ops;
772         ap.a_vp = vp;
773
774         VFS_MPLOCK1(vp->v_mount);
775         DO_OPS(ops, error, &ap, vop_reclaim);
776         VFS_MPUNLOCK(vp->v_mount);
777         return(error);
778 }
779
780 /*
781  * MPSAFE
782  */
783 int
784 vop_bmap(struct vop_ops *ops, struct vnode *vp, off_t loffset,
785         off_t *doffsetp, int *runp, int *runb, buf_cmd_t cmd)
786 {
787         struct vop_bmap_args ap;
788         VFS_MPLOCK_DECLARE;
789         int error;
790
791         ap.a_head.a_desc = &vop_bmap_desc;
792         ap.a_head.a_ops = ops;
793         ap.a_vp = vp;
794         ap.a_loffset = loffset;
795         ap.a_doffsetp = doffsetp;
796         ap.a_runp = runp;
797         ap.a_runb = runb;
798         ap.a_cmd = cmd;
799
800         VFS_MPLOCK1(vp->v_mount);
801         DO_OPS(ops, error, &ap, vop_bmap);
802         VFS_MPUNLOCK(vp->v_mount);
803         return(error);
804 }
805
806 /*
807  * MPSAFE
808  */
809 int
810 vop_strategy(struct vop_ops *ops, struct vnode *vp, struct bio *bio)
811 {
812         struct vop_strategy_args ap;
813         VFS_MPLOCK_DECLARE;
814         int error;
815
816         ap.a_head.a_desc = &vop_strategy_desc;
817         ap.a_head.a_ops = ops;
818         ap.a_vp = vp;
819         ap.a_bio = bio;
820
821         if (vp->v_mount) {
822                 VFS_MPLOCK1(vp->v_mount);
823                 DO_OPS(ops, error, &ap, vop_strategy);
824                 VFS_MPUNLOCK(vp->v_mount);
825         } else {
826                 /* ugly hack for swap */
827                 get_mplock();
828                 DO_OPS(ops, error, &ap, vop_strategy);
829                 rel_mplock();
830         }
831         return(error);
832 }
833
834 /*
835  * MPSAFE
836  */
837 int
838 vop_print(struct vop_ops *ops, struct vnode *vp)
839 {
840         struct vop_print_args ap;
841         VFS_MPLOCK_DECLARE;
842         int error;
843
844         ap.a_head.a_desc = &vop_print_desc;
845         ap.a_head.a_ops = ops;
846         ap.a_vp = vp;
847
848         VFS_MPLOCK1(vp->v_mount);
849         DO_OPS(ops, error, &ap, vop_print);
850         VFS_MPUNLOCK(vp->v_mount);
851         return(error);
852 }
853
854 /*
855  * MPSAFE
856  */
857 int
858 vop_pathconf(struct vop_ops *ops, struct vnode *vp, int name,
859         register_t *retval)
860 {
861         struct vop_pathconf_args ap;
862         VFS_MPLOCK_DECLARE;
863         int error;
864
865         ap.a_head.a_desc = &vop_pathconf_desc;
866         ap.a_head.a_ops = ops;
867         ap.a_vp = vp;
868         ap.a_name = name;
869         ap.a_retval = retval;
870
871         VFS_MPLOCK1(vp->v_mount);
872         DO_OPS(ops, error, &ap, vop_pathconf);
873         VFS_MPUNLOCK(vp->v_mount);
874         return(error);
875 }
876
877 /*
878  * MPSAFE
879  */
880 int
881 vop_advlock(struct vop_ops *ops, struct vnode *vp, caddr_t id, int op,
882         struct flock *fl, int flags)
883 {
884         struct vop_advlock_args ap;
885         VFS_MPLOCK_DECLARE;
886         int error;
887
888         ap.a_head.a_desc = &vop_advlock_desc;
889         ap.a_head.a_ops = ops;
890         ap.a_vp = vp;
891         ap.a_id = id;
892         ap.a_op = op;
893         ap.a_fl = fl;
894         ap.a_flags = flags;
895
896         VFS_MPLOCK1(vp->v_mount);
897         DO_OPS(ops, error, &ap, vop_advlock);
898         VFS_MPUNLOCK(vp->v_mount);
899         return(error);
900 }
901
902 /*
903  * MPSAFE
904  */
905 int
906 vop_balloc(struct vop_ops *ops, struct vnode *vp, off_t startoffset,
907         int size, struct ucred *cred, int flags,
908         struct buf **bpp)
909 {
910         struct vop_balloc_args ap;
911         VFS_MPLOCK_DECLARE;
912         int error;
913
914         ap.a_head.a_desc = &vop_balloc_desc;
915         ap.a_head.a_ops = ops;
916         ap.a_vp = vp;
917         ap.a_startoffset = startoffset;
918         ap.a_size = size;
919         ap.a_cred = cred;
920         ap.a_flags = flags;
921         ap.a_bpp = bpp;
922
923         VFS_MPLOCK1(vp->v_mount);
924         DO_OPS(ops, error, &ap, vop_balloc);
925         VFS_MPUNLOCK(vp->v_mount);
926         return(error);
927 }
928
929 /*
930  * MPSAFE
931  */
932 int
933 vop_reallocblks(struct vop_ops *ops, struct vnode *vp,
934         struct cluster_save *buflist)
935 {
936         struct vop_reallocblks_args ap;
937         VFS_MPLOCK_DECLARE;
938         int error;
939
940         ap.a_head.a_desc = &vop_reallocblks_desc;
941         ap.a_head.a_ops = ops;
942         ap.a_vp = vp;
943         ap.a_buflist = buflist;
944
945         VFS_MPLOCK1(vp->v_mount);
946         DO_OPS(ops, error, &ap, vop_reallocblks);
947         VFS_MPUNLOCK(vp->v_mount);
948         return(error);
949 }
950
951 /*
952  * MPSAFE
953  */
954 int
955 vop_getpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
956         int reqpage, vm_ooffset_t offset, int seqaccess)
957 {
958         struct vop_getpages_args ap;
959         VFS_MPLOCK_DECLARE;
960         int error;
961
962         ap.a_head.a_desc = &vop_getpages_desc;
963         ap.a_head.a_ops = ops;
964         ap.a_vp = vp;
965         ap.a_m = m;
966         ap.a_count = count;
967         ap.a_reqpage = reqpage;
968         ap.a_offset = offset;
969         ap.a_seqaccess = seqaccess;
970
971         VFS_MPLOCK1(vp->v_mount);
972         DO_OPS(ops, error, &ap, vop_getpages);
973         VFS_MPUNLOCK(vp->v_mount);
974         return(error);
975 }
976
977 /*
978  * MPSAFE
979  */
980 int
981 vop_putpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
982         int sync, int *rtvals, vm_ooffset_t offset)
983 {
984         struct vop_putpages_args ap;
985         VFS_MPLOCK_DECLARE;
986         int error;
987
988         ap.a_head.a_desc = &vop_putpages_desc;
989         ap.a_head.a_ops = ops;
990         ap.a_vp = vp;
991         ap.a_m = m;
992         ap.a_count = count;
993         ap.a_sync = sync;
994         ap.a_rtvals = rtvals;
995         ap.a_offset = offset;
996
997         VFS_MPLOCK1(vp->v_mount);
998         DO_OPS(ops, error, &ap, vop_putpages);
999         VFS_MPUNLOCK(vp->v_mount);
1000         return(error);
1001 }
1002
1003 /*
1004  * MPSAFE
1005  */
1006 int
1007 vop_freeblks(struct vop_ops *ops, struct vnode *vp, off_t offset, int length)
1008 {
1009         struct vop_freeblks_args ap;
1010         VFS_MPLOCK_DECLARE;
1011         int error;
1012
1013         ap.a_head.a_desc = &vop_freeblks_desc;
1014         ap.a_head.a_ops = ops;
1015         ap.a_vp = vp;
1016         ap.a_offset = offset;
1017         ap.a_length = length;
1018
1019         VFS_MPLOCK1(vp->v_mount);
1020         DO_OPS(ops, error, &ap, vop_freeblks);
1021         VFS_MPUNLOCK(vp->v_mount);
1022         return(error);
1023 }
1024
1025 /*
1026  * MPSAFE
1027  */
1028 int
1029 vop_getacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1030         struct acl *aclp, struct ucred *cred)
1031 {
1032         struct vop_getacl_args ap;
1033         VFS_MPLOCK_DECLARE;
1034         int error;
1035
1036         ap.a_head.a_desc = &vop_getacl_desc;
1037         ap.a_head.a_ops = ops;
1038         ap.a_vp = vp;
1039         ap.a_type = type;
1040         ap.a_aclp = aclp;
1041         ap.a_cred = cred;
1042
1043         VFS_MPLOCK1(vp->v_mount);
1044         DO_OPS(ops, error, &ap, vop_getacl);
1045         VFS_MPUNLOCK(vp->v_mount);
1046         return(error);
1047 }
1048
1049 /*
1050  * MPSAFE
1051  */
1052 int
1053 vop_setacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1054         struct acl *aclp, struct ucred *cred)
1055 {
1056         struct vop_setacl_args ap;
1057         VFS_MPLOCK_DECLARE;
1058         int error;
1059
1060         ap.a_head.a_desc = &vop_setacl_desc;
1061         ap.a_head.a_ops = ops;
1062         ap.a_vp = vp;
1063         ap.a_type = type;
1064         ap.a_aclp = aclp;
1065         ap.a_cred = cred;
1066
1067         VFS_MPLOCK1(vp->v_mount);
1068         DO_OPS(ops, error, &ap, vop_setacl);
1069         VFS_MPUNLOCK(vp->v_mount);
1070         return(error);
1071 }
1072
1073 /*
1074  * MPSAFE
1075  */
1076 int
1077 vop_aclcheck(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1078         struct acl *aclp, struct ucred *cred)
1079 {
1080         struct vop_aclcheck_args ap;
1081         VFS_MPLOCK_DECLARE;
1082         int error;
1083
1084         ap.a_head.a_desc = &vop_aclcheck_desc;
1085         ap.a_head.a_ops = ops;
1086         ap.a_vp = vp;
1087         ap.a_type = type;
1088         ap.a_aclp = aclp;
1089         ap.a_cred = cred;
1090
1091         VFS_MPLOCK1(vp->v_mount);
1092         DO_OPS(ops, error, &ap, vop_aclcheck);
1093         VFS_MPUNLOCK(vp->v_mount);
1094         return(error);
1095 }
1096
1097 /*
1098  * MPSAFE
1099  */
1100 int
1101 vop_getextattr(struct vop_ops *ops, struct vnode *vp, char *name, 
1102         struct uio *uio, struct ucred *cred)
1103 {
1104         struct vop_getextattr_args ap;
1105         VFS_MPLOCK_DECLARE;
1106         int error;
1107
1108         ap.a_head.a_desc = &vop_getextattr_desc;
1109         ap.a_head.a_ops = ops;
1110         ap.a_vp = vp;
1111         ap.a_name = name;
1112         ap.a_uio = uio;
1113         ap.a_cred = cred;
1114
1115         VFS_MPLOCK1(vp->v_mount);
1116         DO_OPS(ops, error, &ap, vop_getextattr);
1117         VFS_MPUNLOCK(vp->v_mount);
1118         return(error);
1119 }
1120
1121 /*
1122  * MPSAFE
1123  */
1124 int
1125 vop_setextattr(struct vop_ops *ops, struct vnode *vp, char *name, 
1126         struct uio *uio, struct ucred *cred)
1127 {
1128         struct vop_setextattr_args ap;
1129         VFS_MPLOCK_DECLARE;
1130         int error;
1131
1132         ap.a_head.a_desc = &vop_setextattr_desc;
1133         ap.a_head.a_ops = ops;
1134         ap.a_vp = vp;
1135         ap.a_name = name;
1136         ap.a_uio = uio;
1137         ap.a_cred = cred;
1138
1139         VFS_MPLOCK1(vp->v_mount);
1140         DO_OPS(ops, error, &ap, vop_setextattr);
1141         VFS_MPUNLOCK(vp->v_mount);
1142         return(error);
1143 }
1144
1145 /*
1146  * MPSAFE
1147  */
1148 int
1149 vop_mountctl(struct vop_ops *ops, struct vnode *vp, int op, struct file *fp,
1150              const void *ctl, int ctllen, void *buf, int buflen, int *res)
1151 {
1152         struct vop_mountctl_args ap;
1153         VFS_MPLOCK_DECLARE;
1154         int error;
1155
1156         ap.a_head.a_desc = &vop_mountctl_desc;
1157         ap.a_head.a_ops = ops;
1158         ap.a_op = op;
1159         ap.a_ctl = ctl;
1160         ap.a_fp = fp;
1161         ap.a_ctllen = ctllen;
1162         ap.a_buf = buf;
1163         ap.a_buflen = buflen;
1164         ap.a_res = res;
1165
1166         VFS_MPLOCK1(vp->v_mount);
1167         DO_OPS(ops, error, &ap, vop_mountctl);
1168         VFS_MPUNLOCK(vp->v_mount);
1169         return(error);
1170 }
1171
1172 /*
1173  * MPSAFE
1174  */
1175 int
1176 vop_markatime(struct vop_ops *ops, struct vnode *vp, struct ucred *cred)
1177 {
1178         struct vop_markatime_args ap;
1179         VFS_MPLOCK_DECLARE;
1180         int error;
1181
1182         ap.a_head.a_desc = &vop_markatime_desc;
1183         ap.a_head.a_ops = ops;
1184         ap.a_vp = vp;
1185         ap.a_cred = cred;
1186
1187         VFS_MPLOCK1(vp->v_mount);
1188         DO_OPS(ops, error, &ap, vop_markatime);
1189         VFS_MPUNLOCK(vp->v_mount);
1190         return(error);
1191 }
1192
1193 /*
1194  * NEW API FUNCTIONS
1195  *
1196  * nresolve takes a locked ncp, a referenced but unlocked dvp, and a cred,
1197  * and resolves the ncp into a positive or negative hit.
1198  *
1199  * The namecache is automatically adjusted by this function.  The ncp
1200  * is left locked on return.
1201  *
1202  * MPSAFE
1203  */
1204 int
1205 vop_nresolve(struct vop_ops *ops, struct nchandle *nch,
1206              struct vnode *dvp, struct ucred *cred)
1207 {
1208         struct vop_nresolve_args ap;
1209         VFS_MPLOCK_DECLARE;
1210         int error;
1211
1212         ap.a_head.a_desc = &vop_nresolve_desc;
1213         ap.a_head.a_ops = ops;
1214         ap.a_nch = nch;
1215         ap.a_dvp = dvp;
1216         ap.a_cred = cred;
1217
1218         VFS_MPLOCK1(dvp->v_mount);
1219         DO_OPS(ops, error, &ap, vop_nresolve);
1220         VFS_MPUNLOCK(dvp->v_mount);
1221         return(error);
1222 }
1223
1224 /*
1225  * nlookupdotdot takes an unlocked directory, referenced dvp, and looks
1226  * up "..", returning a locked parent directory in *vpp.  If an error
1227  * occurs *vpp will be NULL.
1228  *
1229  * MPSAFE
1230  */
1231 int
1232 vop_nlookupdotdot(struct vop_ops *ops, struct vnode *dvp,
1233         struct vnode **vpp, struct ucred *cred, char **fakename)
1234 {
1235         struct vop_nlookupdotdot_args ap;
1236         VFS_MPLOCK_DECLARE;
1237         int error;
1238
1239         ap.a_head.a_desc = &vop_nlookupdotdot_desc;
1240         ap.a_head.a_ops = ops;
1241         ap.a_dvp = dvp;
1242         ap.a_vpp = vpp;
1243         ap.a_cred = cred;
1244         ap.a_fakename = fakename;
1245
1246         VFS_MPLOCK1(dvp->v_mount);
1247         DO_OPS(ops, error, &ap, vop_nlookupdotdot);
1248         VFS_MPUNLOCK(dvp->v_mount);
1249         return(error);
1250 }
1251
1252 /*
1253  * ncreate takes a locked, resolved ncp that typically represents a negative
1254  * cache hit and creates the file or node specified by the ncp, cred, and
1255  * vattr.  If no error occurs a locked vnode is returned in *vpp.
1256  *
1257  * The dvp passed in is referenced but unlocked.
1258  *
1259  * The namecache is automatically adjusted by this function.  The ncp
1260  * is left locked on return.
1261  *
1262  * MPSAFE
1263  */
1264 int
1265 vop_ncreate(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1266         struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1267 {
1268         struct vop_ncreate_args ap;
1269         VFS_MPLOCK_DECLARE;
1270         int error;
1271
1272         ap.a_head.a_desc = &vop_ncreate_desc;
1273         ap.a_head.a_ops = ops;
1274         ap.a_nch = nch;
1275         ap.a_dvp = dvp;
1276         ap.a_vpp = vpp;
1277         ap.a_cred = cred;
1278         ap.a_vap = vap;
1279
1280         VFS_MPLOCK1(dvp->v_mount);
1281         DO_OPS(ops, error, &ap, vop_ncreate);
1282         VFS_MPUNLOCK(dvp->v_mount);
1283         return(error);
1284 }
1285
1286 /*
1287  * nmkdir takes a locked, resolved ncp that typically represents a negative
1288  * cache hit and creates the directory specified by the ncp, cred, and
1289  * vattr.  If no error occurs a locked vnode is returned in *vpp.
1290  *
1291  * The dvp passed in is referenced but unlocked.
1292  *
1293  * The namecache is automatically adjusted by this function.  The ncp
1294  * is left locked on return.
1295  *
1296  * MPSAFE
1297  */
1298 int
1299 vop_nmkdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1300         struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1301 {
1302         struct vop_nmkdir_args ap;
1303         VFS_MPLOCK_DECLARE;
1304         int error;
1305
1306         ap.a_head.a_desc = &vop_nmkdir_desc;
1307         ap.a_head.a_ops = ops;
1308         ap.a_nch = nch;
1309         ap.a_dvp = dvp;
1310         ap.a_vpp = vpp;
1311         ap.a_cred = cred;
1312         ap.a_vap = vap;
1313
1314         VFS_MPLOCK1(dvp->v_mount);
1315         DO_OPS(ops, error, &ap, vop_nmkdir);
1316         VFS_MPUNLOCK(dvp->v_mount);
1317         return(error);
1318 }
1319
1320 /*
1321  * nmknod takes a locked, resolved ncp that typically represents a negative
1322  * cache hit and creates the node specified by the ncp, cred, and
1323  * vattr.  If no error occurs a locked vnode is returned in *vpp.
1324  *
1325  * The dvp passed in is referenced but unlocked.
1326  *
1327  * The namecache is automatically adjusted by this function.  The ncp
1328  * is left locked on return.
1329  *
1330  * MPSAFE
1331  */
1332 int
1333 vop_nmknod(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1334         struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1335 {
1336         struct vop_nmknod_args ap;
1337         VFS_MPLOCK_DECLARE;
1338         int error;
1339
1340         ap.a_head.a_desc = &vop_nmknod_desc;
1341         ap.a_head.a_ops = ops;
1342         ap.a_nch = nch;
1343         ap.a_dvp = dvp;
1344         ap.a_vpp = vpp;
1345         ap.a_cred = cred;
1346         ap.a_vap = vap;
1347
1348         VFS_MPLOCK1(dvp->v_mount);
1349         DO_OPS(ops, error, &ap, vop_nmknod);
1350         VFS_MPUNLOCK(dvp->v_mount);
1351         return(error);
1352 }
1353
1354 /*
1355  * nlink takes a locked, resolved ncp that typically represents a negative
1356  * cache hit and creates the node specified by the ncp, cred, and
1357  * existing vnode.  The passed vp must be locked and will remain locked
1358  * on return, as does the ncp, whether an error occurs or not.
1359  *
1360  * The dvp passed in is referenced but unlocked.
1361  *
1362  * The namecache is automatically adjusted by this function.  The ncp
1363  * is left locked on return.
1364  *
1365  * MPSAFE
1366  */
1367 int
1368 vop_nlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1369           struct vnode *vp, struct ucred *cred)
1370 {
1371         struct vop_nlink_args ap;
1372         VFS_MPLOCK_DECLARE;
1373         int error;
1374
1375         ap.a_head.a_desc = &vop_nlink_desc;
1376         ap.a_head.a_ops = ops;
1377         ap.a_nch = nch;
1378         ap.a_dvp = dvp;
1379         ap.a_vp = vp;
1380         ap.a_cred = cred;
1381
1382         VFS_MPLOCK1(dvp->v_mount);
1383         DO_OPS(ops, error, &ap, vop_nlink);
1384         VFS_MPUNLOCK(dvp->v_mount);
1385         return(error);
1386 }
1387
1388 /*
1389  * nsymlink takes a locked, resolved ncp that typically represents a negative
1390  * cache hit and creates a symbolic link based on cred, vap, and target (the
1391  * contents of the link).  If no error occurs a locked vnode is returned in
1392  * *vpp.
1393  *
1394  * The dvp passed in is referenced but unlocked.
1395  *
1396  * The namecache is automatically adjusted by this function.  The ncp
1397  * is left locked on return.
1398  *
1399  * MPSAFE
1400  */
1401 int
1402 vop_nsymlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1403         struct vnode **vpp, struct ucred *cred,
1404         struct vattr *vap, char *target)
1405 {
1406         struct vop_nsymlink_args ap;
1407         VFS_MPLOCK_DECLARE;
1408         int error;
1409
1410         ap.a_head.a_desc = &vop_nsymlink_desc;
1411         ap.a_head.a_ops = ops;
1412         ap.a_nch = nch;
1413         ap.a_dvp = dvp;
1414         ap.a_vpp = vpp;
1415         ap.a_cred = cred;
1416         ap.a_vap = vap;
1417         ap.a_target = target;
1418
1419         VFS_MPLOCK1(dvp->v_mount);
1420         DO_OPS(ops, error, &ap, vop_nsymlink);
1421         VFS_MPUNLOCK(dvp->v_mount);
1422         return(error);
1423 }
1424
1425 /*
1426  * nwhiteout takes a locked, resolved ncp that can represent a positive or
1427  * negative hit and executes the whiteout function specified in flags.
1428  *
1429  * The dvp passed in is referenced but unlocked.
1430  *
1431  * The namecache is automatically adjusted by this function.  The ncp
1432  * is left locked on return.
1433  *
1434  * MPSAFE
1435  */
1436 int
1437 vop_nwhiteout(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1438         struct ucred *cred, int flags)
1439 {
1440         struct vop_nwhiteout_args ap;
1441         VFS_MPLOCK_DECLARE;
1442         int error;
1443
1444         ap.a_head.a_desc = &vop_nwhiteout_desc;
1445         ap.a_head.a_ops = ops;
1446         ap.a_nch = nch;
1447         ap.a_dvp = dvp;
1448         ap.a_cred = cred;
1449         ap.a_flags = flags;
1450
1451         VFS_MPLOCK1(dvp->v_mount);
1452         DO_OPS(ops, error, &ap, vop_nwhiteout);
1453         VFS_MPUNLOCK(dvp->v_mount);
1454         return(error);
1455 }
1456
1457 /*
1458  * nremove takes a locked, resolved ncp that generally represents a
1459  * positive hit and removes the file.
1460  *
1461  * The dvp passed in is referenced but unlocked.
1462  *
1463  * The namecache is automatically adjusted by this function.  The ncp
1464  * is left locked on return.
1465  *
1466  * MPSAFE
1467  */
1468 int
1469 vop_nremove(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1470             struct ucred *cred)
1471 {
1472         struct vop_nremove_args ap;
1473         VFS_MPLOCK_DECLARE;
1474         int error;
1475
1476         ap.a_head.a_desc = &vop_nremove_desc;
1477         ap.a_head.a_ops = ops;
1478         ap.a_nch = nch;
1479         ap.a_dvp = dvp;
1480         ap.a_cred = cred;
1481
1482         VFS_MPLOCK1(dvp->v_mount);
1483         DO_OPS(ops, error, &ap, vop_nremove);
1484         VFS_MPUNLOCK(dvp->v_mount);
1485         return(error);
1486 }
1487
1488 /*
1489  * nrmdir takes a locked, resolved ncp that generally represents a
1490  * directory and removes the directory.
1491  *
1492  * The dvp passed in is referenced but unlocked.
1493  *
1494  * The namecache is automatically adjusted by this function.  The ncp
1495  * is left locked on return.
1496  *
1497  * MPSAFE
1498  */
1499 int
1500 vop_nrmdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1501            struct ucred *cred)
1502 {
1503         struct vop_nrmdir_args ap;
1504         VFS_MPLOCK_DECLARE;
1505         int error;
1506
1507         ap.a_head.a_desc = &vop_nrmdir_desc;
1508         ap.a_head.a_ops = ops;
1509         ap.a_nch = nch;
1510         ap.a_dvp = dvp;
1511         ap.a_cred = cred;
1512
1513         VFS_MPLOCK1(dvp->v_mount);
1514         DO_OPS(ops, error, &ap, vop_nrmdir);
1515         VFS_MPUNLOCK(dvp->v_mount);
1516         return(error);
1517 }
1518
1519 /*
1520  * nrename takes TWO locked, resolved ncp's and the cred of the caller
1521  * and renames the source ncp to the target ncp.  The target ncp may 
1522  * represent a positive or negative hit.
1523  *
1524  * The fdvp and tdvp passed in are referenced but unlocked.
1525  *
1526  * The namecache is automatically adjusted by this function.  The ncp
1527  * is left locked on return.  The source ncp is typically changed to
1528  * a negative cache hit and the target ncp typically takes on the
1529  * source ncp's underlying file.
1530  *
1531  * MPSAFE
1532  */
1533 int
1534 vop_nrename(struct vop_ops *ops,
1535             struct nchandle *fnch, struct nchandle *tnch,
1536             struct vnode *fdvp, struct vnode *tdvp,
1537             struct ucred *cred)
1538 {
1539         struct vop_nrename_args ap;
1540         VFS_MPLOCK_DECLARE;
1541         int error;
1542
1543         ap.a_head.a_desc = &vop_nrename_desc;
1544         ap.a_head.a_ops = ops;
1545         ap.a_fnch = fnch;
1546         ap.a_tnch = tnch;
1547         ap.a_fdvp = fdvp;
1548         ap.a_tdvp = tdvp;
1549         ap.a_cred = cred;
1550
1551         VFS_MPLOCK1(fdvp->v_mount);
1552         DO_OPS(ops, error, &ap, vop_nrename);
1553         VFS_MPUNLOCK(fdvp->v_mount);
1554         return(error);
1555 }
1556
1557 /************************************************************************
1558  *              PRIMARY VNODE OPERATIONS FORWARDING CALLS               *
1559  ************************************************************************
1560  *
1561  * These procedures are called from VFSs such as unionfs and nullfs
1562  * when they wish to forward an operation on one VFS to another.  The
1563  * argument structure/message is modified and then directly passed to the
1564  * appropriate routine.  This routines may also be called by initiators
1565  * who have an argument structure in hand rather then discreet arguments.
1566  *
1567  * MPSAFE - Caller expected to already hold the appropriate vfs lock.
1568  */
1569 int
1570 vop_vnoperate_ap(struct vop_generic_args *ap)
1571 {
1572         struct vop_ops *ops;
1573         int error;
1574
1575         ops = ap->a_ops;
1576         error = VOCALL(ops, ap);
1577
1578         return (error);
1579 }
1580
1581 /*
1582  * This routine is called by the cache coherency layer to execute the actual
1583  * VFS operation.  If a journaling layer is present we call though it, else
1584  * we call the native VOP functions.
1585  */
1586 int
1587 vop_cache_operate_ap(struct vop_generic_args *ap)
1588 {
1589         struct vop_ops *ops;
1590         int error;
1591
1592         ops = ap->a_ops;
1593         if (ops->head.vv_mount->mnt_vn_journal_ops)
1594                 error = VOCALL(ops->head.vv_mount->mnt_vn_journal_ops, ap);
1595         else
1596                 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1597         return (error);
1598 }
1599
1600
1601 /*
1602  * This routine is called by the journaling layer to execute the actual
1603  * VFS operation.
1604  */
1605 int
1606 vop_journal_operate_ap(struct vop_generic_args *ap)
1607 {
1608         struct vop_ops *ops;
1609         int error;
1610
1611         ops = ap->a_ops;
1612         error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1613
1614         return (error);
1615 }
1616
1617 int
1618 vop_open_ap(struct vop_open_args *ap)
1619 {
1620         int error;
1621
1622         DO_OPS(ap->a_head.a_ops, error, ap, vop_open);
1623         return(error);
1624 }
1625
1626 int
1627 vop_close_ap(struct vop_close_args *ap)
1628 {
1629         int error;
1630
1631         DO_OPS(ap->a_head.a_ops, error, ap, vop_close);
1632         return(error);
1633 }
1634
1635 int
1636 vop_access_ap(struct vop_access_args *ap)
1637 {
1638         int error;
1639
1640         DO_OPS(ap->a_head.a_ops, error, ap, vop_access);
1641         return(error);
1642 }
1643
1644 int
1645 vop_getattr_ap(struct vop_getattr_args *ap)
1646 {
1647         int error;
1648
1649         DO_OPS(ap->a_head.a_ops, error, ap, vop_getattr);
1650         return(error);
1651 }
1652
1653 int
1654 vop_setattr_ap(struct vop_setattr_args *ap)
1655 {
1656         int error;
1657
1658         DO_OPS(ap->a_head.a_ops, error, ap, vop_setattr);
1659         return(error);
1660 }
1661
1662 int
1663 vop_read_ap(struct vop_read_args *ap)
1664 {
1665         int error;
1666
1667         DO_OPS(ap->a_head.a_ops, error, ap, vop_read);
1668         return(error);
1669 }
1670
1671 int
1672 vop_write_ap(struct vop_write_args *ap)
1673 {
1674         int error;
1675
1676         DO_OPS(ap->a_head.a_ops, error, ap, vop_write);
1677         return(error);
1678 }
1679
1680 int
1681 vop_ioctl_ap(struct vop_ioctl_args *ap)
1682 {
1683         int error;
1684
1685         DO_OPS(ap->a_head.a_ops, error, ap, vop_ioctl);
1686         return(error);
1687 }
1688
1689 int
1690 vop_poll_ap(struct vop_poll_args *ap)
1691 {
1692         int error;
1693
1694         DO_OPS(ap->a_head.a_ops, error, ap, vop_poll);
1695         return(error);
1696 }
1697
1698 int
1699 vop_kqfilter_ap(struct vop_kqfilter_args *ap)
1700 {
1701         int error;
1702
1703         DO_OPS(ap->a_head.a_ops, error, ap, vop_kqfilter);
1704         return(error);
1705 }
1706
1707 int
1708 vop_mmap_ap(struct vop_mmap_args *ap)
1709 {
1710         int error;
1711
1712         DO_OPS(ap->a_head.a_ops, error, ap, vop_mmap);
1713         return(error);
1714 }
1715
1716 int
1717 vop_fsync_ap(struct vop_fsync_args *ap)
1718 {
1719         int error;
1720
1721         DO_OPS(ap->a_head.a_ops, error, ap, vop_fsync);
1722         return(error);
1723 }
1724
1725 int
1726 vop_readdir_ap(struct vop_readdir_args *ap)
1727 {
1728         int error;
1729
1730         DO_OPS(ap->a_head.a_ops, error, ap, vop_readdir);
1731         return(error);
1732 }
1733
1734 int
1735 vop_readlink_ap(struct vop_readlink_args *ap)
1736 {
1737         int error;
1738
1739         DO_OPS(ap->a_head.a_ops, error, ap, vop_readlink);
1740         return(error);
1741 }
1742
1743 int
1744 vop_inactive_ap(struct vop_inactive_args *ap)
1745 {
1746         int error;
1747
1748         DO_OPS(ap->a_head.a_ops, error, ap, vop_inactive);
1749         return(error);
1750 }
1751
1752 int
1753 vop_reclaim_ap(struct vop_reclaim_args *ap)
1754 {
1755         int error;
1756
1757         DO_OPS(ap->a_head.a_ops, error, ap, vop_reclaim);
1758         return(error);
1759 }
1760
1761 int
1762 vop_bmap_ap(struct vop_bmap_args *ap)
1763 {
1764         int error;
1765
1766         DO_OPS(ap->a_head.a_ops, error, ap, vop_bmap);
1767         return(error);
1768 }
1769
1770 int
1771 vop_strategy_ap(struct vop_strategy_args *ap)
1772 {
1773         int error;
1774
1775         DO_OPS(ap->a_head.a_ops, error, ap, vop_strategy);
1776         return(error);
1777 }
1778
1779 int
1780 vop_print_ap(struct vop_print_args *ap)
1781 {
1782         int error;
1783
1784         DO_OPS(ap->a_head.a_ops, error, ap, vop_print);
1785         return(error);
1786 }
1787
1788 int
1789 vop_pathconf_ap(struct vop_pathconf_args *ap)
1790 {
1791         int error;
1792
1793         DO_OPS(ap->a_head.a_ops, error, ap, vop_pathconf);
1794         return(error);
1795 }
1796
1797 int
1798 vop_advlock_ap(struct vop_advlock_args *ap)
1799 {
1800         int error;
1801
1802         DO_OPS(ap->a_head.a_ops, error, ap, vop_advlock);
1803         return(error);
1804 }
1805
1806 int
1807 vop_balloc_ap(struct vop_balloc_args *ap)
1808 {
1809         int error;
1810
1811         DO_OPS(ap->a_head.a_ops, error, ap, vop_balloc);
1812         return(error);
1813 }
1814
1815 int
1816 vop_reallocblks_ap(struct vop_reallocblks_args *ap)
1817 {
1818         int error;
1819
1820         DO_OPS(ap->a_head.a_ops, error, ap, vop_reallocblks);
1821         return(error);
1822 }
1823
1824 int
1825 vop_getpages_ap(struct vop_getpages_args *ap)
1826 {
1827         int error;
1828
1829         DO_OPS(ap->a_head.a_ops, error, ap, vop_getpages);
1830         return(error);
1831 }
1832
1833 int
1834 vop_putpages_ap(struct vop_putpages_args *ap)
1835 {
1836         int error;
1837
1838         DO_OPS(ap->a_head.a_ops, error, ap, vop_putpages);
1839         return(error);
1840 }
1841
1842 int
1843 vop_freeblks_ap(struct vop_freeblks_args *ap)
1844 {
1845         int error;
1846
1847         DO_OPS(ap->a_head.a_ops, error, ap, vop_freeblks);
1848         return(error);
1849 }
1850
1851 int
1852 vop_getacl_ap(struct vop_getacl_args *ap)
1853 {
1854         int error;
1855
1856         DO_OPS(ap->a_head.a_ops, error, ap, vop_getacl);
1857         return(error);
1858 }
1859
1860 int
1861 vop_setacl_ap(struct vop_setacl_args *ap)
1862 {
1863         int error;
1864
1865         DO_OPS(ap->a_head.a_ops, error, ap, vop_setacl);
1866         return(error);
1867 }
1868
1869 int
1870 vop_aclcheck_ap(struct vop_aclcheck_args *ap)
1871 {
1872         int error;
1873
1874         DO_OPS(ap->a_head.a_ops, error, ap, vop_aclcheck);
1875         return(error);
1876 }
1877
1878 int
1879 vop_getextattr_ap(struct vop_getextattr_args *ap)
1880 {
1881         int error;
1882
1883         DO_OPS(ap->a_head.a_ops, error, ap, vop_getextattr);
1884         return(error);
1885 }
1886
1887 int
1888 vop_setextattr_ap(struct vop_setextattr_args *ap)
1889 {
1890         int error;
1891
1892         DO_OPS(ap->a_head.a_ops, error, ap, vop_setextattr);
1893         return(error);
1894 }
1895
1896 int
1897 vop_mountctl_ap(struct vop_mountctl_args *ap)
1898 {
1899         int error;
1900
1901         DO_OPS(ap->a_head.a_ops, error, ap, vop_mountctl);
1902         return(error);
1903 }
1904
1905 int
1906 vop_markatime_ap(struct vop_markatime_args *ap)
1907 {
1908         int error;
1909
1910         DO_OPS(ap->a_head.a_ops, error, ap, vop_markatime);
1911         return(error);
1912 }
1913
1914 int
1915 vop_nresolve_ap(struct vop_nresolve_args *ap)
1916 {
1917         int error;
1918
1919         DO_OPS(ap->a_head.a_ops, error, ap, vop_nresolve);
1920         return(error);
1921 }
1922
1923 int
1924 vop_nlookupdotdot_ap(struct vop_nlookupdotdot_args *ap)
1925 {
1926         int error;
1927
1928         DO_OPS(ap->a_head.a_ops, error, ap, vop_nlookupdotdot);
1929         return(error);
1930 }
1931
1932 int
1933 vop_ncreate_ap(struct vop_ncreate_args *ap)
1934 {
1935         int error;
1936
1937         DO_OPS(ap->a_head.a_ops, error, ap, vop_ncreate);
1938         return(error);
1939 }
1940
1941 int
1942 vop_nmkdir_ap(struct vop_nmkdir_args *ap)
1943 {
1944         int error;
1945
1946         DO_OPS(ap->a_head.a_ops, error, ap, vop_nmkdir);
1947         return(error);
1948 }
1949
1950 int
1951 vop_nmknod_ap(struct vop_nmknod_args *ap)
1952 {
1953         int error;
1954
1955         DO_OPS(ap->a_head.a_ops, error, ap, vop_nmknod);
1956         return(error);
1957 }
1958
1959 int
1960 vop_nlink_ap(struct vop_nlink_args *ap)
1961 {
1962         int error;
1963
1964         DO_OPS(ap->a_head.a_ops, error, ap, vop_nlink);
1965         return(error);
1966 }
1967
1968 int
1969 vop_nsymlink_ap(struct vop_nsymlink_args *ap)
1970 {
1971         int error;
1972
1973         DO_OPS(ap->a_head.a_ops, error, ap, vop_nsymlink);
1974         return(error);
1975 }
1976
1977 int
1978 vop_nwhiteout_ap(struct vop_nwhiteout_args *ap)
1979 {
1980         int error;
1981
1982         DO_OPS(ap->a_head.a_ops, error, ap, vop_nwhiteout);
1983         return(error);
1984 }
1985
1986 int
1987 vop_nremove_ap(struct vop_nremove_args *ap)
1988 {
1989         int error;
1990
1991         DO_OPS(ap->a_head.a_ops, error, ap, vop_nremove);
1992         return(error);
1993 }
1994
1995 int
1996 vop_nrmdir_ap(struct vop_nrmdir_args *ap)
1997 {
1998         int error;
1999
2000         DO_OPS(ap->a_head.a_ops, error, ap, vop_nrmdir);
2001         return(error);
2002 }
2003
2004 int
2005 vop_nrename_ap(struct vop_nrename_args *ap)
2006 {
2007         int error;
2008
2009         DO_OPS(ap->a_head.a_ops, error, ap, vop_nrename);
2010         return(error);
2011 }
2012