2 * Copyright (c) 2000-2001 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
22 /* Copyright (c) 1995 NeXT Computer, Inc. All Rights Reserved */
24 * Copyright (c) 1989, 1993
25 * The Regents of the University of California. All rights reserved.
26 * (c) UNIX System Laboratories, Inc.
27 * All or some portions of this file are derived from material licensed
28 * to the University of California by American Telephone and Telegraph
29 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
30 * the permission of UNIX System Laboratories, Inc.
32 * Redistribution and use in source and binary forms, with or without
33 * modification, are permitted provided that the following conditions
35 * 1. Redistributions of source code must retain the above copyright
36 * notice, this list of conditions and the following disclaimer.
37 * 2. Redistributions in binary form must reproduce the above copyright
38 * notice, this list of conditions and the following disclaimer in the
39 * documentation and/or other materials provided with the distribution.
40 * 3. All advertising materials mentioning features or use of this software
41 * must display the following acknowledgement:
42 * This product includes software developed by the University of
43 * California, Berkeley and its contributors.
44 * 4. Neither the name of the University nor the names of its contributors
45 * may be used to endorse or promote products derived from this software
46 * without specific prior written permission.
48 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
49 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
50 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
51 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
52 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
53 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
54 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
55 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
56 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
57 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
60 * @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95
64 * External virtual filesystem routines
70 #include <sys/param.h>
71 #include <sys/systm.h>
73 #include <sys/mount.h>
75 #include <sys/vnode.h>
77 #include <sys/namei.h>
78 #include <sys/ucred.h>
80 #include <sys/errno.h>
81 #include <sys/malloc.h>
82 #include <sys/domain.h>
84 #include <sys/syslog.h>
87 #include <sys/sysctl.h>
89 #include <kern/assert.h>
91 #include <miscfs/specfs/specdev.h>
93 #include <mach/mach_types.h>
94 #include <mach/memory_object_types.h>
97 enum vtype iftovt_tab
[16] = {
98 VNON
, VFIFO
, VCHR
, VNON
, VDIR
, VNON
, VBLK
, VNON
,
99 VREG
, VNON
, VLNK
, VNON
, VSOCK
, VNON
, VNON
, VBAD
,
101 int vttoif_tab
[9] = {
102 0, S_IFREG
, S_IFDIR
, S_IFBLK
, S_IFCHR
, S_IFLNK
,
103 S_IFSOCK
, S_IFIFO
, S_IFMT
,
106 static void vfree(struct vnode
*vp
);
107 static void vinactive(struct vnode
*vp
);
108 static int vnreclaim(int count
);
110 adjust_vm_object_cache(vm_size_t oval
, vm_size_t nval
);
112 TAILQ_HEAD(freelst
, vnode
) vnode_free_list
; /* vnode free list */
113 TAILQ_HEAD(inactivelst
, vnode
) vnode_inactive_list
; /* vnode inactive list */
114 struct mntlist mountlist
; /* mounted filesystem list */
117 #define VLISTCHECK(fun, vp, list) \
118 if ((vp)->v_freelist.tqe_prev == (struct vnode **)0xdeadb) \
119 panic("%s: %s vnode not on %slist", (fun), (list), (list));
121 #define VINACTIVECHECK(fun, vp, expected) \
123 int __is_inactive = ISSET((vp)->v_flag, VUINACTIVE); \
124 if (__is_inactive ^ expected) \
125 panic("%s: %sinactive vnode, expected %s", (fun), \
126 __is_inactive? "" : "not ", \
127 expected? "inactive": "not inactive"); \
130 #define VLISTCHECK(fun, vp, list)
131 #define VINACTIVECHECK(fun, vp, expected)
132 #endif /* DIAGNOSTIC */
134 #define VLISTNONE(vp) \
136 (vp)->v_freelist.tqe_next = (struct vnode *)0; \
137 (vp)->v_freelist.tqe_prev = (struct vnode **)0xdeadb; \
140 #define VONLIST(vp) \
141 ((vp)->v_freelist.tqe_prev != (struct vnode **)0xdeadb)
143 /* remove a vnode from free vnode list */
144 #define VREMFREE(fun, vp) \
146 VLISTCHECK((fun), (vp), "free"); \
147 TAILQ_REMOVE(&vnode_free_list, (vp), v_freelist); \
152 /* remove a vnode from inactive vnode list */
153 #define VREMINACTIVE(fun, vp) \
155 VLISTCHECK((fun), (vp), "inactive"); \
156 VINACTIVECHECK((fun), (vp), VUINACTIVE); \
157 TAILQ_REMOVE(&vnode_inactive_list, (vp), v_freelist); \
158 CLR((vp)->v_flag, VUINACTIVE); \
163 #define VORECLAIM_ENABLE(vp) \
165 if (ISSET((vp)->v_flag, VORECLAIM)) \
166 panic("vm object raclaim already"); \
167 SET((vp)->v_flag, VORECLAIM); \
170 #define VORECLAIM_DISABLE(vp) \
172 CLR((vp)->v_flag, VORECLAIM); \
173 if (ISSET((vp)->v_flag, VXWANT)) { \
174 CLR((vp)->v_flag, VXWANT); \
175 wakeup((caddr_t)(vp)); \
180 * Have to declare first two locks as actual data even if !MACH_SLOCKS, since
181 * a pointers to them get passed around.
183 simple_lock_data_t mountlist_slock
;
184 simple_lock_data_t mntvnode_slock
;
185 decl_simple_lock_data(,mntid_slock
);
186 decl_simple_lock_data(,vnode_free_list_slock
);
187 decl_simple_lock_data(,spechash_slock
);
190 * vnodetarget is the amount of vnodes we expect to get back
191 * from the the inactive vnode list and VM object cache.
192 * As vnreclaim() is a mainly cpu bound operation for faster
193 * processers this number could be higher.
194 * Having this number too high introduces longer delays in
195 * the execution of getnewvnode().
197 unsigned long vnodetarget
; /* target for vnreclaim() */
198 #define VNODE_FREE_TARGET 20 /* Default value for vnodetarget */
201 * We need quite a few vnodes on the free list to sustain the
202 * rapid stat() the compilation process does, and still benefit from the name
203 * cache. Having too few vnodes on the free list causes serious disk
204 * thrashing as we cycle through them.
206 #define VNODE_FREE_MIN 300 /* freelist should have at least these many */
209 * We need to get vnodes back from the VM object cache when a certain #
210 * of vnodes are reused from the freelist. This is essential for the
211 * caching to be effective in the namecache and the buffer cache [for the
214 #define VNODE_TOOMANY_REUSED (VNODE_FREE_MIN/4)
217 * If we have enough vnodes on the freelist we do not want to reclaim
218 * the vnodes from the VM object cache.
220 #define VNODE_FREE_ENOUGH (VNODE_FREE_MIN + (VNODE_FREE_MIN/2))
223 * Initialize the vnode management data structures.
225 __private_extern__
void
228 extern struct lock__bsd__ exchangelock
;
230 simple_lock_init(&mountlist_slock
);
231 simple_lock_init(&mntvnode_slock
);
232 simple_lock_init(&mntid_slock
);
233 simple_lock_init(&spechash_slock
);
234 TAILQ_INIT(&vnode_free_list
);
235 simple_lock_init(&vnode_free_list_slock
);
236 TAILQ_INIT(&vnode_inactive_list
);
237 CIRCLEQ_INIT(&mountlist
);
238 lockinit(&exchangelock
, PVFS
, "exchange", 0, 0);
241 vnodetarget
= VNODE_FREE_TARGET
;
244 * Scale the vm_object_cache to accomodate the vnodes
247 (void) adjust_vm_object_cache(0, desiredvnodes
- VNODE_FREE_MIN
);
250 /* Reset the VM Object Cache with the values passed in */
251 __private_extern__ kern_return_t
252 reset_vmobjectcache(unsigned int val1
, unsigned int val2
)
254 vm_size_t oval
= val1
- VNODE_FREE_MIN
;
257 if(val2
< VNODE_FREE_MIN
)
260 nval
= val2
- VNODE_FREE_MIN
;
262 return(adjust_vm_object_cache(oval
, nval
));
266 * Mark a mount point as busy. Used to synchronize access and to delay
267 * unmounting. Interlock is not released on failure.
270 vfs_busy(mp
, flags
, interlkp
, p
)
273 struct slock
*interlkp
;
278 if (mp
->mnt_kern_flag
& MNTK_UNMOUNT
) {
279 if (flags
& LK_NOWAIT
)
281 mp
->mnt_kern_flag
|= MNTK_MWAIT
;
283 simple_unlock(interlkp
);
285 * Since all busy locks are shared except the exclusive
286 * lock granted when unmounting, the only place that a
287 * wakeup needs to be done is at the release of the
288 * exclusive lock at the end of dounmount.
290 sleep((caddr_t
)mp
, PVFS
);
292 simple_lock(interlkp
);
297 lkflags
|= LK_INTERLOCK
;
298 if (lockmgr(&mp
->mnt_lock
, lkflags
, interlkp
, p
))
299 panic("vfs_busy: unexpected lock failure");
304 * Free a busy filesystem.
312 lockmgr(&mp
->mnt_lock
, LK_RELEASE
, NULL
, p
);
316 * Lookup a filesystem type, and if found allocate and initialize
317 * a mount structure for it.
319 * Devname is usually updated by mount(8) after booting.
322 vfs_rootmountalloc(fstypename
, devname
, mpp
)
327 struct proc
*p
= current_proc(); /* XXX */
328 struct vfsconf
*vfsp
;
331 for (vfsp
= vfsconf
; vfsp
; vfsp
= vfsp
->vfc_next
)
332 if (!strcmp(vfsp
->vfc_name
, fstypename
))
336 mp
= _MALLOC_ZONE((u_long
)sizeof(struct mount
), M_MOUNT
, M_WAITOK
);
337 bzero((char *)mp
, (u_long
)sizeof(struct mount
));
339 /* Initialize the default IO constraints */
340 mp
->mnt_maxreadcnt
= mp
->mnt_maxwritecnt
= MAXPHYS
;
341 mp
->mnt_segreadcnt
= mp
->mnt_segwritecnt
= 32;
343 lockinit(&mp
->mnt_lock
, PVFS
, "vfslock", 0, 0);
344 (void)vfs_busy(mp
, LK_NOWAIT
, 0, p
);
345 LIST_INIT(&mp
->mnt_vnodelist
);
347 mp
->mnt_op
= vfsp
->vfc_vfsops
;
348 mp
->mnt_flag
= MNT_RDONLY
;
349 mp
->mnt_vnodecovered
= NULLVP
;
350 vfsp
->vfc_refcount
++;
351 mp
->mnt_stat
.f_type
= vfsp
->vfc_typenum
;
352 mp
->mnt_flag
|= vfsp
->vfc_flags
& MNT_VISFLAGMASK
;
353 strncpy(mp
->mnt_stat
.f_fstypename
, vfsp
->vfc_name
, MFSNAMELEN
);
354 mp
->mnt_stat
.f_mntonname
[0] = '/';
355 (void) copystr(devname
, mp
->mnt_stat
.f_mntfromname
, MNAMELEN
- 1, 0);
361 * Find an appropriate filesystem to use for the root. If a filesystem
362 * has not been preselected, walk through the list of known filesystems
363 * trying those that have mountroot routines, and try them until one
364 * works or we have tried them all.
369 struct vfsconf
*vfsp
;
370 extern int (*mountroot
)(void);
373 if (mountroot
!= NULL
) {
374 error
= (*mountroot
)();
378 for (vfsp
= vfsconf
; vfsp
; vfsp
= vfsp
->vfc_next
) {
379 if (vfsp
->vfc_mountroot
== NULL
)
381 if ((error
= (*vfsp
->vfc_mountroot
)()) == 0)
384 printf("%s_mountroot failed: %d\n", vfsp
->vfc_name
, error
);
390 * Lookup a mount point by filesystem identifier.
396 register struct mount
*mp
;
398 simple_lock(&mountlist_slock
);
399 for (mp
= mountlist
.cqh_first
; mp
!= (void *)&mountlist
;
400 mp
= mp
->mnt_list
.cqe_next
) {
401 if (mp
->mnt_stat
.f_fsid
.val
[0] == fsid
->val
[0] &&
402 mp
->mnt_stat
.f_fsid
.val
[1] == fsid
->val
[1]) {
403 simple_unlock(&mountlist_slock
);
407 simple_unlock(&mountlist_slock
);
408 return ((struct mount
*)0);
412 * Get a new unique fsid
418 static u_short xxxfs_mntid
;
423 simple_lock(&mntid_slock
);
424 mtype
= mp
->mnt_vfc
->vfc_typenum
;
425 mp
->mnt_stat
.f_fsid
.val
[0] = makedev(nblkdev
+ mtype
, 0);
426 mp
->mnt_stat
.f_fsid
.val
[1] = mtype
;
427 if (xxxfs_mntid
== 0)
429 tfsid
.val
[0] = makedev(nblkdev
+ mtype
, xxxfs_mntid
);
430 tfsid
.val
[1] = mtype
;
431 if (mountlist
.cqh_first
!= (void *)&mountlist
) {
432 while (vfs_getvfs(&tfsid
)) {
437 mp
->mnt_stat
.f_fsid
.val
[0] = tfsid
.val
[0];
438 simple_unlock(&mntid_slock
);
442 * Set vnode attributes to VNOVAL
446 register struct vattr
*vap
;
450 vap
->va_size
= vap
->va_bytes
= VNOVAL
;
451 vap
->va_mode
= vap
->va_nlink
= vap
->va_uid
= vap
->va_gid
=
452 vap
->va_fsid
= vap
->va_fileid
=
453 vap
->va_blocksize
= vap
->va_rdev
=
454 vap
->va_atime
.tv_sec
= vap
->va_atime
.tv_nsec
=
455 vap
->va_mtime
.tv_sec
= vap
->va_mtime
.tv_nsec
=
456 vap
->va_ctime
.tv_sec
= vap
->va_ctime
.tv_nsec
=
457 vap
->va_flags
= vap
->va_gen
= VNOVAL
;
462 * Routines having to do with the management of the vnode table.
464 extern int (**dead_vnodeop_p
)(void *);
465 static void vclean
__P((struct vnode
*vp
, int flag
, struct proc
*p
));
466 extern void vgonel
__P((struct vnode
*vp
, struct proc
*p
));
467 long numvnodes
, freevnodes
;
469 long vnode_reclaim_tried
;
470 long vnode_objects_reclaimed
;
473 extern struct vattr va_null
;
476 * Return the next vnode from the free list.
479 getnewvnode(tag
, mp
, vops
, vpp
)
482 int (**vops
)(void *);
485 struct proc
*p
= current_proc(); /* XXX */
487 int cnt
, didretry
= 0;
488 static int reused
= 0; /* track the reuse rate */
492 simple_lock(&vnode_free_list_slock
);
494 * MALLOC a vnode if the number of vnodes has not reached the desired
495 * value and the number on the free list is still reasonable...
496 * reuse from the freelist even though we may evict a name cache entry
497 * to reduce the number of vnodes that accumulate.... vnodes tie up
498 * wired memory and are never garbage collected
500 if (numvnodes
< desiredvnodes
&& (freevnodes
< (2 * VNODE_FREE_MIN
))) {
502 simple_unlock(&vnode_free_list_slock
);
503 MALLOC_ZONE(vp
, struct vnode
*, sizeof *vp
, M_VNODE
, M_WAITOK
);
504 bzero((char *)vp
, sizeof *vp
);
505 VLISTNONE(vp
); /* avoid double queue removal */
506 simple_lock_init(&vp
->v_interlock
);
511 * Once the desired number of vnodes are allocated,
512 * we start reusing the vnodes.
514 if (freevnodes
< VNODE_FREE_MIN
) {
516 * if we are low on vnodes on the freelist attempt to get
517 * some back from the inactive list and VM object cache
519 simple_unlock(&vnode_free_list_slock
);
520 (void)vnreclaim(vnodetarget
);
521 simple_lock(&vnode_free_list_slock
);
523 if (numvnodes
>= desiredvnodes
&& reused
> VNODE_TOOMANY_REUSED
) {
525 if (freevnodes
< VNODE_FREE_ENOUGH
) {
526 simple_unlock(&vnode_free_list_slock
);
527 (void)vnreclaim(vnodetarget
);
528 simple_lock(&vnode_free_list_slock
);
532 for (cnt
= 0, vp
= vnode_free_list
.tqh_first
;
533 vp
!= NULLVP
; cnt
++, vp
= vp
->v_freelist
.tqe_next
) {
534 if (simple_lock_try(&vp
->v_interlock
)) {
535 /* got the interlock */
536 if (ISSET(vp
->v_flag
, VORECLAIM
)) {
537 /* skip over the vnodes that are being reclaimed */
538 simple_unlock(&vp
->v_interlock
);
546 * Unless this is a bad time of the month, at most
547 * the first NCPUS items on the free list are
548 * locked, so this is close enough to being empty.
551 simple_unlock(&vnode_free_list_slock
);
552 if (!(didretry
++) && (vnreclaim(vnodetarget
) > 0))
555 log(LOG_EMERG
, "%d vnodes locked, %d desired, %d numvnodes, "
556 "%d free, %d inactive, %d being reclaimed\n",
557 cnt
, desiredvnodes
, numvnodes
, freevnodes
, inactivevnodes
,
564 panic("free vnode isn't: v_type = %d, v_usecount = %d?",
565 vp
->v_type
, vp
->v_usecount
);
567 VREMFREE("getnewvnode", vp
);
569 simple_unlock(&vnode_free_list_slock
);
572 if (vp
->v_type
!= VBAD
)
573 vgonel(vp
, p
); /* clean and reclaim the vnode */
575 simple_unlock(&vp
->v_interlock
);
578 panic("cleaned vnode isn't");
582 panic("Clean vnode has pending I/O's");
586 if (UBCINFOEXISTS(vp
))
587 panic("getnewvnode: ubcinfo not cleaned");
601 vp
->v_flag
= VSTANDARD
;
613 * Move a vnode from one mount queue to another.
621 simple_lock(&mntvnode_slock
);
623 * Delete from old mount point vnode list, if on one.
625 if (vp
->v_mount
!= NULL
)
626 LIST_REMOVE(vp
, v_mntvnodes
);
628 * Insert into list of vnodes for the new mount point, if available.
630 if ((vp
->v_mount
= mp
) != NULL
)
631 LIST_INSERT_HEAD(&mp
->mnt_vnodelist
, vp
, v_mntvnodes
);
632 simple_unlock(&mntvnode_slock
);
636 vpwakeup(struct vnode
*vp
)
639 if (--vp
->v_numoutput
< 0)
640 panic("vpwakeup: neg numoutput");
641 if ((vp
->v_flag
& VBWAIT
|| vp
->v_flag
& VTHROTTLED
)
642 && vp
->v_numoutput
<= 0) {
643 vp
->v_flag
&= ~(VBWAIT
|VTHROTTLED
);
644 wakeup((caddr_t
)&vp
->v_numoutput
);
650 * Update outstanding I/O count and do wakeup if requested.
654 register struct buf
*bp
;
656 CLR(bp
->b_flags
, B_WRITEINPROG
);
661 * Flush out and invalidate all buffers associated with a vnode.
662 * Called with the underlying object locked.
665 vinvalbuf(vp
, flags
, cred
, p
, slpflag
, slptimeo
)
666 register struct vnode
*vp
;
670 int slpflag
, slptimeo
;
672 register struct buf
*bp
;
673 struct buf
*nbp
, *blist
;
676 if (flags
& V_SAVE
) {
677 if (error
= VOP_FSYNC(vp
, cred
, MNT_WAIT
, p
)) {
680 if (vp
->v_dirtyblkhd
.lh_first
)
681 panic("vinvalbuf: dirty bufs");
685 if ((blist
= vp
->v_cleanblkhd
.lh_first
) && flags
& V_SAVEMETA
)
686 while (blist
&& blist
->b_lblkno
< 0)
687 blist
= blist
->b_vnbufs
.le_next
;
688 if (!blist
&& (blist
= vp
->v_dirtyblkhd
.lh_first
) &&
689 (flags
& V_SAVEMETA
))
690 while (blist
&& blist
->b_lblkno
< 0)
691 blist
= blist
->b_vnbufs
.le_next
;
695 for (bp
= blist
; bp
; bp
= nbp
) {
696 nbp
= bp
->b_vnbufs
.le_next
;
697 if (flags
& V_SAVEMETA
&& bp
->b_lblkno
< 0)
700 if (ISSET(bp
->b_flags
, B_BUSY
)) {
701 SET(bp
->b_flags
, B_WANTED
);
702 error
= tsleep((caddr_t
)bp
,
703 slpflag
| (PRIBIO
+ 1), "vinvalbuf",
712 SET(bp
->b_flags
, B_BUSY
);
715 * XXX Since there are no node locks for NFS, I believe
716 * there is a slight chance that a delayed write will
717 * occur while sleeping just above, so check for it.
719 if (ISSET(bp
->b_flags
, B_DELWRI
) && (flags
& V_SAVE
)) {
720 (void) VOP_BWRITE(bp
);
723 SET(bp
->b_flags
, B_INVAL
);
727 if (!(flags
& V_SAVEMETA
) &&
728 (vp
->v_dirtyblkhd
.lh_first
|| vp
->v_cleanblkhd
.lh_first
))
729 panic("vinvalbuf: flush failed");
734 * Create a vnode for a block device.
735 * Used for root filesystem, argdev, and swap areas.
736 * Also used for memory file system special devices.
743 register struct vnode
*vp
;
751 error
= getnewvnode(VT_NON
, (struct mount
*)0, spec_vnodeop_p
, &nvp
);
758 if (nvp
= checkalias(vp
, dev
, (struct mount
*)0)) {
767 * Check to see if the new vnode represents a special device
768 * for which we already have a vnode (either because of
769 * bdevvp() or because of a different vnode representing
770 * the same block device). If such an alias exists, deallocate
771 * the existing contents and return the aliased vnode. The
772 * caller is responsible for filling it with its new contents.
775 checkalias(nvp
, nvp_rdev
, mp
)
776 register struct vnode
*nvp
;
780 struct proc
*p
= current_proc(); /* XXX */
783 struct specinfo
* bufhold
;
786 if (nvp
->v_type
!= VBLK
&& nvp
->v_type
!= VCHR
)
789 bufhold
= (struct specinfo
*)_MALLOC_ZONE(sizeof(struct specinfo
),
791 vpp
= &speclisth
[SPECHASH(nvp_rdev
)];
793 simple_lock(&spechash_slock
);
794 for (vp
= *vpp
; vp
; vp
= vp
->v_specnext
) {
795 if (nvp_rdev
!= vp
->v_rdev
|| nvp
->v_type
!= vp
->v_type
)
798 * Alias, but not in use, so flush it out.
800 simple_lock(&vp
->v_interlock
);
801 if (vp
->v_usecount
== 0) {
802 simple_unlock(&spechash_slock
);
806 if (vget(vp
, LK_EXCLUSIVE
| LK_INTERLOCK
, p
)) {
807 simple_unlock(&spechash_slock
);
812 if (vp
== NULL
|| vp
->v_tag
!= VT_NON
) {
813 nvp
->v_specinfo
= bufhold
;
814 buffree
= 0; /* buffer used */
815 bzero(nvp
->v_specinfo
, sizeof(struct specinfo
));
816 nvp
->v_rdev
= nvp_rdev
;
817 nvp
->v_hashchain
= vpp
;
818 nvp
->v_specnext
= *vpp
;
819 nvp
->v_specflags
= 0;
820 simple_unlock(&spechash_slock
);
823 nvp
->v_flag
|= VALIASED
;
824 vp
->v_flag
|= VALIASED
;
827 /* Since buffer is used just return */
830 simple_unlock(&spechash_slock
);
831 VOP_UNLOCK(vp
, 0, p
);
832 simple_lock(&vp
->v_interlock
);
834 vp
->v_op
= nvp
->v_op
;
835 vp
->v_tag
= nvp
->v_tag
;
839 _FREE_ZONE((void *)bufhold
, sizeof (struct specinfo
), M_VNODE
);
844 * Get a reference on a particular vnode and lock it if requested.
845 * If the vnode was on the inactive list, remove it from the list.
846 * If the vnode was on the free list, remove it from the list and
847 * move it to inactive list as needed.
848 * The vnode lock bit is set if the vnode is being eliminated in
849 * vgone. The process is awakened when the transition is completed,
850 * and an error returned to indicate that the vnode is no longer
851 * usable (possibly having been changed to a new file system type).
864 * If the vnode is in the process of being cleaned out for
865 * another use, we wait for the cleaning to finish and then
866 * return failure. Cleaning is determined by checking that
867 * the VXLOCK flag is set.
869 if ((flags
& LK_INTERLOCK
) == 0)
870 simple_lock(&vp
->v_interlock
);
871 if ((vp
->v_flag
& VXLOCK
) || (vp
->v_flag
& VORECLAIM
)) {
872 vp
->v_flag
|= VXWANT
;
873 simple_unlock(&vp
->v_interlock
);
874 (void)tsleep((caddr_t
)vp
, PINOD
, "vget", 0);
879 * vnode is being terminated.
880 * wait for vnode_pager_no_senders() to clear VTERMINATE
882 if (ISSET(vp
->v_flag
, VTERMINATE
)) {
883 SET(vp
->v_flag
, VTERMWANT
);
884 simple_unlock(&vp
->v_interlock
);
885 (void)tsleep((caddr_t
)&vp
->v_ubcinfo
, PINOD
, "vclean", 0);
890 * if the vnode is being initialized,
891 * wait for it to finish initialization
893 if (ISSET(vp
->v_flag
, VUINIT
)) {
894 if (ISSET(vp
->v_flag
, VUINIT
)) {
895 SET(vp
->v_flag
, VUWANT
);
896 simple_unlock(&vp
->v_interlock
);
897 (void) tsleep((caddr_t
)vp
, PINOD
, "vget2", 0);
902 simple_lock(&vnode_free_list_slock
);
903 if (vp
->v_usecount
== 0) {
904 /* If on the free list, remove it from there */
906 VREMFREE("vget", vp
);
908 /* If on the inactive list, remove it from there */
909 if ((vp
->v_usecount
== 1) && UBCINFOEXISTS(vp
)) {
911 VREMINACTIVE("vget", vp
);
915 /* The vnode should not be on the inactive list here */
916 VINACTIVECHECK("vget", vp
, 0);
918 simple_unlock(&vnode_free_list_slock
);
920 if (++vp
->v_usecount
<= 0)
921 panic("vget: v_usecount");
924 * Recover named reference as needed
926 if (UBCISVALID(vp
) && !ubc_issetflags(vp
, UI_HASOBJREF
)) {
927 simple_unlock(&vp
->v_interlock
);
928 if (ubc_getobject(vp
, UBC_HOLDOBJECT
)) {
932 simple_lock(&vp
->v_interlock
);
935 if (flags
& LK_TYPE_MASK
) {
936 if (error
= vn_lock(vp
, flags
| LK_INTERLOCK
, p
))
941 if ((flags
& LK_INTERLOCK
) == 0)
942 simple_unlock(&vp
->v_interlock
);
947 * If the vnode was not active in the first place
948 * must not call vrele() as VOP_INACTIVE() is not
950 * So inlined part of vrele() here.
952 simple_lock(&vp
->v_interlock
);
953 if (--vp
->v_usecount
== 1) {
954 if (UBCINFOEXISTS(vp
)) {
956 simple_unlock(&vp
->v_interlock
);
960 if (vp
->v_usecount
> 0) {
961 simple_unlock(&vp
->v_interlock
);
964 if (vp
->v_usecount
< 0)
965 panic("vget: negative usecount (%d)", vp
->v_usecount
);
967 simple_unlock(&vp
->v_interlock
);
972 * Get a pager reference on the particular vnode.
974 * This is called from ubc_info_init() and it is asumed that
975 * the vnode is neither on the free list on on the inactive list.
976 * It is also assumed that the vnode is neither being recycled
977 * by vgonel nor being terminated by vnode_pager_vrele().
979 * The vnode interlock is NOT held by the caller.
981 __private_extern__
int
985 simple_lock(&vp
->v_interlock
);
986 if (UBCINFOMISSING(vp
))
987 panic("vnode_pager_vget: stolen ubc_info");
989 if (!UBCINFOEXISTS(vp
))
990 panic("vnode_pager_vget: lost ubc_info");
992 if ((vp
->v_flag
& VXLOCK
) || (vp
->v_flag
& VORECLAIM
))
993 panic("vnode_pager_vget: already being reclaimd");
995 if (ISSET(vp
->v_flag
, VTERMINATE
))
996 panic("vnode_pager_vget: already being terminated");
998 simple_lock(&vnode_free_list_slock
);
999 /* The vnode should not be on ANY list */
1001 panic("vnode_pager_vget: still on the list");
1003 /* The vnode should not be on the inactive list here */
1004 VINACTIVECHECK("vnode_pager_vget", vp
, 0);
1005 simple_unlock(&vnode_free_list_slock
);
1007 /* After all those checks, now do the real work :-) */
1008 if (++vp
->v_usecount
<= 0)
1009 panic("vnode_pager_vget: v_usecount");
1010 simple_unlock(&vp
->v_interlock
);
1016 * Stubs to use when there is no locking to be done on the underlying object.
1017 * A minimal shared lock is necessary to ensure that the underlying object
1018 * is not revoked while an operation is in progress. So, an active shared
1019 * count is maintained in an auxillary vnode lock structure.
1023 struct vop_lock_args
/* {
1031 * This code cannot be used until all the non-locking filesystems
1032 * (notably NFS) are converted to properly lock and release nodes.
1033 * Also, certain vnode operations change the locking state within
1034 * the operation (create, mknod, remove, link, rename, mkdir, rmdir,
1035 * and symlink). Ideally these operations should not change the
1036 * lock state, but should be changed to let the caller of the
1037 * function unlock them. Otherwise all intermediate vnode layers
1038 * (such as union, umapfs, etc) must catch these functions to do
1039 * the necessary locking at their layer. Note that the inactive
1040 * and lookup operations also change their lock state, but this
1041 * cannot be avoided, so these two operations will always need
1042 * to be handled in intermediate layers.
1044 struct vnode
*vp
= ap
->a_vp
;
1045 int vnflags
, flags
= ap
->a_flags
;
1047 if (vp
->v_vnlock
== NULL
) {
1048 if ((flags
& LK_TYPE_MASK
) == LK_DRAIN
)
1050 MALLOC_ZONE(vp
->v_vnlock
, struct lock__bsd__
*,
1051 sizeof(struct lock__bsd__
), M_VNODE
, M_WAITOK
);
1052 lockinit(vp
->v_vnlock
, PVFS
, "vnlock", 0, 0);
1054 switch (flags
& LK_TYPE_MASK
) {
1060 vnflags
= LK_SHARED
;
1063 case LK_EXCLUPGRADE
:
1068 panic("vop_nolock: bad operation %d", flags
& LK_TYPE_MASK
);
1070 if (flags
& LK_INTERLOCK
)
1071 vnflags
|= LK_INTERLOCK
;
1072 return(lockmgr(vp
->v_vnlock
, vnflags
, &vp
->v_interlock
, ap
->a_p
));
1075 * Since we are not using the lock manager, we must clear
1076 * the interlock here.
1078 if (ap
->a_flags
& LK_INTERLOCK
)
1079 simple_unlock(&ap
->a_vp
->v_interlock
);
1085 * Decrement the active use count.
1089 struct vop_unlock_args
/* {
1095 struct vnode
*vp
= ap
->a_vp
;
1097 if (vp
->v_vnlock
== NULL
)
1099 return (lockmgr(vp
->v_vnlock
, LK_RELEASE
, NULL
, ap
->a_p
));
1103 * Return whether or not the node is in use.
1107 struct vop_islocked_args
/* {
1111 struct vnode
*vp
= ap
->a_vp
;
1113 if (vp
->v_vnlock
== NULL
)
1115 return (lockstatus(vp
->v_vnlock
));
1126 simple_lock(&vp
->v_interlock
);
1127 if (vp
->v_usecount
<= 0)
1128 panic("vref used where vget required");
1130 /* If on the inactive list, remove it from there */
1131 if ((vp
->v_usecount
== 1) && UBCINFOEXISTS(vp
)) {
1133 simple_lock(&vnode_free_list_slock
);
1134 VREMINACTIVE("vref", vp
);
1135 simple_unlock(&vnode_free_list_slock
);
1138 /* The vnode should not be on the inactive list here */
1139 VINACTIVECHECK("vref", vp
, 0);
1141 if (++vp
->v_usecount
<= 0)
1142 panic("vref v_usecount");
1143 simple_unlock(&vp
->v_interlock
);
1147 * put the vnode on appropriate free list.
1148 * called with v_interlock held.
1155 * if the vnode is not obtained by calling getnewvnode() we
1156 * are not responsible for the cleanup. Just return.
1158 if (!(vp
->v_flag
& VSTANDARD
)) {
1162 if (vp
->v_usecount
!= 0)
1163 panic("vfree: v_usecount");
1165 /* insert at tail of LRU list or at head if VAGE is set */
1166 simple_lock(&vnode_free_list_slock
);
1169 panic("vfree: vnode still on list");
1171 if (vp
->v_flag
& VAGE
) {
1172 TAILQ_INSERT_HEAD(&vnode_free_list
, vp
, v_freelist
);
1173 vp
->v_flag
&= ~VAGE
;
1175 TAILQ_INSERT_TAIL(&vnode_free_list
, vp
, v_freelist
);
1177 simple_unlock(&vnode_free_list_slock
);
1182 * put the vnode on the inactive list.
1183 * called with v_interlock held
1189 if (!UBCINFOEXISTS(vp
))
1190 panic("vinactive: not a UBC vnode");
1192 if (vp
->v_usecount
!= 1)
1193 panic("vinactive: v_usecount");
1195 simple_lock(&vnode_free_list_slock
);
1198 panic("vinactive: vnode still on list");
1199 VINACTIVECHECK("vinactive", vp
, 0);
1201 TAILQ_INSERT_TAIL(&vnode_inactive_list
, vp
, v_freelist
);
1202 SET(vp
->v_flag
, VUINACTIVE
);
1203 CLR(vp
->v_flag
, (VNOCACHE_DATA
| VRAOFF
));
1206 simple_unlock(&vnode_free_list_slock
);
1212 * vput(), just unlock and vrele()
1218 struct proc
*p
= current_proc(); /* XXX */
1220 simple_lock(&vp
->v_interlock
);
1221 if (--vp
->v_usecount
== 1) {
1222 if (UBCINFOEXISTS(vp
)) {
1224 simple_unlock(&vp
->v_interlock
);
1225 VOP_UNLOCK(vp
, 0, p
);
1229 if (vp
->v_usecount
> 0) {
1230 simple_unlock(&vp
->v_interlock
);
1231 VOP_UNLOCK(vp
, 0, p
);
1235 if (vp
->v_usecount
< 0 || vp
->v_writecount
!= 0) {
1236 vprint("vput: bad ref count", vp
);
1237 panic("vput: v_usecount = %d, v_writecount = %d",
1238 vp
->v_usecount
, vp
->v_writecount
);
1241 if (ISSET((vp
)->v_flag
, VUINACTIVE
) && VONLIST(vp
))
1242 VREMINACTIVE("vrele", vp
);
1244 simple_unlock(&vp
->v_interlock
);
1245 VOP_INACTIVE(vp
, p
);
1247 * The interlock is not held and
1248 * VOP_INCATIVE releases the vnode lock.
1249 * We could block and the vnode might get reactivated
1250 * Can not just call vfree without checking the state
1252 simple_lock(&vp
->v_interlock
);
1254 if (vp
->v_usecount
== 0)
1256 else if ((vp
->v_usecount
== 1) && UBCINFOEXISTS(vp
))
1259 simple_unlock(&vp
->v_interlock
);
1264 * If count drops to zero, call inactive routine and return to freelist.
1270 struct proc
*p
= current_proc(); /* XXX */
1272 simple_lock(&vp
->v_interlock
);
1273 if (--vp
->v_usecount
== 1) {
1274 if (UBCINFOEXISTS(vp
)) {
1276 simple_unlock(&vp
->v_interlock
);
1280 if (vp
->v_usecount
> 0) {
1281 simple_unlock(&vp
->v_interlock
);
1285 if (vp
->v_usecount
< 0 || vp
->v_writecount
!= 0) {
1286 vprint("vrele: bad ref count", vp
);
1287 panic("vrele: ref cnt");
1290 if (ISSET((vp
)->v_flag
, VUINACTIVE
) && VONLIST(vp
))
1291 VREMINACTIVE("vrele", vp
);
1294 if ((vp
->v_flag
& VXLOCK
) || (vp
->v_flag
& VORECLAIM
)) {
1295 /* vnode is being cleaned, just return */
1297 simple_unlock(&vp
->v_interlock
);
1301 if (vn_lock(vp
, LK_EXCLUSIVE
| LK_INTERLOCK
, p
) == 0) {
1302 VOP_INACTIVE(vp
, p
);
1304 * vn_lock releases the interlock and
1305 * VOP_INCATIVE releases the vnode lock.
1306 * We could block and the vnode might get reactivated
1307 * Can not just call vfree without checking the state
1309 simple_lock(&vp
->v_interlock
);
1311 if (vp
->v_usecount
== 0)
1313 else if ((vp
->v_usecount
== 1) && UBCINFOEXISTS(vp
))
1316 simple_unlock(&vp
->v_interlock
);
1321 simple_unlock(&vp
->v_interlock
);
1322 kprintf("vrele: vn_lock() failed for vp = 0x%08x\n", vp
);
1331 simple_lock(&vp
->v_interlock
);
1333 simple_unlock(&vp
->v_interlock
);
1338 * Page or buffer structure gets a reference.
1342 register struct vnode
*vp
;
1345 simple_lock(&vp
->v_interlock
);
1347 simple_unlock(&vp
->v_interlock
);
1351 * Page or buffer structure frees a reference.
1355 register struct vnode
*vp
;
1358 simple_lock(&vp
->v_interlock
);
1359 if (vp
->v_holdcnt
<= 0)
1360 panic("holdrele: holdcnt");
1362 simple_unlock(&vp
->v_interlock
);
1366 * Remove any vnodes in the vnode table belonging to mount point mp.
1368 * If MNT_NOFORCE is specified, there should not be any active ones,
1369 * return error if any are found (nb: this is a user error, not a
1370 * system error). If MNT_FORCE is specified, detach any active vnodes
1374 int busyprt
= 0; /* print out busy vnodes */
1376 struct ctldebug debug1
= { "busyprt", &busyprt
};
1381 vflush(mp
, skipvp
, flags
)
1383 struct vnode
*skipvp
;
1386 struct proc
*p
= current_proc();
1387 struct vnode
*vp
, *nvp
;
1390 simple_lock(&mntvnode_slock
);
1392 for (vp
= mp
->mnt_vnodelist
.lh_first
; vp
; vp
= nvp
) {
1393 if (vp
->v_mount
!= mp
)
1395 nvp
= vp
->v_mntvnodes
.le_next
;
1397 * Skip over a selected vnode.
1402 simple_lock(&vp
->v_interlock
);
1404 * Skip over a vnodes marked VSYSTEM or VNOFLUSH.
1406 if ((flags
& SKIPSYSTEM
) && ((vp
->v_flag
& VSYSTEM
) || (vp
->v_flag
& VNOFLUSH
))) {
1407 simple_unlock(&vp
->v_interlock
);
1411 * Skip over a vnodes marked VSWAP.
1413 if ((flags
& SKIPSWAP
) && (vp
->v_flag
& VSWAP
)) {
1414 simple_unlock(&vp
->v_interlock
);
1418 * If WRITECLOSE is set, only flush out regular file
1419 * vnodes open for writing.
1421 if ((flags
& WRITECLOSE
) &&
1422 (vp
->v_writecount
== 0 || vp
->v_type
!= VREG
)) {
1423 simple_unlock(&vp
->v_interlock
);
1427 * With v_usecount == 0, all we need to do is clear
1428 * out the vnode data structures and we are done.
1430 if (vp
->v_usecount
== 0) {
1431 simple_unlock(&mntvnode_slock
);
1433 simple_lock(&mntvnode_slock
);
1437 * If FORCECLOSE is set, forcibly close the vnode.
1438 * For block or character devices, revert to an
1439 * anonymous device. For all other files, just kill them.
1441 if (flags
& FORCECLOSE
) {
1442 simple_unlock(&mntvnode_slock
);
1443 if (vp
->v_type
!= VBLK
&& vp
->v_type
!= VCHR
) {
1447 vp
->v_op
= spec_vnodeop_p
;
1448 insmntque(vp
, (struct mount
*)0);
1450 simple_lock(&mntvnode_slock
);
1455 vprint("vflush: busy vnode", vp
);
1457 simple_unlock(&vp
->v_interlock
);
1460 simple_unlock(&mntvnode_slock
);
1461 if (busy
&& ((flags
& FORCECLOSE
)==0))
1467 * Disassociate the underlying file system from a vnode.
1468 * The vnode interlock is held on entry.
1471 vclean(vp
, flags
, p
)
1481 * if the vnode is not obtained by calling getnewvnode() we
1482 * are not responsible for the cleanup. Just return.
1484 if (!(vp
->v_flag
& VSTANDARD
)) {
1485 simple_unlock(&vp
->v_interlock
);
1490 * Check to see if the vnode is in use.
1491 * If so we have to reference it before we clean it out
1492 * so that its count cannot fall to zero and generate a
1493 * race against ourselves to recycle it.
1495 if (active
= vp
->v_usecount
)
1496 if (++vp
->v_usecount
<= 0)
1497 panic("vclean: v_usecount");
1499 * Prevent the vnode from being recycled or
1500 * brought into use while we clean it out.
1502 if (vp
->v_flag
& VXLOCK
)
1503 panic("vclean: deadlock");
1504 vp
->v_flag
|= VXLOCK
;
1507 * Even if the count is zero, the VOP_INACTIVE routine may still
1508 * have the object locked while it cleans it out. The VOP_LOCK
1509 * ensures that the VOP_INACTIVE routine is done with its work.
1510 * For active vnodes, it ensures that no other activity can
1511 * occur while the underlying object is being cleaned out.
1513 VOP_LOCK(vp
, LK_DRAIN
| LK_INTERLOCK
, p
);
1516 * if this vnode is on the inactive list
1517 * take it off the list.
1519 if ((active
== 1) &&
1520 (ISSET((vp
)->v_flag
, VUINACTIVE
) && VONLIST(vp
))) {
1521 simple_lock(&vnode_free_list_slock
);
1522 VREMINACTIVE("vclean", vp
);
1523 simple_unlock(&vnode_free_list_slock
);
1527 /* Clean the pages in VM. */
1528 if (active
&& (flags
& DOCLOSE
))
1529 VOP_CLOSE(vp
, IO_NDELAY
, NOCRED
, p
);
1531 /* Clean the pages in VM. */
1532 didhold
= ubc_hold(vp
);
1533 if ((active
) && (didhold
))
1534 (void)ubc_clean(vp
, 0); /* do not invalidate */
1537 * Clean out any buffers associated with the vnode.
1539 if (flags
& DOCLOSE
) {
1540 if (vp
->v_tag
== VT_NFS
)
1541 nfs_vinvalbuf(vp
, V_SAVE
, NOCRED
, p
, 0);
1543 vinvalbuf(vp
, V_SAVE
, NOCRED
, p
, 0, 0);
1547 VOP_INACTIVE(vp
, p
);
1549 VOP_UNLOCK(vp
, 0, p
);
1551 /* Destroy ubc named reference */
1554 ubc_destroy_named(vp
);
1558 * Reclaim the vnode.
1560 if (VOP_RECLAIM(vp
, p
))
1561 panic("vclean: cannot reclaim");
1564 if ((vp
->v_vnlock
->lk_flags
& LK_DRAINED
) == 0)
1565 vprint("vclean: lock not drained", vp
);
1566 FREE_ZONE(vp
->v_vnlock
, sizeof (struct lock__bsd__
), M_VNODE
);
1567 vp
->v_vnlock
= NULL
;
1570 /* It's dead, Jim! */
1571 vp
->v_op
= dead_vnodeop_p
;
1575 * Done with purge, notify sleepers of the grim news.
1577 vp
->v_flag
&= ~VXLOCK
;
1578 if (vp
->v_flag
& VXWANT
) {
1579 vp
->v_flag
&= ~VXWANT
;
1580 wakeup((caddr_t
)vp
);
1588 * Eliminate all activity associated with the requested vnode
1589 * and with all vnodes aliased to the requested vnode.
1593 struct vop_revoke_args
/* {
1598 struct vnode
*vp
, *vq
;
1599 struct proc
*p
= current_proc();
1602 if ((ap
->a_flags
& REVOKEALL
) == 0)
1603 panic("vop_revoke");
1607 simple_lock(&vp
->v_interlock
);
1609 if (vp
->v_flag
& VALIASED
) {
1611 * If a vgone (or vclean) is already in progress,
1612 * wait until it is done and return.
1614 if (vp
->v_flag
& VXLOCK
) {
1615 while (vp
->v_flag
& VXLOCK
) {
1616 vp
->v_flag
|= VXWANT
;
1617 simple_unlock(&vp
->v_interlock
);
1618 (void)tsleep((caddr_t
)vp
, PINOD
, "vop_revokeall", 0);
1623 * Ensure that vp will not be vgone'd while we
1624 * are eliminating its aliases.
1626 vp
->v_flag
|= VXLOCK
;
1627 simple_unlock(&vp
->v_interlock
);
1628 while (vp
->v_flag
& VALIASED
) {
1629 simple_lock(&spechash_slock
);
1630 for (vq
= *vp
->v_hashchain
; vq
; vq
= vq
->v_specnext
) {
1631 if (vq
->v_rdev
!= vp
->v_rdev
||
1632 vq
->v_type
!= vp
->v_type
|| vp
== vq
)
1634 simple_unlock(&spechash_slock
);
1639 simple_unlock(&spechash_slock
);
1642 * Remove the lock so that vgone below will
1643 * really eliminate the vnode after which time
1644 * vgone will awaken any sleepers.
1646 simple_lock(&vp
->v_interlock
);
1647 vp
->v_flag
&= ~VXLOCK
;
1654 * Recycle an unused vnode to the front of the free list.
1655 * Release the passed interlock if the vnode will be recycled.
1658 vrecycle(vp
, inter_lkp
, p
)
1660 struct slock
*inter_lkp
;
1664 simple_lock(&vp
->v_interlock
);
1665 if (vp
->v_usecount
== 0) {
1667 simple_unlock(inter_lkp
);
1671 simple_unlock(&vp
->v_interlock
);
1676 * Eliminate all activity associated with a vnode
1677 * in preparation for reuse.
1683 struct proc
*p
= current_proc();
1685 simple_lock(&vp
->v_interlock
);
1690 * vgone, with the vp interlock held.
1701 * if the vnode is not obtained by calling getnewvnode() we
1702 * are not responsible for the cleanup. Just return.
1704 if (!(vp
->v_flag
& VSTANDARD
)) {
1705 simple_unlock(&vp
->v_interlock
);
1710 * If a vgone (or vclean) is already in progress,
1711 * wait until it is done and return.
1713 if (vp
->v_flag
& VXLOCK
) {
1714 while (vp
->v_flag
& VXLOCK
) {
1715 vp
->v_flag
|= VXWANT
;
1716 simple_unlock(&vp
->v_interlock
);
1717 (void)tsleep((caddr_t
)vp
, PINOD
, "vgone", 0);
1722 * Clean out the filesystem specific data.
1724 vclean(vp
, DOCLOSE
, p
);
1726 * Delete from old mount point vnode list, if on one.
1728 if (vp
->v_mount
!= NULL
)
1729 insmntque(vp
, (struct mount
*)0);
1731 * If special device, remove it from special device alias list
1734 if ((vp
->v_type
== VBLK
|| vp
->v_type
== VCHR
) && vp
->v_specinfo
!= 0) {
1735 simple_lock(&spechash_slock
);
1736 if (*vp
->v_hashchain
== vp
) {
1737 *vp
->v_hashchain
= vp
->v_specnext
;
1739 for (vq
= *vp
->v_hashchain
; vq
; vq
= vq
->v_specnext
) {
1740 if (vq
->v_specnext
!= vp
)
1742 vq
->v_specnext
= vp
->v_specnext
;
1746 panic("missing bdev");
1748 if (vp
->v_flag
& VALIASED
) {
1750 for (vq
= *vp
->v_hashchain
; vq
; vq
= vq
->v_specnext
) {
1751 if (vq
->v_rdev
!= vp
->v_rdev
||
1752 vq
->v_type
!= vp
->v_type
)
1759 panic("missing alias");
1761 vx
->v_flag
&= ~VALIASED
;
1762 vp
->v_flag
&= ~VALIASED
;
1764 simple_unlock(&spechash_slock
);
1765 FREE_ZONE(vp
->v_specinfo
, sizeof (struct specinfo
), M_VNODE
);
1766 vp
->v_specinfo
= NULL
;
1769 * If it is on the freelist and not already at the head,
1770 * move it to the head of the list. The test of the back
1771 * pointer and the reference count of zero is because
1772 * it will be removed from the free list by getnewvnode,
1773 * but will not have its reference count incremented until
1774 * after calling vgone. If the reference count were
1775 * incremented first, vgone would (incorrectly) try to
1776 * close the previous instance of the underlying object.
1777 * So, the back pointer is explicitly set to `0xdeadb' in
1778 * getnewvnode after removing it from the freelist to ensure
1779 * that we do not try to move it here.
1781 if (vp
->v_usecount
== 0) {
1782 simple_lock(&vnode_free_list_slock
);
1783 if ((vp
->v_freelist
.tqe_prev
!= (struct vnode
**)0xdeadb) &&
1784 vnode_free_list
.tqh_first
!= vp
) {
1785 TAILQ_REMOVE(&vnode_free_list
, vp
, v_freelist
);
1786 TAILQ_INSERT_HEAD(&vnode_free_list
, vp
, v_freelist
);
1788 simple_unlock(&vnode_free_list_slock
);
1794 * Lookup a vnode by device number.
1797 vfinddev(dev
, type
, vpp
)
1805 simple_lock(&spechash_slock
);
1806 for (vp
= speclisth
[SPECHASH(dev
)]; vp
; vp
= vp
->v_specnext
) {
1807 if (dev
!= vp
->v_rdev
|| type
!= vp
->v_type
)
1813 simple_unlock(&spechash_slock
);
1818 * Calculate the total number of references to a special device.
1824 struct vnode
*vq
, *vnext
;
1828 if ((vp
->v_flag
& VALIASED
) == 0)
1829 return (vp
->v_usecount
);
1830 simple_lock(&spechash_slock
);
1831 for (count
= 0, vq
= *vp
->v_hashchain
; vq
; vq
= vnext
) {
1832 vnext
= vq
->v_specnext
;
1833 if (vq
->v_rdev
!= vp
->v_rdev
|| vq
->v_type
!= vp
->v_type
)
1836 * Alias, but not in use, so flush it out.
1838 if (vq
->v_usecount
== 0 && vq
!= vp
) {
1839 simple_unlock(&spechash_slock
);
1843 count
+= vq
->v_usecount
;
1845 simple_unlock(&spechash_slock
);
1849 int prtactive
= 0; /* 1 => print out reclaim of active vnodes */
1852 * Print out a description of a vnode.
1854 static char *typename
[] =
1855 { "VNON", "VREG", "VDIR", "VBLK", "VCHR", "VLNK", "VSOCK", "VFIFO", "VBAD" };
1860 register struct vnode
*vp
;
1865 printf("%s: ", label
);
1866 printf("type %s, usecount %d, writecount %d, refcount %d,",
1867 typename
[vp
->v_type
], vp
->v_usecount
, vp
->v_writecount
,
1870 if (vp
->v_flag
& VROOT
)
1871 strcat(buf
, "|VROOT");
1872 if (vp
->v_flag
& VTEXT
)
1873 strcat(buf
, "|VTEXT");
1874 if (vp
->v_flag
& VSYSTEM
)
1875 strcat(buf
, "|VSYSTEM");
1876 if (vp
->v_flag
& VNOFLUSH
)
1877 strcat(buf
, "|VNOFLUSH");
1878 if (vp
->v_flag
& VXLOCK
)
1879 strcat(buf
, "|VXLOCK");
1880 if (vp
->v_flag
& VXWANT
)
1881 strcat(buf
, "|VXWANT");
1882 if (vp
->v_flag
& VBWAIT
)
1883 strcat(buf
, "|VBWAIT");
1884 if (vp
->v_flag
& VALIASED
)
1885 strcat(buf
, "|VALIASED");
1887 printf(" flags (%s)", &buf
[1]);
1888 if (vp
->v_data
== NULL
) {
1898 * List all of the locked vnodes in the system.
1899 * Called when debugging the kernel.
1904 struct proc
*p
= current_proc();
1905 struct mount
*mp
, *nmp
;
1908 printf("Locked vnodes\n");
1909 simple_lock(&mountlist_slock
);
1910 for (mp
= mountlist
.cqh_first
; mp
!= (void *)&mountlist
; mp
= nmp
) {
1911 if (vfs_busy(mp
, LK_NOWAIT
, &mountlist_slock
, p
)) {
1912 nmp
= mp
->mnt_list
.cqe_next
;
1915 for (vp
= mp
->mnt_vnodelist
.lh_first
;
1917 vp
= vp
->v_mntvnodes
.le_next
) {
1918 if (VOP_ISLOCKED(vp
))
1919 vprint((char *)0, vp
);
1921 simple_lock(&mountlist_slock
);
1922 nmp
= mp
->mnt_list
.cqe_next
;
1925 simple_unlock(&mountlist_slock
);
1930 * Top level filesystem related information gathering.
1933 vfs_sysctl(name
, namelen
, oldp
, oldlenp
, newp
, newlen
, p
)
1942 struct vfsconf
*vfsp
;
1945 * The VFS_NUMMNTOPS shouldn't be at name[0] since
1946 * is a VFS generic variable. So now we must check
1947 * namelen so we don't end up covering any UFS
1948 * variables (sinc UFS vfc_typenum is 1).
1950 * It should have been:
1951 * name[0]: VFS_GENERIC
1952 * name[1]: VFS_NUMMNTOPS
1954 if (namelen
== 1 && name
[0] == VFS_NUMMNTOPS
) {
1955 extern unsigned int vfs_nummntops
;
1956 return (sysctl_rdint(oldp
, oldlenp
, newp
, vfs_nummntops
));
1959 /* all sysctl names at this level are at least name and field */
1961 return (ENOTDIR
); /* overloaded */
1962 if (name
[0] != VFS_GENERIC
) {
1963 for (vfsp
= vfsconf
; vfsp
; vfsp
= vfsp
->vfc_next
)
1964 if (vfsp
->vfc_typenum
== name
[0])
1967 return (EOPNOTSUPP
);
1968 return ((*vfsp
->vfc_vfsops
->vfs_sysctl
)(&name
[1], namelen
- 1,
1969 oldp
, oldlenp
, newp
, newlen
, p
));
1972 case VFS_MAXTYPENUM
:
1973 return (sysctl_rdint(oldp
, oldlenp
, newp
, maxvfsconf
));
1976 return (ENOTDIR
); /* overloaded */
1977 for (vfsp
= vfsconf
; vfsp
; vfsp
= vfsp
->vfc_next
)
1978 if (vfsp
->vfc_typenum
== name
[2])
1981 return (EOPNOTSUPP
);
1982 return (sysctl_rdstruct(oldp
, oldlenp
, newp
, vfsp
,
1983 sizeof(struct vfsconf
)));
1985 return (EOPNOTSUPP
);
1988 int kinfo_vdebug
= 1;
1989 #define KINFO_VNODESLOP 10
1991 * Dump vnode list (via sysctl).
1992 * Copyout address of vnode followed by vnode.
1996 sysctl_vnode(where
, sizep
, p
)
2001 struct mount
*mp
, *nmp
;
2002 struct vnode
*nvp
, *vp
;
2003 char *bp
= where
, *savebp
;
2007 #define VPTRSZ sizeof (struct vnode *)
2008 #define VNODESZ sizeof (struct vnode)
2009 if (where
== NULL
) {
2010 *sizep
= (numvnodes
+ KINFO_VNODESLOP
) * (VPTRSZ
+ VNODESZ
);
2013 ewhere
= where
+ *sizep
;
2015 simple_lock(&mountlist_slock
);
2016 for (mp
= mountlist
.cqh_first
; mp
!= (void *)&mountlist
; mp
= nmp
) {
2017 if (vfs_busy(mp
, LK_NOWAIT
, &mountlist_slock
, p
)) {
2018 nmp
= mp
->mnt_list
.cqe_next
;
2023 simple_lock(&mntvnode_slock
);
2024 for (vp
= mp
->mnt_vnodelist
.lh_first
;
2028 * Check that the vp is still associated with
2029 * this filesystem. RACE: could have been
2030 * recycled onto the same filesystem.
2032 if (vp
->v_mount
!= mp
) {
2033 simple_unlock(&mntvnode_slock
);
2035 printf("kinfo: vp changed\n");
2039 nvp
= vp
->v_mntvnodes
.le_next
;
2040 if (bp
+ VPTRSZ
+ VNODESZ
> ewhere
) {
2041 simple_unlock(&mntvnode_slock
);
2042 *sizep
= bp
- where
;
2045 simple_unlock(&mntvnode_slock
);
2046 if ((error
= copyout((caddr_t
)&vp
, bp
, VPTRSZ
)) ||
2047 (error
= copyout((caddr_t
)vp
, bp
+ VPTRSZ
, VNODESZ
)))
2049 bp
+= VPTRSZ
+ VNODESZ
;
2050 simple_lock(&mntvnode_slock
);
2052 simple_unlock(&mntvnode_slock
);
2053 simple_lock(&mountlist_slock
);
2054 nmp
= mp
->mnt_list
.cqe_next
;
2057 simple_unlock(&mountlist_slock
);
2059 *sizep
= bp
- where
;
2064 * Check to see if a filesystem is mounted on a block device.
2073 if (vp
->v_specflags
& SI_MOUNTEDON
)
2075 if (vp
->v_flag
& VALIASED
) {
2076 simple_lock(&spechash_slock
);
2077 for (vq
= *vp
->v_hashchain
; vq
; vq
= vq
->v_specnext
) {
2078 if (vq
->v_rdev
!= vp
->v_rdev
||
2079 vq
->v_type
!= vp
->v_type
)
2081 if (vq
->v_specflags
& SI_MOUNTEDON
) {
2086 simple_unlock(&spechash_slock
);
2092 * Unmount all filesystems. The list is traversed in reverse order
2093 * of mounting to avoid dependencies.
2095 __private_extern__
void
2098 struct mount
*mp
, *nmp
;
2099 struct proc
*p
= current_proc();
2102 * Since this only runs when rebooting, it is not interlocked.
2104 for (mp
= mountlist
.cqh_last
; mp
!= (void *)&mountlist
; mp
= nmp
) {
2105 nmp
= mp
->mnt_list
.cqe_prev
;
2106 (void) dounmount(mp
, MNT_FORCE
, p
);
2111 * Build hash lists of net addresses and hang them off the mount point.
2112 * Called by vfs_export() to set up the lists of export addresses.
2115 vfs_hang_addrlist(mp
, nep
, argp
)
2117 struct netexport
*nep
;
2118 struct export_args
*argp
;
2120 register struct netcred
*np
;
2121 register struct radix_node_head
*rnh
;
2123 struct radix_node
*rn
;
2124 struct sockaddr
*saddr
, *smask
= 0;
2128 if (argp
->ex_addrlen
== 0) {
2129 if (mp
->mnt_flag
& MNT_DEFEXPORTED
)
2131 np
= &nep
->ne_defexported
;
2132 np
->netc_exflags
= argp
->ex_flags
;
2133 np
->netc_anon
= argp
->ex_anon
;
2134 np
->netc_anon
.cr_ref
= 1;
2135 mp
->mnt_flag
|= MNT_DEFEXPORTED
;
2138 i
= sizeof(struct netcred
) + argp
->ex_addrlen
+ argp
->ex_masklen
;
2139 MALLOC(np
, struct netcred
*, i
, M_NETADDR
, M_WAITOK
);
2140 bzero((caddr_t
)np
, i
);
2141 saddr
= (struct sockaddr
*)(np
+ 1);
2142 if (error
= copyin(argp
->ex_addr
, (caddr_t
)saddr
, argp
->ex_addrlen
))
2144 if (saddr
->sa_len
> argp
->ex_addrlen
)
2145 saddr
->sa_len
= argp
->ex_addrlen
;
2146 if (argp
->ex_masklen
) {
2147 smask
= (struct sockaddr
*)((caddr_t
)saddr
+ argp
->ex_addrlen
);
2148 error
= copyin(argp
->ex_addr
, (caddr_t
)smask
, argp
->ex_masklen
);
2151 if (smask
->sa_len
> argp
->ex_masklen
)
2152 smask
->sa_len
= argp
->ex_masklen
;
2154 i
= saddr
->sa_family
;
2155 if ((rnh
= nep
->ne_rtable
[i
]) == 0) {
2157 * Seems silly to initialize every AF when most are not
2158 * used, do so on demand here
2160 for (dom
= domains
; dom
; dom
= dom
->dom_next
)
2161 if (dom
->dom_family
== i
&& dom
->dom_rtattach
) {
2162 dom
->dom_rtattach((void **)&nep
->ne_rtable
[i
],
2166 if ((rnh
= nep
->ne_rtable
[i
]) == 0) {
2171 rn
= (*rnh
->rnh_addaddr
)((caddr_t
)saddr
, (caddr_t
)smask
, rnh
,
2175 * One of the reasons that rnh_addaddr may fail is that
2176 * the entry already exists. To check for this case, we
2177 * look up the entry to see if it is there. If so, we
2178 * do not need to make a new entry but do return success.
2180 _FREE(np
, M_NETADDR
);
2181 rn
= (*rnh
->rnh_matchaddr
)((caddr_t
)saddr
, rnh
);
2182 if (rn
!= 0 && (rn
->rn_flags
& RNF_ROOT
) == 0 &&
2183 ((struct netcred
*)rn
)->netc_exflags
== argp
->ex_flags
&&
2184 !bcmp((caddr_t
)&((struct netcred
*)rn
)->netc_anon
,
2185 (caddr_t
)&argp
->ex_anon
, sizeof(struct ucred
)))
2189 np
->netc_exflags
= argp
->ex_flags
;
2190 np
->netc_anon
= argp
->ex_anon
;
2191 np
->netc_anon
.cr_ref
= 1;
2194 _FREE(np
, M_NETADDR
);
2200 vfs_free_netcred(rn
, w
)
2201 struct radix_node
*rn
;
2204 register struct radix_node_head
*rnh
= (struct radix_node_head
*)w
;
2206 (*rnh
->rnh_deladdr
)(rn
->rn_key
, rn
->rn_mask
, rnh
);
2207 _FREE((caddr_t
)rn
, M_NETADDR
);
2212 * Free the net address hash lists that are hanging off the mount points.
2215 vfs_free_addrlist(nep
)
2216 struct netexport
*nep
;
2219 register struct radix_node_head
*rnh
;
2221 for (i
= 0; i
<= AF_MAX
; i
++)
2222 if (rnh
= nep
->ne_rtable
[i
]) {
2223 (*rnh
->rnh_walktree
)(rnh
, vfs_free_netcred
,
2225 _FREE((caddr_t
)rnh
, M_RTABLE
);
2226 nep
->ne_rtable
[i
] = 0;
2231 vfs_export(mp
, nep
, argp
)
2233 struct netexport
*nep
;
2234 struct export_args
*argp
;
2238 if (argp
->ex_flags
& MNT_DELEXPORT
) {
2239 vfs_free_addrlist(nep
);
2240 mp
->mnt_flag
&= ~(MNT_EXPORTED
| MNT_DEFEXPORTED
);
2242 if (argp
->ex_flags
& MNT_EXPORTED
) {
2243 if (error
= vfs_hang_addrlist(mp
, nep
, argp
))
2245 mp
->mnt_flag
|= MNT_EXPORTED
;
2251 vfs_export_lookup(mp
, nep
, nam
)
2252 register struct mount
*mp
;
2253 struct netexport
*nep
;
2256 register struct netcred
*np
;
2257 register struct radix_node_head
*rnh
;
2258 struct sockaddr
*saddr
;
2261 if (mp
->mnt_flag
& MNT_EXPORTED
) {
2263 * Lookup in the export list first.
2266 saddr
= mtod(nam
, struct sockaddr
*);
2267 rnh
= nep
->ne_rtable
[saddr
->sa_family
];
2269 np
= (struct netcred
*)
2270 (*rnh
->rnh_matchaddr
)((caddr_t
)saddr
,
2272 if (np
&& np
->netc_rnodes
->rn_flags
& RNF_ROOT
)
2277 * If no address match, use the default if it exists.
2279 if (np
== NULL
&& mp
->mnt_flag
& MNT_DEFEXPORTED
)
2280 np
= &nep
->ne_defexported
;
2286 * try to reclaim vnodes from the memory
2290 vm_object_cache_reclaim(int count
)
2293 void vnode_pager_release_from_cache(int *);
2295 /* attempt to reclaim vnodes from VM object cache */
2297 vnode_pager_release_from_cache(&cnt
);
2302 * Release memory object reference held by inactive vnodes
2303 * and then try to reclaim some vnodes from the memory
2307 vnreclaim(int count
)
2317 /* Try to release "count" vnodes from the inactive list */
2319 if (++loopcnt
> inactivevnodes
) {
2321 * I did my best trying to reclaim the vnodes.
2322 * Do not try any more as that would only lead to
2323 * long latencies. Also in the worst case
2324 * this can get totally CPU bound.
2325 * Just fall though and attempt a reclaim of VM
2331 simple_lock(&vnode_free_list_slock
);
2332 for (vp
= TAILQ_FIRST(&vnode_inactive_list
);
2333 (vp
!= NULLVP
) && (i
< count
);
2334 vp
= TAILQ_NEXT(vp
, v_freelist
)) {
2336 if (!simple_lock_try(&vp
->v_interlock
))
2339 if (vp
->v_usecount
!= 1)
2340 panic("vnreclaim: v_usecount");
2342 if(!UBCINFOEXISTS(vp
)) {
2343 if (vp
->v_type
== VBAD
) {
2344 VREMINACTIVE("vnreclaim", vp
);
2345 simple_unlock(&vp
->v_interlock
);
2348 panic("non UBC vnode on inactive list");
2349 /* Should not reach here */
2352 /* If vnode is already being reclaimed, wait */
2353 if ((vp
->v_flag
& VXLOCK
) || (vp
->v_flag
& VORECLAIM
)) {
2354 vp
->v_flag
|= VXWANT
;
2355 simple_unlock(&vp
->v_interlock
);
2356 simple_unlock(&vnode_free_list_slock
);
2357 (void)tsleep((caddr_t
)vp
, PINOD
, "vocr", 0);
2361 VREMINACTIVE("vnreclaim", vp
);
2362 simple_unlock(&vnode_free_list_slock
);
2364 if (ubc_issetflags(vp
, UI_WASMAPPED
)) {
2366 * We should not reclaim as it is likely
2367 * to be in use. Let it die a natural death.
2368 * Release the UBC reference if one exists
2369 * and put it back at the tail.
2371 simple_unlock(&vp
->v_interlock
);
2372 if (ubc_release_named(vp
)) {
2373 if (UBCINFOEXISTS(vp
)) {
2374 simple_lock(&vp
->v_interlock
);
2375 if (vp
->v_usecount
== 1 && !VONLIST(vp
))
2377 simple_unlock(&vp
->v_interlock
);
2380 simple_lock(&vp
->v_interlock
);
2382 simple_unlock(&vp
->v_interlock
);
2387 VORECLAIM_ENABLE(vp
);
2390 * scrub the dirty pages and invalidate the buffers
2393 err
= vn_lock(vp
, LK_EXCLUSIVE
|LK_INTERLOCK
, p
);
2395 /* cannot reclaim */
2396 simple_lock(&vp
->v_interlock
);
2398 VORECLAIM_DISABLE(vp
);
2400 simple_unlock(&vp
->v_interlock
);
2404 /* keep the vnode alive so we can kill it */
2405 simple_lock(&vp
->v_interlock
);
2406 if(vp
->v_usecount
!= 1)
2407 panic("VOCR: usecount race");
2409 simple_unlock(&vp
->v_interlock
);
2411 /* clean up the state in VM without invalidating */
2412 didhold
= ubc_hold(vp
);
2414 (void)ubc_clean(vp
, 0);
2416 /* flush and invalidate buffers associated with the vnode */
2417 if (vp
->v_tag
== VT_NFS
)
2418 nfs_vinvalbuf(vp
, V_SAVE
, NOCRED
, p
, 0);
2420 vinvalbuf(vp
, V_SAVE
, NOCRED
, p
, 0, 0);
2423 * Note: for the v_usecount == 2 case, VOP_INACTIVE
2424 * has not yet been called. Call it now while vp is
2425 * still locked, it will also release the lock.
2427 if (vp
->v_usecount
== 2)
2428 VOP_INACTIVE(vp
, p
);
2430 VOP_UNLOCK(vp
, 0, p
);
2436 * destroy the ubc named reference.
2437 * If we can't because it is held for I/Os
2438 * in progress, just put it back on the inactive
2439 * list and move on. Otherwise, the paging reference
2440 * is toast (and so is this vnode?).
2442 if (ubc_destroy_named(vp
)) {
2445 simple_lock(&vp
->v_interlock
);
2446 VORECLAIM_DISABLE(vp
);
2447 simple_unlock(&vp
->v_interlock
);
2448 vrele(vp
); /* release extra use we added here */
2450 /* inactive list lock was released, must restart */
2453 simple_unlock(&vnode_free_list_slock
);
2455 vnode_reclaim_tried
+= i
;
2457 i
= vm_object_cache_reclaim(count
);
2458 vnode_objects_reclaimed
+= i
;
2464 * This routine is called from vnode_pager_no_senders()
2465 * which in turn can be called with vnode locked by vnode_uncache()
2466 * But it could also get called as a result of vm_object_cache_trim().
2467 * In that case lock state is unknown.
2468 * AGE the vnode so that it gets recycled quickly.
2469 * Check lock status to decide whether to call vput() or vrele().
2471 __private_extern__
void
2472 vnode_pager_vrele(struct vnode
*vp
)
2475 boolean_t funnel_state
;
2476 int isvnreclaim
= 1;
2478 if (vp
== (struct vnode
*) NULL
)
2479 panic("vnode_pager_vrele: null vp");
2481 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2483 /* Mark the vnode to be recycled */
2486 simple_lock(&vp
->v_interlock
);
2488 * If a vgone (or vclean) is already in progress,
2489 * Do not bother with the ubc_info cleanup.
2490 * Let the vclean deal with it.
2492 if (vp
->v_flag
& VXLOCK
) {
2493 CLR(vp
->v_flag
, VTERMINATE
);
2494 if (ISSET(vp
->v_flag
, VTERMWANT
)) {
2495 CLR(vp
->v_flag
, VTERMWANT
);
2496 wakeup((caddr_t
)&vp
->v_ubcinfo
);
2498 simple_unlock(&vp
->v_interlock
);
2500 (void) thread_funnel_set(kernel_flock
, funnel_state
);
2504 /* It's dead, Jim! */
2505 if (!ISSET(vp
->v_flag
, VORECLAIM
)) {
2507 * called as a result of eviction of the memory
2508 * object from the memory object cache
2512 /* So serialize vnode operations */
2513 VORECLAIM_ENABLE(vp
);
2515 if (!ISSET(vp
->v_flag
, VTERMINATE
))
2516 SET(vp
->v_flag
, VTERMINATE
);
2517 if (UBCINFOEXISTS(vp
)) {
2518 struct ubc_info
*uip
= vp
->v_ubcinfo
;
2520 if (ubc_issetflags(vp
, UI_WASMAPPED
))
2521 SET(vp
->v_flag
, VWASMAPPED
);
2523 vp
->v_ubcinfo
= UBC_NOINFO
; /* catch bad accesses */
2524 simple_unlock(&vp
->v_interlock
);
2525 ubc_info_deallocate(uip
);
2527 if ((vp
->v_type
== VBAD
) && ((vp
)->v_ubcinfo
!= UBC_INFO_NULL
)
2528 && ((vp
)->v_ubcinfo
!= UBC_NOINFO
)) {
2529 struct ubc_info
*uip
= vp
->v_ubcinfo
;
2531 vp
->v_ubcinfo
= UBC_NOINFO
; /* catch bad accesses */
2532 simple_unlock(&vp
->v_interlock
);
2533 ubc_info_deallocate(uip
);
2535 simple_unlock(&vp
->v_interlock
);
2539 CLR(vp
->v_flag
, VTERMINATE
);
2541 if (vp
->v_type
!= VBAD
){
2542 vgone(vp
); /* revoke the vnode */
2543 vrele(vp
); /* and drop the reference */
2547 if (ISSET(vp
->v_flag
, VTERMWANT
)) {
2548 CLR(vp
->v_flag
, VTERMWANT
);
2549 wakeup((caddr_t
)&vp
->v_ubcinfo
);
2552 VORECLAIM_DISABLE(vp
);
2553 (void) thread_funnel_set(kernel_flock
, funnel_state
);
2559 int walk_vnodes_debug
=0;
2564 struct mount
*mp
, *nmp
;
2568 for (mp
= mountlist
.cqh_first
; mp
!= (void *)&mountlist
; mp
= nmp
) {
2569 for (vp
= mp
->mnt_vnodelist
.lh_first
;
2571 vp
= vp
->v_mntvnodes
.le_next
) {
2572 if (vp
->v_usecount
< 0){
2573 if(walk_vnodes_debug
) {
2574 printf("vp is %x\n",vp
);
2578 nmp
= mp
->mnt_list
.cqe_next
;
2580 for (cnt
= 0, vp
= vnode_free_list
.tqh_first
;
2581 vp
!= NULLVP
; cnt
++, vp
= vp
->v_freelist
.tqe_next
) {
2582 if ((vp
->v_usecount
< 0) && walk_vnodes_debug
) {
2583 if(walk_vnodes_debug
) {
2584 printf("vp is %x\n",vp
);
2588 printf("%d - free\n", cnt
);
2590 for (cnt
= 0, vp
= vnode_inactive_list
.tqh_first
;
2591 vp
!= NULLVP
; cnt
++, vp
= vp
->v_freelist
.tqe_next
) {
2592 if ((vp
->v_usecount
< 0) && walk_vnodes_debug
) {
2593 if(walk_vnodes_debug
) {
2594 printf("vp is %x\n",vp
);
2598 printf("%d - inactive\n", cnt
);
2600 #endif /* DIAGNOSTIC */
2603 vfs_io_attributes(vp
, flags
, iosize
, vectors
)
2605 int flags
; /* B_READ or B_WRITE */
2611 /* start with "reasonable" defaults */
2619 *iosize
= mp
->mnt_maxreadcnt
;
2620 *vectors
= mp
->mnt_segreadcnt
;
2623 *iosize
= mp
->mnt_maxwritecnt
;
2624 *vectors
= mp
->mnt_segwritecnt
;
2634 #include <dev/disk.h>
2637 vfs_init_io_attributes(devvp
, mp
)
2638 struct vnode
*devvp
;
2643 off_t writeblockcnt
;
2650 struct proc
*p
= current_proc();
2651 struct ucred
*cred
= p
->p_ucred
;
2653 if ((error
= VOP_IOCTL(devvp
, DKIOCGETMAXBLOCKCOUNTREAD
,
2654 (caddr_t
)&readblockcnt
, 0, cred
, p
)))
2657 if ((error
= VOP_IOCTL(devvp
, DKIOCGETMAXBLOCKCOUNTWRITE
,
2658 (caddr_t
)&writeblockcnt
, 0, cred
, p
)))
2661 if ((error
= VOP_IOCTL(devvp
, DKIOCGETMAXSEGMENTCOUNTREAD
,
2662 (caddr_t
)&readsegcnt
, 0, cred
, p
)))
2665 if ((error
= VOP_IOCTL(devvp
, DKIOCGETMAXSEGMENTCOUNTWRITE
,
2666 (caddr_t
)&writesegcnt
, 0, cred
, p
)))
2669 if ((error
= VOP_IOCTL(devvp
, DKIOCGETBLOCKSIZE
,
2670 (caddr_t
)&blksize
, 0, cred
, p
)))
2673 temp
= readblockcnt
* blksize
;
2674 temp
= (temp
> UINT32_MAX
) ? (UINT32_MAX
/ blksize
) * blksize
: temp
;
2675 mp
->mnt_maxreadcnt
= (u_int32_t
)temp
;
2677 temp
= writeblockcnt
* blksize
;
2678 temp
= (temp
> UINT32_MAX
) ? (UINT32_MAX
/ blksize
) * blksize
: temp
;
2679 mp
->mnt_maxwritecnt
= (u_int32_t
)temp
;
2681 temp
= (readsegcnt
> UINT16_MAX
) ? UINT16_MAX
: readsegcnt
;
2682 mp
->mnt_segreadcnt
= (u_int16_t
)temp
;
2684 temp
= (writesegcnt
> UINT16_MAX
) ? UINT16_MAX
: writesegcnt
;
2685 mp
->mnt_segwritecnt
= (u_int16_t
)temp
;
2688 printf("--- IO attributes for mount point 0x%08x ---\n", mp
);
2689 printf("\tmnt_maxreadcnt = 0x%x", mp
->mnt_maxreadcnt
);
2690 printf("\tmnt_maxwritecnt = 0x%x\n", mp
->mnt_maxwritecnt
);
2691 printf("\tmnt_segreadcnt = 0x%x", mp
->mnt_segreadcnt
);
2692 printf("\tmnt_segwritecnt = 0x%x\n", mp
->mnt_segwritecnt
);