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