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) {
433 if ((error = VOP_GETATTR(vp, &va)) != 0)
435 size_before = va.va_size;
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;
443 VFS_ACCOUNT(mp, va.va_uid, va.va_gid, size_after - size_before);
445 VFS_MPUNLOCK(vp->v_mount);
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)
456 struct vop_ioctl_args ap;
460 ap.a_head.a_desc = &vop_ioctl_desc;
461 ap.a_head.a_ops = ops;
463 ap.a_command = command;
469 VFS_MPLOCK1(vp->v_mount);
470 DO_OPS(ops, error, &ap, vop_ioctl);
471 VFS_MPUNLOCK(vp->v_mount);
479 vop_poll(struct vop_ops *ops, struct vnode *vp, int events, struct ucred *cred)
481 struct vop_poll_args ap;
485 ap.a_head.a_desc = &vop_poll_desc;
486 ap.a_head.a_ops = ops;
488 ap.a_events = events;
491 VFS_MPLOCK1(vp->v_mount);
492 DO_OPS(ops, error, &ap, vop_poll);
493 VFS_MPUNLOCK(vp->v_mount);
501 vop_kqfilter(struct vop_ops *ops, struct vnode *vp, struct knote *kn)
503 struct vop_kqfilter_args ap;
507 ap.a_head.a_desc = &vop_kqfilter_desc;
508 ap.a_head.a_ops = ops;
512 VFS_MPLOCK1(vp->v_mount);
513 DO_OPS(ops, error, &ap, vop_kqfilter);
514 VFS_MPUNLOCK(vp->v_mount);
522 vop_mmap(struct vop_ops *ops, struct vnode *vp, int fflags, struct ucred *cred)
524 struct vop_mmap_args ap;
528 ap.a_head.a_desc = &vop_mmap_desc;
529 ap.a_head.a_ops = ops;
531 ap.a_fflags = fflags;
534 VFS_MPLOCK1(vp->v_mount);
535 DO_OPS(ops, error, &ap, vop_mmap);
536 VFS_MPUNLOCK(vp->v_mount);
544 vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor, int flags)
546 struct vop_fsync_args ap;
550 ap.a_head.a_desc = &vop_fsync_desc;
551 ap.a_head.a_ops = ops;
553 ap.a_waitfor = waitfor;
556 VFS_MPLOCK1(vp->v_mount);
557 DO_OPS(ops, error, &ap, vop_fsync);
558 VFS_MPUNLOCK(vp->v_mount);
566 vop_old_remove(struct vop_ops *ops, struct vnode *dvp,
567 struct vnode *vp, struct componentname *cnp)
569 struct vop_old_remove_args ap;
573 ap.a_head.a_desc = &vop_old_remove_desc;
574 ap.a_head.a_ops = ops;
579 VFS_MPLOCK1(dvp->v_mount);
580 DO_OPS(ops, error, &ap, vop_old_remove);
581 VFS_MPUNLOCK(dvp->v_mount);
589 vop_old_link(struct vop_ops *ops, struct vnode *tdvp,
590 struct vnode *vp, struct componentname *cnp)
592 struct vop_old_link_args ap;
596 ap.a_head.a_desc = &vop_old_link_desc;
597 ap.a_head.a_ops = ops;
602 VFS_MPLOCK1(tdvp->v_mount);
603 DO_OPS(ops, error, &ap, vop_old_link);
604 VFS_MPUNLOCK(tdvp->v_mount);
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)
616 struct vop_old_rename_args ap;
620 ap.a_head.a_desc = &vop_old_rename_desc;
621 ap.a_head.a_ops = ops;
629 VFS_MPLOCK1(tdvp->v_mount);
630 DO_OPS(ops, error, &ap, vop_old_rename);
631 VFS_MPUNLOCK(tdvp->v_mount);
639 vop_old_mkdir(struct vop_ops *ops, struct vnode *dvp,
640 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
642 struct vop_old_mkdir_args ap;
646 ap.a_head.a_desc = &vop_old_mkdir_desc;
647 ap.a_head.a_ops = ops;
653 VFS_MPLOCK1(dvp->v_mount);
654 DO_OPS(ops, error, &ap, vop_old_mkdir);
655 VFS_MPUNLOCK(dvp->v_mount);
663 vop_old_rmdir(struct vop_ops *ops, struct vnode *dvp,
664 struct vnode *vp, struct componentname *cnp)
666 struct vop_old_rmdir_args ap;
670 ap.a_head.a_desc = &vop_old_rmdir_desc;
671 ap.a_head.a_ops = ops;
676 VFS_MPLOCK1(dvp->v_mount);
677 DO_OPS(ops, error, &ap, vop_old_rmdir);
678 VFS_MPUNLOCK(dvp->v_mount);
686 vop_old_symlink(struct vop_ops *ops, struct vnode *dvp,
687 struct vnode **vpp, struct componentname *cnp,
688 struct vattr *vap, char *target)
690 struct vop_old_symlink_args ap;
694 ap.a_head.a_desc = &vop_old_symlink_desc;
695 ap.a_head.a_ops = ops;
700 ap.a_target = target;
702 VFS_MPLOCK1(dvp->v_mount);
703 DO_OPS(ops, error, &ap, vop_old_symlink);
704 VFS_MPUNLOCK(dvp->v_mount);
712 vop_readdir(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
713 struct ucred *cred, int *eofflag, int *ncookies, off_t **cookies)
715 struct vop_readdir_args ap;
719 ap.a_head.a_desc = &vop_readdir_desc;
720 ap.a_head.a_ops = ops;
724 ap.a_eofflag = eofflag;
725 ap.a_ncookies = ncookies;
726 ap.a_cookies = cookies;
728 VFS_MPLOCK1(vp->v_mount);
729 DO_OPS(ops, error, &ap, vop_readdir);
730 VFS_MPUNLOCK(vp->v_mount);
738 vop_readlink(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
741 struct vop_readlink_args ap;
745 ap.a_head.a_desc = &vop_readlink_desc;
746 ap.a_head.a_ops = ops;
751 VFS_MPLOCK1(vp->v_mount);
752 DO_OPS(ops, error, &ap, vop_readlink);
753 VFS_MPUNLOCK(vp->v_mount);
761 vop_inactive(struct vop_ops *ops, struct vnode *vp)
763 struct vop_inactive_args ap;
768 ap.a_head.a_desc = &vop_inactive_desc;
769 ap.a_head.a_ops = ops;
773 * WARNING! Deactivation of the vnode can cause it to be recycled,
774 * clearing vp->v_mount.
777 VFS_MPLOCK_FLAG(mp, MNTK_IN_MPSAFE);
778 DO_OPS(ops, error, &ap, vop_inactive);
787 vop_reclaim(struct vop_ops *ops, struct vnode *vp)
789 struct vop_reclaim_args ap;
794 ap.a_head.a_desc = &vop_reclaim_desc;
795 ap.a_head.a_ops = ops;
799 * WARNING! Reclamation of the vnode will clear vp->v_mount.
803 DO_OPS(ops, error, &ap, vop_reclaim);
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)
815 struct vop_bmap_args ap;
819 ap.a_head.a_desc = &vop_bmap_desc;
820 ap.a_head.a_ops = ops;
822 ap.a_loffset = loffset;
823 ap.a_doffsetp = doffsetp;
828 VFS_MPLOCK1(vp->v_mount);
829 DO_OPS(ops, error, &ap, vop_bmap);
830 VFS_MPUNLOCK(vp->v_mount);
838 vop_strategy(struct vop_ops *ops, struct vnode *vp, struct bio *bio)
840 struct vop_strategy_args ap;
844 ap.a_head.a_desc = &vop_strategy_desc;
845 ap.a_head.a_ops = ops;
850 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_SG_MPSAFE);
851 DO_OPS(ops, error, &ap, vop_strategy);
852 VFS_MPUNLOCK(vp->v_mount);
854 /* ugly hack for swap */
856 DO_OPS(ops, error, &ap, vop_strategy);
866 vop_print(struct vop_ops *ops, struct vnode *vp)
868 struct vop_print_args ap;
872 ap.a_head.a_desc = &vop_print_desc;
873 ap.a_head.a_ops = ops;
876 VFS_MPLOCK1(vp->v_mount);
877 DO_OPS(ops, error, &ap, vop_print);
878 VFS_MPUNLOCK(vp->v_mount);
886 vop_pathconf(struct vop_ops *ops, struct vnode *vp, int name,
889 struct vop_pathconf_args ap;
893 ap.a_head.a_desc = &vop_pathconf_desc;
894 ap.a_head.a_ops = ops;
897 ap.a_retval = retval;
899 VFS_MPLOCK1(vp->v_mount);
900 DO_OPS(ops, error, &ap, vop_pathconf);
901 VFS_MPUNLOCK(vp->v_mount);
909 vop_advlock(struct vop_ops *ops, struct vnode *vp, caddr_t id, int op,
910 struct flock *fl, int flags)
912 struct vop_advlock_args ap;
916 ap.a_head.a_desc = &vop_advlock_desc;
917 ap.a_head.a_ops = ops;
924 VFS_MPLOCK1(vp->v_mount);
925 DO_OPS(ops, error, &ap, vop_advlock);
926 VFS_MPUNLOCK(vp->v_mount);
934 vop_balloc(struct vop_ops *ops, struct vnode *vp, off_t startoffset,
935 int size, struct ucred *cred, int flags,
938 struct vop_balloc_args ap;
942 ap.a_head.a_desc = &vop_balloc_desc;
943 ap.a_head.a_ops = ops;
945 ap.a_startoffset = startoffset;
951 VFS_MPLOCK1(vp->v_mount);
952 DO_OPS(ops, error, &ap, vop_balloc);
953 VFS_MPUNLOCK(vp->v_mount);
961 vop_reallocblks(struct vop_ops *ops, struct vnode *vp,
962 struct cluster_save *buflist)
964 struct vop_reallocblks_args ap;
968 ap.a_head.a_desc = &vop_reallocblks_desc;
969 ap.a_head.a_ops = ops;
971 ap.a_buflist = buflist;
973 VFS_MPLOCK1(vp->v_mount);
974 DO_OPS(ops, error, &ap, vop_reallocblks);
975 VFS_MPUNLOCK(vp->v_mount);
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)
986 struct vop_getpages_args ap;
990 ap.a_head.a_desc = &vop_getpages_desc;
991 ap.a_head.a_ops = ops;
995 ap.a_reqpage = reqpage;
996 ap.a_offset = offset;
997 ap.a_seqaccess = seqaccess;
999 VFS_MPLOCK1(vp->v_mount);
1000 DO_OPS(ops, error, &ap, vop_getpages);
1001 VFS_MPUNLOCK(vp->v_mount);
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)
1012 struct vop_putpages_args ap;
1016 ap.a_head.a_desc = &vop_putpages_desc;
1017 ap.a_head.a_ops = ops;
1022 ap.a_rtvals = rtvals;
1023 ap.a_offset = offset;
1025 VFS_MPLOCK1(vp->v_mount);
1026 DO_OPS(ops, error, &ap, vop_putpages);
1027 VFS_MPUNLOCK(vp->v_mount);
1035 vop_freeblks(struct vop_ops *ops, struct vnode *vp, off_t offset, int length)
1037 struct vop_freeblks_args ap;
1041 ap.a_head.a_desc = &vop_freeblks_desc;
1042 ap.a_head.a_ops = ops;
1044 ap.a_offset = offset;
1045 ap.a_length = length;
1047 VFS_MPLOCK1(vp->v_mount);
1048 DO_OPS(ops, error, &ap, vop_freeblks);
1049 VFS_MPUNLOCK(vp->v_mount);
1057 vop_getacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1058 struct acl *aclp, struct ucred *cred)
1060 struct vop_getacl_args ap;
1064 ap.a_head.a_desc = &vop_getacl_desc;
1065 ap.a_head.a_ops = ops;
1071 VFS_MPLOCK1(vp->v_mount);
1072 DO_OPS(ops, error, &ap, vop_getacl);
1073 VFS_MPUNLOCK(vp->v_mount);
1081 vop_setacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1082 struct acl *aclp, struct ucred *cred)
1084 struct vop_setacl_args ap;
1088 ap.a_head.a_desc = &vop_setacl_desc;
1089 ap.a_head.a_ops = ops;
1095 VFS_MPLOCK1(vp->v_mount);
1096 DO_OPS(ops, error, &ap, vop_setacl);
1097 VFS_MPUNLOCK(vp->v_mount);
1105 vop_aclcheck(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1106 struct acl *aclp, struct ucred *cred)
1108 struct vop_aclcheck_args ap;
1112 ap.a_head.a_desc = &vop_aclcheck_desc;
1113 ap.a_head.a_ops = ops;
1119 VFS_MPLOCK1(vp->v_mount);
1120 DO_OPS(ops, error, &ap, vop_aclcheck);
1121 VFS_MPUNLOCK(vp->v_mount);
1129 vop_getextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1130 char *attrname, struct uio *uio, struct ucred *cred)
1132 struct vop_getextattr_args ap;
1136 ap.a_head.a_desc = &vop_getextattr_desc;
1137 ap.a_head.a_ops = ops;
1139 ap.a_attrnamespace = attrnamespace;
1140 ap.a_attrname = attrname;
1144 VFS_MPLOCK1(vp->v_mount);
1145 DO_OPS(ops, error, &ap, vop_getextattr);
1146 VFS_MPUNLOCK(vp->v_mount);
1154 vop_setextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1155 char *attrname, struct uio *uio, struct ucred *cred)
1157 struct vop_setextattr_args ap;
1161 ap.a_head.a_desc = &vop_setextattr_desc;
1162 ap.a_head.a_ops = ops;
1164 ap.a_attrnamespace = attrnamespace;
1165 ap.a_attrname = attrname;
1169 VFS_MPLOCK1(vp->v_mount);
1170 DO_OPS(ops, error, &ap, vop_setextattr);
1171 VFS_MPUNLOCK(vp->v_mount);
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)
1182 struct vop_mountctl_args ap;
1186 ap.a_head.a_desc = &vop_mountctl_desc;
1187 ap.a_head.a_ops = ops;
1191 ap.a_ctllen = ctllen;
1193 ap.a_buflen = buflen;
1196 VFS_MPLOCK1(vp->v_mount);
1197 DO_OPS(ops, error, &ap, vop_mountctl);
1198 VFS_MPUNLOCK(vp->v_mount);
1206 vop_markatime(struct vop_ops *ops, struct vnode *vp, struct ucred *cred)
1208 struct vop_markatime_args ap;
1212 ap.a_head.a_desc = &vop_markatime_desc;
1213 ap.a_head.a_ops = ops;
1217 VFS_MPLOCK1(vp->v_mount);
1218 DO_OPS(ops, error, &ap, vop_markatime);
1219 VFS_MPUNLOCK(vp->v_mount);
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.
1229 * The namecache is automatically adjusted by this function. The ncp
1230 * is left locked on return.
1235 vop_nresolve(struct vop_ops *ops, struct nchandle *nch,
1236 struct vnode *dvp, struct ucred *cred)
1238 struct vop_nresolve_args ap;
1242 ap.a_head.a_desc = &vop_nresolve_desc;
1243 ap.a_head.a_ops = ops;
1248 VFS_MPLOCK1(dvp->v_mount);
1249 DO_OPS(ops, error, &ap, vop_nresolve);
1250 VFS_MPUNLOCK(dvp->v_mount);
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.
1262 vop_nlookupdotdot(struct vop_ops *ops, struct vnode *dvp,
1263 struct vnode **vpp, struct ucred *cred, char **fakename)
1265 struct vop_nlookupdotdot_args ap;
1269 ap.a_head.a_desc = &vop_nlookupdotdot_desc;
1270 ap.a_head.a_ops = ops;
1274 ap.a_fakename = fakename;
1276 VFS_MPLOCK1(dvp->v_mount);
1277 DO_OPS(ops, error, &ap, vop_nlookupdotdot);
1278 VFS_MPUNLOCK(dvp->v_mount);
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.
1287 * The dvp passed in is referenced but unlocked.
1289 * The namecache is automatically adjusted by this function. The ncp
1290 * is left locked on return.
1295 vop_ncreate(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1296 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1298 struct vop_ncreate_args ap;
1302 ap.a_head.a_desc = &vop_ncreate_desc;
1303 ap.a_head.a_ops = ops;
1310 VFS_MPLOCK1(dvp->v_mount);
1311 DO_OPS(ops, error, &ap, vop_ncreate);
1312 VFS_MPUNLOCK(dvp->v_mount);
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.
1321 * The dvp passed in is referenced but unlocked.
1323 * The namecache is automatically adjusted by this function. The ncp
1324 * is left locked on return.
1329 vop_nmkdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1330 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1332 struct vop_nmkdir_args ap;
1336 ap.a_head.a_desc = &vop_nmkdir_desc;
1337 ap.a_head.a_ops = ops;
1344 VFS_MPLOCK1(dvp->v_mount);
1345 DO_OPS(ops, error, &ap, vop_nmkdir);
1346 VFS_MPUNLOCK(dvp->v_mount);
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.
1355 * The dvp passed in is referenced but unlocked.
1357 * The namecache is automatically adjusted by this function. The ncp
1358 * is left locked on return.
1363 vop_nmknod(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1364 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1366 struct vop_nmknod_args ap;
1370 ap.a_head.a_desc = &vop_nmknod_desc;
1371 ap.a_head.a_ops = ops;
1378 VFS_MPLOCK1(dvp->v_mount);
1379 DO_OPS(ops, error, &ap, vop_nmknod);
1380 VFS_MPUNLOCK(dvp->v_mount);
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.
1390 * The dvp passed in is referenced but unlocked.
1392 * The namecache is automatically adjusted by this function. The ncp
1393 * is left locked on return.
1398 vop_nlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1399 struct vnode *vp, struct ucred *cred)
1401 struct vop_nlink_args ap;
1405 ap.a_head.a_desc = &vop_nlink_desc;
1406 ap.a_head.a_ops = ops;
1412 VFS_MPLOCK1(dvp->v_mount);
1413 DO_OPS(ops, error, &ap, vop_nlink);
1414 VFS_MPUNLOCK(dvp->v_mount);
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
1424 * The dvp passed in is referenced but unlocked.
1426 * The namecache is automatically adjusted by this function. The ncp
1427 * is left locked on return.
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)
1436 struct vop_nsymlink_args ap;
1440 ap.a_head.a_desc = &vop_nsymlink_desc;
1441 ap.a_head.a_ops = ops;
1447 ap.a_target = target;
1449 VFS_MPLOCK1(dvp->v_mount);
1450 DO_OPS(ops, error, &ap, vop_nsymlink);
1451 VFS_MPUNLOCK(dvp->v_mount);
1456 * nwhiteout takes a locked, resolved ncp that can represent a positive or
1457 * negative hit and executes the whiteout function specified in flags.
1459 * The dvp passed in is referenced but unlocked.
1461 * The namecache is automatically adjusted by this function. The ncp
1462 * is left locked on return.
1467 vop_nwhiteout(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1468 struct ucred *cred, int flags)
1470 struct vop_nwhiteout_args ap;
1474 ap.a_head.a_desc = &vop_nwhiteout_desc;
1475 ap.a_head.a_ops = ops;
1481 VFS_MPLOCK1(dvp->v_mount);
1482 DO_OPS(ops, error, &ap, vop_nwhiteout);
1483 VFS_MPUNLOCK(dvp->v_mount);
1488 * nremove takes a locked, resolved ncp that generally represents a
1489 * positive hit and removes the file.
1491 * The dvp passed in is referenced but unlocked.
1493 * The namecache is automatically adjusted by this function. The ncp
1494 * is left locked on return.
1499 vop_nremove(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1502 struct vop_nremove_args ap;
1507 ap.a_head.a_desc = &vop_nremove_desc;
1508 ap.a_head.a_ops = ops;
1513 if ((error = VOP_GETATTR(nch->ncp->nc_vp, &va)) != 0)
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);
1522 VFS_MPUNLOCK(dvp->v_mount);
1527 * nrmdir takes a locked, resolved ncp that generally represents a
1528 * directory and removes the directory.
1530 * The dvp passed in is referenced but unlocked.
1532 * The namecache is automatically adjusted by this function. The ncp
1533 * is left locked on return.
1538 vop_nrmdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1541 struct vop_nrmdir_args ap;
1545 ap.a_head.a_desc = &vop_nrmdir_desc;
1546 ap.a_head.a_ops = ops;
1551 VFS_MPLOCK1(dvp->v_mount);
1552 DO_OPS(ops, error, &ap, vop_nrmdir);
1553 VFS_MPUNLOCK(dvp->v_mount);
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.
1562 * The fdvp and tdvp passed in are referenced but unlocked.
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.
1572 vop_nrename(struct vop_ops *ops,
1573 struct nchandle *fnch, struct nchandle *tnch,
1574 struct vnode *fdvp, struct vnode *tdvp,
1577 struct vop_nrename_args ap;
1581 ap.a_head.a_desc = &vop_nrename_desc;
1582 ap.a_head.a_ops = ops;
1589 VFS_MPLOCK1(fdvp->v_mount);
1590 DO_OPS(ops, error, &ap, vop_nrename);
1591 VFS_MPUNLOCK(fdvp->v_mount);
1595 /************************************************************************
1596 * PRIMARY VNODE OPERATIONS FORWARDING CALLS *
1597 ************************************************************************
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.
1605 * MPSAFE - Caller expected to already hold the appropriate vfs lock.
1608 vop_vnoperate_ap(struct vop_generic_args *ap)
1610 struct vop_ops *ops;
1614 error = VOCALL(ops, ap);
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.
1625 vop_cache_operate_ap(struct vop_generic_args *ap)
1627 struct vop_ops *ops;
1631 if (ops->head.vv_mount->mnt_vn_journal_ops)
1632 error = VOCALL(ops->head.vv_mount->mnt_vn_journal_ops, ap);
1634 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1640 * This routine is called by the journaling layer to execute the actual
1644 vop_journal_operate_ap(struct vop_generic_args *ap)
1646 struct vop_ops *ops;
1650 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1656 vop_open_ap(struct vop_open_args *ap)
1660 DO_OPS(ap->a_head.a_ops, error, ap, vop_open);
1665 vop_close_ap(struct vop_close_args *ap)
1669 DO_OPS(ap->a_head.a_ops, error, ap, vop_close);
1674 vop_access_ap(struct vop_access_args *ap)
1678 DO_OPS(ap->a_head.a_ops, error, ap, vop_access);
1683 vop_getattr_ap(struct vop_getattr_args *ap)
1687 DO_OPS(ap->a_head.a_ops, error, ap, vop_getattr);
1692 vop_setattr_ap(struct vop_setattr_args *ap)
1696 DO_OPS(ap->a_head.a_ops, error, ap, vop_setattr);
1701 vop_read_ap(struct vop_read_args *ap)
1705 DO_OPS(ap->a_head.a_ops, error, ap, vop_read);
1710 vop_write_ap(struct vop_write_args *ap)
1714 DO_OPS(ap->a_head.a_ops, error, ap, vop_write);
1719 vop_ioctl_ap(struct vop_ioctl_args *ap)
1723 DO_OPS(ap->a_head.a_ops, error, ap, vop_ioctl);
1728 vop_poll_ap(struct vop_poll_args *ap)
1732 DO_OPS(ap->a_head.a_ops, error, ap, vop_poll);
1737 vop_kqfilter_ap(struct vop_kqfilter_args *ap)
1741 DO_OPS(ap->a_head.a_ops, error, ap, vop_kqfilter);
1746 vop_mmap_ap(struct vop_mmap_args *ap)
1750 DO_OPS(ap->a_head.a_ops, error, ap, vop_mmap);
1755 vop_fsync_ap(struct vop_fsync_args *ap)
1759 DO_OPS(ap->a_head.a_ops, error, ap, vop_fsync);
1764 vop_readdir_ap(struct vop_readdir_args *ap)
1768 DO_OPS(ap->a_head.a_ops, error, ap, vop_readdir);
1773 vop_readlink_ap(struct vop_readlink_args *ap)
1777 DO_OPS(ap->a_head.a_ops, error, ap, vop_readlink);
1782 vop_inactive_ap(struct vop_inactive_args *ap)
1786 DO_OPS(ap->a_head.a_ops, error, ap, vop_inactive);
1791 vop_reclaim_ap(struct vop_reclaim_args *ap)
1795 DO_OPS(ap->a_head.a_ops, error, ap, vop_reclaim);
1800 vop_bmap_ap(struct vop_bmap_args *ap)
1804 DO_OPS(ap->a_head.a_ops, error, ap, vop_bmap);
1809 vop_strategy_ap(struct vop_strategy_args *ap)
1813 DO_OPS(ap->a_head.a_ops, error, ap, vop_strategy);
1818 vop_print_ap(struct vop_print_args *ap)
1822 DO_OPS(ap->a_head.a_ops, error, ap, vop_print);
1827 vop_pathconf_ap(struct vop_pathconf_args *ap)
1831 DO_OPS(ap->a_head.a_ops, error, ap, vop_pathconf);
1836 vop_advlock_ap(struct vop_advlock_args *ap)
1840 DO_OPS(ap->a_head.a_ops, error, ap, vop_advlock);
1845 vop_balloc_ap(struct vop_balloc_args *ap)
1849 DO_OPS(ap->a_head.a_ops, error, ap, vop_balloc);
1854 vop_reallocblks_ap(struct vop_reallocblks_args *ap)
1858 DO_OPS(ap->a_head.a_ops, error, ap, vop_reallocblks);
1863 vop_getpages_ap(struct vop_getpages_args *ap)
1867 DO_OPS(ap->a_head.a_ops, error, ap, vop_getpages);
1872 vop_putpages_ap(struct vop_putpages_args *ap)
1876 DO_OPS(ap->a_head.a_ops, error, ap, vop_putpages);
1881 vop_freeblks_ap(struct vop_freeblks_args *ap)
1885 DO_OPS(ap->a_head.a_ops, error, ap, vop_freeblks);
1890 vop_getacl_ap(struct vop_getacl_args *ap)
1894 DO_OPS(ap->a_head.a_ops, error, ap, vop_getacl);
1899 vop_setacl_ap(struct vop_setacl_args *ap)
1903 DO_OPS(ap->a_head.a_ops, error, ap, vop_setacl);
1908 vop_aclcheck_ap(struct vop_aclcheck_args *ap)
1912 DO_OPS(ap->a_head.a_ops, error, ap, vop_aclcheck);
1917 vop_getextattr_ap(struct vop_getextattr_args *ap)
1921 DO_OPS(ap->a_head.a_ops, error, ap, vop_getextattr);
1926 vop_setextattr_ap(struct vop_setextattr_args *ap)
1930 DO_OPS(ap->a_head.a_ops, error, ap, vop_setextattr);
1935 vop_mountctl_ap(struct vop_mountctl_args *ap)
1939 DO_OPS(ap->a_head.a_ops, error, ap, vop_mountctl);
1944 vop_markatime_ap(struct vop_markatime_args *ap)
1948 DO_OPS(ap->a_head.a_ops, error, ap, vop_markatime);
1953 vop_nresolve_ap(struct vop_nresolve_args *ap)
1957 DO_OPS(ap->a_head.a_ops, error, ap, vop_nresolve);
1962 vop_nlookupdotdot_ap(struct vop_nlookupdotdot_args *ap)
1966 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlookupdotdot);
1971 vop_ncreate_ap(struct vop_ncreate_args *ap)
1975 DO_OPS(ap->a_head.a_ops, error, ap, vop_ncreate);
1980 vop_nmkdir_ap(struct vop_nmkdir_args *ap)
1984 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmkdir);
1989 vop_nmknod_ap(struct vop_nmknod_args *ap)
1993 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmknod);
1998 vop_nlink_ap(struct vop_nlink_args *ap)
2002 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlink);
2007 vop_nsymlink_ap(struct vop_nsymlink_args *ap)
2011 DO_OPS(ap->a_head.a_ops, error, ap, vop_nsymlink);
2016 vop_nwhiteout_ap(struct vop_nwhiteout_args *ap)
2020 DO_OPS(ap->a_head.a_ops, error, ap, vop_nwhiteout);
2025 vop_nremove_ap(struct vop_nremove_args *ap)
2029 DO_OPS(ap->a_head.a_ops, error, ap, vop_nremove);
2034 vop_nrmdir_ap(struct vop_nrmdir_args *ap)
2038 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrmdir);
2043 vop_nrename_ap(struct vop_nrename_args *ap)
2047 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrename);