2 * Copyright (c) 2004,2009 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * Implement vnode ops wrappers. All vnode ops are wrapped through
38 * These wrappers are responsible for hanlding all MPSAFE issues related
39 * to a vnode operation.
42 #include <sys/param.h>
43 #include <sys/systm.h>
46 #include <sys/dirent.h>
47 #include <sys/domain.h>
48 #include <sys/eventhandler.h>
49 #include <sys/fcntl.h>
50 #include <sys/kernel.h>
51 #include <sys/kthread.h>
52 #include <sys/malloc.h>
54 #include <sys/mount.h>
56 #include <sys/namei.h>
57 #include <sys/reboot.h>
58 #include <sys/socket.h>
60 #include <sys/sysctl.h>
61 #include <sys/syslog.h>
62 #include <sys/vmmeter.h>
63 #include <sys/vnode.h>
64 #include <sys/vfsops.h>
65 #include <sys/sysmsg.h>
66 #include <sys/vfs_quota.h>
68 #include <machine/limits.h>
71 #include <vm/vm_object.h>
72 #include <vm/vm_extern.h>
73 #include <vm/vm_kern.h>
75 #include <vm/vm_map.h>
76 #include <vm/vm_page.h>
77 #include <vm/vm_pager.h>
78 #include <vm/vnode_pager.h>
79 #include <vm/vm_zone.h>
82 #include <sys/thread2.h>
83 #include <sys/mplock2.h>
85 #define VDESCNAME(name) __CONCAT(__CONCAT(vop_,name),_desc)
87 #define VNODEOP_DESC_INIT(name) \
88 struct syslink_desc VDESCNAME(name) = { \
89 __offsetof(struct vop_ops, __CONCAT(vop_, name)), \
92 VNODEOP_DESC_INIT(default);
93 VNODEOP_DESC_INIT(old_lookup);
94 VNODEOP_DESC_INIT(old_create);
95 VNODEOP_DESC_INIT(old_whiteout);
96 VNODEOP_DESC_INIT(old_mknod);
97 VNODEOP_DESC_INIT(open);
98 VNODEOP_DESC_INIT(close);
99 VNODEOP_DESC_INIT(access);
100 VNODEOP_DESC_INIT(getattr);
101 VNODEOP_DESC_INIT(setattr);
102 VNODEOP_DESC_INIT(read);
103 VNODEOP_DESC_INIT(write);
104 VNODEOP_DESC_INIT(ioctl);
105 VNODEOP_DESC_INIT(poll);
106 VNODEOP_DESC_INIT(kqfilter);
107 VNODEOP_DESC_INIT(mmap);
108 VNODEOP_DESC_INIT(fsync);
109 VNODEOP_DESC_INIT(old_remove);
110 VNODEOP_DESC_INIT(old_link);
111 VNODEOP_DESC_INIT(old_rename);
113 VNODEOP_DESC_INIT(old_mkdir);
114 VNODEOP_DESC_INIT(old_rmdir);
115 VNODEOP_DESC_INIT(old_symlink);
116 VNODEOP_DESC_INIT(readdir);
117 VNODEOP_DESC_INIT(readlink);
118 VNODEOP_DESC_INIT(inactive);
119 VNODEOP_DESC_INIT(reclaim);
120 VNODEOP_DESC_INIT(bmap);
121 VNODEOP_DESC_INIT(strategy);
122 VNODEOP_DESC_INIT(print);
123 VNODEOP_DESC_INIT(pathconf);
124 VNODEOP_DESC_INIT(advlock);
125 VNODEOP_DESC_INIT(balloc);
126 VNODEOP_DESC_INIT(reallocblks);
127 VNODEOP_DESC_INIT(getpages);
128 VNODEOP_DESC_INIT(putpages);
129 VNODEOP_DESC_INIT(freeblks);
130 VNODEOP_DESC_INIT(getacl);
131 VNODEOP_DESC_INIT(setacl);
132 VNODEOP_DESC_INIT(aclcheck);
133 VNODEOP_DESC_INIT(getextattr);
134 VNODEOP_DESC_INIT(setextattr);
135 VNODEOP_DESC_INIT(mountctl);
136 VNODEOP_DESC_INIT(markatime);
138 VNODEOP_DESC_INIT(nresolve);
139 VNODEOP_DESC_INIT(nlookupdotdot);
140 VNODEOP_DESC_INIT(ncreate);
141 VNODEOP_DESC_INIT(nmkdir);
142 VNODEOP_DESC_INIT(nmknod);
143 VNODEOP_DESC_INIT(nlink);
144 VNODEOP_DESC_INIT(nsymlink);
145 VNODEOP_DESC_INIT(nwhiteout);
146 VNODEOP_DESC_INIT(nremove);
147 VNODEOP_DESC_INIT(nrmdir);
148 VNODEOP_DESC_INIT(nrename);
150 #define DO_OPS(ops, error, ap, vop_field) \
151 error = ops->vop_field(ap);
153 /************************************************************************
154 * PRIMARY HIGH LEVEL VNODE OPERATIONS CALLS *
155 ************************************************************************
157 * These procedures are called directly from the kernel and/or fileops
158 * code to perform file/device operations on the system.
160 * NOTE: The old namespace api functions such as vop_rename() are no
161 * longer available for general use and have been renamed to
162 * vop_old_*(). Only the code in vfs_default.c is allowed to call
165 * NOTE: The VFS_MPLOCK*() macros handle mounts which do not set
166 * MNTK_MPSAFE or MNTK_xx_MPSAFE.
172 vop_old_lookup(struct vop_ops *ops, struct vnode *dvp,
173 struct vnode **vpp, struct componentname *cnp)
175 struct vop_old_lookup_args ap;
179 ap.a_head.a_desc = &vop_old_lookup_desc;
180 ap.a_head.a_ops = ops;
184 VFS_MPLOCK1(dvp->v_mount);
185 DO_OPS(ops, error, &ap, vop_old_lookup);
186 VFS_MPUNLOCK(dvp->v_mount);
194 vop_old_create(struct vop_ops *ops, struct vnode *dvp,
195 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
197 struct vop_old_create_args ap;
201 ap.a_head.a_desc = &vop_old_create_desc;
202 ap.a_head.a_ops = ops;
208 VFS_MPLOCK1(dvp->v_mount);
209 DO_OPS(ops, error, &ap, vop_old_create);
210 VFS_MPUNLOCK(dvp->v_mount);
218 vop_old_whiteout(struct vop_ops *ops, struct vnode *dvp,
219 struct componentname *cnp, int flags)
221 struct vop_old_whiteout_args ap;
225 ap.a_head.a_desc = &vop_old_whiteout_desc;
226 ap.a_head.a_ops = ops;
231 VFS_MPLOCK1(dvp->v_mount);
232 DO_OPS(ops, error, &ap, vop_old_whiteout);
233 VFS_MPUNLOCK(dvp->v_mount);
241 vop_old_mknod(struct vop_ops *ops, struct vnode *dvp,
242 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
244 struct vop_old_mknod_args ap;
248 ap.a_head.a_desc = &vop_old_mknod_desc;
249 ap.a_head.a_ops = ops;
255 VFS_MPLOCK1(dvp->v_mount);
256 DO_OPS(ops, error, &ap, vop_old_mknod);
257 VFS_MPUNLOCK(dvp->v_mount);
262 * NOTE: VAGE is always cleared when calling VOP_OPEN().
265 vop_open(struct vop_ops *ops, struct vnode *vp, int mode, struct ucred *cred,
268 struct vop_open_args ap;
273 * Decrement 3-2-1-0. Does not decrement beyond 0
275 if (vp->v_flag & VAGE0) {
276 vclrflags(vp, VAGE0);
277 } else if (vp->v_flag & VAGE1) {
278 vclrflags(vp, VAGE1);
279 vsetflags(vp, VAGE0);
282 ap.a_head.a_desc = &vop_open_desc;
283 ap.a_head.a_ops = ops;
289 VFS_MPLOCK1(vp->v_mount);
290 DO_OPS(ops, error, &ap, vop_open);
291 VFS_MPUNLOCK(vp->v_mount);
299 vop_close(struct vop_ops *ops, struct vnode *vp, int fflag)
301 struct vop_close_args ap;
305 ap.a_head.a_desc = &vop_close_desc;
306 ap.a_head.a_ops = ops;
310 VFS_MPLOCK1(vp->v_mount);
311 DO_OPS(ops, error, &ap, vop_close);
312 VFS_MPUNLOCK(vp->v_mount);
320 vop_access(struct vop_ops *ops, struct vnode *vp, int mode, int flags,
323 struct vop_access_args ap;
327 ap.a_head.a_desc = &vop_access_desc;
328 ap.a_head.a_ops = ops;
334 VFS_MPLOCK1(vp->v_mount);
335 DO_OPS(ops, error, &ap, vop_access);
336 VFS_MPUNLOCK(vp->v_mount);
344 vop_getattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap)
346 struct vop_getattr_args ap;
350 ap.a_head.a_desc = &vop_getattr_desc;
351 ap.a_head.a_ops = ops;
355 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_GA_MPSAFE);
356 DO_OPS(ops, error, &ap, vop_getattr);
357 VFS_MPUNLOCK(vp->v_mount);
366 vop_setattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap,
369 struct vop_setattr_args ap;
373 ap.a_head.a_desc = &vop_setattr_desc;
374 ap.a_head.a_ops = ops;
379 VFS_MPLOCK1(vp->v_mount);
380 DO_OPS(ops, error, &ap, vop_setattr);
381 VFS_MPUNLOCK(vp->v_mount);
389 vop_read(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
392 struct vop_read_args ap;
396 ap.a_head.a_desc = &vop_read_desc;
397 ap.a_head.a_ops = ops;
400 ap.a_ioflag = ioflag;
403 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_RD_MPSAFE);
404 DO_OPS(ops, error, &ap, vop_read);
405 VFS_MPUNLOCK(vp->v_mount);
413 vop_write(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
416 struct vop_write_args ap;
418 int error, do_accounting = 0;
420 uint64_t size_before=0, size_after=0;
422 uint64_t offset, delta;
424 ap.a_head.a_desc = &vop_write_desc;
425 ap.a_head.a_ops = ops;
428 ap.a_ioflag = ioflag;
431 /* is this a regular vnode ? */
432 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_WR_MPSAFE);
433 if (vfs_quota_enabled && (vp->v_type == VREG)) {
434 if ((error = VOP_GETATTR(vp, &va)) != 0)
436 size_before = va.va_size;
437 /* this file may already have been removed */
441 offset = uio->uio_offset;
442 if (ioflag & IO_APPEND)
443 offset = size_before;
444 size_after = offset + uio->uio_resid;
445 if (size_after < size_before)
446 size_after = size_before;
447 delta = size_after - size_before;
450 if (!vq_write_ok(mp, va.va_uid, va.va_gid, delta)) {
455 DO_OPS(ops, error, &ap, vop_write);
456 if ((error == 0) && do_accounting) {
457 VFS_ACCOUNT(mp, va.va_uid, va.va_gid, size_after - size_before);
460 VFS_MPUNLOCK(vp->v_mount);
468 vop_ioctl(struct vop_ops *ops, struct vnode *vp, u_long command, caddr_t data,
469 int fflag, struct ucred *cred, struct sysmsg *msg)
471 struct vop_ioctl_args ap;
475 ap.a_head.a_desc = &vop_ioctl_desc;
476 ap.a_head.a_ops = ops;
478 ap.a_command = command;
484 VFS_MPLOCK1(vp->v_mount);
485 DO_OPS(ops, error, &ap, vop_ioctl);
486 VFS_MPUNLOCK(vp->v_mount);
494 vop_poll(struct vop_ops *ops, struct vnode *vp, int events, struct ucred *cred)
496 struct vop_poll_args ap;
500 ap.a_head.a_desc = &vop_poll_desc;
501 ap.a_head.a_ops = ops;
503 ap.a_events = events;
506 VFS_MPLOCK1(vp->v_mount);
507 DO_OPS(ops, error, &ap, vop_poll);
508 VFS_MPUNLOCK(vp->v_mount);
516 vop_kqfilter(struct vop_ops *ops, struct vnode *vp, struct knote *kn)
518 struct vop_kqfilter_args ap;
522 ap.a_head.a_desc = &vop_kqfilter_desc;
523 ap.a_head.a_ops = ops;
527 VFS_MPLOCK1(vp->v_mount);
528 DO_OPS(ops, error, &ap, vop_kqfilter);
529 VFS_MPUNLOCK(vp->v_mount);
537 vop_mmap(struct vop_ops *ops, struct vnode *vp, int fflags, struct ucred *cred)
539 struct vop_mmap_args ap;
543 ap.a_head.a_desc = &vop_mmap_desc;
544 ap.a_head.a_ops = ops;
546 ap.a_fflags = fflags;
549 VFS_MPLOCK1(vp->v_mount);
550 DO_OPS(ops, error, &ap, vop_mmap);
551 VFS_MPUNLOCK(vp->v_mount);
559 vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor, int flags)
561 struct vop_fsync_args ap;
565 ap.a_head.a_desc = &vop_fsync_desc;
566 ap.a_head.a_ops = ops;
568 ap.a_waitfor = waitfor;
571 VFS_MPLOCK1(vp->v_mount);
572 DO_OPS(ops, error, &ap, vop_fsync);
573 VFS_MPUNLOCK(vp->v_mount);
581 vop_old_remove(struct vop_ops *ops, struct vnode *dvp,
582 struct vnode *vp, struct componentname *cnp)
584 struct vop_old_remove_args ap;
588 ap.a_head.a_desc = &vop_old_remove_desc;
589 ap.a_head.a_ops = ops;
594 VFS_MPLOCK1(dvp->v_mount);
595 DO_OPS(ops, error, &ap, vop_old_remove);
596 VFS_MPUNLOCK(dvp->v_mount);
604 vop_old_link(struct vop_ops *ops, struct vnode *tdvp,
605 struct vnode *vp, struct componentname *cnp)
607 struct vop_old_link_args ap;
611 ap.a_head.a_desc = &vop_old_link_desc;
612 ap.a_head.a_ops = ops;
617 VFS_MPLOCK1(tdvp->v_mount);
618 DO_OPS(ops, error, &ap, vop_old_link);
619 VFS_MPUNLOCK(tdvp->v_mount);
627 vop_old_rename(struct vop_ops *ops,
628 struct vnode *fdvp, struct vnode *fvp, struct componentname *fcnp,
629 struct vnode *tdvp, struct vnode *tvp, struct componentname *tcnp)
631 struct vop_old_rename_args ap;
635 ap.a_head.a_desc = &vop_old_rename_desc;
636 ap.a_head.a_ops = ops;
644 VFS_MPLOCK1(tdvp->v_mount);
645 DO_OPS(ops, error, &ap, vop_old_rename);
646 VFS_MPUNLOCK(tdvp->v_mount);
654 vop_old_mkdir(struct vop_ops *ops, struct vnode *dvp,
655 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
657 struct vop_old_mkdir_args ap;
661 ap.a_head.a_desc = &vop_old_mkdir_desc;
662 ap.a_head.a_ops = ops;
668 VFS_MPLOCK1(dvp->v_mount);
669 DO_OPS(ops, error, &ap, vop_old_mkdir);
670 VFS_MPUNLOCK(dvp->v_mount);
678 vop_old_rmdir(struct vop_ops *ops, struct vnode *dvp,
679 struct vnode *vp, struct componentname *cnp)
681 struct vop_old_rmdir_args ap;
685 ap.a_head.a_desc = &vop_old_rmdir_desc;
686 ap.a_head.a_ops = ops;
691 VFS_MPLOCK1(dvp->v_mount);
692 DO_OPS(ops, error, &ap, vop_old_rmdir);
693 VFS_MPUNLOCK(dvp->v_mount);
701 vop_old_symlink(struct vop_ops *ops, struct vnode *dvp,
702 struct vnode **vpp, struct componentname *cnp,
703 struct vattr *vap, char *target)
705 struct vop_old_symlink_args ap;
709 ap.a_head.a_desc = &vop_old_symlink_desc;
710 ap.a_head.a_ops = ops;
715 ap.a_target = target;
717 VFS_MPLOCK1(dvp->v_mount);
718 DO_OPS(ops, error, &ap, vop_old_symlink);
719 VFS_MPUNLOCK(dvp->v_mount);
727 vop_readdir(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
728 struct ucred *cred, int *eofflag, int *ncookies, off_t **cookies)
730 struct vop_readdir_args ap;
734 ap.a_head.a_desc = &vop_readdir_desc;
735 ap.a_head.a_ops = ops;
739 ap.a_eofflag = eofflag;
740 ap.a_ncookies = ncookies;
741 ap.a_cookies = cookies;
743 VFS_MPLOCK1(vp->v_mount);
744 DO_OPS(ops, error, &ap, vop_readdir);
745 VFS_MPUNLOCK(vp->v_mount);
753 vop_readlink(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
756 struct vop_readlink_args ap;
760 ap.a_head.a_desc = &vop_readlink_desc;
761 ap.a_head.a_ops = ops;
766 VFS_MPLOCK1(vp->v_mount);
767 DO_OPS(ops, error, &ap, vop_readlink);
768 VFS_MPUNLOCK(vp->v_mount);
776 vop_inactive(struct vop_ops *ops, struct vnode *vp)
778 struct vop_inactive_args ap;
783 ap.a_head.a_desc = &vop_inactive_desc;
784 ap.a_head.a_ops = ops;
788 * WARNING! Deactivation of the vnode can cause it to be recycled,
789 * clearing vp->v_mount.
792 VFS_MPLOCK_FLAG(mp, MNTK_IN_MPSAFE);
793 DO_OPS(ops, error, &ap, vop_inactive);
802 vop_reclaim(struct vop_ops *ops, struct vnode *vp)
804 struct vop_reclaim_args ap;
809 ap.a_head.a_desc = &vop_reclaim_desc;
810 ap.a_head.a_ops = ops;
814 * WARNING! Reclamation of the vnode will clear vp->v_mount.
818 DO_OPS(ops, error, &ap, vop_reclaim);
827 vop_bmap(struct vop_ops *ops, struct vnode *vp, off_t loffset,
828 off_t *doffsetp, int *runp, int *runb, buf_cmd_t cmd)
830 struct vop_bmap_args ap;
834 ap.a_head.a_desc = &vop_bmap_desc;
835 ap.a_head.a_ops = ops;
837 ap.a_loffset = loffset;
838 ap.a_doffsetp = doffsetp;
843 VFS_MPLOCK1(vp->v_mount);
844 DO_OPS(ops, error, &ap, vop_bmap);
845 VFS_MPUNLOCK(vp->v_mount);
853 vop_strategy(struct vop_ops *ops, struct vnode *vp, struct bio *bio)
855 struct vop_strategy_args ap;
859 ap.a_head.a_desc = &vop_strategy_desc;
860 ap.a_head.a_ops = ops;
865 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_SG_MPSAFE);
866 DO_OPS(ops, error, &ap, vop_strategy);
867 VFS_MPUNLOCK(vp->v_mount);
869 /* ugly hack for swap */
871 DO_OPS(ops, error, &ap, vop_strategy);
881 vop_print(struct vop_ops *ops, struct vnode *vp)
883 struct vop_print_args ap;
887 ap.a_head.a_desc = &vop_print_desc;
888 ap.a_head.a_ops = ops;
891 VFS_MPLOCK1(vp->v_mount);
892 DO_OPS(ops, error, &ap, vop_print);
893 VFS_MPUNLOCK(vp->v_mount);
901 vop_pathconf(struct vop_ops *ops, struct vnode *vp, int name,
904 struct vop_pathconf_args ap;
908 ap.a_head.a_desc = &vop_pathconf_desc;
909 ap.a_head.a_ops = ops;
912 ap.a_retval = retval;
914 VFS_MPLOCK1(vp->v_mount);
915 DO_OPS(ops, error, &ap, vop_pathconf);
916 VFS_MPUNLOCK(vp->v_mount);
924 vop_advlock(struct vop_ops *ops, struct vnode *vp, caddr_t id, int op,
925 struct flock *fl, int flags)
927 struct vop_advlock_args ap;
931 ap.a_head.a_desc = &vop_advlock_desc;
932 ap.a_head.a_ops = ops;
939 VFS_MPLOCK1(vp->v_mount);
940 DO_OPS(ops, error, &ap, vop_advlock);
941 VFS_MPUNLOCK(vp->v_mount);
949 vop_balloc(struct vop_ops *ops, struct vnode *vp, off_t startoffset,
950 int size, struct ucred *cred, int flags,
953 struct vop_balloc_args ap;
957 ap.a_head.a_desc = &vop_balloc_desc;
958 ap.a_head.a_ops = ops;
960 ap.a_startoffset = startoffset;
966 VFS_MPLOCK1(vp->v_mount);
967 DO_OPS(ops, error, &ap, vop_balloc);
968 VFS_MPUNLOCK(vp->v_mount);
976 vop_reallocblks(struct vop_ops *ops, struct vnode *vp,
977 struct cluster_save *buflist)
979 struct vop_reallocblks_args ap;
983 ap.a_head.a_desc = &vop_reallocblks_desc;
984 ap.a_head.a_ops = ops;
986 ap.a_buflist = buflist;
988 VFS_MPLOCK1(vp->v_mount);
989 DO_OPS(ops, error, &ap, vop_reallocblks);
990 VFS_MPUNLOCK(vp->v_mount);
998 vop_getpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
999 int reqpage, vm_ooffset_t offset, int seqaccess)
1001 struct vop_getpages_args ap;
1005 ap.a_head.a_desc = &vop_getpages_desc;
1006 ap.a_head.a_ops = ops;
1010 ap.a_reqpage = reqpage;
1011 ap.a_offset = offset;
1012 ap.a_seqaccess = seqaccess;
1014 VFS_MPLOCK1(vp->v_mount);
1015 DO_OPS(ops, error, &ap, vop_getpages);
1016 VFS_MPUNLOCK(vp->v_mount);
1024 vop_putpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
1025 int sync, int *rtvals, vm_ooffset_t offset)
1027 struct vop_putpages_args ap;
1031 ap.a_head.a_desc = &vop_putpages_desc;
1032 ap.a_head.a_ops = ops;
1037 ap.a_rtvals = rtvals;
1038 ap.a_offset = offset;
1040 VFS_MPLOCK1(vp->v_mount);
1041 DO_OPS(ops, error, &ap, vop_putpages);
1042 VFS_MPUNLOCK(vp->v_mount);
1050 vop_freeblks(struct vop_ops *ops, struct vnode *vp, off_t offset, int length)
1052 struct vop_freeblks_args ap;
1056 ap.a_head.a_desc = &vop_freeblks_desc;
1057 ap.a_head.a_ops = ops;
1059 ap.a_offset = offset;
1060 ap.a_length = length;
1062 VFS_MPLOCK1(vp->v_mount);
1063 DO_OPS(ops, error, &ap, vop_freeblks);
1064 VFS_MPUNLOCK(vp->v_mount);
1072 vop_getacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1073 struct acl *aclp, struct ucred *cred)
1075 struct vop_getacl_args ap;
1079 ap.a_head.a_desc = &vop_getacl_desc;
1080 ap.a_head.a_ops = ops;
1086 VFS_MPLOCK1(vp->v_mount);
1087 DO_OPS(ops, error, &ap, vop_getacl);
1088 VFS_MPUNLOCK(vp->v_mount);
1096 vop_setacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1097 struct acl *aclp, struct ucred *cred)
1099 struct vop_setacl_args ap;
1103 ap.a_head.a_desc = &vop_setacl_desc;
1104 ap.a_head.a_ops = ops;
1110 VFS_MPLOCK1(vp->v_mount);
1111 DO_OPS(ops, error, &ap, vop_setacl);
1112 VFS_MPUNLOCK(vp->v_mount);
1120 vop_aclcheck(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1121 struct acl *aclp, struct ucred *cred)
1123 struct vop_aclcheck_args ap;
1127 ap.a_head.a_desc = &vop_aclcheck_desc;
1128 ap.a_head.a_ops = ops;
1134 VFS_MPLOCK1(vp->v_mount);
1135 DO_OPS(ops, error, &ap, vop_aclcheck);
1136 VFS_MPUNLOCK(vp->v_mount);
1144 vop_getextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1145 char *attrname, struct uio *uio, struct ucred *cred)
1147 struct vop_getextattr_args ap;
1151 ap.a_head.a_desc = &vop_getextattr_desc;
1152 ap.a_head.a_ops = ops;
1154 ap.a_attrnamespace = attrnamespace;
1155 ap.a_attrname = attrname;
1159 VFS_MPLOCK1(vp->v_mount);
1160 DO_OPS(ops, error, &ap, vop_getextattr);
1161 VFS_MPUNLOCK(vp->v_mount);
1169 vop_setextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1170 char *attrname, struct uio *uio, struct ucred *cred)
1172 struct vop_setextattr_args ap;
1176 ap.a_head.a_desc = &vop_setextattr_desc;
1177 ap.a_head.a_ops = ops;
1179 ap.a_attrnamespace = attrnamespace;
1180 ap.a_attrname = attrname;
1184 VFS_MPLOCK1(vp->v_mount);
1185 DO_OPS(ops, error, &ap, vop_setextattr);
1186 VFS_MPUNLOCK(vp->v_mount);
1194 vop_mountctl(struct vop_ops *ops, struct vnode *vp, int op, struct file *fp,
1195 const void *ctl, int ctllen, void *buf, int buflen, int *res)
1197 struct vop_mountctl_args ap;
1201 ap.a_head.a_desc = &vop_mountctl_desc;
1202 ap.a_head.a_ops = ops;
1206 ap.a_ctllen = ctllen;
1208 ap.a_buflen = buflen;
1211 VFS_MPLOCK1(vp->v_mount);
1212 DO_OPS(ops, error, &ap, vop_mountctl);
1213 VFS_MPUNLOCK(vp->v_mount);
1221 vop_markatime(struct vop_ops *ops, struct vnode *vp, struct ucred *cred)
1223 struct vop_markatime_args ap;
1227 ap.a_head.a_desc = &vop_markatime_desc;
1228 ap.a_head.a_ops = ops;
1232 VFS_MPLOCK1(vp->v_mount);
1233 DO_OPS(ops, error, &ap, vop_markatime);
1234 VFS_MPUNLOCK(vp->v_mount);
1241 * nresolve takes a locked ncp, a referenced but unlocked dvp, and a cred,
1242 * and resolves the ncp into a positive or negative hit.
1244 * The namecache is automatically adjusted by this function. The ncp
1245 * is left locked on return.
1250 vop_nresolve(struct vop_ops *ops, struct nchandle *nch,
1251 struct vnode *dvp, struct ucred *cred)
1253 struct vop_nresolve_args ap;
1257 ap.a_head.a_desc = &vop_nresolve_desc;
1258 ap.a_head.a_ops = ops;
1263 VFS_MPLOCK1(dvp->v_mount);
1264 DO_OPS(ops, error, &ap, vop_nresolve);
1265 VFS_MPUNLOCK(dvp->v_mount);
1270 * nlookupdotdot takes an unlocked directory, referenced dvp, and looks
1271 * up "..", returning a locked parent directory in *vpp. If an error
1272 * occurs *vpp will be NULL.
1277 vop_nlookupdotdot(struct vop_ops *ops, struct vnode *dvp,
1278 struct vnode **vpp, struct ucred *cred, char **fakename)
1280 struct vop_nlookupdotdot_args ap;
1284 ap.a_head.a_desc = &vop_nlookupdotdot_desc;
1285 ap.a_head.a_ops = ops;
1289 ap.a_fakename = fakename;
1291 VFS_MPLOCK1(dvp->v_mount);
1292 DO_OPS(ops, error, &ap, vop_nlookupdotdot);
1293 VFS_MPUNLOCK(dvp->v_mount);
1298 * ncreate takes a locked, resolved ncp that typically represents a negative
1299 * cache hit and creates the file or node specified by the ncp, cred, and
1300 * vattr. If no error occurs a locked vnode is returned in *vpp.
1302 * The dvp passed in is referenced but unlocked.
1304 * The namecache is automatically adjusted by this function. The ncp
1305 * is left locked on return.
1310 vop_ncreate(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1311 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1313 struct vop_ncreate_args ap;
1317 ap.a_head.a_desc = &vop_ncreate_desc;
1318 ap.a_head.a_ops = ops;
1325 VFS_MPLOCK1(dvp->v_mount);
1326 DO_OPS(ops, error, &ap, vop_ncreate);
1327 VFS_MPUNLOCK(dvp->v_mount);
1332 * nmkdir takes a locked, resolved ncp that typically represents a negative
1333 * cache hit and creates the directory specified by the ncp, cred, and
1334 * vattr. If no error occurs a locked vnode is returned in *vpp.
1336 * The dvp passed in is referenced but unlocked.
1338 * The namecache is automatically adjusted by this function. The ncp
1339 * is left locked on return.
1344 vop_nmkdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1345 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1347 struct vop_nmkdir_args ap;
1351 ap.a_head.a_desc = &vop_nmkdir_desc;
1352 ap.a_head.a_ops = ops;
1359 VFS_MPLOCK1(dvp->v_mount);
1360 DO_OPS(ops, error, &ap, vop_nmkdir);
1361 VFS_MPUNLOCK(dvp->v_mount);
1366 * nmknod takes a locked, resolved ncp that typically represents a negative
1367 * cache hit and creates the node specified by the ncp, cred, and
1368 * vattr. If no error occurs a locked vnode is returned in *vpp.
1370 * The dvp passed in is referenced but unlocked.
1372 * The namecache is automatically adjusted by this function. The ncp
1373 * is left locked on return.
1378 vop_nmknod(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1379 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1381 struct vop_nmknod_args ap;
1385 ap.a_head.a_desc = &vop_nmknod_desc;
1386 ap.a_head.a_ops = ops;
1393 VFS_MPLOCK1(dvp->v_mount);
1394 DO_OPS(ops, error, &ap, vop_nmknod);
1395 VFS_MPUNLOCK(dvp->v_mount);
1400 * nlink takes a locked, resolved ncp that typically represents a negative
1401 * cache hit and creates the node specified by the ncp, cred, and
1402 * existing vnode. The passed vp must be locked and will remain locked
1403 * on return, as does the ncp, whether an error occurs or not.
1405 * The dvp passed in is referenced but unlocked.
1407 * The namecache is automatically adjusted by this function. The ncp
1408 * is left locked on return.
1413 vop_nlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1414 struct vnode *vp, struct ucred *cred)
1416 struct vop_nlink_args ap;
1420 ap.a_head.a_desc = &vop_nlink_desc;
1421 ap.a_head.a_ops = ops;
1427 VFS_MPLOCK1(dvp->v_mount);
1428 DO_OPS(ops, error, &ap, vop_nlink);
1429 VFS_MPUNLOCK(dvp->v_mount);
1434 * nsymlink takes a locked, resolved ncp that typically represents a negative
1435 * cache hit and creates a symbolic link based on cred, vap, and target (the
1436 * contents of the link). If no error occurs a locked vnode is returned in
1439 * The dvp passed in is referenced but unlocked.
1441 * The namecache is automatically adjusted by this function. The ncp
1442 * is left locked on return.
1447 vop_nsymlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1448 struct vnode **vpp, struct ucred *cred,
1449 struct vattr *vap, char *target)
1451 struct vop_nsymlink_args ap;
1455 ap.a_head.a_desc = &vop_nsymlink_desc;
1456 ap.a_head.a_ops = ops;
1462 ap.a_target = target;
1464 VFS_MPLOCK1(dvp->v_mount);
1465 DO_OPS(ops, error, &ap, vop_nsymlink);
1466 VFS_MPUNLOCK(dvp->v_mount);
1471 * nwhiteout takes a locked, resolved ncp that can represent a positive or
1472 * negative hit and executes the whiteout function specified in flags.
1474 * The dvp passed in is referenced but unlocked.
1476 * The namecache is automatically adjusted by this function. The ncp
1477 * is left locked on return.
1482 vop_nwhiteout(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1483 struct ucred *cred, int flags)
1485 struct vop_nwhiteout_args ap;
1489 ap.a_head.a_desc = &vop_nwhiteout_desc;
1490 ap.a_head.a_ops = ops;
1496 VFS_MPLOCK1(dvp->v_mount);
1497 DO_OPS(ops, error, &ap, vop_nwhiteout);
1498 VFS_MPUNLOCK(dvp->v_mount);
1503 * nremove takes a locked, resolved ncp that generally represents a
1504 * positive hit and removes the file.
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_nremove(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1517 struct vop_nremove_args ap;
1522 ap.a_head.a_desc = &vop_nremove_desc;
1523 ap.a_head.a_ops = ops;
1528 if ((error = VOP_GETATTR(nch->ncp->nc_vp, &va)) != 0)
1531 VFS_MPLOCK1(dvp->v_mount);
1532 DO_OPS(ops, error, &ap, vop_nremove);
1533 /* Only update space counters if this is the last hard link */
1534 if ((error == 0) && (va.va_nlink == 1)) {
1535 VFS_ACCOUNT(nch->mount, va.va_uid, va.va_gid, -va.va_size);
1537 VFS_MPUNLOCK(dvp->v_mount);
1542 * nrmdir takes a locked, resolved ncp that generally represents a
1543 * directory and removes the directory.
1545 * The dvp passed in is referenced but unlocked.
1547 * The namecache is automatically adjusted by this function. The ncp
1548 * is left locked on return.
1553 vop_nrmdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1556 struct vop_nrmdir_args ap;
1560 ap.a_head.a_desc = &vop_nrmdir_desc;
1561 ap.a_head.a_ops = ops;
1566 VFS_MPLOCK1(dvp->v_mount);
1567 DO_OPS(ops, error, &ap, vop_nrmdir);
1568 VFS_MPUNLOCK(dvp->v_mount);
1573 * nrename takes TWO locked, resolved ncp's and the cred of the caller
1574 * and renames the source ncp to the target ncp. The target ncp may
1575 * represent a positive or negative hit.
1577 * The fdvp and tdvp passed in are referenced but unlocked.
1579 * The namecache is automatically adjusted by this function. The ncp
1580 * is left locked on return. The source ncp is typically changed to
1581 * a negative cache hit and the target ncp typically takes on the
1582 * source ncp's underlying file.
1587 vop_nrename(struct vop_ops *ops,
1588 struct nchandle *fnch, struct nchandle *tnch,
1589 struct vnode *fdvp, struct vnode *tdvp,
1592 struct vop_nrename_args ap;
1596 ap.a_head.a_desc = &vop_nrename_desc;
1597 ap.a_head.a_ops = ops;
1604 VFS_MPLOCK1(fdvp->v_mount);
1605 DO_OPS(ops, error, &ap, vop_nrename);
1606 VFS_MPUNLOCK(fdvp->v_mount);
1610 /************************************************************************
1611 * PRIMARY VNODE OPERATIONS FORWARDING CALLS *
1612 ************************************************************************
1614 * These procedures are called from VFSs such as unionfs and nullfs
1615 * when they wish to forward an operation on one VFS to another. The
1616 * argument structure/message is modified and then directly passed to the
1617 * appropriate routine. This routines may also be called by initiators
1618 * who have an argument structure in hand rather then discreet arguments.
1620 * MPSAFE - Caller expected to already hold the appropriate vfs lock.
1623 vop_vnoperate_ap(struct vop_generic_args *ap)
1625 struct vop_ops *ops;
1629 error = VOCALL(ops, ap);
1635 * This routine is called by the cache coherency layer to execute the actual
1636 * VFS operation. If a journaling layer is present we call though it, else
1637 * we call the native VOP functions.
1640 vop_cache_operate_ap(struct vop_generic_args *ap)
1642 struct vop_ops *ops;
1646 if (ops->head.vv_mount->mnt_vn_journal_ops)
1647 error = VOCALL(ops->head.vv_mount->mnt_vn_journal_ops, ap);
1649 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1655 * This routine is called by the journaling layer to execute the actual
1659 vop_journal_operate_ap(struct vop_generic_args *ap)
1661 struct vop_ops *ops;
1665 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1671 vop_open_ap(struct vop_open_args *ap)
1675 DO_OPS(ap->a_head.a_ops, error, ap, vop_open);
1680 vop_close_ap(struct vop_close_args *ap)
1684 DO_OPS(ap->a_head.a_ops, error, ap, vop_close);
1689 vop_access_ap(struct vop_access_args *ap)
1693 DO_OPS(ap->a_head.a_ops, error, ap, vop_access);
1698 vop_getattr_ap(struct vop_getattr_args *ap)
1702 DO_OPS(ap->a_head.a_ops, error, ap, vop_getattr);
1707 vop_setattr_ap(struct vop_setattr_args *ap)
1711 DO_OPS(ap->a_head.a_ops, error, ap, vop_setattr);
1716 vop_read_ap(struct vop_read_args *ap)
1720 DO_OPS(ap->a_head.a_ops, error, ap, vop_read);
1725 vop_write_ap(struct vop_write_args *ap)
1729 DO_OPS(ap->a_head.a_ops, error, ap, vop_write);
1734 vop_ioctl_ap(struct vop_ioctl_args *ap)
1738 DO_OPS(ap->a_head.a_ops, error, ap, vop_ioctl);
1743 vop_poll_ap(struct vop_poll_args *ap)
1747 DO_OPS(ap->a_head.a_ops, error, ap, vop_poll);
1752 vop_kqfilter_ap(struct vop_kqfilter_args *ap)
1756 DO_OPS(ap->a_head.a_ops, error, ap, vop_kqfilter);
1761 vop_mmap_ap(struct vop_mmap_args *ap)
1765 DO_OPS(ap->a_head.a_ops, error, ap, vop_mmap);
1770 vop_fsync_ap(struct vop_fsync_args *ap)
1774 DO_OPS(ap->a_head.a_ops, error, ap, vop_fsync);
1779 vop_readdir_ap(struct vop_readdir_args *ap)
1783 DO_OPS(ap->a_head.a_ops, error, ap, vop_readdir);
1788 vop_readlink_ap(struct vop_readlink_args *ap)
1792 DO_OPS(ap->a_head.a_ops, error, ap, vop_readlink);
1797 vop_inactive_ap(struct vop_inactive_args *ap)
1801 DO_OPS(ap->a_head.a_ops, error, ap, vop_inactive);
1806 vop_reclaim_ap(struct vop_reclaim_args *ap)
1810 DO_OPS(ap->a_head.a_ops, error, ap, vop_reclaim);
1815 vop_bmap_ap(struct vop_bmap_args *ap)
1819 DO_OPS(ap->a_head.a_ops, error, ap, vop_bmap);
1824 vop_strategy_ap(struct vop_strategy_args *ap)
1828 DO_OPS(ap->a_head.a_ops, error, ap, vop_strategy);
1833 vop_print_ap(struct vop_print_args *ap)
1837 DO_OPS(ap->a_head.a_ops, error, ap, vop_print);
1842 vop_pathconf_ap(struct vop_pathconf_args *ap)
1846 DO_OPS(ap->a_head.a_ops, error, ap, vop_pathconf);
1851 vop_advlock_ap(struct vop_advlock_args *ap)
1855 DO_OPS(ap->a_head.a_ops, error, ap, vop_advlock);
1860 vop_balloc_ap(struct vop_balloc_args *ap)
1864 DO_OPS(ap->a_head.a_ops, error, ap, vop_balloc);
1869 vop_reallocblks_ap(struct vop_reallocblks_args *ap)
1873 DO_OPS(ap->a_head.a_ops, error, ap, vop_reallocblks);
1878 vop_getpages_ap(struct vop_getpages_args *ap)
1882 DO_OPS(ap->a_head.a_ops, error, ap, vop_getpages);
1887 vop_putpages_ap(struct vop_putpages_args *ap)
1891 DO_OPS(ap->a_head.a_ops, error, ap, vop_putpages);
1896 vop_freeblks_ap(struct vop_freeblks_args *ap)
1900 DO_OPS(ap->a_head.a_ops, error, ap, vop_freeblks);
1905 vop_getacl_ap(struct vop_getacl_args *ap)
1909 DO_OPS(ap->a_head.a_ops, error, ap, vop_getacl);
1914 vop_setacl_ap(struct vop_setacl_args *ap)
1918 DO_OPS(ap->a_head.a_ops, error, ap, vop_setacl);
1923 vop_aclcheck_ap(struct vop_aclcheck_args *ap)
1927 DO_OPS(ap->a_head.a_ops, error, ap, vop_aclcheck);
1932 vop_getextattr_ap(struct vop_getextattr_args *ap)
1936 DO_OPS(ap->a_head.a_ops, error, ap, vop_getextattr);
1941 vop_setextattr_ap(struct vop_setextattr_args *ap)
1945 DO_OPS(ap->a_head.a_ops, error, ap, vop_setextattr);
1950 vop_mountctl_ap(struct vop_mountctl_args *ap)
1954 DO_OPS(ap->a_head.a_ops, error, ap, vop_mountctl);
1959 vop_markatime_ap(struct vop_markatime_args *ap)
1963 DO_OPS(ap->a_head.a_ops, error, ap, vop_markatime);
1968 vop_nresolve_ap(struct vop_nresolve_args *ap)
1972 DO_OPS(ap->a_head.a_ops, error, ap, vop_nresolve);
1977 vop_nlookupdotdot_ap(struct vop_nlookupdotdot_args *ap)
1981 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlookupdotdot);
1986 vop_ncreate_ap(struct vop_ncreate_args *ap)
1990 DO_OPS(ap->a_head.a_ops, error, ap, vop_ncreate);
1995 vop_nmkdir_ap(struct vop_nmkdir_args *ap)
1999 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmkdir);
2004 vop_nmknod_ap(struct vop_nmknod_args *ap)
2008 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmknod);
2013 vop_nlink_ap(struct vop_nlink_args *ap)
2017 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlink);
2022 vop_nsymlink_ap(struct vop_nsymlink_args *ap)
2026 DO_OPS(ap->a_head.a_ops, error, ap, vop_nsymlink);
2031 vop_nwhiteout_ap(struct vop_nwhiteout_args *ap)
2035 DO_OPS(ap->a_head.a_ops, error, ap, vop_nwhiteout);
2040 vop_nremove_ap(struct vop_nremove_args *ap)
2044 DO_OPS(ap->a_head.a_ops, error, ap, vop_nremove);
2049 vop_nrmdir_ap(struct vop_nrmdir_args *ap)
2053 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrmdir);
2058 vop_nrename_ap(struct vop_nrename_args *ap)
2062 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrename);