2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95
39 * $FreeBSD: src/sys/kern/vfs_subr.c,v 1.249.2.30 2003/04/04 20:35:57 tegge Exp $
40 * $DragonFly: src/sys/kern/vfs_subr.c,v 1.44 2004/10/22 18:03:50 dillon Exp $
44 * External virtual filesystem routines
48 #include <sys/param.h>
49 #include <sys/systm.h>
52 #include <sys/dirent.h>
53 #include <sys/domain.h>
54 #include <sys/eventhandler.h>
55 #include <sys/fcntl.h>
56 #include <sys/kernel.h>
57 #include <sys/kthread.h>
58 #include <sys/malloc.h>
60 #include <sys/mount.h>
62 #include <sys/namei.h>
63 #include <sys/reboot.h>
64 #include <sys/socket.h>
66 #include <sys/sysctl.h>
67 #include <sys/syslog.h>
68 #include <sys/vmmeter.h>
69 #include <sys/vnode.h>
71 #include <machine/limits.h>
74 #include <vm/vm_object.h>
75 #include <vm/vm_extern.h>
76 #include <vm/vm_kern.h>
78 #include <vm/vm_map.h>
79 #include <vm/vm_page.h>
80 #include <vm/vm_pager.h>
81 #include <vm/vnode_pager.h>
82 #include <vm/vm_zone.h>
85 #include <sys/thread2.h>
87 static MALLOC_DEFINE(M_NETADDR, "Export Host", "Export host address structure");
90 SYSCTL_INT(_debug, OID_AUTO, numvnodes, CTLFLAG_RD, &numvnodes, 0, "");
92 enum vtype iftovt_tab[16] = {
93 VNON, VFIFO, VCHR, VNON, VDIR, VNON, VBLK, VNON,
94 VREG, VNON, VLNK, VNON, VSOCK, VNON, VNON, VBAD,
97 0, S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK,
98 S_IFSOCK, S_IFIFO, S_IFMT,
101 static int reassignbufcalls;
102 SYSCTL_INT(_vfs, OID_AUTO, reassignbufcalls, CTLFLAG_RW,
103 &reassignbufcalls, 0, "");
104 static int reassignbufloops;
105 SYSCTL_INT(_vfs, OID_AUTO, reassignbufloops, CTLFLAG_RW,
106 &reassignbufloops, 0, "");
107 static int reassignbufsortgood;
108 SYSCTL_INT(_vfs, OID_AUTO, reassignbufsortgood, CTLFLAG_RW,
109 &reassignbufsortgood, 0, "");
110 static int reassignbufsortbad;
111 SYSCTL_INT(_vfs, OID_AUTO, reassignbufsortbad, CTLFLAG_RW,
112 &reassignbufsortbad, 0, "");
113 static int reassignbufmethod = 1;
114 SYSCTL_INT(_vfs, OID_AUTO, reassignbufmethod, CTLFLAG_RW,
115 &reassignbufmethod, 0, "");
117 #ifdef ENABLE_VFS_IOOPT
119 SYSCTL_INT(_vfs, OID_AUTO, ioopt, CTLFLAG_RW, &vfs_ioopt, 0, "");
122 int nfs_mount_type = -1;
123 static struct lwkt_token spechash_token;
124 struct nfs_public nfs_pub; /* publicly exported FS */
127 SYSCTL_INT(_kern, KERN_MAXVNODES, maxvnodes, CTLFLAG_RW,
128 &desiredvnodes, 0, "Maximum number of vnodes");
130 static void vfs_free_addrlist (struct netexport *nep);
131 static int vfs_free_netcred (struct radix_node *rn, void *w);
132 static int vfs_hang_addrlist (struct mount *mp, struct netexport *nep,
133 struct export_args *argp);
135 extern int dev_ref_debug;
136 extern struct vnodeopv_entry_desc spec_vnodeop_entries[];
139 * Return 0 if the vnode is already on the free list or cannot be placed
140 * on the free list. Return 1 if the vnode can be placed on the free list.
143 vshouldfree(struct vnode *vp, int usecount)
145 if (vp->v_flag & VFREE)
146 return (0); /* already free */
147 if (vp->v_holdcnt != 0 || vp->v_usecount != usecount)
148 return (0); /* other holderse */
150 (vp->v_object->ref_count || vp->v_object->resident_page_count)) {
157 * Initialize the vnode management data structures.
159 * Called from vfsinit()
165 * Desired vnodes is a result of the physical page count
166 * and the size of kernel's heap. It scales in proportion
167 * to the amount of available physical memory. This can
168 * cause trouble on 64-bit and large memory platforms.
170 /* desiredvnodes = maxproc + vmstats.v_page_count / 4; */
172 min(maxproc + vmstats.v_page_count /4,
173 2 * (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) /
174 (5 * (sizeof(struct vm_object) + sizeof(struct vnode))));
176 lwkt_token_init(&spechash_token);
180 * Knob to control the precision of file timestamps:
182 * 0 = seconds only; nanoseconds zeroed.
183 * 1 = seconds and nanoseconds, accurate within 1/HZ.
184 * 2 = seconds and nanoseconds, truncated to microseconds.
185 * >=3 = seconds and nanoseconds, maximum precision.
187 enum { TSP_SEC, TSP_HZ, TSP_USEC, TSP_NSEC };
189 static int timestamp_precision = TSP_SEC;
190 SYSCTL_INT(_vfs, OID_AUTO, timestamp_precision, CTLFLAG_RW,
191 ×tamp_precision, 0, "");
194 * Get a current timestamp.
197 vfs_timestamp(struct timespec *tsp)
201 switch (timestamp_precision) {
203 tsp->tv_sec = time_second;
211 TIMEVAL_TO_TIMESPEC(&tv, tsp);
221 * Set vnode attributes to VNOVAL
224 vattr_null(struct vattr *vap)
227 vap->va_size = VNOVAL;
228 vap->va_bytes = VNOVAL;
229 vap->va_mode = VNOVAL;
230 vap->va_nlink = VNOVAL;
231 vap->va_uid = VNOVAL;
232 vap->va_gid = VNOVAL;
233 vap->va_fsid = VNOVAL;
234 vap->va_fileid = VNOVAL;
235 vap->va_blocksize = VNOVAL;
236 vap->va_rdev = VNOVAL;
237 vap->va_atime.tv_sec = VNOVAL;
238 vap->va_atime.tv_nsec = VNOVAL;
239 vap->va_mtime.tv_sec = VNOVAL;
240 vap->va_mtime.tv_nsec = VNOVAL;
241 vap->va_ctime.tv_sec = VNOVAL;
242 vap->va_ctime.tv_nsec = VNOVAL;
243 vap->va_flags = VNOVAL;
244 vap->va_gen = VNOVAL;
249 * Update outstanding I/O count and do wakeup if requested.
252 vwakeup(struct buf *bp)
256 bp->b_flags &= ~B_WRITEINPROG;
257 if ((vp = bp->b_vp)) {
259 if (vp->v_numoutput < 0)
260 panic("vwakeup: neg numoutput");
261 if ((vp->v_numoutput == 0) && (vp->v_flag & VBWAIT)) {
262 vp->v_flag &= ~VBWAIT;
263 wakeup((caddr_t) &vp->v_numoutput);
269 * Flush out and invalidate all buffers associated with a vnode.
274 vinvalbuf(struct vnode *vp, int flags, struct thread *td,
275 int slpflag, int slptimeo)
278 struct buf *nbp, *blist;
282 if (flags & V_SAVE) {
284 while (vp->v_numoutput) {
285 vp->v_flag |= VBWAIT;
286 error = tsleep((caddr_t)&vp->v_numoutput,
287 slpflag, "vinvlbuf", slptimeo);
293 if (!TAILQ_EMPTY(&vp->v_dirtyblkhd)) {
295 if ((error = VOP_FSYNC(vp, MNT_WAIT, td)) != 0)
298 if (vp->v_numoutput > 0 ||
299 !TAILQ_EMPTY(&vp->v_dirtyblkhd))
300 panic("vinvalbuf: dirty bufs");
306 blist = TAILQ_FIRST(&vp->v_cleanblkhd);
308 blist = TAILQ_FIRST(&vp->v_dirtyblkhd);
312 for (bp = blist; bp; bp = nbp) {
313 nbp = TAILQ_NEXT(bp, b_vnbufs);
314 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT)) {
315 error = BUF_TIMELOCK(bp,
316 LK_EXCLUSIVE | LK_SLEEPFAIL,
317 "vinvalbuf", slpflag, slptimeo);
324 * XXX Since there are no node locks for NFS, I
325 * believe there is a slight chance that a delayed
326 * write will occur while sleeping just above, so
327 * check for it. Note that vfs_bio_awrite expects
328 * buffers to reside on a queue, while VOP_BWRITE and
331 if (((bp->b_flags & (B_DELWRI | B_INVAL)) == B_DELWRI) &&
334 if (bp->b_vp == vp) {
335 if (bp->b_flags & B_CLUSTEROK) {
340 bp->b_flags |= B_ASYNC;
341 VOP_BWRITE(bp->b_vp, bp);
345 (void) VOP_BWRITE(bp->b_vp, bp);
350 bp->b_flags |= (B_INVAL | B_NOCACHE | B_RELBUF);
351 bp->b_flags &= ~B_ASYNC;
357 * Wait for I/O to complete. XXX needs cleaning up. The vnode can
358 * have write I/O in-progress but if there is a VM object then the
359 * VM object can also have read-I/O in-progress.
362 while (vp->v_numoutput > 0) {
363 vp->v_flag |= VBWAIT;
364 tsleep(&vp->v_numoutput, 0, "vnvlbv", 0);
366 if (VOP_GETVOBJECT(vp, &object) == 0) {
367 while (object->paging_in_progress)
368 vm_object_pip_sleep(object, "vnvlbx");
370 } while (vp->v_numoutput > 0);
375 * Destroy the copy in the VM cache, too.
377 if (VOP_GETVOBJECT(vp, &object) == 0) {
378 vm_object_page_remove(object, 0, 0,
379 (flags & V_SAVE) ? TRUE : FALSE);
382 if (!TAILQ_EMPTY(&vp->v_dirtyblkhd) || !TAILQ_EMPTY(&vp->v_cleanblkhd))
383 panic("vinvalbuf: flush failed");
388 * Truncate a file's buffer and pages to a specified length. This
389 * is in lieu of the old vinvalbuf mechanism, which performed unneeded
392 * The vnode must be locked.
395 vtruncbuf(struct vnode *vp, struct thread *td, off_t length, int blksize)
403 * Round up to the *next* lbn.
405 trunclbn = (length + blksize - 1) / blksize;
412 for (bp = TAILQ_FIRST(&vp->v_cleanblkhd); bp; bp = nbp) {
413 nbp = TAILQ_NEXT(bp, b_vnbufs);
414 if (bp->b_lblkno >= trunclbn) {
415 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT)) {
416 BUF_LOCK(bp, LK_EXCLUSIVE|LK_SLEEPFAIL);
420 bp->b_flags |= (B_INVAL | B_RELBUF);
421 bp->b_flags &= ~B_ASYNC;
426 (((nbp->b_xflags & BX_VNCLEAN) == 0) ||
428 (nbp->b_flags & B_DELWRI))) {
434 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
435 nbp = TAILQ_NEXT(bp, b_vnbufs);
436 if (bp->b_lblkno >= trunclbn) {
437 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT)) {
438 BUF_LOCK(bp, LK_EXCLUSIVE|LK_SLEEPFAIL);
442 bp->b_flags |= (B_INVAL | B_RELBUF);
443 bp->b_flags &= ~B_ASYNC;
448 (((nbp->b_xflags & BX_VNDIRTY) == 0) ||
450 (nbp->b_flags & B_DELWRI) == 0)) {
459 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
460 nbp = TAILQ_NEXT(bp, b_vnbufs);
461 if ((bp->b_flags & B_DELWRI) && (bp->b_lblkno < 0)) {
462 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT)) {
463 BUF_LOCK(bp, LK_EXCLUSIVE|LK_SLEEPFAIL);
467 if (bp->b_vp == vp) {
468 bp->b_flags |= B_ASYNC;
470 bp->b_flags &= ~B_ASYNC;
472 VOP_BWRITE(bp->b_vp, bp);
480 while (vp->v_numoutput > 0) {
481 vp->v_flag |= VBWAIT;
482 tsleep(&vp->v_numoutput, 0, "vbtrunc", 0);
487 vnode_pager_setsize(vp, length);
493 * Associate a buffer with a vnode.
496 bgetvp(struct vnode *vp, struct buf *bp)
498 KASSERT(bp->b_vp == NULL, ("bgetvp: not free"));
502 bp->b_dev = vn_todev(vp);
504 * Insert onto list for new vnode.
507 bp->b_xflags |= BX_VNCLEAN;
508 bp->b_xflags &= ~BX_VNDIRTY;
509 TAILQ_INSERT_TAIL(&vp->v_cleanblkhd, bp, b_vnbufs);
514 * Disassociate a buffer from a vnode.
517 brelvp(struct buf *bp)
520 struct buflists *listheadp;
522 KASSERT(bp->b_vp != NULL, ("brelvp: NULL"));
525 * Delete from old vnode list, if on one.
529 if (bp->b_xflags & (BX_VNDIRTY | BX_VNCLEAN)) {
530 if (bp->b_xflags & BX_VNDIRTY)
531 listheadp = &vp->v_dirtyblkhd;
533 listheadp = &vp->v_cleanblkhd;
534 TAILQ_REMOVE(listheadp, bp, b_vnbufs);
535 bp->b_xflags &= ~(BX_VNDIRTY | BX_VNCLEAN);
537 if ((vp->v_flag & VONWORKLST) && TAILQ_EMPTY(&vp->v_dirtyblkhd)) {
538 vp->v_flag &= ~VONWORKLST;
539 LIST_REMOVE(vp, v_synclist);
547 * Associate a p-buffer with a vnode.
549 * Also sets B_PAGING flag to indicate that vnode is not fully associated
550 * with the buffer. i.e. the bp has not been linked into the vnode or
554 pbgetvp(struct vnode *vp, struct buf *bp)
556 KASSERT(bp->b_vp == NULL, ("pbgetvp: not free"));
559 bp->b_flags |= B_PAGING;
560 bp->b_dev = vn_todev(vp);
564 * Disassociate a p-buffer from a vnode.
567 pbrelvp(struct buf *bp)
569 KASSERT(bp->b_vp != NULL, ("pbrelvp: NULL"));
572 if (TAILQ_NEXT(bp, b_vnbufs) != NULL) {
574 "relpbuf(): b_vp was probably reassignbuf()d %p %x",
579 bp->b_vp = (struct vnode *) 0;
580 bp->b_flags &= ~B_PAGING;
584 pbreassignbuf(struct buf *bp, struct vnode *newvp)
586 if ((bp->b_flags & B_PAGING) == 0) {
588 "pbreassignbuf() on non phys bp %p",
596 * Reassign a buffer from one vnode to another.
597 * Used to assign file specific control information
598 * (indirect blocks) to the vnode to which they belong.
601 reassignbuf(struct buf *bp, struct vnode *newvp)
603 struct buflists *listheadp;
607 printf("reassignbuf: NULL");
613 * B_PAGING flagged buffers cannot be reassigned because their vp
614 * is not fully linked in.
616 if (bp->b_flags & B_PAGING)
617 panic("cannot reassign paging buffer");
621 * Delete from old vnode list, if on one.
623 if (bp->b_xflags & (BX_VNDIRTY | BX_VNCLEAN)) {
624 if (bp->b_xflags & BX_VNDIRTY)
625 listheadp = &bp->b_vp->v_dirtyblkhd;
627 listheadp = &bp->b_vp->v_cleanblkhd;
628 TAILQ_REMOVE(listheadp, bp, b_vnbufs);
629 bp->b_xflags &= ~(BX_VNDIRTY | BX_VNCLEAN);
630 if (bp->b_vp != newvp) {
632 bp->b_vp = NULL; /* for clarification */
636 * If dirty, put on list of dirty buffers; otherwise insert onto list
639 if (bp->b_flags & B_DELWRI) {
642 listheadp = &newvp->v_dirtyblkhd;
643 if ((newvp->v_flag & VONWORKLST) == 0) {
644 switch (newvp->v_type) {
651 newvp->v_rdev->si_mountpoint != NULL) {
659 vn_syncer_add_to_worklist(newvp, delay);
661 bp->b_xflags |= BX_VNDIRTY;
662 tbp = TAILQ_FIRST(listheadp);
665 (bp->b_lblkno > 0 && tbp->b_lblkno < 0) ||
666 (bp->b_lblkno > 0 && bp->b_lblkno < tbp->b_lblkno)) {
667 TAILQ_INSERT_HEAD(listheadp, bp, b_vnbufs);
668 ++reassignbufsortgood;
669 } else if (bp->b_lblkno < 0) {
670 TAILQ_INSERT_TAIL(listheadp, bp, b_vnbufs);
671 ++reassignbufsortgood;
672 } else if (reassignbufmethod == 1) {
674 * New sorting algorithm, only handle sequential case,
675 * otherwise append to end (but before metadata)
677 if ((tbp = gbincore(newvp, bp->b_lblkno - 1)) != NULL &&
678 (tbp->b_xflags & BX_VNDIRTY)) {
680 * Found the best place to insert the buffer
682 TAILQ_INSERT_AFTER(listheadp, tbp, bp, b_vnbufs);
683 ++reassignbufsortgood;
686 * Missed, append to end, but before meta-data.
687 * We know that the head buffer in the list is
688 * not meta-data due to prior conditionals.
690 * Indirect effects: NFS second stage write
691 * tends to wind up here, giving maximum
692 * distance between the unstable write and the
695 tbp = TAILQ_LAST(listheadp, buflists);
696 while (tbp && tbp->b_lblkno < 0)
697 tbp = TAILQ_PREV(tbp, buflists, b_vnbufs);
698 TAILQ_INSERT_AFTER(listheadp, tbp, bp, b_vnbufs);
699 ++reassignbufsortbad;
703 * Old sorting algorithm, scan queue and insert
706 while ((ttbp = TAILQ_NEXT(tbp, b_vnbufs)) &&
707 (ttbp->b_lblkno < bp->b_lblkno)) {
711 TAILQ_INSERT_AFTER(listheadp, tbp, bp, b_vnbufs);
714 bp->b_xflags |= BX_VNCLEAN;
715 TAILQ_INSERT_TAIL(&newvp->v_cleanblkhd, bp, b_vnbufs);
716 if ((newvp->v_flag & VONWORKLST) &&
717 TAILQ_EMPTY(&newvp->v_dirtyblkhd)) {
718 newvp->v_flag &= ~VONWORKLST;
719 LIST_REMOVE(newvp, v_synclist);
722 if (bp->b_vp != newvp) {
730 * Create a vnode for a block device.
731 * Used for mounting the root file system.
734 bdevvp(dev_t dev, struct vnode **vpp)
744 error = getnewvnode(VT_NON, NULL, spec_vnode_vops, &nvp, 0, 0);
751 vp->v_udev = dev->si_udev;
758 v_associate_rdev(struct vnode *vp, dev_t dev)
762 if (dev == NULL || dev == NODEV)
764 if (dev_is_good(dev) == 0)
766 KKASSERT(vp->v_rdev == NULL);
769 vp->v_rdev = reference_dev(dev);
770 lwkt_gettoken(&ilock, &spechash_token);
771 SLIST_INSERT_HEAD(&dev->si_hlist, vp, v_specnext);
772 lwkt_reltoken(&ilock);
777 v_release_rdev(struct vnode *vp)
782 if ((dev = vp->v_rdev) != NULL) {
783 lwkt_gettoken(&ilock, &spechash_token);
784 SLIST_REMOVE(&dev->si_hlist, vp, vnode, v_specnext);
785 if (dev_ref_debug && vp->v_opencount != 0) {
786 printf("releasing rdev with non-0 "
787 "v_opencount(%d) (revoked?)\n",
793 lwkt_reltoken(&ilock);
798 * Add a vnode to the alias list hung off the dev_t. We only associate
799 * the device number with the vnode. The actual device is not associated
800 * until the vnode is opened (usually in spec_open()), and will be
801 * disassociated on last close.
804 addaliasu(struct vnode *nvp, udev_t nvp_udev)
806 if (nvp->v_type != VBLK && nvp->v_type != VCHR)
807 panic("addaliasu on non-special vnode");
808 nvp->v_udev = nvp_udev;
812 * Disassociate a vnode from its underlying filesystem.
814 * The vnode must be VX locked and refd
816 * If there are v_usecount references to the vnode other then ours we have
817 * to VOP_CLOSE the vnode before we can deactivate and reclaim it.
820 vclean(struct vnode *vp, int flags, struct thread *td)
825 * If the vnode has already been reclaimed we have nothing to do.
827 if (vp->v_flag & VRECLAIMED)
829 vp->v_flag |= VRECLAIMED;
832 * Scrap the vfs cache
834 cache_inval_vp(vp, CINV_SELF);
837 * Check to see if the vnode is in use. If so we have to reference it
838 * before we clean it out so that its count cannot fall to zero and
839 * generate a race against ourselves to recycle it.
841 active = (vp->v_usecount > 1);
844 * Clean out any buffers associated with the vnode and destroy its
845 * object, if it has one.
847 vinvalbuf(vp, V_SAVE, td, 0, 0);
848 VOP_DESTROYVOBJECT(vp);
851 * If purging an active vnode, it must be closed and
852 * deactivated before being reclaimed. XXX
854 * Note that neither of these routines unlocks the vnode.
858 VOP_CLOSE(vp, FNONBLOCK, td);
862 * If the vnode has not be deactivated, deactivated it.
864 if ((vp->v_flag & VINACTIVE) == 0) {
865 vp->v_flag |= VINACTIVE;
866 VOP_INACTIVE(vp, td);
872 if (VOP_RECLAIM(vp, td))
873 panic("vclean: cannot reclaim");
876 * Done with purge, notify sleepers of the grim news.
878 vp->v_ops = dead_vnode_vops;
884 * Eliminate all activity associated with the requested vnode
885 * and with all vnodes aliased to the requested vnode.
887 * The vnode must be referenced and vx_lock()'d
889 * revoke { struct vnode *a_vp, int a_flags }
892 vop_stdrevoke(struct vop_revoke_args *ap)
894 struct vnode *vp, *vq;
898 KASSERT((ap->a_flags & REVOKEALL) != 0, ("vop_revoke"));
903 * If the vnode is already dead don't try to revoke it
905 if (vp->v_flag & VRECLAIMED)
909 * If the vnode has a device association, scrap all vnodes associated
910 * with the device. Don't let the device disappear on us while we
911 * are scrapping the vnodes.
913 * The passed vp will probably show up in the list, do not VX lock
916 if (vp->v_type != VCHR && vp->v_type != VBLK)
918 if ((dev = vp->v_rdev) == NULL) {
919 if ((dev = udev2dev(vp->v_udev, vp->v_type == VBLK)) == NODEV)
923 lwkt_gettoken(&ilock, &spechash_token);
924 while ((vq = SLIST_FIRST(&dev->si_hlist)) != NULL) {
925 if (vp == vq || vx_get(vq) == 0) {
926 if (vq == SLIST_FIRST(&dev->si_hlist))
932 lwkt_reltoken(&ilock);
938 * Recycle an unused vnode to the front of the free list.
940 * Returns 1 if we were successfully able to recycle the vnode,
944 vrecycle(struct vnode *vp, struct thread *td)
946 if (vp->v_usecount == 1) {
954 * Eliminate all activity associated with a vnode in preparation for reuse.
956 * The vnode must be VX locked and refd and will remain VX locked and refd
957 * on return. This routine may be called with the vnode in any state, as
958 * long as it is VX locked. The vnode will be cleaned out and marked
959 * VRECLAIMED but will not actually be reused until all existing refs and
962 * NOTE: This routine may be called on a vnode which has not yet been
963 * already been deactivated (VOP_INACTIVE), or on a vnode which has
964 * already been reclaimed.
966 * This routine is not responsible for placing us back on the freelist.
967 * Instead, it happens automatically when the caller releases the VX lock
968 * (assuming there aren't any other references).
971 vgone(struct vnode *vp)
974 * assert that the VX lock is held. This is an absolute requirement
975 * now for vgone() to be called.
977 KKASSERT(vp->v_lock.lk_exclusivecount == 1);
980 * Clean out the filesystem specific data and set the VRECLAIMED
981 * bit. Also deactivate the vnode if necessary.
983 vclean(vp, DOCLOSE, curthread);
986 * Delete from old mount point vnode list, if on one.
988 if (vp->v_mount != NULL)
992 * If special device, remove it from special device alias list
993 * if it is on one. This should normally only occur if a vnode is
994 * being revoked as the device should otherwise have been released
997 if ((vp->v_type == VBLK || vp->v_type == VCHR) && vp->v_rdev != NULL) {
1008 * Lookup a vnode by device number.
1011 vfinddev(dev_t dev, enum vtype type, struct vnode **vpp)
1016 lwkt_gettoken(&ilock, &spechash_token);
1017 SLIST_FOREACH(vp, &dev->si_hlist, v_specnext) {
1018 if (type == vp->v_type) {
1020 lwkt_reltoken(&ilock);
1024 lwkt_reltoken(&ilock);
1029 * Calculate the total number of references to a special device. This
1030 * routine may only be called for VBLK and VCHR vnodes since v_rdev is
1031 * an overloaded field. Since udev2dev can now return NODEV, we have
1032 * to check for a NULL v_rdev.
1035 count_dev(dev_t dev)
1041 if (SLIST_FIRST(&dev->si_hlist)) {
1042 lwkt_gettoken(&ilock, &spechash_token);
1043 SLIST_FOREACH(vp, &dev->si_hlist, v_specnext) {
1044 count += vp->v_usecount;
1046 lwkt_reltoken(&ilock);
1052 count_udev(udev_t udev)
1056 if ((dev = udev2dev(udev, 0)) == NODEV)
1058 return(count_dev(dev));
1062 vcount(struct vnode *vp)
1064 if (vp->v_rdev == NULL)
1066 return(count_dev(vp->v_rdev));
1070 * Print out a description of a vnode.
1072 static char *typename[] =
1073 {"VNON", "VREG", "VDIR", "VBLK", "VCHR", "VLNK", "VSOCK", "VFIFO", "VBAD"};
1076 vprint(char *label, struct vnode *vp)
1081 printf("%s: %p: ", label, (void *)vp);
1083 printf("%p: ", (void *)vp);
1084 printf("type %s, usecount %d, writecount %d, refcount %d,",
1085 typename[vp->v_type], vp->v_usecount, vp->v_writecount,
1088 if (vp->v_flag & VROOT)
1089 strcat(buf, "|VROOT");
1090 if (vp->v_flag & VTEXT)
1091 strcat(buf, "|VTEXT");
1092 if (vp->v_flag & VSYSTEM)
1093 strcat(buf, "|VSYSTEM");
1094 if (vp->v_flag & VBWAIT)
1095 strcat(buf, "|VBWAIT");
1096 if (vp->v_flag & VFREE)
1097 strcat(buf, "|VFREE");
1098 if (vp->v_flag & VOBJBUF)
1099 strcat(buf, "|VOBJBUF");
1101 printf(" flags (%s)", &buf[1]);
1102 if (vp->v_data == NULL) {
1111 #include <ddb/ddb.h>
1113 * List all of the locked vnodes in the system.
1114 * Called when debugging the kernel.
1116 DB_SHOW_COMMAND(lockedvnodes, lockedvnodes)
1118 struct thread *td = curthread; /* XXX */
1120 struct mount *mp, *nmp;
1123 printf("Locked vnodes\n");
1124 lwkt_gettoken(&ilock, &mountlist_token);
1125 for (mp = TAILQ_FIRST(&mountlist); mp != NULL; mp = nmp) {
1126 if (vfs_busy(mp, LK_NOWAIT, &ilock, td)) {
1127 nmp = TAILQ_NEXT(mp, mnt_list);
1130 TAILQ_FOREACH(vp, &mp->mnt_nvnodelist, v_nmntvnodes) {
1131 if (VOP_ISLOCKED(vp, NULL))
1132 vprint((char *)0, vp);
1134 lwkt_gettokref(&ilock);
1135 nmp = TAILQ_NEXT(mp, mnt_list);
1138 lwkt_reltoken(&ilock);
1143 * Top level filesystem related information gathering.
1145 static int sysctl_ovfs_conf (SYSCTL_HANDLER_ARGS);
1148 vfs_sysctl(SYSCTL_HANDLER_ARGS)
1150 int *name = (int *)arg1 - 1; /* XXX */
1151 u_int namelen = arg2 + 1; /* XXX */
1152 struct vfsconf *vfsp;
1154 #if 1 || defined(COMPAT_PRELITE2)
1155 /* Resolve ambiguity between VFS_VFSCONF and VFS_GENERIC. */
1157 return (sysctl_ovfs_conf(oidp, arg1, arg2, req));
1161 /* all sysctl names at this level are at least name and field */
1163 return (ENOTDIR); /* overloaded */
1164 if (name[0] != VFS_GENERIC) {
1165 for (vfsp = vfsconf; vfsp; vfsp = vfsp->vfc_next)
1166 if (vfsp->vfc_typenum == name[0])
1169 return (EOPNOTSUPP);
1170 return ((*vfsp->vfc_vfsops->vfs_sysctl)(&name[1], namelen - 1,
1171 oldp, oldlenp, newp, newlen, p));
1175 case VFS_MAXTYPENUM:
1178 return (SYSCTL_OUT(req, &maxvfsconf, sizeof(int)));
1181 return (ENOTDIR); /* overloaded */
1182 for (vfsp = vfsconf; vfsp; vfsp = vfsp->vfc_next)
1183 if (vfsp->vfc_typenum == name[2])
1186 return (EOPNOTSUPP);
1187 return (SYSCTL_OUT(req, vfsp, sizeof *vfsp));
1189 return (EOPNOTSUPP);
1192 SYSCTL_NODE(_vfs, VFS_GENERIC, generic, CTLFLAG_RD, vfs_sysctl,
1193 "Generic filesystem");
1195 #if 1 || defined(COMPAT_PRELITE2)
1198 sysctl_ovfs_conf(SYSCTL_HANDLER_ARGS)
1201 struct vfsconf *vfsp;
1202 struct ovfsconf ovfs;
1204 for (vfsp = vfsconf; vfsp; vfsp = vfsp->vfc_next) {
1205 ovfs.vfc_vfsops = vfsp->vfc_vfsops; /* XXX used as flag */
1206 strcpy(ovfs.vfc_name, vfsp->vfc_name);
1207 ovfs.vfc_index = vfsp->vfc_typenum;
1208 ovfs.vfc_refcount = vfsp->vfc_refcount;
1209 ovfs.vfc_flags = vfsp->vfc_flags;
1210 error = SYSCTL_OUT(req, &ovfs, sizeof ovfs);
1217 #endif /* 1 || COMPAT_PRELITE2 */
1220 #define KINFO_VNODESLOP 10
1222 * Dump vnode list (via sysctl).
1223 * Copyout address of vnode followed by vnode.
1227 sysctl_vnode(SYSCTL_HANDLER_ARGS)
1229 struct proc *p = curproc; /* XXX */
1230 struct mount *mp, *nmp;
1231 struct vnode *nvp, *vp;
1236 #define VPTRSZ sizeof (struct vnode *)
1237 #define VNODESZ sizeof (struct vnode)
1240 if (!req->oldptr) /* Make an estimate */
1241 return (SYSCTL_OUT(req, 0,
1242 (numvnodes + KINFO_VNODESLOP) * (VPTRSZ + VNODESZ)));
1244 lwkt_gettoken(&ilock, &mountlist_token);
1245 for (mp = TAILQ_FIRST(&mountlist); mp != NULL; mp = nmp) {
1246 if (vfs_busy(mp, LK_NOWAIT, &ilock, p)) {
1247 nmp = TAILQ_NEXT(mp, mnt_list);
1250 lwkt_gettoken(&jlock, &mntvnode_token);
1252 for (vp = TAILQ_FIRST(&mp->mnt_nvnodelist);
1256 * Check that the vp is still associated with
1257 * this filesystem. RACE: could have been
1258 * recycled onto the same filesystem.
1260 if (vp->v_mount != mp)
1262 nvp = TAILQ_NEXT(vp, v_nmntvnodes);
1263 if ((error = SYSCTL_OUT(req, &vp, VPTRSZ)) ||
1264 (error = SYSCTL_OUT(req, vp, VNODESZ))) {
1265 lwkt_reltoken(&jlock);
1269 lwkt_reltoken(&jlock);
1270 lwkt_gettokref(&ilock);
1271 nmp = TAILQ_NEXT(mp, mnt_list); /* ZZZ */
1274 lwkt_reltoken(&ilock);
1282 * Exporting the vnode list on large systems causes them to crash.
1283 * Exporting the vnode list on medium systems causes sysctl to coredump.
1286 SYSCTL_PROC(_kern, KERN_VNODE, vnode, CTLTYPE_OPAQUE|CTLFLAG_RD,
1287 0, 0, sysctl_vnode, "S,vnode", "");
1291 * Check to see if a filesystem is mounted on a block device.
1294 vfs_mountedon(struct vnode *vp)
1298 if ((dev = vp->v_rdev) == NULL)
1299 dev = udev2dev(vp->v_udev, (vp->v_type == VBLK));
1300 if (dev != NODEV && dev->si_mountpoint)
1306 * Unmount all filesystems. The list is traversed in reverse order
1307 * of mounting to avoid dependencies.
1310 vfs_unmountall(void)
1313 struct thread *td = curthread;
1316 if (td->td_proc == NULL)
1317 td = initproc->p_thread; /* XXX XXX use proc0 instead? */
1320 * Since this only runs when rebooting, it is not interlocked.
1322 while(!TAILQ_EMPTY(&mountlist)) {
1323 mp = TAILQ_LAST(&mountlist, mntlist);
1324 error = dounmount(mp, MNT_FORCE, td);
1326 TAILQ_REMOVE(&mountlist, mp, mnt_list);
1327 printf("unmount of %s failed (",
1328 mp->mnt_stat.f_mntonname);
1332 printf("%d)\n", error);
1334 /* The unmount has removed mp from the mountlist */
1340 * Build hash lists of net addresses and hang them off the mount point.
1341 * Called by ufs_mount() to set up the lists of export addresses.
1344 vfs_hang_addrlist(struct mount *mp, struct netexport *nep,
1345 struct export_args *argp)
1348 struct radix_node_head *rnh;
1350 struct radix_node *rn;
1351 struct sockaddr *saddr, *smask = 0;
1355 if (argp->ex_addrlen == 0) {
1356 if (mp->mnt_flag & MNT_DEFEXPORTED)
1358 np = &nep->ne_defexported;
1359 np->netc_exflags = argp->ex_flags;
1360 np->netc_anon = argp->ex_anon;
1361 np->netc_anon.cr_ref = 1;
1362 mp->mnt_flag |= MNT_DEFEXPORTED;
1366 if (argp->ex_addrlen < 0 || argp->ex_addrlen > MLEN)
1368 if (argp->ex_masklen < 0 || argp->ex_masklen > MLEN)
1371 i = sizeof(struct netcred) + argp->ex_addrlen + argp->ex_masklen;
1372 np = (struct netcred *) malloc(i, M_NETADDR, M_WAITOK);
1373 bzero((caddr_t) np, i);
1374 saddr = (struct sockaddr *) (np + 1);
1375 if ((error = copyin(argp->ex_addr, (caddr_t) saddr, argp->ex_addrlen)))
1377 if (saddr->sa_len > argp->ex_addrlen)
1378 saddr->sa_len = argp->ex_addrlen;
1379 if (argp->ex_masklen) {
1380 smask = (struct sockaddr *)((caddr_t)saddr + argp->ex_addrlen);
1381 error = copyin(argp->ex_mask, (caddr_t)smask, argp->ex_masklen);
1384 if (smask->sa_len > argp->ex_masklen)
1385 smask->sa_len = argp->ex_masklen;
1387 i = saddr->sa_family;
1388 if ((rnh = nep->ne_rtable[i]) == 0) {
1390 * Seems silly to initialize every AF when most are not used,
1391 * do so on demand here
1393 for (dom = domains; dom; dom = dom->dom_next)
1394 if (dom->dom_family == i && dom->dom_rtattach) {
1395 dom->dom_rtattach((void **) &nep->ne_rtable[i],
1399 if ((rnh = nep->ne_rtable[i]) == 0) {
1404 rn = (*rnh->rnh_addaddr) ((caddr_t) saddr, (caddr_t) smask, rnh,
1406 if (rn == 0 || np != (struct netcred *) rn) { /* already exists */
1410 np->netc_exflags = argp->ex_flags;
1411 np->netc_anon = argp->ex_anon;
1412 np->netc_anon.cr_ref = 1;
1415 free(np, M_NETADDR);
1421 vfs_free_netcred(struct radix_node *rn, void *w)
1423 struct radix_node_head *rnh = (struct radix_node_head *) w;
1425 (*rnh->rnh_deladdr) (rn->rn_key, rn->rn_mask, rnh);
1426 free((caddr_t) rn, M_NETADDR);
1431 * Free the net address hash lists that are hanging off the mount points.
1434 vfs_free_addrlist(struct netexport *nep)
1437 struct radix_node_head *rnh;
1439 for (i = 0; i <= AF_MAX; i++)
1440 if ((rnh = nep->ne_rtable[i])) {
1441 (*rnh->rnh_walktree) (rnh, vfs_free_netcred,
1443 free((caddr_t) rnh, M_RTABLE);
1444 nep->ne_rtable[i] = 0;
1449 vfs_export(struct mount *mp, struct netexport *nep, struct export_args *argp)
1453 if (argp->ex_flags & MNT_DELEXPORT) {
1454 if (mp->mnt_flag & MNT_EXPUBLIC) {
1455 vfs_setpublicfs(NULL, NULL, NULL);
1456 mp->mnt_flag &= ~MNT_EXPUBLIC;
1458 vfs_free_addrlist(nep);
1459 mp->mnt_flag &= ~(MNT_EXPORTED | MNT_DEFEXPORTED);
1461 if (argp->ex_flags & MNT_EXPORTED) {
1462 if (argp->ex_flags & MNT_EXPUBLIC) {
1463 if ((error = vfs_setpublicfs(mp, nep, argp)) != 0)
1465 mp->mnt_flag |= MNT_EXPUBLIC;
1467 if ((error = vfs_hang_addrlist(mp, nep, argp)))
1469 mp->mnt_flag |= MNT_EXPORTED;
1476 * Set the publicly exported filesystem (WebNFS). Currently, only
1477 * one public filesystem is possible in the spec (RFC 2054 and 2055)
1480 vfs_setpublicfs(struct mount *mp, struct netexport *nep,
1481 struct export_args *argp)
1488 * mp == NULL -> invalidate the current info, the FS is
1489 * no longer exported. May be called from either vfs_export
1490 * or unmount, so check if it hasn't already been done.
1493 if (nfs_pub.np_valid) {
1494 nfs_pub.np_valid = 0;
1495 if (nfs_pub.np_index != NULL) {
1496 FREE(nfs_pub.np_index, M_TEMP);
1497 nfs_pub.np_index = NULL;
1504 * Only one allowed at a time.
1506 if (nfs_pub.np_valid != 0 && mp != nfs_pub.np_mount)
1510 * Get real filehandle for root of exported FS.
1512 bzero((caddr_t)&nfs_pub.np_handle, sizeof(nfs_pub.np_handle));
1513 nfs_pub.np_handle.fh_fsid = mp->mnt_stat.f_fsid;
1515 if ((error = VFS_ROOT(mp, &rvp)))
1518 if ((error = VFS_VPTOFH(rvp, &nfs_pub.np_handle.fh_fid)))
1524 * If an indexfile was specified, pull it in.
1526 if (argp->ex_indexfile != NULL) {
1527 MALLOC(nfs_pub.np_index, char *, MAXNAMLEN + 1, M_TEMP,
1529 error = copyinstr(argp->ex_indexfile, nfs_pub.np_index,
1530 MAXNAMLEN, (size_t *)0);
1533 * Check for illegal filenames.
1535 for (cp = nfs_pub.np_index; *cp; cp++) {
1543 FREE(nfs_pub.np_index, M_TEMP);
1548 nfs_pub.np_mount = mp;
1549 nfs_pub.np_valid = 1;
1554 vfs_export_lookup(struct mount *mp, struct netexport *nep,
1555 struct sockaddr *nam)
1558 struct radix_node_head *rnh;
1559 struct sockaddr *saddr;
1562 if (mp->mnt_flag & MNT_EXPORTED) {
1564 * Lookup in the export list first.
1568 rnh = nep->ne_rtable[saddr->sa_family];
1570 np = (struct netcred *)
1571 (*rnh->rnh_matchaddr)((caddr_t)saddr,
1573 if (np && np->netc_rnodes->rn_flags & RNF_ROOT)
1578 * If no address match, use the default if it exists.
1580 if (np == NULL && mp->mnt_flag & MNT_DEFEXPORTED)
1581 np = &nep->ne_defexported;
1587 * perform msync on all vnodes under a mount point. The mount point must
1588 * be locked. This code is also responsible for lazy-freeing unreferenced
1589 * vnodes whos VM objects no longer contain pages.
1591 * NOTE: MNT_WAIT still skips vnodes in the VXLOCK state.
1593 static int vfs_msync_scan1(struct mount *mp, struct vnode *vp, void *data);
1594 static int vfs_msync_scan2(struct mount *mp, struct vnode *vp, void *data);
1597 vfs_msync(struct mount *mp, int flags)
1599 vmntvnodescan(mp, VMSC_REFVP, vfs_msync_scan1, vfs_msync_scan2,
1604 * scan1 is a fast pre-check. There could be hundreds of thousands of
1605 * vnodes, we cannot afford to do anything heavy weight until we have a
1606 * fairly good indication that there is work to do.
1610 vfs_msync_scan1(struct mount *mp, struct vnode *vp, void *data)
1612 int flags = (int)data;
1614 if ((vp->v_flag & VRECLAIMED) == 0) {
1615 if (vshouldfree(vp, 0))
1616 return(0); /* call scan2 */
1617 if ((mp->mnt_flag & MNT_RDONLY) == 0 &&
1618 (vp->v_flag & VOBJDIRTY) &&
1619 (flags == MNT_WAIT || VOP_ISLOCKED(vp, NULL) == 0)) {
1620 return(0); /* call scan2 */
1625 * do not call scan2, continue the loop
1632 vfs_msync_scan2(struct mount *mp, struct vnode *vp, void *data)
1635 int flags = (int)data;
1637 if (vp->v_flag & VRECLAIMED)
1640 if ((mp->mnt_flag & MNT_RDONLY) == 0 &&
1641 (vp->v_flag & VOBJDIRTY) &&
1642 (flags == MNT_WAIT || VOP_ISLOCKED(vp, NULL) == 0)) {
1643 if (VOP_GETVOBJECT(vp, &obj) == 0) {
1644 vm_object_page_clean(obj, 0, 0,
1645 flags == MNT_WAIT ? OBJPC_SYNC : OBJPC_NOSYNC);
1652 * Create the VM object needed for VMIO and mmap support. This
1653 * is done for all VREG files in the system. Some filesystems might
1654 * afford the additional metadata buffering capability of the
1655 * VMIO code by making the device node be VMIO mode also.
1657 * vp must be locked when vfs_object_create is called.
1660 vfs_object_create(struct vnode *vp, struct thread *td)
1662 return (VOP_CREATEVOBJECT(vp, td));
1666 * Record a process's interest in events which might happen to
1667 * a vnode. Because poll uses the historic select-style interface
1668 * internally, this routine serves as both the ``check for any
1669 * pending events'' and the ``record my interest in future events''
1670 * functions. (These are done together, while the lock is held,
1671 * to avoid race conditions.)
1674 vn_pollrecord(struct vnode *vp, struct thread *td, int events)
1678 lwkt_gettoken(&ilock, &vp->v_pollinfo.vpi_token);
1679 if (vp->v_pollinfo.vpi_revents & events) {
1681 * This leaves events we are not interested
1682 * in available for the other process which
1683 * which presumably had requested them
1684 * (otherwise they would never have been
1687 events &= vp->v_pollinfo.vpi_revents;
1688 vp->v_pollinfo.vpi_revents &= ~events;
1690 lwkt_reltoken(&ilock);
1693 vp->v_pollinfo.vpi_events |= events;
1694 selrecord(td, &vp->v_pollinfo.vpi_selinfo);
1695 lwkt_reltoken(&ilock);
1700 * Note the occurrence of an event. If the VN_POLLEVENT macro is used,
1701 * it is possible for us to miss an event due to race conditions, but
1702 * that condition is expected to be rare, so for the moment it is the
1703 * preferred interface.
1706 vn_pollevent(struct vnode *vp, int events)
1710 lwkt_gettoken(&ilock, &vp->v_pollinfo.vpi_token);
1711 if (vp->v_pollinfo.vpi_events & events) {
1713 * We clear vpi_events so that we don't
1714 * call selwakeup() twice if two events are
1715 * posted before the polling process(es) is
1716 * awakened. This also ensures that we take at
1717 * most one selwakeup() if the polling process
1718 * is no longer interested. However, it does
1719 * mean that only one event can be noticed at
1720 * a time. (Perhaps we should only clear those
1721 * event bits which we note?) XXX
1723 vp->v_pollinfo.vpi_events = 0; /* &= ~events ??? */
1724 vp->v_pollinfo.vpi_revents |= events;
1725 selwakeup(&vp->v_pollinfo.vpi_selinfo);
1727 lwkt_reltoken(&ilock);
1731 * Wake up anyone polling on vp because it is being revoked.
1732 * This depends on dead_poll() returning POLLHUP for correct
1736 vn_pollgone(struct vnode *vp)
1740 lwkt_gettoken(&ilock, &vp->v_pollinfo.vpi_token);
1741 if (vp->v_pollinfo.vpi_events) {
1742 vp->v_pollinfo.vpi_events = 0;
1743 selwakeup(&vp->v_pollinfo.vpi_selinfo);
1745 lwkt_reltoken(&ilock);
1749 * extract the dev_t from a VBLK or VCHR. The vnode must have been opened
1750 * (or v_rdev might be NULL).
1753 vn_todev(struct vnode *vp)
1755 if (vp->v_type != VBLK && vp->v_type != VCHR)
1757 KKASSERT(vp->v_rdev != NULL);
1758 return (vp->v_rdev);
1762 * Check if vnode represents a disk device. The vnode does not need to be
1766 vn_isdisk(struct vnode *vp, int *errp)
1770 if (vp->v_type != VBLK && vp->v_type != VCHR) {
1776 if ((dev = vp->v_rdev) == NULL)
1777 dev = udev2dev(vp->v_udev, (vp->v_type == VBLK));
1778 if (dev == NULL || dev == NODEV) {
1783 if (dev_is_good(dev) == 0) {
1788 if ((dev_dflags(dev) & D_DISK) == 0) {
1799 NDFREE(struct nameidata *ndp, const uint flags)
1801 if (!(flags & NDF_NO_FREE_PNBUF) &&
1802 (ndp->ni_cnd.cn_flags & CNP_HASBUF)) {
1803 zfree(namei_zone, ndp->ni_cnd.cn_pnbuf);
1804 ndp->ni_cnd.cn_flags &= ~CNP_HASBUF;
1806 if (!(flags & NDF_NO_DVP_UNLOCK) &&
1807 (ndp->ni_cnd.cn_flags & CNP_LOCKPARENT) &&
1808 ndp->ni_dvp != ndp->ni_vp) {
1809 VOP_UNLOCK(ndp->ni_dvp, 0, ndp->ni_cnd.cn_td);
1811 if (!(flags & NDF_NO_DVP_RELE) &&
1812 (ndp->ni_cnd.cn_flags & (CNP_LOCKPARENT|CNP_WANTPARENT))) {
1816 if (!(flags & NDF_NO_VP_UNLOCK) &&
1817 (ndp->ni_cnd.cn_flags & CNP_LOCKLEAF) && ndp->ni_vp) {
1818 VOP_UNLOCK(ndp->ni_vp, 0, ndp->ni_cnd.cn_td);
1820 if (!(flags & NDF_NO_VP_RELE) &&
1825 if (!(flags & NDF_NO_STARTDIR_RELE) &&
1826 (ndp->ni_cnd.cn_flags & CNP_SAVESTART)) {
1827 vrele(ndp->ni_startdir);
1828 ndp->ni_startdir = NULL;
1832 #ifdef DEBUG_VFS_LOCKS
1835 assert_vop_locked(struct vnode *vp, const char *str)
1837 if (vp && IS_LOCKING_VFS(vp) && !VOP_ISLOCKED(vp, NULL)) {
1838 panic("%s: %p is not locked shared but should be", str, vp);
1843 assert_vop_unlocked(struct vnode *vp, const char *str)
1845 if (vp && IS_LOCKING_VFS(vp)) {
1846 if (VOP_ISLOCKED(vp, curthread) == LK_EXCLUSIVE) {
1847 panic("%s: %p is locked but should not be", str, vp);