2 * Copyright (c) 1989, 1993
3 * The Regents of the University of California. All rights reserved.
4 * (c) UNIX System Laboratories, Inc.
5 * All or some portions of this file are derived from material licensed
6 * to the University of California by American Telephone and Telegraph
7 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
8 * the permission of UNIX System Laboratories, Inc.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 4. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95
38 * External virtual filesystem routines
41 #include <sys/cdefs.h>
42 __FBSDID("$FreeBSD$");
44 #include "opt_compat.h"
46 #include "opt_watchdog.h"
48 #include <sys/param.h>
49 #include <sys/systm.h>
52 #include <sys/condvar.h>
54 #include <sys/dirent.h>
55 #include <sys/event.h>
56 #include <sys/eventhandler.h>
57 #include <sys/extattr.h>
59 #include <sys/fcntl.h>
62 #include <sys/kernel.h>
63 #include <sys/kthread.h>
64 #include <sys/lockf.h>
65 #include <sys/malloc.h>
66 #include <sys/mount.h>
67 #include <sys/namei.h>
69 #include <sys/reboot.h>
70 #include <sys/rwlock.h>
71 #include <sys/sched.h>
72 #include <sys/sleepqueue.h>
75 #include <sys/sysctl.h>
76 #include <sys/syslog.h>
77 #include <sys/vmmeter.h>
78 #include <sys/vnode.h>
79 #include <sys/watchdog.h>
81 #include <machine/stdarg.h>
83 #include <security/mac/mac_framework.h>
86 #include <vm/vm_object.h>
87 #include <vm/vm_extern.h>
89 #include <vm/vm_map.h>
90 #include <vm/vm_page.h>
91 #include <vm/vm_kern.h>
98 static void delmntque(struct vnode *vp);
99 static int flushbuflist(struct bufv *bufv, int flags, struct bufobj *bo,
100 int slpflag, int slptimeo);
101 static void syncer_shutdown(void *arg, int howto);
102 static int vtryrecycle(struct vnode *vp);
103 static void v_incr_usecount(struct vnode *);
104 static void v_decr_usecount(struct vnode *);
105 static void v_decr_useonly(struct vnode *);
106 static void v_upgrade_usecount(struct vnode *);
107 static void vnlru_free(int);
108 static void vgonel(struct vnode *);
109 static void vfs_knllock(void *arg);
110 static void vfs_knlunlock(void *arg);
111 static void vfs_knl_assert_locked(void *arg);
112 static void vfs_knl_assert_unlocked(void *arg);
113 static void destroy_vpollinfo(struct vpollinfo *vi);
116 * Number of vnodes in existence. Increased whenever getnewvnode()
117 * allocates a new vnode, decreased in vdropl() for VI_DOOMED vnode.
119 static unsigned long numvnodes;
121 SYSCTL_ULONG(_vfs, OID_AUTO, numvnodes, CTLFLAG_RD, &numvnodes, 0,
122 "Number of vnodes in existence");
125 * Conversion tables for conversion from vnode types to inode formats
128 enum vtype iftovt_tab[16] = {
129 VNON, VFIFO, VCHR, VNON, VDIR, VNON, VBLK, VNON,
130 VREG, VNON, VLNK, VNON, VSOCK, VNON, VNON, VBAD,
132 int vttoif_tab[10] = {
133 0, S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK,
134 S_IFSOCK, S_IFIFO, S_IFMT, S_IFMT
138 * List of vnodes that are ready for recycling.
140 static TAILQ_HEAD(freelst, vnode) vnode_free_list;
143 * Free vnode target. Free vnodes may simply be files which have been stat'd
144 * but not read. This is somewhat common, and a small cache of such files
145 * should be kept to avoid recreation costs.
147 static u_long wantfreevnodes;
148 SYSCTL_ULONG(_vfs, OID_AUTO, wantfreevnodes, CTLFLAG_RW, &wantfreevnodes, 0, "");
149 /* Number of vnodes in the free list. */
150 static u_long freevnodes;
151 SYSCTL_ULONG(_vfs, OID_AUTO, freevnodes, CTLFLAG_RD, &freevnodes, 0,
152 "Number of vnodes in the free list");
154 static int vlru_allow_cache_src;
155 SYSCTL_INT(_vfs, OID_AUTO, vlru_allow_cache_src, CTLFLAG_RW,
156 &vlru_allow_cache_src, 0, "Allow vlru to reclaim source vnode");
159 * Various variables used for debugging the new implementation of
161 * XXX these are probably of (very) limited utility now.
163 static int reassignbufcalls;
164 SYSCTL_INT(_vfs, OID_AUTO, reassignbufcalls, CTLFLAG_RW, &reassignbufcalls, 0,
165 "Number of calls to reassignbuf");
168 * Cache for the mount type id assigned to NFS. This is used for
169 * special checks in nfs/nfs_nqlease.c and vm/vnode_pager.c.
171 int nfs_mount_type = -1;
173 /* To keep more than one thread at a time from running vfs_getnewfsid */
174 static struct mtx mntid_mtx;
177 * Lock for any access to the following:
182 static struct mtx vnode_free_list_mtx;
184 /* Publicly exported FS */
185 struct nfs_public nfs_pub;
187 /* Zone for allocation of new vnodes - used exclusively by getnewvnode() */
188 static uma_zone_t vnode_zone;
189 static uma_zone_t vnodepoll_zone;
192 * The workitem queue.
194 * It is useful to delay writes of file data and filesystem metadata
195 * for tens of seconds so that quickly created and deleted files need
196 * not waste disk bandwidth being created and removed. To realize this,
197 * we append vnodes to a "workitem" queue. When running with a soft
198 * updates implementation, most pending metadata dependencies should
199 * not wait for more than a few seconds. Thus, mounted on block devices
200 * are delayed only about a half the time that file data is delayed.
201 * Similarly, directory updates are more critical, so are only delayed
202 * about a third the time that file data is delayed. Thus, there are
203 * SYNCER_MAXDELAY queues that are processed round-robin at a rate of
204 * one each second (driven off the filesystem syncer process). The
205 * syncer_delayno variable indicates the next queue that is to be processed.
206 * Items that need to be processed soon are placed in this queue:
208 * syncer_workitem_pending[syncer_delayno]
210 * A delay of fifteen seconds is done by placing the request fifteen
211 * entries later in the queue:
213 * syncer_workitem_pending[(syncer_delayno + 15) & syncer_mask]
216 static int syncer_delayno;
217 static long syncer_mask;
218 LIST_HEAD(synclist, bufobj);
219 static struct synclist *syncer_workitem_pending;
221 * The sync_mtx protects:
226 * syncer_workitem_pending
227 * syncer_worklist_len
230 static struct mtx sync_mtx;
231 static struct cv sync_wakeup;
233 #define SYNCER_MAXDELAY 32
234 static int syncer_maxdelay = SYNCER_MAXDELAY; /* maximum delay time */
235 static int syncdelay = 30; /* max time to delay syncing data */
236 static int filedelay = 30; /* time to delay syncing files */
237 SYSCTL_INT(_kern, OID_AUTO, filedelay, CTLFLAG_RW, &filedelay, 0,
238 "Time to delay syncing files (in seconds)");
239 static int dirdelay = 29; /* time to delay syncing directories */
240 SYSCTL_INT(_kern, OID_AUTO, dirdelay, CTLFLAG_RW, &dirdelay, 0,
241 "Time to delay syncing directories (in seconds)");
242 static int metadelay = 28; /* time to delay syncing metadata */
243 SYSCTL_INT(_kern, OID_AUTO, metadelay, CTLFLAG_RW, &metadelay, 0,
244 "Time to delay syncing metadata (in seconds)");
245 static int rushjob; /* number of slots to run ASAP */
246 static int stat_rush_requests; /* number of times I/O speeded up */
247 SYSCTL_INT(_debug, OID_AUTO, rush_requests, CTLFLAG_RW, &stat_rush_requests, 0,
248 "Number of times I/O speeded up (rush requests)");
251 * When shutting down the syncer, run it at four times normal speed.
253 #define SYNCER_SHUTDOWN_SPEEDUP 4
254 static int sync_vnode_count;
255 static int syncer_worklist_len;
256 static enum { SYNCER_RUNNING, SYNCER_SHUTTING_DOWN, SYNCER_FINAL_DELAY }
260 * Number of vnodes we want to exist at any one time. This is mostly used
261 * to size hash tables in vnode-related code. It is normally not used in
262 * getnewvnode(), as wantfreevnodes is normally nonzero.)
264 * XXX desiredvnodes is historical cruft and should not exist.
267 SYSCTL_INT(_kern, KERN_MAXVNODES, maxvnodes, CTLFLAG_RW,
268 &desiredvnodes, 0, "Maximum number of vnodes");
269 SYSCTL_ULONG(_kern, OID_AUTO, minvnodes, CTLFLAG_RW,
270 &wantfreevnodes, 0, "Minimum number of vnodes (legacy)");
271 static int vnlru_nowhere;
272 SYSCTL_INT(_debug, OID_AUTO, vnlru_nowhere, CTLFLAG_RW,
273 &vnlru_nowhere, 0, "Number of times the vnlru process ran without success");
276 * Macros to control when a vnode is freed and recycled. All require
277 * the vnode interlock.
279 #define VCANRECYCLE(vp) (((vp)->v_iflag & VI_FREE) && !(vp)->v_holdcnt)
280 #define VSHOULDFREE(vp) (!((vp)->v_iflag & VI_FREE) && !(vp)->v_holdcnt)
281 #define VSHOULDBUSY(vp) (((vp)->v_iflag & VI_FREE) && (vp)->v_holdcnt)
283 /* Shift count for (uintptr_t)vp to initialize vp->v_hash. */
287 * Initialize the vnode management data structures.
289 * Reevaluate the following cap on the number of vnodes after the physical
290 * memory size exceeds 512GB. In the limit, as the physical memory size
291 * grows, the ratio of physical pages to vnodes approaches sixteen to one.
293 #ifndef MAXVNODES_MAX
294 #define MAXVNODES_MAX (512 * (1024 * 1024 * 1024 / (int)PAGE_SIZE / 16))
297 vntblinit(void *dummy __unused)
300 int physvnodes, virtvnodes;
303 * Desiredvnodes is a function of the physical memory size and the
304 * kernel's heap size. Generally speaking, it scales with the
305 * physical memory size. The ratio of desiredvnodes to physical pages
306 * is one to four until desiredvnodes exceeds 98,304. Thereafter, the
307 * marginal ratio of desiredvnodes to physical pages is one to
308 * sixteen. However, desiredvnodes is limited by the kernel's heap
309 * size. The memory required by desiredvnodes vnodes and vm objects
310 * may not exceed one seventh of the kernel's heap size.
312 physvnodes = maxproc + cnt.v_page_count / 16 + 3 * min(98304 * 4,
313 cnt.v_page_count) / 16;
314 virtvnodes = vm_kmem_size / (7 * (sizeof(struct vm_object) +
315 sizeof(struct vnode)));
316 desiredvnodes = min(physvnodes, virtvnodes);
317 if (desiredvnodes > MAXVNODES_MAX) {
319 printf("Reducing kern.maxvnodes %d -> %d\n",
320 desiredvnodes, MAXVNODES_MAX);
321 desiredvnodes = MAXVNODES_MAX;
323 wantfreevnodes = desiredvnodes / 4;
324 mtx_init(&mntid_mtx, "mntid", NULL, MTX_DEF);
325 TAILQ_INIT(&vnode_free_list);
326 mtx_init(&vnode_free_list_mtx, "vnode_free_list", NULL, MTX_DEF);
327 vnode_zone = uma_zcreate("VNODE", sizeof (struct vnode), NULL, NULL,
328 NULL, NULL, UMA_ALIGN_PTR, 0);
329 vnodepoll_zone = uma_zcreate("VNODEPOLL", sizeof (struct vpollinfo),
330 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
332 * Initialize the filesystem syncer.
334 syncer_workitem_pending = hashinit(syncer_maxdelay, M_VNODE,
336 syncer_maxdelay = syncer_mask + 1;
337 mtx_init(&sync_mtx, "Syncer mtx", NULL, MTX_DEF);
338 cv_init(&sync_wakeup, "syncer");
339 for (i = 1; i <= sizeof(struct vnode); i <<= 1)
343 SYSINIT(vfs, SI_SUB_VFS, SI_ORDER_FIRST, vntblinit, NULL);
347 * Mark a mount point as busy. Used to synchronize access and to delay
348 * unmounting. Eventually, mountlist_mtx is not released on failure.
350 * vfs_busy() is a custom lock, it can block the caller.
351 * vfs_busy() only sleeps if the unmount is active on the mount point.
352 * For a mountpoint mp, vfs_busy-enforced lock is before lock of any
353 * vnode belonging to mp.
355 * Lookup uses vfs_busy() to traverse mount points.
357 * / vnode lock A / vnode lock (/var) D
358 * /var vnode lock B /log vnode lock(/var/log) E
359 * vfs_busy lock C vfs_busy lock F
361 * Within each file system, the lock order is C->A->B and F->D->E.
363 * When traversing across mounts, the system follows that lock order:
369 * The lookup() process for namei("/var") illustrates the process:
370 * VOP_LOOKUP() obtains B while A is held
371 * vfs_busy() obtains a shared lock on F while A and B are held
372 * vput() releases lock on B
373 * vput() releases lock on A
374 * VFS_ROOT() obtains lock on D while shared lock on F is held
375 * vfs_unbusy() releases shared lock on F
376 * vn_lock() obtains lock on deadfs vnode vp_crossmp instead of A.
377 * Attempt to lock A (instead of vp_crossmp) while D is held would
378 * violate the global order, causing deadlocks.
380 * dounmount() locks B while F is drained.
383 vfs_busy(struct mount *mp, int flags)
386 MPASS((flags & ~MBF_MASK) == 0);
387 CTR3(KTR_VFS, "%s: mp %p with flags %d", __func__, mp, flags);
392 * If mount point is currenly being unmounted, sleep until the
393 * mount point fate is decided. If thread doing the unmounting fails,
394 * it will clear MNTK_UNMOUNT flag before waking us up, indicating
395 * that this mount point has survived the unmount attempt and vfs_busy
396 * should retry. Otherwise the unmounter thread will set MNTK_REFEXPIRE
397 * flag in addition to MNTK_UNMOUNT, indicating that mount point is
398 * about to be really destroyed. vfs_busy needs to release its
399 * reference on the mount point in this case and return with ENOENT,
400 * telling the caller that mount mount it tried to busy is no longer
403 while (mp->mnt_kern_flag & MNTK_UNMOUNT) {
404 if (flags & MBF_NOWAIT || mp->mnt_kern_flag & MNTK_REFEXPIRE) {
407 CTR1(KTR_VFS, "%s: failed busying before sleeping",
411 if (flags & MBF_MNTLSTLOCK)
412 mtx_unlock(&mountlist_mtx);
413 mp->mnt_kern_flag |= MNTK_MWAIT;
414 msleep(mp, MNT_MTX(mp), PVFS | PDROP, "vfs_busy", 0);
415 if (flags & MBF_MNTLSTLOCK)
416 mtx_lock(&mountlist_mtx);
419 if (flags & MBF_MNTLSTLOCK)
420 mtx_unlock(&mountlist_mtx);
427 * Free a busy filesystem.
430 vfs_unbusy(struct mount *mp)
433 CTR2(KTR_VFS, "%s: mp %p", __func__, mp);
436 KASSERT(mp->mnt_lockref > 0, ("negative mnt_lockref"));
438 if (mp->mnt_lockref == 0 && (mp->mnt_kern_flag & MNTK_DRAINING) != 0) {
439 MPASS(mp->mnt_kern_flag & MNTK_UNMOUNT);
440 CTR1(KTR_VFS, "%s: waking up waiters", __func__);
441 mp->mnt_kern_flag &= ~MNTK_DRAINING;
442 wakeup(&mp->mnt_lockref);
448 * Lookup a mount point by filesystem identifier.
451 vfs_getvfs(fsid_t *fsid)
455 CTR2(KTR_VFS, "%s: fsid %p", __func__, fsid);
456 mtx_lock(&mountlist_mtx);
457 TAILQ_FOREACH(mp, &mountlist, mnt_list) {
458 if (mp->mnt_stat.f_fsid.val[0] == fsid->val[0] &&
459 mp->mnt_stat.f_fsid.val[1] == fsid->val[1]) {
461 mtx_unlock(&mountlist_mtx);
465 mtx_unlock(&mountlist_mtx);
466 CTR2(KTR_VFS, "%s: lookup failed for %p id", __func__, fsid);
467 return ((struct mount *) 0);
471 * Lookup a mount point by filesystem identifier, busying it before
475 vfs_busyfs(fsid_t *fsid)
480 CTR2(KTR_VFS, "%s: fsid %p", __func__, fsid);
481 mtx_lock(&mountlist_mtx);
482 TAILQ_FOREACH(mp, &mountlist, mnt_list) {
483 if (mp->mnt_stat.f_fsid.val[0] == fsid->val[0] &&
484 mp->mnt_stat.f_fsid.val[1] == fsid->val[1]) {
485 error = vfs_busy(mp, MBF_MNTLSTLOCK);
487 mtx_unlock(&mountlist_mtx);
493 CTR2(KTR_VFS, "%s: lookup failed for %p id", __func__, fsid);
494 mtx_unlock(&mountlist_mtx);
495 return ((struct mount *) 0);
499 * Check if a user can access privileged mount options.
502 vfs_suser(struct mount *mp, struct thread *td)
507 * If the thread is jailed, but this is not a jail-friendly file
508 * system, deny immediately.
510 if (!(mp->mnt_vfc->vfc_flags & VFCF_JAIL) && jailed(td->td_ucred))
514 * If the file system was mounted outside the jail of the calling
515 * thread, deny immediately.
517 if (prison_check(td->td_ucred, mp->mnt_cred) != 0)
521 * If file system supports delegated administration, we don't check
522 * for the PRIV_VFS_MOUNT_OWNER privilege - it will be better verified
523 * by the file system itself.
524 * If this is not the user that did original mount, we check for
525 * the PRIV_VFS_MOUNT_OWNER privilege.
527 if (!(mp->mnt_vfc->vfc_flags & VFCF_DELEGADMIN) &&
528 mp->mnt_cred->cr_uid != td->td_ucred->cr_uid) {
529 if ((error = priv_check(td, PRIV_VFS_MOUNT_OWNER)) != 0)
536 * Get a new unique fsid. Try to make its val[0] unique, since this value
537 * will be used to create fake device numbers for stat(). Also try (but
538 * not so hard) make its val[0] unique mod 2^16, since some emulators only
539 * support 16-bit device numbers. We end up with unique val[0]'s for the
540 * first 2^16 calls and unique val[0]'s mod 2^16 for the first 2^8 calls.
542 * Keep in mind that several mounts may be running in parallel. Starting
543 * the search one past where the previous search terminated is both a
544 * micro-optimization and a defense against returning the same fsid to
548 vfs_getnewfsid(struct mount *mp)
550 static uint16_t mntid_base;
555 CTR2(KTR_VFS, "%s: mp %p", __func__, mp);
556 mtx_lock(&mntid_mtx);
557 mtype = mp->mnt_vfc->vfc_typenum;
558 tfsid.val[1] = mtype;
559 mtype = (mtype & 0xFF) << 24;
561 tfsid.val[0] = makedev(255,
562 mtype | ((mntid_base & 0xFF00) << 8) | (mntid_base & 0xFF));
564 if ((nmp = vfs_getvfs(&tfsid)) == NULL)
568 mp->mnt_stat.f_fsid.val[0] = tfsid.val[0];
569 mp->mnt_stat.f_fsid.val[1] = tfsid.val[1];
570 mtx_unlock(&mntid_mtx);
574 * Knob to control the precision of file timestamps:
576 * 0 = seconds only; nanoseconds zeroed.
577 * 1 = seconds and nanoseconds, accurate within 1/HZ.
578 * 2 = seconds and nanoseconds, truncated to microseconds.
579 * >=3 = seconds and nanoseconds, maximum precision.
581 enum { TSP_SEC, TSP_HZ, TSP_USEC, TSP_NSEC };
583 static int timestamp_precision = TSP_SEC;
584 SYSCTL_INT(_vfs, OID_AUTO, timestamp_precision, CTLFLAG_RW,
585 ×tamp_precision, 0, "File timestamp precision (0: seconds, "
586 "1: sec + ns accurate to 1/HZ, 2: sec + ns truncated to ms, "
587 "3+: sec + ns (max. precision))");
590 * Get a current timestamp.
593 vfs_timestamp(struct timespec *tsp)
597 switch (timestamp_precision) {
599 tsp->tv_sec = time_second;
607 TIMEVAL_TO_TIMESPEC(&tv, tsp);
617 * Set vnode attributes to VNOVAL
620 vattr_null(struct vattr *vap)
624 vap->va_size = VNOVAL;
625 vap->va_bytes = VNOVAL;
626 vap->va_mode = VNOVAL;
627 vap->va_nlink = VNOVAL;
628 vap->va_uid = VNOVAL;
629 vap->va_gid = VNOVAL;
630 vap->va_fsid = VNOVAL;
631 vap->va_fileid = VNOVAL;
632 vap->va_blocksize = VNOVAL;
633 vap->va_rdev = VNOVAL;
634 vap->va_atime.tv_sec = VNOVAL;
635 vap->va_atime.tv_nsec = VNOVAL;
636 vap->va_mtime.tv_sec = VNOVAL;
637 vap->va_mtime.tv_nsec = VNOVAL;
638 vap->va_ctime.tv_sec = VNOVAL;
639 vap->va_ctime.tv_nsec = VNOVAL;
640 vap->va_birthtime.tv_sec = VNOVAL;
641 vap->va_birthtime.tv_nsec = VNOVAL;
642 vap->va_flags = VNOVAL;
643 vap->va_gen = VNOVAL;
648 * This routine is called when we have too many vnodes. It attempts
649 * to free <count> vnodes and will potentially free vnodes that still
650 * have VM backing store (VM backing store is typically the cause
651 * of a vnode blowout so we want to do this). Therefore, this operation
652 * is not considered cheap.
654 * A number of conditions may prevent a vnode from being reclaimed.
655 * the buffer cache may have references on the vnode, a directory
656 * vnode may still have references due to the namei cache representing
657 * underlying files, or the vnode may be in active use. It is not
658 * desireable to reuse such vnodes. These conditions may cause the
659 * number of vnodes to reach some minimum value regardless of what
660 * you set kern.maxvnodes to. Do not set kern.maxvnodes too low.
663 vlrureclaim(struct mount *mp)
672 * Calculate the trigger point, don't allow user
673 * screwups to blow us up. This prevents us from
674 * recycling vnodes with lots of resident pages. We
675 * aren't trying to free memory, we are trying to
678 usevnodes = desiredvnodes;
681 trigger = cnt.v_page_count * 2 / usevnodes;
683 vn_start_write(NULL, &mp, V_WAIT);
685 count = mp->mnt_nvnodelistsize / 10 + 1;
687 vp = TAILQ_FIRST(&mp->mnt_nvnodelist);
688 while (vp != NULL && vp->v_type == VMARKER)
689 vp = TAILQ_NEXT(vp, v_nmntvnodes);
692 TAILQ_REMOVE(&mp->mnt_nvnodelist, vp, v_nmntvnodes);
693 TAILQ_INSERT_TAIL(&mp->mnt_nvnodelist, vp, v_nmntvnodes);
698 * If it's been deconstructed already, it's still
699 * referenced, or it exceeds the trigger, skip it.
701 if (vp->v_usecount ||
702 (!vlru_allow_cache_src &&
703 !LIST_EMPTY(&(vp)->v_cache_src)) ||
704 (vp->v_iflag & VI_DOOMED) != 0 || (vp->v_object != NULL &&
705 vp->v_object->resident_page_count > trigger)) {
711 if (VOP_LOCK(vp, LK_INTERLOCK|LK_EXCLUSIVE|LK_NOWAIT)) {
713 goto next_iter_mntunlocked;
717 * v_usecount may have been bumped after VOP_LOCK() dropped
718 * the vnode interlock and before it was locked again.
720 * It is not necessary to recheck VI_DOOMED because it can
721 * only be set by another thread that holds both the vnode
722 * lock and vnode interlock. If another thread has the
723 * vnode lock before we get to VOP_LOCK() and obtains the
724 * vnode interlock after VOP_LOCK() drops the vnode
725 * interlock, the other thread will be unable to drop the
726 * vnode lock before our VOP_LOCK() call fails.
728 if (vp->v_usecount ||
729 (!vlru_allow_cache_src &&
730 !LIST_EMPTY(&(vp)->v_cache_src)) ||
731 (vp->v_object != NULL &&
732 vp->v_object->resident_page_count > trigger)) {
733 VOP_UNLOCK(vp, LK_INTERLOCK);
734 goto next_iter_mntunlocked;
736 KASSERT((vp->v_iflag & VI_DOOMED) == 0,
737 ("VI_DOOMED unexpectedly detected in vlrureclaim()"));
742 next_iter_mntunlocked:
751 kern_yield(PRI_USER);
756 vn_finished_write(mp);
761 * Attempt to keep the free list at wantfreevnodes length.
764 vnlru_free(int count)
768 mtx_assert(&vnode_free_list_mtx, MA_OWNED);
769 for (; count > 0; count--) {
770 vp = TAILQ_FIRST(&vnode_free_list);
772 * The list can be modified while the free_list_mtx
773 * has been dropped and vp could be NULL here.
777 VNASSERT(vp->v_op != NULL, vp,
778 ("vnlru_free: vnode already reclaimed."));
779 KASSERT((vp->v_iflag & VI_FREE) != 0,
780 ("Removing vnode not on freelist"));
781 KASSERT((vp->v_iflag & VI_ACTIVE) == 0,
782 ("Mangling active vnode"));
783 TAILQ_REMOVE(&vnode_free_list, vp, v_actfreelist);
785 * Don't recycle if we can't get the interlock.
787 if (!VI_TRYLOCK(vp)) {
788 TAILQ_INSERT_TAIL(&vnode_free_list, vp, v_actfreelist);
791 VNASSERT(VCANRECYCLE(vp), vp,
792 ("vp inconsistent on freelist"));
794 vp->v_iflag &= ~VI_FREE;
796 mtx_unlock(&vnode_free_list_mtx);
800 * If the recycled succeeded this vdrop will actually free
801 * the vnode. If not it will simply place it back on
805 mtx_lock(&vnode_free_list_mtx);
809 * Attempt to recycle vnodes in a context that is always safe to block.
810 * Calling vlrurecycle() from the bowels of filesystem code has some
811 * interesting deadlock problems.
813 static struct proc *vnlruproc;
814 static int vnlruproc_sig;
819 struct mount *mp, *nmp;
821 struct proc *p = vnlruproc;
823 EVENTHANDLER_REGISTER(shutdown_pre_sync, kproc_shutdown, p,
827 kproc_suspend_check(p);
828 mtx_lock(&vnode_free_list_mtx);
829 if (freevnodes > wantfreevnodes)
830 vnlru_free(freevnodes - wantfreevnodes);
831 if (numvnodes <= desiredvnodes * 9 / 10) {
833 wakeup(&vnlruproc_sig);
834 msleep(vnlruproc, &vnode_free_list_mtx,
835 PVFS|PDROP, "vlruwt", hz);
838 mtx_unlock(&vnode_free_list_mtx);
840 mtx_lock(&mountlist_mtx);
841 for (mp = TAILQ_FIRST(&mountlist); mp != NULL; mp = nmp) {
842 if (vfs_busy(mp, MBF_NOWAIT | MBF_MNTLSTLOCK)) {
843 nmp = TAILQ_NEXT(mp, mnt_list);
846 done += vlrureclaim(mp);
847 mtx_lock(&mountlist_mtx);
848 nmp = TAILQ_NEXT(mp, mnt_list);
851 mtx_unlock(&mountlist_mtx);
854 /* These messages are temporary debugging aids */
855 if (vnlru_nowhere < 5)
856 printf("vnlru process getting nowhere..\n");
857 else if (vnlru_nowhere == 5)
858 printf("vnlru process messages stopped.\n");
861 tsleep(vnlruproc, PPAUSE, "vlrup", hz * 3);
863 kern_yield(PRI_USER);
867 static struct kproc_desc vnlru_kp = {
872 SYSINIT(vnlru, SI_SUB_KTHREAD_UPDATE, SI_ORDER_FIRST, kproc_start,
876 * Routines having to do with the management of the vnode table.
880 * Try to recycle a freed vnode. We abort if anyone picks up a reference
881 * before we actually vgone(). This function must be called with the vnode
882 * held to prevent the vnode from being returned to the free list midway
886 vtryrecycle(struct vnode *vp)
890 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
891 VNASSERT(vp->v_holdcnt, vp,
892 ("vtryrecycle: Recycling vp %p without a reference.", vp));
894 * This vnode may found and locked via some other list, if so we
895 * can't recycle it yet.
897 if (VOP_LOCK(vp, LK_EXCLUSIVE | LK_NOWAIT) != 0) {
899 "%s: impossible to recycle, vp %p lock is already held",
901 return (EWOULDBLOCK);
904 * Don't recycle if its filesystem is being suspended.
906 if (vn_start_write(vp, &vnmp, V_NOWAIT) != 0) {
909 "%s: impossible to recycle, cannot start the write for %p",
914 * If we got this far, we need to acquire the interlock and see if
915 * anyone picked up this vnode from another list. If not, we will
916 * mark it with DOOMED via vgonel() so that anyone who does find it
920 if (vp->v_usecount) {
921 VOP_UNLOCK(vp, LK_INTERLOCK);
922 vn_finished_write(vnmp);
924 "%s: impossible to recycle, %p is already referenced",
928 if ((vp->v_iflag & VI_DOOMED) == 0)
930 VOP_UNLOCK(vp, LK_INTERLOCK);
931 vn_finished_write(vnmp);
936 * Wait for available vnodes.
939 getnewvnode_wait(int suspended)
942 mtx_assert(&vnode_free_list_mtx, MA_OWNED);
943 if (numvnodes > desiredvnodes) {
946 * File system is beeing suspended, we cannot risk a
947 * deadlock here, so allocate new vnode anyway.
949 if (freevnodes > wantfreevnodes)
950 vnlru_free(freevnodes - wantfreevnodes);
953 if (vnlruproc_sig == 0) {
954 vnlruproc_sig = 1; /* avoid unnecessary wakeups */
957 msleep(&vnlruproc_sig, &vnode_free_list_mtx, PVFS,
960 return (numvnodes > desiredvnodes ? ENFILE : 0);
964 getnewvnode_reserve(u_int count)
969 mtx_lock(&vnode_free_list_mtx);
971 if (getnewvnode_wait(0) == 0) {
977 mtx_unlock(&vnode_free_list_mtx);
981 getnewvnode_drop_reserve(void)
986 mtx_lock(&vnode_free_list_mtx);
987 KASSERT(numvnodes >= td->td_vp_reserv, ("reserve too large"));
988 numvnodes -= td->td_vp_reserv;
989 mtx_unlock(&vnode_free_list_mtx);
990 td->td_vp_reserv = 0;
994 * Return the next vnode from the free list.
997 getnewvnode(const char *tag, struct mount *mp, struct vop_vector *vops,
1005 CTR3(KTR_VFS, "%s: mp %p with tag %s", __func__, mp, tag);
1008 if (td->td_vp_reserv > 0) {
1009 td->td_vp_reserv -= 1;
1012 mtx_lock(&vnode_free_list_mtx);
1014 * Lend our context to reclaim vnodes if they've exceeded the max.
1016 if (freevnodes > wantfreevnodes)
1018 error = getnewvnode_wait(mp != NULL && (mp->mnt_kern_flag &
1020 #if 0 /* XXX Not all VFS_VGET/ffs_vget callers check returns. */
1022 mtx_unlock(&vnode_free_list_mtx);
1027 mtx_unlock(&vnode_free_list_mtx);
1029 vp = (struct vnode *) uma_zalloc(vnode_zone, M_WAITOK|M_ZERO);
1033 vp->v_vnlock = &vp->v_lock;
1034 mtx_init(&vp->v_interlock, "vnode interlock", NULL, MTX_DEF);
1036 * By default, don't allow shared locks unless filesystems
1039 lockinit(vp->v_vnlock, PVFS, tag, VLKTIMEOUT, LK_NOSHARE);
1041 * Initialize bufobj.
1044 bo->__bo_vnode = vp;
1045 mtx_init(BO_MTX(bo), "bufobj interlock", NULL, MTX_DEF);
1046 bo->bo_ops = &buf_ops_bio;
1047 bo->bo_private = vp;
1048 TAILQ_INIT(&bo->bo_clean.bv_hd);
1049 TAILQ_INIT(&bo->bo_dirty.bv_hd);
1051 * Initialize namecache.
1053 LIST_INIT(&vp->v_cache_src);
1054 TAILQ_INIT(&vp->v_cache_dst);
1056 * Finalize various vnode identity bits.
1061 v_incr_usecount(vp);
1065 if (mp != NULL && (mp->mnt_flag & MNT_MULTILABEL) == 0)
1066 mac_vnode_associate_singlelabel(mp, vp);
1067 else if (mp == NULL && vops != &dead_vnodeops)
1068 printf("NULL mp in getnewvnode()\n");
1071 bo->bo_bsize = mp->mnt_stat.f_iosize;
1072 if ((mp->mnt_kern_flag & MNTK_NOKNOTE) != 0)
1073 vp->v_vflag |= VV_NOKNOTE;
1075 rangelock_init(&vp->v_rl);
1078 * For the filesystems which do not use vfs_hash_insert(),
1079 * still initialize v_hash to have vfs_hash_index() useful.
1080 * E.g., nullfs uses vfs_hash_index() on the lower vnode for
1083 vp->v_hash = (uintptr_t)vp >> vnsz2log;
1090 * Delete from old mount point vnode list, if on one.
1093 delmntque(struct vnode *vp)
1103 KASSERT(mp->mnt_activevnodelistsize <= mp->mnt_nvnodelistsize,
1104 ("Active vnode list size %d > Vnode list size %d",
1105 mp->mnt_activevnodelistsize, mp->mnt_nvnodelistsize));
1106 active = vp->v_iflag & VI_ACTIVE;
1107 vp->v_iflag &= ~VI_ACTIVE;
1109 mtx_lock(&vnode_free_list_mtx);
1110 TAILQ_REMOVE(&mp->mnt_activevnodelist, vp, v_actfreelist);
1111 mp->mnt_activevnodelistsize--;
1112 mtx_unlock(&vnode_free_list_mtx);
1116 VNASSERT(mp->mnt_nvnodelistsize > 0, vp,
1117 ("bad mount point vnode list size"));
1118 TAILQ_REMOVE(&mp->mnt_nvnodelist, vp, v_nmntvnodes);
1119 mp->mnt_nvnodelistsize--;
1125 insmntque_stddtr(struct vnode *vp, void *dtr_arg)
1129 vp->v_op = &dead_vnodeops;
1135 * Insert into list of vnodes for the new mount point, if available.
1138 insmntque1(struct vnode *vp, struct mount *mp,
1139 void (*dtr)(struct vnode *, void *), void *dtr_arg)
1142 KASSERT(vp->v_mount == NULL,
1143 ("insmntque: vnode already on per mount vnode list"));
1144 VNASSERT(mp != NULL, vp, ("Don't call insmntque(foo, NULL)"));
1145 ASSERT_VOP_ELOCKED(vp, "insmntque: non-locked vp");
1148 * We acquire the vnode interlock early to ensure that the
1149 * vnode cannot be recycled by another process releasing a
1150 * holdcnt on it before we get it on both the vnode list
1151 * and the active vnode list. The mount mutex protects only
1152 * manipulation of the vnode list and the vnode freelist
1153 * mutex protects only manipulation of the active vnode list.
1154 * Hence the need to hold the vnode interlock throughout.
1158 if (((mp->mnt_kern_flag & MNTK_NOINSMNTQ) != 0 &&
1159 ((mp->mnt_kern_flag & MNTK_UNMOUNTF) != 0 ||
1160 mp->mnt_nvnodelistsize == 0)) &&
1161 (vp->v_vflag & VV_FORCEINSMQ) == 0) {
1170 TAILQ_INSERT_TAIL(&mp->mnt_nvnodelist, vp, v_nmntvnodes);
1171 VNASSERT(mp->mnt_nvnodelistsize >= 0, vp,
1172 ("neg mount point vnode list size"));
1173 mp->mnt_nvnodelistsize++;
1174 KASSERT((vp->v_iflag & VI_ACTIVE) == 0,
1175 ("Activating already active vnode"));
1176 vp->v_iflag |= VI_ACTIVE;
1177 mtx_lock(&vnode_free_list_mtx);
1178 TAILQ_INSERT_HEAD(&mp->mnt_activevnodelist, vp, v_actfreelist);
1179 mp->mnt_activevnodelistsize++;
1180 mtx_unlock(&vnode_free_list_mtx);
1187 insmntque(struct vnode *vp, struct mount *mp)
1190 return (insmntque1(vp, mp, insmntque_stddtr, NULL));
1194 * Flush out and invalidate all buffers associated with a bufobj
1195 * Called with the underlying object locked.
1198 bufobj_invalbuf(struct bufobj *bo, int flags, int slpflag, int slptimeo)
1203 if (flags & V_SAVE) {
1204 error = bufobj_wwait(bo, slpflag, slptimeo);
1209 if (bo->bo_dirty.bv_cnt > 0) {
1211 if ((error = BO_SYNC(bo, MNT_WAIT)) != 0)
1214 * XXX We could save a lock/unlock if this was only
1215 * enabled under INVARIANTS
1218 if (bo->bo_numoutput > 0 || bo->bo_dirty.bv_cnt > 0)
1219 panic("vinvalbuf: dirty bufs");
1223 * If you alter this loop please notice that interlock is dropped and
1224 * reacquired in flushbuflist. Special care is needed to ensure that
1225 * no race conditions occur from this.
1228 error = flushbuflist(&bo->bo_clean,
1229 flags, bo, slpflag, slptimeo);
1230 if (error == 0 && !(flags & V_CLEANONLY))
1231 error = flushbuflist(&bo->bo_dirty,
1232 flags, bo, slpflag, slptimeo);
1233 if (error != 0 && error != EAGAIN) {
1237 } while (error != 0);
1240 * Wait for I/O to complete. XXX needs cleaning up. The vnode can
1241 * have write I/O in-progress but if there is a VM object then the
1242 * VM object can also have read-I/O in-progress.
1245 bufobj_wwait(bo, 0, 0);
1247 if (bo->bo_object != NULL) {
1248 VM_OBJECT_WLOCK(bo->bo_object);
1249 vm_object_pip_wait(bo->bo_object, "bovlbx");
1250 VM_OBJECT_WUNLOCK(bo->bo_object);
1253 } while (bo->bo_numoutput > 0);
1257 * Destroy the copy in the VM cache, too.
1259 if (bo->bo_object != NULL &&
1260 (flags & (V_ALT | V_NORMAL | V_CLEANONLY)) == 0) {
1261 VM_OBJECT_WLOCK(bo->bo_object);
1262 vm_object_page_remove(bo->bo_object, 0, 0, (flags & V_SAVE) ?
1263 OBJPR_CLEANONLY : 0);
1264 VM_OBJECT_WUNLOCK(bo->bo_object);
1269 if ((flags & (V_ALT | V_NORMAL | V_CLEANONLY)) == 0 &&
1270 (bo->bo_dirty.bv_cnt > 0 || bo->bo_clean.bv_cnt > 0))
1271 panic("vinvalbuf: flush failed");
1278 * Flush out and invalidate all buffers associated with a vnode.
1279 * Called with the underlying object locked.
1282 vinvalbuf(struct vnode *vp, int flags, int slpflag, int slptimeo)
1285 CTR3(KTR_VFS, "%s: vp %p with flags %d", __func__, vp, flags);
1286 ASSERT_VOP_LOCKED(vp, "vinvalbuf");
1287 return (bufobj_invalbuf(&vp->v_bufobj, flags, slpflag, slptimeo));
1291 * Flush out buffers on the specified list.
1295 flushbuflist(struct bufv *bufv, int flags, struct bufobj *bo, int slpflag,
1298 struct buf *bp, *nbp;
1303 ASSERT_BO_LOCKED(bo);
1306 TAILQ_FOREACH_SAFE(bp, &bufv->bv_hd, b_bobufs, nbp) {
1307 if (((flags & V_NORMAL) && (bp->b_xflags & BX_ALTDATA)) ||
1308 ((flags & V_ALT) && (bp->b_xflags & BX_ALTDATA) == 0)) {
1314 lblkno = nbp->b_lblkno;
1315 xflags = nbp->b_xflags &
1316 (BX_BKGRDMARKER | BX_VNDIRTY | BX_VNCLEAN);
1319 error = BUF_TIMELOCK(bp,
1320 LK_EXCLUSIVE | LK_SLEEPFAIL | LK_INTERLOCK, BO_MTX(bo),
1321 "flushbuf", slpflag, slptimeo);
1324 return (error != ENOLCK ? error : EAGAIN);
1326 KASSERT(bp->b_bufobj == bo,
1327 ("bp %p wrong b_bufobj %p should be %p",
1328 bp, bp->b_bufobj, bo));
1329 if (bp->b_bufobj != bo) { /* XXX: necessary ? */
1335 * XXX Since there are no node locks for NFS, I
1336 * believe there is a slight chance that a delayed
1337 * write will occur while sleeping just above, so
1340 if (((bp->b_flags & (B_DELWRI | B_INVAL)) == B_DELWRI) &&
1345 bp->b_flags |= B_ASYNC;
1348 return (EAGAIN); /* XXX: why not loop ? */
1353 bp->b_flags |= (B_INVAL | B_RELBUF);
1354 bp->b_flags &= ~B_ASYNC;
1358 (nbp->b_bufobj != bo ||
1359 nbp->b_lblkno != lblkno ||
1361 (BX_BKGRDMARKER | BX_VNDIRTY | BX_VNCLEAN)) != xflags))
1362 break; /* nbp invalid */
1368 * Truncate a file's buffer and pages to a specified length. This
1369 * is in lieu of the old vinvalbuf mechanism, which performed unneeded
1373 vtruncbuf(struct vnode *vp, struct ucred *cred, off_t length, int blksize)
1375 struct buf *bp, *nbp;
1380 CTR5(KTR_VFS, "%s: vp %p with cred %p and block %d:%ju", __func__,
1381 vp, cred, blksize, (uintmax_t)length);
1384 * Round up to the *next* lbn.
1386 trunclbn = (length + blksize - 1) / blksize;
1388 ASSERT_VOP_LOCKED(vp, "vtruncbuf");
1395 TAILQ_FOREACH_SAFE(bp, &bo->bo_clean.bv_hd, b_bobufs, nbp) {
1396 if (bp->b_lblkno < trunclbn)
1399 LK_EXCLUSIVE | LK_SLEEPFAIL | LK_INTERLOCK,
1400 BO_MTX(bo)) == ENOLCK)
1406 bp->b_flags |= (B_INVAL | B_RELBUF);
1407 bp->b_flags &= ~B_ASYNC;
1413 (((nbp->b_xflags & BX_VNCLEAN) == 0) ||
1414 (nbp->b_vp != vp) ||
1415 (nbp->b_flags & B_DELWRI))) {
1421 TAILQ_FOREACH_SAFE(bp, &bo->bo_dirty.bv_hd, b_bobufs, nbp) {
1422 if (bp->b_lblkno < trunclbn)
1425 LK_EXCLUSIVE | LK_SLEEPFAIL | LK_INTERLOCK,
1426 BO_MTX(bo)) == ENOLCK)
1431 bp->b_flags |= (B_INVAL | B_RELBUF);
1432 bp->b_flags &= ~B_ASYNC;
1438 (((nbp->b_xflags & BX_VNDIRTY) == 0) ||
1439 (nbp->b_vp != vp) ||
1440 (nbp->b_flags & B_DELWRI) == 0)) {
1449 TAILQ_FOREACH_SAFE(bp, &bo->bo_dirty.bv_hd, b_bobufs, nbp) {
1450 if (bp->b_lblkno > 0)
1453 * Since we hold the vnode lock this should only
1454 * fail if we're racing with the buf daemon.
1457 LK_EXCLUSIVE | LK_SLEEPFAIL | LK_INTERLOCK,
1458 BO_MTX(bo)) == ENOLCK) {
1461 VNASSERT((bp->b_flags & B_DELWRI), vp,
1462 ("buf(%p) on dirty queue without DELWRI", bp));
1473 bufobj_wwait(bo, 0, 0);
1475 vnode_pager_setsize(vp, length);
1481 * buf_splay() - splay tree core for the clean/dirty list of buffers in
1484 * NOTE: We have to deal with the special case of a background bitmap
1485 * buffer, a situation where two buffers will have the same logical
1486 * block offset. We want (1) only the foreground buffer to be accessed
1487 * in a lookup and (2) must differentiate between the foreground and
1488 * background buffer in the splay tree algorithm because the splay
1489 * tree cannot normally handle multiple entities with the same 'index'.
1490 * We accomplish this by adding differentiating flags to the splay tree's
1495 buf_splay(daddr_t lblkno, b_xflags_t xflags, struct buf *root)
1498 struct buf *lefttreemax, *righttreemin, *y;
1502 lefttreemax = righttreemin = &dummy;
1504 if (lblkno < root->b_lblkno ||
1505 (lblkno == root->b_lblkno &&
1506 (xflags & BX_BKGRDMARKER) < (root->b_xflags & BX_BKGRDMARKER))) {
1507 if ((y = root->b_left) == NULL)
1509 if (lblkno < y->b_lblkno) {
1511 root->b_left = y->b_right;
1514 if ((y = root->b_left) == NULL)
1517 /* Link into the new root's right tree. */
1518 righttreemin->b_left = root;
1519 righttreemin = root;
1520 } else if (lblkno > root->b_lblkno ||
1521 (lblkno == root->b_lblkno &&
1522 (xflags & BX_BKGRDMARKER) > (root->b_xflags & BX_BKGRDMARKER))) {
1523 if ((y = root->b_right) == NULL)
1525 if (lblkno > y->b_lblkno) {
1527 root->b_right = y->b_left;
1530 if ((y = root->b_right) == NULL)
1533 /* Link into the new root's left tree. */
1534 lefttreemax->b_right = root;
1541 /* Assemble the new root. */
1542 lefttreemax->b_right = root->b_left;
1543 righttreemin->b_left = root->b_right;
1544 root->b_left = dummy.b_right;
1545 root->b_right = dummy.b_left;
1550 buf_vlist_remove(struct buf *bp)
1555 KASSERT(bp->b_bufobj != NULL, ("No b_bufobj %p", bp));
1556 ASSERT_BO_LOCKED(bp->b_bufobj);
1557 KASSERT((bp->b_xflags & (BX_VNDIRTY|BX_VNCLEAN)) !=
1558 (BX_VNDIRTY|BX_VNCLEAN),
1559 ("buf_vlist_remove: Buf %p is on two lists", bp));
1560 if (bp->b_xflags & BX_VNDIRTY)
1561 bv = &bp->b_bufobj->bo_dirty;
1563 bv = &bp->b_bufobj->bo_clean;
1564 if (bp != bv->bv_root) {
1565 root = buf_splay(bp->b_lblkno, bp->b_xflags, bv->bv_root);
1566 KASSERT(root == bp, ("splay lookup failed in remove"));
1568 if (bp->b_left == NULL) {
1571 root = buf_splay(bp->b_lblkno, bp->b_xflags, bp->b_left);
1572 root->b_right = bp->b_right;
1575 TAILQ_REMOVE(&bv->bv_hd, bp, b_bobufs);
1577 bp->b_xflags &= ~(BX_VNDIRTY | BX_VNCLEAN);
1581 * Add the buffer to the sorted clean or dirty block list using a
1582 * splay tree algorithm.
1584 * NOTE: xflags is passed as a constant, optimizing this inline function!
1587 buf_vlist_add(struct buf *bp, struct bufobj *bo, b_xflags_t xflags)
1592 ASSERT_BO_LOCKED(bo);
1593 KASSERT((bp->b_xflags & (BX_VNDIRTY|BX_VNCLEAN)) == 0,
1594 ("buf_vlist_add: Buf %p has existing xflags %d", bp, bp->b_xflags));
1595 bp->b_xflags |= xflags;
1596 if (xflags & BX_VNDIRTY)
1601 root = buf_splay(bp->b_lblkno, bp->b_xflags, bv->bv_root);
1605 TAILQ_INSERT_TAIL(&bv->bv_hd, bp, b_bobufs);
1606 } else if (bp->b_lblkno < root->b_lblkno ||
1607 (bp->b_lblkno == root->b_lblkno &&
1608 (bp->b_xflags & BX_BKGRDMARKER) < (root->b_xflags & BX_BKGRDMARKER))) {
1609 bp->b_left = root->b_left;
1611 root->b_left = NULL;
1612 TAILQ_INSERT_BEFORE(root, bp, b_bobufs);
1614 bp->b_right = root->b_right;
1616 root->b_right = NULL;
1617 TAILQ_INSERT_AFTER(&bv->bv_hd, root, bp, b_bobufs);
1624 * Lookup a buffer using the splay tree. Note that we specifically avoid
1625 * shadow buffers used in background bitmap writes.
1627 * This code isn't quite efficient as it could be because we are maintaining
1628 * two sorted lists and do not know which list the block resides in.
1630 * During a "make buildworld" the desired buffer is found at one of
1631 * the roots more than 60% of the time. Thus, checking both roots
1632 * before performing either splay eliminates unnecessary splays on the
1633 * first tree splayed.
1636 gbincore(struct bufobj *bo, daddr_t lblkno)
1640 ASSERT_BO_LOCKED(bo);
1641 if ((bp = bo->bo_clean.bv_root) != NULL &&
1642 bp->b_lblkno == lblkno && !(bp->b_xflags & BX_BKGRDMARKER))
1644 if ((bp = bo->bo_dirty.bv_root) != NULL &&
1645 bp->b_lblkno == lblkno && !(bp->b_xflags & BX_BKGRDMARKER))
1647 if ((bp = bo->bo_clean.bv_root) != NULL) {
1648 bo->bo_clean.bv_root = bp = buf_splay(lblkno, 0, bp);
1649 if (bp->b_lblkno == lblkno && !(bp->b_xflags & BX_BKGRDMARKER))
1652 if ((bp = bo->bo_dirty.bv_root) != NULL) {
1653 bo->bo_dirty.bv_root = bp = buf_splay(lblkno, 0, bp);
1654 if (bp->b_lblkno == lblkno && !(bp->b_xflags & BX_BKGRDMARKER))
1661 * Associate a buffer with a vnode.
1664 bgetvp(struct vnode *vp, struct buf *bp)
1669 ASSERT_BO_LOCKED(bo);
1670 VNASSERT(bp->b_vp == NULL, bp->b_vp, ("bgetvp: not free"));
1672 CTR3(KTR_BUF, "bgetvp(%p) vp %p flags %X", bp, vp, bp->b_flags);
1673 VNASSERT((bp->b_xflags & (BX_VNDIRTY|BX_VNCLEAN)) == 0, vp,
1674 ("bgetvp: bp already attached! %p", bp));
1680 * Insert onto list for new vnode.
1682 buf_vlist_add(bp, bo, BX_VNCLEAN);
1686 * Disassociate a buffer from a vnode.
1689 brelvp(struct buf *bp)
1694 CTR3(KTR_BUF, "brelvp(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags);
1695 KASSERT(bp->b_vp != NULL, ("brelvp: NULL"));
1698 * Delete from old vnode list, if on one.
1700 vp = bp->b_vp; /* XXX */
1703 if (bp->b_xflags & (BX_VNDIRTY | BX_VNCLEAN))
1704 buf_vlist_remove(bp);
1706 panic("brelvp: Buffer %p not on queue.", bp);
1707 if ((bo->bo_flag & BO_ONWORKLST) && bo->bo_dirty.bv_cnt == 0) {
1708 bo->bo_flag &= ~BO_ONWORKLST;
1709 mtx_lock(&sync_mtx);
1710 LIST_REMOVE(bo, bo_synclist);
1711 syncer_worklist_len--;
1712 mtx_unlock(&sync_mtx);
1715 bp->b_bufobj = NULL;
1721 * Add an item to the syncer work queue.
1724 vn_syncer_add_to_worklist(struct bufobj *bo, int delay)
1728 ASSERT_BO_LOCKED(bo);
1730 mtx_lock(&sync_mtx);
1731 if (bo->bo_flag & BO_ONWORKLST)
1732 LIST_REMOVE(bo, bo_synclist);
1734 bo->bo_flag |= BO_ONWORKLST;
1735 syncer_worklist_len++;
1738 if (delay > syncer_maxdelay - 2)
1739 delay = syncer_maxdelay - 2;
1740 slot = (syncer_delayno + delay) & syncer_mask;
1742 LIST_INSERT_HEAD(&syncer_workitem_pending[slot], bo, bo_synclist);
1743 mtx_unlock(&sync_mtx);
1747 sysctl_vfs_worklist_len(SYSCTL_HANDLER_ARGS)
1751 mtx_lock(&sync_mtx);
1752 len = syncer_worklist_len - sync_vnode_count;
1753 mtx_unlock(&sync_mtx);
1754 error = SYSCTL_OUT(req, &len, sizeof(len));
1758 SYSCTL_PROC(_vfs, OID_AUTO, worklist_len, CTLTYPE_INT | CTLFLAG_RD, NULL, 0,
1759 sysctl_vfs_worklist_len, "I", "Syncer thread worklist length");
1761 static struct proc *updateproc;
1762 static void sched_sync(void);
1763 static struct kproc_desc up_kp = {
1768 SYSINIT(syncer, SI_SUB_KTHREAD_UPDATE, SI_ORDER_FIRST, kproc_start, &up_kp);
1771 sync_vnode(struct synclist *slp, struct bufobj **bo, struct thread *td)
1776 *bo = LIST_FIRST(slp);
1779 vp = (*bo)->__bo_vnode; /* XXX */
1780 if (VOP_ISLOCKED(vp) != 0 || VI_TRYLOCK(vp) == 0)
1783 * We use vhold in case the vnode does not
1784 * successfully sync. vhold prevents the vnode from
1785 * going away when we unlock the sync_mtx so that
1786 * we can acquire the vnode interlock.
1789 mtx_unlock(&sync_mtx);
1791 if (vn_start_write(vp, &mp, V_NOWAIT) != 0) {
1793 mtx_lock(&sync_mtx);
1794 return (*bo == LIST_FIRST(slp));
1796 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1797 (void) VOP_FSYNC(vp, MNT_LAZY, td);
1799 vn_finished_write(mp);
1801 if (((*bo)->bo_flag & BO_ONWORKLST) != 0) {
1803 * Put us back on the worklist. The worklist
1804 * routine will remove us from our current
1805 * position and then add us back in at a later
1808 vn_syncer_add_to_worklist(*bo, syncdelay);
1812 mtx_lock(&sync_mtx);
1817 * System filesystem synchronizer daemon.
1822 struct synclist *next, *slp;
1825 struct thread *td = curthread;
1827 int net_worklist_len;
1828 int syncer_final_iter;
1833 syncer_final_iter = 0;
1835 syncer_state = SYNCER_RUNNING;
1836 starttime = time_uptime;
1837 td->td_pflags |= TDP_NORUNNINGBUF;
1839 EVENTHANDLER_REGISTER(shutdown_pre_sync, syncer_shutdown, td->td_proc,
1842 mtx_lock(&sync_mtx);
1844 if (syncer_state == SYNCER_FINAL_DELAY &&
1845 syncer_final_iter == 0) {
1846 mtx_unlock(&sync_mtx);
1847 kproc_suspend_check(td->td_proc);
1848 mtx_lock(&sync_mtx);
1850 net_worklist_len = syncer_worklist_len - sync_vnode_count;
1851 if (syncer_state != SYNCER_RUNNING &&
1852 starttime != time_uptime) {
1854 printf("\nSyncing disks, vnodes remaining...");
1857 printf("%d ", net_worklist_len);
1859 starttime = time_uptime;
1862 * Push files whose dirty time has expired. Be careful
1863 * of interrupt race on slp queue.
1865 * Skip over empty worklist slots when shutting down.
1868 slp = &syncer_workitem_pending[syncer_delayno];
1869 syncer_delayno += 1;
1870 if (syncer_delayno == syncer_maxdelay)
1872 next = &syncer_workitem_pending[syncer_delayno];
1874 * If the worklist has wrapped since the
1875 * it was emptied of all but syncer vnodes,
1876 * switch to the FINAL_DELAY state and run
1877 * for one more second.
1879 if (syncer_state == SYNCER_SHUTTING_DOWN &&
1880 net_worklist_len == 0 &&
1881 last_work_seen == syncer_delayno) {
1882 syncer_state = SYNCER_FINAL_DELAY;
1883 syncer_final_iter = SYNCER_SHUTDOWN_SPEEDUP;
1885 } while (syncer_state != SYNCER_RUNNING && LIST_EMPTY(slp) &&
1886 syncer_worklist_len > 0);
1889 * Keep track of the last time there was anything
1890 * on the worklist other than syncer vnodes.
1891 * Return to the SHUTTING_DOWN state if any
1894 if (net_worklist_len > 0 || syncer_state == SYNCER_RUNNING)
1895 last_work_seen = syncer_delayno;
1896 if (net_worklist_len > 0 && syncer_state == SYNCER_FINAL_DELAY)
1897 syncer_state = SYNCER_SHUTTING_DOWN;
1898 while (!LIST_EMPTY(slp)) {
1899 error = sync_vnode(slp, &bo, td);
1901 LIST_REMOVE(bo, bo_synclist);
1902 LIST_INSERT_HEAD(next, bo, bo_synclist);
1906 if (first_printf == 0)
1907 wdog_kern_pat(WD_LASTVAL);
1910 if (syncer_state == SYNCER_FINAL_DELAY && syncer_final_iter > 0)
1911 syncer_final_iter--;
1913 * The variable rushjob allows the kernel to speed up the
1914 * processing of the filesystem syncer process. A rushjob
1915 * value of N tells the filesystem syncer to process the next
1916 * N seconds worth of work on its queue ASAP. Currently rushjob
1917 * is used by the soft update code to speed up the filesystem
1918 * syncer process when the incore state is getting so far
1919 * ahead of the disk that the kernel memory pool is being
1920 * threatened with exhaustion.
1927 * Just sleep for a short period of time between
1928 * iterations when shutting down to allow some I/O
1931 * If it has taken us less than a second to process the
1932 * current work, then wait. Otherwise start right over
1933 * again. We can still lose time if any single round
1934 * takes more than two seconds, but it does not really
1935 * matter as we are just trying to generally pace the
1936 * filesystem activity.
1938 if (syncer_state != SYNCER_RUNNING ||
1939 time_uptime == starttime) {
1941 sched_prio(td, PPAUSE);
1944 if (syncer_state != SYNCER_RUNNING)
1945 cv_timedwait(&sync_wakeup, &sync_mtx,
1946 hz / SYNCER_SHUTDOWN_SPEEDUP);
1947 else if (time_uptime == starttime)
1948 cv_timedwait(&sync_wakeup, &sync_mtx, hz);
1953 * Request the syncer daemon to speed up its work.
1954 * We never push it to speed up more than half of its
1955 * normal turn time, otherwise it could take over the cpu.
1958 speedup_syncer(void)
1962 mtx_lock(&sync_mtx);
1963 if (rushjob < syncdelay / 2) {
1965 stat_rush_requests += 1;
1968 mtx_unlock(&sync_mtx);
1969 cv_broadcast(&sync_wakeup);
1974 * Tell the syncer to speed up its work and run though its work
1975 * list several times, then tell it to shut down.
1978 syncer_shutdown(void *arg, int howto)
1981 if (howto & RB_NOSYNC)
1983 mtx_lock(&sync_mtx);
1984 syncer_state = SYNCER_SHUTTING_DOWN;
1986 mtx_unlock(&sync_mtx);
1987 cv_broadcast(&sync_wakeup);
1988 kproc_shutdown(arg, howto);
1992 * Reassign a buffer from one vnode to another.
1993 * Used to assign file specific control information
1994 * (indirect blocks) to the vnode to which they belong.
1997 reassignbuf(struct buf *bp)
2010 CTR3(KTR_BUF, "reassignbuf(%p) vp %p flags %X",
2011 bp, bp->b_vp, bp->b_flags);
2013 * B_PAGING flagged buffers cannot be reassigned because their vp
2014 * is not fully linked in.
2016 if (bp->b_flags & B_PAGING)
2017 panic("cannot reassign paging buffer");
2020 * Delete from old vnode list, if on one.
2023 if (bp->b_xflags & (BX_VNDIRTY | BX_VNCLEAN))
2024 buf_vlist_remove(bp);
2026 panic("reassignbuf: Buffer %p not on queue.", bp);
2028 * If dirty, put on list of dirty buffers; otherwise insert onto list
2031 if (bp->b_flags & B_DELWRI) {
2032 if ((bo->bo_flag & BO_ONWORKLST) == 0) {
2033 switch (vp->v_type) {
2043 vn_syncer_add_to_worklist(bo, delay);
2045 buf_vlist_add(bp, bo, BX_VNDIRTY);
2047 buf_vlist_add(bp, bo, BX_VNCLEAN);
2049 if ((bo->bo_flag & BO_ONWORKLST) && bo->bo_dirty.bv_cnt == 0) {
2050 mtx_lock(&sync_mtx);
2051 LIST_REMOVE(bo, bo_synclist);
2052 syncer_worklist_len--;
2053 mtx_unlock(&sync_mtx);
2054 bo->bo_flag &= ~BO_ONWORKLST;
2059 bp = TAILQ_FIRST(&bv->bv_hd);
2060 KASSERT(bp == NULL || bp->b_bufobj == bo,
2061 ("bp %p wrong b_bufobj %p should be %p", bp, bp->b_bufobj, bo));
2062 bp = TAILQ_LAST(&bv->bv_hd, buflists);
2063 KASSERT(bp == NULL || bp->b_bufobj == bo,
2064 ("bp %p wrong b_bufobj %p should be %p", bp, bp->b_bufobj, bo));
2066 bp = TAILQ_FIRST(&bv->bv_hd);
2067 KASSERT(bp == NULL || bp->b_bufobj == bo,
2068 ("bp %p wrong b_bufobj %p should be %p", bp, bp->b_bufobj, bo));
2069 bp = TAILQ_LAST(&bv->bv_hd, buflists);
2070 KASSERT(bp == NULL || bp->b_bufobj == bo,
2071 ("bp %p wrong b_bufobj %p should be %p", bp, bp->b_bufobj, bo));
2077 * Increment the use and hold counts on the vnode, taking care to reference
2078 * the driver's usecount if this is a chardev. The vholdl() will remove
2079 * the vnode from the free list if it is presently free. Requires the
2080 * vnode interlock and returns with it held.
2083 v_incr_usecount(struct vnode *vp)
2086 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
2088 if (vp->v_type == VCHR && vp->v_rdev != NULL) {
2090 vp->v_rdev->si_usecount++;
2097 * Turn a holdcnt into a use+holdcnt such that only one call to
2098 * v_decr_usecount is needed.
2101 v_upgrade_usecount(struct vnode *vp)
2104 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
2106 if (vp->v_type == VCHR && vp->v_rdev != NULL) {
2108 vp->v_rdev->si_usecount++;
2114 * Decrement the vnode use and hold count along with the driver's usecount
2115 * if this is a chardev. The vdropl() below releases the vnode interlock
2116 * as it may free the vnode.
2119 v_decr_usecount(struct vnode *vp)
2122 ASSERT_VI_LOCKED(vp, __FUNCTION__);
2123 VNASSERT(vp->v_usecount > 0, vp,
2124 ("v_decr_usecount: negative usecount"));
2125 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
2127 if (vp->v_type == VCHR && vp->v_rdev != NULL) {
2129 vp->v_rdev->si_usecount--;
2136 * Decrement only the use count and driver use count. This is intended to
2137 * be paired with a follow on vdropl() to release the remaining hold count.
2138 * In this way we may vgone() a vnode with a 0 usecount without risk of
2139 * having it end up on a free list because the hold count is kept above 0.
2142 v_decr_useonly(struct vnode *vp)
2145 ASSERT_VI_LOCKED(vp, __FUNCTION__);
2146 VNASSERT(vp->v_usecount > 0, vp,
2147 ("v_decr_useonly: negative usecount"));
2148 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
2150 if (vp->v_type == VCHR && vp->v_rdev != NULL) {
2152 vp->v_rdev->si_usecount--;
2158 * Grab a particular vnode from the free list, increment its
2159 * reference count and lock it. VI_DOOMED is set if the vnode
2160 * is being destroyed. Only callers who specify LK_RETRY will
2161 * see doomed vnodes. If inactive processing was delayed in
2162 * vput try to do it here.
2165 vget(struct vnode *vp, int flags, struct thread *td)
2170 VNASSERT((flags & LK_TYPE_MASK) != 0, vp,
2171 ("vget: invalid lock operation"));
2172 CTR3(KTR_VFS, "%s: vp %p with flags %d", __func__, vp, flags);
2174 if ((flags & LK_INTERLOCK) == 0)
2177 if ((error = vn_lock(vp, flags | LK_INTERLOCK)) != 0) {
2179 CTR2(KTR_VFS, "%s: impossible to lock vnode %p", __func__,
2183 if (vp->v_iflag & VI_DOOMED && (flags & LK_RETRY) == 0)
2184 panic("vget: vn_lock failed to return ENOENT\n");
2186 /* Upgrade our holdcnt to a usecount. */
2187 v_upgrade_usecount(vp);
2189 * We don't guarantee that any particular close will
2190 * trigger inactive processing so just make a best effort
2191 * here at preventing a reference to a removed file. If
2192 * we don't succeed no harm is done.
2194 if (vp->v_iflag & VI_OWEINACT) {
2195 if (VOP_ISLOCKED(vp) == LK_EXCLUSIVE &&
2196 (flags & LK_NOWAIT) == 0)
2198 vp->v_iflag &= ~VI_OWEINACT;
2205 * Increase the reference count of a vnode.
2208 vref(struct vnode *vp)
2211 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
2213 v_incr_usecount(vp);
2218 * Return reference count of a vnode.
2220 * The results of this call are only guaranteed when some mechanism other
2221 * than the VI lock is used to stop other processes from gaining references
2222 * to the vnode. This may be the case if the caller holds the only reference.
2223 * This is also useful when stale data is acceptable as race conditions may
2224 * be accounted for by some other means.
2227 vrefcnt(struct vnode *vp)
2232 usecnt = vp->v_usecount;
2238 #define VPUTX_VRELE 1
2239 #define VPUTX_VPUT 2
2240 #define VPUTX_VUNREF 3
2243 vputx(struct vnode *vp, int func)
2247 KASSERT(vp != NULL, ("vputx: null vp"));
2248 if (func == VPUTX_VUNREF)
2249 ASSERT_VOP_LOCKED(vp, "vunref");
2250 else if (func == VPUTX_VPUT)
2251 ASSERT_VOP_LOCKED(vp, "vput");
2253 KASSERT(func == VPUTX_VRELE, ("vputx: wrong func"));
2254 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
2257 /* Skip this v_writecount check if we're going to panic below. */
2258 VNASSERT(vp->v_writecount < vp->v_usecount || vp->v_usecount < 1, vp,
2259 ("vputx: missed vn_close"));
2262 if (vp->v_usecount > 1 || ((vp->v_iflag & VI_DOINGINACT) &&
2263 vp->v_usecount == 1)) {
2264 if (func == VPUTX_VPUT)
2266 v_decr_usecount(vp);
2270 if (vp->v_usecount != 1) {
2271 vprint("vputx: negative ref count", vp);
2272 panic("vputx: negative ref cnt");
2274 CTR2(KTR_VFS, "%s: return vnode %p to the freelist", __func__, vp);
2276 * We want to hold the vnode until the inactive finishes to
2277 * prevent vgone() races. We drop the use count here and the
2278 * hold count below when we're done.
2282 * We must call VOP_INACTIVE with the node locked. Mark
2283 * as VI_DOINGINACT to avoid recursion.
2285 vp->v_iflag |= VI_OWEINACT;
2288 error = vn_lock(vp, LK_EXCLUSIVE | LK_INTERLOCK);
2292 if (VOP_ISLOCKED(vp) != LK_EXCLUSIVE) {
2293 error = VOP_LOCK(vp, LK_UPGRADE | LK_INTERLOCK |
2299 if (VOP_ISLOCKED(vp) != LK_EXCLUSIVE)
2303 if (vp->v_usecount > 0)
2304 vp->v_iflag &= ~VI_OWEINACT;
2306 if (vp->v_iflag & VI_OWEINACT)
2307 vinactive(vp, curthread);
2308 if (func != VPUTX_VUNREF)
2315 * Vnode put/release.
2316 * If count drops to zero, call inactive routine and return to freelist.
2319 vrele(struct vnode *vp)
2322 vputx(vp, VPUTX_VRELE);
2326 * Release an already locked vnode. This give the same effects as
2327 * unlock+vrele(), but takes less time and avoids releasing and
2328 * re-aquiring the lock (as vrele() acquires the lock internally.)
2331 vput(struct vnode *vp)
2334 vputx(vp, VPUTX_VPUT);
2338 * Release an exclusively locked vnode. Do not unlock the vnode lock.
2341 vunref(struct vnode *vp)
2344 vputx(vp, VPUTX_VUNREF);
2348 * Somebody doesn't want the vnode recycled.
2351 vhold(struct vnode *vp)
2360 * Increase the hold count and activate if this is the first reference.
2363 vholdl(struct vnode *vp)
2367 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
2369 if (!VSHOULDBUSY(vp))
2371 ASSERT_VI_LOCKED(vp, "vholdl");
2372 VNASSERT((vp->v_iflag & VI_FREE) != 0, vp, ("vnode not free"));
2373 VNASSERT(vp->v_op != NULL, vp, ("vholdl: vnode already reclaimed."));
2375 * Remove a vnode from the free list, mark it as in use,
2376 * and put it on the active list.
2378 mtx_lock(&vnode_free_list_mtx);
2379 TAILQ_REMOVE(&vnode_free_list, vp, v_actfreelist);
2381 vp->v_iflag &= ~(VI_FREE|VI_AGE);
2382 KASSERT((vp->v_iflag & VI_ACTIVE) == 0,
2383 ("Activating already active vnode"));
2384 vp->v_iflag |= VI_ACTIVE;
2386 TAILQ_INSERT_HEAD(&mp->mnt_activevnodelist, vp, v_actfreelist);
2387 mp->mnt_activevnodelistsize++;
2388 mtx_unlock(&vnode_free_list_mtx);
2392 * Note that there is one less who cares about this vnode.
2393 * vdrop() is the opposite of vhold().
2396 vdrop(struct vnode *vp)
2404 * Drop the hold count of the vnode. If this is the last reference to
2405 * the vnode we place it on the free list unless it has been vgone'd
2406 * (marked VI_DOOMED) in which case we will free it.
2409 vdropl(struct vnode *vp)
2415 ASSERT_VI_LOCKED(vp, "vdropl");
2416 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
2417 if (vp->v_holdcnt <= 0)
2418 panic("vdrop: holdcnt %d", vp->v_holdcnt);
2420 if (vp->v_holdcnt > 0) {
2424 if ((vp->v_iflag & VI_DOOMED) == 0) {
2426 * Mark a vnode as free: remove it from its active list
2427 * and put it up for recycling on the freelist.
2429 VNASSERT(vp->v_op != NULL, vp,
2430 ("vdropl: vnode already reclaimed."));
2431 VNASSERT((vp->v_iflag & VI_FREE) == 0, vp,
2432 ("vnode already free"));
2433 VNASSERT(VSHOULDFREE(vp), vp,
2434 ("vdropl: freeing when we shouldn't"));
2435 active = vp->v_iflag & VI_ACTIVE;
2436 vp->v_iflag &= ~VI_ACTIVE;
2438 mtx_lock(&vnode_free_list_mtx);
2440 TAILQ_REMOVE(&mp->mnt_activevnodelist, vp,
2442 mp->mnt_activevnodelistsize--;
2444 if (vp->v_iflag & VI_AGE) {
2445 TAILQ_INSERT_HEAD(&vnode_free_list, vp, v_actfreelist);
2447 TAILQ_INSERT_TAIL(&vnode_free_list, vp, v_actfreelist);
2450 vp->v_iflag &= ~VI_AGE;
2451 vp->v_iflag |= VI_FREE;
2452 mtx_unlock(&vnode_free_list_mtx);
2457 * The vnode has been marked for destruction, so free it.
2459 CTR2(KTR_VFS, "%s: destroying the vnode %p", __func__, vp);
2460 mtx_lock(&vnode_free_list_mtx);
2462 mtx_unlock(&vnode_free_list_mtx);
2464 VNASSERT((vp->v_iflag & VI_FREE) == 0, vp,
2465 ("cleaned vnode still on the free list."));
2466 VNASSERT(vp->v_data == NULL, vp, ("cleaned vnode isn't"));
2467 VNASSERT(vp->v_holdcnt == 0, vp, ("Non-zero hold count"));
2468 VNASSERT(vp->v_usecount == 0, vp, ("Non-zero use count"));
2469 VNASSERT(vp->v_writecount == 0, vp, ("Non-zero write count"));
2470 VNASSERT(bo->bo_numoutput == 0, vp, ("Clean vnode has pending I/O's"));
2471 VNASSERT(bo->bo_clean.bv_cnt == 0, vp, ("cleanbufcnt not 0"));
2472 VNASSERT(bo->bo_clean.bv_root == NULL, vp, ("cleanblkroot not NULL"));
2473 VNASSERT(bo->bo_dirty.bv_cnt == 0, vp, ("dirtybufcnt not 0"));
2474 VNASSERT(bo->bo_dirty.bv_root == NULL, vp, ("dirtyblkroot not NULL"));
2475 VNASSERT(TAILQ_EMPTY(&vp->v_cache_dst), vp, ("vp has namecache dst"));
2476 VNASSERT(LIST_EMPTY(&vp->v_cache_src), vp, ("vp has namecache src"));
2477 VNASSERT(vp->v_cache_dd == NULL, vp, ("vp has namecache for .."));
2480 mac_vnode_destroy(vp);
2482 if (vp->v_pollinfo != NULL)
2483 destroy_vpollinfo(vp->v_pollinfo);
2485 /* XXX Elsewhere we detect an already freed vnode via NULL v_op. */
2488 rangelock_destroy(&vp->v_rl);
2489 lockdestroy(vp->v_vnlock);
2490 mtx_destroy(&vp->v_interlock);
2491 mtx_destroy(BO_MTX(bo));
2492 uma_zfree(vnode_zone, vp);
2496 * Call VOP_INACTIVE on the vnode and manage the DOINGINACT and OWEINACT
2497 * flags. DOINGINACT prevents us from recursing in calls to vinactive.
2498 * OWEINACT tracks whether a vnode missed a call to inactive due to a
2499 * failed lock upgrade.
2502 vinactive(struct vnode *vp, struct thread *td)
2504 struct vm_object *obj;
2506 ASSERT_VOP_ELOCKED(vp, "vinactive");
2507 ASSERT_VI_LOCKED(vp, "vinactive");
2508 VNASSERT((vp->v_iflag & VI_DOINGINACT) == 0, vp,
2509 ("vinactive: recursed on VI_DOINGINACT"));
2510 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
2511 vp->v_iflag |= VI_DOINGINACT;
2512 vp->v_iflag &= ~VI_OWEINACT;
2515 * Before moving off the active list, we must be sure that any
2516 * modified pages are on the vnode's dirty list since these will
2517 * no longer be checked once the vnode is on the inactive list.
2518 * Because the vnode vm object keeps a hold reference on the vnode
2519 * if there is at least one resident non-cached page, the vnode
2520 * cannot leave the active list without the page cleanup done.
2523 if (obj != NULL && (obj->flags & OBJ_MIGHTBEDIRTY) != 0) {
2524 VM_OBJECT_WLOCK(obj);
2525 vm_object_page_clean(obj, 0, 0, OBJPC_NOSYNC);
2526 VM_OBJECT_WUNLOCK(obj);
2528 VOP_INACTIVE(vp, td);
2530 VNASSERT(vp->v_iflag & VI_DOINGINACT, vp,
2531 ("vinactive: lost VI_DOINGINACT"));
2532 vp->v_iflag &= ~VI_DOINGINACT;
2536 * Remove any vnodes in the vnode table belonging to mount point mp.
2538 * If FORCECLOSE is not specified, there should not be any active ones,
2539 * return error if any are found (nb: this is a user error, not a
2540 * system error). If FORCECLOSE is specified, detach any active vnodes
2543 * If WRITECLOSE is set, only flush out regular file vnodes open for
2546 * SKIPSYSTEM causes any vnodes marked VV_SYSTEM to be skipped.
2548 * `rootrefs' specifies the base reference count for the root vnode
2549 * of this filesystem. The root vnode is considered busy if its
2550 * v_usecount exceeds this value. On a successful return, vflush(, td)
2551 * will call vrele() on the root vnode exactly rootrefs times.
2552 * If the SKIPSYSTEM or WRITECLOSE flags are specified, rootrefs must
2556 static int busyprt = 0; /* print out busy vnodes */
2557 SYSCTL_INT(_debug, OID_AUTO, busyprt, CTLFLAG_RW, &busyprt, 0, "Print out busy vnodes");
2561 vflush(struct mount *mp, int rootrefs, int flags, struct thread *td)
2563 struct vnode *vp, *mvp, *rootvp = NULL;
2565 int busy = 0, error;
2567 CTR4(KTR_VFS, "%s: mp %p with rootrefs %d and flags %d", __func__, mp,
2570 KASSERT((flags & (SKIPSYSTEM | WRITECLOSE)) == 0,
2571 ("vflush: bad args"));
2573 * Get the filesystem root vnode. We can vput() it
2574 * immediately, since with rootrefs > 0, it won't go away.
2576 if ((error = VFS_ROOT(mp, LK_EXCLUSIVE, &rootvp)) != 0) {
2577 CTR2(KTR_VFS, "%s: vfs_root lookup failed with %d",
2584 MNT_VNODE_FOREACH_ALL(vp, mp, mvp) {
2586 error = vn_lock(vp, LK_INTERLOCK | LK_EXCLUSIVE);
2589 MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
2593 * Skip over a vnodes marked VV_SYSTEM.
2595 if ((flags & SKIPSYSTEM) && (vp->v_vflag & VV_SYSTEM)) {
2601 * If WRITECLOSE is set, flush out unlinked but still open
2602 * files (even if open only for reading) and regular file
2603 * vnodes open for writing.
2605 if (flags & WRITECLOSE) {
2606 if (vp->v_object != NULL) {
2607 VM_OBJECT_WLOCK(vp->v_object);
2608 vm_object_page_clean(vp->v_object, 0, 0, 0);
2609 VM_OBJECT_WUNLOCK(vp->v_object);
2611 error = VOP_FSYNC(vp, MNT_WAIT, td);
2615 MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
2618 error = VOP_GETATTR(vp, &vattr, td->td_ucred);
2621 if ((vp->v_type == VNON ||
2622 (error == 0 && vattr.va_nlink > 0)) &&
2623 (vp->v_writecount == 0 || vp->v_type != VREG)) {
2631 * With v_usecount == 0, all we need to do is clear out the
2632 * vnode data structures and we are done.
2634 * If FORCECLOSE is set, forcibly close the vnode.
2636 if (vp->v_usecount == 0 || (flags & FORCECLOSE)) {
2637 VNASSERT(vp->v_usecount == 0 ||
2638 (vp->v_type != VCHR && vp->v_type != VBLK), vp,
2639 ("device VNODE %p is FORCECLOSED", vp));
2645 vprint("vflush: busy vnode", vp);
2651 if (rootrefs > 0 && (flags & FORCECLOSE) == 0) {
2653 * If just the root vnode is busy, and if its refcount
2654 * is equal to `rootrefs', then go ahead and kill it.
2657 KASSERT(busy > 0, ("vflush: not busy"));
2658 VNASSERT(rootvp->v_usecount >= rootrefs, rootvp,
2659 ("vflush: usecount %d < rootrefs %d",
2660 rootvp->v_usecount, rootrefs));
2661 if (busy == 1 && rootvp->v_usecount == rootrefs) {
2662 VOP_LOCK(rootvp, LK_EXCLUSIVE|LK_INTERLOCK);
2664 VOP_UNLOCK(rootvp, 0);
2670 CTR2(KTR_VFS, "%s: failing as %d vnodes are busy", __func__,
2674 for (; rootrefs > 0; rootrefs--)
2680 * Recycle an unused vnode to the front of the free list.
2683 vrecycle(struct vnode *vp)
2687 ASSERT_VOP_ELOCKED(vp, "vrecycle");
2688 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
2691 if (vp->v_usecount == 0) {
2700 * Eliminate all activity associated with a vnode
2701 * in preparation for reuse.
2704 vgone(struct vnode *vp)
2712 vgonel_reclaim_lowervp_vfs(struct mount *mp __unused,
2713 struct vnode *lowervp __unused)
2718 * Notify upper mounts about reclaimed vnode.
2721 vgonel_reclaim_lowervp(struct vnode *vp)
2723 static struct vfsops vgonel_vfsops = {
2724 .vfs_reclaim_lowervp = vgonel_reclaim_lowervp_vfs
2726 struct mount *mp, *ump, *mmp;
2733 if (TAILQ_EMPTY(&mp->mnt_uppers))
2736 mmp = malloc(sizeof(struct mount), M_TEMP, M_WAITOK | M_ZERO);
2737 mmp->mnt_op = &vgonel_vfsops;
2738 mmp->mnt_kern_flag |= MNTK_MARKER;
2740 mp->mnt_kern_flag |= MNTK_VGONE_UPPER;
2741 for (ump = TAILQ_FIRST(&mp->mnt_uppers); ump != NULL;) {
2742 if ((ump->mnt_kern_flag & MNTK_MARKER) != 0) {
2743 ump = TAILQ_NEXT(ump, mnt_upper_link);
2746 TAILQ_INSERT_AFTER(&mp->mnt_uppers, ump, mmp, mnt_upper_link);
2748 VFS_RECLAIM_LOWERVP(ump, vp);
2750 ump = TAILQ_NEXT(mmp, mnt_upper_link);
2751 TAILQ_REMOVE(&mp->mnt_uppers, mmp, mnt_upper_link);
2754 mp->mnt_kern_flag &= ~MNTK_VGONE_UPPER;
2755 if ((mp->mnt_kern_flag & MNTK_VGONE_WAITER) != 0) {
2756 mp->mnt_kern_flag &= ~MNTK_VGONE_WAITER;
2757 wakeup(&mp->mnt_uppers);
2764 * vgone, with the vp interlock held.
2767 vgonel(struct vnode *vp)
2774 ASSERT_VOP_ELOCKED(vp, "vgonel");
2775 ASSERT_VI_LOCKED(vp, "vgonel");
2776 VNASSERT(vp->v_holdcnt, vp,
2777 ("vgonel: vp %p has no reference.", vp));
2778 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
2782 * Don't vgonel if we're already doomed.
2784 if (vp->v_iflag & VI_DOOMED)
2786 vp->v_iflag |= VI_DOOMED;
2789 * Check to see if the vnode is in use. If so, we have to call
2790 * VOP_CLOSE() and VOP_INACTIVE().
2792 active = vp->v_usecount;
2793 oweinact = (vp->v_iflag & VI_OWEINACT);
2795 vgonel_reclaim_lowervp(vp);
2798 * Clean out any buffers associated with the vnode.
2799 * If the flush fails, just toss the buffers.
2802 if (!TAILQ_EMPTY(&vp->v_bufobj.bo_dirty.bv_hd))
2803 (void) vn_start_secondary_write(vp, &mp, V_WAIT);
2804 if (vinvalbuf(vp, V_SAVE, 0, 0) != 0)
2805 vinvalbuf(vp, 0, 0, 0);
2808 * If purging an active vnode, it must be closed and
2809 * deactivated before being reclaimed.
2812 VOP_CLOSE(vp, FNONBLOCK, NOCRED, td);
2813 if (oweinact || active) {
2815 if ((vp->v_iflag & VI_DOINGINACT) == 0)
2819 if (vp->v_type == VSOCK)
2820 vfs_unp_reclaim(vp);
2822 * Reclaim the vnode.
2824 if (VOP_RECLAIM(vp, td))
2825 panic("vgone: cannot reclaim");
2827 vn_finished_secondary_write(mp);
2828 VNASSERT(vp->v_object == NULL, vp,
2829 ("vop_reclaim left v_object vp=%p, tag=%s", vp, vp->v_tag));
2831 * Clear the advisory locks and wake up waiting threads.
2833 (void)VOP_ADVLOCKPURGE(vp);
2835 * Delete from old mount point vnode list.
2840 * Done with purge, reset to the standard lock and invalidate
2844 vp->v_vnlock = &vp->v_lock;
2845 vp->v_op = &dead_vnodeops;
2851 * Calculate the total number of references to a special device.
2854 vcount(struct vnode *vp)
2859 count = vp->v_rdev->si_usecount;
2865 * Same as above, but using the struct cdev *as argument
2868 count_dev(struct cdev *dev)
2873 count = dev->si_usecount;
2879 * Print out a description of a vnode.
2881 static char *typename[] =
2882 {"VNON", "VREG", "VDIR", "VBLK", "VCHR", "VLNK", "VSOCK", "VFIFO", "VBAD",
2886 vn_printf(struct vnode *vp, const char *fmt, ...)
2889 char buf[256], buf2[16];
2895 printf("%p: ", (void *)vp);
2896 printf("tag %s, type %s\n", vp->v_tag, typename[vp->v_type]);
2897 printf(" usecount %d, writecount %d, refcount %d mountedhere %p\n",
2898 vp->v_usecount, vp->v_writecount, vp->v_holdcnt, vp->v_mountedhere);
2901 if (vp->v_vflag & VV_ROOT)
2902 strlcat(buf, "|VV_ROOT", sizeof(buf));
2903 if (vp->v_vflag & VV_ISTTY)
2904 strlcat(buf, "|VV_ISTTY", sizeof(buf));
2905 if (vp->v_vflag & VV_NOSYNC)
2906 strlcat(buf, "|VV_NOSYNC", sizeof(buf));
2907 if (vp->v_vflag & VV_ETERNALDEV)
2908 strlcat(buf, "|VV_ETERNALDEV", sizeof(buf));
2909 if (vp->v_vflag & VV_CACHEDLABEL)
2910 strlcat(buf, "|VV_CACHEDLABEL", sizeof(buf));
2911 if (vp->v_vflag & VV_TEXT)
2912 strlcat(buf, "|VV_TEXT", sizeof(buf));
2913 if (vp->v_vflag & VV_COPYONWRITE)
2914 strlcat(buf, "|VV_COPYONWRITE", sizeof(buf));
2915 if (vp->v_vflag & VV_SYSTEM)
2916 strlcat(buf, "|VV_SYSTEM", sizeof(buf));
2917 if (vp->v_vflag & VV_PROCDEP)
2918 strlcat(buf, "|VV_PROCDEP", sizeof(buf));
2919 if (vp->v_vflag & VV_NOKNOTE)
2920 strlcat(buf, "|VV_NOKNOTE", sizeof(buf));
2921 if (vp->v_vflag & VV_DELETED)
2922 strlcat(buf, "|VV_DELETED", sizeof(buf));
2923 if (vp->v_vflag & VV_MD)
2924 strlcat(buf, "|VV_MD", sizeof(buf));
2925 if (vp->v_vflag & VV_FORCEINSMQ)
2926 strlcat(buf, "|VV_FORCEINSMQ", sizeof(buf));
2927 flags = vp->v_vflag & ~(VV_ROOT | VV_ISTTY | VV_NOSYNC | VV_ETERNALDEV |
2928 VV_CACHEDLABEL | VV_TEXT | VV_COPYONWRITE | VV_SYSTEM | VV_PROCDEP |
2929 VV_NOKNOTE | VV_DELETED | VV_MD | VV_FORCEINSMQ);
2931 snprintf(buf2, sizeof(buf2), "|VV(0x%lx)", flags);
2932 strlcat(buf, buf2, sizeof(buf));
2934 if (vp->v_iflag & VI_MOUNT)
2935 strlcat(buf, "|VI_MOUNT", sizeof(buf));
2936 if (vp->v_iflag & VI_AGE)
2937 strlcat(buf, "|VI_AGE", sizeof(buf));
2938 if (vp->v_iflag & VI_DOOMED)
2939 strlcat(buf, "|VI_DOOMED", sizeof(buf));
2940 if (vp->v_iflag & VI_FREE)
2941 strlcat(buf, "|VI_FREE", sizeof(buf));
2942 if (vp->v_iflag & VI_ACTIVE)
2943 strlcat(buf, "|VI_ACTIVE", sizeof(buf));
2944 if (vp->v_iflag & VI_DOINGINACT)
2945 strlcat(buf, "|VI_DOINGINACT", sizeof(buf));
2946 if (vp->v_iflag & VI_OWEINACT)
2947 strlcat(buf, "|VI_OWEINACT", sizeof(buf));
2948 flags = vp->v_iflag & ~(VI_MOUNT | VI_AGE | VI_DOOMED | VI_FREE |
2949 VI_ACTIVE | VI_DOINGINACT | VI_OWEINACT);
2951 snprintf(buf2, sizeof(buf2), "|VI(0x%lx)", flags);
2952 strlcat(buf, buf2, sizeof(buf));
2954 printf(" flags (%s)\n", buf + 1);
2955 if (mtx_owned(VI_MTX(vp)))
2956 printf(" VI_LOCKed");
2957 if (vp->v_object != NULL)
2958 printf(" v_object %p ref %d pages %d\n",
2959 vp->v_object, vp->v_object->ref_count,
2960 vp->v_object->resident_page_count);
2962 lockmgr_printinfo(vp->v_vnlock);
2963 if (vp->v_data != NULL)
2969 * List all of the locked vnodes in the system.
2970 * Called when debugging the kernel.
2972 DB_SHOW_COMMAND(lockedvnods, lockedvnodes)
2974 struct mount *mp, *nmp;
2978 * Note: because this is DDB, we can't obey the locking semantics
2979 * for these structures, which means we could catch an inconsistent
2980 * state and dereference a nasty pointer. Not much to be done
2983 db_printf("Locked vnodes\n");
2984 for (mp = TAILQ_FIRST(&mountlist); mp != NULL; mp = nmp) {
2985 nmp = TAILQ_NEXT(mp, mnt_list);
2986 TAILQ_FOREACH(vp, &mp->mnt_nvnodelist, v_nmntvnodes) {
2987 if (vp->v_type != VMARKER &&
2991 nmp = TAILQ_NEXT(mp, mnt_list);
2996 * Show details about the given vnode.
2998 DB_SHOW_COMMAND(vnode, db_show_vnode)
3004 vp = (struct vnode *)addr;
3005 vn_printf(vp, "vnode ");
3009 * Show details about the given mount point.
3011 DB_SHOW_COMMAND(mount, db_show_mount)
3022 /* No address given, print short info about all mount points. */
3023 TAILQ_FOREACH(mp, &mountlist, mnt_list) {
3024 db_printf("%p %s on %s (%s)\n", mp,
3025 mp->mnt_stat.f_mntfromname,
3026 mp->mnt_stat.f_mntonname,
3027 mp->mnt_stat.f_fstypename);
3031 db_printf("\nMore info: show mount <addr>\n");
3035 mp = (struct mount *)addr;
3036 db_printf("%p %s on %s (%s)\n", mp, mp->mnt_stat.f_mntfromname,
3037 mp->mnt_stat.f_mntonname, mp->mnt_stat.f_fstypename);
3040 mflags = mp->mnt_flag;
3041 #define MNT_FLAG(flag) do { \
3042 if (mflags & (flag)) { \
3043 if (buf[0] != '\0') \
3044 strlcat(buf, ", ", sizeof(buf)); \
3045 strlcat(buf, (#flag) + 4, sizeof(buf)); \
3046 mflags &= ~(flag); \
3049 MNT_FLAG(MNT_RDONLY);
3050 MNT_FLAG(MNT_SYNCHRONOUS);
3051 MNT_FLAG(MNT_NOEXEC);
3052 MNT_FLAG(MNT_NOSUID);
3053 MNT_FLAG(MNT_NFS4ACLS);
3054 MNT_FLAG(MNT_UNION);
3055 MNT_FLAG(MNT_ASYNC);
3056 MNT_FLAG(MNT_SUIDDIR);
3057 MNT_FLAG(MNT_SOFTDEP);
3058 MNT_FLAG(MNT_NOSYMFOLLOW);
3059 MNT_FLAG(MNT_GJOURNAL);
3060 MNT_FLAG(MNT_MULTILABEL);
3062 MNT_FLAG(MNT_NOATIME);
3063 MNT_FLAG(MNT_NOCLUSTERR);
3064 MNT_FLAG(MNT_NOCLUSTERW);
3066 MNT_FLAG(MNT_EXRDONLY);
3067 MNT_FLAG(MNT_EXPORTED);
3068 MNT_FLAG(MNT_DEFEXPORTED);
3069 MNT_FLAG(MNT_EXPORTANON);
3070 MNT_FLAG(MNT_EXKERB);
3071 MNT_FLAG(MNT_EXPUBLIC);
3072 MNT_FLAG(MNT_LOCAL);
3073 MNT_FLAG(MNT_QUOTA);
3074 MNT_FLAG(MNT_ROOTFS);
3076 MNT_FLAG(MNT_IGNORE);
3077 MNT_FLAG(MNT_UPDATE);
3078 MNT_FLAG(MNT_DELEXPORT);
3079 MNT_FLAG(MNT_RELOAD);
3080 MNT_FLAG(MNT_FORCE);
3081 MNT_FLAG(MNT_SNAPSHOT);
3082 MNT_FLAG(MNT_BYFSID);
3086 strlcat(buf, ", ", sizeof(buf));
3087 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
3088 "0x%016jx", mflags);
3090 db_printf(" mnt_flag = %s\n", buf);
3093 flags = mp->mnt_kern_flag;
3094 #define MNT_KERN_FLAG(flag) do { \
3095 if (flags & (flag)) { \
3096 if (buf[0] != '\0') \
3097 strlcat(buf, ", ", sizeof(buf)); \
3098 strlcat(buf, (#flag) + 5, sizeof(buf)); \
3102 MNT_KERN_FLAG(MNTK_UNMOUNTF);
3103 MNT_KERN_FLAG(MNTK_ASYNC);
3104 MNT_KERN_FLAG(MNTK_SOFTDEP);
3105 MNT_KERN_FLAG(MNTK_NOINSMNTQ);
3106 MNT_KERN_FLAG(MNTK_DRAINING);
3107 MNT_KERN_FLAG(MNTK_REFEXPIRE);
3108 MNT_KERN_FLAG(MNTK_EXTENDED_SHARED);
3109 MNT_KERN_FLAG(MNTK_SHARED_WRITES);
3110 MNT_KERN_FLAG(MNTK_NO_IOPF);
3111 MNT_KERN_FLAG(MNTK_VGONE_UPPER);
3112 MNT_KERN_FLAG(MNTK_VGONE_WAITER);
3113 MNT_KERN_FLAG(MNTK_LOOKUP_EXCL_DOTDOT);
3114 MNT_KERN_FLAG(MNTK_MARKER);
3115 MNT_KERN_FLAG(MNTK_NOASYNC);
3116 MNT_KERN_FLAG(MNTK_UNMOUNT);
3117 MNT_KERN_FLAG(MNTK_MWAIT);
3118 MNT_KERN_FLAG(MNTK_SUSPEND);
3119 MNT_KERN_FLAG(MNTK_SUSPEND2);
3120 MNT_KERN_FLAG(MNTK_SUSPENDED);
3121 MNT_KERN_FLAG(MNTK_LOOKUP_SHARED);
3122 MNT_KERN_FLAG(MNTK_NOKNOTE);
3123 #undef MNT_KERN_FLAG
3126 strlcat(buf, ", ", sizeof(buf));
3127 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
3130 db_printf(" mnt_kern_flag = %s\n", buf);
3132 db_printf(" mnt_opt = ");
3133 opt = TAILQ_FIRST(mp->mnt_opt);
3135 db_printf("%s", opt->name);
3136 opt = TAILQ_NEXT(opt, link);
3137 while (opt != NULL) {
3138 db_printf(", %s", opt->name);
3139 opt = TAILQ_NEXT(opt, link);
3145 db_printf(" mnt_stat = { version=%u type=%u flags=0x%016jx "
3146 "bsize=%ju iosize=%ju blocks=%ju bfree=%ju bavail=%jd files=%ju "
3147 "ffree=%jd syncwrites=%ju asyncwrites=%ju syncreads=%ju "
3148 "asyncreads=%ju namemax=%u owner=%u fsid=[%d, %d] }\n",
3149 (u_int)sp->f_version, (u_int)sp->f_type, (uintmax_t)sp->f_flags,
3150 (uintmax_t)sp->f_bsize, (uintmax_t)sp->f_iosize,
3151 (uintmax_t)sp->f_blocks, (uintmax_t)sp->f_bfree,
3152 (intmax_t)sp->f_bavail, (uintmax_t)sp->f_files,
3153 (intmax_t)sp->f_ffree, (uintmax_t)sp->f_syncwrites,
3154 (uintmax_t)sp->f_asyncwrites, (uintmax_t)sp->f_syncreads,
3155 (uintmax_t)sp->f_asyncreads, (u_int)sp->f_namemax,
3156 (u_int)sp->f_owner, (int)sp->f_fsid.val[0], (int)sp->f_fsid.val[1]);
3158 db_printf(" mnt_cred = { uid=%u ruid=%u",
3159 (u_int)mp->mnt_cred->cr_uid, (u_int)mp->mnt_cred->cr_ruid);
3160 if (jailed(mp->mnt_cred))
3161 db_printf(", jail=%d", mp->mnt_cred->cr_prison->pr_id);
3163 db_printf(" mnt_ref = %d\n", mp->mnt_ref);
3164 db_printf(" mnt_gen = %d\n", mp->mnt_gen);
3165 db_printf(" mnt_nvnodelistsize = %d\n", mp->mnt_nvnodelistsize);
3166 db_printf(" mnt_activevnodelistsize = %d\n",
3167 mp->mnt_activevnodelistsize);
3168 db_printf(" mnt_writeopcount = %d\n", mp->mnt_writeopcount);
3169 db_printf(" mnt_maxsymlinklen = %d\n", mp->mnt_maxsymlinklen);
3170 db_printf(" mnt_iosize_max = %d\n", mp->mnt_iosize_max);
3171 db_printf(" mnt_hashseed = %u\n", mp->mnt_hashseed);
3172 db_printf(" mnt_secondary_writes = %d\n", mp->mnt_secondary_writes);
3173 db_printf(" mnt_secondary_accwrites = %d\n",
3174 mp->mnt_secondary_accwrites);
3175 db_printf(" mnt_gjprovider = %s\n",
3176 mp->mnt_gjprovider != NULL ? mp->mnt_gjprovider : "NULL");
3178 db_printf("\n\nList of active vnodes\n");
3179 TAILQ_FOREACH(vp, &mp->mnt_activevnodelist, v_actfreelist) {
3180 if (vp->v_type != VMARKER) {
3181 vn_printf(vp, "vnode ");
3186 db_printf("\n\nList of inactive vnodes\n");
3187 TAILQ_FOREACH(vp, &mp->mnt_nvnodelist, v_nmntvnodes) {
3188 if (vp->v_type != VMARKER && (vp->v_iflag & VI_ACTIVE) == 0) {
3189 vn_printf(vp, "vnode ");
3198 * Fill in a struct xvfsconf based on a struct vfsconf.
3201 vfsconf2x(struct sysctl_req *req, struct vfsconf *vfsp)
3203 struct xvfsconf xvfsp;
3205 bzero(&xvfsp, sizeof(xvfsp));
3206 strcpy(xvfsp.vfc_name, vfsp->vfc_name);
3207 xvfsp.vfc_typenum = vfsp->vfc_typenum;
3208 xvfsp.vfc_refcount = vfsp->vfc_refcount;
3209 xvfsp.vfc_flags = vfsp->vfc_flags;
3211 * These are unused in userland, we keep them
3212 * to not break binary compatibility.
3214 xvfsp.vfc_vfsops = NULL;
3215 xvfsp.vfc_next = NULL;
3216 return (SYSCTL_OUT(req, &xvfsp, sizeof(xvfsp)));
3219 #ifdef COMPAT_FREEBSD32
3221 uint32_t vfc_vfsops;
3222 char vfc_name[MFSNAMELEN];
3223 int32_t vfc_typenum;
3224 int32_t vfc_refcount;
3230 vfsconf2x32(struct sysctl_req *req, struct vfsconf *vfsp)
3232 struct xvfsconf32 xvfsp;
3234 strcpy(xvfsp.vfc_name, vfsp->vfc_name);
3235 xvfsp.vfc_typenum = vfsp->vfc_typenum;
3236 xvfsp.vfc_refcount = vfsp->vfc_refcount;
3237 xvfsp.vfc_flags = vfsp->vfc_flags;
3238 xvfsp.vfc_vfsops = 0;
3240 return (SYSCTL_OUT(req, &xvfsp, sizeof(xvfsp)));
3245 * Top level filesystem related information gathering.
3248 sysctl_vfs_conflist(SYSCTL_HANDLER_ARGS)
3250 struct vfsconf *vfsp;
3254 TAILQ_FOREACH(vfsp, &vfsconf, vfc_list) {
3255 #ifdef COMPAT_FREEBSD32
3256 if (req->flags & SCTL_MASK32)
3257 error = vfsconf2x32(req, vfsp);
3260 error = vfsconf2x(req, vfsp);
3267 SYSCTL_PROC(_vfs, OID_AUTO, conflist, CTLTYPE_OPAQUE | CTLFLAG_RD,
3268 NULL, 0, sysctl_vfs_conflist,
3269 "S,xvfsconf", "List of all configured filesystems");
3271 #ifndef BURN_BRIDGES
3272 static int sysctl_ovfs_conf(SYSCTL_HANDLER_ARGS);
3275 vfs_sysctl(SYSCTL_HANDLER_ARGS)
3277 int *name = (int *)arg1 - 1; /* XXX */
3278 u_int namelen = arg2 + 1; /* XXX */
3279 struct vfsconf *vfsp;
3281 log(LOG_WARNING, "userland calling deprecated sysctl, "
3282 "please rebuild world\n");
3284 #if 1 || defined(COMPAT_PRELITE2)
3285 /* Resolve ambiguity between VFS_VFSCONF and VFS_GENERIC. */
3287 return (sysctl_ovfs_conf(oidp, arg1, arg2, req));
3291 case VFS_MAXTYPENUM:
3294 return (SYSCTL_OUT(req, &maxvfsconf, sizeof(int)));
3297 return (ENOTDIR); /* overloaded */
3298 TAILQ_FOREACH(vfsp, &vfsconf, vfc_list)
3299 if (vfsp->vfc_typenum == name[2])
3302 return (EOPNOTSUPP);
3303 #ifdef COMPAT_FREEBSD32
3304 if (req->flags & SCTL_MASK32)
3305 return (vfsconf2x32(req, vfsp));
3308 return (vfsconf2x(req, vfsp));
3310 return (EOPNOTSUPP);
3313 static SYSCTL_NODE(_vfs, VFS_GENERIC, generic, CTLFLAG_RD | CTLFLAG_SKIP,
3314 vfs_sysctl, "Generic filesystem");
3316 #if 1 || defined(COMPAT_PRELITE2)
3319 sysctl_ovfs_conf(SYSCTL_HANDLER_ARGS)
3322 struct vfsconf *vfsp;
3323 struct ovfsconf ovfs;
3325 TAILQ_FOREACH(vfsp, &vfsconf, vfc_list) {
3326 bzero(&ovfs, sizeof(ovfs));
3327 ovfs.vfc_vfsops = vfsp->vfc_vfsops; /* XXX used as flag */
3328 strcpy(ovfs.vfc_name, vfsp->vfc_name);
3329 ovfs.vfc_index = vfsp->vfc_typenum;
3330 ovfs.vfc_refcount = vfsp->vfc_refcount;
3331 ovfs.vfc_flags = vfsp->vfc_flags;
3332 error = SYSCTL_OUT(req, &ovfs, sizeof ovfs);
3339 #endif /* 1 || COMPAT_PRELITE2 */
3340 #endif /* !BURN_BRIDGES */
3342 #define KINFO_VNODESLOP 10
3345 * Dump vnode list (via sysctl).
3349 sysctl_vnode(SYSCTL_HANDLER_ARGS)
3357 * Stale numvnodes access is not fatal here.
3360 len = (numvnodes + KINFO_VNODESLOP) * sizeof *xvn;
3362 /* Make an estimate */
3363 return (SYSCTL_OUT(req, 0, len));
3365 error = sysctl_wire_old_buffer(req, 0);
3368 xvn = malloc(len, M_TEMP, M_ZERO | M_WAITOK);
3370 mtx_lock(&mountlist_mtx);
3371 TAILQ_FOREACH(mp, &mountlist, mnt_list) {
3372 if (vfs_busy(mp, MBF_NOWAIT | MBF_MNTLSTLOCK))
3375 TAILQ_FOREACH(vp, &mp->mnt_nvnodelist, v_nmntvnodes) {
3379 xvn[n].xv_size = sizeof *xvn;
3380 xvn[n].xv_vnode = vp;
3381 xvn[n].xv_id = 0; /* XXX compat */
3382 #define XV_COPY(field) xvn[n].xv_##field = vp->v_##field
3384 XV_COPY(writecount);
3390 xvn[n].xv_flag = vp->v_vflag;
3392 switch (vp->v_type) {
3399 if (vp->v_rdev == NULL) {
3403 xvn[n].xv_dev = dev2udev(vp->v_rdev);
3406 xvn[n].xv_socket = vp->v_socket;
3409 xvn[n].xv_fifo = vp->v_fifoinfo;
3414 /* shouldn't happen? */
3422 mtx_lock(&mountlist_mtx);
3427 mtx_unlock(&mountlist_mtx);
3429 error = SYSCTL_OUT(req, xvn, n * sizeof *xvn);
3434 SYSCTL_PROC(_kern, KERN_VNODE, vnode, CTLTYPE_OPAQUE|CTLFLAG_RD,
3435 0, 0, sysctl_vnode, "S,xvnode", "");
3439 * Unmount all filesystems. The list is traversed in reverse order
3440 * of mounting to avoid dependencies.
3443 vfs_unmountall(void)
3449 CTR1(KTR_VFS, "%s: unmounting all filesystems", __func__);
3453 * Since this only runs when rebooting, it is not interlocked.
3455 while(!TAILQ_EMPTY(&mountlist)) {
3456 mp = TAILQ_LAST(&mountlist, mntlist);
3457 error = dounmount(mp, MNT_FORCE, td);
3459 TAILQ_REMOVE(&mountlist, mp, mnt_list);
3461 * XXX: Due to the way in which we mount the root
3462 * file system off of devfs, devfs will generate a
3463 * "busy" warning when we try to unmount it before
3464 * the root. Don't print a warning as a result in
3465 * order to avoid false positive errors that may
3466 * cause needless upset.
3468 if (strcmp(mp->mnt_vfc->vfc_name, "devfs") != 0) {
3469 printf("unmount of %s failed (",
3470 mp->mnt_stat.f_mntonname);
3474 printf("%d)\n", error);
3477 /* The unmount has removed mp from the mountlist */
3483 * perform msync on all vnodes under a mount point
3484 * the mount point must be locked.
3487 vfs_msync(struct mount *mp, int flags)
3489 struct vnode *vp, *mvp;
3490 struct vm_object *obj;
3492 CTR2(KTR_VFS, "%s: mp %p", __func__, mp);
3493 MNT_VNODE_FOREACH_ACTIVE(vp, mp, mvp) {
3495 if (obj != NULL && (obj->flags & OBJ_MIGHTBEDIRTY) != 0 &&
3496 (flags == MNT_WAIT || VOP_ISLOCKED(vp) == 0)) {
3498 LK_EXCLUSIVE | LK_RETRY | LK_INTERLOCK,
3500 if (vp->v_vflag & VV_NOSYNC) { /* unlinked */
3507 VM_OBJECT_WLOCK(obj);
3508 vm_object_page_clean(obj, 0, 0,
3510 OBJPC_SYNC : OBJPC_NOSYNC);
3511 VM_OBJECT_WUNLOCK(obj);
3521 destroy_vpollinfo(struct vpollinfo *vi)
3523 seldrain(&vi->vpi_selinfo);
3524 knlist_destroy(&vi->vpi_selinfo.si_note);
3525 mtx_destroy(&vi->vpi_lock);
3526 uma_zfree(vnodepoll_zone, vi);
3530 * Initalize per-vnode helper structure to hold poll-related state.
3533 v_addpollinfo(struct vnode *vp)
3535 struct vpollinfo *vi;
3537 if (vp->v_pollinfo != NULL)
3539 vi = uma_zalloc(vnodepoll_zone, M_WAITOK);
3540 mtx_init(&vi->vpi_lock, "vnode pollinfo", NULL, MTX_DEF);
3541 knlist_init(&vi->vpi_selinfo.si_note, vp, vfs_knllock,
3542 vfs_knlunlock, vfs_knl_assert_locked, vfs_knl_assert_unlocked);
3544 if (vp->v_pollinfo != NULL) {
3546 destroy_vpollinfo(vi);
3549 vp->v_pollinfo = vi;
3554 * Record a process's interest in events which might happen to
3555 * a vnode. Because poll uses the historic select-style interface
3556 * internally, this routine serves as both the ``check for any
3557 * pending events'' and the ``record my interest in future events''
3558 * functions. (These are done together, while the lock is held,
3559 * to avoid race conditions.)
3562 vn_pollrecord(struct vnode *vp, struct thread *td, int events)
3566 mtx_lock(&vp->v_pollinfo->vpi_lock);
3567 if (vp->v_pollinfo->vpi_revents & events) {
3569 * This leaves events we are not interested
3570 * in available for the other process which
3571 * which presumably had requested them
3572 * (otherwise they would never have been
3575 events &= vp->v_pollinfo->vpi_revents;
3576 vp->v_pollinfo->vpi_revents &= ~events;
3578 mtx_unlock(&vp->v_pollinfo->vpi_lock);
3581 vp->v_pollinfo->vpi_events |= events;
3582 selrecord(td, &vp->v_pollinfo->vpi_selinfo);
3583 mtx_unlock(&vp->v_pollinfo->vpi_lock);
3588 * Routine to create and manage a filesystem syncer vnode.
3590 #define sync_close ((int (*)(struct vop_close_args *))nullop)
3591 static int sync_fsync(struct vop_fsync_args *);
3592 static int sync_inactive(struct vop_inactive_args *);
3593 static int sync_reclaim(struct vop_reclaim_args *);
3595 static struct vop_vector sync_vnodeops = {
3596 .vop_bypass = VOP_EOPNOTSUPP,
3597 .vop_close = sync_close, /* close */
3598 .vop_fsync = sync_fsync, /* fsync */
3599 .vop_inactive = sync_inactive, /* inactive */
3600 .vop_reclaim = sync_reclaim, /* reclaim */
3601 .vop_lock1 = vop_stdlock, /* lock */
3602 .vop_unlock = vop_stdunlock, /* unlock */
3603 .vop_islocked = vop_stdislocked, /* islocked */
3607 * Create a new filesystem syncer vnode for the specified mount point.
3610 vfs_allocate_syncvnode(struct mount *mp)
3614 static long start, incr, next;
3617 /* Allocate a new vnode */
3618 error = getnewvnode("syncer", mp, &sync_vnodeops, &vp);
3620 panic("vfs_allocate_syncvnode: getnewvnode() failed");
3622 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
3623 vp->v_vflag |= VV_FORCEINSMQ;
3624 error = insmntque(vp, mp);
3626 panic("vfs_allocate_syncvnode: insmntque() failed");
3627 vp->v_vflag &= ~VV_FORCEINSMQ;
3630 * Place the vnode onto the syncer worklist. We attempt to
3631 * scatter them about on the list so that they will go off
3632 * at evenly distributed times even if all the filesystems
3633 * are mounted at once.
3636 if (next == 0 || next > syncer_maxdelay) {
3640 start = syncer_maxdelay / 2;
3641 incr = syncer_maxdelay;
3647 vn_syncer_add_to_worklist(bo, syncdelay > 0 ? next % syncdelay : 0);
3648 /* XXX - vn_syncer_add_to_worklist() also grabs and drops sync_mtx. */
3649 mtx_lock(&sync_mtx);
3651 if (mp->mnt_syncer == NULL) {
3652 mp->mnt_syncer = vp;
3655 mtx_unlock(&sync_mtx);
3658 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
3665 vfs_deallocate_syncvnode(struct mount *mp)
3669 mtx_lock(&sync_mtx);
3670 vp = mp->mnt_syncer;
3672 mp->mnt_syncer = NULL;
3673 mtx_unlock(&sync_mtx);
3679 * Do a lazy sync of the filesystem.
3682 sync_fsync(struct vop_fsync_args *ap)
3684 struct vnode *syncvp = ap->a_vp;
3685 struct mount *mp = syncvp->v_mount;
3690 * We only need to do something if this is a lazy evaluation.
3692 if (ap->a_waitfor != MNT_LAZY)
3696 * Move ourselves to the back of the sync list.
3698 bo = &syncvp->v_bufobj;
3700 vn_syncer_add_to_worklist(bo, syncdelay);
3704 * Walk the list of vnodes pushing all that are dirty and
3705 * not already on the sync list.
3707 mtx_lock(&mountlist_mtx);
3708 if (vfs_busy(mp, MBF_NOWAIT | MBF_MNTLSTLOCK) != 0) {
3709 mtx_unlock(&mountlist_mtx);
3712 if (vn_start_write(NULL, &mp, V_NOWAIT) != 0) {
3716 save = curthread_pflags_set(TDP_SYNCIO);
3717 vfs_msync(mp, MNT_NOWAIT);
3718 error = VFS_SYNC(mp, MNT_LAZY);
3719 curthread_pflags_restore(save);
3720 vn_finished_write(mp);
3726 * The syncer vnode is no referenced.
3729 sync_inactive(struct vop_inactive_args *ap)
3737 * The syncer vnode is no longer needed and is being decommissioned.
3739 * Modifications to the worklist must be protected by sync_mtx.
3742 sync_reclaim(struct vop_reclaim_args *ap)
3744 struct vnode *vp = ap->a_vp;
3749 mtx_lock(&sync_mtx);
3750 if (vp->v_mount->mnt_syncer == vp)
3751 vp->v_mount->mnt_syncer = NULL;
3752 if (bo->bo_flag & BO_ONWORKLST) {
3753 LIST_REMOVE(bo, bo_synclist);
3754 syncer_worklist_len--;
3756 bo->bo_flag &= ~BO_ONWORKLST;
3758 mtx_unlock(&sync_mtx);
3765 * Check if vnode represents a disk device
3768 vn_isdisk(struct vnode *vp, int *errp)
3774 if (vp->v_type != VCHR)
3776 else if (vp->v_rdev == NULL)
3778 else if (vp->v_rdev->si_devsw == NULL)
3780 else if (!(vp->v_rdev->si_devsw->d_flags & D_DISK))
3785 return (error == 0);
3789 * Common filesystem object access control check routine. Accepts a
3790 * vnode's type, "mode", uid and gid, requested access mode, credentials,
3791 * and optional call-by-reference privused argument allowing vaccess()
3792 * to indicate to the caller whether privilege was used to satisfy the
3793 * request (obsoleted). Returns 0 on success, or an errno on failure.
3796 vaccess(enum vtype type, mode_t file_mode, uid_t file_uid, gid_t file_gid,
3797 accmode_t accmode, struct ucred *cred, int *privused)
3799 accmode_t dac_granted;
3800 accmode_t priv_granted;
3802 KASSERT((accmode & ~(VEXEC | VWRITE | VREAD | VADMIN | VAPPEND)) == 0,
3803 ("invalid bit in accmode"));
3804 KASSERT((accmode & VAPPEND) == 0 || (accmode & VWRITE),
3805 ("VAPPEND without VWRITE"));
3808 * Look for a normal, non-privileged way to access the file/directory
3809 * as requested. If it exists, go with that.
3812 if (privused != NULL)
3817 /* Check the owner. */
3818 if (cred->cr_uid == file_uid) {
3819 dac_granted |= VADMIN;
3820 if (file_mode & S_IXUSR)
3821 dac_granted |= VEXEC;
3822 if (file_mode & S_IRUSR)
3823 dac_granted |= VREAD;
3824 if (file_mode & S_IWUSR)
3825 dac_granted |= (VWRITE | VAPPEND);
3827 if ((accmode & dac_granted) == accmode)
3833 /* Otherwise, check the groups (first match) */
3834 if (groupmember(file_gid, cred)) {
3835 if (file_mode & S_IXGRP)
3836 dac_granted |= VEXEC;
3837 if (file_mode & S_IRGRP)
3838 dac_granted |= VREAD;
3839 if (file_mode & S_IWGRP)
3840 dac_granted |= (VWRITE | VAPPEND);
3842 if ((accmode & dac_granted) == accmode)
3848 /* Otherwise, check everyone else. */
3849 if (file_mode & S_IXOTH)
3850 dac_granted |= VEXEC;
3851 if (file_mode & S_IROTH)
3852 dac_granted |= VREAD;
3853 if (file_mode & S_IWOTH)
3854 dac_granted |= (VWRITE | VAPPEND);
3855 if ((accmode & dac_granted) == accmode)
3860 * Build a privilege mask to determine if the set of privileges
3861 * satisfies the requirements when combined with the granted mask
3862 * from above. For each privilege, if the privilege is required,
3863 * bitwise or the request type onto the priv_granted mask.
3869 * For directories, use PRIV_VFS_LOOKUP to satisfy VEXEC
3870 * requests, instead of PRIV_VFS_EXEC.
3872 if ((accmode & VEXEC) && ((dac_granted & VEXEC) == 0) &&
3873 !priv_check_cred(cred, PRIV_VFS_LOOKUP, 0))
3874 priv_granted |= VEXEC;
3877 * Ensure that at least one execute bit is on. Otherwise,
3878 * a privileged user will always succeed, and we don't want
3879 * this to happen unless the file really is executable.
3881 if ((accmode & VEXEC) && ((dac_granted & VEXEC) == 0) &&
3882 (file_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0 &&
3883 !priv_check_cred(cred, PRIV_VFS_EXEC, 0))
3884 priv_granted |= VEXEC;
3887 if ((accmode & VREAD) && ((dac_granted & VREAD) == 0) &&
3888 !priv_check_cred(cred, PRIV_VFS_READ, 0))
3889 priv_granted |= VREAD;
3891 if ((accmode & VWRITE) && ((dac_granted & VWRITE) == 0) &&
3892 !priv_check_cred(cred, PRIV_VFS_WRITE, 0))
3893 priv_granted |= (VWRITE | VAPPEND);
3895 if ((accmode & VADMIN) && ((dac_granted & VADMIN) == 0) &&
3896 !priv_check_cred(cred, PRIV_VFS_ADMIN, 0))
3897 priv_granted |= VADMIN;
3899 if ((accmode & (priv_granted | dac_granted)) == accmode) {
3900 /* XXX audit: privilege used */
3901 if (privused != NULL)
3906 return ((accmode & VADMIN) ? EPERM : EACCES);
3910 * Credential check based on process requesting service, and per-attribute
3914 extattr_check_cred(struct vnode *vp, int attrnamespace, struct ucred *cred,
3915 struct thread *td, accmode_t accmode)
3919 * Kernel-invoked always succeeds.
3925 * Do not allow privileged processes in jail to directly manipulate
3926 * system attributes.
3928 switch (attrnamespace) {
3929 case EXTATTR_NAMESPACE_SYSTEM:
3930 /* Potentially should be: return (EPERM); */
3931 return (priv_check_cred(cred, PRIV_VFS_EXTATTR_SYSTEM, 0));
3932 case EXTATTR_NAMESPACE_USER:
3933 return (VOP_ACCESS(vp, accmode, cred, td));
3939 #ifdef DEBUG_VFS_LOCKS
3941 * This only exists to supress warnings from unlocked specfs accesses. It is
3942 * no longer ok to have an unlocked VFS.
3944 #define IGNORE_LOCK(vp) (panicstr != NULL || (vp) == NULL || \
3945 (vp)->v_type == VCHR || (vp)->v_type == VBAD)
3947 int vfs_badlock_ddb = 1; /* Drop into debugger on violation. */
3948 SYSCTL_INT(_debug, OID_AUTO, vfs_badlock_ddb, CTLFLAG_RW, &vfs_badlock_ddb, 0,
3949 "Drop into debugger on lock violation");
3951 int vfs_badlock_mutex = 1; /* Check for interlock across VOPs. */
3952 SYSCTL_INT(_debug, OID_AUTO, vfs_badlock_mutex, CTLFLAG_RW, &vfs_badlock_mutex,
3953 0, "Check for interlock across VOPs");
3955 int vfs_badlock_print = 1; /* Print lock violations. */
3956 SYSCTL_INT(_debug, OID_AUTO, vfs_badlock_print, CTLFLAG_RW, &vfs_badlock_print,
3957 0, "Print lock violations");
3960 int vfs_badlock_backtrace = 1; /* Print backtrace at lock violations. */
3961 SYSCTL_INT(_debug, OID_AUTO, vfs_badlock_backtrace, CTLFLAG_RW,
3962 &vfs_badlock_backtrace, 0, "Print backtrace at lock violations");
3966 vfs_badlock(const char *msg, const char *str, struct vnode *vp)
3970 if (vfs_badlock_backtrace)
3973 if (vfs_badlock_print)
3974 printf("%s: %p %s\n", str, (void *)vp, msg);
3975 if (vfs_badlock_ddb)
3976 kdb_enter(KDB_WHY_VFSLOCK, "lock violation");
3980 assert_vi_locked(struct vnode *vp, const char *str)
3983 if (vfs_badlock_mutex && !mtx_owned(VI_MTX(vp)))
3984 vfs_badlock("interlock is not locked but should be", str, vp);
3988 assert_vi_unlocked(struct vnode *vp, const char *str)
3991 if (vfs_badlock_mutex && mtx_owned(VI_MTX(vp)))
3992 vfs_badlock("interlock is locked but should not be", str, vp);
3996 assert_vop_locked(struct vnode *vp, const char *str)
4000 if (!IGNORE_LOCK(vp)) {
4001 locked = VOP_ISLOCKED(vp);
4002 if (locked == 0 || locked == LK_EXCLOTHER)
4003 vfs_badlock("is not locked but should be", str, vp);
4008 assert_vop_unlocked(struct vnode *vp, const char *str)
4011 if (!IGNORE_LOCK(vp) && VOP_ISLOCKED(vp) == LK_EXCLUSIVE)
4012 vfs_badlock("is locked but should not be", str, vp);
4016 assert_vop_elocked(struct vnode *vp, const char *str)
4019 if (!IGNORE_LOCK(vp) && VOP_ISLOCKED(vp) != LK_EXCLUSIVE)
4020 vfs_badlock("is not exclusive locked but should be", str, vp);
4025 assert_vop_elocked_other(struct vnode *vp, const char *str)
4028 if (!IGNORE_LOCK(vp) && VOP_ISLOCKED(vp) != LK_EXCLOTHER)
4029 vfs_badlock("is not exclusive locked by another thread",
4034 assert_vop_slocked(struct vnode *vp, const char *str)
4037 if (!IGNORE_LOCK(vp) && VOP_ISLOCKED(vp) != LK_SHARED)
4038 vfs_badlock("is not locked shared but should be", str, vp);
4041 #endif /* DEBUG_VFS_LOCKS */
4044 vop_rename_fail(struct vop_rename_args *ap)
4047 if (ap->a_tvp != NULL)
4049 if (ap->a_tdvp == ap->a_tvp)
4058 vop_rename_pre(void *ap)
4060 struct vop_rename_args *a = ap;
4062 #ifdef DEBUG_VFS_LOCKS
4064 ASSERT_VI_UNLOCKED(a->a_tvp, "VOP_RENAME");
4065 ASSERT_VI_UNLOCKED(a->a_tdvp, "VOP_RENAME");
4066 ASSERT_VI_UNLOCKED(a->a_fvp, "VOP_RENAME");
4067 ASSERT_VI_UNLOCKED(a->a_fdvp, "VOP_RENAME");
4069 /* Check the source (from). */
4070 if (a->a_tdvp->v_vnlock != a->a_fdvp->v_vnlock &&
4071 (a->a_tvp == NULL || a->a_tvp->v_vnlock != a->a_fdvp->v_vnlock))
4072 ASSERT_VOP_UNLOCKED(a->a_fdvp, "vop_rename: fdvp locked");
4073 if (a->a_tvp == NULL || a->a_tvp->v_vnlock != a->a_fvp->v_vnlock)
4074 ASSERT_VOP_UNLOCKED(a->a_fvp, "vop_rename: fvp locked");
4076 /* Check the target. */
4078 ASSERT_VOP_LOCKED(a->a_tvp, "vop_rename: tvp not locked");
4079 ASSERT_VOP_LOCKED(a->a_tdvp, "vop_rename: tdvp not locked");
4081 if (a->a_tdvp != a->a_fdvp)
4083 if (a->a_tvp != a->a_fvp)
4091 vop_strategy_pre(void *ap)
4093 #ifdef DEBUG_VFS_LOCKS
4094 struct vop_strategy_args *a;
4101 * Cluster ops lock their component buffers but not the IO container.
4103 if ((bp->b_flags & B_CLUSTER) != 0)
4106 if (panicstr == NULL && !BUF_ISLOCKED(bp)) {
4107 if (vfs_badlock_print)
4109 "VOP_STRATEGY: bp is not locked but should be\n");
4110 if (vfs_badlock_ddb)
4111 kdb_enter(KDB_WHY_VFSLOCK, "lock violation");
4117 vop_lock_pre(void *ap)
4119 #ifdef DEBUG_VFS_LOCKS
4120 struct vop_lock1_args *a = ap;
4122 if ((a->a_flags & LK_INTERLOCK) == 0)
4123 ASSERT_VI_UNLOCKED(a->a_vp, "VOP_LOCK");
4125 ASSERT_VI_LOCKED(a->a_vp, "VOP_LOCK");
4130 vop_lock_post(void *ap, int rc)
4132 #ifdef DEBUG_VFS_LOCKS
4133 struct vop_lock1_args *a = ap;
4135 ASSERT_VI_UNLOCKED(a->a_vp, "VOP_LOCK");
4137 ASSERT_VOP_LOCKED(a->a_vp, "VOP_LOCK");
4142 vop_unlock_pre(void *ap)
4144 #ifdef DEBUG_VFS_LOCKS
4145 struct vop_unlock_args *a = ap;
4147 if (a->a_flags & LK_INTERLOCK)
4148 ASSERT_VI_LOCKED(a->a_vp, "VOP_UNLOCK");
4149 ASSERT_VOP_LOCKED(a->a_vp, "VOP_UNLOCK");
4154 vop_unlock_post(void *ap, int rc)
4156 #ifdef DEBUG_VFS_LOCKS
4157 struct vop_unlock_args *a = ap;
4159 if (a->a_flags & LK_INTERLOCK)
4160 ASSERT_VI_UNLOCKED(a->a_vp, "VOP_UNLOCK");
4165 vop_create_post(void *ap, int rc)
4167 struct vop_create_args *a = ap;
4170 VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE);
4174 vop_deleteextattr_post(void *ap, int rc)
4176 struct vop_deleteextattr_args *a = ap;
4179 VFS_KNOTE_LOCKED(a->a_vp, NOTE_ATTRIB);
4183 vop_link_post(void *ap, int rc)
4185 struct vop_link_args *a = ap;
4188 VFS_KNOTE_LOCKED(a->a_vp, NOTE_LINK);
4189 VFS_KNOTE_LOCKED(a->a_tdvp, NOTE_WRITE);
4194 vop_mkdir_post(void *ap, int rc)
4196 struct vop_mkdir_args *a = ap;
4199 VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE | NOTE_LINK);
4203 vop_mknod_post(void *ap, int rc)
4205 struct vop_mknod_args *a = ap;
4208 VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE);
4212 vop_remove_post(void *ap, int rc)
4214 struct vop_remove_args *a = ap;
4217 VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE);
4218 VFS_KNOTE_LOCKED(a->a_vp, NOTE_DELETE);
4223 vop_rename_post(void *ap, int rc)
4225 struct vop_rename_args *a = ap;
4228 VFS_KNOTE_UNLOCKED(a->a_fdvp, NOTE_WRITE);
4229 VFS_KNOTE_UNLOCKED(a->a_tdvp, NOTE_WRITE);
4230 VFS_KNOTE_UNLOCKED(a->a_fvp, NOTE_RENAME);
4232 VFS_KNOTE_UNLOCKED(a->a_tvp, NOTE_DELETE);
4234 if (a->a_tdvp != a->a_fdvp)
4236 if (a->a_tvp != a->a_fvp)
4244 vop_rmdir_post(void *ap, int rc)
4246 struct vop_rmdir_args *a = ap;
4249 VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE | NOTE_LINK);
4250 VFS_KNOTE_LOCKED(a->a_vp, NOTE_DELETE);
4255 vop_setattr_post(void *ap, int rc)
4257 struct vop_setattr_args *a = ap;
4260 VFS_KNOTE_LOCKED(a->a_vp, NOTE_ATTRIB);
4264 vop_setextattr_post(void *ap, int rc)
4266 struct vop_setextattr_args *a = ap;
4269 VFS_KNOTE_LOCKED(a->a_vp, NOTE_ATTRIB);
4273 vop_symlink_post(void *ap, int rc)
4275 struct vop_symlink_args *a = ap;
4278 VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE);
4281 static struct knlist fs_knlist;
4284 vfs_event_init(void *arg)
4286 knlist_init_mtx(&fs_knlist, NULL);
4288 /* XXX - correct order? */
4289 SYSINIT(vfs_knlist, SI_SUB_VFS, SI_ORDER_ANY, vfs_event_init, NULL);
4292 vfs_event_signal(fsid_t *fsid, uint32_t event, intptr_t data __unused)
4295 KNOTE_UNLOCKED(&fs_knlist, event);
4298 static int filt_fsattach(struct knote *kn);
4299 static void filt_fsdetach(struct knote *kn);
4300 static int filt_fsevent(struct knote *kn, long hint);
4302 struct filterops fs_filtops = {
4304 .f_attach = filt_fsattach,
4305 .f_detach = filt_fsdetach,
4306 .f_event = filt_fsevent
4310 filt_fsattach(struct knote *kn)
4313 kn->kn_flags |= EV_CLEAR;
4314 knlist_add(&fs_knlist, kn, 0);
4319 filt_fsdetach(struct knote *kn)
4322 knlist_remove(&fs_knlist, kn, 0);
4326 filt_fsevent(struct knote *kn, long hint)
4329 kn->kn_fflags |= hint;
4330 return (kn->kn_fflags != 0);
4334 sysctl_vfs_ctl(SYSCTL_HANDLER_ARGS)
4340 error = SYSCTL_IN(req, &vc, sizeof(vc));
4343 if (vc.vc_vers != VFS_CTL_VERS1)
4345 mp = vfs_getvfs(&vc.vc_fsid);
4348 /* ensure that a specific sysctl goes to the right filesystem. */
4349 if (strcmp(vc.vc_fstypename, "*") != 0 &&
4350 strcmp(vc.vc_fstypename, mp->mnt_vfc->vfc_name) != 0) {
4354 VCTLTOREQ(&vc, req);
4355 error = VFS_SYSCTL(mp, vc.vc_op, req);
4360 SYSCTL_PROC(_vfs, OID_AUTO, ctl, CTLTYPE_OPAQUE | CTLFLAG_WR,
4361 NULL, 0, sysctl_vfs_ctl, "",
4365 * Function to initialize a va_filerev field sensibly.
4366 * XXX: Wouldn't a random number make a lot more sense ??
4369 init_va_filerev(void)
4374 return (((u_quad_t)bt.sec << 32LL) | (bt.frac >> 32LL));
4377 static int filt_vfsread(struct knote *kn, long hint);
4378 static int filt_vfswrite(struct knote *kn, long hint);
4379 static int filt_vfsvnode(struct knote *kn, long hint);
4380 static void filt_vfsdetach(struct knote *kn);
4381 static struct filterops vfsread_filtops = {
4383 .f_detach = filt_vfsdetach,
4384 .f_event = filt_vfsread
4386 static struct filterops vfswrite_filtops = {
4388 .f_detach = filt_vfsdetach,
4389 .f_event = filt_vfswrite
4391 static struct filterops vfsvnode_filtops = {
4393 .f_detach = filt_vfsdetach,
4394 .f_event = filt_vfsvnode
4398 vfs_knllock(void *arg)
4400 struct vnode *vp = arg;
4402 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
4406 vfs_knlunlock(void *arg)
4408 struct vnode *vp = arg;
4414 vfs_knl_assert_locked(void *arg)
4416 #ifdef DEBUG_VFS_LOCKS
4417 struct vnode *vp = arg;
4419 ASSERT_VOP_LOCKED(vp, "vfs_knl_assert_locked");
4424 vfs_knl_assert_unlocked(void *arg)
4426 #ifdef DEBUG_VFS_LOCKS
4427 struct vnode *vp = arg;
4429 ASSERT_VOP_UNLOCKED(vp, "vfs_knl_assert_unlocked");
4434 vfs_kqfilter(struct vop_kqfilter_args *ap)
4436 struct vnode *vp = ap->a_vp;
4437 struct knote *kn = ap->a_kn;
4440 switch (kn->kn_filter) {
4442 kn->kn_fop = &vfsread_filtops;
4445 kn->kn_fop = &vfswrite_filtops;
4448 kn->kn_fop = &vfsvnode_filtops;
4454 kn->kn_hook = (caddr_t)vp;
4457 if (vp->v_pollinfo == NULL)
4459 knl = &vp->v_pollinfo->vpi_selinfo.si_note;
4460 knlist_add(knl, kn, 0);
4466 * Detach knote from vnode
4469 filt_vfsdetach(struct knote *kn)
4471 struct vnode *vp = (struct vnode *)kn->kn_hook;
4473 KASSERT(vp->v_pollinfo != NULL, ("Missing v_pollinfo"));
4474 knlist_remove(&vp->v_pollinfo->vpi_selinfo.si_note, kn, 0);
4479 filt_vfsread(struct knote *kn, long hint)
4481 struct vnode *vp = (struct vnode *)kn->kn_hook;
4486 * filesystem is gone, so set the EOF flag and schedule
4487 * the knote for deletion.
4489 if (hint == NOTE_REVOKE) {
4491 kn->kn_flags |= (EV_EOF | EV_ONESHOT);
4496 if (VOP_GETATTR(vp, &va, curthread->td_ucred))
4500 kn->kn_data = va.va_size - kn->kn_fp->f_offset;
4501 res = (kn->kn_data != 0);
4508 filt_vfswrite(struct knote *kn, long hint)
4510 struct vnode *vp = (struct vnode *)kn->kn_hook;
4515 * filesystem is gone, so set the EOF flag and schedule
4516 * the knote for deletion.
4518 if (hint == NOTE_REVOKE)
4519 kn->kn_flags |= (EV_EOF | EV_ONESHOT);
4527 filt_vfsvnode(struct knote *kn, long hint)
4529 struct vnode *vp = (struct vnode *)kn->kn_hook;
4533 if (kn->kn_sfflags & hint)
4534 kn->kn_fflags |= hint;
4535 if (hint == NOTE_REVOKE) {
4536 kn->kn_flags |= EV_EOF;
4540 res = (kn->kn_fflags != 0);
4546 vfs_read_dirent(struct vop_readdir_args *ap, struct dirent *dp, off_t off)
4550 if (dp->d_reclen > ap->a_uio->uio_resid)
4551 return (ENAMETOOLONG);
4552 error = uiomove(dp, dp->d_reclen, ap->a_uio);
4554 if (ap->a_ncookies != NULL) {
4555 if (ap->a_cookies != NULL)
4556 free(ap->a_cookies, M_TEMP);
4557 ap->a_cookies = NULL;
4558 *ap->a_ncookies = 0;
4562 if (ap->a_ncookies == NULL)
4565 KASSERT(ap->a_cookies,
4566 ("NULL ap->a_cookies value with non-NULL ap->a_ncookies!"));
4568 *ap->a_cookies = realloc(*ap->a_cookies,
4569 (*ap->a_ncookies + 1) * sizeof(u_long), M_TEMP, M_WAITOK | M_ZERO);
4570 (*ap->a_cookies)[*ap->a_ncookies] = off;
4575 * Mark for update the access time of the file if the filesystem
4576 * supports VOP_MARKATIME. This functionality is used by execve and
4577 * mmap, so we want to avoid the I/O implied by directly setting
4578 * va_atime for the sake of efficiency.
4581 vfs_mark_atime(struct vnode *vp, struct ucred *cred)
4586 ASSERT_VOP_LOCKED(vp, "vfs_mark_atime");
4587 if (mp != NULL && (mp->mnt_flag & (MNT_NOATIME | MNT_RDONLY)) == 0)
4588 (void)VOP_MARKATIME(vp);
4592 * The purpose of this routine is to remove granularity from accmode_t,
4593 * reducing it into standard unix access bits - VEXEC, VREAD, VWRITE,
4594 * VADMIN and VAPPEND.
4596 * If it returns 0, the caller is supposed to continue with the usual
4597 * access checks using 'accmode' as modified by this routine. If it
4598 * returns nonzero value, the caller is supposed to return that value
4601 * Note that after this routine runs, accmode may be zero.
4604 vfs_unixify_accmode(accmode_t *accmode)
4607 * There is no way to specify explicit "deny" rule using
4608 * file mode or POSIX.1e ACLs.
4610 if (*accmode & VEXPLICIT_DENY) {
4616 * None of these can be translated into usual access bits.
4617 * Also, the common case for NFSv4 ACLs is to not contain
4618 * either of these bits. Caller should check for VWRITE
4619 * on the containing directory instead.
4621 if (*accmode & (VDELETE_CHILD | VDELETE))
4624 if (*accmode & VADMIN_PERMS) {
4625 *accmode &= ~VADMIN_PERMS;
4630 * There is no way to deny VREAD_ATTRIBUTES, VREAD_ACL
4631 * or VSYNCHRONIZE using file mode or POSIX.1e ACL.
4633 *accmode &= ~(VSTAT_PERMS | VSYNCHRONIZE);
4639 * These are helper functions for filesystems to traverse all
4640 * their vnodes. See MNT_VNODE_FOREACH_ALL() in sys/mount.h.
4642 * This interface replaces MNT_VNODE_FOREACH.
4645 MALLOC_DEFINE(M_VNODE_MARKER, "vnodemarker", "vnode marker");
4648 __mnt_vnode_next_all(struct vnode **mvp, struct mount *mp)
4653 kern_yield(PRI_USER);
4655 KASSERT((*mvp)->v_mount == mp, ("marker vnode mount list mismatch"));
4656 vp = TAILQ_NEXT(*mvp, v_nmntvnodes);
4657 while (vp != NULL && (vp->v_type == VMARKER ||
4658 (vp->v_iflag & VI_DOOMED) != 0))
4659 vp = TAILQ_NEXT(vp, v_nmntvnodes);
4661 /* Check if we are done */
4663 __mnt_vnode_markerfree_all(mvp, mp);
4664 /* MNT_IUNLOCK(mp); -- done in above function */
4665 mtx_assert(MNT_MTX(mp), MA_NOTOWNED);
4668 TAILQ_REMOVE(&mp->mnt_nvnodelist, *mvp, v_nmntvnodes);
4669 TAILQ_INSERT_AFTER(&mp->mnt_nvnodelist, vp, *mvp, v_nmntvnodes);
4676 __mnt_vnode_first_all(struct vnode **mvp, struct mount *mp)
4680 *mvp = malloc(sizeof(struct vnode), M_VNODE_MARKER, M_WAITOK | M_ZERO);
4683 (*mvp)->v_type = VMARKER;
4685 vp = TAILQ_FIRST(&mp->mnt_nvnodelist);
4686 while (vp != NULL && (vp->v_type == VMARKER ||
4687 (vp->v_iflag & VI_DOOMED) != 0))
4688 vp = TAILQ_NEXT(vp, v_nmntvnodes);
4690 /* Check if we are done */
4694 free(*mvp, M_VNODE_MARKER);
4698 (*mvp)->v_mount = mp;
4699 TAILQ_INSERT_AFTER(&mp->mnt_nvnodelist, vp, *mvp, v_nmntvnodes);
4707 __mnt_vnode_markerfree_all(struct vnode **mvp, struct mount *mp)
4715 mtx_assert(MNT_MTX(mp), MA_OWNED);
4717 KASSERT((*mvp)->v_mount == mp, ("marker vnode mount list mismatch"));
4718 TAILQ_REMOVE(&mp->mnt_nvnodelist, *mvp, v_nmntvnodes);
4721 free(*mvp, M_VNODE_MARKER);
4726 * These are helper functions for filesystems to traverse their
4727 * active vnodes. See MNT_VNODE_FOREACH_ACTIVE() in sys/mount.h
4730 mnt_vnode_markerfree_active(struct vnode **mvp, struct mount *mp)
4733 KASSERT((*mvp)->v_mount == mp, ("marker vnode mount list mismatch"));
4738 free(*mvp, M_VNODE_MARKER);
4742 static struct vnode *
4743 mnt_vnode_next_active(struct vnode **mvp, struct mount *mp)
4745 struct vnode *vp, *nvp;
4747 mtx_assert(&vnode_free_list_mtx, MA_OWNED);
4748 KASSERT((*mvp)->v_mount == mp, ("marker vnode mount list mismatch"));
4750 vp = TAILQ_NEXT(*mvp, v_actfreelist);
4751 TAILQ_REMOVE(&mp->mnt_activevnodelist, *mvp, v_actfreelist);
4752 while (vp != NULL) {
4753 if (vp->v_type == VMARKER) {
4754 vp = TAILQ_NEXT(vp, v_actfreelist);
4757 if (!VI_TRYLOCK(vp)) {
4758 if (mp_ncpus == 1 || should_yield()) {
4759 TAILQ_INSERT_BEFORE(vp, *mvp, v_actfreelist);
4760 mtx_unlock(&vnode_free_list_mtx);
4761 kern_yield(PRI_USER);
4762 mtx_lock(&vnode_free_list_mtx);
4767 KASSERT(vp->v_type != VMARKER, ("locked marker %p", vp));
4768 KASSERT(vp->v_mount == mp || vp->v_mount == NULL,
4769 ("alien vnode on the active list %p %p", vp, mp));
4770 if (vp->v_mount == mp && (vp->v_iflag & VI_DOOMED) == 0)
4772 nvp = TAILQ_NEXT(vp, v_actfreelist);
4777 /* Check if we are done */
4779 mtx_unlock(&vnode_free_list_mtx);
4780 mnt_vnode_markerfree_active(mvp, mp);
4783 TAILQ_INSERT_AFTER(&mp->mnt_activevnodelist, vp, *mvp, v_actfreelist);
4784 mtx_unlock(&vnode_free_list_mtx);
4785 ASSERT_VI_LOCKED(vp, "active iter");
4786 KASSERT((vp->v_iflag & VI_ACTIVE) != 0, ("Non-active vp %p", vp));
4791 __mnt_vnode_next_active(struct vnode **mvp, struct mount *mp)
4795 kern_yield(PRI_USER);
4796 mtx_lock(&vnode_free_list_mtx);
4797 return (mnt_vnode_next_active(mvp, mp));
4801 __mnt_vnode_first_active(struct vnode **mvp, struct mount *mp)
4805 *mvp = malloc(sizeof(struct vnode), M_VNODE_MARKER, M_WAITOK | M_ZERO);
4809 (*mvp)->v_type = VMARKER;
4810 (*mvp)->v_mount = mp;
4812 mtx_lock(&vnode_free_list_mtx);
4813 vp = TAILQ_FIRST(&mp->mnt_activevnodelist);
4815 mtx_unlock(&vnode_free_list_mtx);
4816 mnt_vnode_markerfree_active(mvp, mp);
4819 TAILQ_INSERT_BEFORE(vp, *mvp, v_actfreelist);
4820 return (mnt_vnode_next_active(mvp, mp));
4824 __mnt_vnode_markerfree_active(struct vnode **mvp, struct mount *mp)
4830 mtx_lock(&vnode_free_list_mtx);
4831 TAILQ_REMOVE(&mp->mnt_activevnodelist, *mvp, v_actfreelist);
4832 mtx_unlock(&vnode_free_list_mtx);
4833 mnt_vnode_markerfree_active(mvp, mp);