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 /************************************************************************
153 * PRIMARY HIGH LEVEL VNODE OPERATIONS CALLS *
154 ************************************************************************
156 * These procedures are called directly from the kernel and/or fileops
157 * code to perform file/device operations on the system.
159 * NOTE: The old namespace api functions such as vop_rename() are no
160 * longer available for general use and have been renamed to
161 * vop_old_*(). Only the code in vfs_default.c is allowed to call
164 * NOTE: The VFS_MPLOCK*() macros handle mounts which do not set
165 * MNTK_MPSAFE or MNTK_xx_MPSAFE.
171 vop_old_lookup(struct vop_ops *ops, struct vnode *dvp,
172 struct vnode **vpp, struct componentname *cnp)
174 struct vop_old_lookup_args ap;
178 ap.a_head.a_desc = &vop_old_lookup_desc;
179 ap.a_head.a_ops = ops;
183 VFS_MPLOCK1(dvp->v_mount);
184 DO_OPS(ops, error, &ap, vop_old_lookup);
185 VFS_MPUNLOCK(dvp->v_mount);
193 vop_old_create(struct vop_ops *ops, struct vnode *dvp,
194 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
196 struct vop_old_create_args ap;
200 ap.a_head.a_desc = &vop_old_create_desc;
201 ap.a_head.a_ops = ops;
207 VFS_MPLOCK1(dvp->v_mount);
208 DO_OPS(ops, error, &ap, vop_old_create);
209 VFS_MPUNLOCK(dvp->v_mount);
217 vop_old_whiteout(struct vop_ops *ops, struct vnode *dvp,
218 struct componentname *cnp, int flags)
220 struct vop_old_whiteout_args ap;
224 ap.a_head.a_desc = &vop_old_whiteout_desc;
225 ap.a_head.a_ops = ops;
230 VFS_MPLOCK1(dvp->v_mount);
231 DO_OPS(ops, error, &ap, vop_old_whiteout);
232 VFS_MPUNLOCK(dvp->v_mount);
240 vop_old_mknod(struct vop_ops *ops, struct vnode *dvp,
241 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
243 struct vop_old_mknod_args ap;
247 ap.a_head.a_desc = &vop_old_mknod_desc;
248 ap.a_head.a_ops = ops;
254 VFS_MPLOCK1(dvp->v_mount);
255 DO_OPS(ops, error, &ap, vop_old_mknod);
256 VFS_MPUNLOCK(dvp->v_mount);
261 * NOTE: VAGE is always cleared when calling VOP_OPEN().
264 vop_open(struct vop_ops *ops, struct vnode *vp, int mode, struct ucred *cred,
267 struct vop_open_args ap;
272 * Decrement 3-2-1-0. Does not decrement beyond 0
274 if (vp->v_flag & VAGE0) {
275 vclrflags(vp, VAGE0);
276 } else if (vp->v_flag & VAGE1) {
277 vclrflags(vp, VAGE1);
278 vsetflags(vp, VAGE0);
281 ap.a_head.a_desc = &vop_open_desc;
282 ap.a_head.a_ops = ops;
288 VFS_MPLOCK1(vp->v_mount);
289 DO_OPS(ops, error, &ap, vop_open);
290 VFS_MPUNLOCK(vp->v_mount);
298 vop_close(struct vop_ops *ops, struct vnode *vp, int fflag)
300 struct vop_close_args ap;
304 ap.a_head.a_desc = &vop_close_desc;
305 ap.a_head.a_ops = ops;
309 VFS_MPLOCK1(vp->v_mount);
310 DO_OPS(ops, error, &ap, vop_close);
311 VFS_MPUNLOCK(vp->v_mount);
319 vop_access(struct vop_ops *ops, struct vnode *vp, int mode, int flags,
322 struct vop_access_args ap;
326 ap.a_head.a_desc = &vop_access_desc;
327 ap.a_head.a_ops = ops;
333 VFS_MPLOCK1(vp->v_mount);
334 DO_OPS(ops, error, &ap, vop_access);
335 VFS_MPUNLOCK(vp->v_mount);
343 vop_getattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap)
345 struct vop_getattr_args ap;
349 ap.a_head.a_desc = &vop_getattr_desc;
350 ap.a_head.a_ops = ops;
354 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_GA_MPSAFE);
355 DO_OPS(ops, error, &ap, vop_getattr);
356 VFS_MPUNLOCK(vp->v_mount);
365 vop_setattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap,
368 struct vop_setattr_args ap;
372 ap.a_head.a_desc = &vop_setattr_desc;
373 ap.a_head.a_ops = ops;
378 VFS_MPLOCK1(vp->v_mount);
379 DO_OPS(ops, error, &ap, vop_setattr);
380 VFS_MPUNLOCK(vp->v_mount);
388 vop_read(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
391 struct vop_read_args ap;
395 ap.a_head.a_desc = &vop_read_desc;
396 ap.a_head.a_ops = ops;
399 ap.a_ioflag = ioflag;
402 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_RD_MPSAFE);
403 DO_OPS(ops, error, &ap, vop_read);
404 VFS_MPUNLOCK(vp->v_mount);
412 vop_write(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
415 struct vop_write_args ap;
419 ap.a_head.a_desc = &vop_write_desc;
420 ap.a_head.a_ops = ops;
423 ap.a_ioflag = ioflag;
426 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_WR_MPSAFE);
427 DO_OPS(ops, error, &ap, vop_write);
428 VFS_MPUNLOCK(vp->v_mount);
436 vop_ioctl(struct vop_ops *ops, struct vnode *vp, u_long command, caddr_t data,
437 int fflag, struct ucred *cred, struct sysmsg *msg)
439 struct vop_ioctl_args ap;
443 ap.a_head.a_desc = &vop_ioctl_desc;
444 ap.a_head.a_ops = ops;
446 ap.a_command = command;
452 VFS_MPLOCK1(vp->v_mount);
453 DO_OPS(ops, error, &ap, vop_ioctl);
454 VFS_MPUNLOCK(vp->v_mount);
462 vop_poll(struct vop_ops *ops, struct vnode *vp, int events, struct ucred *cred)
464 struct vop_poll_args ap;
468 ap.a_head.a_desc = &vop_poll_desc;
469 ap.a_head.a_ops = ops;
471 ap.a_events = events;
474 VFS_MPLOCK1(vp->v_mount);
475 DO_OPS(ops, error, &ap, vop_poll);
476 VFS_MPUNLOCK(vp->v_mount);
484 vop_kqfilter(struct vop_ops *ops, struct vnode *vp, struct knote *kn)
486 struct vop_kqfilter_args ap;
490 ap.a_head.a_desc = &vop_kqfilter_desc;
491 ap.a_head.a_ops = ops;
495 VFS_MPLOCK1(vp->v_mount);
496 DO_OPS(ops, error, &ap, vop_kqfilter);
497 VFS_MPUNLOCK(vp->v_mount);
505 vop_mmap(struct vop_ops *ops, struct vnode *vp, int fflags, struct ucred *cred)
507 struct vop_mmap_args ap;
511 ap.a_head.a_desc = &vop_mmap_desc;
512 ap.a_head.a_ops = ops;
514 ap.a_fflags = fflags;
517 VFS_MPLOCK1(vp->v_mount);
518 DO_OPS(ops, error, &ap, vop_mmap);
519 VFS_MPUNLOCK(vp->v_mount);
527 vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor, int flags)
529 struct vop_fsync_args ap;
533 ap.a_head.a_desc = &vop_fsync_desc;
534 ap.a_head.a_ops = ops;
536 ap.a_waitfor = waitfor;
539 VFS_MPLOCK1(vp->v_mount);
540 DO_OPS(ops, error, &ap, vop_fsync);
541 VFS_MPUNLOCK(vp->v_mount);
549 vop_old_remove(struct vop_ops *ops, struct vnode *dvp,
550 struct vnode *vp, struct componentname *cnp)
552 struct vop_old_remove_args ap;
556 ap.a_head.a_desc = &vop_old_remove_desc;
557 ap.a_head.a_ops = ops;
562 VFS_MPLOCK1(dvp->v_mount);
563 DO_OPS(ops, error, &ap, vop_old_remove);
564 VFS_MPUNLOCK(dvp->v_mount);
572 vop_old_link(struct vop_ops *ops, struct vnode *tdvp,
573 struct vnode *vp, struct componentname *cnp)
575 struct vop_old_link_args ap;
579 ap.a_head.a_desc = &vop_old_link_desc;
580 ap.a_head.a_ops = ops;
585 VFS_MPLOCK1(tdvp->v_mount);
586 DO_OPS(ops, error, &ap, vop_old_link);
587 VFS_MPUNLOCK(tdvp->v_mount);
595 vop_old_rename(struct vop_ops *ops,
596 struct vnode *fdvp, struct vnode *fvp, struct componentname *fcnp,
597 struct vnode *tdvp, struct vnode *tvp, struct componentname *tcnp)
599 struct vop_old_rename_args ap;
603 ap.a_head.a_desc = &vop_old_rename_desc;
604 ap.a_head.a_ops = ops;
612 VFS_MPLOCK1(tdvp->v_mount);
613 DO_OPS(ops, error, &ap, vop_old_rename);
614 VFS_MPUNLOCK(tdvp->v_mount);
622 vop_old_mkdir(struct vop_ops *ops, struct vnode *dvp,
623 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
625 struct vop_old_mkdir_args ap;
629 ap.a_head.a_desc = &vop_old_mkdir_desc;
630 ap.a_head.a_ops = ops;
636 VFS_MPLOCK1(dvp->v_mount);
637 DO_OPS(ops, error, &ap, vop_old_mkdir);
638 VFS_MPUNLOCK(dvp->v_mount);
646 vop_old_rmdir(struct vop_ops *ops, struct vnode *dvp,
647 struct vnode *vp, struct componentname *cnp)
649 struct vop_old_rmdir_args ap;
653 ap.a_head.a_desc = &vop_old_rmdir_desc;
654 ap.a_head.a_ops = ops;
659 VFS_MPLOCK1(dvp->v_mount);
660 DO_OPS(ops, error, &ap, vop_old_rmdir);
661 VFS_MPUNLOCK(dvp->v_mount);
669 vop_old_symlink(struct vop_ops *ops, struct vnode *dvp,
670 struct vnode **vpp, struct componentname *cnp,
671 struct vattr *vap, char *target)
673 struct vop_old_symlink_args ap;
677 ap.a_head.a_desc = &vop_old_symlink_desc;
678 ap.a_head.a_ops = ops;
683 ap.a_target = target;
685 VFS_MPLOCK1(dvp->v_mount);
686 DO_OPS(ops, error, &ap, vop_old_symlink);
687 VFS_MPUNLOCK(dvp->v_mount);
695 vop_readdir(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
696 struct ucred *cred, int *eofflag, int *ncookies, off_t **cookies)
698 struct vop_readdir_args ap;
702 ap.a_head.a_desc = &vop_readdir_desc;
703 ap.a_head.a_ops = ops;
707 ap.a_eofflag = eofflag;
708 ap.a_ncookies = ncookies;
709 ap.a_cookies = cookies;
711 VFS_MPLOCK1(vp->v_mount);
712 DO_OPS(ops, error, &ap, vop_readdir);
713 VFS_MPUNLOCK(vp->v_mount);
721 vop_readlink(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
724 struct vop_readlink_args ap;
728 ap.a_head.a_desc = &vop_readlink_desc;
729 ap.a_head.a_ops = ops;
734 VFS_MPLOCK1(vp->v_mount);
735 DO_OPS(ops, error, &ap, vop_readlink);
736 VFS_MPUNLOCK(vp->v_mount);
744 vop_inactive(struct vop_ops *ops, struct vnode *vp)
746 struct vop_inactive_args ap;
751 ap.a_head.a_desc = &vop_inactive_desc;
752 ap.a_head.a_ops = ops;
756 * WARNING! Deactivation of the vnode can cause it to be recycled,
757 * clearing vp->v_mount.
760 VFS_MPLOCK_FLAG(mp, MNTK_IN_MPSAFE);
761 DO_OPS(ops, error, &ap, vop_inactive);
770 vop_reclaim(struct vop_ops *ops, struct vnode *vp)
772 struct vop_reclaim_args ap;
777 ap.a_head.a_desc = &vop_reclaim_desc;
778 ap.a_head.a_ops = ops;
782 * WARNING! Reclamation of the vnode will clear vp->v_mount.
786 DO_OPS(ops, error, &ap, vop_reclaim);
795 vop_bmap(struct vop_ops *ops, struct vnode *vp, off_t loffset,
796 off_t *doffsetp, int *runp, int *runb, buf_cmd_t cmd)
798 struct vop_bmap_args ap;
802 ap.a_head.a_desc = &vop_bmap_desc;
803 ap.a_head.a_ops = ops;
805 ap.a_loffset = loffset;
806 ap.a_doffsetp = doffsetp;
811 VFS_MPLOCK1(vp->v_mount);
812 DO_OPS(ops, error, &ap, vop_bmap);
813 VFS_MPUNLOCK(vp->v_mount);
821 vop_strategy(struct vop_ops *ops, struct vnode *vp, struct bio *bio)
823 struct vop_strategy_args ap;
827 ap.a_head.a_desc = &vop_strategy_desc;
828 ap.a_head.a_ops = ops;
834 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_SG_MPSAFE);
835 DO_OPS(ops, error, &ap, vop_strategy);
836 VFS_MPUNLOCK(vp->v_mount);
838 /* ugly hack for swap */
840 DO_OPS(ops, error, &ap, vop_strategy);
850 vop_print(struct vop_ops *ops, struct vnode *vp)
852 struct vop_print_args ap;
856 ap.a_head.a_desc = &vop_print_desc;
857 ap.a_head.a_ops = ops;
860 VFS_MPLOCK1(vp->v_mount);
861 DO_OPS(ops, error, &ap, vop_print);
862 VFS_MPUNLOCK(vp->v_mount);
870 vop_pathconf(struct vop_ops *ops, struct vnode *vp, int name,
873 struct vop_pathconf_args ap;
877 ap.a_head.a_desc = &vop_pathconf_desc;
878 ap.a_head.a_ops = ops;
881 ap.a_retval = retval;
883 VFS_MPLOCK1(vp->v_mount);
884 DO_OPS(ops, error, &ap, vop_pathconf);
885 VFS_MPUNLOCK(vp->v_mount);
893 vop_advlock(struct vop_ops *ops, struct vnode *vp, caddr_t id, int op,
894 struct flock *fl, int flags)
896 struct vop_advlock_args ap;
900 ap.a_head.a_desc = &vop_advlock_desc;
901 ap.a_head.a_ops = ops;
908 VFS_MPLOCK1(vp->v_mount);
909 DO_OPS(ops, error, &ap, vop_advlock);
910 VFS_MPUNLOCK(vp->v_mount);
918 vop_balloc(struct vop_ops *ops, struct vnode *vp, off_t startoffset,
919 int size, struct ucred *cred, int flags,
922 struct vop_balloc_args ap;
926 ap.a_head.a_desc = &vop_balloc_desc;
927 ap.a_head.a_ops = ops;
929 ap.a_startoffset = startoffset;
935 VFS_MPLOCK1(vp->v_mount);
936 DO_OPS(ops, error, &ap, vop_balloc);
937 VFS_MPUNLOCK(vp->v_mount);
945 vop_reallocblks(struct vop_ops *ops, struct vnode *vp,
946 struct cluster_save *buflist)
948 struct vop_reallocblks_args ap;
952 ap.a_head.a_desc = &vop_reallocblks_desc;
953 ap.a_head.a_ops = ops;
955 ap.a_buflist = buflist;
957 VFS_MPLOCK1(vp->v_mount);
958 DO_OPS(ops, error, &ap, vop_reallocblks);
959 VFS_MPUNLOCK(vp->v_mount);
967 vop_getpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
968 int reqpage, vm_ooffset_t offset, int seqaccess)
970 struct vop_getpages_args ap;
974 ap.a_head.a_desc = &vop_getpages_desc;
975 ap.a_head.a_ops = ops;
979 ap.a_reqpage = reqpage;
980 ap.a_offset = offset;
981 ap.a_seqaccess = seqaccess;
983 VFS_MPLOCK1(vp->v_mount);
984 DO_OPS(ops, error, &ap, vop_getpages);
985 VFS_MPUNLOCK(vp->v_mount);
993 vop_putpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
994 int sync, int *rtvals, vm_ooffset_t offset)
996 struct vop_putpages_args ap;
1000 ap.a_head.a_desc = &vop_putpages_desc;
1001 ap.a_head.a_ops = ops;
1006 ap.a_rtvals = rtvals;
1007 ap.a_offset = offset;
1009 VFS_MPLOCK1(vp->v_mount);
1010 DO_OPS(ops, error, &ap, vop_putpages);
1011 VFS_MPUNLOCK(vp->v_mount);
1019 vop_freeblks(struct vop_ops *ops, struct vnode *vp, off_t offset, int length)
1021 struct vop_freeblks_args ap;
1025 ap.a_head.a_desc = &vop_freeblks_desc;
1026 ap.a_head.a_ops = ops;
1028 ap.a_offset = offset;
1029 ap.a_length = length;
1031 VFS_MPLOCK1(vp->v_mount);
1032 DO_OPS(ops, error, &ap, vop_freeblks);
1033 VFS_MPUNLOCK(vp->v_mount);
1041 vop_getacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1042 struct acl *aclp, struct ucred *cred)
1044 struct vop_getacl_args ap;
1048 ap.a_head.a_desc = &vop_getacl_desc;
1049 ap.a_head.a_ops = ops;
1055 VFS_MPLOCK1(vp->v_mount);
1056 DO_OPS(ops, error, &ap, vop_getacl);
1057 VFS_MPUNLOCK(vp->v_mount);
1065 vop_setacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1066 struct acl *aclp, struct ucred *cred)
1068 struct vop_setacl_args ap;
1072 ap.a_head.a_desc = &vop_setacl_desc;
1073 ap.a_head.a_ops = ops;
1079 VFS_MPLOCK1(vp->v_mount);
1080 DO_OPS(ops, error, &ap, vop_setacl);
1081 VFS_MPUNLOCK(vp->v_mount);
1089 vop_aclcheck(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1090 struct acl *aclp, struct ucred *cred)
1092 struct vop_aclcheck_args ap;
1096 ap.a_head.a_desc = &vop_aclcheck_desc;
1097 ap.a_head.a_ops = ops;
1103 VFS_MPLOCK1(vp->v_mount);
1104 DO_OPS(ops, error, &ap, vop_aclcheck);
1105 VFS_MPUNLOCK(vp->v_mount);
1113 vop_getextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1114 char *attrname, struct uio *uio, struct ucred *cred)
1116 struct vop_getextattr_args ap;
1120 ap.a_head.a_desc = &vop_getextattr_desc;
1121 ap.a_head.a_ops = ops;
1123 ap.a_attrnamespace = attrnamespace;
1124 ap.a_attrname = attrname;
1128 VFS_MPLOCK1(vp->v_mount);
1129 DO_OPS(ops, error, &ap, vop_getextattr);
1130 VFS_MPUNLOCK(vp->v_mount);
1138 vop_setextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1139 char *attrname, struct uio *uio, struct ucred *cred)
1141 struct vop_setextattr_args ap;
1145 ap.a_head.a_desc = &vop_setextattr_desc;
1146 ap.a_head.a_ops = ops;
1148 ap.a_attrnamespace = attrnamespace;
1149 ap.a_attrname = attrname;
1153 VFS_MPLOCK1(vp->v_mount);
1154 DO_OPS(ops, error, &ap, vop_setextattr);
1155 VFS_MPUNLOCK(vp->v_mount);
1163 vop_mountctl(struct vop_ops *ops, struct vnode *vp, int op, struct file *fp,
1164 const void *ctl, int ctllen, void *buf, int buflen, int *res)
1166 struct vop_mountctl_args ap;
1170 ap.a_head.a_desc = &vop_mountctl_desc;
1171 ap.a_head.a_ops = ops;
1175 ap.a_ctllen = ctllen;
1177 ap.a_buflen = buflen;
1180 VFS_MPLOCK1(vp->v_mount);
1181 DO_OPS(ops, error, &ap, vop_mountctl);
1182 VFS_MPUNLOCK(vp->v_mount);
1190 vop_markatime(struct vop_ops *ops, struct vnode *vp, struct ucred *cred)
1192 struct vop_markatime_args ap;
1196 ap.a_head.a_desc = &vop_markatime_desc;
1197 ap.a_head.a_ops = ops;
1201 VFS_MPLOCK1(vp->v_mount);
1202 DO_OPS(ops, error, &ap, vop_markatime);
1203 VFS_MPUNLOCK(vp->v_mount);
1210 * nresolve takes a locked ncp, a referenced but unlocked dvp, and a cred,
1211 * and resolves the ncp into a positive or negative hit.
1213 * The namecache is automatically adjusted by this function. The ncp
1214 * is left locked on return.
1219 vop_nresolve(struct vop_ops *ops, struct nchandle *nch,
1220 struct vnode *dvp, struct ucred *cred)
1222 struct vop_nresolve_args ap;
1226 ap.a_head.a_desc = &vop_nresolve_desc;
1227 ap.a_head.a_ops = ops;
1232 VFS_MPLOCK1(dvp->v_mount);
1233 DO_OPS(ops, error, &ap, vop_nresolve);
1234 VFS_MPUNLOCK(dvp->v_mount);
1239 * nlookupdotdot takes an unlocked directory, referenced dvp, and looks
1240 * up "..", returning a locked parent directory in *vpp. If an error
1241 * occurs *vpp will be NULL.
1246 vop_nlookupdotdot(struct vop_ops *ops, struct vnode *dvp,
1247 struct vnode **vpp, struct ucred *cred, char **fakename)
1249 struct vop_nlookupdotdot_args ap;
1253 ap.a_head.a_desc = &vop_nlookupdotdot_desc;
1254 ap.a_head.a_ops = ops;
1258 ap.a_fakename = fakename;
1260 VFS_MPLOCK1(dvp->v_mount);
1261 DO_OPS(ops, error, &ap, vop_nlookupdotdot);
1262 VFS_MPUNLOCK(dvp->v_mount);
1267 * ncreate takes a locked, resolved ncp that typically represents a negative
1268 * cache hit and creates the file or node specified by the ncp, cred, and
1269 * vattr. If no error occurs a locked vnode is returned in *vpp.
1271 * The dvp passed in is referenced but unlocked.
1273 * The namecache is automatically adjusted by this function. The ncp
1274 * is left locked on return.
1279 vop_ncreate(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1280 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1282 struct vop_ncreate_args ap;
1286 ap.a_head.a_desc = &vop_ncreate_desc;
1287 ap.a_head.a_ops = ops;
1294 VFS_MPLOCK1(dvp->v_mount);
1295 DO_OPS(ops, error, &ap, vop_ncreate);
1296 VFS_MPUNLOCK(dvp->v_mount);
1301 * nmkdir takes a locked, resolved ncp that typically represents a negative
1302 * cache hit and creates the directory specified by the ncp, cred, and
1303 * vattr. If no error occurs a locked vnode is returned in *vpp.
1305 * The dvp passed in is referenced but unlocked.
1307 * The namecache is automatically adjusted by this function. The ncp
1308 * is left locked on return.
1313 vop_nmkdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1314 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1316 struct vop_nmkdir_args ap;
1320 ap.a_head.a_desc = &vop_nmkdir_desc;
1321 ap.a_head.a_ops = ops;
1328 VFS_MPLOCK1(dvp->v_mount);
1329 DO_OPS(ops, error, &ap, vop_nmkdir);
1330 VFS_MPUNLOCK(dvp->v_mount);
1335 * nmknod takes a locked, resolved ncp that typically represents a negative
1336 * cache hit and creates the node specified by the ncp, cred, and
1337 * vattr. If no error occurs a locked vnode is returned in *vpp.
1339 * The dvp passed in is referenced but unlocked.
1341 * The namecache is automatically adjusted by this function. The ncp
1342 * is left locked on return.
1347 vop_nmknod(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1348 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1350 struct vop_nmknod_args ap;
1354 ap.a_head.a_desc = &vop_nmknod_desc;
1355 ap.a_head.a_ops = ops;
1362 VFS_MPLOCK1(dvp->v_mount);
1363 DO_OPS(ops, error, &ap, vop_nmknod);
1364 VFS_MPUNLOCK(dvp->v_mount);
1369 * nlink takes a locked, resolved ncp that typically represents a negative
1370 * cache hit and creates the node specified by the ncp, cred, and
1371 * existing vnode. The passed vp must be locked and will remain locked
1372 * on return, as does the ncp, whether an error occurs or not.
1374 * The dvp passed in is referenced but unlocked.
1376 * The namecache is automatically adjusted by this function. The ncp
1377 * is left locked on return.
1382 vop_nlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1383 struct vnode *vp, struct ucred *cred)
1385 struct vop_nlink_args ap;
1389 ap.a_head.a_desc = &vop_nlink_desc;
1390 ap.a_head.a_ops = ops;
1396 VFS_MPLOCK1(dvp->v_mount);
1397 DO_OPS(ops, error, &ap, vop_nlink);
1398 VFS_MPUNLOCK(dvp->v_mount);
1403 * nsymlink takes a locked, resolved ncp that typically represents a negative
1404 * cache hit and creates a symbolic link based on cred, vap, and target (the
1405 * contents of the link). If no error occurs a locked vnode is returned in
1408 * The dvp passed in is referenced but unlocked.
1410 * The namecache is automatically adjusted by this function. The ncp
1411 * is left locked on return.
1416 vop_nsymlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1417 struct vnode **vpp, struct ucred *cred,
1418 struct vattr *vap, char *target)
1420 struct vop_nsymlink_args ap;
1424 ap.a_head.a_desc = &vop_nsymlink_desc;
1425 ap.a_head.a_ops = ops;
1431 ap.a_target = target;
1433 VFS_MPLOCK1(dvp->v_mount);
1434 DO_OPS(ops, error, &ap, vop_nsymlink);
1435 VFS_MPUNLOCK(dvp->v_mount);
1440 * nwhiteout takes a locked, resolved ncp that can represent a positive or
1441 * negative hit and executes the whiteout function specified in flags.
1443 * The dvp passed in is referenced but unlocked.
1445 * The namecache is automatically adjusted by this function. The ncp
1446 * is left locked on return.
1451 vop_nwhiteout(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1452 struct ucred *cred, int flags)
1454 struct vop_nwhiteout_args ap;
1458 ap.a_head.a_desc = &vop_nwhiteout_desc;
1459 ap.a_head.a_ops = ops;
1465 VFS_MPLOCK1(dvp->v_mount);
1466 DO_OPS(ops, error, &ap, vop_nwhiteout);
1467 VFS_MPUNLOCK(dvp->v_mount);
1472 * nremove takes a locked, resolved ncp that generally represents a
1473 * positive hit and removes the file.
1475 * The dvp passed in is referenced but unlocked.
1477 * The namecache is automatically adjusted by this function. The ncp
1478 * is left locked on return.
1483 vop_nremove(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1486 struct vop_nremove_args ap;
1490 ap.a_head.a_desc = &vop_nremove_desc;
1491 ap.a_head.a_ops = ops;
1496 VFS_MPLOCK1(dvp->v_mount);
1497 DO_OPS(ops, error, &ap, vop_nremove);
1498 VFS_MPUNLOCK(dvp->v_mount);
1503 * nrmdir takes a locked, resolved ncp that generally represents a
1504 * directory and removes the directory.
1506 * The dvp passed in is referenced but unlocked.
1508 * The namecache is automatically adjusted by this function. The ncp
1509 * is left locked on return.
1514 vop_nrmdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1517 struct vop_nrmdir_args ap;
1521 ap.a_head.a_desc = &vop_nrmdir_desc;
1522 ap.a_head.a_ops = ops;
1527 VFS_MPLOCK1(dvp->v_mount);
1528 DO_OPS(ops, error, &ap, vop_nrmdir);
1529 VFS_MPUNLOCK(dvp->v_mount);
1534 * nrename takes TWO locked, resolved ncp's and the cred of the caller
1535 * and renames the source ncp to the target ncp. The target ncp may
1536 * represent a positive or negative hit.
1538 * The fdvp and tdvp passed in are referenced but unlocked.
1540 * The namecache is automatically adjusted by this function. The ncp
1541 * is left locked on return. The source ncp is typically changed to
1542 * a negative cache hit and the target ncp typically takes on the
1543 * source ncp's underlying file.
1548 vop_nrename(struct vop_ops *ops,
1549 struct nchandle *fnch, struct nchandle *tnch,
1550 struct vnode *fdvp, struct vnode *tdvp,
1553 struct vop_nrename_args ap;
1557 ap.a_head.a_desc = &vop_nrename_desc;
1558 ap.a_head.a_ops = ops;
1565 VFS_MPLOCK1(fdvp->v_mount);
1566 DO_OPS(ops, error, &ap, vop_nrename);
1567 VFS_MPUNLOCK(fdvp->v_mount);
1571 /************************************************************************
1572 * PRIMARY VNODE OPERATIONS FORWARDING CALLS *
1573 ************************************************************************
1575 * These procedures are called from VFSs such as unionfs and nullfs
1576 * when they wish to forward an operation on one VFS to another. The
1577 * argument structure/message is modified and then directly passed to the
1578 * appropriate routine. This routines may also be called by initiators
1579 * who have an argument structure in hand rather then discreet arguments.
1581 * MPSAFE - Caller expected to already hold the appropriate vfs lock.
1584 vop_vnoperate_ap(struct vop_generic_args *ap)
1586 struct vop_ops *ops;
1590 error = VOCALL(ops, ap);
1596 * This routine is called by the cache coherency layer to execute the actual
1597 * VFS operation. If a journaling layer is present we call though it, else
1598 * we call the native VOP functions.
1601 vop_cache_operate_ap(struct vop_generic_args *ap)
1603 struct vop_ops *ops;
1607 if (ops->head.vv_mount->mnt_vn_journal_ops)
1608 error = VOCALL(ops->head.vv_mount->mnt_vn_journal_ops, ap);
1610 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1616 * This routine is called by the journaling layer to execute the actual
1620 vop_journal_operate_ap(struct vop_generic_args *ap)
1622 struct vop_ops *ops;
1626 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1632 vop_open_ap(struct vop_open_args *ap)
1636 DO_OPS(ap->a_head.a_ops, error, ap, vop_open);
1641 vop_close_ap(struct vop_close_args *ap)
1645 DO_OPS(ap->a_head.a_ops, error, ap, vop_close);
1650 vop_access_ap(struct vop_access_args *ap)
1654 DO_OPS(ap->a_head.a_ops, error, ap, vop_access);
1659 vop_getattr_ap(struct vop_getattr_args *ap)
1663 DO_OPS(ap->a_head.a_ops, error, ap, vop_getattr);
1668 vop_setattr_ap(struct vop_setattr_args *ap)
1672 DO_OPS(ap->a_head.a_ops, error, ap, vop_setattr);
1677 vop_read_ap(struct vop_read_args *ap)
1681 DO_OPS(ap->a_head.a_ops, error, ap, vop_read);
1686 vop_write_ap(struct vop_write_args *ap)
1690 DO_OPS(ap->a_head.a_ops, error, ap, vop_write);
1695 vop_ioctl_ap(struct vop_ioctl_args *ap)
1699 DO_OPS(ap->a_head.a_ops, error, ap, vop_ioctl);
1704 vop_poll_ap(struct vop_poll_args *ap)
1708 DO_OPS(ap->a_head.a_ops, error, ap, vop_poll);
1713 vop_kqfilter_ap(struct vop_kqfilter_args *ap)
1717 DO_OPS(ap->a_head.a_ops, error, ap, vop_kqfilter);
1722 vop_mmap_ap(struct vop_mmap_args *ap)
1726 DO_OPS(ap->a_head.a_ops, error, ap, vop_mmap);
1731 vop_fsync_ap(struct vop_fsync_args *ap)
1735 DO_OPS(ap->a_head.a_ops, error, ap, vop_fsync);
1740 vop_readdir_ap(struct vop_readdir_args *ap)
1744 DO_OPS(ap->a_head.a_ops, error, ap, vop_readdir);
1749 vop_readlink_ap(struct vop_readlink_args *ap)
1753 DO_OPS(ap->a_head.a_ops, error, ap, vop_readlink);
1758 vop_inactive_ap(struct vop_inactive_args *ap)
1762 DO_OPS(ap->a_head.a_ops, error, ap, vop_inactive);
1767 vop_reclaim_ap(struct vop_reclaim_args *ap)
1771 DO_OPS(ap->a_head.a_ops, error, ap, vop_reclaim);
1776 vop_bmap_ap(struct vop_bmap_args *ap)
1780 DO_OPS(ap->a_head.a_ops, error, ap, vop_bmap);
1785 vop_strategy_ap(struct vop_strategy_args *ap)
1789 DO_OPS(ap->a_head.a_ops, error, ap, vop_strategy);
1794 vop_print_ap(struct vop_print_args *ap)
1798 DO_OPS(ap->a_head.a_ops, error, ap, vop_print);
1803 vop_pathconf_ap(struct vop_pathconf_args *ap)
1807 DO_OPS(ap->a_head.a_ops, error, ap, vop_pathconf);
1812 vop_advlock_ap(struct vop_advlock_args *ap)
1816 DO_OPS(ap->a_head.a_ops, error, ap, vop_advlock);
1821 vop_balloc_ap(struct vop_balloc_args *ap)
1825 DO_OPS(ap->a_head.a_ops, error, ap, vop_balloc);
1830 vop_reallocblks_ap(struct vop_reallocblks_args *ap)
1834 DO_OPS(ap->a_head.a_ops, error, ap, vop_reallocblks);
1839 vop_getpages_ap(struct vop_getpages_args *ap)
1843 DO_OPS(ap->a_head.a_ops, error, ap, vop_getpages);
1848 vop_putpages_ap(struct vop_putpages_args *ap)
1852 DO_OPS(ap->a_head.a_ops, error, ap, vop_putpages);
1857 vop_freeblks_ap(struct vop_freeblks_args *ap)
1861 DO_OPS(ap->a_head.a_ops, error, ap, vop_freeblks);
1866 vop_getacl_ap(struct vop_getacl_args *ap)
1870 DO_OPS(ap->a_head.a_ops, error, ap, vop_getacl);
1875 vop_setacl_ap(struct vop_setacl_args *ap)
1879 DO_OPS(ap->a_head.a_ops, error, ap, vop_setacl);
1884 vop_aclcheck_ap(struct vop_aclcheck_args *ap)
1888 DO_OPS(ap->a_head.a_ops, error, ap, vop_aclcheck);
1893 vop_getextattr_ap(struct vop_getextattr_args *ap)
1897 DO_OPS(ap->a_head.a_ops, error, ap, vop_getextattr);
1902 vop_setextattr_ap(struct vop_setextattr_args *ap)
1906 DO_OPS(ap->a_head.a_ops, error, ap, vop_setextattr);
1911 vop_mountctl_ap(struct vop_mountctl_args *ap)
1915 DO_OPS(ap->a_head.a_ops, error, ap, vop_mountctl);
1920 vop_markatime_ap(struct vop_markatime_args *ap)
1924 DO_OPS(ap->a_head.a_ops, error, ap, vop_markatime);
1929 vop_nresolve_ap(struct vop_nresolve_args *ap)
1933 DO_OPS(ap->a_head.a_ops, error, ap, vop_nresolve);
1938 vop_nlookupdotdot_ap(struct vop_nlookupdotdot_args *ap)
1942 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlookupdotdot);
1947 vop_ncreate_ap(struct vop_ncreate_args *ap)
1951 DO_OPS(ap->a_head.a_ops, error, ap, vop_ncreate);
1956 vop_nmkdir_ap(struct vop_nmkdir_args *ap)
1960 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmkdir);
1965 vop_nmknod_ap(struct vop_nmknod_args *ap)
1969 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmknod);
1974 vop_nlink_ap(struct vop_nlink_args *ap)
1978 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlink);
1983 vop_nsymlink_ap(struct vop_nsymlink_args *ap)
1987 DO_OPS(ap->a_head.a_ops, error, ap, vop_nsymlink);
1992 vop_nwhiteout_ap(struct vop_nwhiteout_args *ap)
1996 DO_OPS(ap->a_head.a_ops, error, ap, vop_nwhiteout);
2001 vop_nremove_ap(struct vop_nremove_args *ap)
2005 DO_OPS(ap->a_head.a_ops, error, ap, vop_nremove);
2010 vop_nrmdir_ap(struct vop_nrmdir_args *ap)
2014 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrmdir);
2019 vop_nrename_ap(struct vop_nrename_args *ap)
2023 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrename);