xref: /dragonfly/sys/kern/vfs_vopops.c (revision 1a05b9d1)
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:
10  *
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.
20  *
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.
33  */
34 /*
35  * Implement vnode ops wrappers.  All vnode ops are wrapped through
36  * these functions.
37  *
38  * These wrappers are responsible for hanlding all MPSAFE issues related
39  * to a vnode operation.
40  */
41 
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>
67 
68 #include <machine/limits.h>
69 
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>
80 
81 #include <sys/buf2.h>
82 #include <sys/mplock2.h>
83 
84 #define VDESCNAME(name)	__CONCAT(__CONCAT(vop_,name),_desc)
85 
86 #define VNODEOP_DESC_INIT(name)						\
87 	struct syslink_desc VDESCNAME(name) = {				\
88 		__offsetof(struct vop_ops, __CONCAT(vop_, name)),	\
89 		#name }
90 
91 VNODEOP_DESC_INIT(default);
92 VNODEOP_DESC_INIT(old_lookup);
93 VNODEOP_DESC_INIT(old_create);
94 VNODEOP_DESC_INIT(old_whiteout);
95 VNODEOP_DESC_INIT(old_mknod);
96 VNODEOP_DESC_INIT(open);
97 VNODEOP_DESC_INIT(close);
98 VNODEOP_DESC_INIT(access);
99 VNODEOP_DESC_INIT(getattr);
100 VNODEOP_DESC_INIT(getattr_quick);
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);
112 
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);
137 
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);
149 
150 #define DO_OPS(ops, error, ap, vop_field)	\
151 	error = ops->vop_field(ap)
152 
153 /************************************************************************
154  *		PRIMARY HIGH LEVEL VNODE OPERATIONS CALLS		*
155  ************************************************************************
156  *
157  * These procedures are called directly from the kernel and/or fileops
158  * code to perform file/device operations on the system.
159  *
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.
164  *
165  * NOTE: The VFS_MPLOCK() macro handle mounts which do not set MNTK_MPSAFE.
166  *
167  * MPSAFE
168  */
169 
170 int
171 vop_old_lookup(struct vop_ops *ops, struct vnode *dvp,
172 	struct vnode **vpp, struct componentname *cnp)
173 {
174 	struct vop_old_lookup_args ap;
175 	VFS_MPLOCK_DECLARE;
176 	int error;
177 
178 	ap.a_head.a_desc = &vop_old_lookup_desc;
179 	ap.a_head.a_ops = ops;
180 	ap.a_dvp = dvp;
181 	ap.a_vpp = vpp;
182 	ap.a_cnp = cnp;
183 	VFS_MPLOCK(dvp->v_mount);
184 	DO_OPS(ops, error, &ap, vop_old_lookup);
185 	VFS_MPUNLOCK();
186 
187 	return(error);
188 }
189 
190 /*
191  * MPSAFE
192  */
193 int
194 vop_old_create(struct vop_ops *ops, struct vnode *dvp,
195 	struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
196 {
197 	struct vop_old_create_args ap;
198 	VFS_MPLOCK_DECLARE;
199 	int error;
200 
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;
207 
208 	VFS_MPLOCK(dvp->v_mount);
209 	DO_OPS(ops, error, &ap, vop_old_create);
210 	VFS_MPUNLOCK();
211 
212 	return(error);
213 }
214 
215 /*
216  * MPSAFE
217  */
218 int
219 vop_old_whiteout(struct vop_ops *ops, struct vnode *dvp,
220 	struct componentname *cnp, int flags)
221 {
222 	struct vop_old_whiteout_args ap;
223 	VFS_MPLOCK_DECLARE;
224 	int error;
225 
226 	ap.a_head.a_desc = &vop_old_whiteout_desc;
227 	ap.a_head.a_ops = ops;
228 	ap.a_dvp = dvp;
229 	ap.a_cnp = cnp;
230 	ap.a_flags = flags;
231 
232 	VFS_MPLOCK(dvp->v_mount);
233 	DO_OPS(ops, error, &ap, vop_old_whiteout);
234 	VFS_MPUNLOCK();
235 
236 	return(error);
237 }
238 
239 /*
240  * MPSAFE
241  */
242 int
243 vop_old_mknod(struct vop_ops *ops, struct vnode *dvp,
244 	struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
245 {
246 	struct vop_old_mknod_args ap;
247 	VFS_MPLOCK_DECLARE;
248 	int error;
249 
250 	ap.a_head.a_desc = &vop_old_mknod_desc;
251 	ap.a_head.a_ops = ops;
252 	ap.a_dvp = dvp;
253 	ap.a_vpp = vpp;
254 	ap.a_cnp = cnp;
255 	ap.a_vap = vap;
256 
257 	VFS_MPLOCK(dvp->v_mount);
258 	DO_OPS(ops, error, &ap, vop_old_mknod);
259 	VFS_MPUNLOCK();
260 
261 	return(error);
262 }
263 
264 /*
265  * NOTE: VAGE is always cleared when calling VOP_OPEN().
266  */
267 int
268 vop_open(struct vop_ops *ops, struct vnode *vp, int mode, struct ucred *cred,
269 	struct file *fp)
270 {
271 	struct vop_open_args ap;
272 	VFS_MPLOCK_DECLARE;
273 	int error;
274 
275 	/*
276 	 * Decrement 3-2-1-0.  Does not decrement beyond 0
277 	 */
278 	if (vp->v_flag & VAGE0) {
279 		vclrflags(vp, VAGE0);
280 	} else if (vp->v_flag & VAGE1) {
281 		vclrflags(vp, VAGE1);
282 		vsetflags(vp, VAGE0);
283 	}
284 
285 	ap.a_head.a_desc = &vop_open_desc;
286 	ap.a_head.a_ops = ops;
287 	ap.a_vp = vp;
288 	ap.a_fp = fp;
289 	ap.a_mode = mode;
290 	ap.a_cred = cred;
291 
292 	VFS_MPLOCK(vp->v_mount);
293 	DO_OPS(ops, error, &ap, vop_open);
294 	VFS_MPUNLOCK();
295 
296 	return(error);
297 }
298 
299 /*
300  * MPSAFE
301  */
302 int
303 vop_close(struct vop_ops *ops, struct vnode *vp, int fflag,
304          struct file *fp)
305 {
306 	struct vop_close_args ap;
307 	VFS_MPLOCK_DECLARE;
308 	int error;
309 
310 	ap.a_head.a_desc = &vop_close_desc;
311 	ap.a_head.a_ops = ops;
312 	ap.a_vp = vp;
313 	ap.a_fp = fp;
314 	ap.a_fflag = fflag;
315 
316 	VFS_MPLOCK(vp->v_mount);
317 	DO_OPS(ops, error, &ap, vop_close);
318 	VFS_MPUNLOCK();
319 
320 	return(error);
321 }
322 
323 /*
324  * MPSAFE
325  */
326 int
327 vop_access(struct vop_ops *ops, struct vnode *vp, int mode, int flags,
328 	   struct ucred *cred)
329 {
330 	struct vop_access_args ap;
331 	VFS_MPLOCK_DECLARE;
332 	int error;
333 
334 	ap.a_head.a_desc = &vop_access_desc;
335 	ap.a_head.a_ops = ops;
336 	ap.a_vp = vp;
337 	ap.a_mode = mode;
338 	ap.a_flags = flags;
339 	ap.a_cred = cred;
340 
341 	VFS_MPLOCK(vp->v_mount);
342 	DO_OPS(ops, error, &ap, vop_access);
343 	VFS_MPUNLOCK();
344 
345 	return(error);
346 }
347 
348 /*
349  * MPSAFE
350  */
351 int
352 vop_getattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap,
353 	struct file *fp)
354 {
355 	struct vop_getattr_args ap;
356 	VFS_MPLOCK_DECLARE;
357 	int error;
358 
359 	ap.a_head.a_desc = &vop_getattr_desc;
360 	ap.a_head.a_ops = ops;
361 	ap.a_vp = vp;
362 	ap.a_vap = vap;
363 	ap.a_fp = fp;
364 
365 	VFS_MPLOCK_FLAG(vp->v_mount, MNTK_GA_MPSAFE);
366 	DO_OPS(ops, error, &ap, vop_getattr);
367 	VFS_MPUNLOCK();
368 
369 	return(error);
370 }
371 
372 /*
373  * MPSAFE
374  */
375 int
376 vop_getattr_quick(struct vop_ops *ops, struct vnode *vp, struct vattr *vap)
377 {
378 	struct vop_getattr_args ap;
379 	VFS_MPLOCK_DECLARE;
380 	int error;
381 
382 	ap.a_head.a_desc = &vop_getattr_quick_desc;
383 	ap.a_head.a_ops = ops;
384 	ap.a_vp = vp;
385 	ap.a_vap = vap;
386 	ap.a_fp = NULL;
387 
388 	VFS_MPLOCK_FLAG(vp->v_mount, MNTK_GA_MPSAFE);
389 	DO_OPS(ops, error, &ap, vop_getattr_quick);
390 	VFS_MPUNLOCK();
391 
392 	return(error);
393 }
394 
395 /*
396  * MPSAFE
397  */
398 int
399 vop_setattr(struct vop_ops *ops, struct vnode *vp, struct vattr *vap,
400 	struct ucred *cred, struct file *fp)
401 {
402 	struct vop_setattr_args ap;
403 	VFS_MPLOCK_DECLARE;
404 	int error;
405 
406 	ap.a_head.a_desc = &vop_setattr_desc;
407 	ap.a_head.a_ops = ops;
408 	ap.a_vp = vp;
409 	ap.a_vap = vap;
410 	ap.a_cred = cred;
411 	ap.a_fp = fp;
412 
413 	VFS_MPLOCK(vp->v_mount);
414 	DO_OPS(ops, error, &ap, vop_setattr);
415 	VFS_MPUNLOCK();
416 
417 	return(error);
418 }
419 
420 /*
421  * MPSAFE
422  */
423 int
424 vop_read(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
425 	struct ucred *cred, struct file *fp)
426 {
427 	struct vop_read_args ap;
428 	VFS_MPLOCK_DECLARE;
429 	int error;
430 
431 	ap.a_head.a_desc = &vop_read_desc;
432 	ap.a_head.a_ops = ops;
433 	ap.a_vp = vp;
434 	ap.a_uio = uio;
435 	ap.a_ioflag = ioflag;
436 	ap.a_cred = cred;
437 	ap.a_fp = fp;
438 
439 	VFS_MPLOCK_FLAG(vp->v_mount, MNTK_RD_MPSAFE);
440 	DO_OPS(ops, error, &ap, vop_read);
441 	VFS_MPUNLOCK();
442 
443 	return(error);
444 }
445 
446 /*
447  * MPSAFE
448  */
449 int
450 vop_write(struct vop_ops *ops, struct vnode *vp, struct uio *uio, int ioflag,
451 	struct ucred *cred, struct file *fp)
452 {
453 	struct vop_write_args ap;
454 	VFS_MPLOCK_DECLARE;
455 	int error, do_accounting = 0;
456 	struct vattr va;
457 	uint64_t size_before=0, size_after=0;
458 	struct mount *mp;
459 	uint64_t offset, delta;
460 
461 	ap.a_head.a_desc = &vop_write_desc;
462 	ap.a_head.a_ops = ops;
463 	ap.a_vp = vp;
464 	ap.a_uio = uio;
465 	ap.a_ioflag = ioflag;
466 	ap.a_cred = cred;
467 	ap.a_fp = fp;
468 
469 	/* is this a regular vnode ? */
470 	VFS_MPLOCK_FLAG(vp->v_mount, MNTK_WR_MPSAFE);
471 	if (vfs_quota_enabled && (vp->v_type == VREG)) {
472 		if ((error = VOP_GETATTR(vp, &va)) != 0)
473 			goto done;
474 		size_before = va.va_size;
475 		/* this file may already have been removed */
476 		if (va.va_nlink > 0)
477 			do_accounting = 1;
478 
479 		offset = uio->uio_offset;
480 		if (ioflag & IO_APPEND)
481 			offset = size_before;
482 		size_after = offset + uio->uio_resid;
483 		if (size_after < size_before)
484 			size_after = size_before;
485 		delta = size_after - size_before;
486 		mp = vq_vptomp(vp);
487 		/* QUOTA CHECK */
488 		if (!vq_write_ok(mp, va.va_uid, va.va_gid, delta)) {
489 			error = EDQUOT;
490 			goto done;
491 		}
492 	}
493 	DO_OPS(ops, error, &ap, vop_write);
494 	if ((error == 0) && do_accounting) {
495 		VFS_ACCOUNT(mp, va.va_uid, va.va_gid, size_after - size_before);
496 	}
497 done:
498 	VFS_MPUNLOCK();
499 
500 	return(error);
501 }
502 
503 /*
504  * MPSAFE
505  */
506 int
507 vop_ioctl(struct vop_ops *ops, struct vnode *vp, u_long command, caddr_t data,
508 	int fflag, struct ucred *cred, struct sysmsg *msg)
509 {
510 	struct vop_ioctl_args ap;
511 	VFS_MPLOCK_DECLARE;
512 	int error;
513 
514 	ap.a_head.a_desc = &vop_ioctl_desc;
515 	ap.a_head.a_ops = ops;
516 	ap.a_vp = vp;
517 	ap.a_command = command;
518 	ap.a_data = data;
519 	ap.a_fflag = fflag;
520 	ap.a_cred = cred;
521 	ap.a_sysmsg = msg;
522 
523 	VFS_MPLOCK(vp->v_mount);
524 	DO_OPS(ops, error, &ap, vop_ioctl);
525 	VFS_MPUNLOCK();
526 
527 	return(error);
528 }
529 
530 /*
531  * MPSAFE
532  */
533 int
534 vop_poll(struct vop_ops *ops, struct vnode *vp, int events, struct ucred *cred)
535 {
536 	struct vop_poll_args ap;
537 	VFS_MPLOCK_DECLARE;
538 	int error;
539 
540 	ap.a_head.a_desc = &vop_poll_desc;
541 	ap.a_head.a_ops = ops;
542 	ap.a_vp = vp;
543 	ap.a_events = events;
544 	ap.a_cred = cred;
545 
546 	VFS_MPLOCK(vp->v_mount);
547 	DO_OPS(ops, error, &ap, vop_poll);
548 	VFS_MPUNLOCK();
549 
550 	return(error);
551 }
552 
553 /*
554  * MPSAFE
555  */
556 int
557 vop_kqfilter(struct vop_ops *ops, struct vnode *vp, struct knote *kn)
558 {
559 	struct vop_kqfilter_args ap;
560 	VFS_MPLOCK_DECLARE;
561 	int error;
562 
563 	ap.a_head.a_desc = &vop_kqfilter_desc;
564 	ap.a_head.a_ops = ops;
565 	ap.a_vp = vp;
566 	ap.a_kn = kn;
567 
568 	VFS_MPLOCK(vp->v_mount);
569 	DO_OPS(ops, error, &ap, vop_kqfilter);
570 	VFS_MPUNLOCK();
571 
572 	return(error);
573 }
574 
575 /*
576  * MPSAFE
577  */
578 int
579 vop_mmap(struct vop_ops *ops, struct vnode *vp, int fflags, struct ucred *cred)
580 {
581 	struct vop_mmap_args ap;
582 	VFS_MPLOCK_DECLARE;
583 	int error;
584 
585 	ap.a_head.a_desc = &vop_mmap_desc;
586 	ap.a_head.a_ops = ops;
587 	ap.a_vp = vp;
588 	ap.a_fflags = fflags;
589 	ap.a_cred = cred;
590 
591 	VFS_MPLOCK(vp->v_mount);
592 	DO_OPS(ops, error, &ap, vop_mmap);
593 	VFS_MPUNLOCK();
594 
595 	return(error);
596 }
597 
598 /*
599  * MPSAFE
600  */
601 int
602 vop_fsync(struct vop_ops *ops, struct vnode *vp, int waitfor, int flags,
603 	struct file *fp)
604 {
605 	struct vop_fsync_args ap;
606 	VFS_MPLOCK_DECLARE;
607 	int error;
608 
609 	ap.a_head.a_desc = &vop_fsync_desc;
610 	ap.a_head.a_ops = ops;
611 	ap.a_vp = vp;
612 	ap.a_waitfor = waitfor;
613 	ap.a_flags = flags;
614 	ap.a_fp = fp;
615 
616 	VFS_MPLOCK(vp->v_mount);
617 	DO_OPS(ops, error, &ap, vop_fsync);
618 	VFS_MPUNLOCK();
619 
620 	return(error);
621 }
622 
623 /*
624  * MPSAFE
625  */
626 int
627 vop_old_remove(struct vop_ops *ops, struct vnode *dvp,
628 	struct vnode *vp, struct componentname *cnp)
629 {
630 	struct vop_old_remove_args ap;
631 	VFS_MPLOCK_DECLARE;
632 	int error;
633 
634 	ap.a_head.a_desc = &vop_old_remove_desc;
635 	ap.a_head.a_ops = ops;
636 	ap.a_dvp = dvp;
637 	ap.a_vp = vp;
638 	ap.a_cnp = cnp;
639 
640 	VFS_MPLOCK(dvp->v_mount);
641 	DO_OPS(ops, error, &ap, vop_old_remove);
642 	VFS_MPUNLOCK();
643 
644 	return(error);
645 }
646 
647 /*
648  * MPSAFE
649  */
650 int
651 vop_old_link(struct vop_ops *ops, struct vnode *tdvp,
652 	struct vnode *vp, struct componentname *cnp)
653 {
654 	struct vop_old_link_args ap;
655 	VFS_MPLOCK_DECLARE;
656 	int error;
657 
658 	ap.a_head.a_desc = &vop_old_link_desc;
659 	ap.a_head.a_ops = ops;
660 	ap.a_tdvp = tdvp;
661 	ap.a_vp = vp;
662 	ap.a_cnp = cnp;
663 
664 	VFS_MPLOCK(tdvp->v_mount);
665 	DO_OPS(ops, error, &ap, vop_old_link);
666 	VFS_MPUNLOCK();
667 
668 	return(error);
669 }
670 
671 /*
672  * MPSAFE
673  */
674 int
675 vop_old_rename(struct vop_ops *ops,
676 	   struct vnode *fdvp, struct vnode *fvp, struct componentname *fcnp,
677 	   struct vnode *tdvp, struct vnode *tvp, struct componentname *tcnp)
678 {
679 	struct vop_old_rename_args ap;
680 	VFS_MPLOCK_DECLARE;
681 	int error;
682 
683 	ap.a_head.a_desc = &vop_old_rename_desc;
684 	ap.a_head.a_ops = ops;
685 	ap.a_fdvp = fdvp;
686 	ap.a_fvp = fvp;
687 	ap.a_fcnp = fcnp;
688 	ap.a_tdvp = tdvp;
689 	ap.a_tvp = tvp;
690 	ap.a_tcnp = tcnp;
691 
692 	VFS_MPLOCK(tdvp->v_mount);
693 	DO_OPS(ops, error, &ap, vop_old_rename);
694 	VFS_MPUNLOCK();
695 
696 	return(error);
697 }
698 
699 /*
700  * MPSAFE
701  */
702 int
703 vop_old_mkdir(struct vop_ops *ops, struct vnode *dvp,
704 	struct vnode **vpp, struct componentname *cnp, struct vattr *vap)
705 {
706 	struct vop_old_mkdir_args ap;
707 	VFS_MPLOCK_DECLARE;
708 	int error;
709 
710 	ap.a_head.a_desc = &vop_old_mkdir_desc;
711 	ap.a_head.a_ops = ops;
712 	ap.a_dvp = dvp;
713 	ap.a_vpp = vpp;
714 	ap.a_cnp = cnp;
715 	ap.a_vap = vap;
716 
717 	VFS_MPLOCK(dvp->v_mount);
718 	DO_OPS(ops, error, &ap, vop_old_mkdir);
719 	VFS_MPUNLOCK();
720 
721 	return(error);
722 }
723 
724 /*
725  * MPSAFE
726  */
727 int
728 vop_old_rmdir(struct vop_ops *ops, struct vnode *dvp,
729 	struct vnode *vp, struct componentname *cnp)
730 {
731 	struct vop_old_rmdir_args ap;
732 	VFS_MPLOCK_DECLARE;
733 	int error;
734 
735 	ap.a_head.a_desc = &vop_old_rmdir_desc;
736 	ap.a_head.a_ops = ops;
737 	ap.a_dvp = dvp;
738 	ap.a_vp = vp;
739 	ap.a_cnp = cnp;
740 
741 	VFS_MPLOCK(dvp->v_mount);
742 	DO_OPS(ops, error, &ap, vop_old_rmdir);
743 	VFS_MPUNLOCK();
744 
745 	return(error);
746 }
747 
748 /*
749  * MPSAFE
750  */
751 int
752 vop_old_symlink(struct vop_ops *ops, struct vnode *dvp,
753 	struct vnode **vpp, struct componentname *cnp,
754 	struct vattr *vap, char *target)
755 {
756 	struct vop_old_symlink_args ap;
757 	VFS_MPLOCK_DECLARE;
758 	int error;
759 
760 	ap.a_head.a_desc = &vop_old_symlink_desc;
761 	ap.a_head.a_ops = ops;
762 	ap.a_dvp = dvp;
763 	ap.a_vpp = vpp;
764 	ap.a_cnp = cnp;
765 	ap.a_vap = vap;
766 	ap.a_target = target;
767 
768 	VFS_MPLOCK(dvp->v_mount);
769 	DO_OPS(ops, error, &ap, vop_old_symlink);
770 	VFS_MPUNLOCK();
771 
772 	return(error);
773 }
774 
775 /*
776  * MPSAFE
777  */
778 int
779 vop_readdir(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
780 	struct ucred *cred, int *eofflag, int *ncookies, off_t **cookies,
781 	struct file *fp)
782 {
783 	struct vop_readdir_args ap;
784 	VFS_MPLOCK_DECLARE;
785 	int error;
786 
787 	ap.a_head.a_desc = &vop_readdir_desc;
788 	ap.a_head.a_ops = ops;
789 	ap.a_vp = vp;
790 	ap.a_uio = uio;
791 	ap.a_cred = cred;
792 	ap.a_eofflag = eofflag;
793 	ap.a_ncookies = ncookies;
794 	ap.a_cookies = cookies;
795 	ap.a_fp = fp;
796 
797 	VFS_MPLOCK(vp->v_mount);
798 	DO_OPS(ops, error, &ap, vop_readdir);
799 	VFS_MPUNLOCK();
800 
801 	return(error);
802 }
803 
804 /*
805  * MPSAFE
806  */
807 int
808 vop_readlink(struct vop_ops *ops, struct vnode *vp, struct uio *uio,
809 	struct ucred *cred)
810 {
811 	struct vop_readlink_args ap;
812 	VFS_MPLOCK_DECLARE;
813 	int error;
814 
815 	ap.a_head.a_desc = &vop_readlink_desc;
816 	ap.a_head.a_ops = ops;
817 	ap.a_vp = vp;
818 	ap.a_uio = uio;
819 	ap.a_cred = cred;
820 
821 	VFS_MPLOCK(vp->v_mount);
822 	DO_OPS(ops, error, &ap, vop_readlink);
823 	VFS_MPUNLOCK();
824 
825 	return(error);
826 }
827 
828 /*
829  * MPSAFE
830  */
831 int
832 vop_inactive(struct vop_ops *ops, struct vnode *vp)
833 {
834 	struct vop_inactive_args ap;
835 	struct mount *mp;
836 	VFS_MPLOCK_DECLARE;
837 	int error;
838 
839 	ap.a_head.a_desc = &vop_inactive_desc;
840 	ap.a_head.a_ops = ops;
841 	ap.a_vp = vp;
842 
843 	/*
844 	 * WARNING!  Deactivation of the vnode can cause it to be recycled,
845 	 *	     clearing vp->v_mount.
846 	 */
847 	mp = vp->v_mount;
848 	VFS_MPLOCK_FLAG(mp, MNTK_IN_MPSAFE);
849 	DO_OPS(ops, error, &ap, vop_inactive);
850 	VFS_MPUNLOCK();
851 
852 	return(error);
853 }
854 
855 /*
856  * MPSAFE
857  */
858 int
859 vop_reclaim(struct vop_ops *ops, struct vnode *vp)
860 {
861 	struct vop_reclaim_args ap;
862 	struct mount *mp;
863 	VFS_MPLOCK_DECLARE;
864 	int error;
865 
866 	ap.a_head.a_desc = &vop_reclaim_desc;
867 	ap.a_head.a_ops = ops;
868 	ap.a_vp = vp;
869 
870 	/*
871 	 * WARNING!  Reclamation of the vnode will clear vp->v_mount.
872 	 */
873 	mp = vp->v_mount;
874 	VFS_MPLOCK(mp);
875 	DO_OPS(ops, error, &ap, vop_reclaim);
876 	VFS_MPUNLOCK();
877 
878 	return(error);
879 }
880 
881 /*
882  * MPSAFE
883  */
884 int
885 vop_bmap(struct vop_ops *ops, struct vnode *vp, off_t loffset,
886 	off_t *doffsetp, int *runp, int *runb, buf_cmd_t cmd)
887 {
888 	struct vop_bmap_args ap;
889 	VFS_MPLOCK_DECLARE;
890 	int error;
891 
892 	ap.a_head.a_desc = &vop_bmap_desc;
893 	ap.a_head.a_ops = ops;
894 	ap.a_vp = vp;
895 	ap.a_loffset = loffset;
896 	ap.a_doffsetp = doffsetp;
897 	ap.a_runp = runp;
898 	ap.a_runb = runb;
899 	ap.a_cmd = cmd;
900 
901 	VFS_MPLOCK(vp->v_mount);
902 	DO_OPS(ops, error, &ap, vop_bmap);
903 	VFS_MPUNLOCK();
904 
905 	return(error);
906 }
907 
908 /*
909  * WARNING!  Vnode can go-away after the ops call (e.g. async flush
910  *	     from buffer kthread).
911  */
912 int
913 vop_strategy(struct vop_ops *ops, struct vnode *vp, struct bio *bio)
914 {
915 	struct vop_strategy_args ap;
916 	VFS_MPLOCK_DECLARE;
917 	int error;
918 
919 	ap.a_head.a_desc = &vop_strategy_desc;
920 	ap.a_head.a_ops = ops;
921 	ap.a_vp = vp;
922 	ap.a_bio = bio;
923 
924 	if (vp->v_mount) {
925 		VFS_MPLOCK_FLAG(vp->v_mount, MNTK_SG_MPSAFE);
926 		DO_OPS(ops, error, &ap, vop_strategy);
927 		VFS_MPUNLOCK();
928 	} else {
929 		/* ugly hack for swap */
930 		get_mplock();
931 		DO_OPS(ops, error, &ap, vop_strategy);
932 		rel_mplock();
933 	}
934 	return(error);
935 }
936 
937 /*
938  * MPSAFE
939  */
940 int
941 vop_print(struct vop_ops *ops, struct vnode *vp)
942 {
943 	struct vop_print_args ap;
944 	VFS_MPLOCK_DECLARE;
945 	int error;
946 
947 	ap.a_head.a_desc = &vop_print_desc;
948 	ap.a_head.a_ops = ops;
949 	ap.a_vp = vp;
950 
951 	VFS_MPLOCK(vp->v_mount);
952 	DO_OPS(ops, error, &ap, vop_print);
953 	VFS_MPUNLOCK();
954 
955 	return(error);
956 }
957 
958 /*
959  * MPSAFE
960  */
961 int
962 vop_pathconf(struct vop_ops *ops, struct vnode *vp, int name,
963 	register_t *retval)
964 {
965 	struct vop_pathconf_args ap;
966 	VFS_MPLOCK_DECLARE;
967 	int error;
968 
969 	ap.a_head.a_desc = &vop_pathconf_desc;
970 	ap.a_head.a_ops = ops;
971 	ap.a_vp = vp;
972 	ap.a_name = name;
973 	ap.a_retval = retval;
974 
975 	VFS_MPLOCK(vp->v_mount);
976 	DO_OPS(ops, error, &ap, vop_pathconf);
977 	VFS_MPUNLOCK();
978 
979 	return(error);
980 }
981 
982 /*
983  * MPSAFE
984  */
985 int
986 vop_advlock(struct vop_ops *ops, struct vnode *vp, caddr_t id, int op,
987 	struct flock *fl, int flags)
988 {
989 	struct vop_advlock_args ap;
990 	VFS_MPLOCK_DECLARE;
991 	int error;
992 
993 	ap.a_head.a_desc = &vop_advlock_desc;
994 	ap.a_head.a_ops = ops;
995 	ap.a_vp = vp;
996 	ap.a_id = id;
997 	ap.a_op = op;
998 	ap.a_fl = fl;
999 	ap.a_flags = flags;
1000 
1001 	VFS_MPLOCK(vp->v_mount);
1002 	DO_OPS(ops, error, &ap, vop_advlock);
1003 	VFS_MPUNLOCK();
1004 
1005 	return(error);
1006 }
1007 
1008 /*
1009  * MPSAFE
1010  */
1011 int
1012 vop_balloc(struct vop_ops *ops, struct vnode *vp, off_t startoffset,
1013 	int size, struct ucred *cred, int flags,
1014 	struct buf **bpp)
1015 {
1016 	struct vop_balloc_args ap;
1017 	VFS_MPLOCK_DECLARE;
1018 	int error;
1019 
1020 	ap.a_head.a_desc = &vop_balloc_desc;
1021 	ap.a_head.a_ops = ops;
1022 	ap.a_vp = vp;
1023 	ap.a_startoffset = startoffset;
1024 	ap.a_size = size;
1025 	ap.a_cred = cred;
1026 	ap.a_flags = flags;
1027 	ap.a_bpp = bpp;
1028 
1029 	VFS_MPLOCK(vp->v_mount);
1030 	DO_OPS(ops, error, &ap, vop_balloc);
1031 	VFS_MPUNLOCK();
1032 
1033 	return(error);
1034 }
1035 
1036 /*
1037  * MPSAFE
1038  */
1039 int
1040 vop_reallocblks(struct vop_ops *ops, struct vnode *vp,
1041 	struct cluster_save *buflist)
1042 {
1043 	struct vop_reallocblks_args ap;
1044 	VFS_MPLOCK_DECLARE;
1045 	int error;
1046 
1047 	ap.a_head.a_desc = &vop_reallocblks_desc;
1048 	ap.a_head.a_ops = ops;
1049 	ap.a_vp = vp;
1050 	ap.a_buflist = buflist;
1051 
1052 	VFS_MPLOCK(vp->v_mount);
1053 	DO_OPS(ops, error, &ap, vop_reallocblks);
1054 	VFS_MPUNLOCK();
1055 
1056 	return(error);
1057 }
1058 
1059 /*
1060  * MPSAFE
1061  */
1062 int
1063 vop_getpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
1064 	int reqpage, vm_ooffset_t offset, int seqaccess)
1065 {
1066 	struct vop_getpages_args ap;
1067 	VFS_MPLOCK_DECLARE;
1068 	int error;
1069 
1070 	ap.a_head.a_desc = &vop_getpages_desc;
1071 	ap.a_head.a_ops = ops;
1072 	ap.a_vp = vp;
1073 	ap.a_m = m;
1074 	ap.a_count = count;
1075 	ap.a_reqpage = reqpage;
1076 	ap.a_offset = offset;
1077 	ap.a_seqaccess = seqaccess;
1078 
1079 	VFS_MPLOCK(vp->v_mount);
1080 	DO_OPS(ops, error, &ap, vop_getpages);
1081 	VFS_MPUNLOCK();
1082 
1083 	return(error);
1084 }
1085 
1086 /*
1087  * MPSAFE
1088  */
1089 int
1090 vop_putpages(struct vop_ops *ops, struct vnode *vp, vm_page_t *m, int count,
1091 	int sync, int *rtvals, vm_ooffset_t offset)
1092 {
1093 	struct vop_putpages_args ap;
1094 	VFS_MPLOCK_DECLARE;
1095 	int error;
1096 
1097 	ap.a_head.a_desc = &vop_putpages_desc;
1098 	ap.a_head.a_ops = ops;
1099 	ap.a_vp = vp;
1100 	ap.a_m = m;
1101 	ap.a_count = count;
1102 	ap.a_sync = sync;
1103 	ap.a_rtvals = rtvals;
1104 	ap.a_offset = offset;
1105 
1106 	VFS_MPLOCK(vp->v_mount);
1107 	DO_OPS(ops, error, &ap, vop_putpages);
1108 	VFS_MPUNLOCK();
1109 
1110 	return(error);
1111 }
1112 
1113 /*
1114  * MPSAFE
1115  */
1116 int
1117 vop_freeblks(struct vop_ops *ops, struct vnode *vp, off_t offset, int length)
1118 {
1119 	struct vop_freeblks_args ap;
1120 	VFS_MPLOCK_DECLARE;
1121 	int error;
1122 
1123 	ap.a_head.a_desc = &vop_freeblks_desc;
1124 	ap.a_head.a_ops = ops;
1125 	ap.a_vp = vp;
1126 	ap.a_offset = offset;
1127 	ap.a_length = length;
1128 
1129 	VFS_MPLOCK(vp->v_mount);
1130 	DO_OPS(ops, error, &ap, vop_freeblks);
1131 	VFS_MPUNLOCK();
1132 
1133 	return(error);
1134 }
1135 
1136 /*
1137  * MPSAFE
1138  */
1139 int
1140 vop_getacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1141 	struct acl *aclp, struct ucred *cred)
1142 {
1143 	struct vop_getacl_args ap;
1144 	VFS_MPLOCK_DECLARE;
1145 	int error;
1146 
1147 	ap.a_head.a_desc = &vop_getacl_desc;
1148 	ap.a_head.a_ops = ops;
1149 	ap.a_vp = vp;
1150 	ap.a_type = type;
1151 	ap.a_aclp = aclp;
1152 	ap.a_cred = cred;
1153 
1154 	VFS_MPLOCK(vp->v_mount);
1155 	DO_OPS(ops, error, &ap, vop_getacl);
1156 	VFS_MPUNLOCK();
1157 
1158 	return(error);
1159 }
1160 
1161 /*
1162  * MPSAFE
1163  */
1164 int
1165 vop_setacl(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1166 	struct acl *aclp, struct ucred *cred)
1167 {
1168 	struct vop_setacl_args ap;
1169 	VFS_MPLOCK_DECLARE;
1170 	int error;
1171 
1172 	ap.a_head.a_desc = &vop_setacl_desc;
1173 	ap.a_head.a_ops = ops;
1174 	ap.a_vp = vp;
1175 	ap.a_type = type;
1176 	ap.a_aclp = aclp;
1177 	ap.a_cred = cred;
1178 
1179 	VFS_MPLOCK(vp->v_mount);
1180 	DO_OPS(ops, error, &ap, vop_setacl);
1181 	VFS_MPUNLOCK();
1182 
1183 	return(error);
1184 }
1185 
1186 /*
1187  * MPSAFE
1188  */
1189 int
1190 vop_aclcheck(struct vop_ops *ops, struct vnode *vp, acl_type_t type,
1191 	struct acl *aclp, struct ucred *cred)
1192 {
1193 	struct vop_aclcheck_args ap;
1194 	VFS_MPLOCK_DECLARE;
1195 	int error;
1196 
1197 	ap.a_head.a_desc = &vop_aclcheck_desc;
1198 	ap.a_head.a_ops = ops;
1199 	ap.a_vp = vp;
1200 	ap.a_type = type;
1201 	ap.a_aclp = aclp;
1202 	ap.a_cred = cred;
1203 
1204 	VFS_MPLOCK(vp->v_mount);
1205 	DO_OPS(ops, error, &ap, vop_aclcheck);
1206 	VFS_MPUNLOCK();
1207 
1208 	return(error);
1209 }
1210 
1211 /*
1212  * MPSAFE
1213  */
1214 int
1215 vop_getextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1216 	       char *attrname, struct uio *uio, struct ucred *cred)
1217 {
1218 	struct vop_getextattr_args ap;
1219 	VFS_MPLOCK_DECLARE;
1220 	int error;
1221 
1222 	ap.a_head.a_desc = &vop_getextattr_desc;
1223 	ap.a_head.a_ops = ops;
1224 	ap.a_vp = vp;
1225 	ap.a_attrnamespace = attrnamespace;
1226 	ap.a_attrname = attrname;
1227 	ap.a_uio = uio;
1228 	ap.a_cred = cred;
1229 
1230 	VFS_MPLOCK(vp->v_mount);
1231 	DO_OPS(ops, error, &ap, vop_getextattr);
1232 	VFS_MPUNLOCK();
1233 
1234 	return(error);
1235 }
1236 
1237 /*
1238  * MPSAFE
1239  */
1240 int
1241 vop_setextattr(struct vop_ops *ops, struct vnode *vp, int attrnamespace,
1242 	       char *attrname, struct uio *uio, struct ucred *cred)
1243 {
1244 	struct vop_setextattr_args ap;
1245 	VFS_MPLOCK_DECLARE;
1246 	int error;
1247 
1248 	ap.a_head.a_desc = &vop_setextattr_desc;
1249 	ap.a_head.a_ops = ops;
1250 	ap.a_vp = vp;
1251 	ap.a_attrnamespace = attrnamespace;
1252 	ap.a_attrname = attrname;
1253 	ap.a_uio = uio;
1254 	ap.a_cred = cred;
1255 
1256 	VFS_MPLOCK(vp->v_mount);
1257 	DO_OPS(ops, error, &ap, vop_setextattr);
1258 	VFS_MPUNLOCK();
1259 
1260 	return(error);
1261 }
1262 
1263 /*
1264  * MPSAFE
1265  */
1266 int
1267 vop_mountctl(struct vop_ops *ops, struct vnode *vp, int op, struct file *fp,
1268 	     const void *ctl, int ctllen, void *buf, int buflen, int *res)
1269 {
1270 	struct vop_mountctl_args ap;
1271 	VFS_MPLOCK_DECLARE;
1272 	int error;
1273 
1274 	ap.a_head.a_desc = &vop_mountctl_desc;
1275 	ap.a_head.a_ops = ops;
1276 	ap.a_op = op;
1277 	ap.a_ctl = ctl;
1278 	ap.a_fp = fp;
1279 	ap.a_ctllen = ctllen;
1280 	ap.a_buf = buf;
1281 	ap.a_buflen = buflen;
1282 	ap.a_res = res;
1283 
1284 	VFS_MPLOCK(vp->v_mount);
1285 	DO_OPS(ops, error, &ap, vop_mountctl);
1286 	VFS_MPUNLOCK();
1287 
1288 	return(error);
1289 }
1290 
1291 /*
1292  * MPSAFE
1293  */
1294 int
1295 vop_markatime(struct vop_ops *ops, struct vnode *vp, struct ucred *cred)
1296 {
1297 	struct vop_markatime_args ap;
1298 	VFS_MPLOCK_DECLARE;
1299 	int error;
1300 
1301 	ap.a_head.a_desc = &vop_markatime_desc;
1302 	ap.a_head.a_ops = ops;
1303 	ap.a_vp = vp;
1304 	ap.a_cred = cred;
1305 
1306 	VFS_MPLOCK(vp->v_mount);
1307 	DO_OPS(ops, error, &ap, vop_markatime);
1308 	VFS_MPUNLOCK();
1309 
1310 	return(error);
1311 }
1312 
1313 /*
1314  * NEW API FUNCTIONS
1315  *
1316  * nresolve takes a locked ncp, a referenced but unlocked dvp, and a cred,
1317  * and resolves the ncp into a positive or negative hit.
1318  *
1319  * The namecache is automatically adjusted by this function.  The ncp
1320  * is left locked on return.
1321  *
1322  * MPSAFE
1323  */
1324 int
1325 vop_nresolve(struct vop_ops *ops, struct nchandle *nch,
1326 	     struct vnode *dvp, struct ucred *cred)
1327 {
1328 	struct vop_nresolve_args ap;
1329 	VFS_MPLOCK_DECLARE;
1330 	int error;
1331 
1332 	ap.a_head.a_desc = &vop_nresolve_desc;
1333 	ap.a_head.a_ops = ops;
1334 	ap.a_nch = nch;
1335 	ap.a_dvp = dvp;
1336 	ap.a_cred = cred;
1337 
1338 	VFS_MPLOCK(dvp->v_mount);
1339 	DO_OPS(ops, error, &ap, vop_nresolve);
1340 	VFS_MPUNLOCK();
1341 
1342 	return(error);
1343 }
1344 
1345 /*
1346  * nlookupdotdot takes an unlocked directory, referenced dvp, and looks
1347  * up "..", returning a locked parent directory in *vpp.  If an error
1348  * occurs *vpp will be NULL.
1349  *
1350  * MPSAFE
1351  */
1352 int
1353 vop_nlookupdotdot(struct vop_ops *ops, struct vnode *dvp,
1354 	struct vnode **vpp, struct ucred *cred, char **fakename)
1355 {
1356 	struct vop_nlookupdotdot_args ap;
1357 	VFS_MPLOCK_DECLARE;
1358 	int error;
1359 
1360 	ap.a_head.a_desc = &vop_nlookupdotdot_desc;
1361 	ap.a_head.a_ops = ops;
1362 	ap.a_dvp = dvp;
1363 	ap.a_vpp = vpp;
1364 	ap.a_cred = cred;
1365 	ap.a_fakename = fakename;
1366 
1367 	VFS_MPLOCK(dvp->v_mount);
1368 	DO_OPS(ops, error, &ap, vop_nlookupdotdot);
1369 	VFS_MPUNLOCK();
1370 
1371 	return(error);
1372 }
1373 
1374 /*
1375  * ncreate takes a locked, resolved ncp that typically represents a negative
1376  * cache hit and creates the file or node specified by the ncp, cred, and
1377  * vattr.  If no error occurs a locked vnode is returned in *vpp.
1378  *
1379  * The dvp passed in is referenced but unlocked.
1380  *
1381  * The namecache is automatically adjusted by this function.  The ncp
1382  * is left locked on return.
1383  *
1384  * MPSAFE
1385  */
1386 int
1387 vop_ncreate(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1388 	struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1389 {
1390 	struct vop_ncreate_args ap;
1391 	VFS_MPLOCK_DECLARE;
1392 	int error;
1393 
1394 	ap.a_head.a_desc = &vop_ncreate_desc;
1395 	ap.a_head.a_ops = ops;
1396 	ap.a_nch = nch;
1397 	ap.a_dvp = dvp;
1398 	ap.a_vpp = vpp;
1399 	ap.a_cred = cred;
1400 	ap.a_vap = vap;
1401 
1402 	VFS_MPLOCK(dvp->v_mount);
1403 	DO_OPS(ops, error, &ap, vop_ncreate);
1404 	VFS_MPUNLOCK();
1405 
1406 	return(error);
1407 }
1408 
1409 /*
1410  * nmkdir takes a locked, resolved ncp that typically represents a negative
1411  * cache hit and creates the directory specified by the ncp, cred, and
1412  * vattr.  If no error occurs a locked vnode is returned in *vpp.
1413  *
1414  * The dvp passed in is referenced but unlocked.
1415  *
1416  * The namecache is automatically adjusted by this function.  The ncp
1417  * is left locked on return.
1418  *
1419  * MPSAFE
1420  */
1421 int
1422 vop_nmkdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1423 	struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1424 {
1425 	struct vop_nmkdir_args ap;
1426 	VFS_MPLOCK_DECLARE;
1427 	int error;
1428 
1429 	ap.a_head.a_desc = &vop_nmkdir_desc;
1430 	ap.a_head.a_ops = ops;
1431 	ap.a_nch = nch;
1432 	ap.a_dvp = dvp;
1433 	ap.a_vpp = vpp;
1434 	ap.a_cred = cred;
1435 	ap.a_vap = vap;
1436 
1437 	VFS_MPLOCK(dvp->v_mount);
1438 	DO_OPS(ops, error, &ap, vop_nmkdir);
1439 	VFS_MPUNLOCK();
1440 
1441 	return(error);
1442 }
1443 
1444 /*
1445  * nmknod takes a locked, resolved ncp that typically represents a negative
1446  * cache hit and creates the node specified by the ncp, cred, and
1447  * vattr.  If no error occurs a locked vnode is returned in *vpp.
1448  *
1449  * The dvp passed in is referenced but unlocked.
1450  *
1451  * The namecache is automatically adjusted by this function.  The ncp
1452  * is left locked on return.
1453  *
1454  * MPSAFE
1455  */
1456 int
1457 vop_nmknod(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1458 	struct vnode **vpp, struct ucred *cred, struct vattr *vap)
1459 {
1460 	struct vop_nmknod_args ap;
1461 	VFS_MPLOCK_DECLARE;
1462 	int error;
1463 
1464 	ap.a_head.a_desc = &vop_nmknod_desc;
1465 	ap.a_head.a_ops = ops;
1466 	ap.a_nch = nch;
1467 	ap.a_dvp = dvp;
1468 	ap.a_vpp = vpp;
1469 	ap.a_cred = cred;
1470 	ap.a_vap = vap;
1471 
1472 	VFS_MPLOCK(dvp->v_mount);
1473 	DO_OPS(ops, error, &ap, vop_nmknod);
1474 	VFS_MPUNLOCK();
1475 
1476 	return(error);
1477 }
1478 
1479 /*
1480  * nlink takes a locked, resolved ncp that typically represents a negative
1481  * cache hit and creates the node specified by the ncp, cred, and
1482  * existing vnode.  The passed vp must be locked and will remain locked
1483  * on return, as does the ncp, whether an error occurs or not.
1484  *
1485  * The dvp passed in is referenced but unlocked.
1486  *
1487  * The namecache is automatically adjusted by this function.  The ncp
1488  * is left locked on return.
1489  *
1490  * MPSAFE
1491  */
1492 int
1493 vop_nlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1494 	  struct vnode *vp, struct ucred *cred)
1495 {
1496 	struct vop_nlink_args ap;
1497 	VFS_MPLOCK_DECLARE;
1498 	int error;
1499 
1500 	ap.a_head.a_desc = &vop_nlink_desc;
1501 	ap.a_head.a_ops = ops;
1502 	ap.a_nch = nch;
1503 	ap.a_dvp = dvp;
1504 	ap.a_vp = vp;
1505 	ap.a_cred = cred;
1506 
1507 	VFS_MPLOCK(dvp->v_mount);
1508 	DO_OPS(ops, error, &ap, vop_nlink);
1509 	VFS_MPUNLOCK();
1510 
1511 	return(error);
1512 }
1513 
1514 /*
1515  * nsymlink takes a locked, resolved ncp that typically represents a negative
1516  * cache hit and creates a symbolic link based on cred, vap, and target (the
1517  * contents of the link).  If no error occurs a locked vnode is returned in
1518  * *vpp.
1519  *
1520  * The dvp passed in is referenced but unlocked.
1521  *
1522  * The namecache is automatically adjusted by this function.  The ncp
1523  * is left locked on return.
1524  *
1525  * MPSAFE
1526  */
1527 int
1528 vop_nsymlink(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1529 	struct vnode **vpp, struct ucred *cred,
1530 	struct vattr *vap, char *target)
1531 {
1532 	struct vop_nsymlink_args ap;
1533 	VFS_MPLOCK_DECLARE;
1534 	int error;
1535 
1536 	ap.a_head.a_desc = &vop_nsymlink_desc;
1537 	ap.a_head.a_ops = ops;
1538 	ap.a_nch = nch;
1539 	ap.a_dvp = dvp;
1540 	ap.a_vpp = vpp;
1541 	ap.a_cred = cred;
1542 	ap.a_vap = vap;
1543 	ap.a_target = target;
1544 
1545 	VFS_MPLOCK(dvp->v_mount);
1546 	DO_OPS(ops, error, &ap, vop_nsymlink);
1547 	VFS_MPUNLOCK();
1548 
1549 	return(error);
1550 }
1551 
1552 /*
1553  * nwhiteout takes a locked, resolved ncp that can represent a positive or
1554  * negative hit and executes the whiteout function specified in flags.
1555  *
1556  * The dvp passed in is referenced but unlocked.
1557  *
1558  * The namecache is automatically adjusted by this function.  The ncp
1559  * is left locked on return.
1560  *
1561  * MPSAFE
1562  */
1563 int
1564 vop_nwhiteout(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1565 	struct ucred *cred, int flags)
1566 {
1567 	struct vop_nwhiteout_args ap;
1568 	VFS_MPLOCK_DECLARE;
1569 	int error;
1570 
1571 	ap.a_head.a_desc = &vop_nwhiteout_desc;
1572 	ap.a_head.a_ops = ops;
1573 	ap.a_nch = nch;
1574 	ap.a_dvp = dvp;
1575 	ap.a_cred = cred;
1576 	ap.a_flags = flags;
1577 
1578 	VFS_MPLOCK(dvp->v_mount);
1579 	DO_OPS(ops, error, &ap, vop_nwhiteout);
1580 	VFS_MPUNLOCK();
1581 
1582 	return(error);
1583 }
1584 
1585 /*
1586  * nremove takes a locked, resolved ncp that generally represents a
1587  * positive hit and removes the file.
1588  *
1589  * The dvp passed in is referenced but unlocked.
1590  *
1591  * The namecache is automatically adjusted by this function.  The ncp
1592  * is left locked on return.
1593  *
1594  * MPSAFE
1595  */
1596 int
1597 vop_nremove(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1598 	    struct ucred *cred)
1599 {
1600 	struct vop_nremove_args ap;
1601 	VFS_MPLOCK_DECLARE;
1602 	int error;
1603 	struct vattr va;
1604 
1605 	ap.a_head.a_desc = &vop_nremove_desc;
1606 	ap.a_head.a_ops = ops;
1607 	ap.a_nch = nch;
1608 	ap.a_dvp = dvp;
1609 	ap.a_cred = cred;
1610 
1611 	if ((error = VOP_GETATTR(nch->ncp->nc_vp, &va)) != 0)
1612 		return (error);
1613 
1614 	VFS_MPLOCK(dvp->v_mount);
1615 	DO_OPS(ops, error, &ap, vop_nremove);
1616 	/* Only update space counters if this is the last hard link */
1617 	if ((error == 0) && (va.va_nlink == 1)) {
1618 		VFS_ACCOUNT(nch->mount, va.va_uid, va.va_gid, -va.va_size);
1619 	}
1620 	VFS_MPUNLOCK();
1621 
1622 	return(error);
1623 }
1624 
1625 /*
1626  * nrmdir takes a locked, resolved ncp that generally represents a
1627  * directory and removes the directory.
1628  *
1629  * The dvp passed in is referenced but unlocked.
1630  *
1631  * The namecache is automatically adjusted by this function.  The ncp
1632  * is left locked on return.
1633  *
1634  * MPSAFE
1635  */
1636 int
1637 vop_nrmdir(struct vop_ops *ops, struct nchandle *nch, struct vnode *dvp,
1638 	   struct ucred *cred)
1639 {
1640 	struct vop_nrmdir_args ap;
1641 	VFS_MPLOCK_DECLARE;
1642 	int error;
1643 
1644 	ap.a_head.a_desc = &vop_nrmdir_desc;
1645 	ap.a_head.a_ops = ops;
1646 	ap.a_nch = nch;
1647 	ap.a_dvp = dvp;
1648 	ap.a_cred = cred;
1649 
1650 	VFS_MPLOCK(dvp->v_mount);
1651 	DO_OPS(ops, error, &ap, vop_nrmdir);
1652 	VFS_MPUNLOCK();
1653 
1654 	return(error);
1655 }
1656 
1657 /*
1658  * nrename takes TWO locked, resolved ncp's and the cred of the caller
1659  * and renames the source ncp to the target ncp.  The target ncp may
1660  * represent a positive or negative hit.
1661  *
1662  * The fdvp and tdvp passed in are referenced but unlocked.
1663  *
1664  * The namecache is automatically adjusted by this function.  The ncp
1665  * is left locked on return.  The source ncp is typically changed to
1666  * a negative cache hit and the target ncp typically takes on the
1667  * source ncp's underlying file.
1668  *
1669  * MPSAFE
1670  */
1671 int
1672 vop_nrename(struct vop_ops *ops,
1673 	    struct nchandle *fnch, struct nchandle *tnch,
1674 	    struct vnode *fdvp, struct vnode *tdvp,
1675 	    struct ucred *cred)
1676 {
1677 	struct vop_nrename_args ap;
1678 	VFS_MPLOCK_DECLARE;
1679 	int error;
1680 
1681 	ap.a_head.a_desc = &vop_nrename_desc;
1682 	ap.a_head.a_ops = ops;
1683 	ap.a_fnch = fnch;
1684 	ap.a_tnch = tnch;
1685 	ap.a_fdvp = fdvp;
1686 	ap.a_tdvp = tdvp;
1687 	ap.a_cred = cred;
1688 
1689 	VFS_MPLOCK(fdvp->v_mount);
1690 	DO_OPS(ops, error, &ap, vop_nrename);
1691 	VFS_MPUNLOCK();
1692 
1693 	return(error);
1694 }
1695 
1696 /************************************************************************
1697  *		PRIMARY VNODE OPERATIONS FORWARDING CALLS		*
1698  ************************************************************************
1699  *
1700  * These procedures are called from VFSs such as nullfs
1701  * when they wish to forward an operation on one VFS to another.  The
1702  * argument structure/message is modified and then directly passed to the
1703  * appropriate routine.  This routines may also be called by initiators
1704  * who have an argument structure in hand rather then discreet arguments.
1705  *
1706  * MPSAFE - Caller expected to already hold the appropriate vfs lock.
1707  */
1708 int
1709 vop_vnoperate_ap(struct vop_generic_args *ap)
1710 {
1711 	struct vop_ops *ops;
1712 	int error;
1713 
1714 	ops = ap->a_ops;
1715 	error = VOCALL(ops, ap);
1716 
1717 	return (error);
1718 }
1719 
1720 /*
1721  * This routine is called by the cache coherency layer to execute the actual
1722  * VFS operation.  If a journaling layer is present we call though it, else
1723  * we call the native VOP functions.
1724  */
1725 int
1726 vop_cache_operate_ap(struct vop_generic_args *ap)
1727 {
1728 	struct vop_ops *ops;
1729 	int error;
1730 
1731 	ops = ap->a_ops;
1732 	if (ops->head.vv_mount->mnt_vn_journal_ops)
1733 		error = VOCALL(ops->head.vv_mount->mnt_vn_journal_ops, ap);
1734 	else
1735 		error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1736 	return (error);
1737 }
1738 
1739 
1740 /*
1741  * This routine is called by the journaling layer to execute the actual
1742  * VFS operation.
1743  */
1744 int
1745 vop_journal_operate_ap(struct vop_generic_args *ap)
1746 {
1747 	struct vop_ops *ops;
1748 	int error;
1749 
1750 	ops = ap->a_ops;
1751 	error = VOCALL(ops->head.vv_mount->mnt_vn_norm_ops, ap);
1752 
1753 	return (error);
1754 }
1755 
1756 int
1757 vop_open_ap(struct vop_open_args *ap)
1758 {
1759 	int error;
1760 
1761 	DO_OPS(ap->a_head.a_ops, error, ap, vop_open);
1762 	return(error);
1763 }
1764 
1765 int
1766 vop_close_ap(struct vop_close_args *ap)
1767 {
1768 	int error;
1769 
1770 	DO_OPS(ap->a_head.a_ops, error, ap, vop_close);
1771 	return(error);
1772 }
1773 
1774 int
1775 vop_access_ap(struct vop_access_args *ap)
1776 {
1777 	int error;
1778 
1779 	DO_OPS(ap->a_head.a_ops, error, ap, vop_access);
1780 	return(error);
1781 }
1782 
1783 int
1784 vop_getattr_ap(struct vop_getattr_args *ap)
1785 {
1786 	int error;
1787 
1788 	DO_OPS(ap->a_head.a_ops, error, ap, vop_getattr);
1789 	return(error);
1790 }
1791 
1792 int
1793 vop_getattr_quick_ap(struct vop_getattr_args *ap)
1794 {
1795 	int error;
1796 
1797 	DO_OPS(ap->a_head.a_ops, error, ap, vop_getattr_quick);
1798 	return(error);
1799 }
1800 
1801 int
1802 vop_setattr_ap(struct vop_setattr_args *ap)
1803 {
1804 	int error;
1805 
1806 	DO_OPS(ap->a_head.a_ops, error, ap, vop_setattr);
1807 	return(error);
1808 }
1809 
1810 int
1811 vop_read_ap(struct vop_read_args *ap)
1812 {
1813 	int error;
1814 
1815 	DO_OPS(ap->a_head.a_ops, error, ap, vop_read);
1816 	return(error);
1817 }
1818 
1819 int
1820 vop_write_ap(struct vop_write_args *ap)
1821 {
1822 	int error;
1823 
1824 	DO_OPS(ap->a_head.a_ops, error, ap, vop_write);
1825 	return(error);
1826 }
1827 
1828 int
1829 vop_ioctl_ap(struct vop_ioctl_args *ap)
1830 {
1831 	int error;
1832 
1833 	DO_OPS(ap->a_head.a_ops, error, ap, vop_ioctl);
1834 	return(error);
1835 }
1836 
1837 int
1838 vop_poll_ap(struct vop_poll_args *ap)
1839 {
1840 	int error;
1841 
1842 	DO_OPS(ap->a_head.a_ops, error, ap, vop_poll);
1843 	return(error);
1844 }
1845 
1846 int
1847 vop_kqfilter_ap(struct vop_kqfilter_args *ap)
1848 {
1849 	int error;
1850 
1851 	DO_OPS(ap->a_head.a_ops, error, ap, vop_kqfilter);
1852 	return(error);
1853 }
1854 
1855 int
1856 vop_mmap_ap(struct vop_mmap_args *ap)
1857 {
1858 	int error;
1859 
1860 	DO_OPS(ap->a_head.a_ops, error, ap, vop_mmap);
1861 	return(error);
1862 }
1863 
1864 int
1865 vop_fsync_ap(struct vop_fsync_args *ap)
1866 {
1867 	int error;
1868 
1869 	DO_OPS(ap->a_head.a_ops, error, ap, vop_fsync);
1870 	return(error);
1871 }
1872 
1873 int
1874 vop_readdir_ap(struct vop_readdir_args *ap)
1875 {
1876 	int error;
1877 
1878 	DO_OPS(ap->a_head.a_ops, error, ap, vop_readdir);
1879 	return(error);
1880 }
1881 
1882 int
1883 vop_readlink_ap(struct vop_readlink_args *ap)
1884 {
1885 	int error;
1886 
1887 	DO_OPS(ap->a_head.a_ops, error, ap, vop_readlink);
1888 	return(error);
1889 }
1890 
1891 int
1892 vop_inactive_ap(struct vop_inactive_args *ap)
1893 {
1894 	int error;
1895 
1896 	DO_OPS(ap->a_head.a_ops, error, ap, vop_inactive);
1897 	return(error);
1898 }
1899 
1900 int
1901 vop_reclaim_ap(struct vop_reclaim_args *ap)
1902 {
1903 	int error;
1904 
1905 	DO_OPS(ap->a_head.a_ops, error, ap, vop_reclaim);
1906 	return(error);
1907 }
1908 
1909 int
1910 vop_bmap_ap(struct vop_bmap_args *ap)
1911 {
1912 	int error;
1913 
1914 	DO_OPS(ap->a_head.a_ops, error, ap, vop_bmap);
1915 	return(error);
1916 }
1917 
1918 int
1919 vop_strategy_ap(struct vop_strategy_args *ap)
1920 {
1921 	int error;
1922 
1923 	DO_OPS(ap->a_head.a_ops, error, ap, vop_strategy);
1924 	return(error);
1925 }
1926 
1927 int
1928 vop_print_ap(struct vop_print_args *ap)
1929 {
1930 	int error;
1931 
1932 	DO_OPS(ap->a_head.a_ops, error, ap, vop_print);
1933 	return(error);
1934 }
1935 
1936 int
1937 vop_pathconf_ap(struct vop_pathconf_args *ap)
1938 {
1939 	int error;
1940 
1941 	DO_OPS(ap->a_head.a_ops, error, ap, vop_pathconf);
1942 	return(error);
1943 }
1944 
1945 int
1946 vop_advlock_ap(struct vop_advlock_args *ap)
1947 {
1948 	int error;
1949 
1950 	DO_OPS(ap->a_head.a_ops, error, ap, vop_advlock);
1951 	return(error);
1952 }
1953 
1954 int
1955 vop_balloc_ap(struct vop_balloc_args *ap)
1956 {
1957 	int error;
1958 
1959 	DO_OPS(ap->a_head.a_ops, error, ap, vop_balloc);
1960 	return(error);
1961 }
1962 
1963 int
1964 vop_reallocblks_ap(struct vop_reallocblks_args *ap)
1965 {
1966 	int error;
1967 
1968 	DO_OPS(ap->a_head.a_ops, error, ap, vop_reallocblks);
1969 	return(error);
1970 }
1971 
1972 int
1973 vop_getpages_ap(struct vop_getpages_args *ap)
1974 {
1975 	int error;
1976 
1977 	DO_OPS(ap->a_head.a_ops, error, ap, vop_getpages);
1978 	return(error);
1979 }
1980 
1981 int
1982 vop_putpages_ap(struct vop_putpages_args *ap)
1983 {
1984 	int error;
1985 
1986 	DO_OPS(ap->a_head.a_ops, error, ap, vop_putpages);
1987 	return(error);
1988 }
1989 
1990 int
1991 vop_freeblks_ap(struct vop_freeblks_args *ap)
1992 {
1993 	int error;
1994 
1995 	DO_OPS(ap->a_head.a_ops, error, ap, vop_freeblks);
1996 	return(error);
1997 }
1998 
1999 int
2000 vop_getacl_ap(struct vop_getacl_args *ap)
2001 {
2002 	int error;
2003 
2004 	DO_OPS(ap->a_head.a_ops, error, ap, vop_getacl);
2005 	return(error);
2006 }
2007 
2008 int
2009 vop_setacl_ap(struct vop_setacl_args *ap)
2010 {
2011 	int error;
2012 
2013 	DO_OPS(ap->a_head.a_ops, error, ap, vop_setacl);
2014 	return(error);
2015 }
2016 
2017 int
2018 vop_aclcheck_ap(struct vop_aclcheck_args *ap)
2019 {
2020 	int error;
2021 
2022 	DO_OPS(ap->a_head.a_ops, error, ap, vop_aclcheck);
2023 	return(error);
2024 }
2025 
2026 int
2027 vop_getextattr_ap(struct vop_getextattr_args *ap)
2028 {
2029 	int error;
2030 
2031 	DO_OPS(ap->a_head.a_ops, error, ap, vop_getextattr);
2032 	return(error);
2033 }
2034 
2035 int
2036 vop_setextattr_ap(struct vop_setextattr_args *ap)
2037 {
2038 	int error;
2039 
2040 	DO_OPS(ap->a_head.a_ops, error, ap, vop_setextattr);
2041 	return(error);
2042 }
2043 
2044 int
2045 vop_mountctl_ap(struct vop_mountctl_args *ap)
2046 {
2047 	int error;
2048 
2049 	DO_OPS(ap->a_head.a_ops, error, ap, vop_mountctl);
2050 	return(error);
2051 }
2052 
2053 int
2054 vop_markatime_ap(struct vop_markatime_args *ap)
2055 {
2056 	int error;
2057 
2058 	DO_OPS(ap->a_head.a_ops, error, ap, vop_markatime);
2059 	return(error);
2060 }
2061 
2062 int
2063 vop_nresolve_ap(struct vop_nresolve_args *ap)
2064 {
2065 	int error;
2066 
2067 	DO_OPS(ap->a_head.a_ops, error, ap, vop_nresolve);
2068 	return(error);
2069 }
2070 
2071 int
2072 vop_nlookupdotdot_ap(struct vop_nlookupdotdot_args *ap)
2073 {
2074 	int error;
2075 
2076 	DO_OPS(ap->a_head.a_ops, error, ap, vop_nlookupdotdot);
2077 	return(error);
2078 }
2079 
2080 int
2081 vop_ncreate_ap(struct vop_ncreate_args *ap)
2082 {
2083 	int error;
2084 
2085 	DO_OPS(ap->a_head.a_ops, error, ap, vop_ncreate);
2086 	return(error);
2087 }
2088 
2089 int
2090 vop_nmkdir_ap(struct vop_nmkdir_args *ap)
2091 {
2092 	int error;
2093 
2094 	DO_OPS(ap->a_head.a_ops, error, ap, vop_nmkdir);
2095 	return(error);
2096 }
2097 
2098 int
2099 vop_nmknod_ap(struct vop_nmknod_args *ap)
2100 {
2101 	int error;
2102 
2103 	DO_OPS(ap->a_head.a_ops, error, ap, vop_nmknod);
2104 	return(error);
2105 }
2106 
2107 int
2108 vop_nlink_ap(struct vop_nlink_args *ap)
2109 {
2110 	int error;
2111 
2112 	DO_OPS(ap->a_head.a_ops, error, ap, vop_nlink);
2113 	return(error);
2114 }
2115 
2116 int
2117 vop_nsymlink_ap(struct vop_nsymlink_args *ap)
2118 {
2119 	int error;
2120 
2121 	DO_OPS(ap->a_head.a_ops, error, ap, vop_nsymlink);
2122 	return(error);
2123 }
2124 
2125 int
2126 vop_nwhiteout_ap(struct vop_nwhiteout_args *ap)
2127 {
2128 	int error;
2129 
2130 	DO_OPS(ap->a_head.a_ops, error, ap, vop_nwhiteout);
2131 	return(error);
2132 }
2133 
2134 int
2135 vop_nremove_ap(struct vop_nremove_args *ap)
2136 {
2137 	int error;
2138 
2139 	DO_OPS(ap->a_head.a_ops, error, ap, vop_nremove);
2140 	return(error);
2141 }
2142 
2143 int
2144 vop_nrmdir_ap(struct vop_nrmdir_args *ap)
2145 {
2146 	int error;
2147 
2148 	DO_OPS(ap->a_head.a_ops, error, ap, vop_nrmdir);
2149 	return(error);
2150 }
2151 
2152 int
2153 vop_nrename_ap(struct vop_nrename_args *ap)
2154 {
2155 	int error;
2156 
2157 	DO_OPS(ap->a_head.a_ops, error, ap, vop_nrename);
2158 	return(error);
2159 }
2160 
2161