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,
302 struct vop_close_args ap;
306 ap.a_head.a_desc = &vop_close_desc;
307 ap.a_head.a_ops = ops;
312 VFS_MPLOCK1(vp->v_mount);
313 DO_OPS(ops, error, &ap, vop_close);
314 VFS_MPUNLOCK(vp->v_mount);
322 vop_access(struct vop_ops *ops, struct vnode *vp, int mode, int flags,
325 struct vop_access_args ap;
329 ap.a_head.a_desc = &vop_access_desc;
330 ap.a_head.a_ops = ops;
336 VFS_MPLOCK1(vp->v_mount);
337 DO_OPS(ops, error, &ap, vop_access);
338 VFS_MPUNLOCK(vp->v_mount);
346 vop_getattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap)
348 struct vop_getattr_args ap;
352 ap.a_head.a_desc = &vop_getattr_desc;
353 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,
371 struct vop_setattr_args ap;
375 ap.a_head.a_desc = &vop_setattr_desc;
376 ap.a_head.a_ops = ops;
381 VFS_MPLOCK1(vp->v_mount);
382 DO_OPS(ops, error, &ap, vop_setattr);
383 VFS_MPUNLOCK(vp->v_mount);
391 vop_read(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
394 struct vop_read_args ap;
398 ap.a_head.a_desc = &vop_read_desc;
399 ap.a_head.a_ops = ops;
402 ap.a_ioflag = ioflag;
405 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_RD_MPSAFE);
406 DO_OPS(ops, error, &ap, vop_read);
407 VFS_MPUNLOCK(vp->v_mount);
415 vop_write(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
418 struct vop_write_args ap;
420 int error, do_accounting = 0;
422 uint64_t size_before=0, size_after=0;
424 uint64_t offset, delta;
426 ap.a_head.a_desc = &vop_write_desc;
427 ap.a_head.a_ops = ops;
430 ap.a_ioflag = ioflag;
433 /* is this a regular vnode ? */
434 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_WR_MPSAFE);
435 if (vfs_quota_enabled && (vp->v_type == VREG)) {
436 if ((error = VOP_GETATTR(vp, &va)) != 0)
438 size_before = va.va_size;
439 /* this file may already have been removed */
443 offset = uio->uio_offset;
444 if (ioflag & IO_APPEND)
445 offset = size_before;
446 size_after = offset + uio->uio_resid;
447 if (size_after < size_before)
448 size_after = size_before;
449 delta = size_after - size_before;
452 if (!vq_write_ok(mp, va.va_uid, va.va_gid, delta)) {
457 DO_OPS(ops, error, &ap, vop_write);
458 if ((error == 0) && do_accounting) {
459 VFS_ACCOUNT(mp, va.va_uid, va.va_gid, size_after - size_before);
462 VFS_MPUNLOCK(vp->v_mount);
470 vop_ioctl(struct vop_ops *ops, struct vnode *vp, u_long command, caddr_t data,
471 int fflag, struct ucred *cred, struct sysmsg *msg)
473 struct vop_ioctl_args ap;
477 ap.a_head.a_desc = &vop_ioctl_desc;
478 ap.a_head.a_ops = ops;
480 ap.a_command = command;
486 VFS_MPLOCK1(vp->v_mount);
487 DO_OPS(ops, error, &ap, vop_ioctl);
488 VFS_MPUNLOCK(vp->v_mount);
496 vop_poll(struct vop_ops *ops, struct vnode *vp, int events, struct ucred *cred)
498 struct vop_poll_args ap;
502 ap.a_head.a_desc = &vop_poll_desc;
503 ap.a_head.a_ops = ops;
505 ap.a_events = events;
508 VFS_MPLOCK1(vp->v_mount);
509 DO_OPS(ops, error, &ap, vop_poll);
510 VFS_MPUNLOCK(vp->v_mount);
518 vop_kqfilter(struct vop_ops *ops, struct vnode *vp, struct knote *kn)
520 struct vop_kqfilter_args ap;
524 ap.a_head.a_desc = &vop_kqfilter_desc;
525 ap.a_head.a_ops = ops;
529 VFS_MPLOCK1(vp->v_mount);
530 DO_OPS(ops, error, &ap, vop_kqfilter);
531 VFS_MPUNLOCK(vp->v_mount);
539 vop_mmap(struct vop_ops *ops, struct vnode *vp, int fflags, struct ucred *cred)
541 struct vop_mmap_args ap;
545 ap.a_head.a_desc = &vop_mmap_desc;
546 ap.a_head.a_ops = ops;
548 ap.a_fflags = fflags;
551 VFS_MPLOCK1(vp->v_mount);
552 DO_OPS(ops, error, &ap, vop_mmap);
553 VFS_MPUNLOCK(vp->v_mount);
561 vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor, int flags)
563 struct vop_fsync_args ap;
567 ap.a_head.a_desc = &vop_fsync_desc;
568 ap.a_head.a_ops = ops;
570 ap.a_waitfor = waitfor;
573 VFS_MPLOCK1(vp->v_mount);
574 DO_OPS(ops, error, &ap, vop_fsync);
575 VFS_MPUNLOCK(vp->v_mount);
583 vop_old_remove(struct vop_ops *ops, struct vnode *dvp,
584 struct vnode *vp, struct componentname *cnp)
586 struct vop_old_remove_args ap;
590 ap.a_head.a_desc = &vop_old_remove_desc;
591 ap.a_head.a_ops = ops;
596 VFS_MPLOCK1(dvp->v_mount);
597 DO_OPS(ops, error, &ap, vop_old_remove);
598 VFS_MPUNLOCK(dvp->v_mount);
606 vop_old_link(struct vop_ops *ops, struct vnode *tdvp,
607 struct vnode *vp, struct componentname *cnp)
609 struct vop_old_link_args ap;
613 ap.a_head.a_desc = &vop_old_link_desc;
614 ap.a_head.a_ops = ops;
619 VFS_MPLOCK1(tdvp->v_mount);
620 DO_OPS(ops, error, &ap, vop_old_link);
621 VFS_MPUNLOCK(tdvp->v_mount);
629 vop_old_rename(struct vop_ops *ops,
630 struct vnode *fdvp, struct vnode *fvp, struct componentname *fcnp,
631 struct vnode *tdvp, struct vnode *tvp, struct componentname *tcnp)
633 struct vop_old_rename_args ap;
637 ap.a_head.a_desc = &vop_old_rename_desc;
638 ap.a_head.a_ops = ops;
646 VFS_MPLOCK1(tdvp->v_mount);
647 DO_OPS(ops, error, &ap, vop_old_rename);
648 VFS_MPUNLOCK(tdvp->v_mount);
656 vop_old_mkdir(struct vop_ops *ops, struct vnode *dvp,
657 struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
659 struct vop_old_mkdir_args ap;
663 ap.a_head.a_desc = &vop_old_mkdir_desc;
664 ap.a_head.a_ops = ops;
670 VFS_MPLOCK1(dvp->v_mount);
671 DO_OPS(ops, error, &ap, vop_old_mkdir);
672 VFS_MPUNLOCK(dvp->v_mount);
680 vop_old_rmdir(struct vop_ops *ops, struct vnode *dvp,
681 struct vnode *vp, struct componentname *cnp)
683 struct vop_old_rmdir_args ap;
687 ap.a_head.a_desc = &vop_old_rmdir_desc;
688 ap.a_head.a_ops = ops;
693 VFS_MPLOCK1(dvp->v_mount);
694 DO_OPS(ops, error, &ap, vop_old_rmdir);
695 VFS_MPUNLOCK(dvp->v_mount);
703 vop_old_symlink(struct vop_ops *ops, struct vnode *dvp,
704 struct vnode **vpp, struct componentname *cnp,
705 struct vattr *vap, char *target)
707 struct vop_old_symlink_args ap;
711 ap.a_head.a_desc = &vop_old_symlink_desc;
712 ap.a_head.a_ops = ops;
717 ap.a_target = target;
719 VFS_MPLOCK1(dvp->v_mount);
720 DO_OPS(ops, error, &ap, vop_old_symlink);
721 VFS_MPUNLOCK(dvp->v_mount);
729 vop_readdir(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
730 struct ucred *cred, int *eofflag, int *ncookies, off_t **cookies)
732 struct vop_readdir_args ap;
736 ap.a_head.a_desc = &vop_readdir_desc;
737 ap.a_head.a_ops = ops;
741 ap.a_eofflag = eofflag;
742 ap.a_ncookies = ncookies;
743 ap.a_cookies = cookies;
745 VFS_MPLOCK1(vp->v_mount);
746 DO_OPS(ops, error, &ap, vop_readdir);
747 VFS_MPUNLOCK(vp->v_mount);
755 vop_readlink(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
758 struct vop_readlink_args ap;
762 ap.a_head.a_desc = &vop_readlink_desc;
763 ap.a_head.a_ops = ops;
768 VFS_MPLOCK1(vp->v_mount);
769 DO_OPS(ops, error, &ap, vop_readlink);
770 VFS_MPUNLOCK(vp->v_mount);
778 vop_inactive(struct vop_ops *ops, struct vnode *vp)
780 struct vop_inactive_args ap;
785 ap.a_head.a_desc = &vop_inactive_desc;
786 ap.a_head.a_ops = ops;
790 * WARNING! Deactivation of the vnode can cause it to be recycled,
791 * clearing vp->v_mount.
794 VFS_MPLOCK_FLAG(mp, MNTK_IN_MPSAFE);
795 DO_OPS(ops, error, &ap, vop_inactive);
804 vop_reclaim(struct vop_ops *ops, struct vnode *vp)
806 struct vop_reclaim_args ap;
811 ap.a_head.a_desc = &vop_reclaim_desc;
812 ap.a_head.a_ops = ops;
816 * WARNING! Reclamation of the vnode will clear vp->v_mount.
820 DO_OPS(ops, error, &ap, vop_reclaim);
829 vop_bmap(struct vop_ops *ops, struct vnode *vp, off_t loffset,
830 off_t *doffsetp, int *runp, int *runb, buf_cmd_t cmd)
832 struct vop_bmap_args ap;
836 ap.a_head.a_desc = &vop_bmap_desc;
837 ap.a_head.a_ops = ops;
839 ap.a_loffset = loffset;
840 ap.a_doffsetp = doffsetp;
845 VFS_MPLOCK1(vp->v_mount);
846 DO_OPS(ops, error, &ap, vop_bmap);
847 VFS_MPUNLOCK(vp->v_mount);
855 vop_strategy(struct vop_ops *ops, struct vnode *vp, struct bio *bio)
857 struct vop_strategy_args ap;
861 ap.a_head.a_desc = &vop_strategy_desc;
862 ap.a_head.a_ops = ops;
867 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_SG_MPSAFE);
868 DO_OPS(ops, error, &ap, vop_strategy);
869 VFS_MPUNLOCK(vp->v_mount);
871 /* ugly hack for swap */
873 DO_OPS(ops, error, &ap, vop_strategy);
883 vop_print(struct vop_ops *ops, struct vnode *vp)
885 struct vop_print_args ap;
889 ap.a_head.a_desc = &vop_print_desc;
890 ap.a_head.a_ops = ops;
893 VFS_MPLOCK1(vp->v_mount);
894 DO_OPS(ops, error, &ap, vop_print);
895 VFS_MPUNLOCK(vp->v_mount);
903 vop_pathconf(struct vop_ops *ops, struct vnode *vp, int name,
906 struct vop_pathconf_args ap;
910 ap.a_head.a_desc = &vop_pathconf_desc;
911 ap.a_head.a_ops = ops;
914 ap.a_retval = retval;
916 VFS_MPLOCK1(vp->v_mount);
917 DO_OPS(ops, error, &ap, vop_pathconf);
918 VFS_MPUNLOCK(vp->v_mount);
926 vop_advlock(struct vop_ops *ops, struct vnode *vp, caddr_t id, int op,
927 struct flock *fl, int flags)
929 struct vop_advlock_args ap;
933 ap.a_head.a_desc = &vop_advlock_desc;
934 ap.a_head.a_ops = ops;
941 VFS_MPLOCK1(vp->v_mount);
942 DO_OPS(ops, error, &ap, vop_advlock);
943 VFS_MPUNLOCK(vp->v_mount);
951 vop_balloc(struct vop_ops *ops, struct vnode *vp, off_t startoffset,
952 int size, struct ucred *cred, int flags,
955 struct vop_balloc_args ap;
959 ap.a_head.a_desc = &vop_balloc_desc;
960 ap.a_head.a_ops = ops;
962 ap.a_startoffset = startoffset;
968 VFS_MPLOCK1(vp->v_mount);
969 DO_OPS(ops, error, &ap, vop_balloc);
970 VFS_MPUNLOCK(vp->v_mount);
978 vop_reallocblks(struct vop_ops *ops, struct vnode *vp,
979 struct cluster_save *buflist)
981 struct vop_reallocblks_args ap;
985 ap.a_head.a_desc = &vop_reallocblks_desc;
986 ap.a_head.a_ops = ops;
988 ap.a_buflist = buflist;
990 VFS_MPLOCK1(vp->v_mount);
991 DO_OPS(ops, error, &ap, vop_reallocblks);
992 VFS_MPUNLOCK(vp->v_mount);
1000 vop_getpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
1001 int reqpage, vm_ooffset_t offset, int seqaccess)
1003 struct vop_getpages_args ap;
1007 ap.a_head.a_desc = &vop_getpages_desc;
1008 ap.a_head.a_ops = ops;
1012 ap.a_reqpage = reqpage;
1013 ap.a_offset = offset;
1014 ap.a_seqaccess = seqaccess;
1016 VFS_MPLOCK1(vp->v_mount);
1017 DO_OPS(ops, error, &ap, vop_getpages);
1018 VFS_MPUNLOCK(vp->v_mount);
1026 vop_putpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
1027 int sync, int *rtvals, vm_ooffset_t offset)
1029 struct vop_putpages_args ap;
1033 ap.a_head.a_desc = &vop_putpages_desc;
1034 ap.a_head.a_ops = ops;
1039 ap.a_rtvals = rtvals;
1040 ap.a_offset = offset;
1042 VFS_MPLOCK1(vp->v_mount);
1043 DO_OPS(ops, error, &ap, vop_putpages);
1044 VFS_MPUNLOCK(vp->v_mount);
1052 vop_freeblks(struct vop_ops *ops, struct vnode *vp, off_t offset, int length)
1054 struct vop_freeblks_args ap;
1058 ap.a_head.a_desc = &vop_freeblks_desc;
1059 ap.a_head.a_ops = ops;
1061 ap.a_offset = offset;
1062 ap.a_length = length;
1064 VFS_MPLOCK1(vp->v_mount);
1065 DO_OPS(ops, error, &ap, vop_freeblks);
1066 VFS_MPUNLOCK(vp->v_mount);
1074 vop_getacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1075 struct acl *aclp, struct ucred *cred)
1077 struct vop_getacl_args ap;
1081 ap.a_head.a_desc = &vop_getacl_desc;
1082 ap.a_head.a_ops = ops;
1088 VFS_MPLOCK1(vp->v_mount);
1089 DO_OPS(ops, error, &ap, vop_getacl);
1090 VFS_MPUNLOCK(vp->v_mount);
1098 vop_setacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1099 struct acl *aclp, struct ucred *cred)
1101 struct vop_setacl_args ap;
1105 ap.a_head.a_desc = &vop_setacl_desc;
1106 ap.a_head.a_ops = ops;
1112 VFS_MPLOCK1(vp->v_mount);
1113 DO_OPS(ops, error, &ap, vop_setacl);
1114 VFS_MPUNLOCK(vp->v_mount);
1122 vop_aclcheck(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1123 struct acl *aclp, struct ucred *cred)
1125 struct vop_aclcheck_args ap;
1129 ap.a_head.a_desc = &vop_aclcheck_desc;
1130 ap.a_head.a_ops = ops;
1136 VFS_MPLOCK1(vp->v_mount);
1137 DO_OPS(ops, error, &ap, vop_aclcheck);
1138 VFS_MPUNLOCK(vp->v_mount);
1146 vop_getextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1147 char *attrname, struct uio *uio, struct ucred *cred)
1149 struct vop_getextattr_args ap;
1153 ap.a_head.a_desc = &vop_getextattr_desc;
1154 ap.a_head.a_ops = ops;
1156 ap.a_attrnamespace = attrnamespace;
1157 ap.a_attrname = attrname;
1161 VFS_MPLOCK1(vp->v_mount);
1162 DO_OPS(ops, error, &ap, vop_getextattr);
1163 VFS_MPUNLOCK(vp->v_mount);
1171 vop_setextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1172 char *attrname, struct uio *uio, struct ucred *cred)
1174 struct vop_setextattr_args ap;
1178 ap.a_head.a_desc = &vop_setextattr_desc;
1179 ap.a_head.a_ops = ops;
1181 ap.a_attrnamespace = attrnamespace;
1182 ap.a_attrname = attrname;
1186 VFS_MPLOCK1(vp->v_mount);
1187 DO_OPS(ops, error, &ap, vop_setextattr);
1188 VFS_MPUNLOCK(vp->v_mount);
1196 vop_mountctl(struct vop_ops *ops, struct vnode *vp, int op, struct file *fp,
1197 const void *ctl, int ctllen, void *buf, int buflen, int *res)
1199 struct vop_mountctl_args ap;
1203 ap.a_head.a_desc = &vop_mountctl_desc;
1204 ap.a_head.a_ops = ops;
1208 ap.a_ctllen = ctllen;
1210 ap.a_buflen = buflen;
1213 VFS_MPLOCK1(vp->v_mount);
1214 DO_OPS(ops, error, &ap, vop_mountctl);
1215 VFS_MPUNLOCK(vp->v_mount);
1223 vop_markatime(struct vop_ops *ops, struct vnode *vp, struct ucred *cred)
1225 struct vop_markatime_args ap;
1229 ap.a_head.a_desc = &vop_markatime_desc;
1230 ap.a_head.a_ops = ops;
1234 VFS_MPLOCK1(vp->v_mount);
1235 DO_OPS(ops, error, &ap, vop_markatime);
1236 VFS_MPUNLOCK(vp->v_mount);
1243 * nresolve takes a locked ncp, a referenced but unlocked dvp, and a cred,
1244 * and resolves the ncp into a positive or negative hit.
1246 * The namecache is automatically adjusted by this function. The ncp
1247 * is left locked on return.
1252 vop_nresolve(struct vop_ops *ops, struct nchandle *nch,
1253 struct vnode *dvp, struct ucred *cred)
1255 struct vop_nresolve_args ap;
1259 ap.a_head.a_desc = &vop_nresolve_desc;
1260 ap.a_head.a_ops = ops;
1265 VFS_MPLOCK1(dvp->v_mount);
1266 DO_OPS(ops, error, &ap, vop_nresolve);
1267 VFS_MPUNLOCK(dvp->v_mount);
1272 * nlookupdotdot takes an unlocked directory, referenced dvp, and looks
1273 * up "..", returning a locked parent directory in *vpp. If an error
1274 * occurs *vpp will be NULL.
1279 vop_nlookupdotdot(struct vop_ops *ops, struct vnode *dvp,
1280 struct vnode **vpp, struct ucred *cred, char **fakename)
1282 struct vop_nlookupdotdot_args ap;
1286 ap.a_head.a_desc = &vop_nlookupdotdot_desc;
1287 ap.a_head.a_ops = ops;
1291 ap.a_fakename = fakename;
1293 VFS_MPLOCK1(dvp->v_mount);
1294 DO_OPS(ops, error, &ap, vop_nlookupdotdot);
1295 VFS_MPUNLOCK(dvp->v_mount);
1300 * ncreate takes a locked, resolved ncp that typically represents a negative
1301 * cache hit and creates the file or node specified by the ncp, cred, and
1302 * vattr. If no error occurs a locked vnode is returned in *vpp.
1304 * The dvp passed in is referenced but unlocked.
1306 * The namecache is automatically adjusted by this function. The ncp
1307 * is left locked on return.
1312 vop_ncreate(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1313 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1315 struct vop_ncreate_args ap;
1319 ap.a_head.a_desc = &vop_ncreate_desc;
1320 ap.a_head.a_ops = ops;
1327 VFS_MPLOCK1(dvp->v_mount);
1328 DO_OPS(ops, error, &ap, vop_ncreate);
1329 VFS_MPUNLOCK(dvp->v_mount);
1334 * nmkdir takes a locked, resolved ncp that typically represents a negative
1335 * cache hit and creates the directory specified by the ncp, cred, and
1336 * vattr. If no error occurs a locked vnode is returned in *vpp.
1338 * The dvp passed in is referenced but unlocked.
1340 * The namecache is automatically adjusted by this function. The ncp
1341 * is left locked on return.
1346 vop_nmkdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1347 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1349 struct vop_nmkdir_args ap;
1353 ap.a_head.a_desc = &vop_nmkdir_desc;
1354 ap.a_head.a_ops = ops;
1361 VFS_MPLOCK1(dvp->v_mount);
1362 DO_OPS(ops, error, &ap, vop_nmkdir);
1363 VFS_MPUNLOCK(dvp->v_mount);
1368 * nmknod takes a locked, resolved ncp that typically represents a negative
1369 * cache hit and creates the node specified by the ncp, cred, and
1370 * vattr. If no error occurs a locked vnode is returned in *vpp.
1372 * The dvp passed in is referenced but unlocked.
1374 * The namecache is automatically adjusted by this function. The ncp
1375 * is left locked on return.
1380 vop_nmknod(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1381 struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1383 struct vop_nmknod_args ap;
1387 ap.a_head.a_desc = &vop_nmknod_desc;
1388 ap.a_head.a_ops = ops;
1395 VFS_MPLOCK1(dvp->v_mount);
1396 DO_OPS(ops, error, &ap, vop_nmknod);
1397 VFS_MPUNLOCK(dvp->v_mount);
1402 * nlink takes a locked, resolved ncp that typically represents a negative
1403 * cache hit and creates the node specified by the ncp, cred, and
1404 * existing vnode. The passed vp must be locked and will remain locked
1405 * on return, as does the ncp, whether an error occurs or not.
1407 * The dvp passed in is referenced but unlocked.
1409 * The namecache is automatically adjusted by this function. The ncp
1410 * is left locked on return.
1415 vop_nlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1416 struct vnode *vp, struct ucred *cred)
1418 struct vop_nlink_args ap;
1422 ap.a_head.a_desc = &vop_nlink_desc;
1423 ap.a_head.a_ops = ops;
1429 VFS_MPLOCK1(dvp->v_mount);
1430 DO_OPS(ops, error, &ap, vop_nlink);
1431 VFS_MPUNLOCK(dvp->v_mount);
1436 * nsymlink takes a locked, resolved ncp that typically represents a negative
1437 * cache hit and creates a symbolic link based on cred, vap, and target (the
1438 * contents of the link). If no error occurs a locked vnode is returned in
1441 * The dvp passed in is referenced but unlocked.
1443 * The namecache is automatically adjusted by this function. The ncp
1444 * is left locked on return.
1449 vop_nsymlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1450 struct vnode **vpp, struct ucred *cred,
1451 struct vattr *vap, char *target)
1453 struct vop_nsymlink_args ap;
1457 ap.a_head.a_desc = &vop_nsymlink_desc;
1458 ap.a_head.a_ops = ops;
1464 ap.a_target = target;
1466 VFS_MPLOCK1(dvp->v_mount);
1467 DO_OPS(ops, error, &ap, vop_nsymlink);
1468 VFS_MPUNLOCK(dvp->v_mount);
1473 * nwhiteout takes a locked, resolved ncp that can represent a positive or
1474 * negative hit and executes the whiteout function specified in flags.
1476 * The dvp passed in is referenced but unlocked.
1478 * The namecache is automatically adjusted by this function. The ncp
1479 * is left locked on return.
1484 vop_nwhiteout(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1485 struct ucred *cred, int flags)
1487 struct vop_nwhiteout_args ap;
1491 ap.a_head.a_desc = &vop_nwhiteout_desc;
1492 ap.a_head.a_ops = ops;
1498 VFS_MPLOCK1(dvp->v_mount);
1499 DO_OPS(ops, error, &ap, vop_nwhiteout);
1500 VFS_MPUNLOCK(dvp->v_mount);
1505 * nremove takes a locked, resolved ncp that generally represents a
1506 * positive hit and removes the file.
1508 * The dvp passed in is referenced but unlocked.
1510 * The namecache is automatically adjusted by this function. The ncp
1511 * is left locked on return.
1516 vop_nremove(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1519 struct vop_nremove_args ap;
1524 ap.a_head.a_desc = &vop_nremove_desc;
1525 ap.a_head.a_ops = ops;
1530 if ((error = VOP_GETATTR(nch->ncp->nc_vp, &va)) != 0)
1533 VFS_MPLOCK1(dvp->v_mount);
1534 DO_OPS(ops, error, &ap, vop_nremove);
1535 /* Only update space counters if this is the last hard link */
1536 if ((error == 0) && (va.va_nlink == 1)) {
1537 VFS_ACCOUNT(nch->mount, va.va_uid, va.va_gid, -va.va_size);
1539 VFS_MPUNLOCK(dvp->v_mount);
1544 * nrmdir takes a locked, resolved ncp that generally represents a
1545 * directory and removes the directory.
1547 * The dvp passed in is referenced but unlocked.
1549 * The namecache is automatically adjusted by this function. The ncp
1550 * is left locked on return.
1555 vop_nrmdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1558 struct vop_nrmdir_args ap;
1562 ap.a_head.a_desc = &vop_nrmdir_desc;
1563 ap.a_head.a_ops = ops;
1568 VFS_MPLOCK1(dvp->v_mount);
1569 DO_OPS(ops, error, &ap, vop_nrmdir);
1570 VFS_MPUNLOCK(dvp->v_mount);
1575 * nrename takes TWO locked, resolved ncp's and the cred of the caller
1576 * and renames the source ncp to the target ncp. The target ncp may
1577 * represent a positive or negative hit.
1579 * The fdvp and tdvp passed in are referenced but unlocked.
1581 * The namecache is automatically adjusted by this function. The ncp
1582 * is left locked on return. The source ncp is typically changed to
1583 * a negative cache hit and the target ncp typically takes on the
1584 * source ncp's underlying file.
1589 vop_nrename(struct vop_ops *ops,
1590 struct nchandle *fnch, struct nchandle *tnch,
1591 struct vnode *fdvp, struct vnode *tdvp,
1594 struct vop_nrename_args ap;
1598 ap.a_head.a_desc = &vop_nrename_desc;
1599 ap.a_head.a_ops = ops;
1606 VFS_MPLOCK1(fdvp->v_mount);
1607 DO_OPS(ops, error, &ap, vop_nrename);
1608 VFS_MPUNLOCK(fdvp->v_mount);
1612 /************************************************************************
1613 * PRIMARY VNODE OPERATIONS FORWARDING CALLS *
1614 ************************************************************************
1616 * These procedures are called from VFSs such as unionfs and nullfs
1617 * when they wish to forward an operation on one VFS to another. The
1618 * argument structure/message is modified and then directly passed to the
1619 * appropriate routine. This routines may also be called by initiators
1620 * who have an argument structure in hand rather then discreet arguments.
1622 * MPSAFE - Caller expected to already hold the appropriate vfs lock.
1625 vop_vnoperate_ap(struct vop_generic_args *ap)
1627 struct vop_ops *ops;
1631 error = VOCALL(ops, ap);
1637 * This routine is called by the cache coherency layer to execute the actual
1638 * VFS operation. If a journaling layer is present we call though it, else
1639 * we call the native VOP functions.
1642 vop_cache_operate_ap(struct vop_generic_args *ap)
1644 struct vop_ops *ops;
1648 if (ops->head.vv_mount->mnt_vn_journal_ops)
1649 error = VOCALL(ops->head.vv_mount->mnt_vn_journal_ops, ap);
1651 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1657 * This routine is called by the journaling layer to execute the actual
1661 vop_journal_operate_ap(struct vop_generic_args *ap)
1663 struct vop_ops *ops;
1667 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1673 vop_open_ap(struct vop_open_args *ap)
1677 DO_OPS(ap->a_head.a_ops, error, ap, vop_open);
1682 vop_close_ap(struct vop_close_args *ap)
1686 DO_OPS(ap->a_head.a_ops, error, ap, vop_close);
1691 vop_access_ap(struct vop_access_args *ap)
1695 DO_OPS(ap->a_head.a_ops, error, ap, vop_access);
1700 vop_getattr_ap(struct vop_getattr_args *ap)
1704 DO_OPS(ap->a_head.a_ops, error, ap, vop_getattr);
1709 vop_setattr_ap(struct vop_setattr_args *ap)
1713 DO_OPS(ap->a_head.a_ops, error, ap, vop_setattr);
1718 vop_read_ap(struct vop_read_args *ap)
1722 DO_OPS(ap->a_head.a_ops, error, ap, vop_read);
1727 vop_write_ap(struct vop_write_args *ap)
1731 DO_OPS(ap->a_head.a_ops, error, ap, vop_write);
1736 vop_ioctl_ap(struct vop_ioctl_args *ap)
1740 DO_OPS(ap->a_head.a_ops, error, ap, vop_ioctl);
1745 vop_poll_ap(struct vop_poll_args *ap)
1749 DO_OPS(ap->a_head.a_ops, error, ap, vop_poll);
1754 vop_kqfilter_ap(struct vop_kqfilter_args *ap)
1758 DO_OPS(ap->a_head.a_ops, error, ap, vop_kqfilter);
1763 vop_mmap_ap(struct vop_mmap_args *ap)
1767 DO_OPS(ap->a_head.a_ops, error, ap, vop_mmap);
1772 vop_fsync_ap(struct vop_fsync_args *ap)
1776 DO_OPS(ap->a_head.a_ops, error, ap, vop_fsync);
1781 vop_readdir_ap(struct vop_readdir_args *ap)
1785 DO_OPS(ap->a_head.a_ops, error, ap, vop_readdir);
1790 vop_readlink_ap(struct vop_readlink_args *ap)
1794 DO_OPS(ap->a_head.a_ops, error, ap, vop_readlink);
1799 vop_inactive_ap(struct vop_inactive_args *ap)
1803 DO_OPS(ap->a_head.a_ops, error, ap, vop_inactive);
1808 vop_reclaim_ap(struct vop_reclaim_args *ap)
1812 DO_OPS(ap->a_head.a_ops, error, ap, vop_reclaim);
1817 vop_bmap_ap(struct vop_bmap_args *ap)
1821 DO_OPS(ap->a_head.a_ops, error, ap, vop_bmap);
1826 vop_strategy_ap(struct vop_strategy_args *ap)
1830 DO_OPS(ap->a_head.a_ops, error, ap, vop_strategy);
1835 vop_print_ap(struct vop_print_args *ap)
1839 DO_OPS(ap->a_head.a_ops, error, ap, vop_print);
1844 vop_pathconf_ap(struct vop_pathconf_args *ap)
1848 DO_OPS(ap->a_head.a_ops, error, ap, vop_pathconf);
1853 vop_advlock_ap(struct vop_advlock_args *ap)
1857 DO_OPS(ap->a_head.a_ops, error, ap, vop_advlock);
1862 vop_balloc_ap(struct vop_balloc_args *ap)
1866 DO_OPS(ap->a_head.a_ops, error, ap, vop_balloc);
1871 vop_reallocblks_ap(struct vop_reallocblks_args *ap)
1875 DO_OPS(ap->a_head.a_ops, error, ap, vop_reallocblks);
1880 vop_getpages_ap(struct vop_getpages_args *ap)
1884 DO_OPS(ap->a_head.a_ops, error, ap, vop_getpages);
1889 vop_putpages_ap(struct vop_putpages_args *ap)
1893 DO_OPS(ap->a_head.a_ops, error, ap, vop_putpages);
1898 vop_freeblks_ap(struct vop_freeblks_args *ap)
1902 DO_OPS(ap->a_head.a_ops, error, ap, vop_freeblks);
1907 vop_getacl_ap(struct vop_getacl_args *ap)
1911 DO_OPS(ap->a_head.a_ops, error, ap, vop_getacl);
1916 vop_setacl_ap(struct vop_setacl_args *ap)
1920 DO_OPS(ap->a_head.a_ops, error, ap, vop_setacl);
1925 vop_aclcheck_ap(struct vop_aclcheck_args *ap)
1929 DO_OPS(ap->a_head.a_ops, error, ap, vop_aclcheck);
1934 vop_getextattr_ap(struct vop_getextattr_args *ap)
1938 DO_OPS(ap->a_head.a_ops, error, ap, vop_getextattr);
1943 vop_setextattr_ap(struct vop_setextattr_args *ap)
1947 DO_OPS(ap->a_head.a_ops, error, ap, vop_setextattr);
1952 vop_mountctl_ap(struct vop_mountctl_args *ap)
1956 DO_OPS(ap->a_head.a_ops, error, ap, vop_mountctl);
1961 vop_markatime_ap(struct vop_markatime_args *ap)
1965 DO_OPS(ap->a_head.a_ops, error, ap, vop_markatime);
1970 vop_nresolve_ap(struct vop_nresolve_args *ap)
1974 DO_OPS(ap->a_head.a_ops, error, ap, vop_nresolve);
1979 vop_nlookupdotdot_ap(struct vop_nlookupdotdot_args *ap)
1983 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlookupdotdot);
1988 vop_ncreate_ap(struct vop_ncreate_args *ap)
1992 DO_OPS(ap->a_head.a_ops, error, ap, vop_ncreate);
1997 vop_nmkdir_ap(struct vop_nmkdir_args *ap)
2001 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmkdir);
2006 vop_nmknod_ap(struct vop_nmknod_args *ap)
2010 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmknod);
2015 vop_nlink_ap(struct vop_nlink_args *ap)
2019 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlink);
2024 vop_nsymlink_ap(struct vop_nsymlink_args *ap)
2028 DO_OPS(ap->a_head.a_ops, error, ap, vop_nsymlink);
2033 vop_nwhiteout_ap(struct vop_nwhiteout_args *ap)
2037 DO_OPS(ap->a_head.a_ops, error, ap, vop_nwhiteout);
2042 vop_nremove_ap(struct vop_nremove_args *ap)
2046 DO_OPS(ap->a_head.a_ops, error, ap, vop_nremove);
2051 vop_nrmdir_ap(struct vop_nrmdir_args *ap)
2055 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrmdir);
2060 vop_nrename_ap(struct vop_nrename_args *ap)
2064 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrename);