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>
67 #include <machine/limits.h>
70 #include <vm/vm_object.h>
71 #include <vm/vm_extern.h>
72 #include <vm/vm_kern.h>
74 #include <vm/vm_map.h>
75 #include <vm/vm_page.h>
76 #include <vm/vm_pager.h>
77 #include <vm/vnode_pager.h>
78 #include <vm/vm_zone.h>
81 #include <sys/thread2.h>
82 #include <sys/mplock2.h>
84 #define VDESCNAME(name) __CONCAT(__CONCAT(vop_,name),_desc)
86 #define VNODEOP_DESC_INIT(name) \
87 struct syslink_desc VDESCNAME(name) = { \
88 __offsetof(struct vop_ops, __CONCAT(vop_, name)), \
91 VNODEOP_DESC_INIT(default);
92 VNODEOP_DESC_INIT(old_lookup);
93 VNODEOP_DESC_INIT(old_create);
94 VNODEOP_DESC_INIT(old_whiteout);
95 VNODEOP_DESC_INIT(old_mknod);
96 VNODEOP_DESC_INIT(open);
97 VNODEOP_DESC_INIT(close);
98 VNODEOP_DESC_INIT(access);
99 VNODEOP_DESC_INIT(getattr);
100 VNODEOP_DESC_INIT(setattr);
101 VNODEOP_DESC_INIT(read);
102 VNODEOP_DESC_INIT(write);
103 VNODEOP_DESC_INIT(ioctl);
104 VNODEOP_DESC_INIT(poll);
105 VNODEOP_DESC_INIT(kqfilter);
106 VNODEOP_DESC_INIT(mmap);
107 VNODEOP_DESC_INIT(fsync);
108 VNODEOP_DESC_INIT(old_remove);
109 VNODEOP_DESC_INIT(old_link);
110 VNODEOP_DESC_INIT(old_rename);
112 VNODEOP_DESC_INIT(old_mkdir);
113 VNODEOP_DESC_INIT(old_rmdir);
114 VNODEOP_DESC_INIT(old_symlink);
115 VNODEOP_DESC_INIT(readdir);
116 VNODEOP_DESC_INIT(readlink);
117 VNODEOP_DESC_INIT(inactive);
118 VNODEOP_DESC_INIT(reclaim);
119 VNODEOP_DESC_INIT(bmap);
120 VNODEOP_DESC_INIT(strategy);
121 VNODEOP_DESC_INIT(print);
122 VNODEOP_DESC_INIT(pathconf);
123 VNODEOP_DESC_INIT(advlock);
124 VNODEOP_DESC_INIT(balloc);
125 VNODEOP_DESC_INIT(reallocblks);
126 VNODEOP_DESC_INIT(getpages);
127 VNODEOP_DESC_INIT(putpages);
128 VNODEOP_DESC_INIT(freeblks);
129 VNODEOP_DESC_INIT(getacl);
130 VNODEOP_DESC_INIT(setacl);
131 VNODEOP_DESC_INIT(aclcheck);
132 VNODEOP_DESC_INIT(getextattr);
133 VNODEOP_DESC_INIT(setextattr);
134 VNODEOP_DESC_INIT(mountctl);
135 VNODEOP_DESC_INIT(markatime);
137 VNODEOP_DESC_INIT(nresolve);
138 VNODEOP_DESC_INIT(nlookupdotdot);
139 VNODEOP_DESC_INIT(ncreate);
140 VNODEOP_DESC_INIT(nmkdir);
141 VNODEOP_DESC_INIT(nmknod);
142 VNODEOP_DESC_INIT(nlink);
143 VNODEOP_DESC_INIT(nsymlink);
144 VNODEOP_DESC_INIT(nwhiteout);
145 VNODEOP_DESC_INIT(nremove);
146 VNODEOP_DESC_INIT(nrmdir);
147 VNODEOP_DESC_INIT(nrename);
149 #define DO_OPS(ops, error, ap, vop_field) \
150 error = ops->vop_field(ap);
152 #define VFS_MPLOCK_DECLARE struct lwkt_tokref xlock; int xlock_mpsafe
154 #define VFS_MPLOCK(mp) VFS_MPLOCK_FLAG(mp, MNTK_MPSAFE)
156 #define VFS_MPLOCK_FLAG(mp, flag) \
158 if (mp->mnt_kern_flag & flag) { \
161 get_mplock(); /* TEMPORARY */ \
162 lwkt_gettoken(&xlock, &mp->mnt_token); \
167 #define VFS_MPUNLOCK(mp) \
169 if (xlock_mpsafe == 0) { \
170 lwkt_reltoken(&xlock); \
171 rel_mplock(); /* TEMPORARY */ \
175 /************************************************************************
176 * PRIMARY HIGH LEVEL VNODE OPERATIONS CALLS *
177 ************************************************************************
179 * These procedures are called directly from the kernel and/or fileops
180 * code to perform file/device operations on the system.
182 * NOTE: The old namespace api functions such as vop_rename() are no
183 * longer available for general use and have been renamed to
184 * vop_old_*(). Only the code in vfs_default.c is allowed to call
187 * NOTE: The VFS_MPLOCK*() macros handle mounts which do not set
188 * MNTK_MPSAFE or MNTK_xx_MPSAFE.
194 vop_old_lookup(struct vop_ops *ops, struct vnode *dvp,
195 struct vnode **vpp, struct componentname *cnp)
197 struct vop_old_lookup_args ap;
201 ap.a_head.a_desc = &vop_old_lookup_desc;
202 ap.a_head.a_ops = ops;
206 VFS_MPLOCK(dvp->v_mount);
207 DO_OPS(ops, error, &ap, vop_old_lookup);
208 VFS_MPUNLOCK(dvp->v_mount);
216 vop_old_create(struct vop_ops *ops, struct vnode *dvp,
217 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
219 struct vop_old_create_args ap;
223 ap.a_head.a_desc = &vop_old_create_desc;
224 ap.a_head.a_ops = ops;
230 VFS_MPLOCK(dvp->v_mount);
231 DO_OPS(ops, error, &ap, vop_old_create);
232 VFS_MPUNLOCK(dvp->v_mount);
240 vop_old_whiteout(struct vop_ops *ops, struct vnode *dvp,
241 struct componentname *cnp, int flags)
243 struct vop_old_whiteout_args ap;
247 ap.a_head.a_desc = &vop_old_whiteout_desc;
248 ap.a_head.a_ops = ops;
253 VFS_MPLOCK(dvp->v_mount);
254 DO_OPS(ops, error, &ap, vop_old_whiteout);
255 VFS_MPUNLOCK(dvp->v_mount);
263 vop_old_mknod(struct vop_ops *ops, struct vnode *dvp,
264 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
266 struct vop_old_mknod_args ap;
270 ap.a_head.a_desc = &vop_old_mknod_desc;
271 ap.a_head.a_ops = ops;
277 VFS_MPLOCK(dvp->v_mount);
278 DO_OPS(ops, error, &ap, vop_old_mknod);
279 VFS_MPUNLOCK(dvp->v_mount);
284 * NOTE: VAGE is always cleared when calling VOP_OPEN().
287 vop_open(struct vop_ops *ops, struct vnode *vp, int mode, struct ucred *cred,
290 struct vop_open_args ap;
295 * Decrement 3-2-1-0. Does not decrement beyond 0
297 if (vp->v_flag & VAGE0) {
298 vp->v_flag &= ~VAGE0;
299 } else if (vp->v_flag & VAGE1) {
300 vp->v_flag &= ~VAGE1;
304 ap.a_head.a_desc = &vop_open_desc;
305 ap.a_head.a_ops = ops;
311 VFS_MPLOCK(vp->v_mount);
312 DO_OPS(ops, error, &ap, vop_open);
313 VFS_MPUNLOCK(vp->v_mount);
321 vop_close(struct vop_ops *ops, struct vnode *vp, int fflag)
323 struct vop_close_args ap;
327 ap.a_head.a_desc = &vop_close_desc;
328 ap.a_head.a_ops = ops;
332 VFS_MPLOCK(vp->v_mount);
333 DO_OPS(ops, error, &ap, vop_close);
334 VFS_MPUNLOCK(vp->v_mount);
342 vop_access(struct vop_ops *ops, struct vnode *vp, int mode, int flags,
345 struct vop_access_args ap;
349 ap.a_head.a_desc = &vop_access_desc;
350 ap.a_head.a_ops = ops;
356 VFS_MPLOCK(vp->v_mount);
357 DO_OPS(ops, error, &ap, vop_access);
358 VFS_MPUNLOCK(vp->v_mount);
366 vop_getattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap)
368 struct vop_getattr_args ap;
372 ap.a_head.a_desc = &vop_getattr_desc;
373 ap.a_head.a_ops = ops;
377 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_GA_MPSAFE);
378 DO_OPS(ops, error, &ap, vop_getattr);
379 VFS_MPUNLOCK(vp->v_mount);
388 vop_setattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap,
391 struct vop_setattr_args ap;
395 ap.a_head.a_desc = &vop_setattr_desc;
396 ap.a_head.a_ops = ops;
401 VFS_MPLOCK(vp->v_mount);
402 DO_OPS(ops, error, &ap, vop_setattr);
403 VFS_MPUNLOCK(vp->v_mount);
411 vop_read(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
414 struct vop_read_args ap;
418 ap.a_head.a_desc = &vop_read_desc;
419 ap.a_head.a_ops = ops;
422 ap.a_ioflag = ioflag;
425 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_RD_MPSAFE);
426 DO_OPS(ops, error, &ap, vop_read);
427 VFS_MPUNLOCK(vp->v_mount);
435 vop_write(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
438 struct vop_write_args ap;
442 ap.a_head.a_desc = &vop_write_desc;
443 ap.a_head.a_ops = ops;
446 ap.a_ioflag = ioflag;
449 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_WR_MPSAFE);
450 DO_OPS(ops, error, &ap, vop_write);
451 VFS_MPUNLOCK(vp->v_mount);
459 vop_ioctl(struct vop_ops *ops, struct vnode *vp, u_long command, caddr_t data,
460 int fflag, struct ucred *cred, struct sysmsg *msg)
462 struct vop_ioctl_args ap;
466 ap.a_head.a_desc = &vop_ioctl_desc;
467 ap.a_head.a_ops = ops;
469 ap.a_command = command;
475 VFS_MPLOCK(vp->v_mount);
476 DO_OPS(ops, error, &ap, vop_ioctl);
477 VFS_MPUNLOCK(vp->v_mount);
485 vop_poll(struct vop_ops *ops, struct vnode *vp, int events, struct ucred *cred)
487 struct vop_poll_args ap;
491 ap.a_head.a_desc = &vop_poll_desc;
492 ap.a_head.a_ops = ops;
494 ap.a_events = events;
497 VFS_MPLOCK(vp->v_mount);
498 DO_OPS(ops, error, &ap, vop_poll);
499 VFS_MPUNLOCK(vp->v_mount);
507 vop_kqfilter(struct vop_ops *ops, struct vnode *vp, struct knote *kn)
509 struct vop_kqfilter_args ap;
513 ap.a_head.a_desc = &vop_kqfilter_desc;
514 ap.a_head.a_ops = ops;
518 VFS_MPLOCK(vp->v_mount);
519 DO_OPS(ops, error, &ap, vop_kqfilter);
520 VFS_MPUNLOCK(vp->v_mount);
528 vop_mmap(struct vop_ops *ops, struct vnode *vp, int fflags, struct ucred *cred)
530 struct vop_mmap_args ap;
534 ap.a_head.a_desc = &vop_mmap_desc;
535 ap.a_head.a_ops = ops;
537 ap.a_fflags = fflags;
540 VFS_MPLOCK(vp->v_mount);
541 DO_OPS(ops, error, &ap, vop_mmap);
542 VFS_MPUNLOCK(vp->v_mount);
550 vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor, int flags)
552 struct vop_fsync_args ap;
556 ap.a_head.a_desc = &vop_fsync_desc;
557 ap.a_head.a_ops = ops;
559 ap.a_waitfor = waitfor;
562 VFS_MPLOCK(vp->v_mount);
563 DO_OPS(ops, error, &ap, vop_fsync);
564 VFS_MPUNLOCK(vp->v_mount);
572 vop_old_remove(struct vop_ops *ops, struct vnode *dvp,
573 struct vnode *vp, struct componentname *cnp)
575 struct vop_old_remove_args ap;
579 ap.a_head.a_desc = &vop_old_remove_desc;
580 ap.a_head.a_ops = ops;
585 VFS_MPLOCK(dvp->v_mount);
586 DO_OPS(ops, error, &ap, vop_old_remove);
587 VFS_MPUNLOCK(dvp->v_mount);
595 vop_old_link(struct vop_ops *ops, struct vnode *tdvp,
596 struct vnode *vp, struct componentname *cnp)
598 struct vop_old_link_args ap;
602 ap.a_head.a_desc = &vop_old_link_desc;
603 ap.a_head.a_ops = ops;
608 VFS_MPLOCK(tdvp->v_mount);
609 DO_OPS(ops, error, &ap, vop_old_link);
610 VFS_MPUNLOCK(tdvp->v_mount);
618 vop_old_rename(struct vop_ops *ops,
619 struct vnode *fdvp, struct vnode *fvp, struct componentname *fcnp,
620 struct vnode *tdvp, struct vnode *tvp, struct componentname *tcnp)
622 struct vop_old_rename_args ap;
626 ap.a_head.a_desc = &vop_old_rename_desc;
627 ap.a_head.a_ops = ops;
635 VFS_MPLOCK(tdvp->v_mount);
636 DO_OPS(ops, error, &ap, vop_old_rename);
637 VFS_MPUNLOCK(tdvp->v_mount);
645 vop_old_mkdir(struct vop_ops *ops, struct vnode *dvp,
646 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
648 struct vop_old_mkdir_args ap;
652 ap.a_head.a_desc = &vop_old_mkdir_desc;
653 ap.a_head.a_ops = ops;
659 VFS_MPLOCK(dvp->v_mount);
660 DO_OPS(ops, error, &ap, vop_old_mkdir);
661 VFS_MPUNLOCK(dvp->v_mount);
669 vop_old_rmdir(struct vop_ops *ops, struct vnode *dvp,
670 struct vnode *vp, struct componentname *cnp)
672 struct vop_old_rmdir_args ap;
676 ap.a_head.a_desc = &vop_old_rmdir_desc;
677 ap.a_head.a_ops = ops;
682 VFS_MPLOCK(dvp->v_mount);
683 DO_OPS(ops, error, &ap, vop_old_rmdir);
684 VFS_MPUNLOCK(dvp->v_mount);
692 vop_old_symlink(struct vop_ops *ops, struct vnode *dvp,
693 struct vnode **vpp, struct componentname *cnp,
694 struct vattr *vap, char *target)
696 struct vop_old_symlink_args ap;
700 ap.a_head.a_desc = &vop_old_symlink_desc;
701 ap.a_head.a_ops = ops;
706 ap.a_target = target;
708 VFS_MPLOCK(dvp->v_mount);
709 DO_OPS(ops, error, &ap, vop_old_symlink);
710 VFS_MPUNLOCK(dvp->v_mount);
718 vop_readdir(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
719 struct ucred *cred, int *eofflag, int *ncookies, off_t **cookies)
721 struct vop_readdir_args ap;
725 ap.a_head.a_desc = &vop_readdir_desc;
726 ap.a_head.a_ops = ops;
730 ap.a_eofflag = eofflag;
731 ap.a_ncookies = ncookies;
732 ap.a_cookies = cookies;
734 VFS_MPLOCK(vp->v_mount);
735 DO_OPS(ops, error, &ap, vop_readdir);
736 VFS_MPUNLOCK(vp->v_mount);
744 vop_readlink(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
747 struct vop_readlink_args ap;
751 ap.a_head.a_desc = &vop_readlink_desc;
752 ap.a_head.a_ops = ops;
757 VFS_MPLOCK(vp->v_mount);
758 DO_OPS(ops, error, &ap, vop_readlink);
759 VFS_MPUNLOCK(vp->v_mount);
767 vop_inactive(struct vop_ops *ops, struct vnode *vp)
769 struct vop_inactive_args ap;
773 ap.a_head.a_desc = &vop_inactive_desc;
774 ap.a_head.a_ops = ops;
777 VFS_MPLOCK(vp->v_mount);
778 DO_OPS(ops, error, &ap, vop_inactive);
779 VFS_MPUNLOCK(vp->v_mount);
787 vop_reclaim(struct vop_ops *ops, struct vnode *vp)
789 struct vop_reclaim_args ap;
793 ap.a_head.a_desc = &vop_reclaim_desc;
794 ap.a_head.a_ops = ops;
797 VFS_MPLOCK(vp->v_mount);
798 DO_OPS(ops, error, &ap, vop_reclaim);
799 VFS_MPUNLOCK(vp->v_mount);
807 vop_bmap(struct vop_ops *ops, struct vnode *vp, off_t loffset,
808 off_t *doffsetp, int *runp, int *runb, buf_cmd_t cmd)
810 struct vop_bmap_args ap;
814 ap.a_head.a_desc = &vop_bmap_desc;
815 ap.a_head.a_ops = ops;
817 ap.a_loffset = loffset;
818 ap.a_doffsetp = doffsetp;
823 VFS_MPLOCK(vp->v_mount);
824 DO_OPS(ops, error, &ap, vop_bmap);
825 VFS_MPUNLOCK(vp->v_mount);
833 vop_strategy(struct vop_ops *ops, struct vnode *vp, struct bio *bio)
835 struct vop_strategy_args ap;
839 ap.a_head.a_desc = &vop_strategy_desc;
840 ap.a_head.a_ops = ops;
844 VFS_MPLOCK(vp->v_mount);
845 DO_OPS(ops, error, &ap, vop_strategy);
846 VFS_MPUNLOCK(vp->v_mount);
854 vop_print(struct vop_ops *ops, struct vnode *vp)
856 struct vop_print_args ap;
860 ap.a_head.a_desc = &vop_print_desc;
861 ap.a_head.a_ops = ops;
864 VFS_MPLOCK(vp->v_mount);
865 DO_OPS(ops, error, &ap, vop_print);
866 VFS_MPUNLOCK(vp->v_mount);
874 vop_pathconf(struct vop_ops *ops, struct vnode *vp, int name,
877 struct vop_pathconf_args ap;
881 ap.a_head.a_desc = &vop_pathconf_desc;
882 ap.a_head.a_ops = ops;
885 ap.a_retval = retval;
887 VFS_MPLOCK(vp->v_mount);
888 DO_OPS(ops, error, &ap, vop_pathconf);
889 VFS_MPUNLOCK(vp->v_mount);
897 vop_advlock(struct vop_ops *ops, struct vnode *vp, caddr_t id, int op,
898 struct flock *fl, int flags)
900 struct vop_advlock_args ap;
904 ap.a_head.a_desc = &vop_advlock_desc;
905 ap.a_head.a_ops = ops;
912 VFS_MPLOCK(vp->v_mount);
913 DO_OPS(ops, error, &ap, vop_advlock);
914 VFS_MPUNLOCK(vp->v_mount);
922 vop_balloc(struct vop_ops *ops, struct vnode *vp, off_t startoffset,
923 int size, struct ucred *cred, int flags,
926 struct vop_balloc_args ap;
930 ap.a_head.a_desc = &vop_balloc_desc;
931 ap.a_head.a_ops = ops;
933 ap.a_startoffset = startoffset;
939 VFS_MPLOCK(vp->v_mount);
940 DO_OPS(ops, error, &ap, vop_balloc);
941 VFS_MPUNLOCK(vp->v_mount);
949 vop_reallocblks(struct vop_ops *ops, struct vnode *vp,
950 struct cluster_save *buflist)
952 struct vop_reallocblks_args ap;
956 ap.a_head.a_desc = &vop_reallocblks_desc;
957 ap.a_head.a_ops = ops;
959 ap.a_buflist = buflist;
961 VFS_MPLOCK(vp->v_mount);
962 DO_OPS(ops, error, &ap, vop_reallocblks);
963 VFS_MPUNLOCK(vp->v_mount);
971 vop_getpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
972 int reqpage, vm_ooffset_t offset)
974 struct vop_getpages_args ap;
978 ap.a_head.a_desc = &vop_getpages_desc;
979 ap.a_head.a_ops = ops;
983 ap.a_reqpage = reqpage;
984 ap.a_offset = offset;
986 VFS_MPLOCK(vp->v_mount);
987 DO_OPS(ops, error, &ap, vop_getpages);
988 VFS_MPUNLOCK(vp->v_mount);
996 vop_putpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
997 int sync, int *rtvals, vm_ooffset_t offset)
999 struct vop_putpages_args ap;
1003 ap.a_head.a_desc = &vop_putpages_desc;
1004 ap.a_head.a_ops = ops;
1009 ap.a_rtvals = rtvals;
1010 ap.a_offset = offset;
1012 VFS_MPLOCK(vp->v_mount);
1013 DO_OPS(ops, error, &ap, vop_putpages);
1014 VFS_MPUNLOCK(vp->v_mount);
1022 vop_freeblks(struct vop_ops *ops, struct vnode *vp, off_t offset, int length)
1024 struct vop_freeblks_args ap;
1028 ap.a_head.a_desc = &vop_freeblks_desc;
1029 ap.a_head.a_ops = ops;
1031 ap.a_offset = offset;
1032 ap.a_length = length;
1034 VFS_MPLOCK(vp->v_mount);
1035 DO_OPS(ops, error, &ap, vop_freeblks);
1036 VFS_MPUNLOCK(vp->v_mount);
1044 vop_getacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1045 struct acl *aclp, struct ucred *cred)
1047 struct vop_getacl_args ap;
1051 ap.a_head.a_desc = &vop_getacl_desc;
1052 ap.a_head.a_ops = ops;
1058 VFS_MPLOCK(vp->v_mount);
1059 DO_OPS(ops, error, &ap, vop_getacl);
1060 VFS_MPUNLOCK(vp->v_mount);
1068 vop_setacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1069 struct acl *aclp, struct ucred *cred)
1071 struct vop_setacl_args ap;
1075 ap.a_head.a_desc = &vop_setacl_desc;
1076 ap.a_head.a_ops = ops;
1082 VFS_MPLOCK(vp->v_mount);
1083 DO_OPS(ops, error, &ap, vop_setacl);
1084 VFS_MPUNLOCK(vp->v_mount);
1092 vop_aclcheck(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1093 struct acl *aclp, struct ucred *cred)
1095 struct vop_aclcheck_args ap;
1099 ap.a_head.a_desc = &vop_aclcheck_desc;
1100 ap.a_head.a_ops = ops;
1106 VFS_MPLOCK(vp->v_mount);
1107 DO_OPS(ops, error, &ap, vop_aclcheck);
1108 VFS_MPUNLOCK(vp->v_mount);
1116 vop_getextattr(struct vop_ops *ops, struct vnode *vp, char *name,
1117 struct uio *uio, struct ucred *cred)
1119 struct vop_getextattr_args ap;
1123 ap.a_head.a_desc = &vop_getextattr_desc;
1124 ap.a_head.a_ops = ops;
1130 VFS_MPLOCK(vp->v_mount);
1131 DO_OPS(ops, error, &ap, vop_getextattr);
1132 VFS_MPUNLOCK(vp->v_mount);
1140 vop_setextattr(struct vop_ops *ops, struct vnode *vp, char *name,
1141 struct uio *uio, struct ucred *cred)
1143 struct vop_setextattr_args ap;
1147 ap.a_head.a_desc = &vop_setextattr_desc;
1148 ap.a_head.a_ops = ops;
1154 VFS_MPLOCK(vp->v_mount);
1155 DO_OPS(ops, error, &ap, vop_setextattr);
1156 VFS_MPUNLOCK(vp->v_mount);
1164 vop_mountctl(struct vop_ops *ops, struct vnode *vp, int op, struct file *fp,
1165 const void *ctl, int ctllen, void *buf, int buflen, int *res)
1167 struct vop_mountctl_args ap;
1171 ap.a_head.a_desc = &vop_mountctl_desc;
1172 ap.a_head.a_ops = ops;
1176 ap.a_ctllen = ctllen;
1178 ap.a_buflen = buflen;
1181 VFS_MPLOCK(vp->v_mount);
1182 DO_OPS(ops, error, &ap, vop_mountctl);
1183 VFS_MPUNLOCK(vp->v_mount);
1191 vop_markatime(struct vop_ops *ops, struct vnode *vp, struct ucred *cred)
1193 struct vop_markatime_args ap;
1197 ap.a_head.a_desc = &vop_markatime_desc;
1198 ap.a_head.a_ops = ops;
1202 VFS_MPLOCK(vp->v_mount);
1203 DO_OPS(ops, error, &ap, vop_markatime);
1204 VFS_MPUNLOCK(vp->v_mount);
1211 * nresolve takes a locked ncp, a referenced but unlocked dvp, and a cred,
1212 * and resolves the ncp into a positive or negative hit.
1214 * The namecache is automatically adjusted by this function. The ncp
1215 * is left locked on return.
1220 vop_nresolve(struct vop_ops *ops, struct nchandle *nch,
1221 struct vnode *dvp, struct ucred *cred)
1223 struct vop_nresolve_args ap;
1227 ap.a_head.a_desc = &vop_nresolve_desc;
1228 ap.a_head.a_ops = ops;
1233 VFS_MPLOCK(dvp->v_mount);
1234 DO_OPS(ops, error, &ap, vop_nresolve);
1235 VFS_MPUNLOCK(dvp->v_mount);
1240 * nlookupdotdot takes an unlocked directory, referenced dvp, and looks
1241 * up "..", returning a locked parent directory in *vpp. If an error
1242 * occurs *vpp will be NULL.
1247 vop_nlookupdotdot(struct vop_ops *ops, struct vnode *dvp,
1248 struct vnode **vpp, struct ucred *cred, char **fakename)
1250 struct vop_nlookupdotdot_args ap;
1254 ap.a_head.a_desc = &vop_nlookupdotdot_desc;
1255 ap.a_head.a_ops = ops;
1259 ap.a_fakename = fakename;
1261 VFS_MPLOCK(dvp->v_mount);
1262 DO_OPS(ops, error, &ap, vop_nlookupdotdot);
1263 VFS_MPUNLOCK(dvp->v_mount);
1268 * ncreate takes a locked, resolved ncp that typically represents a negative
1269 * cache hit and creates the file or node specified by the ncp, cred, and
1270 * vattr. If no error occurs a locked vnode is returned in *vpp.
1272 * The dvp passed in is referenced but unlocked.
1274 * The namecache is automatically adjusted by this function. The ncp
1275 * is left locked on return.
1280 vop_ncreate(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1281 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1283 struct vop_ncreate_args ap;
1287 ap.a_head.a_desc = &vop_ncreate_desc;
1288 ap.a_head.a_ops = ops;
1295 VFS_MPLOCK(dvp->v_mount);
1296 DO_OPS(ops, error, &ap, vop_ncreate);
1297 VFS_MPUNLOCK(dvp->v_mount);
1302 * nmkdir takes a locked, resolved ncp that typically represents a negative
1303 * cache hit and creates the directory specified by the ncp, cred, and
1304 * vattr. If no error occurs a locked vnode is returned in *vpp.
1306 * The dvp passed in is referenced but unlocked.
1308 * The namecache is automatically adjusted by this function. The ncp
1309 * is left locked on return.
1314 vop_nmkdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1315 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1317 struct vop_nmkdir_args ap;
1321 ap.a_head.a_desc = &vop_nmkdir_desc;
1322 ap.a_head.a_ops = ops;
1329 VFS_MPLOCK(dvp->v_mount);
1330 DO_OPS(ops, error, &ap, vop_nmkdir);
1331 VFS_MPUNLOCK(dvp->v_mount);
1336 * nmknod takes a locked, resolved ncp that typically represents a negative
1337 * cache hit and creates the node specified by the ncp, cred, and
1338 * vattr. If no error occurs a locked vnode is returned in *vpp.
1340 * The dvp passed in is referenced but unlocked.
1342 * The namecache is automatically adjusted by this function. The ncp
1343 * is left locked on return.
1348 vop_nmknod(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1349 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1351 struct vop_nmknod_args ap;
1355 ap.a_head.a_desc = &vop_nmknod_desc;
1356 ap.a_head.a_ops = ops;
1363 VFS_MPLOCK(dvp->v_mount);
1364 DO_OPS(ops, error, &ap, vop_nmknod);
1365 VFS_MPUNLOCK(dvp->v_mount);
1370 * nlink takes a locked, resolved ncp that typically represents a negative
1371 * cache hit and creates the node specified by the ncp, cred, and
1372 * existing vnode. The passed vp must be locked and will remain locked
1373 * on return, as does the ncp, whether an error occurs or not.
1375 * The dvp passed in is referenced but unlocked.
1377 * The namecache is automatically adjusted by this function. The ncp
1378 * is left locked on return.
1383 vop_nlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1384 struct vnode *vp, struct ucred *cred)
1386 struct vop_nlink_args ap;
1390 ap.a_head.a_desc = &vop_nlink_desc;
1391 ap.a_head.a_ops = ops;
1397 VFS_MPLOCK(dvp->v_mount);
1398 DO_OPS(ops, error, &ap, vop_nlink);
1399 VFS_MPUNLOCK(dvp->v_mount);
1404 * nsymlink takes a locked, resolved ncp that typically represents a negative
1405 * cache hit and creates a symbolic link based on cred, vap, and target (the
1406 * contents of the link). If no error occurs a locked vnode is returned in
1409 * The dvp passed in is referenced but unlocked.
1411 * The namecache is automatically adjusted by this function. The ncp
1412 * is left locked on return.
1417 vop_nsymlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1418 struct vnode **vpp, struct ucred *cred,
1419 struct vattr *vap, char *target)
1421 struct vop_nsymlink_args ap;
1425 ap.a_head.a_desc = &vop_nsymlink_desc;
1426 ap.a_head.a_ops = ops;
1432 ap.a_target = target;
1434 VFS_MPLOCK(dvp->v_mount);
1435 DO_OPS(ops, error, &ap, vop_nsymlink);
1436 VFS_MPUNLOCK(dvp->v_mount);
1441 * nwhiteout takes a locked, resolved ncp that can represent a positive or
1442 * negative hit and executes the whiteout function specified in flags.
1444 * The dvp passed in is referenced but unlocked.
1446 * The namecache is automatically adjusted by this function. The ncp
1447 * is left locked on return.
1452 vop_nwhiteout(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1453 struct ucred *cred, int flags)
1455 struct vop_nwhiteout_args ap;
1459 ap.a_head.a_desc = &vop_nwhiteout_desc;
1460 ap.a_head.a_ops = ops;
1466 VFS_MPLOCK(dvp->v_mount);
1467 DO_OPS(ops, error, &ap, vop_nwhiteout);
1468 VFS_MPUNLOCK(dvp->v_mount);
1473 * nremove takes a locked, resolved ncp that generally represents a
1474 * positive hit and removes the file.
1476 * The dvp passed in is referenced but unlocked.
1478 * The namecache is automatically adjusted by this function. The ncp
1479 * is left locked on return.
1484 vop_nremove(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1487 struct vop_nremove_args ap;
1491 ap.a_head.a_desc = &vop_nremove_desc;
1492 ap.a_head.a_ops = ops;
1497 VFS_MPLOCK(dvp->v_mount);
1498 DO_OPS(ops, error, &ap, vop_nremove);
1499 VFS_MPUNLOCK(dvp->v_mount);
1504 * nrmdir takes a locked, resolved ncp that generally represents a
1505 * directory and removes the directory.
1507 * The dvp passed in is referenced but unlocked.
1509 * The namecache is automatically adjusted by this function. The ncp
1510 * is left locked on return.
1515 vop_nrmdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1518 struct vop_nrmdir_args ap;
1522 ap.a_head.a_desc = &vop_nrmdir_desc;
1523 ap.a_head.a_ops = ops;
1528 VFS_MPLOCK(dvp->v_mount);
1529 DO_OPS(ops, error, &ap, vop_nrmdir);
1530 VFS_MPUNLOCK(dvp->v_mount);
1535 * nrename takes TWO locked, resolved ncp's and the cred of the caller
1536 * and renames the source ncp to the target ncp. The target ncp may
1537 * represent a positive or negative hit.
1539 * The fdvp and tdvp passed in are referenced but unlocked.
1541 * The namecache is automatically adjusted by this function. The ncp
1542 * is left locked on return. The source ncp is typically changed to
1543 * a negative cache hit and the target ncp typically takes on the
1544 * source ncp's underlying file.
1549 vop_nrename(struct vop_ops *ops,
1550 struct nchandle *fnch, struct nchandle *tnch,
1551 struct vnode *fdvp, struct vnode *tdvp,
1554 struct vop_nrename_args ap;
1558 ap.a_head.a_desc = &vop_nrename_desc;
1559 ap.a_head.a_ops = ops;
1566 VFS_MPLOCK(fdvp->v_mount);
1567 DO_OPS(ops, error, &ap, vop_nrename);
1568 VFS_MPUNLOCK(fdvp->v_mount);
1572 /************************************************************************
1573 * PRIMARY VNODE OPERATIONS FORWARDING CALLS *
1574 ************************************************************************
1576 * These procedures are called from VFSs such as unionfs and nullfs
1577 * when they wish to forward an operation on one VFS to another. The
1578 * argument structure/message is modified and then directly passed to the
1579 * appropriate routine. This routines may also be called by initiators
1580 * who have an argument structure in hand rather then discreet arguments.
1582 * MPSAFE - Caller expected to already hold the appropriate vfs lock.
1585 vop_vnoperate_ap(struct vop_generic_args *ap)
1587 struct vop_ops *ops;
1591 error = VOCALL(ops, ap);
1597 * This routine is called by the cache coherency layer to execute the actual
1598 * VFS operation. If a journaling layer is present we call though it, else
1599 * we call the native VOP functions.
1602 vop_cache_operate_ap(struct vop_generic_args *ap)
1604 struct vop_ops *ops;
1608 if (ops->head.vv_mount->mnt_vn_journal_ops)
1609 error = VOCALL(ops->head.vv_mount->mnt_vn_journal_ops, ap);
1611 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1617 * This routine is called by the journaling layer to execute the actual
1621 vop_journal_operate_ap(struct vop_generic_args *ap)
1623 struct vop_ops *ops;
1627 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1633 vop_open_ap(struct vop_open_args *ap)
1637 DO_OPS(ap->a_head.a_ops, error, ap, vop_open);
1642 vop_close_ap(struct vop_close_args *ap)
1646 DO_OPS(ap->a_head.a_ops, error, ap, vop_close);
1651 vop_access_ap(struct vop_access_args *ap)
1655 DO_OPS(ap->a_head.a_ops, error, ap, vop_access);
1660 vop_getattr_ap(struct vop_getattr_args *ap)
1664 DO_OPS(ap->a_head.a_ops, error, ap, vop_getattr);
1669 vop_setattr_ap(struct vop_setattr_args *ap)
1673 DO_OPS(ap->a_head.a_ops, error, ap, vop_setattr);
1678 vop_read_ap(struct vop_read_args *ap)
1682 DO_OPS(ap->a_head.a_ops, error, ap, vop_read);
1687 vop_write_ap(struct vop_write_args *ap)
1691 DO_OPS(ap->a_head.a_ops, error, ap, vop_write);
1696 vop_ioctl_ap(struct vop_ioctl_args *ap)
1700 DO_OPS(ap->a_head.a_ops, error, ap, vop_ioctl);
1705 vop_poll_ap(struct vop_poll_args *ap)
1709 DO_OPS(ap->a_head.a_ops, error, ap, vop_poll);
1714 vop_kqfilter_ap(struct vop_kqfilter_args *ap)
1718 DO_OPS(ap->a_head.a_ops, error, ap, vop_kqfilter);
1723 vop_mmap_ap(struct vop_mmap_args *ap)
1727 DO_OPS(ap->a_head.a_ops, error, ap, vop_mmap);
1732 vop_fsync_ap(struct vop_fsync_args *ap)
1736 DO_OPS(ap->a_head.a_ops, error, ap, vop_fsync);
1741 vop_readdir_ap(struct vop_readdir_args *ap)
1745 DO_OPS(ap->a_head.a_ops, error, ap, vop_readdir);
1750 vop_readlink_ap(struct vop_readlink_args *ap)
1754 DO_OPS(ap->a_head.a_ops, error, ap, vop_readlink);
1759 vop_inactive_ap(struct vop_inactive_args *ap)
1763 DO_OPS(ap->a_head.a_ops, error, ap, vop_inactive);
1768 vop_reclaim_ap(struct vop_reclaim_args *ap)
1772 DO_OPS(ap->a_head.a_ops, error, ap, vop_reclaim);
1777 vop_bmap_ap(struct vop_bmap_args *ap)
1781 DO_OPS(ap->a_head.a_ops, error, ap, vop_bmap);
1786 vop_strategy_ap(struct vop_strategy_args *ap)
1790 DO_OPS(ap->a_head.a_ops, error, ap, vop_strategy);
1795 vop_print_ap(struct vop_print_args *ap)
1799 DO_OPS(ap->a_head.a_ops, error, ap, vop_print);
1804 vop_pathconf_ap(struct vop_pathconf_args *ap)
1808 DO_OPS(ap->a_head.a_ops, error, ap, vop_pathconf);
1813 vop_advlock_ap(struct vop_advlock_args *ap)
1817 DO_OPS(ap->a_head.a_ops, error, ap, vop_advlock);
1822 vop_balloc_ap(struct vop_balloc_args *ap)
1826 DO_OPS(ap->a_head.a_ops, error, ap, vop_balloc);
1831 vop_reallocblks_ap(struct vop_reallocblks_args *ap)
1835 DO_OPS(ap->a_head.a_ops, error, ap, vop_reallocblks);
1840 vop_getpages_ap(struct vop_getpages_args *ap)
1844 DO_OPS(ap->a_head.a_ops, error, ap, vop_getpages);
1849 vop_putpages_ap(struct vop_putpages_args *ap)
1853 DO_OPS(ap->a_head.a_ops, error, ap, vop_putpages);
1858 vop_freeblks_ap(struct vop_freeblks_args *ap)
1862 DO_OPS(ap->a_head.a_ops, error, ap, vop_freeblks);
1867 vop_getacl_ap(struct vop_getacl_args *ap)
1871 DO_OPS(ap->a_head.a_ops, error, ap, vop_getacl);
1876 vop_setacl_ap(struct vop_setacl_args *ap)
1880 DO_OPS(ap->a_head.a_ops, error, ap, vop_setacl);
1885 vop_aclcheck_ap(struct vop_aclcheck_args *ap)
1889 DO_OPS(ap->a_head.a_ops, error, ap, vop_aclcheck);
1894 vop_getextattr_ap(struct vop_getextattr_args *ap)
1898 DO_OPS(ap->a_head.a_ops, error, ap, vop_getextattr);
1903 vop_setextattr_ap(struct vop_setextattr_args *ap)
1907 DO_OPS(ap->a_head.a_ops, error, ap, vop_setextattr);
1912 vop_mountctl_ap(struct vop_mountctl_args *ap)
1916 DO_OPS(ap->a_head.a_ops, error, ap, vop_mountctl);
1921 vop_markatime_ap(struct vop_markatime_args *ap)
1925 DO_OPS(ap->a_head.a_ops, error, ap, vop_markatime);
1930 vop_nresolve_ap(struct vop_nresolve_args *ap)
1934 DO_OPS(ap->a_head.a_ops, error, ap, vop_nresolve);
1939 vop_nlookupdotdot_ap(struct vop_nlookupdotdot_args *ap)
1943 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlookupdotdot);
1948 vop_ncreate_ap(struct vop_ncreate_args *ap)
1952 DO_OPS(ap->a_head.a_ops, error, ap, vop_ncreate);
1957 vop_nmkdir_ap(struct vop_nmkdir_args *ap)
1961 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmkdir);
1966 vop_nmknod_ap(struct vop_nmknod_args *ap)
1970 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmknod);
1975 vop_nlink_ap(struct vop_nlink_args *ap)
1979 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlink);
1984 vop_nsymlink_ap(struct vop_nsymlink_args *ap)
1988 DO_OPS(ap->a_head.a_ops, error, ap, vop_nsymlink);
1993 vop_nwhiteout_ap(struct vop_nwhiteout_args *ap)
1997 DO_OPS(ap->a_head.a_ops, error, ap, vop_nwhiteout);
2002 vop_nremove_ap(struct vop_nremove_args *ap)
2006 DO_OPS(ap->a_head.a_ops, error, ap, vop_nremove);
2011 vop_nrmdir_ap(struct vop_nrmdir_args *ap)
2015 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrmdir);
2020 vop_nrename_ap(struct vop_nrename_args *ap)
2024 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrename);