]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - sys/kern/vfs_default.c
sys: Remove $FreeBSD$: one-line .c pattern
[FreeBSD/FreeBSD.git] / sys / kern / vfs_default.c
1 /*-
2  * SPDX-License-Identifier: BSD-3-Clause
3  *
4  * Copyright (c) 1989, 1993
5  *      The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed
8  * to Berkeley by John Heidemann of the UCLA Ficus project.
9  *
10  * Source: * @(#)i405_init.c 2.10 92/04/27 UCLA Ficus project
11  *
12  * Redistribution and use in source and binary forms, with or without
13  * modification, are permitted provided that the following conditions
14  * are met:
15  * 1. Redistributions of source code must retain the above copyright
16  *    notice, this list of conditions and the following disclaimer.
17  * 2. Redistributions in binary form must reproduce the above copyright
18  *    notice, this list of conditions and the following disclaimer in the
19  *    documentation and/or other materials provided with the distribution.
20  * 3. Neither the name of the University nor the names of its contributors
21  *    may be used to endorse or promote products derived from this software
22  *    without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34  * SUCH DAMAGE.
35  */
36
37 #include <sys/cdefs.h>
38 #include <sys/param.h>
39 #include <sys/systm.h>
40 #include <sys/bio.h>
41 #include <sys/buf.h>
42 #include <sys/conf.h>
43 #include <sys/event.h>
44 #include <sys/filio.h>
45 #include <sys/kernel.h>
46 #include <sys/limits.h>
47 #include <sys/lock.h>
48 #include <sys/lockf.h>
49 #include <sys/malloc.h>
50 #include <sys/mount.h>
51 #include <sys/namei.h>
52 #include <sys/rwlock.h>
53 #include <sys/fcntl.h>
54 #include <sys/unistd.h>
55 #include <sys/vnode.h>
56 #include <sys/dirent.h>
57 #include <sys/poll.h>
58 #include <sys/stat.h>
59 #include <security/audit/audit.h>
60 #include <sys/priv.h>
61
62 #include <security/mac/mac_framework.h>
63
64 #include <vm/vm.h>
65 #include <vm/vm_object.h>
66 #include <vm/vm_extern.h>
67 #include <vm/pmap.h>
68 #include <vm/vm_map.h>
69 #include <vm/vm_page.h>
70 #include <vm/vm_pager.h>
71 #include <vm/vnode_pager.h>
72
73 static int      vop_nolookup(struct vop_lookup_args *);
74 static int      vop_norename(struct vop_rename_args *);
75 static int      vop_nostrategy(struct vop_strategy_args *);
76 static int      dirent_exists(struct vnode *vp, const char *dirname,
77                               struct thread *td);
78
79 static int vop_stdis_text(struct vop_is_text_args *ap);
80 static int vop_stdunset_text(struct vop_unset_text_args *ap);
81 static int vop_stdadd_writecount(struct vop_add_writecount_args *ap);
82 static int vop_stdcopy_file_range(struct vop_copy_file_range_args *ap);
83 static int vop_stdfdatasync(struct vop_fdatasync_args *ap);
84 static int vop_stdgetpages_async(struct vop_getpages_async_args *ap);
85 static int vop_stdread_pgcache(struct vop_read_pgcache_args *ap);
86 static int vop_stdstat(struct vop_stat_args *ap);
87 static int vop_stdvput_pair(struct vop_vput_pair_args *ap);
88
89 /*
90  * This vnode table stores what we want to do if the filesystem doesn't
91  * implement a particular VOP.
92  *
93  * If there is no specific entry here, we will return EOPNOTSUPP.
94  *
95  * Note that every filesystem has to implement either vop_access
96  * or vop_accessx; failing to do so will result in immediate crash
97  * due to stack overflow, as vop_stdaccess() calls vop_stdaccessx(),
98  * which calls vop_stdaccess() etc.
99  */
100
101 struct vop_vector default_vnodeops = {
102         .vop_default =          NULL,
103         .vop_bypass =           VOP_EOPNOTSUPP,
104
105         .vop_access =           vop_stdaccess,
106         .vop_accessx =          vop_stdaccessx,
107         .vop_advise =           vop_stdadvise,
108         .vop_advlock =          vop_stdadvlock,
109         .vop_advlockasync =     vop_stdadvlockasync,
110         .vop_advlockpurge =     vop_stdadvlockpurge,
111         .vop_allocate =         vop_stdallocate,
112         .vop_bmap =             vop_stdbmap,
113         .vop_close =            VOP_NULL,
114         .vop_fsync =            VOP_NULL,
115         .vop_stat =             vop_stdstat,
116         .vop_fdatasync =        vop_stdfdatasync,
117         .vop_getpages =         vop_stdgetpages,
118         .vop_getpages_async =   vop_stdgetpages_async,
119         .vop_getwritemount =    vop_stdgetwritemount,
120         .vop_inactive =         VOP_NULL,
121         .vop_need_inactive =    vop_stdneed_inactive,
122         .vop_ioctl =            vop_stdioctl,
123         .vop_kqfilter =         vop_stdkqfilter,
124         .vop_islocked =         vop_stdislocked,
125         .vop_lock1 =            vop_stdlock,
126         .vop_lookup =           vop_nolookup,
127         .vop_open =             VOP_NULL,
128         .vop_pathconf =         VOP_EINVAL,
129         .vop_poll =             vop_nopoll,
130         .vop_putpages =         vop_stdputpages,
131         .vop_readlink =         VOP_EINVAL,
132         .vop_read_pgcache =     vop_stdread_pgcache,
133         .vop_rename =           vop_norename,
134         .vop_revoke =           VOP_PANIC,
135         .vop_strategy =         vop_nostrategy,
136         .vop_unlock =           vop_stdunlock,
137         .vop_vptocnp =          vop_stdvptocnp,
138         .vop_vptofh =           vop_stdvptofh,
139         .vop_unp_bind =         vop_stdunp_bind,
140         .vop_unp_connect =      vop_stdunp_connect,
141         .vop_unp_detach =       vop_stdunp_detach,
142         .vop_is_text =          vop_stdis_text,
143         .vop_set_text =         vop_stdset_text,
144         .vop_unset_text =       vop_stdunset_text,
145         .vop_add_writecount =   vop_stdadd_writecount,
146         .vop_copy_file_range =  vop_stdcopy_file_range,
147         .vop_vput_pair =        vop_stdvput_pair,
148 };
149 VFS_VOP_VECTOR_REGISTER(default_vnodeops);
150
151 /*
152  * Series of placeholder functions for various error returns for
153  * VOPs.
154  */
155
156 int
157 vop_eopnotsupp(struct vop_generic_args *ap)
158 {
159         /*
160         printf("vop_notsupp[%s]\n", ap->a_desc->vdesc_name);
161         */
162
163         return (EOPNOTSUPP);
164 }
165
166 int
167 vop_ebadf(struct vop_generic_args *ap)
168 {
169
170         return (EBADF);
171 }
172
173 int
174 vop_enotty(struct vop_generic_args *ap)
175 {
176
177         return (ENOTTY);
178 }
179
180 int
181 vop_einval(struct vop_generic_args *ap)
182 {
183
184         return (EINVAL);
185 }
186
187 int
188 vop_enoent(struct vop_generic_args *ap)
189 {
190
191         return (ENOENT);
192 }
193
194 int
195 vop_eagain(struct vop_generic_args *ap)
196 {
197
198         return (EAGAIN);
199 }
200
201 int
202 vop_null(struct vop_generic_args *ap)
203 {
204
205         return (0);
206 }
207
208 /*
209  * Helper function to panic on some bad VOPs in some filesystems.
210  */
211 int
212 vop_panic(struct vop_generic_args *ap)
213 {
214
215         panic("filesystem goof: vop_panic[%s]", ap->a_desc->vdesc_name);
216 }
217
218 /*
219  * vop_std<something> and vop_no<something> are default functions for use by
220  * filesystems that need the "default reasonable" implementation for a
221  * particular operation.
222  *
223  * The documentation for the operations they implement exists (if it exists)
224  * in the VOP_<SOMETHING>(9) manpage (all uppercase).
225  */
226
227 /*
228  * Default vop for filesystems that do not support name lookup
229  */
230 static int
231 vop_nolookup(struct vop_lookup_args *ap)
232 {
233
234         *ap->a_vpp = NULL;
235         return (ENOTDIR);
236 }
237
238 /*
239  * vop_norename:
240  *
241  * Handle unlock and reference counting for arguments of vop_rename
242  * for filesystems that do not implement rename operation.
243  */
244 static int
245 vop_norename(struct vop_rename_args *ap)
246 {
247
248         vop_rename_fail(ap);
249         return (EOPNOTSUPP);
250 }
251
252 /*
253  *      vop_nostrategy:
254  *
255  *      Strategy routine for VFS devices that have none.
256  *
257  *      BIO_ERROR and B_INVAL must be cleared prior to calling any strategy
258  *      routine.  Typically this is done for a BIO_READ strategy call.
259  *      Typically B_INVAL is assumed to already be clear prior to a write
260  *      and should not be cleared manually unless you just made the buffer
261  *      invalid.  BIO_ERROR should be cleared either way.
262  */
263
264 static int
265 vop_nostrategy (struct vop_strategy_args *ap)
266 {
267         printf("No strategy for buffer at %p\n", ap->a_bp);
268         vn_printf(ap->a_vp, "vnode ");
269         ap->a_bp->b_ioflags |= BIO_ERROR;
270         ap->a_bp->b_error = EOPNOTSUPP;
271         bufdone(ap->a_bp);
272         return (EOPNOTSUPP);
273 }
274
275 /*
276  * Check if a named file exists in a given directory vnode
277  *
278  * Returns 0 if the file exists, ENOENT if it doesn't, or errors returned by
279  * vn_dir_next_dirent().
280  */
281 static int
282 dirent_exists(struct vnode *vp, const char *dirname, struct thread *td)
283 {
284         char *dirbuf;
285         int error, eofflag;
286         size_t dirbuflen, len;
287         off_t off;
288         struct dirent *dp;
289         struct vattr va;
290
291         ASSERT_VOP_LOCKED(vp, "vnode not locked");
292         KASSERT(vp->v_type == VDIR, ("vp %p is not a directory", vp));
293
294         error = VOP_GETATTR(vp, &va, td->td_ucred);
295         if (error != 0)
296                 return (error);
297
298         dirbuflen = MAX(DEV_BSIZE, GENERIC_MAXDIRSIZ);
299         if (dirbuflen < va.va_blocksize)
300                 dirbuflen = va.va_blocksize;
301         dirbuf = malloc(dirbuflen, M_TEMP, M_WAITOK);
302
303         len = 0;
304         off = 0;
305         eofflag = 0;
306
307         for (;;) {
308                 error = vn_dir_next_dirent(vp, td, dirbuf, dirbuflen,
309                     &dp, &len, &off, &eofflag);
310                 if (error != 0)
311                         goto out;
312
313                 if (len == 0)
314                         break;
315
316                 if (dp->d_type != DT_WHT && dp->d_fileno != 0 &&
317                     strcmp(dp->d_name, dirname) == 0)
318                         goto out;
319         }
320
321         error = ENOENT;
322
323 out:
324         free(dirbuf, M_TEMP);
325         return (error);
326 }
327
328 int
329 vop_stdaccess(struct vop_access_args *ap)
330 {
331
332         KASSERT((ap->a_accmode & ~(VEXEC | VWRITE | VREAD | VADMIN |
333             VAPPEND)) == 0, ("invalid bit in accmode"));
334
335         return (VOP_ACCESSX(ap->a_vp, ap->a_accmode, ap->a_cred, ap->a_td));
336 }
337
338 int
339 vop_stdaccessx(struct vop_accessx_args *ap)
340 {
341         int error;
342         accmode_t accmode = ap->a_accmode;
343
344         error = vfs_unixify_accmode(&accmode);
345         if (error != 0)
346                 return (error);
347
348         if (accmode == 0)
349                 return (0);
350
351         return (VOP_ACCESS(ap->a_vp, accmode, ap->a_cred, ap->a_td));
352 }
353
354 /*
355  * Advisory record locking support
356  */
357 int
358 vop_stdadvlock(struct vop_advlock_args *ap)
359 {
360         struct vnode *vp;
361         struct mount *mp;
362         struct vattr vattr;
363         int error;
364
365         vp = ap->a_vp;
366
367         /*
368          * Provide atomicity of open(O_CREAT | O_EXCL | O_EXLOCK) for
369          * local filesystems.  See vn_open_cred() for reciprocal part.
370          */
371         mp = vp->v_mount;
372         if (mp != NULL && (mp->mnt_flag & MNT_LOCAL) != 0 &&
373             ap->a_op == F_SETLK && (ap->a_flags & F_FIRSTOPEN) == 0) {
374                 VI_LOCK(vp);
375                 while ((vp->v_iflag & VI_FOPENING) != 0)
376                         msleep(vp, VI_MTX(vp), PLOCK, "lockfo", 0);
377                 VI_UNLOCK(vp);
378         }
379
380         if (ap->a_fl->l_whence == SEEK_END) {
381                 /*
382                  * The NFSv4 server must avoid doing a vn_lock() here, since it
383                  * can deadlock the nfsd threads, due to a LOR.  Fortunately
384                  * the NFSv4 server always uses SEEK_SET and this code is
385                  * only required for the SEEK_END case.
386                  */
387                 vn_lock(vp, LK_SHARED | LK_RETRY);
388                 error = VOP_GETATTR(vp, &vattr, curthread->td_ucred);
389                 VOP_UNLOCK(vp);
390                 if (error)
391                         return (error);
392         } else
393                 vattr.va_size = 0;
394
395         return (lf_advlock(ap, &(vp->v_lockf), vattr.va_size));
396 }
397
398 int
399 vop_stdadvlockasync(struct vop_advlockasync_args *ap)
400 {
401         struct vnode *vp;
402         struct vattr vattr;
403         int error;
404
405         vp = ap->a_vp;
406         if (ap->a_fl->l_whence == SEEK_END) {
407                 /* The size argument is only needed for SEEK_END. */
408                 vn_lock(vp, LK_SHARED | LK_RETRY);
409                 error = VOP_GETATTR(vp, &vattr, curthread->td_ucred);
410                 VOP_UNLOCK(vp);
411                 if (error)
412                         return (error);
413         } else
414                 vattr.va_size = 0;
415
416         return (lf_advlockasync(ap, &(vp->v_lockf), vattr.va_size));
417 }
418
419 int
420 vop_stdadvlockpurge(struct vop_advlockpurge_args *ap)
421 {
422         struct vnode *vp;
423
424         vp = ap->a_vp;
425         lf_purgelocks(vp, &vp->v_lockf);
426         return (0);
427 }
428
429 /*
430  * vop_stdpathconf:
431  *
432  * Standard implementation of POSIX pathconf, to get information about limits
433  * for a filesystem.
434  * Override per filesystem for the case where the filesystem has smaller
435  * limits.
436  */
437 int
438 vop_stdpathconf(struct vop_pathconf_args *ap)
439 {
440
441         switch (ap->a_name) {
442                 case _PC_ASYNC_IO:
443                         *ap->a_retval = _POSIX_ASYNCHRONOUS_IO;
444                         return (0);
445                 case _PC_PATH_MAX:
446                         *ap->a_retval = PATH_MAX;
447                         return (0);
448                 case _PC_ACL_EXTENDED:
449                 case _PC_ACL_NFS4:
450                 case _PC_CAP_PRESENT:
451                 case _PC_INF_PRESENT:
452                 case _PC_MAC_PRESENT:
453                         *ap->a_retval = 0;
454                         return (0);
455                 default:
456                         return (EINVAL);
457         }
458         /* NOTREACHED */
459 }
460
461 /*
462  * Standard lock, unlock and islocked functions.
463  */
464 int
465 vop_stdlock(struct vop_lock1_args *ap)
466 {
467         struct vnode *vp = ap->a_vp;
468         struct mtx *ilk;
469
470         ilk = VI_MTX(vp);
471         return (lockmgr_lock_flags(vp->v_vnlock, ap->a_flags,
472             &ilk->lock_object, ap->a_file, ap->a_line));
473 }
474
475 /* See above. */
476 int
477 vop_stdunlock(struct vop_unlock_args *ap)
478 {
479         struct vnode *vp = ap->a_vp;
480
481         return (lockmgr_unlock(vp->v_vnlock));
482 }
483
484 /* See above. */
485 int
486 vop_stdislocked(struct vop_islocked_args *ap)
487 {
488
489         return (lockstatus(ap->a_vp->v_vnlock));
490 }
491
492 /*
493  * Variants of the above set.
494  *
495  * Differences are:
496  * - shared locking disablement is not supported
497  * - v_vnlock pointer is not honored
498  */
499 int
500 vop_lock(struct vop_lock1_args *ap)
501 {
502         struct vnode *vp = ap->a_vp;
503         int flags = ap->a_flags;
504         struct mtx *ilk;
505
506         MPASS(vp->v_vnlock == &vp->v_lock);
507
508         if (__predict_false((flags & ~(LK_TYPE_MASK | LK_NODDLKTREAT | LK_RETRY)) != 0))
509                 goto other;
510
511         switch (flags & LK_TYPE_MASK) {
512         case LK_SHARED:
513                 return (lockmgr_slock(&vp->v_lock, flags, ap->a_file, ap->a_line));
514         case LK_EXCLUSIVE:
515                 return (lockmgr_xlock(&vp->v_lock, flags, ap->a_file, ap->a_line));
516         }
517 other:
518         ilk = VI_MTX(vp);
519         return (lockmgr_lock_flags(&vp->v_lock, flags,
520             &ilk->lock_object, ap->a_file, ap->a_line));
521 }
522
523 int
524 vop_unlock(struct vop_unlock_args *ap)
525 {
526         struct vnode *vp = ap->a_vp;
527
528         MPASS(vp->v_vnlock == &vp->v_lock);
529
530         return (lockmgr_unlock(&vp->v_lock));
531 }
532
533 int
534 vop_islocked(struct vop_islocked_args *ap)
535 {
536         struct vnode *vp = ap->a_vp;
537
538         MPASS(vp->v_vnlock == &vp->v_lock);
539
540         return (lockstatus(&vp->v_lock));
541 }
542
543 /*
544  * Return true for select/poll.
545  */
546 int
547 vop_nopoll(struct vop_poll_args *ap)
548 {
549
550         if (ap->a_events & ~POLLSTANDARD)
551                 return (POLLNVAL);
552         return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
553 }
554
555 /*
556  * Implement poll for local filesystems that support it.
557  */
558 int
559 vop_stdpoll(struct vop_poll_args *ap)
560 {
561         if (ap->a_events & ~POLLSTANDARD)
562                 return (vn_pollrecord(ap->a_vp, ap->a_td, ap->a_events));
563         return (ap->a_events & (POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM));
564 }
565
566 /*
567  * Return our mount point, as we will take charge of the writes.
568  */
569 int
570 vop_stdgetwritemount(struct vop_getwritemount_args *ap)
571 {
572         struct mount *mp;
573         struct vnode *vp;
574
575         /*
576          * Note that having a reference does not prevent forced unmount from
577          * setting ->v_mount to NULL after the lock gets released. This is of
578          * no consequence for typical consumers (most notably vn_start_write)
579          * since in this case the vnode is VIRF_DOOMED. Unmount might have
580          * progressed far enough that its completion is only delayed by the
581          * reference obtained here. The consumer only needs to concern itself
582          * with releasing it.
583          */
584         vp = ap->a_vp;
585         mp = vfs_ref_from_vp(vp);
586         *(ap->a_mpp) = mp;
587         return (0);
588 }
589
590 /*
591  * If the file system doesn't implement VOP_BMAP, then return sensible defaults:
592  * - Return the vnode's bufobj instead of any underlying device's bufobj
593  * - Calculate the physical block number as if there were equal size
594  *   consecutive blocks, but
595  * - Report no contiguous runs of blocks.
596  */
597 int
598 vop_stdbmap(struct vop_bmap_args *ap)
599 {
600
601         if (ap->a_bop != NULL)
602                 *ap->a_bop = &ap->a_vp->v_bufobj;
603         if (ap->a_bnp != NULL)
604                 *ap->a_bnp = ap->a_bn * btodb(ap->a_vp->v_mount->mnt_stat.f_iosize);
605         if (ap->a_runp != NULL)
606                 *ap->a_runp = 0;
607         if (ap->a_runb != NULL)
608                 *ap->a_runb = 0;
609         return (0);
610 }
611
612 int
613 vop_stdfsync(struct vop_fsync_args *ap)
614 {
615
616         return (vn_fsync_buf(ap->a_vp, ap->a_waitfor));
617 }
618
619 static int
620 vop_stdfdatasync(struct vop_fdatasync_args *ap)
621 {
622
623         return (VOP_FSYNC(ap->a_vp, MNT_WAIT, ap->a_td));
624 }
625
626 int
627 vop_stdfdatasync_buf(struct vop_fdatasync_args *ap)
628 {
629
630         return (vn_fsync_buf(ap->a_vp, MNT_WAIT));
631 }
632
633 /* XXX Needs good comment and more info in the manpage (VOP_GETPAGES(9)). */
634 int
635 vop_stdgetpages(struct vop_getpages_args *ap)
636 {
637
638         return vnode_pager_generic_getpages(ap->a_vp, ap->a_m,
639             ap->a_count, ap->a_rbehind, ap->a_rahead, NULL, NULL);
640 }
641
642 static int
643 vop_stdgetpages_async(struct vop_getpages_async_args *ap)
644 {
645         int error;
646
647         error = VOP_GETPAGES(ap->a_vp, ap->a_m, ap->a_count, ap->a_rbehind,
648             ap->a_rahead);
649         if (ap->a_iodone != NULL)
650                 ap->a_iodone(ap->a_arg, ap->a_m, ap->a_count, error);
651         return (error);
652 }
653
654 int
655 vop_stdkqfilter(struct vop_kqfilter_args *ap)
656 {
657         return vfs_kqfilter(ap);
658 }
659
660 /* XXX Needs good comment and more info in the manpage (VOP_PUTPAGES(9)). */
661 int
662 vop_stdputpages(struct vop_putpages_args *ap)
663 {
664
665         return vnode_pager_generic_putpages(ap->a_vp, ap->a_m, ap->a_count,
666              ap->a_sync, ap->a_rtvals);
667 }
668
669 int
670 vop_stdvptofh(struct vop_vptofh_args *ap)
671 {
672         return (EOPNOTSUPP);
673 }
674
675 int
676 vop_stdvptocnp(struct vop_vptocnp_args *ap)
677 {
678         struct vnode *const vp = ap->a_vp;
679         struct vnode **const dvp = ap->a_vpp;
680         char *buf = ap->a_buf;
681         size_t *buflen = ap->a_buflen;
682         char *dirbuf;
683         int i = *buflen;
684         int error = 0, covered = 0;
685         int eofflag, flags, locked;
686         size_t dirbuflen, len;
687         off_t off;
688         ino_t fileno;
689         struct vattr va;
690         struct nameidata nd;
691         struct thread *const td = curthread;
692         struct ucred *const cred = td->td_ucred;
693         struct dirent *dp;
694         struct vnode *mvp;
695
696         if (vp->v_type != VDIR)
697                 return (ENOENT);
698
699         error = VOP_GETATTR(vp, &va, cred);
700         if (error)
701                 return (error);
702
703         VREF(vp);
704         locked = VOP_ISLOCKED(vp);
705         VOP_UNLOCK(vp);
706         NDINIT_ATVP(&nd, LOOKUP, FOLLOW | LOCKSHARED | LOCKLEAF, UIO_SYSSPACE,
707             "..", vp, td);
708         flags = FREAD;
709         error = vn_open_cred(&nd, &flags, 0, VN_OPEN_NOAUDIT, cred, NULL);
710         if (error) {
711                 vn_lock(vp, locked | LK_RETRY);
712                 return (error);
713         }
714         NDFREE(&nd, NDF_ONLY_PNBUF);
715
716         mvp = *dvp = nd.ni_vp;
717
718         if (vp->v_mount != (*dvp)->v_mount &&
719             ((*dvp)->v_vflag & VV_ROOT) &&
720             ((*dvp)->v_mount->mnt_flag & MNT_UNION)) {
721                 *dvp = (*dvp)->v_mount->mnt_vnodecovered;
722                 VREF(mvp);
723                 VOP_UNLOCK(mvp);
724                 vn_close(mvp, FREAD, cred, td);
725                 VREF(*dvp);
726                 vn_lock(*dvp, LK_SHARED | LK_RETRY);
727                 covered = 1;
728         }
729
730         fileno = va.va_fileid;
731
732         dirbuflen = MAX(DEV_BSIZE, GENERIC_MAXDIRSIZ);
733         if (dirbuflen < va.va_blocksize)
734                 dirbuflen = va.va_blocksize;
735         dirbuf = malloc(dirbuflen, M_TEMP, M_WAITOK);
736
737         if ((*dvp)->v_type != VDIR) {
738                 error = ENOENT;
739                 goto out;
740         }
741
742         len = 0;
743         off = 0;
744         eofflag = 0;
745
746         for (;;) {
747                 /* call VOP_READDIR of parent */
748                 error = vn_dir_next_dirent(*dvp, td,
749                     dirbuf, dirbuflen, &dp, &len, &off, &eofflag);
750                 if (error != 0)
751                         goto out;
752
753                 if (len == 0) {
754                         error = ENOENT;
755                         goto out;
756                 }
757
758                 if ((dp->d_type != DT_WHT) &&
759                     (dp->d_fileno == fileno)) {
760                         if (covered) {
761                                 VOP_UNLOCK(*dvp);
762                                 vn_lock(mvp, LK_SHARED | LK_RETRY);
763                                 if (dirent_exists(mvp, dp->d_name, td) == 0) {
764                                         error = ENOENT;
765                                         VOP_UNLOCK(mvp);
766                                         vn_lock(*dvp, LK_SHARED | LK_RETRY);
767                                         goto out;
768                                 }
769                                 VOP_UNLOCK(mvp);
770                                 vn_lock(*dvp, LK_SHARED | LK_RETRY);
771                         }
772                         i -= dp->d_namlen;
773
774                         if (i < 0) {
775                                 error = ENOMEM;
776                                 goto out;
777                         }
778                         if (dp->d_namlen == 1 && dp->d_name[0] == '.') {
779                                 error = ENOENT;
780                         } else {
781                                 bcopy(dp->d_name, buf + i, dp->d_namlen);
782                                 error = 0;
783                         }
784                         goto out;
785                 }
786         }
787
788 out:
789         free(dirbuf, M_TEMP);
790         if (!error) {
791                 *buflen = i;
792                 vref(*dvp);
793         }
794         if (covered) {
795                 vput(*dvp);
796                 vrele(mvp);
797         } else {
798                 VOP_UNLOCK(mvp);
799                 vn_close(mvp, FREAD, cred, td);
800         }
801         vn_lock(vp, locked | LK_RETRY);
802         return (error);
803 }
804
805 int
806 vop_stdallocate(struct vop_allocate_args *ap)
807 {
808 #ifdef __notyet__
809         struct statfs *sfs;
810         off_t maxfilesize = 0;
811 #endif
812         struct iovec aiov;
813         struct vattr vattr, *vap;
814         struct uio auio;
815         off_t fsize, len, cur, offset;
816         uint8_t *buf;
817         struct thread *td;
818         struct vnode *vp;
819         size_t iosize;
820         int error;
821
822         buf = NULL;
823         error = 0;
824         td = curthread;
825         vap = &vattr;
826         vp = ap->a_vp;
827         len = *ap->a_len;
828         offset = *ap->a_offset;
829
830         error = VOP_GETATTR(vp, vap, ap->a_cred);
831         if (error != 0)
832                 goto out;
833         fsize = vap->va_size;
834         iosize = vap->va_blocksize;
835         if (iosize == 0)
836                 iosize = BLKDEV_IOSIZE;
837         if (iosize > maxphys)
838                 iosize = maxphys;
839         buf = malloc(iosize, M_TEMP, M_WAITOK);
840
841 #ifdef __notyet__
842         /*
843          * Check if the filesystem sets f_maxfilesize; if not use
844          * VOP_SETATTR to perform the check.
845          */
846         sfs = malloc(sizeof(struct statfs), M_STATFS, M_WAITOK);
847         error = VFS_STATFS(vp->v_mount, sfs, td);
848         if (error == 0)
849                 maxfilesize = sfs->f_maxfilesize;
850         free(sfs, M_STATFS);
851         if (error != 0)
852                 goto out;
853         if (maxfilesize) {
854                 if (offset > maxfilesize || len > maxfilesize ||
855                     offset + len > maxfilesize) {
856                         error = EFBIG;
857                         goto out;
858                 }
859         } else
860 #endif
861         if (offset + len > vap->va_size) {
862                 /*
863                  * Test offset + len against the filesystem's maxfilesize.
864                  */
865                 VATTR_NULL(vap);
866                 vap->va_size = offset + len;
867                 error = VOP_SETATTR(vp, vap, ap->a_cred);
868                 if (error != 0)
869                         goto out;
870                 VATTR_NULL(vap);
871                 vap->va_size = fsize;
872                 error = VOP_SETATTR(vp, vap, ap->a_cred);
873                 if (error != 0)
874                         goto out;
875         }
876
877         for (;;) {
878                 /*
879                  * Read and write back anything below the nominal file
880                  * size.  There's currently no way outside the filesystem
881                  * to know whether this area is sparse or not.
882                  */
883                 cur = iosize;
884                 if ((offset % iosize) != 0)
885                         cur -= (offset % iosize);
886                 if (cur > len)
887                         cur = len;
888                 if (offset < fsize) {
889                         aiov.iov_base = buf;
890                         aiov.iov_len = cur;
891                         auio.uio_iov = &aiov;
892                         auio.uio_iovcnt = 1;
893                         auio.uio_offset = offset;
894                         auio.uio_resid = cur;
895                         auio.uio_segflg = UIO_SYSSPACE;
896                         auio.uio_rw = UIO_READ;
897                         auio.uio_td = td;
898                         error = VOP_READ(vp, &auio, ap->a_ioflag, ap->a_cred);
899                         if (error != 0)
900                                 break;
901                         if (auio.uio_resid > 0) {
902                                 bzero(buf + cur - auio.uio_resid,
903                                     auio.uio_resid);
904                         }
905                 } else {
906                         bzero(buf, cur);
907                 }
908
909                 aiov.iov_base = buf;
910                 aiov.iov_len = cur;
911                 auio.uio_iov = &aiov;
912                 auio.uio_iovcnt = 1;
913                 auio.uio_offset = offset;
914                 auio.uio_resid = cur;
915                 auio.uio_segflg = UIO_SYSSPACE;
916                 auio.uio_rw = UIO_WRITE;
917                 auio.uio_td = td;
918
919                 error = VOP_WRITE(vp, &auio, ap->a_ioflag, ap->a_cred);
920                 if (error != 0)
921                         break;
922
923                 len -= cur;
924                 offset += cur;
925                 if (len == 0)
926                         break;
927                 if (should_yield())
928                         break;
929         }
930
931  out:
932         *ap->a_len = len;
933         *ap->a_offset = offset;
934         free(buf, M_TEMP);
935         return (error);
936 }
937
938 int
939 vop_stdadvise(struct vop_advise_args *ap)
940 {
941         struct vnode *vp;
942         struct bufobj *bo;
943         daddr_t startn, endn;
944         off_t bstart, bend, start, end;
945         int bsize, error;
946
947         vp = ap->a_vp;
948         switch (ap->a_advice) {
949         case POSIX_FADV_WILLNEED:
950                 /*
951                  * Do nothing for now.  Filesystems should provide a
952                  * custom method which starts an asynchronous read of
953                  * the requested region.
954                  */
955                 error = 0;
956                 break;
957         case POSIX_FADV_DONTNEED:
958                 error = 0;
959                 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
960                 if (VN_IS_DOOMED(vp)) {
961                         VOP_UNLOCK(vp);
962                         break;
963                 }
964
965                 /*
966                  * Round to block boundaries (and later possibly further to
967                  * page boundaries).  Applications cannot reasonably be aware  
968                  * of the boundaries, and the rounding must be to expand at
969                  * both extremities to cover enough.  It still doesn't cover
970                  * read-ahead.  For partial blocks, this gives unnecessary
971                  * discarding of buffers but is efficient enough since the
972                  * pages usually remain in VMIO for some time.
973                  */
974                 bsize = vp->v_bufobj.bo_bsize;
975                 bstart = rounddown(ap->a_start, bsize);
976                 bend = roundup(ap->a_end, bsize);
977
978                 /*
979                  * Deactivate pages in the specified range from the backing VM
980                  * object.  Pages that are resident in the buffer cache will
981                  * remain wired until their corresponding buffers are released
982                  * below.
983                  */
984                 if (vp->v_object != NULL) {
985                         start = trunc_page(bstart);
986                         end = round_page(bend);
987                         VM_OBJECT_RLOCK(vp->v_object);
988                         vm_object_page_noreuse(vp->v_object, OFF_TO_IDX(start),
989                             OFF_TO_IDX(end));
990                         VM_OBJECT_RUNLOCK(vp->v_object);
991                 }
992
993                 bo = &vp->v_bufobj;
994                 BO_RLOCK(bo);
995                 startn = bstart / bsize;
996                 endn = bend / bsize;
997                 error = bnoreuselist(&bo->bo_clean, bo, startn, endn);
998                 if (error == 0)
999                         error = bnoreuselist(&bo->bo_dirty, bo, startn, endn);
1000                 BO_RUNLOCK(bo);
1001                 VOP_UNLOCK(vp);
1002                 break;
1003         default:
1004                 error = EINVAL;
1005                 break;
1006         }
1007         return (error);
1008 }
1009
1010 int
1011 vop_stdunp_bind(struct vop_unp_bind_args *ap)
1012 {
1013
1014         ap->a_vp->v_unpcb = ap->a_unpcb;
1015         return (0);
1016 }
1017
1018 int
1019 vop_stdunp_connect(struct vop_unp_connect_args *ap)
1020 {
1021
1022         *ap->a_unpcb = ap->a_vp->v_unpcb;
1023         return (0);
1024 }
1025
1026 int
1027 vop_stdunp_detach(struct vop_unp_detach_args *ap)
1028 {
1029
1030         ap->a_vp->v_unpcb = NULL;
1031         return (0);
1032 }
1033
1034 static int
1035 vop_stdis_text(struct vop_is_text_args *ap)
1036 {
1037
1038         return (ap->a_vp->v_writecount < 0);
1039 }
1040
1041 int
1042 vop_stdset_text(struct vop_set_text_args *ap)
1043 {
1044         struct vnode *vp;
1045         struct mount *mp;
1046         int error, n;
1047
1048         vp = ap->a_vp;
1049
1050         /*
1051          * Avoid the interlock if execs are already present.
1052          */
1053         n = atomic_load_int(&vp->v_writecount);
1054         for (;;) {
1055                 if (n > -1) {
1056                         break;
1057                 }
1058                 if (atomic_fcmpset_int(&vp->v_writecount, &n, n - 1)) {
1059                         return (0);
1060                 }
1061         }
1062
1063         VI_LOCK(vp);
1064         if (vp->v_writecount > 0) {
1065                 error = ETXTBSY;
1066         } else {
1067                 /*
1068                  * If requested by fs, keep a use reference to the
1069                  * vnode until the last text reference is released.
1070                  */
1071                 mp = vp->v_mount;
1072                 if (mp != NULL && (mp->mnt_kern_flag & MNTK_TEXT_REFS) != 0 &&
1073                     vp->v_writecount == 0) {
1074                         VNPASS((vp->v_iflag & VI_TEXT_REF) == 0, vp);
1075                         vp->v_iflag |= VI_TEXT_REF;
1076                         vrefl(vp);
1077                 }
1078
1079                 atomic_subtract_int(&vp->v_writecount, 1);
1080                 error = 0;
1081         }
1082         VI_UNLOCK(vp);
1083         return (error);
1084 }
1085
1086 static int
1087 vop_stdunset_text(struct vop_unset_text_args *ap)
1088 {
1089         struct vnode *vp;
1090         int error, n;
1091         bool last;
1092
1093         vp = ap->a_vp;
1094
1095         /*
1096          * Avoid the interlock if this is not the last exec.
1097          */
1098         n = atomic_load_int(&vp->v_writecount);
1099         for (;;) {
1100                 if (n >= -1) {
1101                         break;
1102                 }
1103                 if (atomic_fcmpset_int(&vp->v_writecount, &n, n + 1)) {
1104                         return (0);
1105                 }
1106         }
1107
1108         last = false;
1109         VI_LOCK(vp);
1110         if (vp->v_writecount < 0) {
1111                 if ((vp->v_iflag & VI_TEXT_REF) != 0 &&
1112                     vp->v_writecount == -1) {
1113                         last = true;
1114                         vp->v_iflag &= ~VI_TEXT_REF;
1115                 }
1116                 atomic_add_int(&vp->v_writecount, 1);
1117                 error = 0;
1118         } else {
1119                 error = EINVAL;
1120         }
1121         VI_UNLOCK(vp);
1122         if (last)
1123                 vunref(vp);
1124         return (error);
1125 }
1126
1127 static int
1128 vop_stdadd_writecount(struct vop_add_writecount_args *ap)
1129 {
1130         struct vnode *vp;
1131         struct mount *mp;
1132         int error;
1133
1134         vp = ap->a_vp;
1135         VI_LOCK_FLAGS(vp, MTX_DUPOK);
1136         if (vp->v_writecount < 0) {
1137                 error = ETXTBSY;
1138         } else {
1139                 VNASSERT(vp->v_writecount + ap->a_inc >= 0, vp,
1140                     ("neg writecount increment %d", ap->a_inc));
1141                 if (vp->v_writecount == 0) {
1142                         mp = vp->v_mount;
1143                         if (mp != NULL && (mp->mnt_kern_flag & MNTK_NOMSYNC) == 0)
1144                                 vlazy(vp);
1145                 }
1146                 vp->v_writecount += ap->a_inc;
1147                 error = 0;
1148         }
1149         VI_UNLOCK(vp);
1150         return (error);
1151 }
1152
1153 int
1154 vop_stdneed_inactive(struct vop_need_inactive_args *ap)
1155 {
1156
1157         return (1);
1158 }
1159
1160 int
1161 vop_stdioctl(struct vop_ioctl_args *ap)
1162 {
1163         struct vnode *vp;
1164         struct vattr va;
1165         off_t *offp;
1166         int error;
1167
1168         switch (ap->a_command) {
1169         case FIOSEEKDATA:
1170         case FIOSEEKHOLE:
1171                 vp = ap->a_vp;
1172                 error = vn_lock(vp, LK_SHARED);
1173                 if (error != 0)
1174                         return (EBADF);
1175                 if (vp->v_type == VREG)
1176                         error = VOP_GETATTR(vp, &va, ap->a_cred);
1177                 else
1178                         error = ENOTTY;
1179                 if (error == 0) {
1180                         offp = ap->a_data;
1181                         if (*offp < 0 || *offp >= va.va_size)
1182                                 error = ENXIO;
1183                         else if (ap->a_command == FIOSEEKHOLE)
1184                                 *offp = va.va_size;
1185                 }
1186                 VOP_UNLOCK(vp);
1187                 break;
1188         default:
1189                 error = ENOTTY;
1190                 break;
1191         }
1192         return (error);
1193 }
1194
1195 /*
1196  * vfs default ops
1197  * used to fill the vfs function table to get reasonable default return values.
1198  */
1199 int
1200 vfs_stdroot(struct mount *mp, int flags, struct vnode **vpp)
1201 {
1202
1203         return (EOPNOTSUPP);
1204 }
1205
1206 int
1207 vfs_stdstatfs(struct mount *mp, struct statfs *sbp)
1208 {
1209
1210         return (EOPNOTSUPP);
1211 }
1212
1213 int
1214 vfs_stdquotactl(struct mount *mp, int cmds, uid_t uid, void *arg)
1215 {
1216
1217         return (EOPNOTSUPP);
1218 }
1219
1220 int
1221 vfs_stdsync(struct mount *mp, int waitfor)
1222 {
1223         struct vnode *vp, *mvp;
1224         struct thread *td;
1225         int error, lockreq, allerror = 0;
1226
1227         td = curthread;
1228         lockreq = LK_EXCLUSIVE | LK_INTERLOCK;
1229         if (waitfor != MNT_WAIT)
1230                 lockreq |= LK_NOWAIT;
1231         /*
1232          * Force stale buffer cache information to be flushed.
1233          */
1234 loop:
1235         MNT_VNODE_FOREACH_ALL(vp, mp, mvp) {
1236                 if (vp->v_bufobj.bo_dirty.bv_cnt == 0) {
1237                         VI_UNLOCK(vp);
1238                         continue;
1239                 }
1240                 if ((error = vget(vp, lockreq)) != 0) {
1241                         if (error == ENOENT) {
1242                                 MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
1243                                 goto loop;
1244                         }
1245                         continue;
1246                 }
1247                 error = VOP_FSYNC(vp, waitfor, td);
1248                 if (error)
1249                         allerror = error;
1250                 vput(vp);
1251         }
1252         return (allerror);
1253 }
1254
1255 int
1256 vfs_stdnosync(struct mount *mp, int waitfor)
1257 {
1258
1259         return (0);
1260 }
1261
1262 static int
1263 vop_stdcopy_file_range(struct vop_copy_file_range_args *ap)
1264 {
1265         int error;
1266
1267         error = vn_generic_copy_file_range(ap->a_invp, ap->a_inoffp,
1268             ap->a_outvp, ap->a_outoffp, ap->a_lenp, ap->a_flags, ap->a_incred,
1269             ap->a_outcred, ap->a_fsizetd);
1270         return (error);
1271 }
1272
1273 int
1274 vfs_stdvget(struct mount *mp, ino_t ino, int flags, struct vnode **vpp)
1275 {
1276
1277         return (EOPNOTSUPP);
1278 }
1279
1280 int
1281 vfs_stdfhtovp(struct mount *mp, struct fid *fhp, int flags, struct vnode **vpp)
1282 {
1283
1284         return (EOPNOTSUPP);
1285 }
1286
1287 int
1288 vfs_stdinit(struct vfsconf *vfsp)
1289 {
1290
1291         return (0);
1292 }
1293
1294 int
1295 vfs_stduninit(struct vfsconf *vfsp)
1296 {
1297
1298         return(0);
1299 }
1300
1301 int
1302 vfs_stdextattrctl(struct mount *mp, int cmd, struct vnode *filename_vp,
1303     int attrnamespace, const char *attrname)
1304 {
1305
1306         if (filename_vp != NULL)
1307                 VOP_UNLOCK(filename_vp);
1308         return (EOPNOTSUPP);
1309 }
1310
1311 int
1312 vfs_stdsysctl(struct mount *mp, fsctlop_t op, struct sysctl_req *req)
1313 {
1314
1315         return (EOPNOTSUPP);
1316 }
1317
1318 static vop_bypass_t *
1319 bp_by_off(struct vop_vector *vop, struct vop_generic_args *a)
1320 {
1321
1322         return (*(vop_bypass_t **)((char *)vop + a->a_desc->vdesc_vop_offset));
1323 }
1324
1325 int
1326 vop_sigdefer(struct vop_vector *vop, struct vop_generic_args *a)
1327 {
1328         vop_bypass_t *bp;
1329         int prev_stops, rc;
1330
1331         bp = bp_by_off(vop, a);
1332         MPASS(bp != NULL);
1333
1334         prev_stops = sigdeferstop(SIGDEFERSTOP_SILENT);
1335         rc = bp(a);
1336         sigallowstop(prev_stops);
1337         return (rc);
1338 }
1339
1340 static int
1341 vop_stdstat(struct vop_stat_args *a)
1342 {
1343         struct vattr vattr;
1344         struct vattr *vap;
1345         struct vnode *vp;
1346         struct stat *sb;
1347         int error;
1348         u_short mode;
1349
1350         vp = a->a_vp;
1351         sb = a->a_sb;
1352
1353         error = vop_stat_helper_pre(a);
1354         if (error != 0)
1355                 return (error);
1356
1357         vap = &vattr;
1358
1359         /*
1360          * Initialize defaults for new and unusual fields, so that file
1361          * systems which don't support these fields don't need to know
1362          * about them.
1363          */
1364         vap->va_birthtime.tv_sec = -1;
1365         vap->va_birthtime.tv_nsec = 0;
1366         vap->va_fsid = VNOVAL;
1367         vap->va_rdev = NODEV;
1368
1369         error = VOP_GETATTR(vp, vap, a->a_active_cred);
1370         if (error)
1371                 goto out;
1372
1373         /*
1374          * Zero the spare stat fields
1375          */
1376         bzero(sb, sizeof *sb);
1377
1378         /*
1379          * Copy from vattr table
1380          */
1381         if (vap->va_fsid != VNOVAL)
1382                 sb->st_dev = vap->va_fsid;
1383         else
1384                 sb->st_dev = vp->v_mount->mnt_stat.f_fsid.val[0];
1385         sb->st_ino = vap->va_fileid;
1386         mode = vap->va_mode;
1387         switch (vap->va_type) {
1388         case VREG:
1389                 mode |= S_IFREG;
1390                 break;
1391         case VDIR:
1392                 mode |= S_IFDIR;
1393                 break;
1394         case VBLK:
1395                 mode |= S_IFBLK;
1396                 break;
1397         case VCHR:
1398                 mode |= S_IFCHR;
1399                 break;
1400         case VLNK:
1401                 mode |= S_IFLNK;
1402                 break;
1403         case VSOCK:
1404                 mode |= S_IFSOCK;
1405                 break;
1406         case VFIFO:
1407                 mode |= S_IFIFO;
1408                 break;
1409         default:
1410                 error = EBADF;
1411                 goto out;
1412         }
1413         sb->st_mode = mode;
1414         sb->st_nlink = vap->va_nlink;
1415         sb->st_uid = vap->va_uid;
1416         sb->st_gid = vap->va_gid;
1417         sb->st_rdev = vap->va_rdev;
1418         if (vap->va_size > OFF_MAX) {
1419                 error = EOVERFLOW;
1420                 goto out;
1421         }
1422         sb->st_size = vap->va_size;
1423         sb->st_atim.tv_sec = vap->va_atime.tv_sec;
1424         sb->st_atim.tv_nsec = vap->va_atime.tv_nsec;
1425         sb->st_mtim.tv_sec = vap->va_mtime.tv_sec;
1426         sb->st_mtim.tv_nsec = vap->va_mtime.tv_nsec;
1427         sb->st_ctim.tv_sec = vap->va_ctime.tv_sec;
1428         sb->st_ctim.tv_nsec = vap->va_ctime.tv_nsec;
1429         sb->st_birthtim.tv_sec = vap->va_birthtime.tv_sec;
1430         sb->st_birthtim.tv_nsec = vap->va_birthtime.tv_nsec;
1431
1432         /*
1433          * According to www.opengroup.org, the meaning of st_blksize is
1434          *   "a filesystem-specific preferred I/O block size for this
1435          *    object.  In some filesystem types, this may vary from file
1436          *    to file"
1437          * Use minimum/default of PAGE_SIZE (e.g. for VCHR).
1438          */
1439
1440         sb->st_blksize = max(PAGE_SIZE, vap->va_blocksize);
1441         sb->st_flags = vap->va_flags;
1442         sb->st_blocks = vap->va_bytes / S_BLKSIZE;
1443         sb->st_gen = vap->va_gen;
1444 out:
1445         return (vop_stat_helper_post(a, error));
1446 }
1447
1448 static int
1449 vop_stdread_pgcache(struct vop_read_pgcache_args *ap __unused)
1450 {
1451         return (EJUSTRETURN);
1452 }
1453
1454 static int
1455 vop_stdvput_pair(struct vop_vput_pair_args *ap)
1456 {
1457         struct vnode *dvp, *vp, **vpp;
1458
1459         dvp = ap->a_dvp;
1460         vpp = ap->a_vpp;
1461         vput(dvp);
1462         if (vpp != NULL && ap->a_unlock_vp && (vp = *vpp) != NULL)
1463                 vput(vp);
1464         return (0);
1465 }