2 * Copyright (c) 2004,2009 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
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
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.
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
35 * Implement vnode ops wrappers. All vnode ops are wrapped through
38 * These wrappers are responsible for hanlding all MPSAFE issues related
39 * to a vnode operation.
42 #include <sys/param.h>
43 #include <sys/systm.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>
54 #include <sys/mount.h>
56 #include <sys/namei.h>
57 #include <sys/reboot.h>
58 #include <sys/socket.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>
68 #include <machine/limits.h>
71 #include <vm/vm_object.h>
72 #include <vm/vm_extern.h>
73 #include <vm/vm_kern.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>
82 #include <sys/thread2.h>
83 #include <sys/mplock2.h>
85 #define VDESCNAME(name) __CONCAT(__CONCAT(vop_,name),_desc)
87 #define VNODEOP_DESC_INIT(name) \
88 struct syslink_desc VDESCNAME(name) = { \
89 __offsetof(struct vop_ops, __CONCAT(vop_, name)), \
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);
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);
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);
150 #define DO_OPS(ops, error, ap, vop_field) \
151 error = ops->vop_field(ap);
153 /************************************************************************
154 * PRIMARY HIGH LEVEL VNODE OPERATIONS CALLS *
155 ************************************************************************
157 * These procedures are called directly from the kernel and/or fileops
158 * code to perform file/device operations on the system.
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
165 * NOTE: The VFS_MPLOCK*() macros handle mounts which do not set
166 * MNTK_MPSAFE or MNTK_xx_MPSAFE.
172 vop_old_lookup(struct vop_ops *ops, struct vnode *dvp,
173 struct vnode **vpp, struct componentname *cnp)
175 struct vop_old_lookup_args ap;
179 ap.a_head.a_desc = &vop_old_lookup_desc;
180 ap.a_head.a_ops = ops;
184 VFS_MPLOCK1(dvp->v_mount);
185 DO_OPS(ops, error, &ap, vop_old_lookup);
186 VFS_MPUNLOCK(dvp->v_mount);
194 vop_old_create(struct vop_ops *ops, struct vnode *dvp,
195 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
197 struct vop_old_create_args ap;
201 ap.a_head.a_desc = &vop_old_create_desc;
202 ap.a_head.a_ops = ops;
208 VFS_MPLOCK1(dvp->v_mount);
209 DO_OPS(ops, error, &ap, vop_old_create);
210 VFS_MPUNLOCK(dvp->v_mount);
218 vop_old_whiteout(struct vop_ops *ops, struct vnode *dvp,
219 struct componentname *cnp, int flags)
221 struct vop_old_whiteout_args ap;
225 ap.a_head.a_desc = &vop_old_whiteout_desc;
226 ap.a_head.a_ops = ops;
231 VFS_MPLOCK1(dvp->v_mount);
232 DO_OPS(ops, error, &ap, vop_old_whiteout);
233 VFS_MPUNLOCK(dvp->v_mount);
241 vop_old_mknod(struct vop_ops *ops, struct vnode *dvp,
242 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
244 struct vop_old_mknod_args ap;
248 ap.a_head.a_desc = &vop_old_mknod_desc;
249 ap.a_head.a_ops = ops;
255 VFS_MPLOCK1(dvp->v_mount);
256 DO_OPS(ops, error, &ap, vop_old_mknod);
257 VFS_MPUNLOCK(dvp->v_mount);
262 * NOTE: VAGE is always cleared when calling VOP_OPEN().
265 vop_open(struct vop_ops *ops, struct vnode *vp, int mode, struct ucred *cred,
268 struct vop_open_args ap;
273 * Decrement 3-2-1-0. Does not decrement beyond 0
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);
282 ap.a_head.a_desc = &vop_open_desc;
283 ap.a_head.a_ops = ops;
289 VFS_MPLOCK1(vp->v_mount);
290 DO_OPS(ops, error, &ap, vop_open);
291 VFS_MPUNLOCK(vp->v_mount);
299 vop_close(struct vop_ops *ops, struct vnode *vp, int fflag)
301 struct vop_close_args ap;
305 ap.a_head.a_desc = &vop_close_desc;
306 ap.a_head.a_ops = ops;
310 VFS_MPLOCK1(vp->v_mount);
311 DO_OPS(ops, error, &ap, vop_close);
312 VFS_MPUNLOCK(vp->v_mount);
320 vop_access(struct vop_ops *ops, struct vnode *vp, int mode, int flags,
323 struct vop_access_args ap;
327 ap.a_head.a_desc = &vop_access_desc;
328 ap.a_head.a_ops = ops;
334 VFS_MPLOCK1(vp->v_mount);
335 DO_OPS(ops, error, &ap, vop_access);
336 VFS_MPUNLOCK(vp->v_mount);
344 vop_getattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap)
346 struct vop_getattr_args ap;
350 ap.a_head.a_desc = &vop_getattr_desc;
351 ap.a_head.a_ops = ops;
355 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_GA_MPSAFE);
356 DO_OPS(ops, error, &ap, vop_getattr);
357 VFS_MPUNLOCK(vp->v_mount);
366 vop_setattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap,
369 struct vop_setattr_args ap;
373 ap.a_head.a_desc = &vop_setattr_desc;
374 ap.a_head.a_ops = ops;
379 VFS_MPLOCK1(vp->v_mount);
380 DO_OPS(ops, error, &ap, vop_setattr);
381 VFS_MPUNLOCK(vp->v_mount);
389 vop_read(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
392 struct vop_read_args ap;
396 ap.a_head.a_desc = &vop_read_desc;
397 ap.a_head.a_ops = ops;
400 ap.a_ioflag = ioflag;
403 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_RD_MPSAFE);
404 DO_OPS(ops, error, &ap, vop_read);
405 VFS_MPUNLOCK(vp->v_mount);
413 vop_write(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
416 struct vop_write_args ap;
418 int error, do_accounting = 0;
420 uint64_t size_before=0, size_after=0;
423 ap.a_head.a_desc = &vop_write_desc;
424 ap.a_head.a_ops = ops;
427 ap.a_ioflag = ioflag;
430 /* is this a regular vnode ? */
431 if ((vp->v_type == VREG) && vfs_accounting_enabled) {
432 if ((error = VOP_GETATTR(vp, &va)) != 0)
434 size_before = va.va_size;
435 /* this file may already have been removed */
440 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_WR_MPSAFE);
441 DO_OPS(ops, error, &ap, vop_write);
442 if ((error == 0) && do_accounting) {
443 size_after = vp->v_filesize;
445 VFS_ACCOUNT(mp, va.va_uid, va.va_gid, size_after - size_before);
447 VFS_MPUNLOCK(vp->v_mount);
455 vop_ioctl(struct vop_ops *ops, struct vnode *vp, u_long command, caddr_t data,
456 int fflag, struct ucred *cred, struct sysmsg *msg)
458 struct vop_ioctl_args ap;
462 ap.a_head.a_desc = &vop_ioctl_desc;
463 ap.a_head.a_ops = ops;
465 ap.a_command = command;
471 VFS_MPLOCK1(vp->v_mount);
472 DO_OPS(ops, error, &ap, vop_ioctl);
473 VFS_MPUNLOCK(vp->v_mount);
481 vop_poll(struct vop_ops *ops, struct vnode *vp, int events, struct ucred *cred)
483 struct vop_poll_args ap;
487 ap.a_head.a_desc = &vop_poll_desc;
488 ap.a_head.a_ops = ops;
490 ap.a_events = events;
493 VFS_MPLOCK1(vp->v_mount);
494 DO_OPS(ops, error, &ap, vop_poll);
495 VFS_MPUNLOCK(vp->v_mount);
503 vop_kqfilter(struct vop_ops *ops, struct vnode *vp, struct knote *kn)
505 struct vop_kqfilter_args ap;
509 ap.a_head.a_desc = &vop_kqfilter_desc;
510 ap.a_head.a_ops = ops;
514 VFS_MPLOCK1(vp->v_mount);
515 DO_OPS(ops, error, &ap, vop_kqfilter);
516 VFS_MPUNLOCK(vp->v_mount);
524 vop_mmap(struct vop_ops *ops, struct vnode *vp, int fflags, struct ucred *cred)
526 struct vop_mmap_args ap;
530 ap.a_head.a_desc = &vop_mmap_desc;
531 ap.a_head.a_ops = ops;
533 ap.a_fflags = fflags;
536 VFS_MPLOCK1(vp->v_mount);
537 DO_OPS(ops, error, &ap, vop_mmap);
538 VFS_MPUNLOCK(vp->v_mount);
546 vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor, int flags)
548 struct vop_fsync_args ap;
552 ap.a_head.a_desc = &vop_fsync_desc;
553 ap.a_head.a_ops = ops;
555 ap.a_waitfor = waitfor;
558 VFS_MPLOCK1(vp->v_mount);
559 DO_OPS(ops, error, &ap, vop_fsync);
560 VFS_MPUNLOCK(vp->v_mount);
568 vop_old_remove(struct vop_ops *ops, struct vnode *dvp,
569 struct vnode *vp, struct componentname *cnp)
571 struct vop_old_remove_args ap;
575 ap.a_head.a_desc = &vop_old_remove_desc;
576 ap.a_head.a_ops = ops;
581 VFS_MPLOCK1(dvp->v_mount);
582 DO_OPS(ops, error, &ap, vop_old_remove);
583 VFS_MPUNLOCK(dvp->v_mount);
591 vop_old_link(struct vop_ops *ops, struct vnode *tdvp,
592 struct vnode *vp, struct componentname *cnp)
594 struct vop_old_link_args ap;
598 ap.a_head.a_desc = &vop_old_link_desc;
599 ap.a_head.a_ops = ops;
604 VFS_MPLOCK1(tdvp->v_mount);
605 DO_OPS(ops, error, &ap, vop_old_link);
606 VFS_MPUNLOCK(tdvp->v_mount);
614 vop_old_rename(struct vop_ops *ops,
615 struct vnode *fdvp, struct vnode *fvp, struct componentname *fcnp,
616 struct vnode *tdvp, struct vnode *tvp, struct componentname *tcnp)
618 struct vop_old_rename_args ap;
622 ap.a_head.a_desc = &vop_old_rename_desc;
623 ap.a_head.a_ops = ops;
631 VFS_MPLOCK1(tdvp->v_mount);
632 DO_OPS(ops, error, &ap, vop_old_rename);
633 VFS_MPUNLOCK(tdvp->v_mount);
641 vop_old_mkdir(struct vop_ops *ops, struct vnode *dvp,
642 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
644 struct vop_old_mkdir_args ap;
648 ap.a_head.a_desc = &vop_old_mkdir_desc;
649 ap.a_head.a_ops = ops;
655 VFS_MPLOCK1(dvp->v_mount);
656 DO_OPS(ops, error, &ap, vop_old_mkdir);
657 VFS_MPUNLOCK(dvp->v_mount);
665 vop_old_rmdir(struct vop_ops *ops, struct vnode *dvp,
666 struct vnode *vp, struct componentname *cnp)
668 struct vop_old_rmdir_args ap;
672 ap.a_head.a_desc = &vop_old_rmdir_desc;
673 ap.a_head.a_ops = ops;
678 VFS_MPLOCK1(dvp->v_mount);
679 DO_OPS(ops, error, &ap, vop_old_rmdir);
680 VFS_MPUNLOCK(dvp->v_mount);
688 vop_old_symlink(struct vop_ops *ops, struct vnode *dvp,
689 struct vnode **vpp, struct componentname *cnp,
690 struct vattr *vap, char *target)
692 struct vop_old_symlink_args ap;
696 ap.a_head.a_desc = &vop_old_symlink_desc;
697 ap.a_head.a_ops = ops;
702 ap.a_target = target;
704 VFS_MPLOCK1(dvp->v_mount);
705 DO_OPS(ops, error, &ap, vop_old_symlink);
706 VFS_MPUNLOCK(dvp->v_mount);
714 vop_readdir(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
715 struct ucred *cred, int *eofflag, int *ncookies, off_t **cookies)
717 struct vop_readdir_args ap;
721 ap.a_head.a_desc = &vop_readdir_desc;
722 ap.a_head.a_ops = ops;
726 ap.a_eofflag = eofflag;
727 ap.a_ncookies = ncookies;
728 ap.a_cookies = cookies;
730 VFS_MPLOCK1(vp->v_mount);
731 DO_OPS(ops, error, &ap, vop_readdir);
732 VFS_MPUNLOCK(vp->v_mount);
740 vop_readlink(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
743 struct vop_readlink_args ap;
747 ap.a_head.a_desc = &vop_readlink_desc;
748 ap.a_head.a_ops = ops;
753 VFS_MPLOCK1(vp->v_mount);
754 DO_OPS(ops, error, &ap, vop_readlink);
755 VFS_MPUNLOCK(vp->v_mount);
763 vop_inactive(struct vop_ops *ops, struct vnode *vp)
765 struct vop_inactive_args ap;
770 ap.a_head.a_desc = &vop_inactive_desc;
771 ap.a_head.a_ops = ops;
775 * WARNING! Deactivation of the vnode can cause it to be recycled,
776 * clearing vp->v_mount.
779 VFS_MPLOCK_FLAG(mp, MNTK_IN_MPSAFE);
780 DO_OPS(ops, error, &ap, vop_inactive);
789 vop_reclaim(struct vop_ops *ops, struct vnode *vp)
791 struct vop_reclaim_args ap;
796 ap.a_head.a_desc = &vop_reclaim_desc;
797 ap.a_head.a_ops = ops;
801 * WARNING! Reclamation of the vnode will clear vp->v_mount.
805 DO_OPS(ops, error, &ap, vop_reclaim);
814 vop_bmap(struct vop_ops *ops, struct vnode *vp, off_t loffset,
815 off_t *doffsetp, int *runp, int *runb, buf_cmd_t cmd)
817 struct vop_bmap_args ap;
821 ap.a_head.a_desc = &vop_bmap_desc;
822 ap.a_head.a_ops = ops;
824 ap.a_loffset = loffset;
825 ap.a_doffsetp = doffsetp;
830 VFS_MPLOCK1(vp->v_mount);
831 DO_OPS(ops, error, &ap, vop_bmap);
832 VFS_MPUNLOCK(vp->v_mount);
840 vop_strategy(struct vop_ops *ops, struct vnode *vp, struct bio *bio)
842 struct vop_strategy_args ap;
846 ap.a_head.a_desc = &vop_strategy_desc;
847 ap.a_head.a_ops = ops;
852 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_SG_MPSAFE);
853 DO_OPS(ops, error, &ap, vop_strategy);
854 VFS_MPUNLOCK(vp->v_mount);
856 /* ugly hack for swap */
858 DO_OPS(ops, error, &ap, vop_strategy);
868 vop_print(struct vop_ops *ops, struct vnode *vp)
870 struct vop_print_args ap;
874 ap.a_head.a_desc = &vop_print_desc;
875 ap.a_head.a_ops = ops;
878 VFS_MPLOCK1(vp->v_mount);
879 DO_OPS(ops, error, &ap, vop_print);
880 VFS_MPUNLOCK(vp->v_mount);
888 vop_pathconf(struct vop_ops *ops, struct vnode *vp, int name,
891 struct vop_pathconf_args ap;
895 ap.a_head.a_desc = &vop_pathconf_desc;
896 ap.a_head.a_ops = ops;
899 ap.a_retval = retval;
901 VFS_MPLOCK1(vp->v_mount);
902 DO_OPS(ops, error, &ap, vop_pathconf);
903 VFS_MPUNLOCK(vp->v_mount);
911 vop_advlock(struct vop_ops *ops, struct vnode *vp, caddr_t id, int op,
912 struct flock *fl, int flags)
914 struct vop_advlock_args ap;
918 ap.a_head.a_desc = &vop_advlock_desc;
919 ap.a_head.a_ops = ops;
926 VFS_MPLOCK1(vp->v_mount);
927 DO_OPS(ops, error, &ap, vop_advlock);
928 VFS_MPUNLOCK(vp->v_mount);
936 vop_balloc(struct vop_ops *ops, struct vnode *vp, off_t startoffset,
937 int size, struct ucred *cred, int flags,
940 struct vop_balloc_args ap;
944 ap.a_head.a_desc = &vop_balloc_desc;
945 ap.a_head.a_ops = ops;
947 ap.a_startoffset = startoffset;
953 VFS_MPLOCK1(vp->v_mount);
954 DO_OPS(ops, error, &ap, vop_balloc);
955 VFS_MPUNLOCK(vp->v_mount);
963 vop_reallocblks(struct vop_ops *ops, struct vnode *vp,
964 struct cluster_save *buflist)
966 struct vop_reallocblks_args ap;
970 ap.a_head.a_desc = &vop_reallocblks_desc;
971 ap.a_head.a_ops = ops;
973 ap.a_buflist = buflist;
975 VFS_MPLOCK1(vp->v_mount);
976 DO_OPS(ops, error, &ap, vop_reallocblks);
977 VFS_MPUNLOCK(vp->v_mount);
985 vop_getpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
986 int reqpage, vm_ooffset_t offset, int seqaccess)
988 struct vop_getpages_args ap;
992 ap.a_head.a_desc = &vop_getpages_desc;
993 ap.a_head.a_ops = ops;
997 ap.a_reqpage = reqpage;
998 ap.a_offset = offset;
999 ap.a_seqaccess = seqaccess;
1001 VFS_MPLOCK1(vp->v_mount);
1002 DO_OPS(ops, error, &ap, vop_getpages);
1003 VFS_MPUNLOCK(vp->v_mount);
1011 vop_putpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
1012 int sync, int *rtvals, vm_ooffset_t offset)
1014 struct vop_putpages_args ap;
1018 ap.a_head.a_desc = &vop_putpages_desc;
1019 ap.a_head.a_ops = ops;
1024 ap.a_rtvals = rtvals;
1025 ap.a_offset = offset;
1027 VFS_MPLOCK1(vp->v_mount);
1028 DO_OPS(ops, error, &ap, vop_putpages);
1029 VFS_MPUNLOCK(vp->v_mount);
1037 vop_freeblks(struct vop_ops *ops, struct vnode *vp, off_t offset, int length)
1039 struct vop_freeblks_args ap;
1043 ap.a_head.a_desc = &vop_freeblks_desc;
1044 ap.a_head.a_ops = ops;
1046 ap.a_offset = offset;
1047 ap.a_length = length;
1049 VFS_MPLOCK1(vp->v_mount);
1050 DO_OPS(ops, error, &ap, vop_freeblks);
1051 VFS_MPUNLOCK(vp->v_mount);
1059 vop_getacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1060 struct acl *aclp, struct ucred *cred)
1062 struct vop_getacl_args ap;
1066 ap.a_head.a_desc = &vop_getacl_desc;
1067 ap.a_head.a_ops = ops;
1073 VFS_MPLOCK1(vp->v_mount);
1074 DO_OPS(ops, error, &ap, vop_getacl);
1075 VFS_MPUNLOCK(vp->v_mount);
1083 vop_setacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1084 struct acl *aclp, struct ucred *cred)
1086 struct vop_setacl_args ap;
1090 ap.a_head.a_desc = &vop_setacl_desc;
1091 ap.a_head.a_ops = ops;
1097 VFS_MPLOCK1(vp->v_mount);
1098 DO_OPS(ops, error, &ap, vop_setacl);
1099 VFS_MPUNLOCK(vp->v_mount);
1107 vop_aclcheck(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1108 struct acl *aclp, struct ucred *cred)
1110 struct vop_aclcheck_args ap;
1114 ap.a_head.a_desc = &vop_aclcheck_desc;
1115 ap.a_head.a_ops = ops;
1121 VFS_MPLOCK1(vp->v_mount);
1122 DO_OPS(ops, error, &ap, vop_aclcheck);
1123 VFS_MPUNLOCK(vp->v_mount);
1131 vop_getextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1132 char *attrname, struct uio *uio, struct ucred *cred)
1134 struct vop_getextattr_args ap;
1138 ap.a_head.a_desc = &vop_getextattr_desc;
1139 ap.a_head.a_ops = ops;
1141 ap.a_attrnamespace = attrnamespace;
1142 ap.a_attrname = attrname;
1146 VFS_MPLOCK1(vp->v_mount);
1147 DO_OPS(ops, error, &ap, vop_getextattr);
1148 VFS_MPUNLOCK(vp->v_mount);
1156 vop_setextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1157 char *attrname, struct uio *uio, struct ucred *cred)
1159 struct vop_setextattr_args ap;
1163 ap.a_head.a_desc = &vop_setextattr_desc;
1164 ap.a_head.a_ops = ops;
1166 ap.a_attrnamespace = attrnamespace;
1167 ap.a_attrname = attrname;
1171 VFS_MPLOCK1(vp->v_mount);
1172 DO_OPS(ops, error, &ap, vop_setextattr);
1173 VFS_MPUNLOCK(vp->v_mount);
1181 vop_mountctl(struct vop_ops *ops, struct vnode *vp, int op, struct file *fp,
1182 const void *ctl, int ctllen, void *buf, int buflen, int *res)
1184 struct vop_mountctl_args ap;
1188 ap.a_head.a_desc = &vop_mountctl_desc;
1189 ap.a_head.a_ops = ops;
1193 ap.a_ctllen = ctllen;
1195 ap.a_buflen = buflen;
1198 VFS_MPLOCK1(vp->v_mount);
1199 DO_OPS(ops, error, &ap, vop_mountctl);
1200 VFS_MPUNLOCK(vp->v_mount);
1208 vop_markatime(struct vop_ops *ops, struct vnode *vp, struct ucred *cred)
1210 struct vop_markatime_args ap;
1214 ap.a_head.a_desc = &vop_markatime_desc;
1215 ap.a_head.a_ops = ops;
1219 VFS_MPLOCK1(vp->v_mount);
1220 DO_OPS(ops, error, &ap, vop_markatime);
1221 VFS_MPUNLOCK(vp->v_mount);
1228 * nresolve takes a locked ncp, a referenced but unlocked dvp, and a cred,
1229 * and resolves the ncp into a positive or negative hit.
1231 * The namecache is automatically adjusted by this function. The ncp
1232 * is left locked on return.
1237 vop_nresolve(struct vop_ops *ops, struct nchandle *nch,
1238 struct vnode *dvp, struct ucred *cred)
1240 struct vop_nresolve_args ap;
1244 ap.a_head.a_desc = &vop_nresolve_desc;
1245 ap.a_head.a_ops = ops;
1250 VFS_MPLOCK1(dvp->v_mount);
1251 DO_OPS(ops, error, &ap, vop_nresolve);
1252 VFS_MPUNLOCK(dvp->v_mount);
1257 * nlookupdotdot takes an unlocked directory, referenced dvp, and looks
1258 * up "..", returning a locked parent directory in *vpp. If an error
1259 * occurs *vpp will be NULL.
1264 vop_nlookupdotdot(struct vop_ops *ops, struct vnode *dvp,
1265 struct vnode **vpp, struct ucred *cred, char **fakename)
1267 struct vop_nlookupdotdot_args ap;
1271 ap.a_head.a_desc = &vop_nlookupdotdot_desc;
1272 ap.a_head.a_ops = ops;
1276 ap.a_fakename = fakename;
1278 VFS_MPLOCK1(dvp->v_mount);
1279 DO_OPS(ops, error, &ap, vop_nlookupdotdot);
1280 VFS_MPUNLOCK(dvp->v_mount);
1285 * ncreate takes a locked, resolved ncp that typically represents a negative
1286 * cache hit and creates the file or node specified by the ncp, cred, and
1287 * vattr. If no error occurs a locked vnode is returned in *vpp.
1289 * The dvp passed in is referenced but unlocked.
1291 * The namecache is automatically adjusted by this function. The ncp
1292 * is left locked on return.
1297 vop_ncreate(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1298 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1300 struct vop_ncreate_args ap;
1304 ap.a_head.a_desc = &vop_ncreate_desc;
1305 ap.a_head.a_ops = ops;
1312 VFS_MPLOCK1(dvp->v_mount);
1313 DO_OPS(ops, error, &ap, vop_ncreate);
1314 VFS_MPUNLOCK(dvp->v_mount);
1319 * nmkdir takes a locked, resolved ncp that typically represents a negative
1320 * cache hit and creates the directory specified by the ncp, cred, and
1321 * vattr. If no error occurs a locked vnode is returned in *vpp.
1323 * The dvp passed in is referenced but unlocked.
1325 * The namecache is automatically adjusted by this function. The ncp
1326 * is left locked on return.
1331 vop_nmkdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1332 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1334 struct vop_nmkdir_args ap;
1338 ap.a_head.a_desc = &vop_nmkdir_desc;
1339 ap.a_head.a_ops = ops;
1346 VFS_MPLOCK1(dvp->v_mount);
1347 DO_OPS(ops, error, &ap, vop_nmkdir);
1348 VFS_MPUNLOCK(dvp->v_mount);
1353 * nmknod takes a locked, resolved ncp that typically represents a negative
1354 * cache hit and creates the node specified by the ncp, cred, and
1355 * vattr. If no error occurs a locked vnode is returned in *vpp.
1357 * The dvp passed in is referenced but unlocked.
1359 * The namecache is automatically adjusted by this function. The ncp
1360 * is left locked on return.
1365 vop_nmknod(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1366 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1368 struct vop_nmknod_args ap;
1372 ap.a_head.a_desc = &vop_nmknod_desc;
1373 ap.a_head.a_ops = ops;
1380 VFS_MPLOCK1(dvp->v_mount);
1381 DO_OPS(ops, error, &ap, vop_nmknod);
1382 VFS_MPUNLOCK(dvp->v_mount);
1387 * nlink takes a locked, resolved ncp that typically represents a negative
1388 * cache hit and creates the node specified by the ncp, cred, and
1389 * existing vnode. The passed vp must be locked and will remain locked
1390 * on return, as does the ncp, whether an error occurs or not.
1392 * The dvp passed in is referenced but unlocked.
1394 * The namecache is automatically adjusted by this function. The ncp
1395 * is left locked on return.
1400 vop_nlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1401 struct vnode *vp, struct ucred *cred)
1403 struct vop_nlink_args ap;
1407 ap.a_head.a_desc = &vop_nlink_desc;
1408 ap.a_head.a_ops = ops;
1414 VFS_MPLOCK1(dvp->v_mount);
1415 DO_OPS(ops, error, &ap, vop_nlink);
1416 VFS_MPUNLOCK(dvp->v_mount);
1421 * nsymlink takes a locked, resolved ncp that typically represents a negative
1422 * cache hit and creates a symbolic link based on cred, vap, and target (the
1423 * contents of the link). If no error occurs a locked vnode is returned in
1426 * The dvp passed in is referenced but unlocked.
1428 * The namecache is automatically adjusted by this function. The ncp
1429 * is left locked on return.
1434 vop_nsymlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1435 struct vnode **vpp, struct ucred *cred,
1436 struct vattr *vap, char *target)
1438 struct vop_nsymlink_args ap;
1442 ap.a_head.a_desc = &vop_nsymlink_desc;
1443 ap.a_head.a_ops = ops;
1449 ap.a_target = target;
1451 VFS_MPLOCK1(dvp->v_mount);
1452 DO_OPS(ops, error, &ap, vop_nsymlink);
1453 VFS_MPUNLOCK(dvp->v_mount);
1458 * nwhiteout takes a locked, resolved ncp that can represent a positive or
1459 * negative hit and executes the whiteout function specified in flags.
1461 * The dvp passed in is referenced but unlocked.
1463 * The namecache is automatically adjusted by this function. The ncp
1464 * is left locked on return.
1469 vop_nwhiteout(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1470 struct ucred *cred, int flags)
1472 struct vop_nwhiteout_args ap;
1476 ap.a_head.a_desc = &vop_nwhiteout_desc;
1477 ap.a_head.a_ops = ops;
1483 VFS_MPLOCK1(dvp->v_mount);
1484 DO_OPS(ops, error, &ap, vop_nwhiteout);
1485 VFS_MPUNLOCK(dvp->v_mount);
1490 * nremove takes a locked, resolved ncp that generally represents a
1491 * positive hit and removes the file.
1493 * The dvp passed in is referenced but unlocked.
1495 * The namecache is automatically adjusted by this function. The ncp
1496 * is left locked on return.
1501 vop_nremove(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1504 struct vop_nremove_args ap;
1509 ap.a_head.a_desc = &vop_nremove_desc;
1510 ap.a_head.a_ops = ops;
1515 if ((error = VOP_GETATTR(nch->ncp->nc_vp, &va)) != 0)
1518 VFS_MPLOCK1(dvp->v_mount);
1519 DO_OPS(ops, error, &ap, vop_nremove);
1520 /* Only update space counters if this is the last hard link */
1521 if ((error == 0) && (va.va_nlink == 1)) {
1522 VFS_ACCOUNT(nch->mount, va.va_uid, va.va_gid, -va.va_size);
1524 VFS_MPUNLOCK(dvp->v_mount);
1529 * nrmdir takes a locked, resolved ncp that generally represents a
1530 * directory and removes the directory.
1532 * The dvp passed in is referenced but unlocked.
1534 * The namecache is automatically adjusted by this function. The ncp
1535 * is left locked on return.
1540 vop_nrmdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1543 struct vop_nrmdir_args ap;
1547 ap.a_head.a_desc = &vop_nrmdir_desc;
1548 ap.a_head.a_ops = ops;
1553 VFS_MPLOCK1(dvp->v_mount);
1554 DO_OPS(ops, error, &ap, vop_nrmdir);
1555 VFS_MPUNLOCK(dvp->v_mount);
1560 * nrename takes TWO locked, resolved ncp's and the cred of the caller
1561 * and renames the source ncp to the target ncp. The target ncp may
1562 * represent a positive or negative hit.
1564 * The fdvp and tdvp passed in are referenced but unlocked.
1566 * The namecache is automatically adjusted by this function. The ncp
1567 * is left locked on return. The source ncp is typically changed to
1568 * a negative cache hit and the target ncp typically takes on the
1569 * source ncp's underlying file.
1574 vop_nrename(struct vop_ops *ops,
1575 struct nchandle *fnch, struct nchandle *tnch,
1576 struct vnode *fdvp, struct vnode *tdvp,
1579 struct vop_nrename_args ap;
1583 ap.a_head.a_desc = &vop_nrename_desc;
1584 ap.a_head.a_ops = ops;
1591 VFS_MPLOCK1(fdvp->v_mount);
1592 DO_OPS(ops, error, &ap, vop_nrename);
1593 VFS_MPUNLOCK(fdvp->v_mount);
1597 /************************************************************************
1598 * PRIMARY VNODE OPERATIONS FORWARDING CALLS *
1599 ************************************************************************
1601 * These procedures are called from VFSs such as unionfs and nullfs
1602 * when they wish to forward an operation on one VFS to another. The
1603 * argument structure/message is modified and then directly passed to the
1604 * appropriate routine. This routines may also be called by initiators
1605 * who have an argument structure in hand rather then discreet arguments.
1607 * MPSAFE - Caller expected to already hold the appropriate vfs lock.
1610 vop_vnoperate_ap(struct vop_generic_args *ap)
1612 struct vop_ops *ops;
1616 error = VOCALL(ops, ap);
1622 * This routine is called by the cache coherency layer to execute the actual
1623 * VFS operation. If a journaling layer is present we call though it, else
1624 * we call the native VOP functions.
1627 vop_cache_operate_ap(struct vop_generic_args *ap)
1629 struct vop_ops *ops;
1633 if (ops->head.vv_mount->mnt_vn_journal_ops)
1634 error = VOCALL(ops->head.vv_mount->mnt_vn_journal_ops, ap);
1636 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1642 * This routine is called by the journaling layer to execute the actual
1646 vop_journal_operate_ap(struct vop_generic_args *ap)
1648 struct vop_ops *ops;
1652 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1658 vop_open_ap(struct vop_open_args *ap)
1662 DO_OPS(ap->a_head.a_ops, error, ap, vop_open);
1667 vop_close_ap(struct vop_close_args *ap)
1671 DO_OPS(ap->a_head.a_ops, error, ap, vop_close);
1676 vop_access_ap(struct vop_access_args *ap)
1680 DO_OPS(ap->a_head.a_ops, error, ap, vop_access);
1685 vop_getattr_ap(struct vop_getattr_args *ap)
1689 DO_OPS(ap->a_head.a_ops, error, ap, vop_getattr);
1694 vop_setattr_ap(struct vop_setattr_args *ap)
1698 DO_OPS(ap->a_head.a_ops, error, ap, vop_setattr);
1703 vop_read_ap(struct vop_read_args *ap)
1707 DO_OPS(ap->a_head.a_ops, error, ap, vop_read);
1712 vop_write_ap(struct vop_write_args *ap)
1716 DO_OPS(ap->a_head.a_ops, error, ap, vop_write);
1721 vop_ioctl_ap(struct vop_ioctl_args *ap)
1725 DO_OPS(ap->a_head.a_ops, error, ap, vop_ioctl);
1730 vop_poll_ap(struct vop_poll_args *ap)
1734 DO_OPS(ap->a_head.a_ops, error, ap, vop_poll);
1739 vop_kqfilter_ap(struct vop_kqfilter_args *ap)
1743 DO_OPS(ap->a_head.a_ops, error, ap, vop_kqfilter);
1748 vop_mmap_ap(struct vop_mmap_args *ap)
1752 DO_OPS(ap->a_head.a_ops, error, ap, vop_mmap);
1757 vop_fsync_ap(struct vop_fsync_args *ap)
1761 DO_OPS(ap->a_head.a_ops, error, ap, vop_fsync);
1766 vop_readdir_ap(struct vop_readdir_args *ap)
1770 DO_OPS(ap->a_head.a_ops, error, ap, vop_readdir);
1775 vop_readlink_ap(struct vop_readlink_args *ap)
1779 DO_OPS(ap->a_head.a_ops, error, ap, vop_readlink);
1784 vop_inactive_ap(struct vop_inactive_args *ap)
1788 DO_OPS(ap->a_head.a_ops, error, ap, vop_inactive);
1793 vop_reclaim_ap(struct vop_reclaim_args *ap)
1797 DO_OPS(ap->a_head.a_ops, error, ap, vop_reclaim);
1802 vop_bmap_ap(struct vop_bmap_args *ap)
1806 DO_OPS(ap->a_head.a_ops, error, ap, vop_bmap);
1811 vop_strategy_ap(struct vop_strategy_args *ap)
1815 DO_OPS(ap->a_head.a_ops, error, ap, vop_strategy);
1820 vop_print_ap(struct vop_print_args *ap)
1824 DO_OPS(ap->a_head.a_ops, error, ap, vop_print);
1829 vop_pathconf_ap(struct vop_pathconf_args *ap)
1833 DO_OPS(ap->a_head.a_ops, error, ap, vop_pathconf);
1838 vop_advlock_ap(struct vop_advlock_args *ap)
1842 DO_OPS(ap->a_head.a_ops, error, ap, vop_advlock);
1847 vop_balloc_ap(struct vop_balloc_args *ap)
1851 DO_OPS(ap->a_head.a_ops, error, ap, vop_balloc);
1856 vop_reallocblks_ap(struct vop_reallocblks_args *ap)
1860 DO_OPS(ap->a_head.a_ops, error, ap, vop_reallocblks);
1865 vop_getpages_ap(struct vop_getpages_args *ap)
1869 DO_OPS(ap->a_head.a_ops, error, ap, vop_getpages);
1874 vop_putpages_ap(struct vop_putpages_args *ap)
1878 DO_OPS(ap->a_head.a_ops, error, ap, vop_putpages);
1883 vop_freeblks_ap(struct vop_freeblks_args *ap)
1887 DO_OPS(ap->a_head.a_ops, error, ap, vop_freeblks);
1892 vop_getacl_ap(struct vop_getacl_args *ap)
1896 DO_OPS(ap->a_head.a_ops, error, ap, vop_getacl);
1901 vop_setacl_ap(struct vop_setacl_args *ap)
1905 DO_OPS(ap->a_head.a_ops, error, ap, vop_setacl);
1910 vop_aclcheck_ap(struct vop_aclcheck_args *ap)
1914 DO_OPS(ap->a_head.a_ops, error, ap, vop_aclcheck);
1919 vop_getextattr_ap(struct vop_getextattr_args *ap)
1923 DO_OPS(ap->a_head.a_ops, error, ap, vop_getextattr);
1928 vop_setextattr_ap(struct vop_setextattr_args *ap)
1932 DO_OPS(ap->a_head.a_ops, error, ap, vop_setextattr);
1937 vop_mountctl_ap(struct vop_mountctl_args *ap)
1941 DO_OPS(ap->a_head.a_ops, error, ap, vop_mountctl);
1946 vop_markatime_ap(struct vop_markatime_args *ap)
1950 DO_OPS(ap->a_head.a_ops, error, ap, vop_markatime);
1955 vop_nresolve_ap(struct vop_nresolve_args *ap)
1959 DO_OPS(ap->a_head.a_ops, error, ap, vop_nresolve);
1964 vop_nlookupdotdot_ap(struct vop_nlookupdotdot_args *ap)
1968 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlookupdotdot);
1973 vop_ncreate_ap(struct vop_ncreate_args *ap)
1977 DO_OPS(ap->a_head.a_ops, error, ap, vop_ncreate);
1982 vop_nmkdir_ap(struct vop_nmkdir_args *ap)
1986 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmkdir);
1991 vop_nmknod_ap(struct vop_nmknod_args *ap)
1995 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmknod);
2000 vop_nlink_ap(struct vop_nlink_args *ap)
2004 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlink);
2009 vop_nsymlink_ap(struct vop_nsymlink_args *ap)
2013 DO_OPS(ap->a_head.a_ops, error, ap, vop_nsymlink);
2018 vop_nwhiteout_ap(struct vop_nwhiteout_args *ap)
2022 DO_OPS(ap->a_head.a_ops, error, ap, vop_nwhiteout);
2027 vop_nremove_ap(struct vop_nremove_args *ap)
2031 DO_OPS(ap->a_head.a_ops, error, ap, vop_nremove);
2036 vop_nrmdir_ap(struct vop_nrmdir_args *ap)
2040 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrmdir);
2045 vop_nrename_ap(struct vop_nrename_args *ap)
2049 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrename);