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;
442 /* does this vnode belong to a pfs/nullfs mount ? */
443 /* XXX: vp->v_pfsmp may point to a freed structure
444 * we use mountlist_exists() to check if it is valid
446 if ((vp->v_pfsmp != NULL) && (mountlist_exists(vp->v_pfsmp))) {
447 /* yes, use a copy of the real mp */
450 /* no, we can use vp->v_mount directly */
453 VFS_ACCOUNT(mp, va.va_uid, va.va_gid, size_after - size_before);
455 VFS_MPUNLOCK(vp->v_mount);
463 vop_ioctl(struct vop_ops *ops, struct vnode *vp, u_long command, caddr_t data,
464 int fflag, struct ucred *cred, struct sysmsg *msg)
466 struct vop_ioctl_args ap;
470 ap.a_head.a_desc = &vop_ioctl_desc;
471 ap.a_head.a_ops = ops;
473 ap.a_command = command;
479 VFS_MPLOCK1(vp->v_mount);
480 DO_OPS(ops, error, &ap, vop_ioctl);
481 VFS_MPUNLOCK(vp->v_mount);
489 vop_poll(struct vop_ops *ops, struct vnode *vp, int events, struct ucred *cred)
491 struct vop_poll_args ap;
495 ap.a_head.a_desc = &vop_poll_desc;
496 ap.a_head.a_ops = ops;
498 ap.a_events = events;
501 VFS_MPLOCK1(vp->v_mount);
502 DO_OPS(ops, error, &ap, vop_poll);
503 VFS_MPUNLOCK(vp->v_mount);
511 vop_kqfilter(struct vop_ops *ops, struct vnode *vp, struct knote *kn)
513 struct vop_kqfilter_args ap;
517 ap.a_head.a_desc = &vop_kqfilter_desc;
518 ap.a_head.a_ops = ops;
522 VFS_MPLOCK1(vp->v_mount);
523 DO_OPS(ops, error, &ap, vop_kqfilter);
524 VFS_MPUNLOCK(vp->v_mount);
532 vop_mmap(struct vop_ops *ops, struct vnode *vp, int fflags, struct ucred *cred)
534 struct vop_mmap_args ap;
538 ap.a_head.a_desc = &vop_mmap_desc;
539 ap.a_head.a_ops = ops;
541 ap.a_fflags = fflags;
544 VFS_MPLOCK1(vp->v_mount);
545 DO_OPS(ops, error, &ap, vop_mmap);
546 VFS_MPUNLOCK(vp->v_mount);
554 vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor, int flags)
556 struct vop_fsync_args ap;
560 ap.a_head.a_desc = &vop_fsync_desc;
561 ap.a_head.a_ops = ops;
563 ap.a_waitfor = waitfor;
566 VFS_MPLOCK1(vp->v_mount);
567 DO_OPS(ops, error, &ap, vop_fsync);
568 VFS_MPUNLOCK(vp->v_mount);
576 vop_old_remove(struct vop_ops *ops, struct vnode *dvp,
577 struct vnode *vp, struct componentname *cnp)
579 struct vop_old_remove_args ap;
583 ap.a_head.a_desc = &vop_old_remove_desc;
584 ap.a_head.a_ops = ops;
589 VFS_MPLOCK1(dvp->v_mount);
590 DO_OPS(ops, error, &ap, vop_old_remove);
591 VFS_MPUNLOCK(dvp->v_mount);
599 vop_old_link(struct vop_ops *ops, struct vnode *tdvp,
600 struct vnode *vp, struct componentname *cnp)
602 struct vop_old_link_args ap;
606 ap.a_head.a_desc = &vop_old_link_desc;
607 ap.a_head.a_ops = ops;
612 VFS_MPLOCK1(tdvp->v_mount);
613 DO_OPS(ops, error, &ap, vop_old_link);
614 VFS_MPUNLOCK(tdvp->v_mount);
622 vop_old_rename(struct vop_ops *ops,
623 struct vnode *fdvp, struct vnode *fvp, struct componentname *fcnp,
624 struct vnode *tdvp, struct vnode *tvp, struct componentname *tcnp)
626 struct vop_old_rename_args ap;
630 ap.a_head.a_desc = &vop_old_rename_desc;
631 ap.a_head.a_ops = ops;
639 VFS_MPLOCK1(tdvp->v_mount);
640 DO_OPS(ops, error, &ap, vop_old_rename);
641 VFS_MPUNLOCK(tdvp->v_mount);
649 vop_old_mkdir(struct vop_ops *ops, struct vnode *dvp,
650 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
652 struct vop_old_mkdir_args ap;
656 ap.a_head.a_desc = &vop_old_mkdir_desc;
657 ap.a_head.a_ops = ops;
663 VFS_MPLOCK1(dvp->v_mount);
664 DO_OPS(ops, error, &ap, vop_old_mkdir);
665 VFS_MPUNLOCK(dvp->v_mount);
673 vop_old_rmdir(struct vop_ops *ops, struct vnode *dvp,
674 struct vnode *vp, struct componentname *cnp)
676 struct vop_old_rmdir_args ap;
680 ap.a_head.a_desc = &vop_old_rmdir_desc;
681 ap.a_head.a_ops = ops;
686 VFS_MPLOCK1(dvp->v_mount);
687 DO_OPS(ops, error, &ap, vop_old_rmdir);
688 VFS_MPUNLOCK(dvp->v_mount);
696 vop_old_symlink(struct vop_ops *ops, struct vnode *dvp,
697 struct vnode **vpp, struct componentname *cnp,
698 struct vattr *vap, char *target)
700 struct vop_old_symlink_args ap;
704 ap.a_head.a_desc = &vop_old_symlink_desc;
705 ap.a_head.a_ops = ops;
710 ap.a_target = target;
712 VFS_MPLOCK1(dvp->v_mount);
713 DO_OPS(ops, error, &ap, vop_old_symlink);
714 VFS_MPUNLOCK(dvp->v_mount);
722 vop_readdir(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
723 struct ucred *cred, int *eofflag, int *ncookies, off_t **cookies)
725 struct vop_readdir_args ap;
729 ap.a_head.a_desc = &vop_readdir_desc;
730 ap.a_head.a_ops = ops;
734 ap.a_eofflag = eofflag;
735 ap.a_ncookies = ncookies;
736 ap.a_cookies = cookies;
738 VFS_MPLOCK1(vp->v_mount);
739 DO_OPS(ops, error, &ap, vop_readdir);
740 VFS_MPUNLOCK(vp->v_mount);
748 vop_readlink(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
751 struct vop_readlink_args ap;
755 ap.a_head.a_desc = &vop_readlink_desc;
756 ap.a_head.a_ops = ops;
761 VFS_MPLOCK1(vp->v_mount);
762 DO_OPS(ops, error, &ap, vop_readlink);
763 VFS_MPUNLOCK(vp->v_mount);
771 vop_inactive(struct vop_ops *ops, struct vnode *vp)
773 struct vop_inactive_args ap;
778 ap.a_head.a_desc = &vop_inactive_desc;
779 ap.a_head.a_ops = ops;
783 * WARNING! Deactivation of the vnode can cause it to be recycled,
784 * clearing vp->v_mount.
787 VFS_MPLOCK_FLAG(mp, MNTK_IN_MPSAFE);
788 DO_OPS(ops, error, &ap, vop_inactive);
797 vop_reclaim(struct vop_ops *ops, struct vnode *vp)
799 struct vop_reclaim_args ap;
804 ap.a_head.a_desc = &vop_reclaim_desc;
805 ap.a_head.a_ops = ops;
809 * WARNING! Reclamation of the vnode will clear vp->v_mount.
813 DO_OPS(ops, error, &ap, vop_reclaim);
822 vop_bmap(struct vop_ops *ops, struct vnode *vp, off_t loffset,
823 off_t *doffsetp, int *runp, int *runb, buf_cmd_t cmd)
825 struct vop_bmap_args ap;
829 ap.a_head.a_desc = &vop_bmap_desc;
830 ap.a_head.a_ops = ops;
832 ap.a_loffset = loffset;
833 ap.a_doffsetp = doffsetp;
838 VFS_MPLOCK1(vp->v_mount);
839 DO_OPS(ops, error, &ap, vop_bmap);
840 VFS_MPUNLOCK(vp->v_mount);
848 vop_strategy(struct vop_ops *ops, struct vnode *vp, struct bio *bio)
850 struct vop_strategy_args ap;
854 ap.a_head.a_desc = &vop_strategy_desc;
855 ap.a_head.a_ops = ops;
860 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_SG_MPSAFE);
861 DO_OPS(ops, error, &ap, vop_strategy);
862 VFS_MPUNLOCK(vp->v_mount);
864 /* ugly hack for swap */
866 DO_OPS(ops, error, &ap, vop_strategy);
876 vop_print(struct vop_ops *ops, struct vnode *vp)
878 struct vop_print_args ap;
882 ap.a_head.a_desc = &vop_print_desc;
883 ap.a_head.a_ops = ops;
886 VFS_MPLOCK1(vp->v_mount);
887 DO_OPS(ops, error, &ap, vop_print);
888 VFS_MPUNLOCK(vp->v_mount);
896 vop_pathconf(struct vop_ops *ops, struct vnode *vp, int name,
899 struct vop_pathconf_args ap;
903 ap.a_head.a_desc = &vop_pathconf_desc;
904 ap.a_head.a_ops = ops;
907 ap.a_retval = retval;
909 VFS_MPLOCK1(vp->v_mount);
910 DO_OPS(ops, error, &ap, vop_pathconf);
911 VFS_MPUNLOCK(vp->v_mount);
919 vop_advlock(struct vop_ops *ops, struct vnode *vp, caddr_t id, int op,
920 struct flock *fl, int flags)
922 struct vop_advlock_args ap;
926 ap.a_head.a_desc = &vop_advlock_desc;
927 ap.a_head.a_ops = ops;
934 VFS_MPLOCK1(vp->v_mount);
935 DO_OPS(ops, error, &ap, vop_advlock);
936 VFS_MPUNLOCK(vp->v_mount);
944 vop_balloc(struct vop_ops *ops, struct vnode *vp, off_t startoffset,
945 int size, struct ucred *cred, int flags,
948 struct vop_balloc_args ap;
952 ap.a_head.a_desc = &vop_balloc_desc;
953 ap.a_head.a_ops = ops;
955 ap.a_startoffset = startoffset;
961 VFS_MPLOCK1(vp->v_mount);
962 DO_OPS(ops, error, &ap, vop_balloc);
963 VFS_MPUNLOCK(vp->v_mount);
971 vop_reallocblks(struct vop_ops *ops, struct vnode *vp,
972 struct cluster_save *buflist)
974 struct vop_reallocblks_args ap;
978 ap.a_head.a_desc = &vop_reallocblks_desc;
979 ap.a_head.a_ops = ops;
981 ap.a_buflist = buflist;
983 VFS_MPLOCK1(vp->v_mount);
984 DO_OPS(ops, error, &ap, vop_reallocblks);
985 VFS_MPUNLOCK(vp->v_mount);
993 vop_getpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
994 int reqpage, vm_ooffset_t offset, int seqaccess)
996 struct vop_getpages_args ap;
1000 ap.a_head.a_desc = &vop_getpages_desc;
1001 ap.a_head.a_ops = ops;
1005 ap.a_reqpage = reqpage;
1006 ap.a_offset = offset;
1007 ap.a_seqaccess = seqaccess;
1009 VFS_MPLOCK1(vp->v_mount);
1010 DO_OPS(ops, error, &ap, vop_getpages);
1011 VFS_MPUNLOCK(vp->v_mount);
1019 vop_putpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
1020 int sync, int *rtvals, vm_ooffset_t offset)
1022 struct vop_putpages_args ap;
1026 ap.a_head.a_desc = &vop_putpages_desc;
1027 ap.a_head.a_ops = ops;
1032 ap.a_rtvals = rtvals;
1033 ap.a_offset = offset;
1035 VFS_MPLOCK1(vp->v_mount);
1036 DO_OPS(ops, error, &ap, vop_putpages);
1037 VFS_MPUNLOCK(vp->v_mount);
1045 vop_freeblks(struct vop_ops *ops, struct vnode *vp, off_t offset, int length)
1047 struct vop_freeblks_args ap;
1051 ap.a_head.a_desc = &vop_freeblks_desc;
1052 ap.a_head.a_ops = ops;
1054 ap.a_offset = offset;
1055 ap.a_length = length;
1057 VFS_MPLOCK1(vp->v_mount);
1058 DO_OPS(ops, error, &ap, vop_freeblks);
1059 VFS_MPUNLOCK(vp->v_mount);
1067 vop_getacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1068 struct acl *aclp, struct ucred *cred)
1070 struct vop_getacl_args ap;
1074 ap.a_head.a_desc = &vop_getacl_desc;
1075 ap.a_head.a_ops = ops;
1081 VFS_MPLOCK1(vp->v_mount);
1082 DO_OPS(ops, error, &ap, vop_getacl);
1083 VFS_MPUNLOCK(vp->v_mount);
1091 vop_setacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1092 struct acl *aclp, struct ucred *cred)
1094 struct vop_setacl_args ap;
1098 ap.a_head.a_desc = &vop_setacl_desc;
1099 ap.a_head.a_ops = ops;
1105 VFS_MPLOCK1(vp->v_mount);
1106 DO_OPS(ops, error, &ap, vop_setacl);
1107 VFS_MPUNLOCK(vp->v_mount);
1115 vop_aclcheck(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1116 struct acl *aclp, struct ucred *cred)
1118 struct vop_aclcheck_args ap;
1122 ap.a_head.a_desc = &vop_aclcheck_desc;
1123 ap.a_head.a_ops = ops;
1129 VFS_MPLOCK1(vp->v_mount);
1130 DO_OPS(ops, error, &ap, vop_aclcheck);
1131 VFS_MPUNLOCK(vp->v_mount);
1139 vop_getextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1140 char *attrname, struct uio *uio, struct ucred *cred)
1142 struct vop_getextattr_args ap;
1146 ap.a_head.a_desc = &vop_getextattr_desc;
1147 ap.a_head.a_ops = ops;
1149 ap.a_attrnamespace = attrnamespace;
1150 ap.a_attrname = attrname;
1154 VFS_MPLOCK1(vp->v_mount);
1155 DO_OPS(ops, error, &ap, vop_getextattr);
1156 VFS_MPUNLOCK(vp->v_mount);
1164 vop_setextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1165 char *attrname, struct uio *uio, struct ucred *cred)
1167 struct vop_setextattr_args ap;
1171 ap.a_head.a_desc = &vop_setextattr_desc;
1172 ap.a_head.a_ops = ops;
1174 ap.a_attrnamespace = attrnamespace;
1175 ap.a_attrname = attrname;
1179 VFS_MPLOCK1(vp->v_mount);
1180 DO_OPS(ops, error, &ap, vop_setextattr);
1181 VFS_MPUNLOCK(vp->v_mount);
1189 vop_mountctl(struct vop_ops *ops, struct vnode *vp, int op, struct file *fp,
1190 const void *ctl, int ctllen, void *buf, int buflen, int *res)
1192 struct vop_mountctl_args ap;
1196 ap.a_head.a_desc = &vop_mountctl_desc;
1197 ap.a_head.a_ops = ops;
1201 ap.a_ctllen = ctllen;
1203 ap.a_buflen = buflen;
1206 VFS_MPLOCK1(vp->v_mount);
1207 DO_OPS(ops, error, &ap, vop_mountctl);
1208 VFS_MPUNLOCK(vp->v_mount);
1216 vop_markatime(struct vop_ops *ops, struct vnode *vp, struct ucred *cred)
1218 struct vop_markatime_args ap;
1222 ap.a_head.a_desc = &vop_markatime_desc;
1223 ap.a_head.a_ops = ops;
1227 VFS_MPLOCK1(vp->v_mount);
1228 DO_OPS(ops, error, &ap, vop_markatime);
1229 VFS_MPUNLOCK(vp->v_mount);
1236 * nresolve takes a locked ncp, a referenced but unlocked dvp, and a cred,
1237 * and resolves the ncp into a positive or negative hit.
1239 * The namecache is automatically adjusted by this function. The ncp
1240 * is left locked on return.
1245 vop_nresolve(struct vop_ops *ops, struct nchandle *nch,
1246 struct vnode *dvp, struct ucred *cred)
1248 struct vop_nresolve_args ap;
1252 ap.a_head.a_desc = &vop_nresolve_desc;
1253 ap.a_head.a_ops = ops;
1258 VFS_MPLOCK1(dvp->v_mount);
1259 DO_OPS(ops, error, &ap, vop_nresolve);
1260 VFS_MPUNLOCK(dvp->v_mount);
1265 * nlookupdotdot takes an unlocked directory, referenced dvp, and looks
1266 * up "..", returning a locked parent directory in *vpp. If an error
1267 * occurs *vpp will be NULL.
1272 vop_nlookupdotdot(struct vop_ops *ops, struct vnode *dvp,
1273 struct vnode **vpp, struct ucred *cred, char **fakename)
1275 struct vop_nlookupdotdot_args ap;
1279 ap.a_head.a_desc = &vop_nlookupdotdot_desc;
1280 ap.a_head.a_ops = ops;
1284 ap.a_fakename = fakename;
1286 VFS_MPLOCK1(dvp->v_mount);
1287 DO_OPS(ops, error, &ap, vop_nlookupdotdot);
1288 VFS_MPUNLOCK(dvp->v_mount);
1293 * ncreate takes a locked, resolved ncp that typically represents a negative
1294 * cache hit and creates the file or node specified by the ncp, cred, and
1295 * vattr. If no error occurs a locked vnode is returned in *vpp.
1297 * The dvp passed in is referenced but unlocked.
1299 * The namecache is automatically adjusted by this function. The ncp
1300 * is left locked on return.
1305 vop_ncreate(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1306 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1308 struct vop_ncreate_args ap;
1312 ap.a_head.a_desc = &vop_ncreate_desc;
1313 ap.a_head.a_ops = ops;
1320 VFS_MPLOCK1(dvp->v_mount);
1321 DO_OPS(ops, error, &ap, vop_ncreate);
1322 VFS_MPUNLOCK(dvp->v_mount);
1327 * nmkdir takes a locked, resolved ncp that typically represents a negative
1328 * cache hit and creates the directory specified by the ncp, cred, and
1329 * vattr. If no error occurs a locked vnode is returned in *vpp.
1331 * The dvp passed in is referenced but unlocked.
1333 * The namecache is automatically adjusted by this function. The ncp
1334 * is left locked on return.
1339 vop_nmkdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1340 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1342 struct vop_nmkdir_args ap;
1346 ap.a_head.a_desc = &vop_nmkdir_desc;
1347 ap.a_head.a_ops = ops;
1354 VFS_MPLOCK1(dvp->v_mount);
1355 DO_OPS(ops, error, &ap, vop_nmkdir);
1356 VFS_MPUNLOCK(dvp->v_mount);
1361 * nmknod takes a locked, resolved ncp that typically represents a negative
1362 * cache hit and creates the node specified by the ncp, cred, and
1363 * vattr. If no error occurs a locked vnode is returned in *vpp.
1365 * The dvp passed in is referenced but unlocked.
1367 * The namecache is automatically adjusted by this function. The ncp
1368 * is left locked on return.
1373 vop_nmknod(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1374 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1376 struct vop_nmknod_args ap;
1380 ap.a_head.a_desc = &vop_nmknod_desc;
1381 ap.a_head.a_ops = ops;
1388 VFS_MPLOCK1(dvp->v_mount);
1389 DO_OPS(ops, error, &ap, vop_nmknod);
1390 VFS_MPUNLOCK(dvp->v_mount);
1395 * nlink takes a locked, resolved ncp that typically represents a negative
1396 * cache hit and creates the node specified by the ncp, cred, and
1397 * existing vnode. The passed vp must be locked and will remain locked
1398 * on return, as does the ncp, whether an error occurs or not.
1400 * The dvp passed in is referenced but unlocked.
1402 * The namecache is automatically adjusted by this function. The ncp
1403 * is left locked on return.
1408 vop_nlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1409 struct vnode *vp, struct ucred *cred)
1411 struct vop_nlink_args ap;
1415 ap.a_head.a_desc = &vop_nlink_desc;
1416 ap.a_head.a_ops = ops;
1422 VFS_MPLOCK1(dvp->v_mount);
1423 DO_OPS(ops, error, &ap, vop_nlink);
1424 VFS_MPUNLOCK(dvp->v_mount);
1429 * nsymlink takes a locked, resolved ncp that typically represents a negative
1430 * cache hit and creates a symbolic link based on cred, vap, and target (the
1431 * contents of the link). If no error occurs a locked vnode is returned in
1434 * The dvp passed in is referenced but unlocked.
1436 * The namecache is automatically adjusted by this function. The ncp
1437 * is left locked on return.
1442 vop_nsymlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1443 struct vnode **vpp, struct ucred *cred,
1444 struct vattr *vap, char *target)
1446 struct vop_nsymlink_args ap;
1450 ap.a_head.a_desc = &vop_nsymlink_desc;
1451 ap.a_head.a_ops = ops;
1457 ap.a_target = target;
1459 VFS_MPLOCK1(dvp->v_mount);
1460 DO_OPS(ops, error, &ap, vop_nsymlink);
1461 VFS_MPUNLOCK(dvp->v_mount);
1466 * nwhiteout takes a locked, resolved ncp that can represent a positive or
1467 * negative hit and executes the whiteout function specified in flags.
1469 * The dvp passed in is referenced but unlocked.
1471 * The namecache is automatically adjusted by this function. The ncp
1472 * is left locked on return.
1477 vop_nwhiteout(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1478 struct ucred *cred, int flags)
1480 struct vop_nwhiteout_args ap;
1484 ap.a_head.a_desc = &vop_nwhiteout_desc;
1485 ap.a_head.a_ops = ops;
1491 VFS_MPLOCK1(dvp->v_mount);
1492 DO_OPS(ops, error, &ap, vop_nwhiteout);
1493 VFS_MPUNLOCK(dvp->v_mount);
1498 * nremove takes a locked, resolved ncp that generally represents a
1499 * positive hit and removes the file.
1501 * The dvp passed in is referenced but unlocked.
1503 * The namecache is automatically adjusted by this function. The ncp
1504 * is left locked on return.
1508 /* FIXME: only substract the file size for its last link */
1510 vop_nremove(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1513 struct vop_nremove_args ap;
1518 ap.a_head.a_desc = &vop_nremove_desc;
1519 ap.a_head.a_ops = ops;
1524 if ((error = VOP_GETATTR(nch->ncp->nc_vp, &va)) != 0)
1527 VFS_MPLOCK1(dvp->v_mount);
1528 DO_OPS(ops, error, &ap, vop_nremove);
1529 VFS_ACCOUNT(nch->mount, va.va_uid, va.va_gid, -va.va_size);
1530 VFS_MPUNLOCK(dvp->v_mount);
1535 * nrmdir takes a locked, resolved ncp that generally represents a
1536 * directory and removes the directory.
1538 * The dvp passed in is referenced but unlocked.
1540 * The namecache is automatically adjusted by this function. The ncp
1541 * is left locked on return.
1546 vop_nrmdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1549 struct vop_nrmdir_args ap;
1553 ap.a_head.a_desc = &vop_nrmdir_desc;
1554 ap.a_head.a_ops = ops;
1559 VFS_MPLOCK1(dvp->v_mount);
1560 DO_OPS(ops, error, &ap, vop_nrmdir);
1561 VFS_MPUNLOCK(dvp->v_mount);
1566 * nrename takes TWO locked, resolved ncp's and the cred of the caller
1567 * and renames the source ncp to the target ncp. The target ncp may
1568 * represent a positive or negative hit.
1570 * The fdvp and tdvp passed in are referenced but unlocked.
1572 * The namecache is automatically adjusted by this function. The ncp
1573 * is left locked on return. The source ncp is typically changed to
1574 * a negative cache hit and the target ncp typically takes on the
1575 * source ncp's underlying file.
1580 vop_nrename(struct vop_ops *ops,
1581 struct nchandle *fnch, struct nchandle *tnch,
1582 struct vnode *fdvp, struct vnode *tdvp,
1585 struct vop_nrename_args ap;
1589 ap.a_head.a_desc = &vop_nrename_desc;
1590 ap.a_head.a_ops = ops;
1597 VFS_MPLOCK1(fdvp->v_mount);
1598 DO_OPS(ops, error, &ap, vop_nrename);
1599 VFS_MPUNLOCK(fdvp->v_mount);
1603 /************************************************************************
1604 * PRIMARY VNODE OPERATIONS FORWARDING CALLS *
1605 ************************************************************************
1607 * These procedures are called from VFSs such as unionfs and nullfs
1608 * when they wish to forward an operation on one VFS to another. The
1609 * argument structure/message is modified and then directly passed to the
1610 * appropriate routine. This routines may also be called by initiators
1611 * who have an argument structure in hand rather then discreet arguments.
1613 * MPSAFE - Caller expected to already hold the appropriate vfs lock.
1616 vop_vnoperate_ap(struct vop_generic_args *ap)
1618 struct vop_ops *ops;
1622 error = VOCALL(ops, ap);
1628 * This routine is called by the cache coherency layer to execute the actual
1629 * VFS operation. If a journaling layer is present we call though it, else
1630 * we call the native VOP functions.
1633 vop_cache_operate_ap(struct vop_generic_args *ap)
1635 struct vop_ops *ops;
1639 if (ops->head.vv_mount->mnt_vn_journal_ops)
1640 error = VOCALL(ops->head.vv_mount->mnt_vn_journal_ops, ap);
1642 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1648 * This routine is called by the journaling layer to execute the actual
1652 vop_journal_operate_ap(struct vop_generic_args *ap)
1654 struct vop_ops *ops;
1658 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1664 vop_open_ap(struct vop_open_args *ap)
1668 DO_OPS(ap->a_head.a_ops, error, ap, vop_open);
1673 vop_close_ap(struct vop_close_args *ap)
1677 DO_OPS(ap->a_head.a_ops, error, ap, vop_close);
1682 vop_access_ap(struct vop_access_args *ap)
1686 DO_OPS(ap->a_head.a_ops, error, ap, vop_access);
1691 vop_getattr_ap(struct vop_getattr_args *ap)
1695 DO_OPS(ap->a_head.a_ops, error, ap, vop_getattr);
1700 vop_setattr_ap(struct vop_setattr_args *ap)
1704 DO_OPS(ap->a_head.a_ops, error, ap, vop_setattr);
1709 vop_read_ap(struct vop_read_args *ap)
1713 DO_OPS(ap->a_head.a_ops, error, ap, vop_read);
1718 vop_write_ap(struct vop_write_args *ap)
1722 DO_OPS(ap->a_head.a_ops, error, ap, vop_write);
1727 vop_ioctl_ap(struct vop_ioctl_args *ap)
1731 DO_OPS(ap->a_head.a_ops, error, ap, vop_ioctl);
1736 vop_poll_ap(struct vop_poll_args *ap)
1740 DO_OPS(ap->a_head.a_ops, error, ap, vop_poll);
1745 vop_kqfilter_ap(struct vop_kqfilter_args *ap)
1749 DO_OPS(ap->a_head.a_ops, error, ap, vop_kqfilter);
1754 vop_mmap_ap(struct vop_mmap_args *ap)
1758 DO_OPS(ap->a_head.a_ops, error, ap, vop_mmap);
1763 vop_fsync_ap(struct vop_fsync_args *ap)
1767 DO_OPS(ap->a_head.a_ops, error, ap, vop_fsync);
1772 vop_readdir_ap(struct vop_readdir_args *ap)
1776 DO_OPS(ap->a_head.a_ops, error, ap, vop_readdir);
1781 vop_readlink_ap(struct vop_readlink_args *ap)
1785 DO_OPS(ap->a_head.a_ops, error, ap, vop_readlink);
1790 vop_inactive_ap(struct vop_inactive_args *ap)
1794 DO_OPS(ap->a_head.a_ops, error, ap, vop_inactive);
1799 vop_reclaim_ap(struct vop_reclaim_args *ap)
1803 DO_OPS(ap->a_head.a_ops, error, ap, vop_reclaim);
1808 vop_bmap_ap(struct vop_bmap_args *ap)
1812 DO_OPS(ap->a_head.a_ops, error, ap, vop_bmap);
1817 vop_strategy_ap(struct vop_strategy_args *ap)
1821 DO_OPS(ap->a_head.a_ops, error, ap, vop_strategy);
1826 vop_print_ap(struct vop_print_args *ap)
1830 DO_OPS(ap->a_head.a_ops, error, ap, vop_print);
1835 vop_pathconf_ap(struct vop_pathconf_args *ap)
1839 DO_OPS(ap->a_head.a_ops, error, ap, vop_pathconf);
1844 vop_advlock_ap(struct vop_advlock_args *ap)
1848 DO_OPS(ap->a_head.a_ops, error, ap, vop_advlock);
1853 vop_balloc_ap(struct vop_balloc_args *ap)
1857 DO_OPS(ap->a_head.a_ops, error, ap, vop_balloc);
1862 vop_reallocblks_ap(struct vop_reallocblks_args *ap)
1866 DO_OPS(ap->a_head.a_ops, error, ap, vop_reallocblks);
1871 vop_getpages_ap(struct vop_getpages_args *ap)
1875 DO_OPS(ap->a_head.a_ops, error, ap, vop_getpages);
1880 vop_putpages_ap(struct vop_putpages_args *ap)
1884 DO_OPS(ap->a_head.a_ops, error, ap, vop_putpages);
1889 vop_freeblks_ap(struct vop_freeblks_args *ap)
1893 DO_OPS(ap->a_head.a_ops, error, ap, vop_freeblks);
1898 vop_getacl_ap(struct vop_getacl_args *ap)
1902 DO_OPS(ap->a_head.a_ops, error, ap, vop_getacl);
1907 vop_setacl_ap(struct vop_setacl_args *ap)
1911 DO_OPS(ap->a_head.a_ops, error, ap, vop_setacl);
1916 vop_aclcheck_ap(struct vop_aclcheck_args *ap)
1920 DO_OPS(ap->a_head.a_ops, error, ap, vop_aclcheck);
1925 vop_getextattr_ap(struct vop_getextattr_args *ap)
1929 DO_OPS(ap->a_head.a_ops, error, ap, vop_getextattr);
1934 vop_setextattr_ap(struct vop_setextattr_args *ap)
1938 DO_OPS(ap->a_head.a_ops, error, ap, vop_setextattr);
1943 vop_mountctl_ap(struct vop_mountctl_args *ap)
1947 DO_OPS(ap->a_head.a_ops, error, ap, vop_mountctl);
1952 vop_markatime_ap(struct vop_markatime_args *ap)
1956 DO_OPS(ap->a_head.a_ops, error, ap, vop_markatime);
1961 vop_nresolve_ap(struct vop_nresolve_args *ap)
1965 DO_OPS(ap->a_head.a_ops, error, ap, vop_nresolve);
1970 vop_nlookupdotdot_ap(struct vop_nlookupdotdot_args *ap)
1974 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlookupdotdot);
1979 vop_ncreate_ap(struct vop_ncreate_args *ap)
1983 DO_OPS(ap->a_head.a_ops, error, ap, vop_ncreate);
1988 vop_nmkdir_ap(struct vop_nmkdir_args *ap)
1992 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmkdir);
1997 vop_nmknod_ap(struct vop_nmknod_args *ap)
2001 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmknod);
2006 vop_nlink_ap(struct vop_nlink_args *ap)
2010 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlink);
2015 vop_nsymlink_ap(struct vop_nsymlink_args *ap)
2019 DO_OPS(ap->a_head.a_ops, error, ap, vop_nsymlink);
2024 vop_nwhiteout_ap(struct vop_nwhiteout_args *ap)
2028 DO_OPS(ap->a_head.a_ops, error, ap, vop_nwhiteout);
2033 vop_nremove_ap(struct vop_nremove_args *ap)
2037 DO_OPS(ap->a_head.a_ops, error, ap, vop_nremove);
2042 vop_nrmdir_ap(struct vop_nrmdir_args *ap)
2046 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrmdir);
2051 vop_nrename_ap(struct vop_nrename_args *ap)
2055 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrename);