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