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
)) {
681 // XXXdbg - if there are dirty bufs, wait for 'em if they're busy
682 for (bp
=vp
->v_dirtyblkhd
.lh_first
; bp
; bp
=nbp
) {
683 nbp
= bp
->b_vnbufs
.le_next
;
684 if (ISSET(bp
->b_flags
, B_BUSY
)) {
685 SET(bp
->b_flags
, B_WANTED
);
686 tsleep((caddr_t
)bp
, slpflag
| (PRIBIO
+ 1), "vinvalbuf", 0);
687 nbp
= vp
->v_dirtyblkhd
.lh_first
;
689 panic("vinvalbuf: dirty buf (vp 0x%x, bp 0x%x)", vp
, bp
);
695 if ((blist
= vp
->v_cleanblkhd
.lh_first
) && (flags
& V_SAVEMETA
))
696 while (blist
&& blist
->b_lblkno
< 0)
697 blist
= blist
->b_vnbufs
.le_next
;
698 if (!blist
&& (blist
= vp
->v_dirtyblkhd
.lh_first
) &&
699 (flags
& V_SAVEMETA
))
700 while (blist
&& blist
->b_lblkno
< 0)
701 blist
= blist
->b_vnbufs
.le_next
;
705 for (bp
= blist
; bp
; bp
= nbp
) {
706 nbp
= bp
->b_vnbufs
.le_next
;
707 if ((flags
& V_SAVEMETA
) && bp
->b_lblkno
< 0)
710 if (ISSET(bp
->b_flags
, B_BUSY
)) {
711 SET(bp
->b_flags
, B_WANTED
);
712 error
= tsleep((caddr_t
)bp
,
713 slpflag
| (PRIBIO
+ 1), "vinvalbuf",
722 SET(bp
->b_flags
, B_BUSY
);
725 * XXX Since there are no node locks for NFS, I believe
726 * there is a slight chance that a delayed write will
727 * occur while sleeping just above, so check for it.
729 if (ISSET(bp
->b_flags
, B_DELWRI
) && (flags
& V_SAVE
)) {
730 (void) VOP_BWRITE(bp
);
734 if (bp
->b_flags
& B_LOCKED
) {
735 panic("vinvalbuf: bp @ 0x%x is locked!\n", bp
);
738 SET(bp
->b_flags
, B_INVAL
);
743 if (!(flags
& V_SAVEMETA
) &&
744 (vp
->v_dirtyblkhd
.lh_first
|| vp
->v_cleanblkhd
.lh_first
))
745 panic("vinvalbuf: flush failed");
750 * Create a vnode for a block device.
751 * Used for root filesystem, argdev, and swap areas.
752 * Also used for memory file system special devices.
759 register struct vnode
*vp
;
767 error
= getnewvnode(VT_NON
, (struct mount
*)0, spec_vnodeop_p
, &nvp
);
774 if (nvp
= checkalias(vp
, dev
, (struct mount
*)0)) {
783 * Check to see if the new vnode represents a special device
784 * for which we already have a vnode (either because of
785 * bdevvp() or because of a different vnode representing
786 * the same block device). If such an alias exists, deallocate
787 * the existing contents and return the aliased vnode. The
788 * caller is responsible for filling it with its new contents.
791 checkalias(nvp
, nvp_rdev
, mp
)
792 register struct vnode
*nvp
;
796 struct proc
*p
= current_proc(); /* XXX */
799 struct specinfo
* bufhold
;
802 if (nvp
->v_type
!= VBLK
&& nvp
->v_type
!= VCHR
)
805 bufhold
= (struct specinfo
*)_MALLOC_ZONE(sizeof(struct specinfo
),
807 vpp
= &speclisth
[SPECHASH(nvp_rdev
)];
809 simple_lock(&spechash_slock
);
810 for (vp
= *vpp
; vp
; vp
= vp
->v_specnext
) {
811 if (nvp_rdev
!= vp
->v_rdev
|| nvp
->v_type
!= vp
->v_type
)
814 * Alias, but not in use, so flush it out.
816 simple_lock(&vp
->v_interlock
);
817 if (vp
->v_usecount
== 0) {
818 simple_unlock(&spechash_slock
);
822 if (vget(vp
, LK_EXCLUSIVE
| LK_INTERLOCK
, p
)) {
823 simple_unlock(&spechash_slock
);
828 if (vp
== NULL
|| vp
->v_tag
!= VT_NON
) {
829 nvp
->v_specinfo
= bufhold
;
830 buffree
= 0; /* buffer used */
831 bzero(nvp
->v_specinfo
, sizeof(struct specinfo
));
832 nvp
->v_rdev
= nvp_rdev
;
833 nvp
->v_hashchain
= vpp
;
834 nvp
->v_specnext
= *vpp
;
835 nvp
->v_specflags
= 0;
836 simple_unlock(&spechash_slock
);
839 nvp
->v_flag
|= VALIASED
;
840 vp
->v_flag
|= VALIASED
;
843 /* Since buffer is used just return */
846 simple_unlock(&spechash_slock
);
847 VOP_UNLOCK(vp
, 0, p
);
848 simple_lock(&vp
->v_interlock
);
850 vp
->v_op
= nvp
->v_op
;
851 vp
->v_tag
= nvp
->v_tag
;
855 _FREE_ZONE((void *)bufhold
, sizeof (struct specinfo
), M_VNODE
);
860 * Get a reference on a particular vnode and lock it if requested.
861 * If the vnode was on the inactive list, remove it from the list.
862 * If the vnode was on the free list, remove it from the list and
863 * move it to inactive list as needed.
864 * The vnode lock bit is set if the vnode is being eliminated in
865 * vgone. The process is awakened when the transition is completed,
866 * and an error returned to indicate that the vnode is no longer
867 * usable (possibly having been changed to a new file system type).
880 * If the vnode is in the process of being cleaned out for
881 * another use, we wait for the cleaning to finish and then
882 * return failure. Cleaning is determined by checking that
883 * the VXLOCK flag is set.
885 if ((flags
& LK_INTERLOCK
) == 0)
886 simple_lock(&vp
->v_interlock
);
887 if ((vp
->v_flag
& VXLOCK
) || (vp
->v_flag
& VORECLAIM
)) {
888 vp
->v_flag
|= VXWANT
;
889 simple_unlock(&vp
->v_interlock
);
890 (void)tsleep((caddr_t
)vp
, PINOD
, "vget", 0);
895 * vnode is being terminated.
896 * wait for vnode_pager_no_senders() to clear VTERMINATE
898 if (ISSET(vp
->v_flag
, VTERMINATE
)) {
899 SET(vp
->v_flag
, VTERMWANT
);
900 simple_unlock(&vp
->v_interlock
);
901 (void)tsleep((caddr_t
)&vp
->v_ubcinfo
, PINOD
, "vclean", 0);
906 * if the vnode is being initialized,
907 * wait for it to finish initialization
909 if (ISSET(vp
->v_flag
, VUINIT
)) {
910 if (ISSET(vp
->v_flag
, VUINIT
)) {
911 SET(vp
->v_flag
, VUWANT
);
912 simple_unlock(&vp
->v_interlock
);
913 (void) tsleep((caddr_t
)vp
, PINOD
, "vget2", 0);
918 simple_lock(&vnode_free_list_slock
);
919 if (vp
->v_usecount
== 0) {
920 /* If on the free list, remove it from there */
922 VREMFREE("vget", vp
);
924 /* If on the inactive list, remove it from there */
925 if ((vp
->v_usecount
== 1) && UBCINFOEXISTS(vp
)) {
927 VREMINACTIVE("vget", vp
);
931 /* The vnode should not be on the inactive list here */
932 VINACTIVECHECK("vget", vp
, 0);
934 simple_unlock(&vnode_free_list_slock
);
936 if (++vp
->v_usecount
<= 0)
937 panic("vget: v_usecount");
940 * Recover named reference as needed
942 if (UBCISVALID(vp
) && !ubc_issetflags(vp
, UI_HASOBJREF
)) {
943 simple_unlock(&vp
->v_interlock
);
944 if (ubc_getobject(vp
, UBC_HOLDOBJECT
)) {
948 simple_lock(&vp
->v_interlock
);
951 if (flags
& LK_TYPE_MASK
) {
952 if (error
= vn_lock(vp
, flags
| LK_INTERLOCK
, p
))
957 if ((flags
& LK_INTERLOCK
) == 0)
958 simple_unlock(&vp
->v_interlock
);
963 * If the vnode was not active in the first place
964 * must not call vrele() as VOP_INACTIVE() is not
966 * So inlined part of vrele() here.
968 simple_lock(&vp
->v_interlock
);
969 if (--vp
->v_usecount
== 1) {
970 if (UBCINFOEXISTS(vp
)) {
972 simple_unlock(&vp
->v_interlock
);
976 if (vp
->v_usecount
> 0) {
977 simple_unlock(&vp
->v_interlock
);
980 if (vp
->v_usecount
< 0)
981 panic("vget: negative usecount (%d)", vp
->v_usecount
);
983 simple_unlock(&vp
->v_interlock
);
988 * Get a pager reference on the particular vnode.
990 * This is called from ubc_info_init() and it is asumed that
991 * the vnode is neither on the free list on on the inactive list.
992 * It is also assumed that the vnode is neither being recycled
993 * by vgonel nor being terminated by vnode_pager_vrele().
995 * The vnode interlock is NOT held by the caller.
997 __private_extern__
int
1001 simple_lock(&vp
->v_interlock
);
1002 if (UBCINFOMISSING(vp
))
1003 panic("vnode_pager_vget: stolen ubc_info");
1005 if (!UBCINFOEXISTS(vp
))
1006 panic("vnode_pager_vget: lost ubc_info");
1008 if ((vp
->v_flag
& VXLOCK
) || (vp
->v_flag
& VORECLAIM
))
1009 panic("vnode_pager_vget: already being reclaimd");
1011 if (ISSET(vp
->v_flag
, VTERMINATE
))
1012 panic("vnode_pager_vget: already being terminated");
1014 simple_lock(&vnode_free_list_slock
);
1015 /* The vnode should not be on ANY list */
1017 panic("vnode_pager_vget: still on the list");
1019 /* The vnode should not be on the inactive list here */
1020 VINACTIVECHECK("vnode_pager_vget", vp
, 0);
1021 simple_unlock(&vnode_free_list_slock
);
1023 /* After all those checks, now do the real work :-) */
1024 if (++vp
->v_usecount
<= 0)
1025 panic("vnode_pager_vget: v_usecount");
1026 simple_unlock(&vp
->v_interlock
);
1032 * Stubs to use when there is no locking to be done on the underlying object.
1033 * A minimal shared lock is necessary to ensure that the underlying object
1034 * is not revoked while an operation is in progress. So, an active shared
1035 * count is maintained in an auxillary vnode lock structure.
1039 struct vop_lock_args
/* {
1047 * This code cannot be used until all the non-locking filesystems
1048 * (notably NFS) are converted to properly lock and release nodes.
1049 * Also, certain vnode operations change the locking state within
1050 * the operation (create, mknod, remove, link, rename, mkdir, rmdir,
1051 * and symlink). Ideally these operations should not change the
1052 * lock state, but should be changed to let the caller of the
1053 * function unlock them. Otherwise all intermediate vnode layers
1054 * (such as union, umapfs, etc) must catch these functions to do
1055 * the necessary locking at their layer. Note that the inactive
1056 * and lookup operations also change their lock state, but this
1057 * cannot be avoided, so these two operations will always need
1058 * to be handled in intermediate layers.
1060 struct vnode
*vp
= ap
->a_vp
;
1061 int vnflags
, flags
= ap
->a_flags
;
1063 if (vp
->v_vnlock
== NULL
) {
1064 if ((flags
& LK_TYPE_MASK
) == LK_DRAIN
)
1066 MALLOC_ZONE(vp
->v_vnlock
, struct lock__bsd__
*,
1067 sizeof(struct lock__bsd__
), M_VNODE
, M_WAITOK
);
1068 lockinit(vp
->v_vnlock
, PVFS
, "vnlock", 0, 0);
1070 switch (flags
& LK_TYPE_MASK
) {
1076 vnflags
= LK_SHARED
;
1079 case LK_EXCLUPGRADE
:
1084 panic("vop_nolock: bad operation %d", flags
& LK_TYPE_MASK
);
1086 if (flags
& LK_INTERLOCK
)
1087 vnflags
|= LK_INTERLOCK
;
1088 return(lockmgr(vp
->v_vnlock
, vnflags
, &vp
->v_interlock
, ap
->a_p
));
1091 * Since we are not using the lock manager, we must clear
1092 * the interlock here.
1094 if (ap
->a_flags
& LK_INTERLOCK
)
1095 simple_unlock(&ap
->a_vp
->v_interlock
);
1101 * Decrement the active use count.
1105 struct vop_unlock_args
/* {
1111 struct vnode
*vp
= ap
->a_vp
;
1113 if (vp
->v_vnlock
== NULL
)
1115 return (lockmgr(vp
->v_vnlock
, LK_RELEASE
, NULL
, ap
->a_p
));
1119 * Return whether or not the node is in use.
1123 struct vop_islocked_args
/* {
1127 struct vnode
*vp
= ap
->a_vp
;
1129 if (vp
->v_vnlock
== NULL
)
1131 return (lockstatus(vp
->v_vnlock
));
1142 simple_lock(&vp
->v_interlock
);
1143 if (vp
->v_usecount
<= 0)
1144 panic("vref used where vget required");
1146 /* If on the inactive list, remove it from there */
1147 if ((vp
->v_usecount
== 1) && UBCINFOEXISTS(vp
)) {
1149 simple_lock(&vnode_free_list_slock
);
1150 VREMINACTIVE("vref", vp
);
1151 simple_unlock(&vnode_free_list_slock
);
1154 /* The vnode should not be on the inactive list here */
1155 VINACTIVECHECK("vref", vp
, 0);
1157 if (++vp
->v_usecount
<= 0)
1158 panic("vref v_usecount");
1159 simple_unlock(&vp
->v_interlock
);
1163 * put the vnode on appropriate free list.
1164 * called with v_interlock held.
1171 * if the vnode is not obtained by calling getnewvnode() we
1172 * are not responsible for the cleanup. Just return.
1174 if (!(vp
->v_flag
& VSTANDARD
)) {
1178 if (vp
->v_usecount
!= 0)
1179 panic("vfree: v_usecount");
1181 /* insert at tail of LRU list or at head if VAGE is set */
1182 simple_lock(&vnode_free_list_slock
);
1185 panic("vfree: vnode still on list");
1187 if (vp
->v_flag
& VAGE
) {
1188 TAILQ_INSERT_HEAD(&vnode_free_list
, vp
, v_freelist
);
1189 vp
->v_flag
&= ~VAGE
;
1191 TAILQ_INSERT_TAIL(&vnode_free_list
, vp
, v_freelist
);
1193 simple_unlock(&vnode_free_list_slock
);
1198 * put the vnode on the inactive list.
1199 * called with v_interlock held
1205 if (!UBCINFOEXISTS(vp
))
1206 panic("vinactive: not a UBC vnode");
1208 if (vp
->v_usecount
!= 1)
1209 panic("vinactive: v_usecount");
1211 simple_lock(&vnode_free_list_slock
);
1214 panic("vinactive: vnode still on list");
1215 VINACTIVECHECK("vinactive", vp
, 0);
1217 TAILQ_INSERT_TAIL(&vnode_inactive_list
, vp
, v_freelist
);
1218 SET(vp
->v_flag
, VUINACTIVE
);
1219 CLR(vp
->v_flag
, (VNOCACHE_DATA
| VRAOFF
));
1222 simple_unlock(&vnode_free_list_slock
);
1228 * vput(), just unlock and vrele()
1234 struct proc
*p
= current_proc(); /* XXX */
1236 simple_lock(&vp
->v_interlock
);
1237 if (--vp
->v_usecount
== 1) {
1238 if (UBCINFOEXISTS(vp
)) {
1240 simple_unlock(&vp
->v_interlock
);
1241 VOP_UNLOCK(vp
, 0, p
);
1245 if (vp
->v_usecount
> 0) {
1246 simple_unlock(&vp
->v_interlock
);
1247 VOP_UNLOCK(vp
, 0, p
);
1251 if (vp
->v_usecount
< 0 || vp
->v_writecount
!= 0) {
1252 vprint("vput: bad ref count", vp
);
1253 panic("vput: v_usecount = %d, v_writecount = %d",
1254 vp
->v_usecount
, vp
->v_writecount
);
1257 if (ISSET((vp
)->v_flag
, VUINACTIVE
) && VONLIST(vp
))
1258 VREMINACTIVE("vrele", vp
);
1260 simple_unlock(&vp
->v_interlock
);
1261 VOP_INACTIVE(vp
, p
);
1263 * The interlock is not held and
1264 * VOP_INCATIVE releases the vnode lock.
1265 * We could block and the vnode might get reactivated
1266 * Can not just call vfree without checking the state
1268 simple_lock(&vp
->v_interlock
);
1270 if (vp
->v_usecount
== 0)
1272 else if ((vp
->v_usecount
== 1) && UBCINFOEXISTS(vp
))
1275 simple_unlock(&vp
->v_interlock
);
1280 * If count drops to zero, call inactive routine and return to freelist.
1286 struct proc
*p
= current_proc(); /* XXX */
1288 simple_lock(&vp
->v_interlock
);
1289 if (--vp
->v_usecount
== 1) {
1290 if (UBCINFOEXISTS(vp
)) {
1292 simple_unlock(&vp
->v_interlock
);
1296 if (vp
->v_usecount
> 0) {
1297 simple_unlock(&vp
->v_interlock
);
1301 if (vp
->v_usecount
< 0 || vp
->v_writecount
!= 0) {
1302 vprint("vrele: bad ref count", vp
);
1303 panic("vrele: ref cnt");
1306 if (ISSET((vp
)->v_flag
, VUINACTIVE
) && VONLIST(vp
))
1307 VREMINACTIVE("vrele", vp
);
1310 if ((vp
->v_flag
& VXLOCK
) || (vp
->v_flag
& VORECLAIM
)) {
1311 /* vnode is being cleaned, just return */
1313 simple_unlock(&vp
->v_interlock
);
1317 if (vn_lock(vp
, LK_EXCLUSIVE
| LK_INTERLOCK
, p
) == 0) {
1318 VOP_INACTIVE(vp
, p
);
1320 * vn_lock releases the interlock and
1321 * VOP_INCATIVE releases the vnode lock.
1322 * We could block and the vnode might get reactivated
1323 * Can not just call vfree without checking the state
1325 simple_lock(&vp
->v_interlock
);
1327 if (vp
->v_usecount
== 0)
1329 else if ((vp
->v_usecount
== 1) && UBCINFOEXISTS(vp
))
1332 simple_unlock(&vp
->v_interlock
);
1337 simple_unlock(&vp
->v_interlock
);
1338 kprintf("vrele: vn_lock() failed for vp = 0x%08x\n", vp
);
1347 simple_lock(&vp
->v_interlock
);
1349 simple_unlock(&vp
->v_interlock
);
1354 * Page or buffer structure gets a reference.
1358 register struct vnode
*vp
;
1361 simple_lock(&vp
->v_interlock
);
1363 simple_unlock(&vp
->v_interlock
);
1367 * Page or buffer structure frees a reference.
1371 register struct vnode
*vp
;
1374 simple_lock(&vp
->v_interlock
);
1375 if (vp
->v_holdcnt
<= 0)
1376 panic("holdrele: holdcnt");
1378 simple_unlock(&vp
->v_interlock
);
1382 * Remove any vnodes in the vnode table belonging to mount point mp.
1384 * If MNT_NOFORCE is specified, there should not be any active ones,
1385 * return error if any are found (nb: this is a user error, not a
1386 * system error). If MNT_FORCE is specified, detach any active vnodes
1390 int busyprt
= 0; /* print out busy vnodes */
1392 struct ctldebug debug1
= { "busyprt", &busyprt
};
1397 vflush(mp
, skipvp
, flags
)
1399 struct vnode
*skipvp
;
1402 struct proc
*p
= current_proc();
1403 struct vnode
*vp
, *nvp
;
1406 simple_lock(&mntvnode_slock
);
1408 for (vp
= mp
->mnt_vnodelist
.lh_first
; vp
; vp
= nvp
) {
1409 if (vp
->v_mount
!= mp
)
1411 nvp
= vp
->v_mntvnodes
.le_next
;
1413 * Skip over a selected vnode.
1418 simple_lock(&vp
->v_interlock
);
1420 * Skip over a vnodes marked VSYSTEM or VNOFLUSH.
1422 if ((flags
& SKIPSYSTEM
) && ((vp
->v_flag
& VSYSTEM
) || (vp
->v_flag
& VNOFLUSH
))) {
1423 simple_unlock(&vp
->v_interlock
);
1427 * Skip over a vnodes marked VSWAP.
1429 if ((flags
& SKIPSWAP
) && (vp
->v_flag
& VSWAP
)) {
1430 simple_unlock(&vp
->v_interlock
);
1434 * If WRITECLOSE is set, only flush out regular file
1435 * vnodes open for writing.
1437 if ((flags
& WRITECLOSE
) &&
1438 (vp
->v_writecount
== 0 || vp
->v_type
!= VREG
)) {
1439 simple_unlock(&vp
->v_interlock
);
1443 * With v_usecount == 0, all we need to do is clear
1444 * out the vnode data structures and we are done.
1446 if (vp
->v_usecount
== 0) {
1447 simple_unlock(&mntvnode_slock
);
1449 simple_lock(&mntvnode_slock
);
1453 * If FORCECLOSE is set, forcibly close the vnode.
1454 * For block or character devices, revert to an
1455 * anonymous device. For all other files, just kill them.
1457 if (flags
& FORCECLOSE
) {
1458 simple_unlock(&mntvnode_slock
);
1459 if (vp
->v_type
!= VBLK
&& vp
->v_type
!= VCHR
) {
1463 vp
->v_op
= spec_vnodeop_p
;
1464 insmntque(vp
, (struct mount
*)0);
1466 simple_lock(&mntvnode_slock
);
1471 vprint("vflush: busy vnode", vp
);
1473 simple_unlock(&vp
->v_interlock
);
1476 simple_unlock(&mntvnode_slock
);
1477 if (busy
&& ((flags
& FORCECLOSE
)==0))
1483 * Disassociate the underlying file system from a vnode.
1484 * The vnode interlock is held on entry.
1487 vclean(vp
, flags
, p
)
1497 * if the vnode is not obtained by calling getnewvnode() we
1498 * are not responsible for the cleanup. Just return.
1500 if (!(vp
->v_flag
& VSTANDARD
)) {
1501 simple_unlock(&vp
->v_interlock
);
1506 * Check to see if the vnode is in use.
1507 * If so we have to reference it before we clean it out
1508 * so that its count cannot fall to zero and generate a
1509 * race against ourselves to recycle it.
1511 if (active
= vp
->v_usecount
)
1512 if (++vp
->v_usecount
<= 0)
1513 panic("vclean: v_usecount");
1515 * Prevent the vnode from being recycled or
1516 * brought into use while we clean it out.
1518 if (vp
->v_flag
& VXLOCK
)
1519 panic("vclean: deadlock");
1520 vp
->v_flag
|= VXLOCK
;
1523 * Even if the count is zero, the VOP_INACTIVE routine may still
1524 * have the object locked while it cleans it out. The VOP_LOCK
1525 * ensures that the VOP_INACTIVE routine is done with its work.
1526 * For active vnodes, it ensures that no other activity can
1527 * occur while the underlying object is being cleaned out.
1529 VOP_LOCK(vp
, LK_DRAIN
| LK_INTERLOCK
, p
);
1532 * if this vnode is on the inactive list
1533 * take it off the list.
1535 if ((active
== 1) &&
1536 (ISSET((vp
)->v_flag
, VUINACTIVE
) && VONLIST(vp
))) {
1537 simple_lock(&vnode_free_list_slock
);
1538 VREMINACTIVE("vclean", vp
);
1539 simple_unlock(&vnode_free_list_slock
);
1543 /* Clean the pages in VM. */
1544 if (active
&& (flags
& DOCLOSE
))
1545 VOP_CLOSE(vp
, IO_NDELAY
, NOCRED
, p
);
1547 /* Clean the pages in VM. */
1548 didhold
= ubc_hold(vp
);
1549 if ((active
) && (didhold
))
1550 (void)ubc_clean(vp
, 0); /* do not invalidate */
1553 * Clean out any buffers associated with the vnode.
1555 if (flags
& DOCLOSE
) {
1556 if (vp
->v_tag
== VT_NFS
)
1557 nfs_vinvalbuf(vp
, V_SAVE
, NOCRED
, p
, 0);
1559 vinvalbuf(vp
, V_SAVE
, NOCRED
, p
, 0, 0);
1563 VOP_INACTIVE(vp
, p
);
1565 VOP_UNLOCK(vp
, 0, p
);
1567 /* Destroy ubc named reference */
1570 ubc_destroy_named(vp
);
1574 * Reclaim the vnode.
1576 if (VOP_RECLAIM(vp
, p
))
1577 panic("vclean: cannot reclaim");
1580 if ((vp
->v_vnlock
->lk_flags
& LK_DRAINED
) == 0)
1581 vprint("vclean: lock not drained", vp
);
1582 FREE_ZONE(vp
->v_vnlock
, sizeof (struct lock__bsd__
), M_VNODE
);
1583 vp
->v_vnlock
= NULL
;
1586 /* It's dead, Jim! */
1587 vp
->v_op
= dead_vnodeop_p
;
1591 * Done with purge, notify sleepers of the grim news.
1593 vp
->v_flag
&= ~VXLOCK
;
1594 if (vp
->v_flag
& VXWANT
) {
1595 vp
->v_flag
&= ~VXWANT
;
1596 wakeup((caddr_t
)vp
);
1604 * Eliminate all activity associated with the requested vnode
1605 * and with all vnodes aliased to the requested vnode.
1609 struct vop_revoke_args
/* {
1614 struct vnode
*vp
, *vq
;
1615 struct proc
*p
= current_proc();
1618 if ((ap
->a_flags
& REVOKEALL
) == 0)
1619 panic("vop_revoke");
1623 simple_lock(&vp
->v_interlock
);
1625 if (vp
->v_flag
& VALIASED
) {
1627 * If a vgone (or vclean) is already in progress,
1628 * wait until it is done and return.
1630 if (vp
->v_flag
& VXLOCK
) {
1631 while (vp
->v_flag
& VXLOCK
) {
1632 vp
->v_flag
|= VXWANT
;
1633 simple_unlock(&vp
->v_interlock
);
1634 (void)tsleep((caddr_t
)vp
, PINOD
, "vop_revokeall", 0);
1639 * Ensure that vp will not be vgone'd while we
1640 * are eliminating its aliases.
1642 vp
->v_flag
|= VXLOCK
;
1643 simple_unlock(&vp
->v_interlock
);
1644 while (vp
->v_flag
& VALIASED
) {
1645 simple_lock(&spechash_slock
);
1646 for (vq
= *vp
->v_hashchain
; vq
; vq
= vq
->v_specnext
) {
1647 if (vq
->v_rdev
!= vp
->v_rdev
||
1648 vq
->v_type
!= vp
->v_type
|| vp
== vq
)
1650 simple_unlock(&spechash_slock
);
1655 simple_unlock(&spechash_slock
);
1658 * Remove the lock so that vgone below will
1659 * really eliminate the vnode after which time
1660 * vgone will awaken any sleepers.
1662 simple_lock(&vp
->v_interlock
);
1663 vp
->v_flag
&= ~VXLOCK
;
1670 * Recycle an unused vnode to the front of the free list.
1671 * Release the passed interlock if the vnode will be recycled.
1674 vrecycle(vp
, inter_lkp
, p
)
1676 struct slock
*inter_lkp
;
1680 simple_lock(&vp
->v_interlock
);
1681 if (vp
->v_usecount
== 0) {
1683 simple_unlock(inter_lkp
);
1687 simple_unlock(&vp
->v_interlock
);
1692 * Eliminate all activity associated with a vnode
1693 * in preparation for reuse.
1699 struct proc
*p
= current_proc();
1701 simple_lock(&vp
->v_interlock
);
1706 * vgone, with the vp interlock held.
1717 * if the vnode is not obtained by calling getnewvnode() we
1718 * are not responsible for the cleanup. Just return.
1720 if (!(vp
->v_flag
& VSTANDARD
)) {
1721 simple_unlock(&vp
->v_interlock
);
1726 * If a vgone (or vclean) is already in progress,
1727 * wait until it is done and return.
1729 if (vp
->v_flag
& VXLOCK
) {
1730 while (vp
->v_flag
& VXLOCK
) {
1731 vp
->v_flag
|= VXWANT
;
1732 simple_unlock(&vp
->v_interlock
);
1733 (void)tsleep((caddr_t
)vp
, PINOD
, "vgone", 0);
1738 * Clean out the filesystem specific data.
1740 vclean(vp
, DOCLOSE
, p
);
1742 * Delete from old mount point vnode list, if on one.
1744 if (vp
->v_mount
!= NULL
)
1745 insmntque(vp
, (struct mount
*)0);
1747 * If special device, remove it from special device alias list
1750 if ((vp
->v_type
== VBLK
|| vp
->v_type
== VCHR
) && vp
->v_specinfo
!= 0) {
1751 simple_lock(&spechash_slock
);
1752 if (*vp
->v_hashchain
== vp
) {
1753 *vp
->v_hashchain
= vp
->v_specnext
;
1755 for (vq
= *vp
->v_hashchain
; vq
; vq
= vq
->v_specnext
) {
1756 if (vq
->v_specnext
!= vp
)
1758 vq
->v_specnext
= vp
->v_specnext
;
1762 panic("missing bdev");
1764 if (vp
->v_flag
& VALIASED
) {
1766 for (vq
= *vp
->v_hashchain
; vq
; vq
= vq
->v_specnext
) {
1767 if (vq
->v_rdev
!= vp
->v_rdev
||
1768 vq
->v_type
!= vp
->v_type
)
1775 panic("missing alias");
1777 vx
->v_flag
&= ~VALIASED
;
1778 vp
->v_flag
&= ~VALIASED
;
1780 simple_unlock(&spechash_slock
);
1781 FREE_ZONE(vp
->v_specinfo
, sizeof (struct specinfo
), M_VNODE
);
1782 vp
->v_specinfo
= NULL
;
1785 * If it is on the freelist and not already at the head,
1786 * move it to the head of the list. The test of the back
1787 * pointer and the reference count of zero is because
1788 * it will be removed from the free list by getnewvnode,
1789 * but will not have its reference count incremented until
1790 * after calling vgone. If the reference count were
1791 * incremented first, vgone would (incorrectly) try to
1792 * close the previous instance of the underlying object.
1793 * So, the back pointer is explicitly set to `0xdeadb' in
1794 * getnewvnode after removing it from the freelist to ensure
1795 * that we do not try to move it here.
1797 if (vp
->v_usecount
== 0) {
1798 simple_lock(&vnode_free_list_slock
);
1799 if ((vp
->v_freelist
.tqe_prev
!= (struct vnode
**)0xdeadb) &&
1800 vnode_free_list
.tqh_first
!= vp
) {
1801 TAILQ_REMOVE(&vnode_free_list
, vp
, v_freelist
);
1802 TAILQ_INSERT_HEAD(&vnode_free_list
, vp
, v_freelist
);
1804 simple_unlock(&vnode_free_list_slock
);
1810 * Lookup a vnode by device number.
1813 vfinddev(dev
, type
, vpp
)
1821 simple_lock(&spechash_slock
);
1822 for (vp
= speclisth
[SPECHASH(dev
)]; vp
; vp
= vp
->v_specnext
) {
1823 if (dev
!= vp
->v_rdev
|| type
!= vp
->v_type
)
1829 simple_unlock(&spechash_slock
);
1834 * Calculate the total number of references to a special device.
1840 struct vnode
*vq
, *vnext
;
1844 if ((vp
->v_flag
& VALIASED
) == 0)
1845 return (vp
->v_usecount
);
1846 simple_lock(&spechash_slock
);
1847 for (count
= 0, vq
= *vp
->v_hashchain
; vq
; vq
= vnext
) {
1848 vnext
= vq
->v_specnext
;
1849 if (vq
->v_rdev
!= vp
->v_rdev
|| vq
->v_type
!= vp
->v_type
)
1852 * Alias, but not in use, so flush it out.
1854 if (vq
->v_usecount
== 0 && vq
!= vp
) {
1855 simple_unlock(&spechash_slock
);
1859 count
+= vq
->v_usecount
;
1861 simple_unlock(&spechash_slock
);
1865 int prtactive
= 0; /* 1 => print out reclaim of active vnodes */
1868 * Print out a description of a vnode.
1870 static char *typename
[] =
1871 { "VNON", "VREG", "VDIR", "VBLK", "VCHR", "VLNK", "VSOCK", "VFIFO", "VBAD" };
1876 register struct vnode
*vp
;
1881 printf("%s: ", label
);
1882 printf("type %s, usecount %d, writecount %d, refcount %d,",
1883 typename
[vp
->v_type
], vp
->v_usecount
, vp
->v_writecount
,
1886 if (vp
->v_flag
& VROOT
)
1887 strcat(buf
, "|VROOT");
1888 if (vp
->v_flag
& VTEXT
)
1889 strcat(buf
, "|VTEXT");
1890 if (vp
->v_flag
& VSYSTEM
)
1891 strcat(buf
, "|VSYSTEM");
1892 if (vp
->v_flag
& VNOFLUSH
)
1893 strcat(buf
, "|VNOFLUSH");
1894 if (vp
->v_flag
& VXLOCK
)
1895 strcat(buf
, "|VXLOCK");
1896 if (vp
->v_flag
& VXWANT
)
1897 strcat(buf
, "|VXWANT");
1898 if (vp
->v_flag
& VBWAIT
)
1899 strcat(buf
, "|VBWAIT");
1900 if (vp
->v_flag
& VALIASED
)
1901 strcat(buf
, "|VALIASED");
1903 printf(" flags (%s)", &buf
[1]);
1904 if (vp
->v_data
== NULL
) {
1914 * List all of the locked vnodes in the system.
1915 * Called when debugging the kernel.
1920 struct proc
*p
= current_proc();
1921 struct mount
*mp
, *nmp
;
1924 printf("Locked vnodes\n");
1925 simple_lock(&mountlist_slock
);
1926 for (mp
= mountlist
.cqh_first
; mp
!= (void *)&mountlist
; mp
= nmp
) {
1927 if (vfs_busy(mp
, LK_NOWAIT
, &mountlist_slock
, p
)) {
1928 nmp
= mp
->mnt_list
.cqe_next
;
1931 for (vp
= mp
->mnt_vnodelist
.lh_first
;
1933 vp
= vp
->v_mntvnodes
.le_next
) {
1934 if (VOP_ISLOCKED(vp
))
1935 vprint((char *)0, vp
);
1937 simple_lock(&mountlist_slock
);
1938 nmp
= mp
->mnt_list
.cqe_next
;
1941 simple_unlock(&mountlist_slock
);
1946 * Top level filesystem related information gathering.
1949 vfs_sysctl(name
, namelen
, oldp
, oldlenp
, newp
, newlen
, p
)
1958 struct vfsconf
*vfsp
;
1961 * The VFS_NUMMNTOPS shouldn't be at name[0] since
1962 * is a VFS generic variable. So now we must check
1963 * namelen so we don't end up covering any UFS
1964 * variables (sinc UFS vfc_typenum is 1).
1966 * It should have been:
1967 * name[0]: VFS_GENERIC
1968 * name[1]: VFS_NUMMNTOPS
1970 if (namelen
== 1 && name
[0] == VFS_NUMMNTOPS
) {
1971 extern unsigned int vfs_nummntops
;
1972 return (sysctl_rdint(oldp
, oldlenp
, newp
, vfs_nummntops
));
1975 /* all sysctl names at this level are at least name and field */
1977 return (ENOTDIR
); /* overloaded */
1978 if (name
[0] != VFS_GENERIC
) {
1979 for (vfsp
= vfsconf
; vfsp
; vfsp
= vfsp
->vfc_next
)
1980 if (vfsp
->vfc_typenum
== name
[0])
1983 return (EOPNOTSUPP
);
1984 return ((*vfsp
->vfc_vfsops
->vfs_sysctl
)(&name
[1], namelen
- 1,
1985 oldp
, oldlenp
, newp
, newlen
, p
));
1988 case VFS_MAXTYPENUM
:
1989 return (sysctl_rdint(oldp
, oldlenp
, newp
, maxvfsconf
));
1992 return (ENOTDIR
); /* overloaded */
1993 for (vfsp
= vfsconf
; vfsp
; vfsp
= vfsp
->vfc_next
)
1994 if (vfsp
->vfc_typenum
== name
[2])
1997 return (EOPNOTSUPP
);
1998 return (sysctl_rdstruct(oldp
, oldlenp
, newp
, vfsp
,
1999 sizeof(struct vfsconf
)));
2001 return (EOPNOTSUPP
);
2004 int kinfo_vdebug
= 1;
2005 #define KINFO_VNODESLOP 10
2007 * Dump vnode list (via sysctl).
2008 * Copyout address of vnode followed by vnode.
2012 sysctl_vnode(where
, sizep
, p
)
2017 struct mount
*mp
, *nmp
;
2018 struct vnode
*nvp
, *vp
;
2019 char *bp
= where
, *savebp
;
2023 #define VPTRSZ sizeof (struct vnode *)
2024 #define VNODESZ sizeof (struct vnode)
2025 if (where
== NULL
) {
2026 *sizep
= (numvnodes
+ KINFO_VNODESLOP
) * (VPTRSZ
+ VNODESZ
);
2029 ewhere
= where
+ *sizep
;
2031 simple_lock(&mountlist_slock
);
2032 for (mp
= mountlist
.cqh_first
; mp
!= (void *)&mountlist
; mp
= nmp
) {
2033 if (vfs_busy(mp
, LK_NOWAIT
, &mountlist_slock
, p
)) {
2034 nmp
= mp
->mnt_list
.cqe_next
;
2039 simple_lock(&mntvnode_slock
);
2040 for (vp
= mp
->mnt_vnodelist
.lh_first
;
2044 * Check that the vp is still associated with
2045 * this filesystem. RACE: could have been
2046 * recycled onto the same filesystem.
2048 if (vp
->v_mount
!= mp
) {
2049 simple_unlock(&mntvnode_slock
);
2051 printf("kinfo: vp changed\n");
2055 nvp
= vp
->v_mntvnodes
.le_next
;
2056 if (bp
+ VPTRSZ
+ VNODESZ
> ewhere
) {
2057 simple_unlock(&mntvnode_slock
);
2058 *sizep
= bp
- where
;
2061 simple_unlock(&mntvnode_slock
);
2062 if ((error
= copyout((caddr_t
)&vp
, bp
, VPTRSZ
)) ||
2063 (error
= copyout((caddr_t
)vp
, bp
+ VPTRSZ
, VNODESZ
)))
2065 bp
+= VPTRSZ
+ VNODESZ
;
2066 simple_lock(&mntvnode_slock
);
2068 simple_unlock(&mntvnode_slock
);
2069 simple_lock(&mountlist_slock
);
2070 nmp
= mp
->mnt_list
.cqe_next
;
2073 simple_unlock(&mountlist_slock
);
2075 *sizep
= bp
- where
;
2080 * Check to see if a filesystem is mounted on a block device.
2089 if (vp
->v_specflags
& SI_MOUNTEDON
)
2091 if (vp
->v_flag
& VALIASED
) {
2092 simple_lock(&spechash_slock
);
2093 for (vq
= *vp
->v_hashchain
; vq
; vq
= vq
->v_specnext
) {
2094 if (vq
->v_rdev
!= vp
->v_rdev
||
2095 vq
->v_type
!= vp
->v_type
)
2097 if (vq
->v_specflags
& SI_MOUNTEDON
) {
2102 simple_unlock(&spechash_slock
);
2108 * Unmount all filesystems. The list is traversed in reverse order
2109 * of mounting to avoid dependencies.
2111 __private_extern__
void
2114 struct mount
*mp
, *nmp
;
2115 struct proc
*p
= current_proc();
2118 * Since this only runs when rebooting, it is not interlocked.
2120 for (mp
= mountlist
.cqh_last
; mp
!= (void *)&mountlist
; mp
= nmp
) {
2121 nmp
= mp
->mnt_list
.cqe_prev
;
2122 (void) dounmount(mp
, MNT_FORCE
, p
);
2127 * Build hash lists of net addresses and hang them off the mount point.
2128 * Called by vfs_export() to set up the lists of export addresses.
2131 vfs_hang_addrlist(mp
, nep
, argp
)
2133 struct netexport
*nep
;
2134 struct export_args
*argp
;
2136 register struct netcred
*np
;
2137 register struct radix_node_head
*rnh
;
2139 struct radix_node
*rn
;
2140 struct sockaddr
*saddr
, *smask
= 0;
2144 if (argp
->ex_addrlen
== 0) {
2145 if (mp
->mnt_flag
& MNT_DEFEXPORTED
)
2147 np
= &nep
->ne_defexported
;
2148 np
->netc_exflags
= argp
->ex_flags
;
2149 np
->netc_anon
= argp
->ex_anon
;
2150 np
->netc_anon
.cr_ref
= 1;
2151 mp
->mnt_flag
|= MNT_DEFEXPORTED
;
2154 i
= sizeof(struct netcred
) + argp
->ex_addrlen
+ argp
->ex_masklen
;
2155 MALLOC(np
, struct netcred
*, i
, M_NETADDR
, M_WAITOK
);
2156 bzero((caddr_t
)np
, i
);
2157 saddr
= (struct sockaddr
*)(np
+ 1);
2158 if (error
= copyin(argp
->ex_addr
, (caddr_t
)saddr
, argp
->ex_addrlen
))
2160 if (saddr
->sa_len
> argp
->ex_addrlen
)
2161 saddr
->sa_len
= argp
->ex_addrlen
;
2162 if (argp
->ex_masklen
) {
2163 smask
= (struct sockaddr
*)((caddr_t
)saddr
+ argp
->ex_addrlen
);
2164 error
= copyin(argp
->ex_addr
, (caddr_t
)smask
, argp
->ex_masklen
);
2167 if (smask
->sa_len
> argp
->ex_masklen
)
2168 smask
->sa_len
= argp
->ex_masklen
;
2170 i
= saddr
->sa_family
;
2171 if ((rnh
= nep
->ne_rtable
[i
]) == 0) {
2173 * Seems silly to initialize every AF when most are not
2174 * used, do so on demand here
2176 for (dom
= domains
; dom
; dom
= dom
->dom_next
)
2177 if (dom
->dom_family
== i
&& dom
->dom_rtattach
) {
2178 dom
->dom_rtattach((void **)&nep
->ne_rtable
[i
],
2182 if ((rnh
= nep
->ne_rtable
[i
]) == 0) {
2187 rn
= (*rnh
->rnh_addaddr
)((caddr_t
)saddr
, (caddr_t
)smask
, rnh
,
2191 * One of the reasons that rnh_addaddr may fail is that
2192 * the entry already exists. To check for this case, we
2193 * look up the entry to see if it is there. If so, we
2194 * do not need to make a new entry but do return success.
2196 _FREE(np
, M_NETADDR
);
2197 rn
= (*rnh
->rnh_matchaddr
)((caddr_t
)saddr
, rnh
);
2198 if (rn
!= 0 && (rn
->rn_flags
& RNF_ROOT
) == 0 &&
2199 ((struct netcred
*)rn
)->netc_exflags
== argp
->ex_flags
&&
2200 !bcmp((caddr_t
)&((struct netcred
*)rn
)->netc_anon
,
2201 (caddr_t
)&argp
->ex_anon
, sizeof(struct ucred
)))
2205 np
->netc_exflags
= argp
->ex_flags
;
2206 np
->netc_anon
= argp
->ex_anon
;
2207 np
->netc_anon
.cr_ref
= 1;
2210 _FREE(np
, M_NETADDR
);
2216 vfs_free_netcred(rn
, w
)
2217 struct radix_node
*rn
;
2220 register struct radix_node_head
*rnh
= (struct radix_node_head
*)w
;
2222 (*rnh
->rnh_deladdr
)(rn
->rn_key
, rn
->rn_mask
, rnh
);
2223 _FREE((caddr_t
)rn
, M_NETADDR
);
2228 * Free the net address hash lists that are hanging off the mount points.
2231 vfs_free_addrlist(nep
)
2232 struct netexport
*nep
;
2235 register struct radix_node_head
*rnh
;
2237 for (i
= 0; i
<= AF_MAX
; i
++)
2238 if (rnh
= nep
->ne_rtable
[i
]) {
2239 (*rnh
->rnh_walktree
)(rnh
, vfs_free_netcred
,
2241 _FREE((caddr_t
)rnh
, M_RTABLE
);
2242 nep
->ne_rtable
[i
] = 0;
2247 vfs_export(mp
, nep
, argp
)
2249 struct netexport
*nep
;
2250 struct export_args
*argp
;
2254 if (argp
->ex_flags
& MNT_DELEXPORT
) {
2255 vfs_free_addrlist(nep
);
2256 mp
->mnt_flag
&= ~(MNT_EXPORTED
| MNT_DEFEXPORTED
);
2258 if (argp
->ex_flags
& MNT_EXPORTED
) {
2259 if (error
= vfs_hang_addrlist(mp
, nep
, argp
))
2261 mp
->mnt_flag
|= MNT_EXPORTED
;
2267 vfs_export_lookup(mp
, nep
, nam
)
2268 register struct mount
*mp
;
2269 struct netexport
*nep
;
2272 register struct netcred
*np
;
2273 register struct radix_node_head
*rnh
;
2274 struct sockaddr
*saddr
;
2277 if (mp
->mnt_flag
& MNT_EXPORTED
) {
2279 * Lookup in the export list first.
2282 saddr
= mtod(nam
, struct sockaddr
*);
2283 rnh
= nep
->ne_rtable
[saddr
->sa_family
];
2285 np
= (struct netcred
*)
2286 (*rnh
->rnh_matchaddr
)((caddr_t
)saddr
,
2288 if (np
&& np
->netc_rnodes
->rn_flags
& RNF_ROOT
)
2293 * If no address match, use the default if it exists.
2295 if (np
== NULL
&& mp
->mnt_flag
& MNT_DEFEXPORTED
)
2296 np
= &nep
->ne_defexported
;
2302 * try to reclaim vnodes from the memory
2306 vm_object_cache_reclaim(int count
)
2309 void vnode_pager_release_from_cache(int *);
2311 /* attempt to reclaim vnodes from VM object cache */
2313 vnode_pager_release_from_cache(&cnt
);
2318 * Release memory object reference held by inactive vnodes
2319 * and then try to reclaim some vnodes from the memory
2323 vnreclaim(int count
)
2333 /* Try to release "count" vnodes from the inactive list */
2335 if (++loopcnt
> inactivevnodes
) {
2337 * I did my best trying to reclaim the vnodes.
2338 * Do not try any more as that would only lead to
2339 * long latencies. Also in the worst case
2340 * this can get totally CPU bound.
2341 * Just fall though and attempt a reclaim of VM
2347 simple_lock(&vnode_free_list_slock
);
2348 for (vp
= TAILQ_FIRST(&vnode_inactive_list
);
2349 (vp
!= NULLVP
) && (i
< count
);
2350 vp
= TAILQ_NEXT(vp
, v_freelist
)) {
2352 if (!simple_lock_try(&vp
->v_interlock
))
2355 if (vp
->v_usecount
!= 1)
2356 panic("vnreclaim: v_usecount");
2358 if(!UBCINFOEXISTS(vp
)) {
2359 if (vp
->v_type
== VBAD
) {
2360 VREMINACTIVE("vnreclaim", vp
);
2361 simple_unlock(&vp
->v_interlock
);
2364 panic("non UBC vnode on inactive list");
2365 /* Should not reach here */
2368 /* If vnode is already being reclaimed, wait */
2369 if ((vp
->v_flag
& VXLOCK
) || (vp
->v_flag
& VORECLAIM
)) {
2370 vp
->v_flag
|= VXWANT
;
2371 simple_unlock(&vp
->v_interlock
);
2372 simple_unlock(&vnode_free_list_slock
);
2373 (void)tsleep((caddr_t
)vp
, PINOD
, "vocr", 0);
2377 VREMINACTIVE("vnreclaim", vp
);
2378 simple_unlock(&vnode_free_list_slock
);
2380 if (ubc_issetflags(vp
, UI_WASMAPPED
)) {
2382 * We should not reclaim as it is likely
2383 * to be in use. Let it die a natural death.
2384 * Release the UBC reference if one exists
2385 * and put it back at the tail.
2387 simple_unlock(&vp
->v_interlock
);
2388 if (ubc_release_named(vp
)) {
2389 if (UBCINFOEXISTS(vp
)) {
2390 simple_lock(&vp
->v_interlock
);
2391 if (vp
->v_usecount
== 1 && !VONLIST(vp
))
2393 simple_unlock(&vp
->v_interlock
);
2396 simple_lock(&vp
->v_interlock
);
2398 simple_unlock(&vp
->v_interlock
);
2403 VORECLAIM_ENABLE(vp
);
2406 * scrub the dirty pages and invalidate the buffers
2409 err
= vn_lock(vp
, LK_EXCLUSIVE
|LK_INTERLOCK
, p
);
2411 /* cannot reclaim */
2412 simple_lock(&vp
->v_interlock
);
2414 VORECLAIM_DISABLE(vp
);
2416 simple_unlock(&vp
->v_interlock
);
2420 /* keep the vnode alive so we can kill it */
2421 simple_lock(&vp
->v_interlock
);
2422 if(vp
->v_usecount
!= 1)
2423 panic("VOCR: usecount race");
2425 simple_unlock(&vp
->v_interlock
);
2427 /* clean up the state in VM without invalidating */
2428 didhold
= ubc_hold(vp
);
2430 (void)ubc_clean(vp
, 0);
2432 /* flush and invalidate buffers associated with the vnode */
2433 if (vp
->v_tag
== VT_NFS
)
2434 nfs_vinvalbuf(vp
, V_SAVE
, NOCRED
, p
, 0);
2436 vinvalbuf(vp
, V_SAVE
, NOCRED
, p
, 0, 0);
2439 * Note: for the v_usecount == 2 case, VOP_INACTIVE
2440 * has not yet been called. Call it now while vp is
2441 * still locked, it will also release the lock.
2443 if (vp
->v_usecount
== 2)
2444 VOP_INACTIVE(vp
, p
);
2446 VOP_UNLOCK(vp
, 0, p
);
2452 * destroy the ubc named reference.
2453 * If we can't because it is held for I/Os
2454 * in progress, just put it back on the inactive
2455 * list and move on. Otherwise, the paging reference
2456 * is toast (and so is this vnode?).
2458 if (ubc_destroy_named(vp
)) {
2461 simple_lock(&vp
->v_interlock
);
2462 VORECLAIM_DISABLE(vp
);
2463 simple_unlock(&vp
->v_interlock
);
2464 vrele(vp
); /* release extra use we added here */
2466 /* inactive list lock was released, must restart */
2469 simple_unlock(&vnode_free_list_slock
);
2471 vnode_reclaim_tried
+= i
;
2473 i
= vm_object_cache_reclaim(count
);
2474 vnode_objects_reclaimed
+= i
;
2480 * This routine is called from vnode_pager_no_senders()
2481 * which in turn can be called with vnode locked by vnode_uncache()
2482 * But it could also get called as a result of vm_object_cache_trim().
2483 * In that case lock state is unknown.
2484 * AGE the vnode so that it gets recycled quickly.
2485 * Check lock status to decide whether to call vput() or vrele().
2487 __private_extern__
void
2488 vnode_pager_vrele(struct vnode
*vp
)
2491 boolean_t funnel_state
;
2492 int isvnreclaim
= 1;
2494 if (vp
== (struct vnode
*) NULL
)
2495 panic("vnode_pager_vrele: null vp");
2497 funnel_state
= thread_funnel_set(kernel_flock
, TRUE
);
2499 /* Mark the vnode to be recycled */
2502 simple_lock(&vp
->v_interlock
);
2504 * If a vgone (or vclean) is already in progress,
2505 * Do not bother with the ubc_info cleanup.
2506 * Let the vclean deal with it.
2508 if (vp
->v_flag
& VXLOCK
) {
2509 CLR(vp
->v_flag
, VTERMINATE
);
2510 if (ISSET(vp
->v_flag
, VTERMWANT
)) {
2511 CLR(vp
->v_flag
, VTERMWANT
);
2512 wakeup((caddr_t
)&vp
->v_ubcinfo
);
2514 simple_unlock(&vp
->v_interlock
);
2516 (void) thread_funnel_set(kernel_flock
, funnel_state
);
2520 /* It's dead, Jim! */
2521 if (!ISSET(vp
->v_flag
, VORECLAIM
)) {
2523 * called as a result of eviction of the memory
2524 * object from the memory object cache
2528 /* So serialize vnode operations */
2529 VORECLAIM_ENABLE(vp
);
2531 if (!ISSET(vp
->v_flag
, VTERMINATE
))
2532 SET(vp
->v_flag
, VTERMINATE
);
2533 if (UBCINFOEXISTS(vp
)) {
2534 struct ubc_info
*uip
= vp
->v_ubcinfo
;
2536 if (ubc_issetflags(vp
, UI_WASMAPPED
))
2537 SET(vp
->v_flag
, VWASMAPPED
);
2539 vp
->v_ubcinfo
= UBC_NOINFO
; /* catch bad accesses */
2540 simple_unlock(&vp
->v_interlock
);
2541 ubc_info_deallocate(uip
);
2543 if ((vp
->v_type
== VBAD
) && ((vp
)->v_ubcinfo
!= UBC_INFO_NULL
)
2544 && ((vp
)->v_ubcinfo
!= UBC_NOINFO
)) {
2545 struct ubc_info
*uip
= vp
->v_ubcinfo
;
2547 vp
->v_ubcinfo
= UBC_NOINFO
; /* catch bad accesses */
2548 simple_unlock(&vp
->v_interlock
);
2549 ubc_info_deallocate(uip
);
2551 simple_unlock(&vp
->v_interlock
);
2555 CLR(vp
->v_flag
, VTERMINATE
);
2557 if (vp
->v_type
!= VBAD
){
2558 vgone(vp
); /* revoke the vnode */
2559 vrele(vp
); /* and drop the reference */
2563 if (ISSET(vp
->v_flag
, VTERMWANT
)) {
2564 CLR(vp
->v_flag
, VTERMWANT
);
2565 wakeup((caddr_t
)&vp
->v_ubcinfo
);
2568 VORECLAIM_DISABLE(vp
);
2569 (void) thread_funnel_set(kernel_flock
, funnel_state
);
2575 int walk_vnodes_debug
=0;
2580 struct mount
*mp
, *nmp
;
2584 for (mp
= mountlist
.cqh_first
; mp
!= (void *)&mountlist
; mp
= nmp
) {
2585 for (vp
= mp
->mnt_vnodelist
.lh_first
;
2587 vp
= vp
->v_mntvnodes
.le_next
) {
2588 if (vp
->v_usecount
< 0){
2589 if(walk_vnodes_debug
) {
2590 printf("vp is %x\n",vp
);
2594 nmp
= mp
->mnt_list
.cqe_next
;
2596 for (cnt
= 0, vp
= vnode_free_list
.tqh_first
;
2597 vp
!= NULLVP
; cnt
++, vp
= vp
->v_freelist
.tqe_next
) {
2598 if ((vp
->v_usecount
< 0) && walk_vnodes_debug
) {
2599 if(walk_vnodes_debug
) {
2600 printf("vp is %x\n",vp
);
2604 printf("%d - free\n", cnt
);
2606 for (cnt
= 0, vp
= vnode_inactive_list
.tqh_first
;
2607 vp
!= NULLVP
; cnt
++, vp
= vp
->v_freelist
.tqe_next
) {
2608 if ((vp
->v_usecount
< 0) && walk_vnodes_debug
) {
2609 if(walk_vnodes_debug
) {
2610 printf("vp is %x\n",vp
);
2614 printf("%d - inactive\n", cnt
);
2616 #endif /* DIAGNOSTIC */
2619 vfs_io_attributes(vp
, flags
, iosize
, vectors
)
2621 int flags
; /* B_READ or B_WRITE */
2627 /* start with "reasonable" defaults */
2635 *iosize
= mp
->mnt_maxreadcnt
;
2636 *vectors
= mp
->mnt_segreadcnt
;
2639 *iosize
= mp
->mnt_maxwritecnt
;
2640 *vectors
= mp
->mnt_segwritecnt
;
2650 #include <dev/disk.h>
2653 vfs_init_io_attributes(devvp
, mp
)
2654 struct vnode
*devvp
;
2659 off_t writeblockcnt
;
2666 struct proc
*p
= current_proc();
2667 struct ucred
*cred
= p
->p_ucred
;
2669 if ((error
= VOP_IOCTL(devvp
, DKIOCGETMAXBLOCKCOUNTREAD
,
2670 (caddr_t
)&readblockcnt
, 0, cred
, p
)))
2673 if ((error
= VOP_IOCTL(devvp
, DKIOCGETMAXBLOCKCOUNTWRITE
,
2674 (caddr_t
)&writeblockcnt
, 0, cred
, p
)))
2677 if ((error
= VOP_IOCTL(devvp
, DKIOCGETMAXSEGMENTCOUNTREAD
,
2678 (caddr_t
)&readsegcnt
, 0, cred
, p
)))
2681 if ((error
= VOP_IOCTL(devvp
, DKIOCGETMAXSEGMENTCOUNTWRITE
,
2682 (caddr_t
)&writesegcnt
, 0, cred
, p
)))
2685 if ((error
= VOP_IOCTL(devvp
, DKIOCGETBLOCKSIZE
,
2686 (caddr_t
)&blksize
, 0, cred
, p
)))
2689 temp
= readblockcnt
* blksize
;
2690 temp
= (temp
> UINT32_MAX
) ? (UINT32_MAX
/ blksize
) * blksize
: temp
;
2691 mp
->mnt_maxreadcnt
= (u_int32_t
)temp
;
2693 temp
= writeblockcnt
* blksize
;
2694 temp
= (temp
> UINT32_MAX
) ? (UINT32_MAX
/ blksize
) * blksize
: temp
;
2695 mp
->mnt_maxwritecnt
= (u_int32_t
)temp
;
2697 temp
= (readsegcnt
> UINT16_MAX
) ? UINT16_MAX
: readsegcnt
;
2698 mp
->mnt_segreadcnt
= (u_int16_t
)temp
;
2700 temp
= (writesegcnt
> UINT16_MAX
) ? UINT16_MAX
: writesegcnt
;
2701 mp
->mnt_segwritecnt
= (u_int16_t
)temp
;
2704 printf("--- IO attributes for mount point 0x%08x ---\n", mp
);
2705 printf("\tmnt_maxreadcnt = 0x%x", mp
->mnt_maxreadcnt
);
2706 printf("\tmnt_maxwritecnt = 0x%x\n", mp
->mnt_maxwritecnt
);
2707 printf("\tmnt_segreadcnt = 0x%x", mp
->mnt_segreadcnt
);
2708 printf("\tmnt_segwritecnt = 0x%x\n", mp
->mnt_segwritecnt
);