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/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() macro handle mounts which do not set MNTK_MPSAFE.
170 vop_old_lookup(struct vop_ops *ops, struct vnode *dvp,
171 struct vnode **vpp, struct componentname *cnp)
173 struct vop_old_lookup_args ap;
177 ap.a_head.a_desc = &vop_old_lookup_desc;
178 ap.a_head.a_ops = ops;
182 VFS_MPLOCK(dvp->v_mount);
183 DO_OPS(ops, error, &ap, vop_old_lookup);
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_MPLOCK(dvp->v_mount);
208 DO_OPS(ops, error, &ap, vop_old_create);
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_MPLOCK(dvp->v_mount);
232 DO_OPS(ops, error, &ap, vop_old_whiteout);
242 vop_old_mknod(struct vop_ops *ops, struct vnode *dvp,
243 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
245 struct vop_old_mknod_args ap;
249 ap.a_head.a_desc = &vop_old_mknod_desc;
250 ap.a_head.a_ops = ops;
256 VFS_MPLOCK(dvp->v_mount);
257 DO_OPS(ops, error, &ap, vop_old_mknod);
264 * NOTE: VAGE is always cleared when calling VOP_OPEN().
267 vop_open(struct vop_ops *ops, struct vnode *vp, int mode, struct ucred *cred,
270 struct vop_open_args ap;
275 * Decrement 3-2-1-0. Does not decrement beyond 0
277 if (vp->v_flag & VAGE0) {
278 vclrflags(vp, VAGE0);
279 } else if (vp->v_flag & VAGE1) {
280 vclrflags(vp, VAGE1);
281 vsetflags(vp, VAGE0);
284 ap.a_head.a_desc = &vop_open_desc;
285 ap.a_head.a_ops = ops;
291 VFS_MPLOCK(vp->v_mount);
292 DO_OPS(ops, error, &ap, vop_open);
302 vop_close(struct vop_ops *ops, struct vnode *vp, int fflag,
305 struct vop_close_args ap;
309 ap.a_head.a_desc = &vop_close_desc;
310 ap.a_head.a_ops = ops;
315 VFS_MPLOCK(vp->v_mount);
316 DO_OPS(ops, error, &ap, vop_close);
326 vop_access(struct vop_ops *ops, struct vnode *vp, int mode, int flags,
329 struct vop_access_args ap;
333 ap.a_head.a_desc = &vop_access_desc;
334 ap.a_head.a_ops = ops;
340 VFS_MPLOCK(vp->v_mount);
341 DO_OPS(ops, error, &ap, vop_access);
351 vop_getattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap,
354 struct vop_getattr_args ap;
358 ap.a_head.a_desc = &vop_getattr_desc;
359 ap.a_head.a_ops = ops;
364 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_GA_MPSAFE);
365 DO_OPS(ops, error, &ap, vop_getattr);
375 vop_setattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap,
376 struct ucred *cred, struct file *fp)
378 struct vop_setattr_args ap;
382 ap.a_head.a_desc = &vop_setattr_desc;
383 ap.a_head.a_ops = ops;
389 VFS_MPLOCK(vp->v_mount);
390 DO_OPS(ops, error, &ap, vop_setattr);
400 vop_read(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
401 struct ucred *cred, struct file *fp)
403 struct vop_read_args ap;
407 ap.a_head.a_desc = &vop_read_desc;
408 ap.a_head.a_ops = ops;
411 ap.a_ioflag = ioflag;
415 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_RD_MPSAFE);
416 DO_OPS(ops, error, &ap, vop_read);
426 vop_write(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
427 struct ucred *cred, struct file *fp)
429 struct vop_write_args ap;
431 int error, do_accounting = 0;
433 uint64_t size_before=0, size_after=0;
435 uint64_t offset, delta;
437 ap.a_head.a_desc = &vop_write_desc;
438 ap.a_head.a_ops = ops;
441 ap.a_ioflag = ioflag;
445 /* is this a regular vnode ? */
446 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_WR_MPSAFE);
447 if (vfs_quota_enabled && (vp->v_type == VREG)) {
448 if ((error = VOP_GETATTR(vp, &va)) != 0)
450 size_before = va.va_size;
451 /* this file may already have been removed */
455 offset = uio->uio_offset;
456 if (ioflag & IO_APPEND)
457 offset = size_before;
458 size_after = offset + uio->uio_resid;
459 if (size_after < size_before)
460 size_after = size_before;
461 delta = size_after - size_before;
464 if (!vq_write_ok(mp, va.va_uid, va.va_gid, delta)) {
469 DO_OPS(ops, error, &ap, vop_write);
470 if ((error == 0) && do_accounting) {
471 VFS_ACCOUNT(mp, va.va_uid, va.va_gid, size_after - size_before);
483 vop_ioctl(struct vop_ops *ops, struct vnode *vp, u_long command, caddr_t data,
484 int fflag, struct ucred *cred, struct sysmsg *msg)
486 struct vop_ioctl_args ap;
490 ap.a_head.a_desc = &vop_ioctl_desc;
491 ap.a_head.a_ops = ops;
493 ap.a_command = command;
499 VFS_MPLOCK(vp->v_mount);
500 DO_OPS(ops, error, &ap, vop_ioctl);
510 vop_poll(struct vop_ops *ops, struct vnode *vp, int events, struct ucred *cred)
512 struct vop_poll_args ap;
516 ap.a_head.a_desc = &vop_poll_desc;
517 ap.a_head.a_ops = ops;
519 ap.a_events = events;
522 VFS_MPLOCK(vp->v_mount);
523 DO_OPS(ops, error, &ap, vop_poll);
533 vop_kqfilter(struct vop_ops *ops, struct vnode *vp, struct knote *kn)
535 struct vop_kqfilter_args ap;
539 ap.a_head.a_desc = &vop_kqfilter_desc;
540 ap.a_head.a_ops = ops;
544 VFS_MPLOCK(vp->v_mount);
545 DO_OPS(ops, error, &ap, vop_kqfilter);
555 vop_mmap(struct vop_ops *ops, struct vnode *vp, int fflags, struct ucred *cred)
557 struct vop_mmap_args ap;
561 ap.a_head.a_desc = &vop_mmap_desc;
562 ap.a_head.a_ops = ops;
564 ap.a_fflags = fflags;
567 VFS_MPLOCK(vp->v_mount);
568 DO_OPS(ops, error, &ap, vop_mmap);
578 vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor, int flags,
581 struct vop_fsync_args ap;
585 ap.a_head.a_desc = &vop_fsync_desc;
586 ap.a_head.a_ops = ops;
588 ap.a_waitfor = waitfor;
592 VFS_MPLOCK(vp->v_mount);
593 DO_OPS(ops, error, &ap, vop_fsync);
603 vop_old_remove(struct vop_ops *ops, struct vnode *dvp,
604 struct vnode *vp, struct componentname *cnp)
606 struct vop_old_remove_args ap;
610 ap.a_head.a_desc = &vop_old_remove_desc;
611 ap.a_head.a_ops = ops;
616 VFS_MPLOCK(dvp->v_mount);
617 DO_OPS(ops, error, &ap, vop_old_remove);
627 vop_old_link(struct vop_ops *ops, struct vnode *tdvp,
628 struct vnode *vp, struct componentname *cnp)
630 struct vop_old_link_args ap;
634 ap.a_head.a_desc = &vop_old_link_desc;
635 ap.a_head.a_ops = ops;
640 VFS_MPLOCK(tdvp->v_mount);
641 DO_OPS(ops, error, &ap, vop_old_link);
651 vop_old_rename(struct vop_ops *ops,
652 struct vnode *fdvp, struct vnode *fvp, struct componentname *fcnp,
653 struct vnode *tdvp, struct vnode *tvp, struct componentname *tcnp)
655 struct vop_old_rename_args ap;
659 ap.a_head.a_desc = &vop_old_rename_desc;
660 ap.a_head.a_ops = ops;
668 VFS_MPLOCK(tdvp->v_mount);
669 DO_OPS(ops, error, &ap, vop_old_rename);
679 vop_old_mkdir(struct vop_ops *ops, struct vnode *dvp,
680 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
682 struct vop_old_mkdir_args ap;
686 ap.a_head.a_desc = &vop_old_mkdir_desc;
687 ap.a_head.a_ops = ops;
693 VFS_MPLOCK(dvp->v_mount);
694 DO_OPS(ops, error, &ap, vop_old_mkdir);
704 vop_old_rmdir(struct vop_ops *ops, struct vnode *dvp,
705 struct vnode *vp, struct componentname *cnp)
707 struct vop_old_rmdir_args ap;
711 ap.a_head.a_desc = &vop_old_rmdir_desc;
712 ap.a_head.a_ops = ops;
717 VFS_MPLOCK(dvp->v_mount);
718 DO_OPS(ops, error, &ap, vop_old_rmdir);
728 vop_old_symlink(struct vop_ops *ops, struct vnode *dvp,
729 struct vnode **vpp, struct componentname *cnp,
730 struct vattr *vap, char *target)
732 struct vop_old_symlink_args ap;
736 ap.a_head.a_desc = &vop_old_symlink_desc;
737 ap.a_head.a_ops = ops;
742 ap.a_target = target;
744 VFS_MPLOCK(dvp->v_mount);
745 DO_OPS(ops, error, &ap, vop_old_symlink);
755 vop_readdir(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
756 struct ucred *cred, int *eofflag, int *ncookies, off_t **cookies,
759 struct vop_readdir_args ap;
763 ap.a_head.a_desc = &vop_readdir_desc;
764 ap.a_head.a_ops = ops;
768 ap.a_eofflag = eofflag;
769 ap.a_ncookies = ncookies;
770 ap.a_cookies = cookies;
773 VFS_MPLOCK(vp->v_mount);
774 DO_OPS(ops, error, &ap, vop_readdir);
784 vop_readlink(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
787 struct vop_readlink_args ap;
791 ap.a_head.a_desc = &vop_readlink_desc;
792 ap.a_head.a_ops = ops;
797 VFS_MPLOCK(vp->v_mount);
798 DO_OPS(ops, error, &ap, vop_readlink);
808 vop_inactive(struct vop_ops *ops, struct vnode *vp)
810 struct vop_inactive_args ap;
815 ap.a_head.a_desc = &vop_inactive_desc;
816 ap.a_head.a_ops = ops;
820 * WARNING! Deactivation of the vnode can cause it to be recycled,
821 * clearing vp->v_mount.
824 VFS_MPLOCK_FLAG(mp, MNTK_IN_MPSAFE);
825 DO_OPS(ops, error, &ap, vop_inactive);
835 vop_reclaim(struct vop_ops *ops, struct vnode *vp)
837 struct vop_reclaim_args ap;
842 ap.a_head.a_desc = &vop_reclaim_desc;
843 ap.a_head.a_ops = ops;
847 * WARNING! Reclamation of the vnode will clear vp->v_mount.
851 DO_OPS(ops, error, &ap, vop_reclaim);
861 vop_bmap(struct vop_ops *ops, struct vnode *vp, off_t loffset,
862 off_t *doffsetp, int *runp, int *runb, buf_cmd_t cmd)
864 struct vop_bmap_args ap;
868 ap.a_head.a_desc = &vop_bmap_desc;
869 ap.a_head.a_ops = ops;
871 ap.a_loffset = loffset;
872 ap.a_doffsetp = doffsetp;
877 VFS_MPLOCK(vp->v_mount);
878 DO_OPS(ops, error, &ap, vop_bmap);
885 * WARNING! Vnode can go-away after the ops call (e.g. async flush
886 * from buffer kthread).
889 vop_strategy(struct vop_ops *ops, struct vnode *vp, struct bio *bio)
891 struct vop_strategy_args ap;
895 ap.a_head.a_desc = &vop_strategy_desc;
896 ap.a_head.a_ops = ops;
901 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_SG_MPSAFE);
902 DO_OPS(ops, error, &ap, vop_strategy);
905 /* ugly hack for swap */
907 DO_OPS(ops, error, &ap, vop_strategy);
917 vop_print(struct vop_ops *ops, struct vnode *vp)
919 struct vop_print_args ap;
923 ap.a_head.a_desc = &vop_print_desc;
924 ap.a_head.a_ops = ops;
927 VFS_MPLOCK(vp->v_mount);
928 DO_OPS(ops, error, &ap, vop_print);
938 vop_pathconf(struct vop_ops *ops, struct vnode *vp, int name,
941 struct vop_pathconf_args ap;
945 ap.a_head.a_desc = &vop_pathconf_desc;
946 ap.a_head.a_ops = ops;
949 ap.a_retval = retval;
951 VFS_MPLOCK(vp->v_mount);
952 DO_OPS(ops, error, &ap, vop_pathconf);
962 vop_advlock(struct vop_ops *ops, struct vnode *vp, caddr_t id, int op,
963 struct flock *fl, int flags)
965 struct vop_advlock_args ap;
969 ap.a_head.a_desc = &vop_advlock_desc;
970 ap.a_head.a_ops = ops;
977 VFS_MPLOCK(vp->v_mount);
978 DO_OPS(ops, error, &ap, vop_advlock);
988 vop_balloc(struct vop_ops *ops, struct vnode *vp, off_t startoffset,
989 int size, struct ucred *cred, int flags,
992 struct vop_balloc_args ap;
996 ap.a_head.a_desc = &vop_balloc_desc;
997 ap.a_head.a_ops = ops;
999 ap.a_startoffset = startoffset;
1005 VFS_MPLOCK(vp->v_mount);
1006 DO_OPS(ops, error, &ap, vop_balloc);
1016 vop_reallocblks(struct vop_ops *ops, struct vnode *vp,
1017 struct cluster_save *buflist)
1019 struct vop_reallocblks_args ap;
1023 ap.a_head.a_desc = &vop_reallocblks_desc;
1024 ap.a_head.a_ops = ops;
1026 ap.a_buflist = buflist;
1028 VFS_MPLOCK(vp->v_mount);
1029 DO_OPS(ops, error, &ap, vop_reallocblks);
1039 vop_getpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
1040 int reqpage, vm_ooffset_t offset, int seqaccess)
1042 struct vop_getpages_args ap;
1046 ap.a_head.a_desc = &vop_getpages_desc;
1047 ap.a_head.a_ops = ops;
1051 ap.a_reqpage = reqpage;
1052 ap.a_offset = offset;
1053 ap.a_seqaccess = seqaccess;
1055 VFS_MPLOCK(vp->v_mount);
1056 DO_OPS(ops, error, &ap, vop_getpages);
1066 vop_putpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
1067 int sync, int *rtvals, vm_ooffset_t offset)
1069 struct vop_putpages_args ap;
1073 ap.a_head.a_desc = &vop_putpages_desc;
1074 ap.a_head.a_ops = ops;
1079 ap.a_rtvals = rtvals;
1080 ap.a_offset = offset;
1082 VFS_MPLOCK(vp->v_mount);
1083 DO_OPS(ops, error, &ap, vop_putpages);
1093 vop_freeblks(struct vop_ops *ops, struct vnode *vp, off_t offset, int length)
1095 struct vop_freeblks_args ap;
1099 ap.a_head.a_desc = &vop_freeblks_desc;
1100 ap.a_head.a_ops = ops;
1102 ap.a_offset = offset;
1103 ap.a_length = length;
1105 VFS_MPLOCK(vp->v_mount);
1106 DO_OPS(ops, error, &ap, vop_freeblks);
1116 vop_getacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1117 struct acl *aclp, struct ucred *cred)
1119 struct vop_getacl_args ap;
1123 ap.a_head.a_desc = &vop_getacl_desc;
1124 ap.a_head.a_ops = ops;
1130 VFS_MPLOCK(vp->v_mount);
1131 DO_OPS(ops, error, &ap, vop_getacl);
1141 vop_setacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1142 struct acl *aclp, struct ucred *cred)
1144 struct vop_setacl_args ap;
1148 ap.a_head.a_desc = &vop_setacl_desc;
1149 ap.a_head.a_ops = ops;
1155 VFS_MPLOCK(vp->v_mount);
1156 DO_OPS(ops, error, &ap, vop_setacl);
1166 vop_aclcheck(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1167 struct acl *aclp, struct ucred *cred)
1169 struct vop_aclcheck_args ap;
1173 ap.a_head.a_desc = &vop_aclcheck_desc;
1174 ap.a_head.a_ops = ops;
1180 VFS_MPLOCK(vp->v_mount);
1181 DO_OPS(ops, error, &ap, vop_aclcheck);
1191 vop_getextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1192 char *attrname, struct uio *uio, struct ucred *cred)
1194 struct vop_getextattr_args ap;
1198 ap.a_head.a_desc = &vop_getextattr_desc;
1199 ap.a_head.a_ops = ops;
1201 ap.a_attrnamespace = attrnamespace;
1202 ap.a_attrname = attrname;
1206 VFS_MPLOCK(vp->v_mount);
1207 DO_OPS(ops, error, &ap, vop_getextattr);
1217 vop_setextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1218 char *attrname, struct uio *uio, struct ucred *cred)
1220 struct vop_setextattr_args ap;
1224 ap.a_head.a_desc = &vop_setextattr_desc;
1225 ap.a_head.a_ops = ops;
1227 ap.a_attrnamespace = attrnamespace;
1228 ap.a_attrname = attrname;
1232 VFS_MPLOCK(vp->v_mount);
1233 DO_OPS(ops, error, &ap, vop_setextattr);
1243 vop_mountctl(struct vop_ops *ops, struct vnode *vp, int op, struct file *fp,
1244 const void *ctl, int ctllen, void *buf, int buflen, int *res)
1246 struct vop_mountctl_args ap;
1250 ap.a_head.a_desc = &vop_mountctl_desc;
1251 ap.a_head.a_ops = ops;
1255 ap.a_ctllen = ctllen;
1257 ap.a_buflen = buflen;
1260 VFS_MPLOCK(vp->v_mount);
1261 DO_OPS(ops, error, &ap, vop_mountctl);
1271 vop_markatime(struct vop_ops *ops, struct vnode *vp, struct ucred *cred)
1273 struct vop_markatime_args ap;
1277 ap.a_head.a_desc = &vop_markatime_desc;
1278 ap.a_head.a_ops = ops;
1282 VFS_MPLOCK(vp->v_mount);
1283 DO_OPS(ops, error, &ap, vop_markatime);
1292 * nresolve takes a locked ncp, a referenced but unlocked dvp, and a cred,
1293 * and resolves the ncp into a positive or negative hit.
1295 * The namecache is automatically adjusted by this function. The ncp
1296 * is left locked on return.
1301 vop_nresolve(struct vop_ops *ops, struct nchandle *nch,
1302 struct vnode *dvp, struct ucred *cred)
1304 struct vop_nresolve_args ap;
1308 ap.a_head.a_desc = &vop_nresolve_desc;
1309 ap.a_head.a_ops = ops;
1314 VFS_MPLOCK(dvp->v_mount);
1315 DO_OPS(ops, error, &ap, vop_nresolve);
1322 * nlookupdotdot takes an unlocked directory, referenced dvp, and looks
1323 * up "..", returning a locked parent directory in *vpp. If an error
1324 * occurs *vpp will be NULL.
1329 vop_nlookupdotdot(struct vop_ops *ops, struct vnode *dvp,
1330 struct vnode **vpp, struct ucred *cred, char **fakename)
1332 struct vop_nlookupdotdot_args ap;
1336 ap.a_head.a_desc = &vop_nlookupdotdot_desc;
1337 ap.a_head.a_ops = ops;
1341 ap.a_fakename = fakename;
1343 VFS_MPLOCK(dvp->v_mount);
1344 DO_OPS(ops, error, &ap, vop_nlookupdotdot);
1351 * ncreate takes a locked, resolved ncp that typically represents a negative
1352 * cache hit and creates the file or node specified by the ncp, cred, and
1353 * vattr. If no error occurs a locked vnode is returned in *vpp.
1355 * The dvp passed in is referenced but unlocked.
1357 * The namecache is automatically adjusted by this function. The ncp
1358 * is left locked on return.
1363 vop_ncreate(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1364 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1366 struct vop_ncreate_args ap;
1370 ap.a_head.a_desc = &vop_ncreate_desc;
1371 ap.a_head.a_ops = ops;
1378 VFS_MPLOCK(dvp->v_mount);
1379 DO_OPS(ops, error, &ap, vop_ncreate);
1386 * nmkdir takes a locked, resolved ncp that typically represents a negative
1387 * cache hit and creates the directory specified by the ncp, cred, and
1388 * vattr. If no error occurs a locked vnode is returned in *vpp.
1390 * The dvp passed in is referenced but unlocked.
1392 * The namecache is automatically adjusted by this function. The ncp
1393 * is left locked on return.
1398 vop_nmkdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1399 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1401 struct vop_nmkdir_args ap;
1405 ap.a_head.a_desc = &vop_nmkdir_desc;
1406 ap.a_head.a_ops = ops;
1413 VFS_MPLOCK(dvp->v_mount);
1414 DO_OPS(ops, error, &ap, vop_nmkdir);
1421 * nmknod takes a locked, resolved ncp that typically represents a negative
1422 * cache hit and creates the node specified by the ncp, cred, and
1423 * vattr. If no error occurs a locked vnode is returned in *vpp.
1425 * The dvp passed in is referenced but unlocked.
1427 * The namecache is automatically adjusted by this function. The ncp
1428 * is left locked on return.
1433 vop_nmknod(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1434 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1436 struct vop_nmknod_args ap;
1440 ap.a_head.a_desc = &vop_nmknod_desc;
1441 ap.a_head.a_ops = ops;
1448 VFS_MPLOCK(dvp->v_mount);
1449 DO_OPS(ops, error, &ap, vop_nmknod);
1456 * nlink takes a locked, resolved ncp that typically represents a negative
1457 * cache hit and creates the node specified by the ncp, cred, and
1458 * existing vnode. The passed vp must be locked and will remain locked
1459 * on return, as does the ncp, whether an error occurs or not.
1461 * The dvp passed in is referenced but unlocked.
1463 * The namecache is automatically adjusted by this function. The ncp
1464 * is left locked on return.
1469 vop_nlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1470 struct vnode *vp, struct ucred *cred)
1472 struct vop_nlink_args ap;
1476 ap.a_head.a_desc = &vop_nlink_desc;
1477 ap.a_head.a_ops = ops;
1483 VFS_MPLOCK(dvp->v_mount);
1484 DO_OPS(ops, error, &ap, vop_nlink);
1491 * nsymlink takes a locked, resolved ncp that typically represents a negative
1492 * cache hit and creates a symbolic link based on cred, vap, and target (the
1493 * contents of the link). If no error occurs a locked vnode is returned in
1496 * The dvp passed in is referenced but unlocked.
1498 * The namecache is automatically adjusted by this function. The ncp
1499 * is left locked on return.
1504 vop_nsymlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1505 struct vnode **vpp, struct ucred *cred,
1506 struct vattr *vap, char *target)
1508 struct vop_nsymlink_args ap;
1512 ap.a_head.a_desc = &vop_nsymlink_desc;
1513 ap.a_head.a_ops = ops;
1519 ap.a_target = target;
1521 VFS_MPLOCK(dvp->v_mount);
1522 DO_OPS(ops, error, &ap, vop_nsymlink);
1529 * nwhiteout takes a locked, resolved ncp that can represent a positive or
1530 * negative hit and executes the whiteout function specified in flags.
1532 * The dvp passed in is referenced but unlocked.
1534 * The namecache is automatically adjusted by this function. The ncp
1535 * is left locked on return.
1540 vop_nwhiteout(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1541 struct ucred *cred, int flags)
1543 struct vop_nwhiteout_args ap;
1547 ap.a_head.a_desc = &vop_nwhiteout_desc;
1548 ap.a_head.a_ops = ops;
1554 VFS_MPLOCK(dvp->v_mount);
1555 DO_OPS(ops, error, &ap, vop_nwhiteout);
1562 * nremove takes a locked, resolved ncp that generally represents a
1563 * positive hit and removes the file.
1565 * The dvp passed in is referenced but unlocked.
1567 * The namecache is automatically adjusted by this function. The ncp
1568 * is left locked on return.
1573 vop_nremove(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1576 struct vop_nremove_args ap;
1581 ap.a_head.a_desc = &vop_nremove_desc;
1582 ap.a_head.a_ops = ops;
1587 if ((error = VOP_GETATTR(nch->ncp->nc_vp, &va)) != 0)
1590 VFS_MPLOCK(dvp->v_mount);
1591 DO_OPS(ops, error, &ap, vop_nremove);
1592 /* Only update space counters if this is the last hard link */
1593 if ((error == 0) && (va.va_nlink == 1)) {
1594 VFS_ACCOUNT(nch->mount, va.va_uid, va.va_gid, -va.va_size);
1602 * nrmdir takes a locked, resolved ncp that generally represents a
1603 * directory and removes the directory.
1605 * The dvp passed in is referenced but unlocked.
1607 * The namecache is automatically adjusted by this function. The ncp
1608 * is left locked on return.
1613 vop_nrmdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1616 struct vop_nrmdir_args ap;
1620 ap.a_head.a_desc = &vop_nrmdir_desc;
1621 ap.a_head.a_ops = ops;
1626 VFS_MPLOCK(dvp->v_mount);
1627 DO_OPS(ops, error, &ap, vop_nrmdir);
1634 * nrename takes TWO locked, resolved ncp's and the cred of the caller
1635 * and renames the source ncp to the target ncp. The target ncp may
1636 * represent a positive or negative hit.
1638 * The fdvp and tdvp passed in are referenced but unlocked.
1640 * The namecache is automatically adjusted by this function. The ncp
1641 * is left locked on return. The source ncp is typically changed to
1642 * a negative cache hit and the target ncp typically takes on the
1643 * source ncp's underlying file.
1648 vop_nrename(struct vop_ops *ops,
1649 struct nchandle *fnch, struct nchandle *tnch,
1650 struct vnode *fdvp, struct vnode *tdvp,
1653 struct vop_nrename_args ap;
1657 ap.a_head.a_desc = &vop_nrename_desc;
1658 ap.a_head.a_ops = ops;
1665 VFS_MPLOCK(fdvp->v_mount);
1666 DO_OPS(ops, error, &ap, vop_nrename);
1672 /************************************************************************
1673 * PRIMARY VNODE OPERATIONS FORWARDING CALLS *
1674 ************************************************************************
1676 * These procedures are called from VFSs such as nullfs
1677 * when they wish to forward an operation on one VFS to another. The
1678 * argument structure/message is modified and then directly passed to the
1679 * appropriate routine. This routines may also be called by initiators
1680 * who have an argument structure in hand rather then discreet arguments.
1682 * MPSAFE - Caller expected to already hold the appropriate vfs lock.
1685 vop_vnoperate_ap(struct vop_generic_args *ap)
1687 struct vop_ops *ops;
1691 error = VOCALL(ops, ap);
1697 * This routine is called by the cache coherency layer to execute the actual
1698 * VFS operation. If a journaling layer is present we call though it, else
1699 * we call the native VOP functions.
1702 vop_cache_operate_ap(struct vop_generic_args *ap)
1704 struct vop_ops *ops;
1708 if (ops->head.vv_mount->mnt_vn_journal_ops)
1709 error = VOCALL(ops->head.vv_mount->mnt_vn_journal_ops, ap);
1711 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1717 * This routine is called by the journaling layer to execute the actual
1721 vop_journal_operate_ap(struct vop_generic_args *ap)
1723 struct vop_ops *ops;
1727 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1733 vop_open_ap(struct vop_open_args *ap)
1737 DO_OPS(ap->a_head.a_ops, error, ap, vop_open);
1742 vop_close_ap(struct vop_close_args *ap)
1746 DO_OPS(ap->a_head.a_ops, error, ap, vop_close);
1751 vop_access_ap(struct vop_access_args *ap)
1755 DO_OPS(ap->a_head.a_ops, error, ap, vop_access);
1760 vop_getattr_ap(struct vop_getattr_args *ap)
1764 DO_OPS(ap->a_head.a_ops, error, ap, vop_getattr);
1769 vop_setattr_ap(struct vop_setattr_args *ap)
1773 DO_OPS(ap->a_head.a_ops, error, ap, vop_setattr);
1778 vop_read_ap(struct vop_read_args *ap)
1782 DO_OPS(ap->a_head.a_ops, error, ap, vop_read);
1787 vop_write_ap(struct vop_write_args *ap)
1791 DO_OPS(ap->a_head.a_ops, error, ap, vop_write);
1796 vop_ioctl_ap(struct vop_ioctl_args *ap)
1800 DO_OPS(ap->a_head.a_ops, error, ap, vop_ioctl);
1805 vop_poll_ap(struct vop_poll_args *ap)
1809 DO_OPS(ap->a_head.a_ops, error, ap, vop_poll);
1814 vop_kqfilter_ap(struct vop_kqfilter_args *ap)
1818 DO_OPS(ap->a_head.a_ops, error, ap, vop_kqfilter);
1823 vop_mmap_ap(struct vop_mmap_args *ap)
1827 DO_OPS(ap->a_head.a_ops, error, ap, vop_mmap);
1832 vop_fsync_ap(struct vop_fsync_args *ap)
1836 DO_OPS(ap->a_head.a_ops, error, ap, vop_fsync);
1841 vop_readdir_ap(struct vop_readdir_args *ap)
1845 DO_OPS(ap->a_head.a_ops, error, ap, vop_readdir);
1850 vop_readlink_ap(struct vop_readlink_args *ap)
1854 DO_OPS(ap->a_head.a_ops, error, ap, vop_readlink);
1859 vop_inactive_ap(struct vop_inactive_args *ap)
1863 DO_OPS(ap->a_head.a_ops, error, ap, vop_inactive);
1868 vop_reclaim_ap(struct vop_reclaim_args *ap)
1872 DO_OPS(ap->a_head.a_ops, error, ap, vop_reclaim);
1877 vop_bmap_ap(struct vop_bmap_args *ap)
1881 DO_OPS(ap->a_head.a_ops, error, ap, vop_bmap);
1886 vop_strategy_ap(struct vop_strategy_args *ap)
1890 DO_OPS(ap->a_head.a_ops, error, ap, vop_strategy);
1895 vop_print_ap(struct vop_print_args *ap)
1899 DO_OPS(ap->a_head.a_ops, error, ap, vop_print);
1904 vop_pathconf_ap(struct vop_pathconf_args *ap)
1908 DO_OPS(ap->a_head.a_ops, error, ap, vop_pathconf);
1913 vop_advlock_ap(struct vop_advlock_args *ap)
1917 DO_OPS(ap->a_head.a_ops, error, ap, vop_advlock);
1922 vop_balloc_ap(struct vop_balloc_args *ap)
1926 DO_OPS(ap->a_head.a_ops, error, ap, vop_balloc);
1931 vop_reallocblks_ap(struct vop_reallocblks_args *ap)
1935 DO_OPS(ap->a_head.a_ops, error, ap, vop_reallocblks);
1940 vop_getpages_ap(struct vop_getpages_args *ap)
1944 DO_OPS(ap->a_head.a_ops, error, ap, vop_getpages);
1949 vop_putpages_ap(struct vop_putpages_args *ap)
1953 DO_OPS(ap->a_head.a_ops, error, ap, vop_putpages);
1958 vop_freeblks_ap(struct vop_freeblks_args *ap)
1962 DO_OPS(ap->a_head.a_ops, error, ap, vop_freeblks);
1967 vop_getacl_ap(struct vop_getacl_args *ap)
1971 DO_OPS(ap->a_head.a_ops, error, ap, vop_getacl);
1976 vop_setacl_ap(struct vop_setacl_args *ap)
1980 DO_OPS(ap->a_head.a_ops, error, ap, vop_setacl);
1985 vop_aclcheck_ap(struct vop_aclcheck_args *ap)
1989 DO_OPS(ap->a_head.a_ops, error, ap, vop_aclcheck);
1994 vop_getextattr_ap(struct vop_getextattr_args *ap)
1998 DO_OPS(ap->a_head.a_ops, error, ap, vop_getextattr);
2003 vop_setextattr_ap(struct vop_setextattr_args *ap)
2007 DO_OPS(ap->a_head.a_ops, error, ap, vop_setextattr);
2012 vop_mountctl_ap(struct vop_mountctl_args *ap)
2016 DO_OPS(ap->a_head.a_ops, error, ap, vop_mountctl);
2021 vop_markatime_ap(struct vop_markatime_args *ap)
2025 DO_OPS(ap->a_head.a_ops, error, ap, vop_markatime);
2030 vop_nresolve_ap(struct vop_nresolve_args *ap)
2034 DO_OPS(ap->a_head.a_ops, error, ap, vop_nresolve);
2039 vop_nlookupdotdot_ap(struct vop_nlookupdotdot_args *ap)
2043 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlookupdotdot);
2048 vop_ncreate_ap(struct vop_ncreate_args *ap)
2052 DO_OPS(ap->a_head.a_ops, error, ap, vop_ncreate);
2057 vop_nmkdir_ap(struct vop_nmkdir_args *ap)
2061 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmkdir);
2066 vop_nmknod_ap(struct vop_nmknod_args *ap)
2070 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmknod);
2075 vop_nlink_ap(struct vop_nlink_args *ap)
2079 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlink);
2084 vop_nsymlink_ap(struct vop_nsymlink_args *ap)
2088 DO_OPS(ap->a_head.a_ops, error, ap, vop_nsymlink);
2093 vop_nwhiteout_ap(struct vop_nwhiteout_args *ap)
2097 DO_OPS(ap->a_head.a_ops, error, ap, vop_nwhiteout);
2102 vop_nremove_ap(struct vop_nremove_args *ap)
2106 DO_OPS(ap->a_head.a_ops, error, ap, vop_nremove);
2111 vop_nrmdir_ap(struct vop_nrmdir_args *ap)
2115 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrmdir);
2120 vop_nrename_ap(struct vop_nrename_args *ap)
2124 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrename);