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);
184 VFS_MPUNLOCK(dvp->v_mount);
192 vop_old_create(struct vop_ops *ops, struct vnode *dvp,
193 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
195 struct vop_old_create_args ap;
199 ap.a_head.a_desc = &vop_old_create_desc;
200 ap.a_head.a_ops = ops;
206 VFS_MPLOCK(dvp->v_mount);
207 DO_OPS(ops, error, &ap, vop_old_create);
208 VFS_MPUNLOCK(dvp->v_mount);
216 vop_old_whiteout(struct vop_ops *ops, struct vnode *dvp,
217 struct componentname *cnp, int flags)
219 struct vop_old_whiteout_args ap;
223 ap.a_head.a_desc = &vop_old_whiteout_desc;
224 ap.a_head.a_ops = ops;
229 VFS_MPLOCK(dvp->v_mount);
230 DO_OPS(ops, error, &ap, vop_old_whiteout);
231 VFS_MPUNLOCK(dvp->v_mount);
239 vop_old_mknod(struct vop_ops *ops, struct vnode *dvp,
240 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
242 struct vop_old_mknod_args ap;
246 ap.a_head.a_desc = &vop_old_mknod_desc;
247 ap.a_head.a_ops = ops;
253 VFS_MPLOCK(dvp->v_mount);
254 DO_OPS(ops, error, &ap, vop_old_mknod);
255 VFS_MPUNLOCK(dvp->v_mount);
260 * NOTE: VAGE is always cleared when calling VOP_OPEN().
263 vop_open(struct vop_ops *ops, struct vnode *vp, int mode, struct ucred *cred,
266 struct vop_open_args ap;
271 * Decrement 3-2-1-0. Does not decrement beyond 0
273 if (vp->v_flag & VAGE0) {
274 vclrflags(vp, VAGE0);
275 } else if (vp->v_flag & VAGE1) {
276 vclrflags(vp, VAGE1);
277 vsetflags(vp, VAGE0);
280 ap.a_head.a_desc = &vop_open_desc;
281 ap.a_head.a_ops = ops;
287 VFS_MPLOCK(vp->v_mount);
288 DO_OPS(ops, error, &ap, vop_open);
289 VFS_MPUNLOCK(vp->v_mount);
297 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;
310 VFS_MPLOCK(vp->v_mount);
311 DO_OPS(ops, error, &ap, vop_close);
312 VFS_MPUNLOCK(vp->v_mount);
320 vop_access(struct vop_ops *ops, struct vnode *vp, int mode, int flags,
323 struct vop_access_args ap;
327 ap.a_head.a_desc = &vop_access_desc;
328 ap.a_head.a_ops = ops;
334 VFS_MPLOCK(vp->v_mount);
335 DO_OPS(ops, error, &ap, vop_access);
336 VFS_MPUNLOCK(vp->v_mount);
344 vop_getattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap,
347 struct vop_getattr_args ap;
351 ap.a_head.a_desc = &vop_getattr_desc;
352 ap.a_head.a_ops = ops;
357 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_GA_MPSAFE);
358 DO_OPS(ops, error, &ap, vop_getattr);
359 VFS_MPUNLOCK(vp->v_mount);
368 vop_setattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap,
369 struct ucred *cred, struct file *fp)
371 struct vop_setattr_args ap;
375 ap.a_head.a_desc = &vop_setattr_desc;
376 ap.a_head.a_ops = ops;
382 VFS_MPLOCK(vp->v_mount);
383 DO_OPS(ops, error, &ap, vop_setattr);
384 VFS_MPUNLOCK(vp->v_mount);
392 vop_read(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
393 struct ucred *cred, struct file *fp)
395 struct vop_read_args ap;
399 ap.a_head.a_desc = &vop_read_desc;
400 ap.a_head.a_ops = ops;
403 ap.a_ioflag = ioflag;
407 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_RD_MPSAFE);
408 DO_OPS(ops, error, &ap, vop_read);
409 VFS_MPUNLOCK(vp->v_mount);
417 vop_write(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
418 struct ucred *cred, struct file *fp)
420 struct vop_write_args ap;
422 int error, do_accounting = 0;
424 uint64_t size_before=0, size_after=0;
426 uint64_t offset, delta;
428 ap.a_head.a_desc = &vop_write_desc;
429 ap.a_head.a_ops = ops;
432 ap.a_ioflag = ioflag;
436 /* is this a regular vnode ? */
437 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_WR_MPSAFE);
438 if (vfs_quota_enabled && (vp->v_type == VREG)) {
439 if ((error = VOP_GETATTR(vp, &va)) != 0)
441 size_before = va.va_size;
442 /* this file may already have been removed */
446 offset = uio->uio_offset;
447 if (ioflag & IO_APPEND)
448 offset = size_before;
449 size_after = offset + uio->uio_resid;
450 if (size_after < size_before)
451 size_after = size_before;
452 delta = size_after - size_before;
455 if (!vq_write_ok(mp, va.va_uid, va.va_gid, delta)) {
460 DO_OPS(ops, error, &ap, vop_write);
461 if ((error == 0) && do_accounting) {
462 VFS_ACCOUNT(mp, va.va_uid, va.va_gid, size_after - size_before);
465 VFS_MPUNLOCK(vp->v_mount);
473 vop_ioctl(struct vop_ops *ops, struct vnode *vp, u_long command, caddr_t data,
474 int fflag, struct ucred *cred, struct sysmsg *msg)
476 struct vop_ioctl_args ap;
480 ap.a_head.a_desc = &vop_ioctl_desc;
481 ap.a_head.a_ops = ops;
483 ap.a_command = command;
489 VFS_MPLOCK(vp->v_mount);
490 DO_OPS(ops, error, &ap, vop_ioctl);
491 VFS_MPUNLOCK(vp->v_mount);
499 vop_poll(struct vop_ops *ops, struct vnode *vp, int events, struct ucred *cred)
501 struct vop_poll_args ap;
505 ap.a_head.a_desc = &vop_poll_desc;
506 ap.a_head.a_ops = ops;
508 ap.a_events = events;
511 VFS_MPLOCK(vp->v_mount);
512 DO_OPS(ops, error, &ap, vop_poll);
513 VFS_MPUNLOCK(vp->v_mount);
521 vop_kqfilter(struct vop_ops *ops, struct vnode *vp, struct knote *kn)
523 struct vop_kqfilter_args ap;
527 ap.a_head.a_desc = &vop_kqfilter_desc;
528 ap.a_head.a_ops = ops;
532 VFS_MPLOCK(vp->v_mount);
533 DO_OPS(ops, error, &ap, vop_kqfilter);
534 VFS_MPUNLOCK(vp->v_mount);
542 vop_mmap(struct vop_ops *ops, struct vnode *vp, int fflags, struct ucred *cred)
544 struct vop_mmap_args ap;
548 ap.a_head.a_desc = &vop_mmap_desc;
549 ap.a_head.a_ops = ops;
551 ap.a_fflags = fflags;
554 VFS_MPLOCK(vp->v_mount);
555 DO_OPS(ops, error, &ap, vop_mmap);
556 VFS_MPUNLOCK(vp->v_mount);
564 vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor, int flags,
567 struct vop_fsync_args ap;
571 ap.a_head.a_desc = &vop_fsync_desc;
572 ap.a_head.a_ops = ops;
574 ap.a_waitfor = waitfor;
578 VFS_MPLOCK(vp->v_mount);
579 DO_OPS(ops, error, &ap, vop_fsync);
580 VFS_MPUNLOCK(vp->v_mount);
588 vop_old_remove(struct vop_ops *ops, struct vnode *dvp,
589 struct vnode *vp, struct componentname *cnp)
591 struct vop_old_remove_args ap;
595 ap.a_head.a_desc = &vop_old_remove_desc;
596 ap.a_head.a_ops = ops;
601 VFS_MPLOCK(dvp->v_mount);
602 DO_OPS(ops, error, &ap, vop_old_remove);
603 VFS_MPUNLOCK(dvp->v_mount);
611 vop_old_link(struct vop_ops *ops, struct vnode *tdvp,
612 struct vnode *vp, struct componentname *cnp)
614 struct vop_old_link_args ap;
618 ap.a_head.a_desc = &vop_old_link_desc;
619 ap.a_head.a_ops = ops;
624 VFS_MPLOCK(tdvp->v_mount);
625 DO_OPS(ops, error, &ap, vop_old_link);
626 VFS_MPUNLOCK(tdvp->v_mount);
634 vop_old_rename(struct vop_ops *ops,
635 struct vnode *fdvp, struct vnode *fvp, struct componentname *fcnp,
636 struct vnode *tdvp, struct vnode *tvp, struct componentname *tcnp)
638 struct vop_old_rename_args ap;
642 ap.a_head.a_desc = &vop_old_rename_desc;
643 ap.a_head.a_ops = ops;
651 VFS_MPLOCK(tdvp->v_mount);
652 DO_OPS(ops, error, &ap, vop_old_rename);
653 VFS_MPUNLOCK(tdvp->v_mount);
661 vop_old_mkdir(struct vop_ops *ops, struct vnode *dvp,
662 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
664 struct vop_old_mkdir_args ap;
668 ap.a_head.a_desc = &vop_old_mkdir_desc;
669 ap.a_head.a_ops = ops;
675 VFS_MPLOCK(dvp->v_mount);
676 DO_OPS(ops, error, &ap, vop_old_mkdir);
677 VFS_MPUNLOCK(dvp->v_mount);
685 vop_old_rmdir(struct vop_ops *ops, struct vnode *dvp,
686 struct vnode *vp, struct componentname *cnp)
688 struct vop_old_rmdir_args ap;
692 ap.a_head.a_desc = &vop_old_rmdir_desc;
693 ap.a_head.a_ops = ops;
698 VFS_MPLOCK(dvp->v_mount);
699 DO_OPS(ops, error, &ap, vop_old_rmdir);
700 VFS_MPUNLOCK(dvp->v_mount);
708 vop_old_symlink(struct vop_ops *ops, struct vnode *dvp,
709 struct vnode **vpp, struct componentname *cnp,
710 struct vattr *vap, char *target)
712 struct vop_old_symlink_args ap;
716 ap.a_head.a_desc = &vop_old_symlink_desc;
717 ap.a_head.a_ops = ops;
722 ap.a_target = target;
724 VFS_MPLOCK(dvp->v_mount);
725 DO_OPS(ops, error, &ap, vop_old_symlink);
726 VFS_MPUNLOCK(dvp->v_mount);
734 vop_readdir(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
735 struct ucred *cred, int *eofflag, int *ncookies, off_t **cookies,
738 struct vop_readdir_args ap;
742 ap.a_head.a_desc = &vop_readdir_desc;
743 ap.a_head.a_ops = ops;
747 ap.a_eofflag = eofflag;
748 ap.a_ncookies = ncookies;
749 ap.a_cookies = cookies;
752 VFS_MPLOCK(vp->v_mount);
753 DO_OPS(ops, error, &ap, vop_readdir);
754 VFS_MPUNLOCK(vp->v_mount);
762 vop_readlink(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
765 struct vop_readlink_args ap;
769 ap.a_head.a_desc = &vop_readlink_desc;
770 ap.a_head.a_ops = ops;
775 VFS_MPLOCK(vp->v_mount);
776 DO_OPS(ops, error, &ap, vop_readlink);
777 VFS_MPUNLOCK(vp->v_mount);
785 vop_inactive(struct vop_ops *ops, struct vnode *vp)
787 struct vop_inactive_args ap;
792 ap.a_head.a_desc = &vop_inactive_desc;
793 ap.a_head.a_ops = ops;
797 * WARNING! Deactivation of the vnode can cause it to be recycled,
798 * clearing vp->v_mount.
801 VFS_MPLOCK_FLAG(mp, MNTK_IN_MPSAFE);
802 DO_OPS(ops, error, &ap, vop_inactive);
811 vop_reclaim(struct vop_ops *ops, struct vnode *vp)
813 struct vop_reclaim_args ap;
818 ap.a_head.a_desc = &vop_reclaim_desc;
819 ap.a_head.a_ops = ops;
823 * WARNING! Reclamation of the vnode will clear vp->v_mount.
827 DO_OPS(ops, error, &ap, vop_reclaim);
836 vop_bmap(struct vop_ops *ops, struct vnode *vp, off_t loffset,
837 off_t *doffsetp, int *runp, int *runb, buf_cmd_t cmd)
839 struct vop_bmap_args ap;
843 ap.a_head.a_desc = &vop_bmap_desc;
844 ap.a_head.a_ops = ops;
846 ap.a_loffset = loffset;
847 ap.a_doffsetp = doffsetp;
852 VFS_MPLOCK(vp->v_mount);
853 DO_OPS(ops, error, &ap, vop_bmap);
854 VFS_MPUNLOCK(vp->v_mount);
862 vop_strategy(struct vop_ops *ops, struct vnode *vp, struct bio *bio)
864 struct vop_strategy_args ap;
868 ap.a_head.a_desc = &vop_strategy_desc;
869 ap.a_head.a_ops = ops;
874 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_SG_MPSAFE);
875 DO_OPS(ops, error, &ap, vop_strategy);
876 VFS_MPUNLOCK(vp->v_mount);
878 /* ugly hack for swap */
880 DO_OPS(ops, error, &ap, vop_strategy);
890 vop_print(struct vop_ops *ops, struct vnode *vp)
892 struct vop_print_args ap;
896 ap.a_head.a_desc = &vop_print_desc;
897 ap.a_head.a_ops = ops;
900 VFS_MPLOCK(vp->v_mount);
901 DO_OPS(ops, error, &ap, vop_print);
902 VFS_MPUNLOCK(vp->v_mount);
910 vop_pathconf(struct vop_ops *ops, struct vnode *vp, int name,
913 struct vop_pathconf_args ap;
917 ap.a_head.a_desc = &vop_pathconf_desc;
918 ap.a_head.a_ops = ops;
921 ap.a_retval = retval;
923 VFS_MPLOCK(vp->v_mount);
924 DO_OPS(ops, error, &ap, vop_pathconf);
925 VFS_MPUNLOCK(vp->v_mount);
933 vop_advlock(struct vop_ops *ops, struct vnode *vp, caddr_t id, int op,
934 struct flock *fl, int flags)
936 struct vop_advlock_args ap;
940 ap.a_head.a_desc = &vop_advlock_desc;
941 ap.a_head.a_ops = ops;
948 VFS_MPLOCK(vp->v_mount);
949 DO_OPS(ops, error, &ap, vop_advlock);
950 VFS_MPUNLOCK(vp->v_mount);
958 vop_balloc(struct vop_ops *ops, struct vnode *vp, off_t startoffset,
959 int size, struct ucred *cred, int flags,
962 struct vop_balloc_args ap;
966 ap.a_head.a_desc = &vop_balloc_desc;
967 ap.a_head.a_ops = ops;
969 ap.a_startoffset = startoffset;
975 VFS_MPLOCK(vp->v_mount);
976 DO_OPS(ops, error, &ap, vop_balloc);
977 VFS_MPUNLOCK(vp->v_mount);
985 vop_reallocblks(struct vop_ops *ops, struct vnode *vp,
986 struct cluster_save *buflist)
988 struct vop_reallocblks_args ap;
992 ap.a_head.a_desc = &vop_reallocblks_desc;
993 ap.a_head.a_ops = ops;
995 ap.a_buflist = buflist;
997 VFS_MPLOCK(vp->v_mount);
998 DO_OPS(ops, error, &ap, vop_reallocblks);
999 VFS_MPUNLOCK(vp->v_mount);
1007 vop_getpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
1008 int reqpage, vm_ooffset_t offset, int seqaccess)
1010 struct vop_getpages_args ap;
1014 ap.a_head.a_desc = &vop_getpages_desc;
1015 ap.a_head.a_ops = ops;
1019 ap.a_reqpage = reqpage;
1020 ap.a_offset = offset;
1021 ap.a_seqaccess = seqaccess;
1023 VFS_MPLOCK(vp->v_mount);
1024 DO_OPS(ops, error, &ap, vop_getpages);
1025 VFS_MPUNLOCK(vp->v_mount);
1033 vop_putpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
1034 int sync, int *rtvals, vm_ooffset_t offset)
1036 struct vop_putpages_args ap;
1040 ap.a_head.a_desc = &vop_putpages_desc;
1041 ap.a_head.a_ops = ops;
1046 ap.a_rtvals = rtvals;
1047 ap.a_offset = offset;
1049 VFS_MPLOCK(vp->v_mount);
1050 DO_OPS(ops, error, &ap, vop_putpages);
1051 VFS_MPUNLOCK(vp->v_mount);
1059 vop_freeblks(struct vop_ops *ops, struct vnode *vp, off_t offset, int length)
1061 struct vop_freeblks_args ap;
1065 ap.a_head.a_desc = &vop_freeblks_desc;
1066 ap.a_head.a_ops = ops;
1068 ap.a_offset = offset;
1069 ap.a_length = length;
1071 VFS_MPLOCK(vp->v_mount);
1072 DO_OPS(ops, error, &ap, vop_freeblks);
1073 VFS_MPUNLOCK(vp->v_mount);
1081 vop_getacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1082 struct acl *aclp, struct ucred *cred)
1084 struct vop_getacl_args ap;
1088 ap.a_head.a_desc = &vop_getacl_desc;
1089 ap.a_head.a_ops = ops;
1095 VFS_MPLOCK(vp->v_mount);
1096 DO_OPS(ops, error, &ap, vop_getacl);
1097 VFS_MPUNLOCK(vp->v_mount);
1105 vop_setacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1106 struct acl *aclp, struct ucred *cred)
1108 struct vop_setacl_args ap;
1112 ap.a_head.a_desc = &vop_setacl_desc;
1113 ap.a_head.a_ops = ops;
1119 VFS_MPLOCK(vp->v_mount);
1120 DO_OPS(ops, error, &ap, vop_setacl);
1121 VFS_MPUNLOCK(vp->v_mount);
1129 vop_aclcheck(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1130 struct acl *aclp, struct ucred *cred)
1132 struct vop_aclcheck_args ap;
1136 ap.a_head.a_desc = &vop_aclcheck_desc;
1137 ap.a_head.a_ops = ops;
1143 VFS_MPLOCK(vp->v_mount);
1144 DO_OPS(ops, error, &ap, vop_aclcheck);
1145 VFS_MPUNLOCK(vp->v_mount);
1153 vop_getextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1154 char *attrname, struct uio *uio, struct ucred *cred)
1156 struct vop_getextattr_args ap;
1160 ap.a_head.a_desc = &vop_getextattr_desc;
1161 ap.a_head.a_ops = ops;
1163 ap.a_attrnamespace = attrnamespace;
1164 ap.a_attrname = attrname;
1168 VFS_MPLOCK(vp->v_mount);
1169 DO_OPS(ops, error, &ap, vop_getextattr);
1170 VFS_MPUNLOCK(vp->v_mount);
1178 vop_setextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1179 char *attrname, struct uio *uio, struct ucred *cred)
1181 struct vop_setextattr_args ap;
1185 ap.a_head.a_desc = &vop_setextattr_desc;
1186 ap.a_head.a_ops = ops;
1188 ap.a_attrnamespace = attrnamespace;
1189 ap.a_attrname = attrname;
1193 VFS_MPLOCK(vp->v_mount);
1194 DO_OPS(ops, error, &ap, vop_setextattr);
1195 VFS_MPUNLOCK(vp->v_mount);
1203 vop_mountctl(struct vop_ops *ops, struct vnode *vp, int op, struct file *fp,
1204 const void *ctl, int ctllen, void *buf, int buflen, int *res)
1206 struct vop_mountctl_args ap;
1210 ap.a_head.a_desc = &vop_mountctl_desc;
1211 ap.a_head.a_ops = ops;
1215 ap.a_ctllen = ctllen;
1217 ap.a_buflen = buflen;
1220 VFS_MPLOCK(vp->v_mount);
1221 DO_OPS(ops, error, &ap, vop_mountctl);
1222 VFS_MPUNLOCK(vp->v_mount);
1230 vop_markatime(struct vop_ops *ops, struct vnode *vp, struct ucred *cred)
1232 struct vop_markatime_args ap;
1236 ap.a_head.a_desc = &vop_markatime_desc;
1237 ap.a_head.a_ops = ops;
1241 VFS_MPLOCK(vp->v_mount);
1242 DO_OPS(ops, error, &ap, vop_markatime);
1243 VFS_MPUNLOCK(vp->v_mount);
1250 * nresolve takes a locked ncp, a referenced but unlocked dvp, and a cred,
1251 * and resolves the ncp into a positive or negative hit.
1253 * The namecache is automatically adjusted by this function. The ncp
1254 * is left locked on return.
1259 vop_nresolve(struct vop_ops *ops, struct nchandle *nch,
1260 struct vnode *dvp, struct ucred *cred)
1262 struct vop_nresolve_args ap;
1266 ap.a_head.a_desc = &vop_nresolve_desc;
1267 ap.a_head.a_ops = ops;
1272 VFS_MPLOCK(dvp->v_mount);
1273 DO_OPS(ops, error, &ap, vop_nresolve);
1274 VFS_MPUNLOCK(dvp->v_mount);
1279 * nlookupdotdot takes an unlocked directory, referenced dvp, and looks
1280 * up "..", returning a locked parent directory in *vpp. If an error
1281 * occurs *vpp will be NULL.
1286 vop_nlookupdotdot(struct vop_ops *ops, struct vnode *dvp,
1287 struct vnode **vpp, struct ucred *cred, char **fakename)
1289 struct vop_nlookupdotdot_args ap;
1293 ap.a_head.a_desc = &vop_nlookupdotdot_desc;
1294 ap.a_head.a_ops = ops;
1298 ap.a_fakename = fakename;
1300 VFS_MPLOCK(dvp->v_mount);
1301 DO_OPS(ops, error, &ap, vop_nlookupdotdot);
1302 VFS_MPUNLOCK(dvp->v_mount);
1307 * ncreate takes a locked, resolved ncp that typically represents a negative
1308 * cache hit and creates the file or node specified by the ncp, cred, and
1309 * vattr. If no error occurs a locked vnode is returned in *vpp.
1311 * The dvp passed in is referenced but unlocked.
1313 * The namecache is automatically adjusted by this function. The ncp
1314 * is left locked on return.
1319 vop_ncreate(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1320 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1322 struct vop_ncreate_args ap;
1326 ap.a_head.a_desc = &vop_ncreate_desc;
1327 ap.a_head.a_ops = ops;
1334 VFS_MPLOCK(dvp->v_mount);
1335 DO_OPS(ops, error, &ap, vop_ncreate);
1336 VFS_MPUNLOCK(dvp->v_mount);
1341 * nmkdir takes a locked, resolved ncp that typically represents a negative
1342 * cache hit and creates the directory specified by the ncp, cred, and
1343 * vattr. If no error occurs a locked vnode is returned in *vpp.
1345 * The dvp passed in is referenced but unlocked.
1347 * The namecache is automatically adjusted by this function. The ncp
1348 * is left locked on return.
1353 vop_nmkdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1354 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1356 struct vop_nmkdir_args ap;
1360 ap.a_head.a_desc = &vop_nmkdir_desc;
1361 ap.a_head.a_ops = ops;
1368 VFS_MPLOCK(dvp->v_mount);
1369 DO_OPS(ops, error, &ap, vop_nmkdir);
1370 VFS_MPUNLOCK(dvp->v_mount);
1375 * nmknod takes a locked, resolved ncp that typically represents a negative
1376 * cache hit and creates the node specified by the ncp, cred, and
1377 * vattr. If no error occurs a locked vnode is returned in *vpp.
1379 * The dvp passed in is referenced but unlocked.
1381 * The namecache is automatically adjusted by this function. The ncp
1382 * is left locked on return.
1387 vop_nmknod(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1388 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1390 struct vop_nmknod_args ap;
1394 ap.a_head.a_desc = &vop_nmknod_desc;
1395 ap.a_head.a_ops = ops;
1402 VFS_MPLOCK(dvp->v_mount);
1403 DO_OPS(ops, error, &ap, vop_nmknod);
1404 VFS_MPUNLOCK(dvp->v_mount);
1409 * nlink takes a locked, resolved ncp that typically represents a negative
1410 * cache hit and creates the node specified by the ncp, cred, and
1411 * existing vnode. The passed vp must be locked and will remain locked
1412 * on return, as does the ncp, whether an error occurs or not.
1414 * The dvp passed in is referenced but unlocked.
1416 * The namecache is automatically adjusted by this function. The ncp
1417 * is left locked on return.
1422 vop_nlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1423 struct vnode *vp, struct ucred *cred)
1425 struct vop_nlink_args ap;
1429 ap.a_head.a_desc = &vop_nlink_desc;
1430 ap.a_head.a_ops = ops;
1436 VFS_MPLOCK(dvp->v_mount);
1437 DO_OPS(ops, error, &ap, vop_nlink);
1438 VFS_MPUNLOCK(dvp->v_mount);
1443 * nsymlink takes a locked, resolved ncp that typically represents a negative
1444 * cache hit and creates a symbolic link based on cred, vap, and target (the
1445 * contents of the link). If no error occurs a locked vnode is returned in
1448 * The dvp passed in is referenced but unlocked.
1450 * The namecache is automatically adjusted by this function. The ncp
1451 * is left locked on return.
1456 vop_nsymlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1457 struct vnode **vpp, struct ucred *cred,
1458 struct vattr *vap, char *target)
1460 struct vop_nsymlink_args ap;
1464 ap.a_head.a_desc = &vop_nsymlink_desc;
1465 ap.a_head.a_ops = ops;
1471 ap.a_target = target;
1473 VFS_MPLOCK(dvp->v_mount);
1474 DO_OPS(ops, error, &ap, vop_nsymlink);
1475 VFS_MPUNLOCK(dvp->v_mount);
1480 * nwhiteout takes a locked, resolved ncp that can represent a positive or
1481 * negative hit and executes the whiteout function specified in flags.
1483 * The dvp passed in is referenced but unlocked.
1485 * The namecache is automatically adjusted by this function. The ncp
1486 * is left locked on return.
1491 vop_nwhiteout(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1492 struct ucred *cred, int flags)
1494 struct vop_nwhiteout_args ap;
1498 ap.a_head.a_desc = &vop_nwhiteout_desc;
1499 ap.a_head.a_ops = ops;
1505 VFS_MPLOCK(dvp->v_mount);
1506 DO_OPS(ops, error, &ap, vop_nwhiteout);
1507 VFS_MPUNLOCK(dvp->v_mount);
1512 * nremove takes a locked, resolved ncp that generally represents a
1513 * positive hit and removes the file.
1515 * The dvp passed in is referenced but unlocked.
1517 * The namecache is automatically adjusted by this function. The ncp
1518 * is left locked on return.
1523 vop_nremove(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1526 struct vop_nremove_args ap;
1531 ap.a_head.a_desc = &vop_nremove_desc;
1532 ap.a_head.a_ops = ops;
1537 if ((error = VOP_GETATTR(nch->ncp->nc_vp, &va)) != 0)
1540 VFS_MPLOCK(dvp->v_mount);
1541 DO_OPS(ops, error, &ap, vop_nremove);
1542 /* Only update space counters if this is the last hard link */
1543 if ((error == 0) && (va.va_nlink == 1)) {
1544 VFS_ACCOUNT(nch->mount, va.va_uid, va.va_gid, -va.va_size);
1546 VFS_MPUNLOCK(dvp->v_mount);
1551 * nrmdir takes a locked, resolved ncp that generally represents a
1552 * directory and removes the directory.
1554 * The dvp passed in is referenced but unlocked.
1556 * The namecache is automatically adjusted by this function. The ncp
1557 * is left locked on return.
1562 vop_nrmdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1565 struct vop_nrmdir_args ap;
1569 ap.a_head.a_desc = &vop_nrmdir_desc;
1570 ap.a_head.a_ops = ops;
1575 VFS_MPLOCK(dvp->v_mount);
1576 DO_OPS(ops, error, &ap, vop_nrmdir);
1577 VFS_MPUNLOCK(dvp->v_mount);
1582 * nrename takes TWO locked, resolved ncp's and the cred of the caller
1583 * and renames the source ncp to the target ncp. The target ncp may
1584 * represent a positive or negative hit.
1586 * The fdvp and tdvp passed in are referenced but unlocked.
1588 * The namecache is automatically adjusted by this function. The ncp
1589 * is left locked on return. The source ncp is typically changed to
1590 * a negative cache hit and the target ncp typically takes on the
1591 * source ncp's underlying file.
1596 vop_nrename(struct vop_ops *ops,
1597 struct nchandle *fnch, struct nchandle *tnch,
1598 struct vnode *fdvp, struct vnode *tdvp,
1601 struct vop_nrename_args ap;
1605 ap.a_head.a_desc = &vop_nrename_desc;
1606 ap.a_head.a_ops = ops;
1613 VFS_MPLOCK(fdvp->v_mount);
1614 DO_OPS(ops, error, &ap, vop_nrename);
1615 VFS_MPUNLOCK(fdvp->v_mount);
1619 /************************************************************************
1620 * PRIMARY VNODE OPERATIONS FORWARDING CALLS *
1621 ************************************************************************
1623 * These procedures are called from VFSs such as nullfs
1624 * when they wish to forward an operation on one VFS to another. The
1625 * argument structure/message is modified and then directly passed to the
1626 * appropriate routine. This routines may also be called by initiators
1627 * who have an argument structure in hand rather then discreet arguments.
1629 * MPSAFE - Caller expected to already hold the appropriate vfs lock.
1632 vop_vnoperate_ap(struct vop_generic_args *ap)
1634 struct vop_ops *ops;
1638 error = VOCALL(ops, ap);
1644 * This routine is called by the cache coherency layer to execute the actual
1645 * VFS operation. If a journaling layer is present we call though it, else
1646 * we call the native VOP functions.
1649 vop_cache_operate_ap(struct vop_generic_args *ap)
1651 struct vop_ops *ops;
1655 if (ops->head.vv_mount->mnt_vn_journal_ops)
1656 error = VOCALL(ops->head.vv_mount->mnt_vn_journal_ops, ap);
1658 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1664 * This routine is called by the journaling layer to execute the actual
1668 vop_journal_operate_ap(struct vop_generic_args *ap)
1670 struct vop_ops *ops;
1674 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1680 vop_open_ap(struct vop_open_args *ap)
1684 DO_OPS(ap->a_head.a_ops, error, ap, vop_open);
1689 vop_close_ap(struct vop_close_args *ap)
1693 DO_OPS(ap->a_head.a_ops, error, ap, vop_close);
1698 vop_access_ap(struct vop_access_args *ap)
1702 DO_OPS(ap->a_head.a_ops, error, ap, vop_access);
1707 vop_getattr_ap(struct vop_getattr_args *ap)
1711 DO_OPS(ap->a_head.a_ops, error, ap, vop_getattr);
1716 vop_setattr_ap(struct vop_setattr_args *ap)
1720 DO_OPS(ap->a_head.a_ops, error, ap, vop_setattr);
1725 vop_read_ap(struct vop_read_args *ap)
1729 DO_OPS(ap->a_head.a_ops, error, ap, vop_read);
1734 vop_write_ap(struct vop_write_args *ap)
1738 DO_OPS(ap->a_head.a_ops, error, ap, vop_write);
1743 vop_ioctl_ap(struct vop_ioctl_args *ap)
1747 DO_OPS(ap->a_head.a_ops, error, ap, vop_ioctl);
1752 vop_poll_ap(struct vop_poll_args *ap)
1756 DO_OPS(ap->a_head.a_ops, error, ap, vop_poll);
1761 vop_kqfilter_ap(struct vop_kqfilter_args *ap)
1765 DO_OPS(ap->a_head.a_ops, error, ap, vop_kqfilter);
1770 vop_mmap_ap(struct vop_mmap_args *ap)
1774 DO_OPS(ap->a_head.a_ops, error, ap, vop_mmap);
1779 vop_fsync_ap(struct vop_fsync_args *ap)
1783 DO_OPS(ap->a_head.a_ops, error, ap, vop_fsync);
1788 vop_readdir_ap(struct vop_readdir_args *ap)
1792 DO_OPS(ap->a_head.a_ops, error, ap, vop_readdir);
1797 vop_readlink_ap(struct vop_readlink_args *ap)
1801 DO_OPS(ap->a_head.a_ops, error, ap, vop_readlink);
1806 vop_inactive_ap(struct vop_inactive_args *ap)
1810 DO_OPS(ap->a_head.a_ops, error, ap, vop_inactive);
1815 vop_reclaim_ap(struct vop_reclaim_args *ap)
1819 DO_OPS(ap->a_head.a_ops, error, ap, vop_reclaim);
1824 vop_bmap_ap(struct vop_bmap_args *ap)
1828 DO_OPS(ap->a_head.a_ops, error, ap, vop_bmap);
1833 vop_strategy_ap(struct vop_strategy_args *ap)
1837 DO_OPS(ap->a_head.a_ops, error, ap, vop_strategy);
1842 vop_print_ap(struct vop_print_args *ap)
1846 DO_OPS(ap->a_head.a_ops, error, ap, vop_print);
1851 vop_pathconf_ap(struct vop_pathconf_args *ap)
1855 DO_OPS(ap->a_head.a_ops, error, ap, vop_pathconf);
1860 vop_advlock_ap(struct vop_advlock_args *ap)
1864 DO_OPS(ap->a_head.a_ops, error, ap, vop_advlock);
1869 vop_balloc_ap(struct vop_balloc_args *ap)
1873 DO_OPS(ap->a_head.a_ops, error, ap, vop_balloc);
1878 vop_reallocblks_ap(struct vop_reallocblks_args *ap)
1882 DO_OPS(ap->a_head.a_ops, error, ap, vop_reallocblks);
1887 vop_getpages_ap(struct vop_getpages_args *ap)
1891 DO_OPS(ap->a_head.a_ops, error, ap, vop_getpages);
1896 vop_putpages_ap(struct vop_putpages_args *ap)
1900 DO_OPS(ap->a_head.a_ops, error, ap, vop_putpages);
1905 vop_freeblks_ap(struct vop_freeblks_args *ap)
1909 DO_OPS(ap->a_head.a_ops, error, ap, vop_freeblks);
1914 vop_getacl_ap(struct vop_getacl_args *ap)
1918 DO_OPS(ap->a_head.a_ops, error, ap, vop_getacl);
1923 vop_setacl_ap(struct vop_setacl_args *ap)
1927 DO_OPS(ap->a_head.a_ops, error, ap, vop_setacl);
1932 vop_aclcheck_ap(struct vop_aclcheck_args *ap)
1936 DO_OPS(ap->a_head.a_ops, error, ap, vop_aclcheck);
1941 vop_getextattr_ap(struct vop_getextattr_args *ap)
1945 DO_OPS(ap->a_head.a_ops, error, ap, vop_getextattr);
1950 vop_setextattr_ap(struct vop_setextattr_args *ap)
1954 DO_OPS(ap->a_head.a_ops, error, ap, vop_setextattr);
1959 vop_mountctl_ap(struct vop_mountctl_args *ap)
1963 DO_OPS(ap->a_head.a_ops, error, ap, vop_mountctl);
1968 vop_markatime_ap(struct vop_markatime_args *ap)
1972 DO_OPS(ap->a_head.a_ops, error, ap, vop_markatime);
1977 vop_nresolve_ap(struct vop_nresolve_args *ap)
1981 DO_OPS(ap->a_head.a_ops, error, ap, vop_nresolve);
1986 vop_nlookupdotdot_ap(struct vop_nlookupdotdot_args *ap)
1990 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlookupdotdot);
1995 vop_ncreate_ap(struct vop_ncreate_args *ap)
1999 DO_OPS(ap->a_head.a_ops, error, ap, vop_ncreate);
2004 vop_nmkdir_ap(struct vop_nmkdir_args *ap)
2008 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmkdir);
2013 vop_nmknod_ap(struct vop_nmknod_args *ap)
2017 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmknod);
2022 vop_nlink_ap(struct vop_nlink_args *ap)
2026 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlink);
2031 vop_nsymlink_ap(struct vop_nsymlink_args *ap)
2035 DO_OPS(ap->a_head.a_ops, error, ap, vop_nsymlink);
2040 vop_nwhiteout_ap(struct vop_nwhiteout_args *ap)
2044 DO_OPS(ap->a_head.a_ops, error, ap, vop_nwhiteout);
2049 vop_nremove_ap(struct vop_nremove_args *ap)
2053 DO_OPS(ap->a_head.a_ops, error, ap, vop_nremove);
2058 vop_nrmdir_ap(struct vop_nrmdir_args *ap)
2062 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrmdir);
2067 vop_nrename_ap(struct vop_nrename_args *ap)
2071 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrename);