kernel - MPSAFE stabilization
[dragonfly.git] / sys / kern / vfs_lock.c
blob2731b5468f0ffa0f0a3e72cd08896c6b0797cfd0
1 /*
2 * Copyright (c) 2004 The DragonFly Project. All rights reserved.
3 *
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@backplane.com>
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
16 * distribution.
17 * 3. Neither the name of The DragonFly Project nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific, prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * SUCH DAMAGE.
34 * $DragonFly: src/sys/kern/vfs_lock.c,v 1.30 2008/06/30 03:57:41 dillon Exp $
38 * External virtual filesystem routines
40 #include "opt_ddb.h"
42 #include <sys/param.h>
43 #include <sys/systm.h>
44 #include <sys/kernel.h>
45 #include <sys/malloc.h>
46 #include <sys/mount.h>
47 #include <sys/proc.h>
48 #include <sys/vnode.h>
49 #include <sys/buf.h>
50 #include <sys/sysctl.h>
52 #include <machine/limits.h>
54 #include <vm/vm.h>
55 #include <vm/vm_object.h>
57 #include <sys/buf2.h>
58 #include <sys/thread2.h>
59 #include <sys/sysref2.h>
61 static void vnode_terminate(struct vnode *vp);
62 static boolean_t vnode_ctor(void *obj, void *private, int ocflags);
63 static void vnode_dtor(void *obj, void *private);
65 static MALLOC_DEFINE(M_VNODE, "vnodes", "vnode structures");
66 static struct sysref_class vnode_sysref_class = {
67 .name = "vnode",
68 .mtype = M_VNODE,
69 .proto = SYSREF_PROTO_VNODE,
70 .offset = offsetof(struct vnode, v_sysref),
71 .objsize = sizeof(struct vnode),
72 .mag_capacity = 256,
73 .flags = SRC_MANAGEDINIT,
74 .ctor = vnode_ctor,
75 .dtor = vnode_dtor,
76 .ops = {
77 .terminate = (sysref_terminate_func_t)vnode_terminate
82 * The vnode free list hold inactive vnodes. Aged inactive vnodes
83 * are inserted prior to the mid point, and otherwise inserted
84 * at the tail.
86 static TAILQ_HEAD(freelst, vnode) vnode_free_list;
87 static struct vnode vnode_free_mid;
88 static struct spinlock vfs_spin = SPINLOCK_INITIALIZER(vfs_spin);
90 int freevnodes = 0;
91 SYSCTL_INT(_debug, OID_AUTO, freevnodes, CTLFLAG_RD,
92 &freevnodes, 0, "");
93 static int wantfreevnodes = 25;
94 SYSCTL_INT(_debug, OID_AUTO, wantfreevnodes, CTLFLAG_RW,
95 &wantfreevnodes, 0, "");
96 #ifdef TRACKVNODE
97 static ulong trackvnode;
98 SYSCTL_ULONG(_debug, OID_AUTO, trackvnode, CTLFLAG_RW,
99 &trackvnode, 0, "");
100 #endif
103 * Called from vfsinit()
105 void
106 vfs_lock_init(void)
108 TAILQ_INIT(&vnode_free_list);
109 TAILQ_INSERT_HEAD(&vnode_free_list, &vnode_free_mid, v_freelist);
110 spin_init(&vfs_spin);
114 * Misc functions
116 static __inline
117 void
118 _vsetflags(struct vnode *vp, int flags)
120 atomic_set_int(&vp->v_flag, flags);
123 static __inline
124 void
125 _vclrflags(struct vnode *vp, int flags)
127 atomic_clear_int(&vp->v_flag, flags);
130 void
131 vsetflags(struct vnode *vp, int flags)
133 _vsetflags(vp, flags);
136 void
137 vclrflags(struct vnode *vp, int flags)
139 _vclrflags(vp, flags);
143 * Inline helper functions. vbusy() and vfree() must be called while
144 * vp->v_spinlock is held.
146 * WARNING! This functions is typically called with v_spinlock held.
148 * MPSAFE
150 static __inline
151 void
152 __vbusy(struct vnode *vp)
154 #ifdef TRACKVNODE
155 if ((ulong)vp == trackvnode)
156 kprintf("__vbusy %p %08x\n", vp, vp->v_flag);
157 #endif
158 spin_lock_wr(&vfs_spin);
159 TAILQ_REMOVE(&vnode_free_list, vp, v_freelist);
160 freevnodes--;
161 _vclrflags(vp, VFREE);
162 spin_unlock_wr(&vfs_spin);
166 * WARNING! This functions is typically called with v_spinlock held.
168 * MPSAFE
170 static __inline
171 void
172 __vfree(struct vnode *vp)
174 #ifdef TRACKVNODE
175 if ((ulong)vp == trackvnode) {
176 kprintf("__vfree %p %08x\n", vp, vp->v_flag);
177 print_backtrace();
179 #endif
180 spin_lock_wr(&vfs_spin);
181 if (vp->v_flag & VRECLAIMED)
182 TAILQ_INSERT_HEAD(&vnode_free_list, vp, v_freelist);
183 else if (vp->v_flag & (VAGE0 | VAGE1))
184 TAILQ_INSERT_BEFORE(&vnode_free_mid, vp, v_freelist);
185 else
186 TAILQ_INSERT_TAIL(&vnode_free_list, vp, v_freelist);
187 freevnodes++;
188 _vsetflags(vp, VFREE);
189 spin_unlock_wr(&vfs_spin);
193 * WARNING! This functions is typically called with v_spinlock held.
195 * MPSAFE
197 static __inline
198 void
199 __vfreetail(struct vnode *vp)
201 #ifdef TRACKVNODE
202 if ((ulong)vp == trackvnode)
203 kprintf("__vfreetail %p %08x\n", vp, vp->v_flag);
204 #endif
205 spin_lock_wr(&vfs_spin);
206 TAILQ_INSERT_TAIL(&vnode_free_list, vp, v_freelist);
207 freevnodes++;
208 _vsetflags(vp, VFREE);
209 spin_unlock_wr(&vfs_spin);
213 * Return a C boolean if we should put the vnode on the freelist (VFREE),
214 * or leave it / mark it as VCACHED.
216 * This routine is only valid if the vnode is already either VFREE or
217 * VCACHED, or if it can become VFREE or VCACHED via vnode_terminate().
219 * WARNING! This functions is typically called with v_spinlock held.
221 * MPSAFE
223 static __inline boolean_t
224 vshouldfree(struct vnode *vp)
226 return (vp->v_auxrefs == 0 &&
227 (vp->v_object == NULL || vp->v_object->resident_page_count == 0));
231 * Add a ref to an active vnode. This function should never be called
232 * with an inactive vnode (use vget() instead).
234 * MPSAFE
236 void
237 vref(struct vnode *vp)
239 KKASSERT(vp->v_sysref.refcnt > 0 &&
240 (vp->v_flag & (VFREE|VINACTIVE)) == 0);
241 sysref_get(&vp->v_sysref);
245 * Release a ref on an active or inactive vnode. The sysref termination
246 * function will be called when the active last active reference is released,
247 * and the vnode is returned to the objcache when the last inactive
248 * reference is released.
250 void
251 vrele(struct vnode *vp)
253 sysref_put(&vp->v_sysref);
257 * Add an auxiliary data structure reference to the vnode. Auxiliary
258 * references do not change the state of the vnode or prevent them
259 * from being deactivated, reclaimed, or placed on the free list.
261 * An auxiliary reference DOES prevent the vnode from being destroyed,
262 * allowing you to vx_lock() it, test state, etc.
264 * An auxiliary reference DOES NOT move a vnode out of the VFREE state
265 * once it has entered it.
267 * MPSAFE
269 void
270 vhold(struct vnode *vp)
272 KKASSERT(vp->v_sysref.refcnt != 0);
273 atomic_add_int(&vp->v_auxrefs, 1);
277 * Remove an auxiliary reference from the vnode.
279 * vdrop needs to check for a VCACHE->VFREE transition to catch cases
280 * where a vnode is held past its reclamation.
282 * MPSAFE
284 void
285 vdrop(struct vnode *vp)
287 KKASSERT(vp->v_sysref.refcnt != 0 && vp->v_auxrefs > 0);
288 spin_lock_wr(&vp->v_spinlock);
289 atomic_subtract_int(&vp->v_auxrefs, 1);
290 if ((vp->v_flag & VCACHED) && vshouldfree(vp)) {
291 _vclrflags(vp, VCACHED);
292 __vfree(vp);
294 spin_unlock_wr(&vp->v_spinlock);
298 * This function is called when the last active reference on the vnode
299 * is released, typically via vrele(). SYSREF will give the vnode a
300 * negative ref count, indicating that it is undergoing termination or
301 * is being set aside for the cache, and one final sysref_put() is
302 * required to actually return it to the memory subsystem.
304 * However, because vnodes may have auxiliary structural references via
305 * v_auxrefs, we must interlock auxiliary references against termination
306 * via the VX lock mechanism. It is possible for a vnode to be reactivated
307 * while we were blocked on the lock.
309 * MPSAFE
311 void
312 vnode_terminate(struct vnode *vp)
314 vx_lock(vp);
315 if (sysref_isinactive(&vp->v_sysref)) {
317 * Deactivate the vnode by marking it VFREE or VCACHED.
318 * The vnode can be reactivated from either state until
319 * reclaimed. These states inherit the 'last' sysref on the
320 * vnode.
322 * NOTE: There may be additional inactive references from
323 * other entities blocking on the VX lock while we hold it,
324 * but this does not prevent us from changing the vnode's
325 * state.
327 * NOTE: The vnode could already be marked inactive. XXX
328 * how?
330 * NOTE: v_mount may be NULL due to assignment to
331 * dead_vnode_vops
333 * NOTE: The vnode may be marked inactive with dirty buffers
334 * or dirty pages in its cached VM object still present.
336 if ((vp->v_flag & VINACTIVE) == 0) {
337 _vsetflags(vp, VINACTIVE);
338 if (vp->v_mount)
339 VOP_INACTIVE(vp);
341 spin_lock_wr(&vp->v_spinlock);
342 KKASSERT((vp->v_flag & (VFREE|VCACHED)) == 0);
343 if (vshouldfree(vp))
344 __vfree(vp);
345 else
346 _vsetflags(vp, VCACHED); /* inactive but not yet free*/
347 spin_unlock_wr(&vp->v_spinlock);
348 vx_unlock(vp);
349 } else {
351 * Someone reactivated the vnode while were blocked on the
352 * VX lock. Release the VX lock and release the (now active)
353 * last reference which is no longer last.
355 vx_unlock(vp);
356 vrele(vp);
361 * Physical vnode constructor / destructor. These are only executed on
362 * the backend of the objcache. They are NOT executed on every vnode
363 * allocation or deallocation.
365 * MPSAFE
367 boolean_t
368 vnode_ctor(void *obj, void *private, int ocflags)
370 struct vnode *vp = obj;
372 lwkt_token_init(&vp->v_token);
373 lockinit(&vp->v_lock, "vnode", 0, 0);
374 ccms_dataspace_init(&vp->v_ccms);
375 TAILQ_INIT(&vp->v_namecache);
376 RB_INIT(&vp->v_rbclean_tree);
377 RB_INIT(&vp->v_rbdirty_tree);
378 RB_INIT(&vp->v_rbhash_tree);
379 return(TRUE);
383 * MPSAFE
385 void
386 vnode_dtor(void *obj, void *private)
388 struct vnode *vp = obj;
390 ccms_dataspace_destroy(&vp->v_ccms);
393 /****************************************************************
394 * VX LOCKING FUNCTIONS *
395 ****************************************************************
397 * These functions lock vnodes for reclamation and deactivation related
398 * activities. The caller must already be holding some sort of reference
399 * on the vnode.
401 * MPSAFE
403 void
404 vx_lock(struct vnode *vp)
406 lockmgr(&vp->v_lock, LK_EXCLUSIVE);
409 static int
410 vx_lock_nonblock(struct vnode *vp)
412 return(lockmgr(&vp->v_lock, LK_EXCLUSIVE | LK_NOWAIT));
415 void
416 vx_unlock(struct vnode *vp)
418 lockmgr(&vp->v_lock, LK_RELEASE);
421 /****************************************************************
422 * VNODE ACQUISITION FUNCTIONS *
423 ****************************************************************
425 * These functions must be used when accessing a vnode via an auxiliary
426 * reference such as the namecache or free list, or when you wish to
427 * do a combo ref+lock sequence.
429 * These functions are MANDATORY for any code chain accessing a vnode
430 * whos activation state is not known.
432 * vget() can be called with LK_NOWAIT and will return EBUSY if the
433 * lock cannot be immediately acquired.
435 * vget()/vput() are used when reactivation is desired.
437 * vx_get() and vx_put() are used when reactivation is not desired.
440 vget(struct vnode *vp, int flags)
442 int error;
445 * A lock type must be passed
447 if ((flags & LK_TYPE_MASK) == 0) {
448 panic("vget() called with no lock specified!");
449 /* NOT REACHED */
453 * Reference the structure and then acquire the lock. 0->1
454 * transitions and refs during termination are allowed here so
455 * call sysref directly.
457 * NOTE: The requested lock might be a shared lock and does
458 * not protect our access to the refcnt or other fields.
460 sysref_get(&vp->v_sysref);
461 if ((error = vn_lock(vp, flags)) != 0) {
463 * The lock failed, undo and return an error.
465 sysref_put(&vp->v_sysref);
466 } else if (vp->v_flag & VRECLAIMED) {
468 * The node is being reclaimed and cannot be reactivated
469 * any more, undo and return ENOENT.
471 vn_unlock(vp);
472 vrele(vp);
473 error = ENOENT;
474 } else {
476 * If the vnode is marked VFREE or VCACHED it needs to be
477 * reactivated, otherwise it had better already be active.
478 * VINACTIVE must also be cleared.
480 * In the VFREE/VCACHED case we have to throw away the
481 * sysref that was earmarking those cases and preventing
482 * the vnode from being destroyed. Our sysref is still held.
484 * The spinlock is our only real protection here.
486 spin_lock_wr(&vp->v_spinlock);
487 if (vp->v_flag & VFREE) {
488 __vbusy(vp);
489 sysref_activate(&vp->v_sysref);
490 spin_unlock_wr(&vp->v_spinlock);
491 sysref_put(&vp->v_sysref);
492 } else if (vp->v_flag & VCACHED) {
493 _vclrflags(vp, VCACHED);
494 sysref_activate(&vp->v_sysref);
495 spin_unlock_wr(&vp->v_spinlock);
496 sysref_put(&vp->v_sysref);
497 } else {
498 if (sysref_isinactive(&vp->v_sysref)) {
499 sysref_activate(&vp->v_sysref);
500 kprintf("Warning vp %p reactivation race\n",
501 vp);
503 spin_unlock_wr(&vp->v_spinlock);
505 _vclrflags(vp, VINACTIVE);
506 error = 0;
508 return(error);
512 * MPSAFE
514 void
515 vput(struct vnode *vp)
517 vn_unlock(vp);
518 vrele(vp);
522 * XXX The vx_*() locks should use auxrefs, not the main reference counter.
524 * MPSAFE
526 void
527 vx_get(struct vnode *vp)
529 sysref_get(&vp->v_sysref);
530 lockmgr(&vp->v_lock, LK_EXCLUSIVE);
534 * MPSAFE
537 vx_get_nonblock(struct vnode *vp)
539 int error;
541 sysref_get(&vp->v_sysref);
542 error = lockmgr(&vp->v_lock, LK_EXCLUSIVE | LK_NOWAIT);
543 if (error)
544 sysref_put(&vp->v_sysref);
545 return(error);
549 * Relase a VX lock that also held a ref on the vnode.
551 * vx_put needs to check for a VCACHE->VFREE transition to catch the
552 * case where e.g. vnlru issues a vgone*().
554 * MPSAFE
556 void
557 vx_put(struct vnode *vp)
559 spin_lock_wr(&vp->v_spinlock);
560 if ((vp->v_flag & VCACHED) && vshouldfree(vp)) {
561 _vclrflags(vp, VCACHED);
562 __vfree(vp);
564 spin_unlock_wr(&vp->v_spinlock);
565 lockmgr(&vp->v_lock, LK_RELEASE);
566 sysref_put(&vp->v_sysref);
570 * Try to reuse a vnode from the free list. NOTE: The returned vnode
571 * is not completely initialized.
573 * MPSAFE
575 static
576 struct vnode *
577 allocfreevnode(void)
579 struct vnode *vp;
580 int count;
582 for (count = 0; count < freevnodes; count++) {
584 * Note that regardless of how we block in this loop,
585 * we only get here if freevnodes != 0 so there
586 * had better be something on the list.
588 * Try to lock the first vnode on the free list.
589 * Cycle if we can't.
591 * XXX NOT MP SAFE
593 spin_lock_wr(&vfs_spin);
594 vp = TAILQ_FIRST(&vnode_free_list);
595 if (vp == &vnode_free_mid)
596 vp = TAILQ_NEXT(vp, v_freelist);
597 if (vx_lock_nonblock(vp)) {
598 KKASSERT(vp->v_flag & VFREE);
599 TAILQ_REMOVE(&vnode_free_list, vp, v_freelist);
600 TAILQ_INSERT_TAIL(&vnode_free_list,
601 vp, v_freelist);
602 spin_unlock_wr(&vfs_spin);
603 continue;
605 spin_unlock_wr(&vfs_spin);
606 #ifdef TRACKVNODE
607 if ((ulong)vp == trackvnode)
608 kprintf("allocfreevnode %p %08x\n", vp, vp->v_flag);
609 #endif
612 * With the vnode locked we can safely remove it
613 * from the free list. We inherit the reference
614 * that was previously associated with the vnode
615 * being on the free list.
617 KKASSERT((vp->v_flag & (VFREE|VINACTIVE)) ==
618 (VFREE|VINACTIVE));
619 KKASSERT(sysref_isinactive(&vp->v_sysref));
620 __vbusy(vp);
623 * Holding the VX lock on an inactive vnode prevents it
624 * from being reactivated or reused. New namecache
625 * associations can only be made using active vnodes.
627 * Another thread may be blocked on our vnode lock while
628 * holding a namecache lock. We can only reuse this vnode
629 * if we can clear all namecache associations without
630 * blocking.
632 if ((vp->v_flag & VRECLAIMED) == 0) {
633 if (cache_inval_vp_nonblock(vp)) {
634 __vfreetail(vp);
635 vx_unlock(vp);
636 continue;
638 vgone_vxlocked(vp);
639 /* vnode is still VX locked */
643 * We can reuse the vnode if no primary or auxiliary
644 * references remain other then ours, else put it
645 * back on the free list and keep looking.
647 * Either the free list inherits the last reference
648 * or we fall through and sysref_activate() the last
649 * reference.
651 * Since the vnode is in a VRECLAIMED state, no new
652 * namecache associations could have been made.
654 KKASSERT(TAILQ_EMPTY(&vp->v_namecache));
655 if (vp->v_auxrefs ||
656 !sysref_islastdeactivation(&vp->v_sysref)) {
657 __vfreetail(vp);
658 vx_unlock(vp);
659 continue;
663 * Return a VX locked vnode suitable for reuse. The caller
664 * inherits the sysref.
666 return(vp);
668 return(NULL);
672 * Obtain a new vnode from the freelist, allocating more if necessary.
673 * The returned vnode is VX locked & refd.
675 * All new vnodes set the VAGE flags. An open() of the vnode will
676 * decrement the (2-bit) flags. Vnodes which are opened several times
677 * are thus retained in the cache over vnodes which are merely stat()d.
679 * MPSAFE
681 struct vnode *
682 allocvnode(int lktimeout, int lkflags)
684 struct vnode *vp;
687 * Try to reuse vnodes if we hit the max. This situation only
688 * occurs in certain large-memory (2G+) situations. We cannot
689 * attempt to directly reclaim vnodes due to nasty recursion
690 * problems.
692 while (numvnodes - freevnodes > desiredvnodes)
693 vnlru_proc_wait();
696 * Try to build up as many vnodes as we can before reallocating
697 * from the free list. A vnode on the free list simply means
698 * that it is inactive with no resident pages. It may or may not
699 * have been reclaimed and could have valuable information associated
700 * with it that we shouldn't throw away unless we really need to.
702 * HAMMER NOTE: Re-establishing a vnode is a fairly expensive
703 * operation for HAMMER but this should benefit UFS as well.
705 if (freevnodes >= wantfreevnodes && numvnodes >= desiredvnodes)
706 vp = allocfreevnode();
707 else
708 vp = NULL;
709 if (vp == NULL) {
710 vp = sysref_alloc(&vnode_sysref_class);
711 lockmgr(&vp->v_lock, LK_EXCLUSIVE);
712 numvnodes++;
716 * We are using a managed sysref class, vnode fields are only
717 * zerod on initial allocation from the backing store, not
718 * on reallocation. Thus we have to clear these fields for both
719 * reallocation and reuse.
721 #ifdef INVARIANTS
722 if (vp->v_data)
723 panic("cleaned vnode isn't");
724 if (bio_track_active(&vp->v_track_read) ||
725 bio_track_active(&vp->v_track_write)) {
726 panic("Clean vnode has pending I/O's");
728 if (vp->v_flag & VONWORKLST)
729 panic("Clean vnode still pending on syncer worklist!");
730 if (!RB_EMPTY(&vp->v_rbdirty_tree))
731 panic("Clean vnode still has dirty buffers!");
732 if (!RB_EMPTY(&vp->v_rbclean_tree))
733 panic("Clean vnode still has clean buffers!");
734 if (!RB_EMPTY(&vp->v_rbhash_tree))
735 panic("Clean vnode still on hash tree!");
736 KKASSERT(vp->v_mount == NULL);
737 #endif
738 vp->v_flag = VAGE0 | VAGE1;
739 vp->v_lastw = 0;
740 vp->v_lasta = 0;
741 vp->v_cstart = 0;
742 vp->v_clen = 0;
743 vp->v_socket = 0;
744 vp->v_opencount = 0;
745 vp->v_writecount = 0; /* XXX */
748 * lktimeout only applies when LK_TIMELOCK is used, and only
749 * the pageout daemon uses it. The timeout may not be zero
750 * or the pageout daemon can deadlock in low-VM situations.
752 if (lktimeout == 0)
753 lktimeout = hz / 10;
754 lockreinit(&vp->v_lock, "vnode", lktimeout, lkflags);
755 KKASSERT(TAILQ_EMPTY(&vp->v_namecache));
756 /* exclusive lock still held */
759 * Note: sysref needs to be activated to convert -0x40000000 to +1.
760 * The -0x40000000 comes from the last ref on reuse, and from
761 * sysref_init() on allocate.
763 sysref_activate(&vp->v_sysref);
764 vp->v_filesize = NOOFFSET;
765 vp->v_type = VNON;
766 vp->v_tag = 0;
767 vp->v_ops = NULL;
768 vp->v_data = NULL;
769 KKASSERT(vp->v_mount == NULL);
771 return (vp);
775 * MPSAFE
778 freesomevnodes(int n)
780 struct vnode *vp;
781 int count = 0;
783 while (n) {
784 --n;
785 if ((vp = allocfreevnode()) == NULL)
786 break;
787 vx_put(vp);
788 --numvnodes;
790 return(count);