tools - Fix backup file permissions for hammer-backup.sh
[dragonfly.git] / sys / kern / vfs_vopops.c
blob7811295449cf36e7c7ac0d6d23e12ed4ed9b48a6
1 /*
2 * Copyright (c) 2004,2009 The DragonFly Project. All rights reserved.
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
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
16 * distribution.
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
32 * SUCH DAMAGE.
35 * Implement vnode ops wrappers. All vnode ops are wrapped through
36 * these functions.
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>
44 #include <sys/buf.h>
45 #include <sys/conf.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>
53 #include <sys/mbuf.h>
54 #include <sys/mount.h>
55 #include <sys/proc.h>
56 #include <sys/namei.h>
57 #include <sys/reboot.h>
58 #include <sys/socket.h>
59 #include <sys/stat.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>
70 #include <vm/vm.h>
71 #include <vm/vm_object.h>
72 #include <vm/vm_extern.h>
73 #include <vm/vm_kern.h>
74 #include <vm/pmap.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>
81 #include <sys/buf2.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)), \
90 #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
163 * those ops.
165 * NOTE: The VFS_MPLOCK*() macros handle mounts which do not set
166 * MNTK_MPSAFE or MNTK_xx_MPSAFE.
168 * 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;
176 VFS_MPLOCK_DECLARE;
177 int error;
179 ap.a_head.a_desc = &vop_old_lookup_desc;
180 ap.a_head.a_ops = ops;
181 ap.a_dvp = dvp;
182 ap.a_vpp = vpp;
183 ap.a_cnp = cnp;
184 VFS_MPLOCK1(dvp->v_mount);
185 DO_OPS(ops, error, &ap, vop_old_lookup);
186 VFS_MPUNLOCK(dvp->v_mount);
187 return(error);
191 * MPSAFE
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;
198 VFS_MPLOCK_DECLARE;
199 int error;
201 ap.a_head.a_desc = &vop_old_create_desc;
202 ap.a_head.a_ops = ops;
203 ap.a_dvp = dvp;
204 ap.a_vpp = vpp;
205 ap.a_cnp = cnp;
206 ap.a_vap = vap;
208 VFS_MPLOCK1(dvp->v_mount);
209 DO_OPS(ops, error, &ap, vop_old_create);
210 VFS_MPUNLOCK(dvp->v_mount);
211 return(error);
215 * MPSAFE
218 vop_old_whiteout(struct vop_ops *ops, struct vnode *dvp,
219 struct componentname *cnp, int flags)
221 struct vop_old_whiteout_args ap;
222 VFS_MPLOCK_DECLARE;
223 int error;
225 ap.a_head.a_desc = &vop_old_whiteout_desc;
226 ap.a_head.a_ops = ops;
227 ap.a_dvp = dvp;
228 ap.a_cnp = cnp;
229 ap.a_flags = flags;
231 VFS_MPLOCK1(dvp->v_mount);
232 DO_OPS(ops, error, &ap, vop_old_whiteout);
233 VFS_MPUNLOCK(dvp->v_mount);
234 return(error);
238 * MPSAFE
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;
245 VFS_MPLOCK_DECLARE;
246 int error;
248 ap.a_head.a_desc = &vop_old_mknod_desc;
249 ap.a_head.a_ops = ops;
250 ap.a_dvp = dvp;
251 ap.a_vpp = vpp;
252 ap.a_cnp = cnp;
253 ap.a_vap = vap;
255 VFS_MPLOCK1(dvp->v_mount);
256 DO_OPS(ops, error, &ap, vop_old_mknod);
257 VFS_MPUNLOCK(dvp->v_mount);
258 return(error);
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,
266 struct file *fp)
268 struct vop_open_args ap;
269 VFS_MPLOCK_DECLARE;
270 int error;
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;
284 ap.a_vp = vp;
285 ap.a_fp = fp;
286 ap.a_mode = mode;
287 ap.a_cred = cred;
289 VFS_MPLOCK1(vp->v_mount);
290 DO_OPS(ops, error, &ap, vop_open);
291 VFS_MPUNLOCK(vp->v_mount);
292 return(error);
296 * MPSAFE
299 vop_close(struct vop_ops *ops, struct vnode *vp, int fflag,
300 struct file *fp)
302 struct vop_close_args ap;
303 VFS_MPLOCK_DECLARE;
304 int error;
306 ap.a_head.a_desc = &vop_close_desc;
307 ap.a_head.a_ops = ops;
308 ap.a_vp = vp;
309 ap.a_fp = fp;
310 ap.a_fflag = fflag;
312 VFS_MPLOCK1(vp->v_mount);
313 DO_OPS(ops, error, &ap, vop_close);
314 VFS_MPUNLOCK(vp->v_mount);
315 return(error);
319 * MPSAFE
322 vop_access(struct vop_ops *ops, struct vnode *vp, int mode, int flags,
323 struct ucred *cred)
325 struct vop_access_args ap;
326 VFS_MPLOCK_DECLARE;
327 int error;
329 ap.a_head.a_desc = &vop_access_desc;
330 ap.a_head.a_ops = ops;
331 ap.a_vp = vp;
332 ap.a_mode = mode;
333 ap.a_flags = flags;
334 ap.a_cred = cred;
336 VFS_MPLOCK1(vp->v_mount);
337 DO_OPS(ops, error, &ap, vop_access);
338 VFS_MPUNLOCK(vp->v_mount);
339 return(error);
343 * MPSAFE
346 vop_getattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap)
348 struct vop_getattr_args ap;
349 VFS_MPLOCK_DECLARE;
350 int error;
352 ap.a_head.a_desc = &vop_getattr_desc;
353 ap.a_head.a_ops = ops;
354 ap.a_vp = vp;
355 ap.a_vap = vap;
357 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_GA_MPSAFE);
358 DO_OPS(ops, error, &ap, vop_getattr);
359 VFS_MPUNLOCK(vp->v_mount);
361 return(error);
365 * MPSAFE
368 vop_setattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap,
369 struct ucred *cred)
371 struct vop_setattr_args ap;
372 VFS_MPLOCK_DECLARE;
373 int error;
375 ap.a_head.a_desc = &vop_setattr_desc;
376 ap.a_head.a_ops = ops;
377 ap.a_vp = vp;
378 ap.a_vap = vap;
379 ap.a_cred = cred;
381 VFS_MPLOCK1(vp->v_mount);
382 DO_OPS(ops, error, &ap, vop_setattr);
383 VFS_MPUNLOCK(vp->v_mount);
384 return(error);
388 * MPSAFE
391 vop_read(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
392 struct ucred *cred)
394 struct vop_read_args ap;
395 VFS_MPLOCK_DECLARE;
396 int error;
398 ap.a_head.a_desc = &vop_read_desc;
399 ap.a_head.a_ops = ops;
400 ap.a_vp = vp;
401 ap.a_uio = uio;
402 ap.a_ioflag = ioflag;
403 ap.a_cred = cred;
405 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_RD_MPSAFE);
406 DO_OPS(ops, error, &ap, vop_read);
407 VFS_MPUNLOCK(vp->v_mount);
408 return(error);
412 * MPSAFE
415 vop_write(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
416 struct ucred *cred)
418 struct vop_write_args ap;
419 VFS_MPLOCK_DECLARE;
420 int error, do_accounting = 0;
421 struct vattr va;
422 uint64_t size_before=0, size_after=0;
423 struct mount *mp;
424 uint64_t offset, delta;
426 ap.a_head.a_desc = &vop_write_desc;
427 ap.a_head.a_ops = ops;
428 ap.a_vp = vp;
429 ap.a_uio = uio;
430 ap.a_ioflag = ioflag;
431 ap.a_cred = cred;
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)
437 goto done;
438 size_before = va.va_size;
439 /* this file may already have been removed */
440 if (va.va_nlink > 0)
441 do_accounting = 1;
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;
450 mp = vq_vptomp(vp);
451 /* QUOTA CHECK */
452 if (!vq_write_ok(mp, va.va_uid, va.va_gid, delta)) {
453 error = EDQUOT;
454 goto done;
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);
461 done:
462 VFS_MPUNLOCK(vp->v_mount);
463 return(error);
467 * MPSAFE
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;
474 VFS_MPLOCK_DECLARE;
475 int error;
477 ap.a_head.a_desc = &vop_ioctl_desc;
478 ap.a_head.a_ops = ops;
479 ap.a_vp = vp;
480 ap.a_command = command;
481 ap.a_data = data;
482 ap.a_fflag = fflag;
483 ap.a_cred = cred;
484 ap.a_sysmsg = msg;
486 VFS_MPLOCK1(vp->v_mount);
487 DO_OPS(ops, error, &ap, vop_ioctl);
488 VFS_MPUNLOCK(vp->v_mount);
489 return(error);
493 * MPSAFE
496 vop_poll(struct vop_ops *ops, struct vnode *vp, int events, struct ucred *cred)
498 struct vop_poll_args ap;
499 VFS_MPLOCK_DECLARE;
500 int error;
502 ap.a_head.a_desc = &vop_poll_desc;
503 ap.a_head.a_ops = ops;
504 ap.a_vp = vp;
505 ap.a_events = events;
506 ap.a_cred = cred;
508 VFS_MPLOCK1(vp->v_mount);
509 DO_OPS(ops, error, &ap, vop_poll);
510 VFS_MPUNLOCK(vp->v_mount);
511 return(error);
515 * MPSAFE
518 vop_kqfilter(struct vop_ops *ops, struct vnode *vp, struct knote *kn)
520 struct vop_kqfilter_args ap;
521 VFS_MPLOCK_DECLARE;
522 int error;
524 ap.a_head.a_desc = &vop_kqfilter_desc;
525 ap.a_head.a_ops = ops;
526 ap.a_vp = vp;
527 ap.a_kn = kn;
529 VFS_MPLOCK1(vp->v_mount);
530 DO_OPS(ops, error, &ap, vop_kqfilter);
531 VFS_MPUNLOCK(vp->v_mount);
532 return(error);
536 * MPSAFE
539 vop_mmap(struct vop_ops *ops, struct vnode *vp, int fflags, struct ucred *cred)
541 struct vop_mmap_args ap;
542 VFS_MPLOCK_DECLARE;
543 int error;
545 ap.a_head.a_desc = &vop_mmap_desc;
546 ap.a_head.a_ops = ops;
547 ap.a_vp = vp;
548 ap.a_fflags = fflags;
549 ap.a_cred = cred;
551 VFS_MPLOCK1(vp->v_mount);
552 DO_OPS(ops, error, &ap, vop_mmap);
553 VFS_MPUNLOCK(vp->v_mount);
554 return(error);
558 * MPSAFE
561 vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor, int flags)
563 struct vop_fsync_args ap;
564 VFS_MPLOCK_DECLARE;
565 int error;
567 ap.a_head.a_desc = &vop_fsync_desc;
568 ap.a_head.a_ops = ops;
569 ap.a_vp = vp;
570 ap.a_waitfor = waitfor;
571 ap.a_flags = flags;
573 VFS_MPLOCK1(vp->v_mount);
574 DO_OPS(ops, error, &ap, vop_fsync);
575 VFS_MPUNLOCK(vp->v_mount);
576 return(error);
580 * MPSAFE
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;
587 VFS_MPLOCK_DECLARE;
588 int error;
590 ap.a_head.a_desc = &vop_old_remove_desc;
591 ap.a_head.a_ops = ops;
592 ap.a_dvp = dvp;
593 ap.a_vp = vp;
594 ap.a_cnp = cnp;
596 VFS_MPLOCK1(dvp->v_mount);
597 DO_OPS(ops, error, &ap, vop_old_remove);
598 VFS_MPUNLOCK(dvp->v_mount);
599 return(error);
603 * MPSAFE
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;
610 VFS_MPLOCK_DECLARE;
611 int error;
613 ap.a_head.a_desc = &vop_old_link_desc;
614 ap.a_head.a_ops = ops;
615 ap.a_tdvp = tdvp;
616 ap.a_vp = vp;
617 ap.a_cnp = cnp;
619 VFS_MPLOCK1(tdvp->v_mount);
620 DO_OPS(ops, error, &ap, vop_old_link);
621 VFS_MPUNLOCK(tdvp->v_mount);
622 return(error);
626 * MPSAFE
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;
634 VFS_MPLOCK_DECLARE;
635 int error;
637 ap.a_head.a_desc = &vop_old_rename_desc;
638 ap.a_head.a_ops = ops;
639 ap.a_fdvp = fdvp;
640 ap.a_fvp = fvp;
641 ap.a_fcnp = fcnp;
642 ap.a_tdvp = tdvp;
643 ap.a_tvp = tvp;
644 ap.a_tcnp = tcnp;
646 VFS_MPLOCK1(tdvp->v_mount);
647 DO_OPS(ops, error, &ap, vop_old_rename);
648 VFS_MPUNLOCK(tdvp->v_mount);
649 return(error);
653 * MPSAFE
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;
660 VFS_MPLOCK_DECLARE;
661 int error;
663 ap.a_head.a_desc = &vop_old_mkdir_desc;
664 ap.a_head.a_ops = ops;
665 ap.a_dvp = dvp;
666 ap.a_vpp = vpp;
667 ap.a_cnp = cnp;
668 ap.a_vap = vap;
670 VFS_MPLOCK1(dvp->v_mount);
671 DO_OPS(ops, error, &ap, vop_old_mkdir);
672 VFS_MPUNLOCK(dvp->v_mount);
673 return(error);
677 * MPSAFE
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;
684 VFS_MPLOCK_DECLARE;
685 int error;
687 ap.a_head.a_desc = &vop_old_rmdir_desc;
688 ap.a_head.a_ops = ops;
689 ap.a_dvp = dvp;
690 ap.a_vp = vp;
691 ap.a_cnp = cnp;
693 VFS_MPLOCK1(dvp->v_mount);
694 DO_OPS(ops, error, &ap, vop_old_rmdir);
695 VFS_MPUNLOCK(dvp->v_mount);
696 return(error);
700 * MPSAFE
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;
708 VFS_MPLOCK_DECLARE;
709 int error;
711 ap.a_head.a_desc = &vop_old_symlink_desc;
712 ap.a_head.a_ops = ops;
713 ap.a_dvp = dvp;
714 ap.a_vpp = vpp;
715 ap.a_cnp = cnp;
716 ap.a_vap = vap;
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);
722 return(error);
726 * MPSAFE
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;
733 VFS_MPLOCK_DECLARE;
734 int error;
736 ap.a_head.a_desc = &vop_readdir_desc;
737 ap.a_head.a_ops = ops;
738 ap.a_vp = vp;
739 ap.a_uio = uio;
740 ap.a_cred = cred;
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);
748 return(error);
752 * MPSAFE
755 vop_readlink(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
756 struct ucred *cred)
758 struct vop_readlink_args ap;
759 VFS_MPLOCK_DECLARE;
760 int error;
762 ap.a_head.a_desc = &vop_readlink_desc;
763 ap.a_head.a_ops = ops;
764 ap.a_vp = vp;
765 ap.a_uio = uio;
766 ap.a_cred = cred;
768 VFS_MPLOCK1(vp->v_mount);
769 DO_OPS(ops, error, &ap, vop_readlink);
770 VFS_MPUNLOCK(vp->v_mount);
771 return(error);
775 * MPSAFE
778 vop_inactive(struct vop_ops *ops, struct vnode *vp)
780 struct vop_inactive_args ap;
781 struct mount *mp;
782 VFS_MPLOCK_DECLARE;
783 int error;
785 ap.a_head.a_desc = &vop_inactive_desc;
786 ap.a_head.a_ops = ops;
787 ap.a_vp = vp;
790 * WARNING! Deactivation of the vnode can cause it to be recycled,
791 * clearing vp->v_mount.
793 mp = vp->v_mount;
794 VFS_MPLOCK_FLAG(mp, MNTK_IN_MPSAFE);
795 DO_OPS(ops, error, &ap, vop_inactive);
796 VFS_MPUNLOCK(mp);
797 return(error);
801 * MPSAFE
804 vop_reclaim(struct vop_ops *ops, struct vnode *vp)
806 struct vop_reclaim_args ap;
807 struct mount *mp;
808 VFS_MPLOCK_DECLARE;
809 int error;
811 ap.a_head.a_desc = &vop_reclaim_desc;
812 ap.a_head.a_ops = ops;
813 ap.a_vp = vp;
816 * WARNING! Reclamation of the vnode will clear vp->v_mount.
818 mp = vp->v_mount;
819 VFS_MPLOCK1(mp);
820 DO_OPS(ops, error, &ap, vop_reclaim);
821 VFS_MPUNLOCK(mp);
822 return(error);
826 * MPSAFE
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;
833 VFS_MPLOCK_DECLARE;
834 int error;
836 ap.a_head.a_desc = &vop_bmap_desc;
837 ap.a_head.a_ops = ops;
838 ap.a_vp = vp;
839 ap.a_loffset = loffset;
840 ap.a_doffsetp = doffsetp;
841 ap.a_runp = runp;
842 ap.a_runb = runb;
843 ap.a_cmd = cmd;
845 VFS_MPLOCK1(vp->v_mount);
846 DO_OPS(ops, error, &ap, vop_bmap);
847 VFS_MPUNLOCK(vp->v_mount);
848 return(error);
852 * MPSAFE
855 vop_strategy(struct vop_ops *ops, struct vnode *vp, struct bio *bio)
857 struct vop_strategy_args ap;
858 VFS_MPLOCK_DECLARE;
859 int error;
861 ap.a_head.a_desc = &vop_strategy_desc;
862 ap.a_head.a_ops = ops;
863 ap.a_vp = vp;
864 ap.a_bio = bio;
866 if (vp->v_mount) {
867 VFS_MPLOCK_FLAG(vp->v_mount, MNTK_SG_MPSAFE);
868 DO_OPS(ops, error, &ap, vop_strategy);
869 VFS_MPUNLOCK(vp->v_mount);
870 } else {
871 /* ugly hack for swap */
872 get_mplock();
873 DO_OPS(ops, error, &ap, vop_strategy);
874 rel_mplock();
876 return(error);
880 * MPSAFE
883 vop_print(struct vop_ops *ops, struct vnode *vp)
885 struct vop_print_args ap;
886 VFS_MPLOCK_DECLARE;
887 int error;
889 ap.a_head.a_desc = &vop_print_desc;
890 ap.a_head.a_ops = ops;
891 ap.a_vp = vp;
893 VFS_MPLOCK1(vp->v_mount);
894 DO_OPS(ops, error, &ap, vop_print);
895 VFS_MPUNLOCK(vp->v_mount);
896 return(error);
900 * MPSAFE
903 vop_pathconf(struct vop_ops *ops, struct vnode *vp, int name,
904 register_t *retval)
906 struct vop_pathconf_args ap;
907 VFS_MPLOCK_DECLARE;
908 int error;
910 ap.a_head.a_desc = &vop_pathconf_desc;
911 ap.a_head.a_ops = ops;
912 ap.a_vp = vp;
913 ap.a_name = name;
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);
919 return(error);
923 * MPSAFE
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;
930 VFS_MPLOCK_DECLARE;
931 int error;
933 ap.a_head.a_desc = &vop_advlock_desc;
934 ap.a_head.a_ops = ops;
935 ap.a_vp = vp;
936 ap.a_id = id;
937 ap.a_op = op;
938 ap.a_fl = fl;
939 ap.a_flags = flags;
941 VFS_MPLOCK1(vp->v_mount);
942 DO_OPS(ops, error, &ap, vop_advlock);
943 VFS_MPUNLOCK(vp->v_mount);
944 return(error);
948 * MPSAFE
951 vop_balloc(struct vop_ops *ops, struct vnode *vp, off_t startoffset,
952 int size, struct ucred *cred, int flags,
953 struct buf **bpp)
955 struct vop_balloc_args ap;
956 VFS_MPLOCK_DECLARE;
957 int error;
959 ap.a_head.a_desc = &vop_balloc_desc;
960 ap.a_head.a_ops = ops;
961 ap.a_vp = vp;
962 ap.a_startoffset = startoffset;
963 ap.a_size = size;
964 ap.a_cred = cred;
965 ap.a_flags = flags;
966 ap.a_bpp = bpp;
968 VFS_MPLOCK1(vp->v_mount);
969 DO_OPS(ops, error, &ap, vop_balloc);
970 VFS_MPUNLOCK(vp->v_mount);
971 return(error);
975 * MPSAFE
978 vop_reallocblks(struct vop_ops *ops, struct vnode *vp,
979 struct cluster_save *buflist)
981 struct vop_reallocblks_args ap;
982 VFS_MPLOCK_DECLARE;
983 int error;
985 ap.a_head.a_desc = &vop_reallocblks_desc;
986 ap.a_head.a_ops = ops;
987 ap.a_vp = vp;
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);
993 return(error);
997 * MPSAFE
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;
1004 VFS_MPLOCK_DECLARE;
1005 int error;
1007 ap.a_head.a_desc = &vop_getpages_desc;
1008 ap.a_head.a_ops = ops;
1009 ap.a_vp = vp;
1010 ap.a_m = m;
1011 ap.a_count = count;
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);
1019 return(error);
1023 * MPSAFE
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;
1030 VFS_MPLOCK_DECLARE;
1031 int error;
1033 ap.a_head.a_desc = &vop_putpages_desc;
1034 ap.a_head.a_ops = ops;
1035 ap.a_vp = vp;
1036 ap.a_m = m;
1037 ap.a_count = count;
1038 ap.a_sync = sync;
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);
1045 return(error);
1049 * MPSAFE
1052 vop_freeblks(struct vop_ops *ops, struct vnode *vp, off_t offset, int length)
1054 struct vop_freeblks_args ap;
1055 VFS_MPLOCK_DECLARE;
1056 int error;
1058 ap.a_head.a_desc = &vop_freeblks_desc;
1059 ap.a_head.a_ops = ops;
1060 ap.a_vp = vp;
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);
1067 return(error);
1071 * MPSAFE
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;
1078 VFS_MPLOCK_DECLARE;
1079 int error;
1081 ap.a_head.a_desc = &vop_getacl_desc;
1082 ap.a_head.a_ops = ops;
1083 ap.a_vp = vp;
1084 ap.a_type = type;
1085 ap.a_aclp = aclp;
1086 ap.a_cred = cred;
1088 VFS_MPLOCK1(vp->v_mount);
1089 DO_OPS(ops, error, &ap, vop_getacl);
1090 VFS_MPUNLOCK(vp->v_mount);
1091 return(error);
1095 * MPSAFE
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;
1102 VFS_MPLOCK_DECLARE;
1103 int error;
1105 ap.a_head.a_desc = &vop_setacl_desc;
1106 ap.a_head.a_ops = ops;
1107 ap.a_vp = vp;
1108 ap.a_type = type;
1109 ap.a_aclp = aclp;
1110 ap.a_cred = cred;
1112 VFS_MPLOCK1(vp->v_mount);
1113 DO_OPS(ops, error, &ap, vop_setacl);
1114 VFS_MPUNLOCK(vp->v_mount);
1115 return(error);
1119 * MPSAFE
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;
1126 VFS_MPLOCK_DECLARE;
1127 int error;
1129 ap.a_head.a_desc = &vop_aclcheck_desc;
1130 ap.a_head.a_ops = ops;
1131 ap.a_vp = vp;
1132 ap.a_type = type;
1133 ap.a_aclp = aclp;
1134 ap.a_cred = cred;
1136 VFS_MPLOCK1(vp->v_mount);
1137 DO_OPS(ops, error, &ap, vop_aclcheck);
1138 VFS_MPUNLOCK(vp->v_mount);
1139 return(error);
1143 * MPSAFE
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;
1150 VFS_MPLOCK_DECLARE;
1151 int error;
1153 ap.a_head.a_desc = &vop_getextattr_desc;
1154 ap.a_head.a_ops = ops;
1155 ap.a_vp = vp;
1156 ap.a_attrnamespace = attrnamespace;
1157 ap.a_attrname = attrname;
1158 ap.a_uio = uio;
1159 ap.a_cred = cred;
1161 VFS_MPLOCK1(vp->v_mount);
1162 DO_OPS(ops, error, &ap, vop_getextattr);
1163 VFS_MPUNLOCK(vp->v_mount);
1164 return(error);
1168 * MPSAFE
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;
1175 VFS_MPLOCK_DECLARE;
1176 int error;
1178 ap.a_head.a_desc = &vop_setextattr_desc;
1179 ap.a_head.a_ops = ops;
1180 ap.a_vp = vp;
1181 ap.a_attrnamespace = attrnamespace;
1182 ap.a_attrname = attrname;
1183 ap.a_uio = uio;
1184 ap.a_cred = cred;
1186 VFS_MPLOCK1(vp->v_mount);
1187 DO_OPS(ops, error, &ap, vop_setextattr);
1188 VFS_MPUNLOCK(vp->v_mount);
1189 return(error);
1193 * MPSAFE
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;
1200 VFS_MPLOCK_DECLARE;
1201 int error;
1203 ap.a_head.a_desc = &vop_mountctl_desc;
1204 ap.a_head.a_ops = ops;
1205 ap.a_op = op;
1206 ap.a_ctl = ctl;
1207 ap.a_fp = fp;
1208 ap.a_ctllen = ctllen;
1209 ap.a_buf = buf;
1210 ap.a_buflen = buflen;
1211 ap.a_res = res;
1213 VFS_MPLOCK1(vp->v_mount);
1214 DO_OPS(ops, error, &ap, vop_mountctl);
1215 VFS_MPUNLOCK(vp->v_mount);
1216 return(error);
1220 * MPSAFE
1223 vop_markatime(struct vop_ops *ops, struct vnode *vp, struct ucred *cred)
1225 struct vop_markatime_args ap;
1226 VFS_MPLOCK_DECLARE;
1227 int error;
1229 ap.a_head.a_desc = &vop_markatime_desc;
1230 ap.a_head.a_ops = ops;
1231 ap.a_vp = vp;
1232 ap.a_cred = cred;
1234 VFS_MPLOCK1(vp->v_mount);
1235 DO_OPS(ops, error, &ap, vop_markatime);
1236 VFS_MPUNLOCK(vp->v_mount);
1237 return(error);
1241 * NEW API FUNCTIONS
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.
1249 * MPSAFE
1252 vop_nresolve(struct vop_ops *ops, struct nchandle *nch,
1253 struct vnode *dvp, struct ucred *cred)
1255 struct vop_nresolve_args ap;
1256 VFS_MPLOCK_DECLARE;
1257 int error;
1259 ap.a_head.a_desc = &vop_nresolve_desc;
1260 ap.a_head.a_ops = ops;
1261 ap.a_nch = nch;
1262 ap.a_dvp = dvp;
1263 ap.a_cred = cred;
1265 VFS_MPLOCK1(dvp->v_mount);
1266 DO_OPS(ops, error, &ap, vop_nresolve);
1267 VFS_MPUNLOCK(dvp->v_mount);
1268 return(error);
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.
1276 * MPSAFE
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;
1283 VFS_MPLOCK_DECLARE;
1284 int error;
1286 ap.a_head.a_desc = &vop_nlookupdotdot_desc;
1287 ap.a_head.a_ops = ops;
1288 ap.a_dvp = dvp;
1289 ap.a_vpp = vpp;
1290 ap.a_cred = cred;
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);
1296 return(error);
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.
1309 * MPSAFE
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;
1316 VFS_MPLOCK_DECLARE;
1317 int error;
1319 ap.a_head.a_desc = &vop_ncreate_desc;
1320 ap.a_head.a_ops = ops;
1321 ap.a_nch = nch;
1322 ap.a_dvp = dvp;
1323 ap.a_vpp = vpp;
1324 ap.a_cred = cred;
1325 ap.a_vap = vap;
1327 VFS_MPLOCK1(dvp->v_mount);
1328 DO_OPS(ops, error, &ap, vop_ncreate);
1329 VFS_MPUNLOCK(dvp->v_mount);
1330 return(error);
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.
1343 * MPSAFE
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;
1350 VFS_MPLOCK_DECLARE;
1351 int error;
1353 ap.a_head.a_desc = &vop_nmkdir_desc;
1354 ap.a_head.a_ops = ops;
1355 ap.a_nch = nch;
1356 ap.a_dvp = dvp;
1357 ap.a_vpp = vpp;
1358 ap.a_cred = cred;
1359 ap.a_vap = vap;
1361 VFS_MPLOCK1(dvp->v_mount);
1362 DO_OPS(ops, error, &ap, vop_nmkdir);
1363 VFS_MPUNLOCK(dvp->v_mount);
1364 return(error);
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.
1377 * MPSAFE
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;
1384 VFS_MPLOCK_DECLARE;
1385 int error;
1387 ap.a_head.a_desc = &vop_nmknod_desc;
1388 ap.a_head.a_ops = ops;
1389 ap.a_nch = nch;
1390 ap.a_dvp = dvp;
1391 ap.a_vpp = vpp;
1392 ap.a_cred = cred;
1393 ap.a_vap = vap;
1395 VFS_MPLOCK1(dvp->v_mount);
1396 DO_OPS(ops, error, &ap, vop_nmknod);
1397 VFS_MPUNLOCK(dvp->v_mount);
1398 return(error);
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.
1412 * MPSAFE
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;
1419 VFS_MPLOCK_DECLARE;
1420 int error;
1422 ap.a_head.a_desc = &vop_nlink_desc;
1423 ap.a_head.a_ops = ops;
1424 ap.a_nch = nch;
1425 ap.a_dvp = dvp;
1426 ap.a_vp = vp;
1427 ap.a_cred = cred;
1429 VFS_MPLOCK1(dvp->v_mount);
1430 DO_OPS(ops, error, &ap, vop_nlink);
1431 VFS_MPUNLOCK(dvp->v_mount);
1432 return(error);
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
1439 * *vpp.
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.
1446 * MPSAFE
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;
1454 VFS_MPLOCK_DECLARE;
1455 int error;
1457 ap.a_head.a_desc = &vop_nsymlink_desc;
1458 ap.a_head.a_ops = ops;
1459 ap.a_nch = nch;
1460 ap.a_dvp = dvp;
1461 ap.a_vpp = vpp;
1462 ap.a_cred = cred;
1463 ap.a_vap = vap;
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);
1469 return(error);
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.
1481 * MPSAFE
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;
1488 VFS_MPLOCK_DECLARE;
1489 int error;
1491 ap.a_head.a_desc = &vop_nwhiteout_desc;
1492 ap.a_head.a_ops = ops;
1493 ap.a_nch = nch;
1494 ap.a_dvp = dvp;
1495 ap.a_cred = cred;
1496 ap.a_flags = flags;
1498 VFS_MPLOCK1(dvp->v_mount);
1499 DO_OPS(ops, error, &ap, vop_nwhiteout);
1500 VFS_MPUNLOCK(dvp->v_mount);
1501 return(error);
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.
1513 * MPSAFE
1516 vop_nremove(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1517 struct ucred *cred)
1519 struct vop_nremove_args ap;
1520 VFS_MPLOCK_DECLARE;
1521 int error;
1522 struct vattr va;
1524 ap.a_head.a_desc = &vop_nremove_desc;
1525 ap.a_head.a_ops = ops;
1526 ap.a_nch = nch;
1527 ap.a_dvp = dvp;
1528 ap.a_cred = cred;
1530 if ((error = VOP_GETATTR(nch->ncp->nc_vp, &va)) != 0)
1531 return (error);
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);
1540 return(error);
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.
1552 * MPSAFE
1555 vop_nrmdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1556 struct ucred *cred)
1558 struct vop_nrmdir_args ap;
1559 VFS_MPLOCK_DECLARE;
1560 int error;
1562 ap.a_head.a_desc = &vop_nrmdir_desc;
1563 ap.a_head.a_ops = ops;
1564 ap.a_nch = nch;
1565 ap.a_dvp = dvp;
1566 ap.a_cred = cred;
1568 VFS_MPLOCK1(dvp->v_mount);
1569 DO_OPS(ops, error, &ap, vop_nrmdir);
1570 VFS_MPUNLOCK(dvp->v_mount);
1571 return(error);
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.
1586 * MPSAFE
1589 vop_nrename(struct vop_ops *ops,
1590 struct nchandle *fnch, struct nchandle *tnch,
1591 struct vnode *fdvp, struct vnode *tdvp,
1592 struct ucred *cred)
1594 struct vop_nrename_args ap;
1595 VFS_MPLOCK_DECLARE;
1596 int error;
1598 ap.a_head.a_desc = &vop_nrename_desc;
1599 ap.a_head.a_ops = ops;
1600 ap.a_fnch = fnch;
1601 ap.a_tnch = tnch;
1602 ap.a_fdvp = fdvp;
1603 ap.a_tdvp = tdvp;
1604 ap.a_cred = cred;
1606 VFS_MPLOCK1(fdvp->v_mount);
1607 DO_OPS(ops, error, &ap, vop_nrename);
1608 VFS_MPUNLOCK(fdvp->v_mount);
1609 return(error);
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;
1628 int error;
1630 ops = ap->a_ops;
1631 error = VOCALL(ops, ap);
1633 return (error);
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;
1645 int error;
1647 ops = ap->a_ops;
1648 if (ops->head.vv_mount->mnt_vn_journal_ops)
1649 error = VOCALL(ops->head.vv_mount->mnt_vn_journal_ops, ap);
1650 else
1651 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1652 return (error);
1657 * This routine is called by the journaling layer to execute the actual
1658 * VFS operation.
1661 vop_journal_operate_ap(struct vop_generic_args *ap)
1663 struct vop_ops *ops;
1664 int error;
1666 ops = ap->a_ops;
1667 error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1669 return (error);
1673 vop_open_ap(struct vop_open_args *ap)
1675 int error;
1677 DO_OPS(ap->a_head.a_ops, error, ap, vop_open);
1678 return(error);
1682 vop_close_ap(struct vop_close_args *ap)
1684 int error;
1686 DO_OPS(ap->a_head.a_ops, error, ap, vop_close);
1687 return(error);
1691 vop_access_ap(struct vop_access_args *ap)
1693 int error;
1695 DO_OPS(ap->a_head.a_ops, error, ap, vop_access);
1696 return(error);
1700 vop_getattr_ap(struct vop_getattr_args *ap)
1702 int error;
1704 DO_OPS(ap->a_head.a_ops, error, ap, vop_getattr);
1705 return(error);
1709 vop_setattr_ap(struct vop_setattr_args *ap)
1711 int error;
1713 DO_OPS(ap->a_head.a_ops, error, ap, vop_setattr);
1714 return(error);
1718 vop_read_ap(struct vop_read_args *ap)
1720 int error;
1722 DO_OPS(ap->a_head.a_ops, error, ap, vop_read);
1723 return(error);
1727 vop_write_ap(struct vop_write_args *ap)
1729 int error;
1731 DO_OPS(ap->a_head.a_ops, error, ap, vop_write);
1732 return(error);
1736 vop_ioctl_ap(struct vop_ioctl_args *ap)
1738 int error;
1740 DO_OPS(ap->a_head.a_ops, error, ap, vop_ioctl);
1741 return(error);
1745 vop_poll_ap(struct vop_poll_args *ap)
1747 int error;
1749 DO_OPS(ap->a_head.a_ops, error, ap, vop_poll);
1750 return(error);
1754 vop_kqfilter_ap(struct vop_kqfilter_args *ap)
1756 int error;
1758 DO_OPS(ap->a_head.a_ops, error, ap, vop_kqfilter);
1759 return(error);
1763 vop_mmap_ap(struct vop_mmap_args *ap)
1765 int error;
1767 DO_OPS(ap->a_head.a_ops, error, ap, vop_mmap);
1768 return(error);
1772 vop_fsync_ap(struct vop_fsync_args *ap)
1774 int error;
1776 DO_OPS(ap->a_head.a_ops, error, ap, vop_fsync);
1777 return(error);
1781 vop_readdir_ap(struct vop_readdir_args *ap)
1783 int error;
1785 DO_OPS(ap->a_head.a_ops, error, ap, vop_readdir);
1786 return(error);
1790 vop_readlink_ap(struct vop_readlink_args *ap)
1792 int error;
1794 DO_OPS(ap->a_head.a_ops, error, ap, vop_readlink);
1795 return(error);
1799 vop_inactive_ap(struct vop_inactive_args *ap)
1801 int error;
1803 DO_OPS(ap->a_head.a_ops, error, ap, vop_inactive);
1804 return(error);
1808 vop_reclaim_ap(struct vop_reclaim_args *ap)
1810 int error;
1812 DO_OPS(ap->a_head.a_ops, error, ap, vop_reclaim);
1813 return(error);
1817 vop_bmap_ap(struct vop_bmap_args *ap)
1819 int error;
1821 DO_OPS(ap->a_head.a_ops, error, ap, vop_bmap);
1822 return(error);
1826 vop_strategy_ap(struct vop_strategy_args *ap)
1828 int error;
1830 DO_OPS(ap->a_head.a_ops, error, ap, vop_strategy);
1831 return(error);
1835 vop_print_ap(struct vop_print_args *ap)
1837 int error;
1839 DO_OPS(ap->a_head.a_ops, error, ap, vop_print);
1840 return(error);
1844 vop_pathconf_ap(struct vop_pathconf_args *ap)
1846 int error;
1848 DO_OPS(ap->a_head.a_ops, error, ap, vop_pathconf);
1849 return(error);
1853 vop_advlock_ap(struct vop_advlock_args *ap)
1855 int error;
1857 DO_OPS(ap->a_head.a_ops, error, ap, vop_advlock);
1858 return(error);
1862 vop_balloc_ap(struct vop_balloc_args *ap)
1864 int error;
1866 DO_OPS(ap->a_head.a_ops, error, ap, vop_balloc);
1867 return(error);
1871 vop_reallocblks_ap(struct vop_reallocblks_args *ap)
1873 int error;
1875 DO_OPS(ap->a_head.a_ops, error, ap, vop_reallocblks);
1876 return(error);
1880 vop_getpages_ap(struct vop_getpages_args *ap)
1882 int error;
1884 DO_OPS(ap->a_head.a_ops, error, ap, vop_getpages);
1885 return(error);
1889 vop_putpages_ap(struct vop_putpages_args *ap)
1891 int error;
1893 DO_OPS(ap->a_head.a_ops, error, ap, vop_putpages);
1894 return(error);
1898 vop_freeblks_ap(struct vop_freeblks_args *ap)
1900 int error;
1902 DO_OPS(ap->a_head.a_ops, error, ap, vop_freeblks);
1903 return(error);
1907 vop_getacl_ap(struct vop_getacl_args *ap)
1909 int error;
1911 DO_OPS(ap->a_head.a_ops, error, ap, vop_getacl);
1912 return(error);
1916 vop_setacl_ap(struct vop_setacl_args *ap)
1918 int error;
1920 DO_OPS(ap->a_head.a_ops, error, ap, vop_setacl);
1921 return(error);
1925 vop_aclcheck_ap(struct vop_aclcheck_args *ap)
1927 int error;
1929 DO_OPS(ap->a_head.a_ops, error, ap, vop_aclcheck);
1930 return(error);
1934 vop_getextattr_ap(struct vop_getextattr_args *ap)
1936 int error;
1938 DO_OPS(ap->a_head.a_ops, error, ap, vop_getextattr);
1939 return(error);
1943 vop_setextattr_ap(struct vop_setextattr_args *ap)
1945 int error;
1947 DO_OPS(ap->a_head.a_ops, error, ap, vop_setextattr);
1948 return(error);
1952 vop_mountctl_ap(struct vop_mountctl_args *ap)
1954 int error;
1956 DO_OPS(ap->a_head.a_ops, error, ap, vop_mountctl);
1957 return(error);
1961 vop_markatime_ap(struct vop_markatime_args *ap)
1963 int error;
1965 DO_OPS(ap->a_head.a_ops, error, ap, vop_markatime);
1966 return(error);
1970 vop_nresolve_ap(struct vop_nresolve_args *ap)
1972 int error;
1974 DO_OPS(ap->a_head.a_ops, error, ap, vop_nresolve);
1975 return(error);
1979 vop_nlookupdotdot_ap(struct vop_nlookupdotdot_args *ap)
1981 int error;
1983 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlookupdotdot);
1984 return(error);
1988 vop_ncreate_ap(struct vop_ncreate_args *ap)
1990 int error;
1992 DO_OPS(ap->a_head.a_ops, error, ap, vop_ncreate);
1993 return(error);
1997 vop_nmkdir_ap(struct vop_nmkdir_args *ap)
1999 int error;
2001 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmkdir);
2002 return(error);
2006 vop_nmknod_ap(struct vop_nmknod_args *ap)
2008 int error;
2010 DO_OPS(ap->a_head.a_ops, error, ap, vop_nmknod);
2011 return(error);
2015 vop_nlink_ap(struct vop_nlink_args *ap)
2017 int error;
2019 DO_OPS(ap->a_head.a_ops, error, ap, vop_nlink);
2020 return(error);
2024 vop_nsymlink_ap(struct vop_nsymlink_args *ap)
2026 int error;
2028 DO_OPS(ap->a_head.a_ops, error, ap, vop_nsymlink);
2029 return(error);
2033 vop_nwhiteout_ap(struct vop_nwhiteout_args *ap)
2035 int error;
2037 DO_OPS(ap->a_head.a_ops, error, ap, vop_nwhiteout);
2038 return(error);
2042 vop_nremove_ap(struct vop_nremove_args *ap)
2044 int error;
2046 DO_OPS(ap->a_head.a_ops, error, ap, vop_nremove);
2047 return(error);
2051 vop_nrmdir_ap(struct vop_nrmdir_args *ap)
2053 int error;
2055 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrmdir);
2056 return(error);
2060 vop_nrename_ap(struct vop_nrename_args *ap)
2062 int error;
2064 DO_OPS(ap->a_head.a_ops, error, ap, vop_nrename);
2065 return(error);