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.45 2004/10/25 19:14:32 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 int nfs_mount_type = -1;
118 static struct lwkt_token spechash_token;
119 struct nfs_public nfs_pub; /* publicly exported FS */
122 SYSCTL_INT(_kern, KERN_MAXVNODES, maxvnodes, CTLFLAG_RW,
123 &desiredvnodes, 0, "Maximum number of vnodes");
125 static void vfs_free_addrlist (struct netexport *nep);
126 static int vfs_free_netcred (struct radix_node *rn, void *w);
127 static int vfs_hang_addrlist (struct mount *mp, struct netexport *nep,
128 struct export_args *argp);
130 extern int dev_ref_debug;
131 extern struct vnodeopv_entry_desc spec_vnodeop_entries[];
134 * Return 0 if the vnode is already on the free list or cannot be placed
135 * on the free list. Return 1 if the vnode can be placed on the free list.
138 vshouldfree(struct vnode *vp, int usecount)
140 if (vp->v_flag & VFREE)
141 return (0); /* already free */
142 if (vp->v_holdcnt != 0 || vp->v_usecount != usecount)
143 return (0); /* other holderse */
145 (vp->v_object->ref_count || vp->v_object->resident_page_count)) {
152 * Initialize the vnode management data structures.
154 * Called from vfsinit()
160 * Desired vnodes is a result of the physical page count
161 * and the size of kernel's heap. It scales in proportion
162 * to the amount of available physical memory. This can
163 * cause trouble on 64-bit and large memory platforms.
165 /* desiredvnodes = maxproc + vmstats.v_page_count / 4; */
167 min(maxproc + vmstats.v_page_count /4,
168 2 * (VM_MAX_KERNEL_ADDRESS - VM_MIN_KERNEL_ADDRESS) /
169 (5 * (sizeof(struct vm_object) + sizeof(struct vnode))));
171 lwkt_token_init(&spechash_token);
175 * Knob to control the precision of file timestamps:
177 * 0 = seconds only; nanoseconds zeroed.
178 * 1 = seconds and nanoseconds, accurate within 1/HZ.
179 * 2 = seconds and nanoseconds, truncated to microseconds.
180 * >=3 = seconds and nanoseconds, maximum precision.
182 enum { TSP_SEC, TSP_HZ, TSP_USEC, TSP_NSEC };
184 static int timestamp_precision = TSP_SEC;
185 SYSCTL_INT(_vfs, OID_AUTO, timestamp_precision, CTLFLAG_RW,
186 ×tamp_precision, 0, "");
189 * Get a current timestamp.
192 vfs_timestamp(struct timespec *tsp)
196 switch (timestamp_precision) {
198 tsp->tv_sec = time_second;
206 TIMEVAL_TO_TIMESPEC(&tv, tsp);
216 * Set vnode attributes to VNOVAL
219 vattr_null(struct vattr *vap)
222 vap->va_size = VNOVAL;
223 vap->va_bytes = VNOVAL;
224 vap->va_mode = VNOVAL;
225 vap->va_nlink = VNOVAL;
226 vap->va_uid = VNOVAL;
227 vap->va_gid = VNOVAL;
228 vap->va_fsid = VNOVAL;
229 vap->va_fileid = VNOVAL;
230 vap->va_blocksize = VNOVAL;
231 vap->va_rdev = VNOVAL;
232 vap->va_atime.tv_sec = VNOVAL;
233 vap->va_atime.tv_nsec = VNOVAL;
234 vap->va_mtime.tv_sec = VNOVAL;
235 vap->va_mtime.tv_nsec = VNOVAL;
236 vap->va_ctime.tv_sec = VNOVAL;
237 vap->va_ctime.tv_nsec = VNOVAL;
238 vap->va_flags = VNOVAL;
239 vap->va_gen = VNOVAL;
244 * Update outstanding I/O count and do wakeup if requested.
247 vwakeup(struct buf *bp)
251 bp->b_flags &= ~B_WRITEINPROG;
252 if ((vp = bp->b_vp)) {
254 if (vp->v_numoutput < 0)
255 panic("vwakeup: neg numoutput");
256 if ((vp->v_numoutput == 0) && (vp->v_flag & VBWAIT)) {
257 vp->v_flag &= ~VBWAIT;
258 wakeup((caddr_t) &vp->v_numoutput);
264 * Flush out and invalidate all buffers associated with a vnode.
269 vinvalbuf(struct vnode *vp, int flags, struct thread *td,
270 int slpflag, int slptimeo)
273 struct buf *nbp, *blist;
277 if (flags & V_SAVE) {
279 while (vp->v_numoutput) {
280 vp->v_flag |= VBWAIT;
281 error = tsleep((caddr_t)&vp->v_numoutput,
282 slpflag, "vinvlbuf", slptimeo);
288 if (!TAILQ_EMPTY(&vp->v_dirtyblkhd)) {
290 if ((error = VOP_FSYNC(vp, MNT_WAIT, td)) != 0)
293 if (vp->v_numoutput > 0 ||
294 !TAILQ_EMPTY(&vp->v_dirtyblkhd))
295 panic("vinvalbuf: dirty bufs");
301 blist = TAILQ_FIRST(&vp->v_cleanblkhd);
303 blist = TAILQ_FIRST(&vp->v_dirtyblkhd);
307 for (bp = blist; bp; bp = nbp) {
308 nbp = TAILQ_NEXT(bp, b_vnbufs);
309 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT)) {
310 error = BUF_TIMELOCK(bp,
311 LK_EXCLUSIVE | LK_SLEEPFAIL,
312 "vinvalbuf", slpflag, slptimeo);
319 * XXX Since there are no node locks for NFS, I
320 * believe there is a slight chance that a delayed
321 * write will occur while sleeping just above, so
322 * check for it. Note that vfs_bio_awrite expects
323 * buffers to reside on a queue, while VOP_BWRITE and
326 if (((bp->b_flags & (B_DELWRI | B_INVAL)) == B_DELWRI) &&
329 if (bp->b_vp == vp) {
330 if (bp->b_flags & B_CLUSTEROK) {
335 bp->b_flags |= B_ASYNC;
336 VOP_BWRITE(bp->b_vp, bp);
340 (void) VOP_BWRITE(bp->b_vp, bp);
345 bp->b_flags |= (B_INVAL | B_NOCACHE | B_RELBUF);
346 bp->b_flags &= ~B_ASYNC;
352 * Wait for I/O to complete. XXX needs cleaning up. The vnode can
353 * have write I/O in-progress but if there is a VM object then the
354 * VM object can also have read-I/O in-progress.
357 while (vp->v_numoutput > 0) {
358 vp->v_flag |= VBWAIT;
359 tsleep(&vp->v_numoutput, 0, "vnvlbv", 0);
361 if (VOP_GETVOBJECT(vp, &object) == 0) {
362 while (object->paging_in_progress)
363 vm_object_pip_sleep(object, "vnvlbx");
365 } while (vp->v_numoutput > 0);
370 * Destroy the copy in the VM cache, too.
372 if (VOP_GETVOBJECT(vp, &object) == 0) {
373 vm_object_page_remove(object, 0, 0,
374 (flags & V_SAVE) ? TRUE : FALSE);
377 if (!TAILQ_EMPTY(&vp->v_dirtyblkhd) || !TAILQ_EMPTY(&vp->v_cleanblkhd))
378 panic("vinvalbuf: flush failed");
383 * Truncate a file's buffer and pages to a specified length. This
384 * is in lieu of the old vinvalbuf mechanism, which performed unneeded
387 * The vnode must be locked.
390 vtruncbuf(struct vnode *vp, struct thread *td, off_t length, int blksize)
398 * Round up to the *next* lbn.
400 trunclbn = (length + blksize - 1) / blksize;
407 for (bp = TAILQ_FIRST(&vp->v_cleanblkhd); bp; bp = nbp) {
408 nbp = TAILQ_NEXT(bp, b_vnbufs);
409 if (bp->b_lblkno >= trunclbn) {
410 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT)) {
411 BUF_LOCK(bp, LK_EXCLUSIVE|LK_SLEEPFAIL);
415 bp->b_flags |= (B_INVAL | B_RELBUF);
416 bp->b_flags &= ~B_ASYNC;
421 (((nbp->b_xflags & BX_VNCLEAN) == 0) ||
423 (nbp->b_flags & B_DELWRI))) {
429 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
430 nbp = TAILQ_NEXT(bp, b_vnbufs);
431 if (bp->b_lblkno >= trunclbn) {
432 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT)) {
433 BUF_LOCK(bp, LK_EXCLUSIVE|LK_SLEEPFAIL);
437 bp->b_flags |= (B_INVAL | B_RELBUF);
438 bp->b_flags &= ~B_ASYNC;
443 (((nbp->b_xflags & BX_VNDIRTY) == 0) ||
445 (nbp->b_flags & B_DELWRI) == 0)) {
454 for (bp = TAILQ_FIRST(&vp->v_dirtyblkhd); bp; bp = nbp) {
455 nbp = TAILQ_NEXT(bp, b_vnbufs);
456 if ((bp->b_flags & B_DELWRI) && (bp->b_lblkno < 0)) {
457 if (BUF_LOCK(bp, LK_EXCLUSIVE | LK_NOWAIT)) {
458 BUF_LOCK(bp, LK_EXCLUSIVE|LK_SLEEPFAIL);
462 if (bp->b_vp == vp) {
463 bp->b_flags |= B_ASYNC;
465 bp->b_flags &= ~B_ASYNC;
467 VOP_BWRITE(bp->b_vp, bp);
475 while (vp->v_numoutput > 0) {
476 vp->v_flag |= VBWAIT;
477 tsleep(&vp->v_numoutput, 0, "vbtrunc", 0);
482 vnode_pager_setsize(vp, length);
488 * Associate a buffer with a vnode.
491 bgetvp(struct vnode *vp, struct buf *bp)
493 KASSERT(bp->b_vp == NULL, ("bgetvp: not free"));
497 bp->b_dev = vn_todev(vp);
499 * Insert onto list for new vnode.
502 bp->b_xflags |= BX_VNCLEAN;
503 bp->b_xflags &= ~BX_VNDIRTY;
504 TAILQ_INSERT_TAIL(&vp->v_cleanblkhd, bp, b_vnbufs);
509 * Disassociate a buffer from a vnode.
512 brelvp(struct buf *bp)
515 struct buflists *listheadp;
517 KASSERT(bp->b_vp != NULL, ("brelvp: NULL"));
520 * Delete from old vnode list, if on one.
524 if (bp->b_xflags & (BX_VNDIRTY | BX_VNCLEAN)) {
525 if (bp->b_xflags & BX_VNDIRTY)
526 listheadp = &vp->v_dirtyblkhd;
528 listheadp = &vp->v_cleanblkhd;
529 TAILQ_REMOVE(listheadp, bp, b_vnbufs);
530 bp->b_xflags &= ~(BX_VNDIRTY | BX_VNCLEAN);
532 if ((vp->v_flag & VONWORKLST) && TAILQ_EMPTY(&vp->v_dirtyblkhd)) {
533 vp->v_flag &= ~VONWORKLST;
534 LIST_REMOVE(vp, v_synclist);
542 * Associate a p-buffer with a vnode.
544 * Also sets B_PAGING flag to indicate that vnode is not fully associated
545 * with the buffer. i.e. the bp has not been linked into the vnode or
549 pbgetvp(struct vnode *vp, struct buf *bp)
551 KASSERT(bp->b_vp == NULL, ("pbgetvp: not free"));
554 bp->b_flags |= B_PAGING;
555 bp->b_dev = vn_todev(vp);
559 * Disassociate a p-buffer from a vnode.
562 pbrelvp(struct buf *bp)
564 KASSERT(bp->b_vp != NULL, ("pbrelvp: NULL"));
567 if (TAILQ_NEXT(bp, b_vnbufs) != NULL) {
569 "relpbuf(): b_vp was probably reassignbuf()d %p %x",
574 bp->b_vp = (struct vnode *) 0;
575 bp->b_flags &= ~B_PAGING;
579 pbreassignbuf(struct buf *bp, struct vnode *newvp)
581 if ((bp->b_flags & B_PAGING) == 0) {
583 "pbreassignbuf() on non phys bp %p",
591 * Reassign a buffer from one vnode to another.
592 * Used to assign file specific control information
593 * (indirect blocks) to the vnode to which they belong.
596 reassignbuf(struct buf *bp, struct vnode *newvp)
598 struct buflists *listheadp;
602 printf("reassignbuf: NULL");
608 * B_PAGING flagged buffers cannot be reassigned because their vp
609 * is not fully linked in.
611 if (bp->b_flags & B_PAGING)
612 panic("cannot reassign paging buffer");
616 * Delete from old vnode list, if on one.
618 if (bp->b_xflags & (BX_VNDIRTY | BX_VNCLEAN)) {
619 if (bp->b_xflags & BX_VNDIRTY)
620 listheadp = &bp->b_vp->v_dirtyblkhd;
622 listheadp = &bp->b_vp->v_cleanblkhd;
623 TAILQ_REMOVE(listheadp, bp, b_vnbufs);
624 bp->b_xflags &= ~(BX_VNDIRTY | BX_VNCLEAN);
625 if (bp->b_vp != newvp) {
627 bp->b_vp = NULL; /* for clarification */
631 * If dirty, put on list of dirty buffers; otherwise insert onto list
634 if (bp->b_flags & B_DELWRI) {
637 listheadp = &newvp->v_dirtyblkhd;
638 if ((newvp->v_flag & VONWORKLST) == 0) {
639 switch (newvp->v_type) {
646 newvp->v_rdev->si_mountpoint != NULL) {
654 vn_syncer_add_to_worklist(newvp, delay);
656 bp->b_xflags |= BX_VNDIRTY;
657 tbp = TAILQ_FIRST(listheadp);
660 (bp->b_lblkno > 0 && tbp->b_lblkno < 0) ||
661 (bp->b_lblkno > 0 && bp->b_lblkno < tbp->b_lblkno)) {
662 TAILQ_INSERT_HEAD(listheadp, bp, b_vnbufs);
663 ++reassignbufsortgood;
664 } else if (bp->b_lblkno < 0) {
665 TAILQ_INSERT_TAIL(listheadp, bp, b_vnbufs);
666 ++reassignbufsortgood;
667 } else if (reassignbufmethod == 1) {
669 * New sorting algorithm, only handle sequential case,
670 * otherwise append to end (but before metadata)
672 if ((tbp = gbincore(newvp, bp->b_lblkno - 1)) != NULL &&
673 (tbp->b_xflags & BX_VNDIRTY)) {
675 * Found the best place to insert the buffer
677 TAILQ_INSERT_AFTER(listheadp, tbp, bp, b_vnbufs);
678 ++reassignbufsortgood;
681 * Missed, append to end, but before meta-data.
682 * We know that the head buffer in the list is
683 * not meta-data due to prior conditionals.
685 * Indirect effects: NFS second stage write
686 * tends to wind up here, giving maximum
687 * distance between the unstable write and the
690 tbp = TAILQ_LAST(listheadp, buflists);
691 while (tbp && tbp->b_lblkno < 0)
692 tbp = TAILQ_PREV(tbp, buflists, b_vnbufs);
693 TAILQ_INSERT_AFTER(listheadp, tbp, bp, b_vnbufs);
694 ++reassignbufsortbad;
698 * Old sorting algorithm, scan queue and insert
701 while ((ttbp = TAILQ_NEXT(tbp, b_vnbufs)) &&
702 (ttbp->b_lblkno < bp->b_lblkno)) {
706 TAILQ_INSERT_AFTER(listheadp, tbp, bp, b_vnbufs);
709 bp->b_xflags |= BX_VNCLEAN;
710 TAILQ_INSERT_TAIL(&newvp->v_cleanblkhd, bp, b_vnbufs);
711 if ((newvp->v_flag & VONWORKLST) &&
712 TAILQ_EMPTY(&newvp->v_dirtyblkhd)) {
713 newvp->v_flag &= ~VONWORKLST;
714 LIST_REMOVE(newvp, v_synclist);
717 if (bp->b_vp != newvp) {
725 * Create a vnode for a block device.
726 * Used for mounting the root file system.
729 bdevvp(dev_t dev, struct vnode **vpp)
739 error = getnewvnode(VT_NON, NULL, spec_vnode_vops, &nvp, 0, 0);
746 vp->v_udev = dev->si_udev;
753 v_associate_rdev(struct vnode *vp, dev_t dev)
757 if (dev == NULL || dev == NODEV)
759 if (dev_is_good(dev) == 0)
761 KKASSERT(vp->v_rdev == NULL);
764 vp->v_rdev = reference_dev(dev);
765 lwkt_gettoken(&ilock, &spechash_token);
766 SLIST_INSERT_HEAD(&dev->si_hlist, vp, v_specnext);
767 lwkt_reltoken(&ilock);
772 v_release_rdev(struct vnode *vp)
777 if ((dev = vp->v_rdev) != NULL) {
778 lwkt_gettoken(&ilock, &spechash_token);
779 SLIST_REMOVE(&dev->si_hlist, vp, vnode, v_specnext);
780 if (dev_ref_debug && vp->v_opencount != 0) {
781 printf("releasing rdev with non-0 "
782 "v_opencount(%d) (revoked?)\n",
788 lwkt_reltoken(&ilock);
793 * Add a vnode to the alias list hung off the dev_t. We only associate
794 * the device number with the vnode. The actual device is not associated
795 * until the vnode is opened (usually in spec_open()), and will be
796 * disassociated on last close.
799 addaliasu(struct vnode *nvp, udev_t nvp_udev)
801 if (nvp->v_type != VBLK && nvp->v_type != VCHR)
802 panic("addaliasu on non-special vnode");
803 nvp->v_udev = nvp_udev;
807 * Disassociate a vnode from its underlying filesystem.
809 * The vnode must be VX locked and refd
811 * If there are v_usecount references to the vnode other then ours we have
812 * to VOP_CLOSE the vnode before we can deactivate and reclaim it.
815 vclean(struct vnode *vp, int flags, struct thread *td)
820 * If the vnode has already been reclaimed we have nothing to do.
822 if (vp->v_flag & VRECLAIMED)
824 vp->v_flag |= VRECLAIMED;
827 * Scrap the vfs cache
829 cache_inval_vp(vp, CINV_SELF);
832 * Check to see if the vnode is in use. If so we have to reference it
833 * before we clean it out so that its count cannot fall to zero and
834 * generate a race against ourselves to recycle it.
836 active = (vp->v_usecount > 1);
839 * Clean out any buffers associated with the vnode and destroy its
840 * object, if it has one.
842 vinvalbuf(vp, V_SAVE, td, 0, 0);
843 VOP_DESTROYVOBJECT(vp);
846 * If purging an active vnode, it must be closed and
847 * deactivated before being reclaimed. XXX
849 * Note that neither of these routines unlocks the vnode.
853 VOP_CLOSE(vp, FNONBLOCK, td);
857 * If the vnode has not be deactivated, deactivated it.
859 if ((vp->v_flag & VINACTIVE) == 0) {
860 vp->v_flag |= VINACTIVE;
861 VOP_INACTIVE(vp, td);
867 if (VOP_RECLAIM(vp, td))
868 panic("vclean: cannot reclaim");
871 * Done with purge, notify sleepers of the grim news.
873 vp->v_ops = dead_vnode_vops;
879 * Eliminate all activity associated with the requested vnode
880 * and with all vnodes aliased to the requested vnode.
882 * The vnode must be referenced and vx_lock()'d
884 * revoke { struct vnode *a_vp, int a_flags }
887 vop_stdrevoke(struct vop_revoke_args *ap)
889 struct vnode *vp, *vq;
893 KASSERT((ap->a_flags & REVOKEALL) != 0, ("vop_revoke"));
898 * If the vnode is already dead don't try to revoke it
900 if (vp->v_flag & VRECLAIMED)
904 * If the vnode has a device association, scrap all vnodes associated
905 * with the device. Don't let the device disappear on us while we
906 * are scrapping the vnodes.
908 * The passed vp will probably show up in the list, do not VX lock
911 if (vp->v_type != VCHR && vp->v_type != VBLK)
913 if ((dev = vp->v_rdev) == NULL) {
914 if ((dev = udev2dev(vp->v_udev, vp->v_type == VBLK)) == NODEV)
918 lwkt_gettoken(&ilock, &spechash_token);
919 while ((vq = SLIST_FIRST(&dev->si_hlist)) != NULL) {
920 if (vp == vq || vx_get(vq) == 0) {
921 if (vq == SLIST_FIRST(&dev->si_hlist))
927 lwkt_reltoken(&ilock);
933 * Recycle an unused vnode to the front of the free list.
935 * Returns 1 if we were successfully able to recycle the vnode,
939 vrecycle(struct vnode *vp, struct thread *td)
941 if (vp->v_usecount == 1) {
949 * Eliminate all activity associated with a vnode in preparation for reuse.
951 * The vnode must be VX locked and refd and will remain VX locked and refd
952 * on return. This routine may be called with the vnode in any state, as
953 * long as it is VX locked. The vnode will be cleaned out and marked
954 * VRECLAIMED but will not actually be reused until all existing refs and
957 * NOTE: This routine may be called on a vnode which has not yet been
958 * already been deactivated (VOP_INACTIVE), or on a vnode which has
959 * already been reclaimed.
961 * This routine is not responsible for placing us back on the freelist.
962 * Instead, it happens automatically when the caller releases the VX lock
963 * (assuming there aren't any other references).
966 vgone(struct vnode *vp)
969 * assert that the VX lock is held. This is an absolute requirement
970 * now for vgone() to be called.
972 KKASSERT(vp->v_lock.lk_exclusivecount == 1);
975 * Clean out the filesystem specific data and set the VRECLAIMED
976 * bit. Also deactivate the vnode if necessary.
978 vclean(vp, DOCLOSE, curthread);
981 * Delete from old mount point vnode list, if on one.
983 if (vp->v_mount != NULL)
987 * If special device, remove it from special device alias list
988 * if it is on one. This should normally only occur if a vnode is
989 * being revoked as the device should otherwise have been released
992 if ((vp->v_type == VBLK || vp->v_type == VCHR) && vp->v_rdev != NULL) {
1003 * Lookup a vnode by device number.
1006 vfinddev(dev_t dev, enum vtype type, struct vnode **vpp)
1011 lwkt_gettoken(&ilock, &spechash_token);
1012 SLIST_FOREACH(vp, &dev->si_hlist, v_specnext) {
1013 if (type == vp->v_type) {
1015 lwkt_reltoken(&ilock);
1019 lwkt_reltoken(&ilock);
1024 * Calculate the total number of references to a special device. This
1025 * routine may only be called for VBLK and VCHR vnodes since v_rdev is
1026 * an overloaded field. Since udev2dev can now return NODEV, we have
1027 * to check for a NULL v_rdev.
1030 count_dev(dev_t dev)
1036 if (SLIST_FIRST(&dev->si_hlist)) {
1037 lwkt_gettoken(&ilock, &spechash_token);
1038 SLIST_FOREACH(vp, &dev->si_hlist, v_specnext) {
1039 count += vp->v_usecount;
1041 lwkt_reltoken(&ilock);
1047 count_udev(udev_t udev)
1051 if ((dev = udev2dev(udev, 0)) == NODEV)
1053 return(count_dev(dev));
1057 vcount(struct vnode *vp)
1059 if (vp->v_rdev == NULL)
1061 return(count_dev(vp->v_rdev));
1065 * Print out a description of a vnode.
1067 static char *typename[] =
1068 {"VNON", "VREG", "VDIR", "VBLK", "VCHR", "VLNK", "VSOCK", "VFIFO", "VBAD"};
1071 vprint(char *label, struct vnode *vp)
1076 printf("%s: %p: ", label, (void *)vp);
1078 printf("%p: ", (void *)vp);
1079 printf("type %s, usecount %d, writecount %d, refcount %d,",
1080 typename[vp->v_type], vp->v_usecount, vp->v_writecount,
1083 if (vp->v_flag & VROOT)
1084 strcat(buf, "|VROOT");
1085 if (vp->v_flag & VTEXT)
1086 strcat(buf, "|VTEXT");
1087 if (vp->v_flag & VSYSTEM)
1088 strcat(buf, "|VSYSTEM");
1089 if (vp->v_flag & VBWAIT)
1090 strcat(buf, "|VBWAIT");
1091 if (vp->v_flag & VFREE)
1092 strcat(buf, "|VFREE");
1093 if (vp->v_flag & VOBJBUF)
1094 strcat(buf, "|VOBJBUF");
1096 printf(" flags (%s)", &buf[1]);
1097 if (vp->v_data == NULL) {
1106 #include <ddb/ddb.h>
1108 * List all of the locked vnodes in the system.
1109 * Called when debugging the kernel.
1111 DB_SHOW_COMMAND(lockedvnodes, lockedvnodes)
1113 struct thread *td = curthread; /* XXX */
1115 struct mount *mp, *nmp;
1118 printf("Locked vnodes\n");
1119 lwkt_gettoken(&ilock, &mountlist_token);
1120 for (mp = TAILQ_FIRST(&mountlist); mp != NULL; mp = nmp) {
1121 if (vfs_busy(mp, LK_NOWAIT, &ilock, td)) {
1122 nmp = TAILQ_NEXT(mp, mnt_list);
1125 TAILQ_FOREACH(vp, &mp->mnt_nvnodelist, v_nmntvnodes) {
1126 if (VOP_ISLOCKED(vp, NULL))
1127 vprint((char *)0, vp);
1129 lwkt_gettokref(&ilock);
1130 nmp = TAILQ_NEXT(mp, mnt_list);
1133 lwkt_reltoken(&ilock);
1138 * Top level filesystem related information gathering.
1140 static int sysctl_ovfs_conf (SYSCTL_HANDLER_ARGS);
1143 vfs_sysctl(SYSCTL_HANDLER_ARGS)
1145 int *name = (int *)arg1 - 1; /* XXX */
1146 u_int namelen = arg2 + 1; /* XXX */
1147 struct vfsconf *vfsp;
1149 #if 1 || defined(COMPAT_PRELITE2)
1150 /* Resolve ambiguity between VFS_VFSCONF and VFS_GENERIC. */
1152 return (sysctl_ovfs_conf(oidp, arg1, arg2, req));
1156 /* all sysctl names at this level are at least name and field */
1158 return (ENOTDIR); /* overloaded */
1159 if (name[0] != VFS_GENERIC) {
1160 for (vfsp = vfsconf; vfsp; vfsp = vfsp->vfc_next)
1161 if (vfsp->vfc_typenum == name[0])
1164 return (EOPNOTSUPP);
1165 return ((*vfsp->vfc_vfsops->vfs_sysctl)(&name[1], namelen - 1,
1166 oldp, oldlenp, newp, newlen, p));
1170 case VFS_MAXTYPENUM:
1173 return (SYSCTL_OUT(req, &maxvfsconf, sizeof(int)));
1176 return (ENOTDIR); /* overloaded */
1177 for (vfsp = vfsconf; vfsp; vfsp = vfsp->vfc_next)
1178 if (vfsp->vfc_typenum == name[2])
1181 return (EOPNOTSUPP);
1182 return (SYSCTL_OUT(req, vfsp, sizeof *vfsp));
1184 return (EOPNOTSUPP);
1187 SYSCTL_NODE(_vfs, VFS_GENERIC, generic, CTLFLAG_RD, vfs_sysctl,
1188 "Generic filesystem");
1190 #if 1 || defined(COMPAT_PRELITE2)
1193 sysctl_ovfs_conf(SYSCTL_HANDLER_ARGS)
1196 struct vfsconf *vfsp;
1197 struct ovfsconf ovfs;
1199 for (vfsp = vfsconf; vfsp; vfsp = vfsp->vfc_next) {
1200 ovfs.vfc_vfsops = vfsp->vfc_vfsops; /* XXX used as flag */
1201 strcpy(ovfs.vfc_name, vfsp->vfc_name);
1202 ovfs.vfc_index = vfsp->vfc_typenum;
1203 ovfs.vfc_refcount = vfsp->vfc_refcount;
1204 ovfs.vfc_flags = vfsp->vfc_flags;
1205 error = SYSCTL_OUT(req, &ovfs, sizeof ovfs);
1212 #endif /* 1 || COMPAT_PRELITE2 */
1215 #define KINFO_VNODESLOP 10
1217 * Dump vnode list (via sysctl).
1218 * Copyout address of vnode followed by vnode.
1222 sysctl_vnode(SYSCTL_HANDLER_ARGS)
1224 struct proc *p = curproc; /* XXX */
1225 struct mount *mp, *nmp;
1226 struct vnode *nvp, *vp;
1231 #define VPTRSZ sizeof (struct vnode *)
1232 #define VNODESZ sizeof (struct vnode)
1235 if (!req->oldptr) /* Make an estimate */
1236 return (SYSCTL_OUT(req, 0,
1237 (numvnodes + KINFO_VNODESLOP) * (VPTRSZ + VNODESZ)));
1239 lwkt_gettoken(&ilock, &mountlist_token);
1240 for (mp = TAILQ_FIRST(&mountlist); mp != NULL; mp = nmp) {
1241 if (vfs_busy(mp, LK_NOWAIT, &ilock, p)) {
1242 nmp = TAILQ_NEXT(mp, mnt_list);
1245 lwkt_gettoken(&jlock, &mntvnode_token);
1247 for (vp = TAILQ_FIRST(&mp->mnt_nvnodelist);
1251 * Check that the vp is still associated with
1252 * this filesystem. RACE: could have been
1253 * recycled onto the same filesystem.
1255 if (vp->v_mount != mp)
1257 nvp = TAILQ_NEXT(vp, v_nmntvnodes);
1258 if ((error = SYSCTL_OUT(req, &vp, VPTRSZ)) ||
1259 (error = SYSCTL_OUT(req, vp, VNODESZ))) {
1260 lwkt_reltoken(&jlock);
1264 lwkt_reltoken(&jlock);
1265 lwkt_gettokref(&ilock);
1266 nmp = TAILQ_NEXT(mp, mnt_list); /* ZZZ */
1269 lwkt_reltoken(&ilock);
1277 * Exporting the vnode list on large systems causes them to crash.
1278 * Exporting the vnode list on medium systems causes sysctl to coredump.
1281 SYSCTL_PROC(_kern, KERN_VNODE, vnode, CTLTYPE_OPAQUE|CTLFLAG_RD,
1282 0, 0, sysctl_vnode, "S,vnode", "");
1286 * Check to see if a filesystem is mounted on a block device.
1289 vfs_mountedon(struct vnode *vp)
1293 if ((dev = vp->v_rdev) == NULL)
1294 dev = udev2dev(vp->v_udev, (vp->v_type == VBLK));
1295 if (dev != NODEV && dev->si_mountpoint)
1301 * Unmount all filesystems. The list is traversed in reverse order
1302 * of mounting to avoid dependencies.
1305 vfs_unmountall(void)
1308 struct thread *td = curthread;
1311 if (td->td_proc == NULL)
1312 td = initproc->p_thread; /* XXX XXX use proc0 instead? */
1315 * Since this only runs when rebooting, it is not interlocked.
1317 while(!TAILQ_EMPTY(&mountlist)) {
1318 mp = TAILQ_LAST(&mountlist, mntlist);
1319 error = dounmount(mp, MNT_FORCE, td);
1321 TAILQ_REMOVE(&mountlist, mp, mnt_list);
1322 printf("unmount of %s failed (",
1323 mp->mnt_stat.f_mntonname);
1327 printf("%d)\n", error);
1329 /* The unmount has removed mp from the mountlist */
1335 * Build hash lists of net addresses and hang them off the mount point.
1336 * Called by ufs_mount() to set up the lists of export addresses.
1339 vfs_hang_addrlist(struct mount *mp, struct netexport *nep,
1340 struct export_args *argp)
1343 struct radix_node_head *rnh;
1345 struct radix_node *rn;
1346 struct sockaddr *saddr, *smask = 0;
1350 if (argp->ex_addrlen == 0) {
1351 if (mp->mnt_flag & MNT_DEFEXPORTED)
1353 np = &nep->ne_defexported;
1354 np->netc_exflags = argp->ex_flags;
1355 np->netc_anon = argp->ex_anon;
1356 np->netc_anon.cr_ref = 1;
1357 mp->mnt_flag |= MNT_DEFEXPORTED;
1361 if (argp->ex_addrlen < 0 || argp->ex_addrlen > MLEN)
1363 if (argp->ex_masklen < 0 || argp->ex_masklen > MLEN)
1366 i = sizeof(struct netcred) + argp->ex_addrlen + argp->ex_masklen;
1367 np = (struct netcred *) malloc(i, M_NETADDR, M_WAITOK);
1368 bzero((caddr_t) np, i);
1369 saddr = (struct sockaddr *) (np + 1);
1370 if ((error = copyin(argp->ex_addr, (caddr_t) saddr, argp->ex_addrlen)))
1372 if (saddr->sa_len > argp->ex_addrlen)
1373 saddr->sa_len = argp->ex_addrlen;
1374 if (argp->ex_masklen) {
1375 smask = (struct sockaddr *)((caddr_t)saddr + argp->ex_addrlen);
1376 error = copyin(argp->ex_mask, (caddr_t)smask, argp->ex_masklen);
1379 if (smask->sa_len > argp->ex_masklen)
1380 smask->sa_len = argp->ex_masklen;
1382 i = saddr->sa_family;
1383 if ((rnh = nep->ne_rtable[i]) == 0) {
1385 * Seems silly to initialize every AF when most are not used,
1386 * do so on demand here
1388 for (dom = domains; dom; dom = dom->dom_next)
1389 if (dom->dom_family == i && dom->dom_rtattach) {
1390 dom->dom_rtattach((void **) &nep->ne_rtable[i],
1394 if ((rnh = nep->ne_rtable[i]) == 0) {
1399 rn = (*rnh->rnh_addaddr) ((caddr_t) saddr, (caddr_t) smask, rnh,
1401 if (rn == 0 || np != (struct netcred *) rn) { /* already exists */
1405 np->netc_exflags = argp->ex_flags;
1406 np->netc_anon = argp->ex_anon;
1407 np->netc_anon.cr_ref = 1;
1410 free(np, M_NETADDR);
1416 vfs_free_netcred(struct radix_node *rn, void *w)
1418 struct radix_node_head *rnh = (struct radix_node_head *) w;
1420 (*rnh->rnh_deladdr) (rn->rn_key, rn->rn_mask, rnh);
1421 free((caddr_t) rn, M_NETADDR);
1426 * Free the net address hash lists that are hanging off the mount points.
1429 vfs_free_addrlist(struct netexport *nep)
1432 struct radix_node_head *rnh;
1434 for (i = 0; i <= AF_MAX; i++)
1435 if ((rnh = nep->ne_rtable[i])) {
1436 (*rnh->rnh_walktree) (rnh, vfs_free_netcred,
1438 free((caddr_t) rnh, M_RTABLE);
1439 nep->ne_rtable[i] = 0;
1444 vfs_export(struct mount *mp, struct netexport *nep, struct export_args *argp)
1448 if (argp->ex_flags & MNT_DELEXPORT) {
1449 if (mp->mnt_flag & MNT_EXPUBLIC) {
1450 vfs_setpublicfs(NULL, NULL, NULL);
1451 mp->mnt_flag &= ~MNT_EXPUBLIC;
1453 vfs_free_addrlist(nep);
1454 mp->mnt_flag &= ~(MNT_EXPORTED | MNT_DEFEXPORTED);
1456 if (argp->ex_flags & MNT_EXPORTED) {
1457 if (argp->ex_flags & MNT_EXPUBLIC) {
1458 if ((error = vfs_setpublicfs(mp, nep, argp)) != 0)
1460 mp->mnt_flag |= MNT_EXPUBLIC;
1462 if ((error = vfs_hang_addrlist(mp, nep, argp)))
1464 mp->mnt_flag |= MNT_EXPORTED;
1471 * Set the publicly exported filesystem (WebNFS). Currently, only
1472 * one public filesystem is possible in the spec (RFC 2054 and 2055)
1475 vfs_setpublicfs(struct mount *mp, struct netexport *nep,
1476 struct export_args *argp)
1483 * mp == NULL -> invalidate the current info, the FS is
1484 * no longer exported. May be called from either vfs_export
1485 * or unmount, so check if it hasn't already been done.
1488 if (nfs_pub.np_valid) {
1489 nfs_pub.np_valid = 0;
1490 if (nfs_pub.np_index != NULL) {
1491 FREE(nfs_pub.np_index, M_TEMP);
1492 nfs_pub.np_index = NULL;
1499 * Only one allowed at a time.
1501 if (nfs_pub.np_valid != 0 && mp != nfs_pub.np_mount)
1505 * Get real filehandle for root of exported FS.
1507 bzero((caddr_t)&nfs_pub.np_handle, sizeof(nfs_pub.np_handle));
1508 nfs_pub.np_handle.fh_fsid = mp->mnt_stat.f_fsid;
1510 if ((error = VFS_ROOT(mp, &rvp)))
1513 if ((error = VFS_VPTOFH(rvp, &nfs_pub.np_handle.fh_fid)))
1519 * If an indexfile was specified, pull it in.
1521 if (argp->ex_indexfile != NULL) {
1522 MALLOC(nfs_pub.np_index, char *, MAXNAMLEN + 1, M_TEMP,
1524 error = copyinstr(argp->ex_indexfile, nfs_pub.np_index,
1525 MAXNAMLEN, (size_t *)0);
1528 * Check for illegal filenames.
1530 for (cp = nfs_pub.np_index; *cp; cp++) {
1538 FREE(nfs_pub.np_index, M_TEMP);
1543 nfs_pub.np_mount = mp;
1544 nfs_pub.np_valid = 1;
1549 vfs_export_lookup(struct mount *mp, struct netexport *nep,
1550 struct sockaddr *nam)
1553 struct radix_node_head *rnh;
1554 struct sockaddr *saddr;
1557 if (mp->mnt_flag & MNT_EXPORTED) {
1559 * Lookup in the export list first.
1563 rnh = nep->ne_rtable[saddr->sa_family];
1565 np = (struct netcred *)
1566 (*rnh->rnh_matchaddr)((caddr_t)saddr,
1568 if (np && np->netc_rnodes->rn_flags & RNF_ROOT)
1573 * If no address match, use the default if it exists.
1575 if (np == NULL && mp->mnt_flag & MNT_DEFEXPORTED)
1576 np = &nep->ne_defexported;
1582 * perform msync on all vnodes under a mount point. The mount point must
1583 * be locked. This code is also responsible for lazy-freeing unreferenced
1584 * vnodes whos VM objects no longer contain pages.
1586 * NOTE: MNT_WAIT still skips vnodes in the VXLOCK state.
1588 static int vfs_msync_scan1(struct mount *mp, struct vnode *vp, void *data);
1589 static int vfs_msync_scan2(struct mount *mp, struct vnode *vp, void *data);
1592 vfs_msync(struct mount *mp, int flags)
1594 vmntvnodescan(mp, VMSC_REFVP, vfs_msync_scan1, vfs_msync_scan2,
1599 * scan1 is a fast pre-check. There could be hundreds of thousands of
1600 * vnodes, we cannot afford to do anything heavy weight until we have a
1601 * fairly good indication that there is work to do.
1605 vfs_msync_scan1(struct mount *mp, struct vnode *vp, void *data)
1607 int flags = (int)data;
1609 if ((vp->v_flag & VRECLAIMED) == 0) {
1610 if (vshouldfree(vp, 0))
1611 return(0); /* call scan2 */
1612 if ((mp->mnt_flag & MNT_RDONLY) == 0 &&
1613 (vp->v_flag & VOBJDIRTY) &&
1614 (flags == MNT_WAIT || VOP_ISLOCKED(vp, NULL) == 0)) {
1615 return(0); /* call scan2 */
1620 * do not call scan2, continue the loop
1627 vfs_msync_scan2(struct mount *mp, struct vnode *vp, void *data)
1630 int flags = (int)data;
1632 if (vp->v_flag & VRECLAIMED)
1635 if ((mp->mnt_flag & MNT_RDONLY) == 0 &&
1636 (vp->v_flag & VOBJDIRTY) &&
1637 (flags == MNT_WAIT || VOP_ISLOCKED(vp, NULL) == 0)) {
1638 if (VOP_GETVOBJECT(vp, &obj) == 0) {
1639 vm_object_page_clean(obj, 0, 0,
1640 flags == MNT_WAIT ? OBJPC_SYNC : OBJPC_NOSYNC);
1647 * Create the VM object needed for VMIO and mmap support. This
1648 * is done for all VREG files in the system. Some filesystems might
1649 * afford the additional metadata buffering capability of the
1650 * VMIO code by making the device node be VMIO mode also.
1652 * vp must be locked when vfs_object_create is called.
1655 vfs_object_create(struct vnode *vp, struct thread *td)
1657 return (VOP_CREATEVOBJECT(vp, td));
1661 * Record a process's interest in events which might happen to
1662 * a vnode. Because poll uses the historic select-style interface
1663 * internally, this routine serves as both the ``check for any
1664 * pending events'' and the ``record my interest in future events''
1665 * functions. (These are done together, while the lock is held,
1666 * to avoid race conditions.)
1669 vn_pollrecord(struct vnode *vp, struct thread *td, int events)
1673 lwkt_gettoken(&ilock, &vp->v_pollinfo.vpi_token);
1674 if (vp->v_pollinfo.vpi_revents & events) {
1676 * This leaves events we are not interested
1677 * in available for the other process which
1678 * which presumably had requested them
1679 * (otherwise they would never have been
1682 events &= vp->v_pollinfo.vpi_revents;
1683 vp->v_pollinfo.vpi_revents &= ~events;
1685 lwkt_reltoken(&ilock);
1688 vp->v_pollinfo.vpi_events |= events;
1689 selrecord(td, &vp->v_pollinfo.vpi_selinfo);
1690 lwkt_reltoken(&ilock);
1695 * Note the occurrence of an event. If the VN_POLLEVENT macro is used,
1696 * it is possible for us to miss an event due to race conditions, but
1697 * that condition is expected to be rare, so for the moment it is the
1698 * preferred interface.
1701 vn_pollevent(struct vnode *vp, int events)
1705 lwkt_gettoken(&ilock, &vp->v_pollinfo.vpi_token);
1706 if (vp->v_pollinfo.vpi_events & events) {
1708 * We clear vpi_events so that we don't
1709 * call selwakeup() twice if two events are
1710 * posted before the polling process(es) is
1711 * awakened. This also ensures that we take at
1712 * most one selwakeup() if the polling process
1713 * is no longer interested. However, it does
1714 * mean that only one event can be noticed at
1715 * a time. (Perhaps we should only clear those
1716 * event bits which we note?) XXX
1718 vp->v_pollinfo.vpi_events = 0; /* &= ~events ??? */
1719 vp->v_pollinfo.vpi_revents |= events;
1720 selwakeup(&vp->v_pollinfo.vpi_selinfo);
1722 lwkt_reltoken(&ilock);
1726 * Wake up anyone polling on vp because it is being revoked.
1727 * This depends on dead_poll() returning POLLHUP for correct
1731 vn_pollgone(struct vnode *vp)
1735 lwkt_gettoken(&ilock, &vp->v_pollinfo.vpi_token);
1736 if (vp->v_pollinfo.vpi_events) {
1737 vp->v_pollinfo.vpi_events = 0;
1738 selwakeup(&vp->v_pollinfo.vpi_selinfo);
1740 lwkt_reltoken(&ilock);
1744 * extract the dev_t from a VBLK or VCHR. The vnode must have been opened
1745 * (or v_rdev might be NULL).
1748 vn_todev(struct vnode *vp)
1750 if (vp->v_type != VBLK && vp->v_type != VCHR)
1752 KKASSERT(vp->v_rdev != NULL);
1753 return (vp->v_rdev);
1757 * Check if vnode represents a disk device. The vnode does not need to be
1761 vn_isdisk(struct vnode *vp, int *errp)
1765 if (vp->v_type != VBLK && vp->v_type != VCHR) {
1771 if ((dev = vp->v_rdev) == NULL)
1772 dev = udev2dev(vp->v_udev, (vp->v_type == VBLK));
1773 if (dev == NULL || dev == NODEV) {
1778 if (dev_is_good(dev) == 0) {
1783 if ((dev_dflags(dev) & D_DISK) == 0) {
1794 NDFREE(struct nameidata *ndp, const uint flags)
1796 if (!(flags & NDF_NO_FREE_PNBUF) &&
1797 (ndp->ni_cnd.cn_flags & CNP_HASBUF)) {
1798 zfree(namei_zone, ndp->ni_cnd.cn_pnbuf);
1799 ndp->ni_cnd.cn_flags &= ~CNP_HASBUF;
1801 if (!(flags & NDF_NO_DVP_UNLOCK) &&
1802 (ndp->ni_cnd.cn_flags & CNP_LOCKPARENT) &&
1803 ndp->ni_dvp != ndp->ni_vp) {
1804 VOP_UNLOCK(ndp->ni_dvp, 0, ndp->ni_cnd.cn_td);
1806 if (!(flags & NDF_NO_DVP_RELE) &&
1807 (ndp->ni_cnd.cn_flags & (CNP_LOCKPARENT|CNP_WANTPARENT))) {
1811 if (!(flags & NDF_NO_VP_UNLOCK) &&
1812 (ndp->ni_cnd.cn_flags & CNP_LOCKLEAF) && ndp->ni_vp) {
1813 VOP_UNLOCK(ndp->ni_vp, 0, ndp->ni_cnd.cn_td);
1815 if (!(flags & NDF_NO_VP_RELE) &&
1820 if (!(flags & NDF_NO_STARTDIR_RELE) &&
1821 (ndp->ni_cnd.cn_flags & CNP_SAVESTART)) {
1822 vrele(ndp->ni_startdir);
1823 ndp->ni_startdir = NULL;
1827 #ifdef DEBUG_VFS_LOCKS
1830 assert_vop_locked(struct vnode *vp, const char *str)
1832 if (vp && IS_LOCKING_VFS(vp) && !VOP_ISLOCKED(vp, NULL)) {
1833 panic("%s: %p is not locked shared but should be", str, vp);
1838 assert_vop_unlocked(struct vnode *vp, const char *str)
1840 if (vp && IS_LOCKING_VFS(vp)) {
1841 if (VOP_ISLOCKED(vp, curthread) == LK_EXCLUSIVE) {
1842 panic("%s: %p is locked but should not be", str, vp);