Merge git://git.dragonflybsd.org/dragonfly
[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         struct mount *mp;
748         VFS_MPLOCK_DECLARE;
749         int error;
750
751         ap.a_head.a_desc = &vop_inactive_desc;
752         ap.a_head.a_ops = ops;
753         ap.a_vp = vp;
754
755         /*
756          * WARNING!  Deactivation of the vnode can cause it to be recycled,
757          *           clearing vp->v_mount.
758          */
759         mp = vp->v_mount;
760         VFS_MPLOCK_FLAG(mp, MNTK_IN_MPSAFE);
761         DO_OPS(ops, error, &ap, vop_inactive);
762         VFS_MPUNLOCK(mp);
763         return(error);
764 }
765
766 /*
767  * MPSAFE
768  */
769 int
770 vop_reclaim(struct vop_ops *ops, struct vnode *vp)
771 {
772         struct vop_reclaim_args ap;
773         struct mount *mp;
774         VFS_MPLOCK_DECLARE;
775         int error;
776
777         ap.a_head.a_desc = &vop_reclaim_desc;
778         ap.a_head.a_ops = ops;
779         ap.a_vp = vp;
780
781         /*
782          * WARNING!  Reclamation of the vnode will clear vp->v_mount.
783          */
784         mp = vp->v_mount;
785         VFS_MPLOCK1(mp);
786         DO_OPS(ops, error, &ap, vop_reclaim);
787         VFS_MPUNLOCK(mp);
788         return(error);
789 }
790
791 /*
792  * MPSAFE
793  */
794 int
795 vop_bmap(struct vop_ops *ops, struct vnode *vp, off_t loffset,
796         off_t *doffsetp, int *runp, int *runb, buf_cmd_t cmd)
797 {
798         struct vop_bmap_args ap;
799         VFS_MPLOCK_DECLARE;
800         int error;
801
802         ap.a_head.a_desc = &vop_bmap_desc;
803         ap.a_head.a_ops = ops;
804         ap.a_vp = vp;
805         ap.a_loffset = loffset;
806         ap.a_doffsetp = doffsetp;
807         ap.a_runp = runp;
808         ap.a_runb = runb;
809         ap.a_cmd = cmd;
810
811         VFS_MPLOCK1(vp->v_mount);
812         DO_OPS(ops, error, &ap, vop_bmap);
813         VFS_MPUNLOCK(vp->v_mount);
814         return(error);
815 }
816
817 /*
818  * MPSAFE
819  */
820 int
821 vop_strategy(struct vop_ops *ops, struct vnode *vp, struct bio *bio)
822 {
823         struct vop_strategy_args ap;
824         VFS_MPLOCK_DECLARE;
825         int error;
826
827         ap.a_head.a_desc = &vop_strategy_desc;
828         ap.a_head.a_ops = ops;
829         ap.a_vp = vp;
830         ap.a_bio = bio;
831
832         if (vp->v_mount) {
833                 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_SG_MPSAFE);
834                 DO_OPS(ops, error, &ap, vop_strategy);
835                 VFS_MPUNLOCK(vp->v_mount);
836         } else {
837                 /* ugly hack for swap */
838                 get_mplock();
839                 DO_OPS(ops, error, &ap, vop_strategy);
840                 rel_mplock();
841         }
842         return(error);
843 }
844
845 /*
846  * MPSAFE
847  */
848 int
849 vop_print(struct vop_ops *ops, struct vnode *vp)
850 {
851         struct vop_print_args ap;
852         VFS_MPLOCK_DECLARE;
853         int error;
854
855         ap.a_head.a_desc = &vop_print_desc;
856         ap.a_head.a_ops = ops;
857         ap.a_vp = vp;
858
859         VFS_MPLOCK1(vp->v_mount);
860         DO_OPS(ops, error, &ap, vop_print);
861         VFS_MPUNLOCK(vp->v_mount);
862         return(error);
863 }
864
865 /*
866  * MPSAFE
867  */
868 int
869 vop_pathconf(struct vop_ops *ops, struct vnode *vp, int name,
870         register_t *retval)
871 {
872         struct vop_pathconf_args ap;
873         VFS_MPLOCK_DECLARE;
874         int error;
875
876         ap.a_head.a_desc = &vop_pathconf_desc;
877         ap.a_head.a_ops = ops;
878         ap.a_vp = vp;
879         ap.a_name = name;
880         ap.a_retval = retval;
881
882         VFS_MPLOCK1(vp->v_mount);
883         DO_OPS(ops, error, &ap, vop_pathconf);
884         VFS_MPUNLOCK(vp->v_mount);
885         return(error);
886 }
887
888 /*
889  * MPSAFE
890  */
891 int
892 vop_advlock(struct vop_ops *ops, struct vnode *vp, caddr_t id, int op,
893         struct flock *fl, int flags)
894 {
895         struct vop_advlock_args ap;
896         VFS_MPLOCK_DECLARE;
897         int error;
898
899         ap.a_head.a_desc = &vop_advlock_desc;
900         ap.a_head.a_ops = ops;
901         ap.a_vp = vp;
902         ap.a_id = id;
903         ap.a_op = op;
904         ap.a_fl = fl;
905         ap.a_flags = flags;
906
907         VFS_MPLOCK1(vp->v_mount);
908         DO_OPS(ops, error, &ap, vop_advlock);
909         VFS_MPUNLOCK(vp->v_mount);
910         return(error);
911 }
912
913 /*
914  * MPSAFE
915  */
916 int
917 vop_balloc(struct vop_ops *ops, struct vnode *vp, off_t startoffset,
918         int size, struct ucred *cred, int flags,
919         struct buf **bpp)
920 {
921         struct vop_balloc_args ap;
922         VFS_MPLOCK_DECLARE;
923         int error;
924
925         ap.a_head.a_desc = &vop_balloc_desc;
926         ap.a_head.a_ops = ops;
927         ap.a_vp = vp;
928         ap.a_startoffset = startoffset;
929         ap.a_size = size;
930         ap.a_cred = cred;
931         ap.a_flags = flags;
932         ap.a_bpp = bpp;
933
934         VFS_MPLOCK1(vp->v_mount);
935         DO_OPS(ops, error, &ap, vop_balloc);
936         VFS_MPUNLOCK(vp->v_mount);
937         return(error);
938 }
939
940 /*
941  * MPSAFE
942  */
943 int
944 vop_reallocblks(struct vop_ops *ops, struct vnode *vp,
945         struct cluster_save *buflist)
946 {
947         struct vop_reallocblks_args ap;
948         VFS_MPLOCK_DECLARE;
949         int error;
950
951         ap.a_head.a_desc = &vop_reallocblks_desc;
952         ap.a_head.a_ops = ops;
953         ap.a_vp = vp;
954         ap.a_buflist = buflist;
955
956         VFS_MPLOCK1(vp->v_mount);
957         DO_OPS(ops, error, &ap, vop_reallocblks);
958         VFS_MPUNLOCK(vp->v_mount);
959         return(error);
960 }
961
962 /*
963  * MPSAFE
964  */
965 int
966 vop_getpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
967         int reqpage, vm_ooffset_t offset, int seqaccess)
968 {
969         struct vop_getpages_args ap;
970         VFS_MPLOCK_DECLARE;
971         int error;
972
973         ap.a_head.a_desc = &vop_getpages_desc;
974         ap.a_head.a_ops = ops;
975         ap.a_vp = vp;
976         ap.a_m = m;
977         ap.a_count = count;
978         ap.a_reqpage = reqpage;
979         ap.a_offset = offset;
980         ap.a_seqaccess = seqaccess;
981
982         VFS_MPLOCK1(vp->v_mount);
983         DO_OPS(ops, error, &ap, vop_getpages);
984         VFS_MPUNLOCK(vp->v_mount);
985         return(error);
986 }
987
988 /*
989  * MPSAFE
990  */
991 int
992 vop_putpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
993         int sync, int *rtvals, vm_ooffset_t offset)
994 {
995         struct vop_putpages_args ap;
996         VFS_MPLOCK_DECLARE;
997         int error;
998
999         ap.a_head.a_desc = &vop_putpages_desc;
1000         ap.a_head.a_ops = ops;
1001         ap.a_vp = vp;
1002         ap.a_m = m;
1003         ap.a_count = count;
1004         ap.a_sync = sync;
1005         ap.a_rtvals = rtvals;
1006         ap.a_offset = offset;
1007
1008         VFS_MPLOCK1(vp->v_mount);
1009         DO_OPS(ops, error, &ap, vop_putpages);
1010         VFS_MPUNLOCK(vp->v_mount);
1011         return(error);
1012 }
1013
1014 /*
1015  * MPSAFE
1016  */
1017 int
1018 vop_freeblks(struct vop_ops *ops, struct vnode *vp, off_t offset, int length)
1019 {
1020         struct vop_freeblks_args ap;
1021         VFS_MPLOCK_DECLARE;
1022         int error;
1023
1024         ap.a_head.a_desc = &vop_freeblks_desc;
1025         ap.a_head.a_ops = ops;
1026         ap.a_vp = vp;
1027         ap.a_offset = offset;
1028         ap.a_length = length;
1029
1030         VFS_MPLOCK1(vp->v_mount);
1031         DO_OPS(ops, error, &ap, vop_freeblks);
1032         VFS_MPUNLOCK(vp->v_mount);
1033         return(error);
1034 }
1035
1036 /*
1037  * MPSAFE
1038  */
1039 int
1040 vop_getacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1041         struct acl *aclp, struct ucred *cred)
1042 {
1043         struct vop_getacl_args ap;
1044         VFS_MPLOCK_DECLARE;
1045         int error;
1046
1047         ap.a_head.a_desc = &vop_getacl_desc;
1048         ap.a_head.a_ops = ops;
1049         ap.a_vp = vp;
1050         ap.a_type = type;
1051         ap.a_aclp = aclp;
1052         ap.a_cred = cred;
1053
1054         VFS_MPLOCK1(vp->v_mount);
1055         DO_OPS(ops, error, &ap, vop_getacl);
1056         VFS_MPUNLOCK(vp->v_mount);
1057         return(error);
1058 }
1059
1060 /*
1061  * MPSAFE
1062  */
1063 int
1064 vop_setacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1065         struct acl *aclp, struct ucred *cred)
1066 {
1067         struct vop_setacl_args ap;
1068         VFS_MPLOCK_DECLARE;
1069         int error;
1070
1071         ap.a_head.a_desc = &vop_setacl_desc;
1072         ap.a_head.a_ops = ops;
1073         ap.a_vp = vp;
1074         ap.a_type = type;
1075         ap.a_aclp = aclp;
1076         ap.a_cred = cred;
1077
1078         VFS_MPLOCK1(vp->v_mount);
1079         DO_OPS(ops, error, &ap, vop_setacl);
1080         VFS_MPUNLOCK(vp->v_mount);
1081         return(error);
1082 }
1083
1084 /*
1085  * MPSAFE
1086  */
1087 int
1088 vop_aclcheck(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1089         struct acl *aclp, struct ucred *cred)
1090 {
1091         struct vop_aclcheck_args ap;
1092         VFS_MPLOCK_DECLARE;
1093         int error;
1094
1095         ap.a_head.a_desc = &vop_aclcheck_desc;
1096         ap.a_head.a_ops = ops;
1097         ap.a_vp = vp;
1098         ap.a_type = type;
1099         ap.a_aclp = aclp;
1100         ap.a_cred = cred;
1101
1102         VFS_MPLOCK1(vp->v_mount);
1103         DO_OPS(ops, error, &ap, vop_aclcheck);
1104         VFS_MPUNLOCK(vp->v_mount);
1105         return(error);
1106 }
1107
1108 /*
1109  * MPSAFE
1110  */
1111 int
1112 vop_getextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1113                char *attrname, struct uio *uio, struct ucred *cred)
1114 {
1115         struct vop_getextattr_args ap;
1116         VFS_MPLOCK_DECLARE;
1117         int error;
1118
1119         ap.a_head.a_desc = &vop_getextattr_desc;
1120         ap.a_head.a_ops = ops;
1121         ap.a_vp = vp;
1122         ap.a_attrnamespace = attrnamespace;
1123         ap.a_attrname = attrname;
1124         ap.a_uio = uio;
1125         ap.a_cred = cred;
1126
1127         VFS_MPLOCK1(vp->v_mount);
1128         DO_OPS(ops, error, &ap, vop_getextattr);
1129         VFS_MPUNLOCK(vp->v_mount);
1130         return(error);
1131 }
1132
1133 /*
1134  * MPSAFE
1135  */
1136 int
1137 vop_setextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1138                char *attrname, struct uio *uio, struct ucred *cred)
1139 {
1140         struct vop_setextattr_args ap;
1141         VFS_MPLOCK_DECLARE;
1142         int error;
1143
1144         ap.a_head.a_desc = &vop_setextattr_desc;
1145         ap.a_head.a_ops = ops;
1146         ap.a_vp = vp;
1147         ap.a_attrnamespace = attrnamespace;
1148         ap.a_attrname = attrname;
1149         ap.a_uio = uio;
1150         ap.a_cred = cred;
1151
1152         VFS_MPLOCK1(vp->v_mount);
1153         DO_OPS(ops, error, &ap, vop_setextattr);
1154         VFS_MPUNLOCK(vp->v_mount);
1155         return(error);
1156 }
1157
1158 /*
1159  * MPSAFE
1160  */
1161 int
1162 vop_mountctl(struct vop_ops *ops, struct vnode *vp, int op, struct file *fp,
1163              const void *ctl, int ctllen, void *buf, int buflen, int *res)
1164 {
1165         struct vop_mountctl_args ap;
1166         VFS_MPLOCK_DECLARE;
1167         int error;
1168
1169         ap.a_head.a_desc = &vop_mountctl_desc;
1170         ap.a_head.a_ops = ops;
1171         ap.a_op = op;
1172         ap.a_ctl = ctl;
1173         ap.a_fp = fp;
1174         ap.a_ctllen = ctllen;
1175         ap.a_buf = buf;
1176         ap.a_buflen = buflen;
1177         ap.a_res = res;
1178
1179         VFS_MPLOCK1(vp->v_mount);
1180         DO_OPS(ops, error, &ap, vop_mountctl);
1181         VFS_MPUNLOCK(vp->v_mount);
1182         return(error);
1183 }
1184
1185 /*
1186  * MPSAFE
1187  */
1188 int
1189 vop_markatime(struct vop_ops *ops, struct vnode *vp, struct ucred *cred)
1190 {
1191         struct vop_markatime_args ap;
1192         VFS_MPLOCK_DECLARE;
1193         int error;
1194
1195         ap.a_head.a_desc = &vop_markatime_desc;
1196         ap.a_head.a_ops = ops;
1197         ap.a_vp = vp;
1198         ap.a_cred = cred;
1199
1200         VFS_MPLOCK1(vp->v_mount);
1201         DO_OPS(ops, error, &ap, vop_markatime);
1202         VFS_MPUNLOCK(vp->v_mount);
1203         return(error);
1204 }
1205
1206 /*
1207  * NEW API FUNCTIONS
1208  *
1209  * nresolve takes a locked ncp, a referenced but unlocked dvp, and a cred,
1210  * and resolves the ncp into a positive or negative hit.
1211  *
1212  * The namecache is automatically adjusted by this function.  The ncp
1213  * is left locked on return.
1214  *
1215  * MPSAFE
1216  */
1217 int
1218 vop_nresolve(struct vop_ops *ops, struct nchandle *nch,
1219              struct vnode *dvp, struct ucred *cred)
1220 {
1221         struct vop_nresolve_args ap;
1222         VFS_MPLOCK_DECLARE;
1223         int error;
1224
1225         ap.a_head.a_desc = &vop_nresolve_desc;
1226         ap.a_head.a_ops = ops;
1227         ap.a_nch = nch;
1228         ap.a_dvp = dvp;
1229         ap.a_cred = cred;
1230
1231         VFS_MPLOCK1(dvp->v_mount);
1232         DO_OPS(ops, error, &ap, vop_nresolve);
1233         VFS_MPUNLOCK(dvp->v_mount);
1234         return(error);
1235 }
1236
1237 /*
1238  * nlookupdotdot takes an unlocked directory, referenced dvp, and looks
1239  * up "..", returning a locked parent directory in *vpp.  If an error
1240  * occurs *vpp will be NULL.
1241  *
1242  * MPSAFE
1243  */
1244 int
1245 vop_nlookupdotdot(struct vop_ops *ops, struct vnode *dvp,
1246         struct vnode **vpp, struct ucred *cred, char **fakename)
1247 {
1248         struct vop_nlookupdotdot_args ap;
1249         VFS_MPLOCK_DECLARE;
1250         int error;
1251
1252         ap.a_head.a_desc = &vop_nlookupdotdot_desc;
1253         ap.a_head.a_ops = ops;
1254         ap.a_dvp = dvp;
1255         ap.a_vpp = vpp;
1256         ap.a_cred = cred;
1257         ap.a_fakename = fakename;
1258
1259         VFS_MPLOCK1(dvp->v_mount);
1260         DO_OPS(ops, error, &ap, vop_nlookupdotdot);
1261         VFS_MPUNLOCK(dvp->v_mount);
1262         return(error);
1263 }
1264
1265 /*
1266  * ncreate takes a locked, resolved ncp that typically represents a negative
1267  * cache hit and creates the file or node specified by the ncp, cred, and
1268  * vattr.  If no error occurs a locked vnode is returned in *vpp.
1269  *
1270  * The dvp passed in is referenced but unlocked.
1271  *
1272  * The namecache is automatically adjusted by this function.  The ncp
1273  * is left locked on return.
1274  *
1275  * MPSAFE
1276  */
1277 int
1278 vop_ncreate(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1279         struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1280 {
1281         struct vop_ncreate_args ap;
1282         VFS_MPLOCK_DECLARE;
1283         int error;
1284
1285         ap.a_head.a_desc = &vop_ncreate_desc;
1286         ap.a_head.a_ops = ops;
1287         ap.a_nch = nch;
1288         ap.a_dvp = dvp;
1289         ap.a_vpp = vpp;
1290         ap.a_cred = cred;
1291         ap.a_vap = vap;
1292
1293         VFS_MPLOCK1(dvp->v_mount);
1294         DO_OPS(ops, error, &ap, vop_ncreate);
1295         VFS_MPUNLOCK(dvp->v_mount);
1296         return(error);
1297 }
1298
1299 /*
1300  * nmkdir takes a locked, resolved ncp that typically represents a negative
1301  * cache hit and creates the directory specified by the ncp, cred, and
1302  * vattr.  If no error occurs a locked vnode is returned in *vpp.
1303  *
1304  * The dvp passed in is referenced but unlocked.
1305  *
1306  * The namecache is automatically adjusted by this function.  The ncp
1307  * is left locked on return.
1308  *
1309  * MPSAFE
1310  */
1311 int
1312 vop_nmkdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1313         struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1314 {
1315         struct vop_nmkdir_args ap;
1316         VFS_MPLOCK_DECLARE;
1317         int error;
1318
1319         ap.a_head.a_desc = &vop_nmkdir_desc;
1320         ap.a_head.a_ops = ops;
1321         ap.a_nch = nch;
1322         ap.a_dvp = dvp;
1323         ap.a_vpp = vpp;
1324         ap.a_cred = cred;
1325         ap.a_vap = vap;
1326
1327         VFS_MPLOCK1(dvp->v_mount);
1328         DO_OPS(ops, error, &ap, vop_nmkdir);
1329         VFS_MPUNLOCK(dvp->v_mount);
1330         return(error);
1331 }
1332
1333 /*
1334  * nmknod takes a locked, resolved ncp that typically represents a negative
1335  * cache hit and creates the node specified by the ncp, cred, and
1336  * vattr.  If no error occurs a locked vnode is returned in *vpp.
1337  *
1338  * The dvp passed in is referenced but unlocked.
1339  *
1340  * The namecache is automatically adjusted by this function.  The ncp
1341  * is left locked on return.
1342  *
1343  * MPSAFE
1344  */
1345 int
1346 vop_nmknod(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1347         struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1348 {
1349         struct vop_nmknod_args ap;
1350         VFS_MPLOCK_DECLARE;
1351         int error;
1352
1353         ap.a_head.a_desc = &vop_nmknod_desc;
1354         ap.a_head.a_ops = ops;
1355         ap.a_nch = nch;
1356         ap.a_dvp = dvp;
1357         ap.a_vpp = vpp;
1358         ap.a_cred = cred;
1359         ap.a_vap = vap;
1360
1361         VFS_MPLOCK1(dvp->v_mount);
1362         DO_OPS(ops, error, &ap, vop_nmknod);
1363         VFS_MPUNLOCK(dvp->v_mount);
1364         return(error);
1365 }
1366
1367 /*
1368  * nlink takes a locked, resolved ncp that typically represents a negative
1369  * cache hit and creates the node specified by the ncp, cred, and
1370  * existing vnode.  The passed vp must be locked and will remain locked
1371  * on return, as does the ncp, whether an error occurs or not.
1372  *
1373  * The dvp passed in is referenced but unlocked.
1374  *
1375  * The namecache is automatically adjusted by this function.  The ncp
1376  * is left locked on return.
1377  *
1378  * MPSAFE
1379  */
1380 int
1381 vop_nlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1382           struct vnode *vp, struct ucred *cred)
1383 {
1384         struct vop_nlink_args ap;
1385         VFS_MPLOCK_DECLARE;
1386         int error;
1387
1388         ap.a_head.a_desc = &vop_nlink_desc;
1389         ap.a_head.a_ops = ops;
1390         ap.a_nch = nch;
1391         ap.a_dvp = dvp;
1392         ap.a_vp = vp;
1393         ap.a_cred = cred;
1394
1395         VFS_MPLOCK1(dvp->v_mount);
1396         DO_OPS(ops, error, &ap, vop_nlink);
1397         VFS_MPUNLOCK(dvp->v_mount);
1398         return(error);
1399 }
1400
1401 /*
1402  * nsymlink takes a locked, resolved ncp that typically represents a negative
1403  * cache hit and creates a symbolic link based on cred, vap, and target (the
1404  * contents of the link).  If no error occurs a locked vnode is returned in
1405  * *vpp.
1406  *
1407  * The dvp passed in is referenced but unlocked.
1408  *
1409  * The namecache is automatically adjusted by this function.  The ncp
1410  * is left locked on return.
1411  *
1412  * MPSAFE
1413  */
1414 int
1415 vop_nsymlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1416         struct vnode **vpp, struct ucred *cred,
1417         struct vattr *vap, char *target)
1418 {
1419         struct vop_nsymlink_args ap;
1420         VFS_MPLOCK_DECLARE;
1421         int error;
1422
1423         ap.a_head.a_desc = &vop_nsymlink_desc;
1424         ap.a_head.a_ops = ops;
1425         ap.a_nch = nch;
1426         ap.a_dvp = dvp;
1427         ap.a_vpp = vpp;
1428         ap.a_cred = cred;
1429         ap.a_vap = vap;
1430         ap.a_target = target;
1431
1432         VFS_MPLOCK1(dvp->v_mount);
1433         DO_OPS(ops, error, &ap, vop_nsymlink);
1434         VFS_MPUNLOCK(dvp->v_mount);
1435         return(error);
1436 }
1437
1438 /*
1439  * nwhiteout takes a locked, resolved ncp that can represent a positive or
1440  * negative hit and executes the whiteout function specified in flags.
1441  *
1442  * The dvp passed in is referenced but unlocked.
1443  *
1444  * The namecache is automatically adjusted by this function.  The ncp
1445  * is left locked on return.
1446  *
1447  * MPSAFE
1448  */
1449 int
1450 vop_nwhiteout(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1451         struct ucred *cred, int flags)
1452 {
1453         struct vop_nwhiteout_args ap;
1454         VFS_MPLOCK_DECLARE;
1455         int error;
1456
1457         ap.a_head.a_desc = &vop_nwhiteout_desc;
1458         ap.a_head.a_ops = ops;
1459         ap.a_nch = nch;
1460         ap.a_dvp = dvp;
1461         ap.a_cred = cred;
1462         ap.a_flags = flags;
1463
1464         VFS_MPLOCK1(dvp->v_mount);
1465         DO_OPS(ops, error, &ap, vop_nwhiteout);
1466         VFS_MPUNLOCK(dvp->v_mount);
1467         return(error);
1468 }
1469
1470 /*
1471  * nremove takes a locked, resolved ncp that generally represents a
1472  * positive hit and removes the file.
1473  *
1474  * The dvp passed in is referenced but unlocked.
1475  *
1476  * The namecache is automatically adjusted by this function.  The ncp
1477  * is left locked on return.
1478  *
1479  * MPSAFE
1480  */
1481 int
1482 vop_nremove(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1483             struct ucred *cred)
1484 {
1485         struct vop_nremove_args ap;
1486         VFS_MPLOCK_DECLARE;
1487         int error;
1488
1489         ap.a_head.a_desc = &vop_nremove_desc;
1490         ap.a_head.a_ops = ops;
1491         ap.a_nch = nch;
1492         ap.a_dvp = dvp;
1493         ap.a_cred = cred;
1494
1495         VFS_MPLOCK1(dvp->v_mount);
1496         DO_OPS(ops, error, &ap, vop_nremove);
1497         VFS_MPUNLOCK(dvp->v_mount);
1498         return(error);
1499 }
1500
1501 /*
1502  * nrmdir takes a locked, resolved ncp that generally represents a
1503  * directory and removes the directory.
1504  *
1505  * The dvp passed in is referenced but unlocked.
1506  *
1507  * The namecache is automatically adjusted by this function.  The ncp
1508  * is left locked on return.
1509  *
1510  * MPSAFE
1511  */
1512 int
1513 vop_nrmdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1514            struct ucred *cred)
1515 {
1516         struct vop_nrmdir_args ap;
1517         VFS_MPLOCK_DECLARE;
1518         int error;
1519
1520         ap.a_head.a_desc = &vop_nrmdir_desc;
1521         ap.a_head.a_ops = ops;
1522         ap.a_nch = nch;
1523         ap.a_dvp = dvp;
1524         ap.a_cred = cred;
1525
1526         VFS_MPLOCK1(dvp->v_mount);
1527         DO_OPS(ops, error, &ap, vop_nrmdir);
1528         VFS_MPUNLOCK(dvp->v_mount);
1529         return(error);
1530 }
1531
1532 /*
1533  * nrename takes TWO locked, resolved ncp's and the cred of the caller
1534  * and renames the source ncp to the target ncp.  The target ncp may 
1535  * represent a positive or negative hit.
1536  *
1537  * The fdvp and tdvp passed in are referenced but unlocked.
1538  *
1539  * The namecache is automatically adjusted by this function.  The ncp
1540  * is left locked on return.  The source ncp is typically changed to
1541  * a negative cache hit and the target ncp typically takes on the
1542  * source ncp's underlying file.
1543  *
1544  * MPSAFE
1545  */
1546 int
1547 vop_nrename(struct vop_ops *ops,
1548             struct nchandle *fnch, struct nchandle *tnch,
1549             struct vnode *fdvp, struct vnode *tdvp,
1550             struct ucred *cred)
1551 {
1552         struct vop_nrename_args ap;
1553         VFS_MPLOCK_DECLARE;
1554         int error;
1555
1556         ap.a_head.a_desc = &vop_nrename_desc;
1557         ap.a_head.a_ops = ops;
1558         ap.a_fnch = fnch;
1559         ap.a_tnch = tnch;
1560         ap.a_fdvp = fdvp;
1561         ap.a_tdvp = tdvp;
1562         ap.a_cred = cred;
1563
1564         VFS_MPLOCK1(fdvp->v_mount);
1565         DO_OPS(ops, error, &ap, vop_nrename);
1566         VFS_MPUNLOCK(fdvp->v_mount);
1567         return(error);
1568 }
1569
1570 /************************************************************************
1571  *              PRIMARY VNODE OPERATIONS FORWARDING CALLS               *
1572  ************************************************************************
1573  *
1574  * These procedures are called from VFSs such as unionfs and nullfs
1575  * when they wish to forward an operation on one VFS to another.  The
1576  * argument structure/message is modified and then directly passed to the
1577  * appropriate routine.  This routines may also be called by initiators
1578  * who have an argument structure in hand rather then discreet arguments.
1579  *
1580  * MPSAFE - Caller expected to already hold the appropriate vfs lock.
1581  */
1582 int
1583 vop_vnoperate_ap(struct vop_generic_args *ap)
1584 {
1585         struct vop_ops *ops;
1586         int error;
1587
1588         ops = ap->a_ops;
1589         error = VOCALL(ops, ap);
1590
1591         return (error);
1592 }
1593
1594 /*
1595  * This routine is called by the cache coherency layer to execute the actual
1596  * VFS operation.  If a journaling layer is present we call though it, else
1597  * we call the native VOP functions.
1598  */
1599 int
1600 vop_cache_operate_ap(struct vop_generic_args *ap)
1601 {
1602         struct vop_ops *ops;
1603         int error;
1604
1605         ops = ap->a_ops;
1606         if (ops->head.vv_mount->mnt_vn_journal_ops)
1607                 error = VOCALL(ops->head.vv_mount->mnt_vn_journal_ops, ap);
1608         else
1609                 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1610         return (error);
1611 }
1612
1613
1614 /*
1615  * This routine is called by the journaling layer to execute the actual
1616  * VFS operation.
1617  */
1618 int
1619 vop_journal_operate_ap(struct vop_generic_args *ap)
1620 {
1621         struct vop_ops *ops;
1622         int error;
1623
1624         ops = ap->a_ops;
1625         error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1626
1627         return (error);
1628 }
1629
1630 int
1631 vop_open_ap(struct vop_open_args *ap)
1632 {
1633         int error;
1634
1635         DO_OPS(ap->a_head.a_ops, error, ap, vop_open);
1636         return(error);
1637 }
1638
1639 int
1640 vop_close_ap(struct vop_close_args *ap)
1641 {
1642         int error;
1643
1644         DO_OPS(ap->a_head.a_ops, error, ap, vop_close);
1645         return(error);
1646 }
1647
1648 int
1649 vop_access_ap(struct vop_access_args *ap)
1650 {
1651         int error;
1652
1653         DO_OPS(ap->a_head.a_ops, error, ap, vop_access);
1654         return(error);
1655 }
1656
1657 int
1658 vop_getattr_ap(struct vop_getattr_args *ap)
1659 {
1660         int error;
1661
1662         DO_OPS(ap->a_head.a_ops, error, ap, vop_getattr);
1663         return(error);
1664 }
1665
1666 int
1667 vop_setattr_ap(struct vop_setattr_args *ap)
1668 {
1669         int error;
1670
1671         DO_OPS(ap->a_head.a_ops, error, ap, vop_setattr);
1672         return(error);
1673 }
1674
1675 int
1676 vop_read_ap(struct vop_read_args *ap)
1677 {
1678         int error;
1679
1680         DO_OPS(ap->a_head.a_ops, error, ap, vop_read);
1681         return(error);
1682 }
1683
1684 int
1685 vop_write_ap(struct vop_write_args *ap)
1686 {
1687         int error;
1688
1689         DO_OPS(ap->a_head.a_ops, error, ap, vop_write);
1690         return(error);
1691 }
1692
1693 int
1694 vop_ioctl_ap(struct vop_ioctl_args *ap)
1695 {
1696         int error;
1697
1698         DO_OPS(ap->a_head.a_ops, error, ap, vop_ioctl);
1699         return(error);
1700 }
1701
1702 int
1703 vop_poll_ap(struct vop_poll_args *ap)
1704 {
1705         int error;
1706
1707         DO_OPS(ap->a_head.a_ops, error, ap, vop_poll);
1708         return(error);
1709 }
1710
1711 int
1712 vop_kqfilter_ap(struct vop_kqfilter_args *ap)
1713 {
1714         int error;
1715
1716         DO_OPS(ap->a_head.a_ops, error, ap, vop_kqfilter);
1717         return(error);
1718 }
1719
1720 int
1721 vop_mmap_ap(struct vop_mmap_args *ap)
1722 {
1723         int error;
1724
1725         DO_OPS(ap->a_head.a_ops, error, ap, vop_mmap);
1726         return(error);
1727 }
1728
1729 int
1730 vop_fsync_ap(struct vop_fsync_args *ap)
1731 {
1732         int error;
1733
1734         DO_OPS(ap->a_head.a_ops, error, ap, vop_fsync);
1735         return(error);
1736 }
1737
1738 int
1739 vop_readdir_ap(struct vop_readdir_args *ap)
1740 {
1741         int error;
1742
1743         DO_OPS(ap->a_head.a_ops, error, ap, vop_readdir);
1744         return(error);
1745 }
1746
1747 int
1748 vop_readlink_ap(struct vop_readlink_args *ap)
1749 {
1750         int error;
1751
1752         DO_OPS(ap->a_head.a_ops, error, ap, vop_readlink);
1753         return(error);
1754 }
1755
1756 int
1757 vop_inactive_ap(struct vop_inactive_args *ap)
1758 {
1759         int error;
1760
1761         DO_OPS(ap->a_head.a_ops, error, ap, vop_inactive);
1762         return(error);
1763 }
1764
1765 int
1766 vop_reclaim_ap(struct vop_reclaim_args *ap)
1767 {
1768         int error;
1769
1770         DO_OPS(ap->a_head.a_ops, error, ap, vop_reclaim);
1771         return(error);
1772 }
1773
1774 int
1775 vop_bmap_ap(struct vop_bmap_args *ap)
1776 {
1777         int error;
1778
1779         DO_OPS(ap->a_head.a_ops, error, ap, vop_bmap);
1780         return(error);
1781 }
1782
1783 int
1784 vop_strategy_ap(struct vop_strategy_args *ap)
1785 {
1786         int error;
1787
1788         DO_OPS(ap->a_head.a_ops, error, ap, vop_strategy);
1789         return(error);
1790 }
1791
1792 int
1793 vop_print_ap(struct vop_print_args *ap)
1794 {
1795         int error;
1796
1797         DO_OPS(ap->a_head.a_ops, error, ap, vop_print);
1798         return(error);
1799 }
1800
1801 int
1802 vop_pathconf_ap(struct vop_pathconf_args *ap)
1803 {
1804         int error;
1805
1806         DO_OPS(ap->a_head.a_ops, error, ap, vop_pathconf);
1807         return(error);
1808 }
1809
1810 int
1811 vop_advlock_ap(struct vop_advlock_args *ap)
1812 {
1813         int error;
1814
1815         DO_OPS(ap->a_head.a_ops, error, ap, vop_advlock);
1816         return(error);
1817 }
1818
1819 int
1820 vop_balloc_ap(struct vop_balloc_args *ap)
1821 {
1822         int error;
1823
1824         DO_OPS(ap->a_head.a_ops, error, ap, vop_balloc);
1825         return(error);
1826 }
1827
1828 int
1829 vop_reallocblks_ap(struct vop_reallocblks_args *ap)
1830 {
1831         int error;
1832
1833         DO_OPS(ap->a_head.a_ops, error, ap, vop_reallocblks);
1834         return(error);
1835 }
1836
1837 int
1838 vop_getpages_ap(struct vop_getpages_args *ap)
1839 {
1840         int error;
1841
1842         DO_OPS(ap->a_head.a_ops, error, ap, vop_getpages);
1843         return(error);
1844 }
1845
1846 int
1847 vop_putpages_ap(struct vop_putpages_args *ap)
1848 {
1849         int error;
1850
1851         DO_OPS(ap->a_head.a_ops, error, ap, vop_putpages);
1852         return(error);
1853 }
1854
1855 int
1856 vop_freeblks_ap(struct vop_freeblks_args *ap)
1857 {
1858         int error;
1859
1860         DO_OPS(ap->a_head.a_ops, error, ap, vop_freeblks);
1861         return(error);
1862 }
1863
1864 int
1865 vop_getacl_ap(struct vop_getacl_args *ap)
1866 {
1867         int error;
1868
1869         DO_OPS(ap->a_head.a_ops, error, ap, vop_getacl);
1870         return(error);
1871 }
1872
1873 int
1874 vop_setacl_ap(struct vop_setacl_args *ap)
1875 {
1876         int error;
1877
1878         DO_OPS(ap->a_head.a_ops, error, ap, vop_setacl);
1879         return(error);
1880 }
1881
1882 int
1883 vop_aclcheck_ap(struct vop_aclcheck_args *ap)
1884 {
1885         int error;
1886
1887         DO_OPS(ap->a_head.a_ops, error, ap, vop_aclcheck);
1888         return(error);
1889 }
1890
1891 int
1892 vop_getextattr_ap(struct vop_getextattr_args *ap)
1893 {
1894         int error;
1895
1896         DO_OPS(ap->a_head.a_ops, error, ap, vop_getextattr);
1897         return(error);
1898 }
1899
1900 int
1901 vop_setextattr_ap(struct vop_setextattr_args *ap)
1902 {
1903         int error;
1904
1905         DO_OPS(ap->a_head.a_ops, error, ap, vop_setextattr);
1906         return(error);
1907 }
1908
1909 int
1910 vop_mountctl_ap(struct vop_mountctl_args *ap)
1911 {
1912         int error;
1913
1914         DO_OPS(ap->a_head.a_ops, error, ap, vop_mountctl);
1915         return(error);
1916 }
1917
1918 int
1919 vop_markatime_ap(struct vop_markatime_args *ap)
1920 {
1921         int error;
1922
1923         DO_OPS(ap->a_head.a_ops, error, ap, vop_markatime);
1924         return(error);
1925 }
1926
1927 int
1928 vop_nresolve_ap(struct vop_nresolve_args *ap)
1929 {
1930         int error;
1931
1932         DO_OPS(ap->a_head.a_ops, error, ap, vop_nresolve);
1933         return(error);
1934 }
1935
1936 int
1937 vop_nlookupdotdot_ap(struct vop_nlookupdotdot_args *ap)
1938 {
1939         int error;
1940
1941         DO_OPS(ap->a_head.a_ops, error, ap, vop_nlookupdotdot);
1942         return(error);
1943 }
1944
1945 int
1946 vop_ncreate_ap(struct vop_ncreate_args *ap)
1947 {
1948         int error;
1949
1950         DO_OPS(ap->a_head.a_ops, error, ap, vop_ncreate);
1951         return(error);
1952 }
1953
1954 int
1955 vop_nmkdir_ap(struct vop_nmkdir_args *ap)
1956 {
1957         int error;
1958
1959         DO_OPS(ap->a_head.a_ops, error, ap, vop_nmkdir);
1960         return(error);
1961 }
1962
1963 int
1964 vop_nmknod_ap(struct vop_nmknod_args *ap)
1965 {
1966         int error;
1967
1968         DO_OPS(ap->a_head.a_ops, error, ap, vop_nmknod);
1969         return(error);
1970 }
1971
1972 int
1973 vop_nlink_ap(struct vop_nlink_args *ap)
1974 {
1975         int error;
1976
1977         DO_OPS(ap->a_head.a_ops, error, ap, vop_nlink);
1978         return(error);
1979 }
1980
1981 int
1982 vop_nsymlink_ap(struct vop_nsymlink_args *ap)
1983 {
1984         int error;
1985
1986         DO_OPS(ap->a_head.a_ops, error, ap, vop_nsymlink);
1987         return(error);
1988 }
1989
1990 int
1991 vop_nwhiteout_ap(struct vop_nwhiteout_args *ap)
1992 {
1993         int error;
1994
1995         DO_OPS(ap->a_head.a_ops, error, ap, vop_nwhiteout);
1996         return(error);
1997 }
1998
1999 int
2000 vop_nremove_ap(struct vop_nremove_args *ap)
2001 {
2002         int error;
2003
2004         DO_OPS(ap->a_head.a_ops, error, ap, vop_nremove);
2005         return(error);
2006 }
2007
2008 int
2009 vop_nrmdir_ap(struct vop_nrmdir_args *ap)
2010 {
2011         int error;
2012
2013         DO_OPS(ap->a_head.a_ops, error, ap, vop_nrmdir);
2014         return(error);
2015 }
2016
2017 int
2018 vop_nrename_ap(struct vop_nrename_args *ap)
2019 {
2020         int error;
2021
2022         DO_OPS(ap->a_head.a_ops, error, ap, vop_nrename);
2023         return(error);
2024 }
2025