2 * SPDX-License-Identifier: BSD-3-Clause
4 * Copyright (c) 1989, 1993
5 * The Regents of the University of California. All rights reserved.
6 * (c) UNIX System Laboratories, Inc.
7 * All or some portions of this file are derived from material licensed
8 * to the University of California by American Telephone and Telegraph
9 * Co. or Unix System Laboratories, Inc. and are reproduced herein with
10 * the permission of UNIX System Laboratories, Inc.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * @(#)vfs_subr.c 8.31 (Berkeley) 5/26/95
40 * External virtual filesystem routines
43 #include <sys/cdefs.h>
44 __FBSDID("$FreeBSD$");
47 #include "opt_watchdog.h"
49 #include <sys/param.h>
50 #include <sys/systm.h>
53 #include <sys/condvar.h>
55 #include <sys/counter.h>
56 #include <sys/dirent.h>
57 #include <sys/event.h>
58 #include <sys/eventhandler.h>
59 #include <sys/extattr.h>
61 #include <sys/fcntl.h>
64 #include <sys/kernel.h>
65 #include <sys/kthread.h>
66 #include <sys/lockf.h>
67 #include <sys/malloc.h>
68 #include <sys/mount.h>
69 #include <sys/namei.h>
70 #include <sys/pctrie.h>
72 #include <sys/reboot.h>
73 #include <sys/refcount.h>
74 #include <sys/rwlock.h>
75 #include <sys/sched.h>
76 #include <sys/sleepqueue.h>
79 #include <sys/sysctl.h>
80 #include <sys/syslog.h>
81 #include <sys/vmmeter.h>
82 #include <sys/vnode.h>
83 #include <sys/watchdog.h>
85 #include <machine/stdarg.h>
87 #include <security/mac/mac_framework.h>
90 #include <vm/vm_object.h>
91 #include <vm/vm_extern.h>
93 #include <vm/vm_map.h>
94 #include <vm/vm_page.h>
95 #include <vm/vm_kern.h>
102 static void delmntque(struct vnode *vp);
103 static int flushbuflist(struct bufv *bufv, int flags, struct bufobj *bo,
104 int slpflag, int slptimeo);
105 static void syncer_shutdown(void *arg, int howto);
106 static int vtryrecycle(struct vnode *vp);
107 static void v_init_counters(struct vnode *);
108 static void v_incr_usecount(struct vnode *);
109 static void v_incr_usecount_locked(struct vnode *);
110 static void v_incr_devcount(struct vnode *);
111 static void v_decr_devcount(struct vnode *);
112 static void vgonel(struct vnode *);
113 static void vfs_knllock(void *arg);
114 static void vfs_knlunlock(void *arg);
115 static void vfs_knl_assert_locked(void *arg);
116 static void vfs_knl_assert_unlocked(void *arg);
117 static void vnlru_return_batches(struct vfsops *mnt_op);
118 static void destroy_vpollinfo(struct vpollinfo *vi);
121 * Number of vnodes in existence. Increased whenever getnewvnode()
122 * allocates a new vnode, decreased in vdropl() for VI_DOOMED vnode.
124 static unsigned long numvnodes;
126 SYSCTL_ULONG(_vfs, OID_AUTO, numvnodes, CTLFLAG_RD, &numvnodes, 0,
127 "Number of vnodes in existence");
129 static counter_u64_t vnodes_created;
130 SYSCTL_COUNTER_U64(_vfs, OID_AUTO, vnodes_created, CTLFLAG_RD, &vnodes_created,
131 "Number of vnodes created by getnewvnode");
133 static u_long mnt_free_list_batch = 128;
134 SYSCTL_ULONG(_vfs, OID_AUTO, mnt_free_list_batch, CTLFLAG_RW,
135 &mnt_free_list_batch, 0, "Limit of vnodes held on mnt's free list");
138 * Conversion tables for conversion from vnode types to inode formats
141 enum vtype iftovt_tab[16] = {
142 VNON, VFIFO, VCHR, VNON, VDIR, VNON, VBLK, VNON,
143 VREG, VNON, VLNK, VNON, VSOCK, VNON, VNON, VBAD,
145 int vttoif_tab[10] = {
146 0, S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK,
147 S_IFSOCK, S_IFIFO, S_IFMT, S_IFMT
151 * List of vnodes that are ready for recycling.
153 static TAILQ_HEAD(freelst, vnode) vnode_free_list;
156 * "Free" vnode target. Free vnodes are rarely completely free, but are
157 * just ones that are cheap to recycle. Usually they are for files which
158 * have been stat'd but not read; these usually have inode and namecache
159 * data attached to them. This target is the preferred minimum size of a
160 * sub-cache consisting mostly of such files. The system balances the size
161 * of this sub-cache with its complement to try to prevent either from
162 * thrashing while the other is relatively inactive. The targets express
163 * a preference for the best balance.
165 * "Above" this target there are 2 further targets (watermarks) related
166 * to recyling of free vnodes. In the best-operating case, the cache is
167 * exactly full, the free list has size between vlowat and vhiwat above the
168 * free target, and recycling from it and normal use maintains this state.
169 * Sometimes the free list is below vlowat or even empty, but this state
170 * is even better for immediate use provided the cache is not full.
171 * Otherwise, vnlru_proc() runs to reclaim enough vnodes (usually non-free
172 * ones) to reach one of these states. The watermarks are currently hard-
173 * coded as 4% and 9% of the available space higher. These and the default
174 * of 25% for wantfreevnodes are too large if the memory size is large.
175 * E.g., 9% of 75% of MAXVNODES is more than 566000 vnodes to reclaim
176 * whenever vnlru_proc() becomes active.
178 static u_long wantfreevnodes;
179 SYSCTL_ULONG(_vfs, OID_AUTO, wantfreevnodes, CTLFLAG_RW,
180 &wantfreevnodes, 0, "Target for minimum number of \"free\" vnodes");
181 static u_long freevnodes;
182 SYSCTL_ULONG(_vfs, OID_AUTO, freevnodes, CTLFLAG_RD,
183 &freevnodes, 0, "Number of \"free\" vnodes");
185 static counter_u64_t recycles_count;
186 SYSCTL_COUNTER_U64(_vfs, OID_AUTO, recycles, CTLFLAG_RD, &recycles_count,
187 "Number of vnodes recycled to meet vnode cache targets");
190 * Various variables used for debugging the new implementation of
192 * XXX these are probably of (very) limited utility now.
194 static int reassignbufcalls;
195 SYSCTL_INT(_vfs, OID_AUTO, reassignbufcalls, CTLFLAG_RW, &reassignbufcalls, 0,
196 "Number of calls to reassignbuf");
198 static counter_u64_t free_owe_inact;
199 SYSCTL_COUNTER_U64(_vfs, OID_AUTO, free_owe_inact, CTLFLAG_RD, &free_owe_inact,
200 "Number of times free vnodes kept on active list due to VFS "
201 "owing inactivation");
203 /* To keep more than one thread at a time from running vfs_getnewfsid */
204 static struct mtx mntid_mtx;
207 * Lock for any access to the following:
212 static struct mtx vnode_free_list_mtx;
214 /* Publicly exported FS */
215 struct nfs_public nfs_pub;
217 static uma_zone_t buf_trie_zone;
219 /* Zone for allocation of new vnodes - used exclusively by getnewvnode() */
220 static uma_zone_t vnode_zone;
221 static uma_zone_t vnodepoll_zone;
224 * The workitem queue.
226 * It is useful to delay writes of file data and filesystem metadata
227 * for tens of seconds so that quickly created and deleted files need
228 * not waste disk bandwidth being created and removed. To realize this,
229 * we append vnodes to a "workitem" queue. When running with a soft
230 * updates implementation, most pending metadata dependencies should
231 * not wait for more than a few seconds. Thus, mounted on block devices
232 * are delayed only about a half the time that file data is delayed.
233 * Similarly, directory updates are more critical, so are only delayed
234 * about a third the time that file data is delayed. Thus, there are
235 * SYNCER_MAXDELAY queues that are processed round-robin at a rate of
236 * one each second (driven off the filesystem syncer process). The
237 * syncer_delayno variable indicates the next queue that is to be processed.
238 * Items that need to be processed soon are placed in this queue:
240 * syncer_workitem_pending[syncer_delayno]
242 * A delay of fifteen seconds is done by placing the request fifteen
243 * entries later in the queue:
245 * syncer_workitem_pending[(syncer_delayno + 15) & syncer_mask]
248 static int syncer_delayno;
249 static long syncer_mask;
250 LIST_HEAD(synclist, bufobj);
251 static struct synclist *syncer_workitem_pending;
253 * The sync_mtx protects:
258 * syncer_workitem_pending
259 * syncer_worklist_len
262 static struct mtx sync_mtx;
263 static struct cv sync_wakeup;
265 #define SYNCER_MAXDELAY 32
266 static int syncer_maxdelay = SYNCER_MAXDELAY; /* maximum delay time */
267 static int syncdelay = 30; /* max time to delay syncing data */
268 static int filedelay = 30; /* time to delay syncing files */
269 SYSCTL_INT(_kern, OID_AUTO, filedelay, CTLFLAG_RW, &filedelay, 0,
270 "Time to delay syncing files (in seconds)");
271 static int dirdelay = 29; /* time to delay syncing directories */
272 SYSCTL_INT(_kern, OID_AUTO, dirdelay, CTLFLAG_RW, &dirdelay, 0,
273 "Time to delay syncing directories (in seconds)");
274 static int metadelay = 28; /* time to delay syncing metadata */
275 SYSCTL_INT(_kern, OID_AUTO, metadelay, CTLFLAG_RW, &metadelay, 0,
276 "Time to delay syncing metadata (in seconds)");
277 static int rushjob; /* number of slots to run ASAP */
278 static int stat_rush_requests; /* number of times I/O speeded up */
279 SYSCTL_INT(_debug, OID_AUTO, rush_requests, CTLFLAG_RW, &stat_rush_requests, 0,
280 "Number of times I/O speeded up (rush requests)");
283 * When shutting down the syncer, run it at four times normal speed.
285 #define SYNCER_SHUTDOWN_SPEEDUP 4
286 static int sync_vnode_count;
287 static int syncer_worklist_len;
288 static enum { SYNCER_RUNNING, SYNCER_SHUTTING_DOWN, SYNCER_FINAL_DELAY }
291 /* Target for maximum number of vnodes. */
293 static int gapvnodes; /* gap between wanted and desired */
294 static int vhiwat; /* enough extras after expansion */
295 static int vlowat; /* minimal extras before expansion */
296 static int vstir; /* nonzero to stir non-free vnodes */
297 static volatile int vsmalltrigger = 8; /* pref to keep if > this many pages */
300 sysctl_update_desiredvnodes(SYSCTL_HANDLER_ARGS)
302 int error, old_desiredvnodes;
304 old_desiredvnodes = desiredvnodes;
305 if ((error = sysctl_handle_int(oidp, arg1, arg2, req)) != 0)
307 if (old_desiredvnodes != desiredvnodes) {
308 wantfreevnodes = desiredvnodes / 4;
309 /* XXX locking seems to be incomplete. */
310 vfs_hash_changesize(desiredvnodes);
311 cache_changesize(desiredvnodes);
316 SYSCTL_PROC(_kern, KERN_MAXVNODES, maxvnodes,
317 CTLTYPE_INT | CTLFLAG_MPSAFE | CTLFLAG_RW, &desiredvnodes, 0,
318 sysctl_update_desiredvnodes, "I", "Target for maximum number of vnodes");
319 SYSCTL_ULONG(_kern, OID_AUTO, minvnodes, CTLFLAG_RW,
320 &wantfreevnodes, 0, "Old name for vfs.wantfreevnodes (legacy)");
321 static int vnlru_nowhere;
322 SYSCTL_INT(_debug, OID_AUTO, vnlru_nowhere, CTLFLAG_RW,
323 &vnlru_nowhere, 0, "Number of times the vnlru process ran without success");
325 /* Shift count for (uintptr_t)vp to initialize vp->v_hash. */
329 * Support for the bufobj clean & dirty pctrie.
332 buf_trie_alloc(struct pctrie *ptree)
335 return uma_zalloc(buf_trie_zone, M_NOWAIT);
339 buf_trie_free(struct pctrie *ptree, void *node)
342 uma_zfree(buf_trie_zone, node);
344 PCTRIE_DEFINE(BUF, buf, b_lblkno, buf_trie_alloc, buf_trie_free);
347 * Initialize the vnode management data structures.
349 * Reevaluate the following cap on the number of vnodes after the physical
350 * memory size exceeds 512GB. In the limit, as the physical memory size
351 * grows, the ratio of the memory size in KB to vnodes approaches 64:1.
353 #ifndef MAXVNODES_MAX
354 #define MAXVNODES_MAX (512 * 1024 * 1024 / 64) /* 8M */
358 * Initialize a vnode as it first enters the zone.
361 vnode_init(void *mem, int size, int flags)
370 vp->v_vnlock = &vp->v_lock;
371 mtx_init(&vp->v_interlock, "vnode interlock", NULL, MTX_DEF);
373 * By default, don't allow shared locks unless filesystems opt-in.
375 lockinit(vp->v_vnlock, PVFS, "vnode", VLKTIMEOUT,
376 LK_NOSHARE | LK_IS_VNODE);
380 bufobj_init(&vp->v_bufobj, vp);
382 * Initialize namecache.
384 LIST_INIT(&vp->v_cache_src);
385 TAILQ_INIT(&vp->v_cache_dst);
387 * Initialize rangelocks.
389 rangelock_init(&vp->v_rl);
394 * Free a vnode when it is cleared from the zone.
397 vnode_fini(void *mem, int size)
403 rangelock_destroy(&vp->v_rl);
404 lockdestroy(vp->v_vnlock);
405 mtx_destroy(&vp->v_interlock);
407 rw_destroy(BO_LOCKPTR(bo));
411 * Provide the size of NFS nclnode and NFS fh for calculation of the
412 * vnode memory consumption. The size is specified directly to
413 * eliminate dependency on NFS-private header.
415 * Other filesystems may use bigger or smaller (like UFS and ZFS)
416 * private inode data, but the NFS-based estimation is ample enough.
417 * Still, we care about differences in the size between 64- and 32-bit
420 * Namecache structure size is heuristically
421 * sizeof(struct namecache_ts) + CACHE_PATH_CUTOFF + 1.
424 #define NFS_NCLNODE_SZ (528 + 64)
427 #define NFS_NCLNODE_SZ (360 + 32)
432 vntblinit(void *dummy __unused)
435 int physvnodes, virtvnodes;
438 * Desiredvnodes is a function of the physical memory size and the
439 * kernel's heap size. Generally speaking, it scales with the
440 * physical memory size. The ratio of desiredvnodes to the physical
441 * memory size is 1:16 until desiredvnodes exceeds 98,304.
443 * marginal ratio of desiredvnodes to the physical memory size is
444 * 1:64. However, desiredvnodes is limited by the kernel's heap
445 * size. The memory required by desiredvnodes vnodes and vm objects
446 * must not exceed 1/10th of the kernel's heap size.
448 physvnodes = maxproc + pgtok(vm_cnt.v_page_count) / 64 +
449 3 * min(98304 * 16, pgtok(vm_cnt.v_page_count)) / 64;
450 virtvnodes = vm_kmem_size / (10 * (sizeof(struct vm_object) +
451 sizeof(struct vnode) + NC_SZ * ncsizefactor + NFS_NCLNODE_SZ));
452 desiredvnodes = min(physvnodes, virtvnodes);
453 if (desiredvnodes > MAXVNODES_MAX) {
455 printf("Reducing kern.maxvnodes %d -> %d\n",
456 desiredvnodes, MAXVNODES_MAX);
457 desiredvnodes = MAXVNODES_MAX;
459 wantfreevnodes = desiredvnodes / 4;
460 mtx_init(&mntid_mtx, "mntid", NULL, MTX_DEF);
461 TAILQ_INIT(&vnode_free_list);
462 mtx_init(&vnode_free_list_mtx, "vnode_free_list", NULL, MTX_DEF);
463 vnode_zone = uma_zcreate("VNODE", sizeof (struct vnode), NULL, NULL,
464 vnode_init, vnode_fini, UMA_ALIGN_PTR, 0);
465 vnodepoll_zone = uma_zcreate("VNODEPOLL", sizeof (struct vpollinfo),
466 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
468 * Preallocate enough nodes to support one-per buf so that
469 * we can not fail an insert. reassignbuf() callers can not
470 * tolerate the insertion failure.
472 buf_trie_zone = uma_zcreate("BUF TRIE", pctrie_node_size(),
473 NULL, NULL, pctrie_zone_init, NULL, UMA_ALIGN_PTR,
474 UMA_ZONE_NOFREE | UMA_ZONE_VM);
475 uma_prealloc(buf_trie_zone, nbuf);
477 vnodes_created = counter_u64_alloc(M_WAITOK);
478 recycles_count = counter_u64_alloc(M_WAITOK);
479 free_owe_inact = counter_u64_alloc(M_WAITOK);
482 * Initialize the filesystem syncer.
484 syncer_workitem_pending = hashinit(syncer_maxdelay, M_VNODE,
486 syncer_maxdelay = syncer_mask + 1;
487 mtx_init(&sync_mtx, "Syncer mtx", NULL, MTX_DEF);
488 cv_init(&sync_wakeup, "syncer");
489 for (i = 1; i <= sizeof(struct vnode); i <<= 1)
493 SYSINIT(vfs, SI_SUB_VFS, SI_ORDER_FIRST, vntblinit, NULL);
497 * Mark a mount point as busy. Used to synchronize access and to delay
498 * unmounting. Eventually, mountlist_mtx is not released on failure.
500 * vfs_busy() is a custom lock, it can block the caller.
501 * vfs_busy() only sleeps if the unmount is active on the mount point.
502 * For a mountpoint mp, vfs_busy-enforced lock is before lock of any
503 * vnode belonging to mp.
505 * Lookup uses vfs_busy() to traverse mount points.
507 * / vnode lock A / vnode lock (/var) D
508 * /var vnode lock B /log vnode lock(/var/log) E
509 * vfs_busy lock C vfs_busy lock F
511 * Within each file system, the lock order is C->A->B and F->D->E.
513 * When traversing across mounts, the system follows that lock order:
519 * The lookup() process for namei("/var") illustrates the process:
520 * VOP_LOOKUP() obtains B while A is held
521 * vfs_busy() obtains a shared lock on F while A and B are held
522 * vput() releases lock on B
523 * vput() releases lock on A
524 * VFS_ROOT() obtains lock on D while shared lock on F is held
525 * vfs_unbusy() releases shared lock on F
526 * vn_lock() obtains lock on deadfs vnode vp_crossmp instead of A.
527 * Attempt to lock A (instead of vp_crossmp) while D is held would
528 * violate the global order, causing deadlocks.
530 * dounmount() locks B while F is drained.
533 vfs_busy(struct mount *mp, int flags)
536 MPASS((flags & ~MBF_MASK) == 0);
537 CTR3(KTR_VFS, "%s: mp %p with flags %d", __func__, mp, flags);
542 * If mount point is currently being unmounted, sleep until the
543 * mount point fate is decided. If thread doing the unmounting fails,
544 * it will clear MNTK_UNMOUNT flag before waking us up, indicating
545 * that this mount point has survived the unmount attempt and vfs_busy
546 * should retry. Otherwise the unmounter thread will set MNTK_REFEXPIRE
547 * flag in addition to MNTK_UNMOUNT, indicating that mount point is
548 * about to be really destroyed. vfs_busy needs to release its
549 * reference on the mount point in this case and return with ENOENT,
550 * telling the caller that mount mount it tried to busy is no longer
553 while (mp->mnt_kern_flag & MNTK_UNMOUNT) {
554 if (flags & MBF_NOWAIT || mp->mnt_kern_flag & MNTK_REFEXPIRE) {
557 CTR1(KTR_VFS, "%s: failed busying before sleeping",
561 if (flags & MBF_MNTLSTLOCK)
562 mtx_unlock(&mountlist_mtx);
563 mp->mnt_kern_flag |= MNTK_MWAIT;
564 msleep(mp, MNT_MTX(mp), PVFS | PDROP, "vfs_busy", 0);
565 if (flags & MBF_MNTLSTLOCK)
566 mtx_lock(&mountlist_mtx);
569 if (flags & MBF_MNTLSTLOCK)
570 mtx_unlock(&mountlist_mtx);
577 * Free a busy filesystem.
580 vfs_unbusy(struct mount *mp)
583 CTR2(KTR_VFS, "%s: mp %p", __func__, mp);
586 KASSERT(mp->mnt_lockref > 0, ("negative mnt_lockref"));
588 if (mp->mnt_lockref == 0 && (mp->mnt_kern_flag & MNTK_DRAINING) != 0) {
589 MPASS(mp->mnt_kern_flag & MNTK_UNMOUNT);
590 CTR1(KTR_VFS, "%s: waking up waiters", __func__);
591 mp->mnt_kern_flag &= ~MNTK_DRAINING;
592 wakeup(&mp->mnt_lockref);
598 * Lookup a mount point by filesystem identifier.
601 vfs_getvfs(fsid_t *fsid)
605 CTR2(KTR_VFS, "%s: fsid %p", __func__, fsid);
606 mtx_lock(&mountlist_mtx);
607 TAILQ_FOREACH(mp, &mountlist, mnt_list) {
608 if (mp->mnt_stat.f_fsid.val[0] == fsid->val[0] &&
609 mp->mnt_stat.f_fsid.val[1] == fsid->val[1]) {
611 mtx_unlock(&mountlist_mtx);
615 mtx_unlock(&mountlist_mtx);
616 CTR2(KTR_VFS, "%s: lookup failed for %p id", __func__, fsid);
617 return ((struct mount *) 0);
621 * Lookup a mount point by filesystem identifier, busying it before
624 * To avoid congestion on mountlist_mtx, implement simple direct-mapped
625 * cache for popular filesystem identifiers. The cache is lockess, using
626 * the fact that struct mount's are never freed. In worst case we may
627 * get pointer to unmounted or even different filesystem, so we have to
628 * check what we got, and go slow way if so.
631 vfs_busyfs(fsid_t *fsid)
633 #define FSID_CACHE_SIZE 256
634 typedef struct mount * volatile vmp_t;
635 static vmp_t cache[FSID_CACHE_SIZE];
640 CTR2(KTR_VFS, "%s: fsid %p", __func__, fsid);
641 hash = fsid->val[0] ^ fsid->val[1];
642 hash = (hash >> 16 ^ hash) & (FSID_CACHE_SIZE - 1);
645 mp->mnt_stat.f_fsid.val[0] != fsid->val[0] ||
646 mp->mnt_stat.f_fsid.val[1] != fsid->val[1])
648 if (vfs_busy(mp, 0) != 0) {
652 if (mp->mnt_stat.f_fsid.val[0] == fsid->val[0] &&
653 mp->mnt_stat.f_fsid.val[1] == fsid->val[1])
659 mtx_lock(&mountlist_mtx);
660 TAILQ_FOREACH(mp, &mountlist, mnt_list) {
661 if (mp->mnt_stat.f_fsid.val[0] == fsid->val[0] &&
662 mp->mnt_stat.f_fsid.val[1] == fsid->val[1]) {
663 error = vfs_busy(mp, MBF_MNTLSTLOCK);
666 mtx_unlock(&mountlist_mtx);
673 CTR2(KTR_VFS, "%s: lookup failed for %p id", __func__, fsid);
674 mtx_unlock(&mountlist_mtx);
675 return ((struct mount *) 0);
679 * Check if a user can access privileged mount options.
682 vfs_suser(struct mount *mp, struct thread *td)
686 if (jailed(td->td_ucred)) {
688 * If the jail of the calling thread lacks permission for
689 * this type of file system, deny immediately.
691 if (!prison_allow(td->td_ucred, mp->mnt_vfc->vfc_prison_flag))
695 * If the file system was mounted outside the jail of the
696 * calling thread, deny immediately.
698 if (prison_check(td->td_ucred, mp->mnt_cred) != 0)
703 * If file system supports delegated administration, we don't check
704 * for the PRIV_VFS_MOUNT_OWNER privilege - it will be better verified
705 * by the file system itself.
706 * If this is not the user that did original mount, we check for
707 * the PRIV_VFS_MOUNT_OWNER privilege.
709 if (!(mp->mnt_vfc->vfc_flags & VFCF_DELEGADMIN) &&
710 mp->mnt_cred->cr_uid != td->td_ucred->cr_uid) {
711 if ((error = priv_check(td, PRIV_VFS_MOUNT_OWNER)) != 0)
718 * Get a new unique fsid. Try to make its val[0] unique, since this value
719 * will be used to create fake device numbers for stat(). Also try (but
720 * not so hard) make its val[0] unique mod 2^16, since some emulators only
721 * support 16-bit device numbers. We end up with unique val[0]'s for the
722 * first 2^16 calls and unique val[0]'s mod 2^16 for the first 2^8 calls.
724 * Keep in mind that several mounts may be running in parallel. Starting
725 * the search one past where the previous search terminated is both a
726 * micro-optimization and a defense against returning the same fsid to
730 vfs_getnewfsid(struct mount *mp)
732 static uint16_t mntid_base;
737 CTR2(KTR_VFS, "%s: mp %p", __func__, mp);
738 mtx_lock(&mntid_mtx);
739 mtype = mp->mnt_vfc->vfc_typenum;
740 tfsid.val[1] = mtype;
741 mtype = (mtype & 0xFF) << 24;
743 tfsid.val[0] = makedev(255,
744 mtype | ((mntid_base & 0xFF00) << 8) | (mntid_base & 0xFF));
746 if ((nmp = vfs_getvfs(&tfsid)) == NULL)
750 mp->mnt_stat.f_fsid.val[0] = tfsid.val[0];
751 mp->mnt_stat.f_fsid.val[1] = tfsid.val[1];
752 mtx_unlock(&mntid_mtx);
756 * Knob to control the precision of file timestamps:
758 * 0 = seconds only; nanoseconds zeroed.
759 * 1 = seconds and nanoseconds, accurate within 1/HZ.
760 * 2 = seconds and nanoseconds, truncated to microseconds.
761 * >=3 = seconds and nanoseconds, maximum precision.
763 enum { TSP_SEC, TSP_HZ, TSP_USEC, TSP_NSEC };
765 static int timestamp_precision = TSP_USEC;
766 SYSCTL_INT(_vfs, OID_AUTO, timestamp_precision, CTLFLAG_RW,
767 ×tamp_precision, 0, "File timestamp precision (0: seconds, "
768 "1: sec + ns accurate to 1/HZ, 2: sec + ns truncated to us, "
769 "3+: sec + ns (max. precision))");
772 * Get a current timestamp.
775 vfs_timestamp(struct timespec *tsp)
779 switch (timestamp_precision) {
781 tsp->tv_sec = time_second;
789 TIMEVAL_TO_TIMESPEC(&tv, tsp);
799 * Set vnode attributes to VNOVAL
802 vattr_null(struct vattr *vap)
806 vap->va_size = VNOVAL;
807 vap->va_bytes = VNOVAL;
808 vap->va_mode = VNOVAL;
809 vap->va_nlink = VNOVAL;
810 vap->va_uid = VNOVAL;
811 vap->va_gid = VNOVAL;
812 vap->va_fsid = VNOVAL;
813 vap->va_fileid = VNOVAL;
814 vap->va_blocksize = VNOVAL;
815 vap->va_rdev = VNOVAL;
816 vap->va_atime.tv_sec = VNOVAL;
817 vap->va_atime.tv_nsec = VNOVAL;
818 vap->va_mtime.tv_sec = VNOVAL;
819 vap->va_mtime.tv_nsec = VNOVAL;
820 vap->va_ctime.tv_sec = VNOVAL;
821 vap->va_ctime.tv_nsec = VNOVAL;
822 vap->va_birthtime.tv_sec = VNOVAL;
823 vap->va_birthtime.tv_nsec = VNOVAL;
824 vap->va_flags = VNOVAL;
825 vap->va_gen = VNOVAL;
830 * This routine is called when we have too many vnodes. It attempts
831 * to free <count> vnodes and will potentially free vnodes that still
832 * have VM backing store (VM backing store is typically the cause
833 * of a vnode blowout so we want to do this). Therefore, this operation
834 * is not considered cheap.
836 * A number of conditions may prevent a vnode from being reclaimed.
837 * the buffer cache may have references on the vnode, a directory
838 * vnode may still have references due to the namei cache representing
839 * underlying files, or the vnode may be in active use. It is not
840 * desirable to reuse such vnodes. These conditions may cause the
841 * number of vnodes to reach some minimum value regardless of what
842 * you set kern.maxvnodes to. Do not set kern.maxvnodes too low.
845 vlrureclaim(struct mount *mp, int reclaim_nc_src, int trigger)
848 int count, done, target;
851 vn_start_write(NULL, &mp, V_WAIT);
853 count = mp->mnt_nvnodelistsize;
854 target = count * (int64_t)gapvnodes / imax(desiredvnodes, 1);
855 target = target / 10 + 1;
856 while (count != 0 && done < target) {
857 vp = TAILQ_FIRST(&mp->mnt_nvnodelist);
858 while (vp != NULL && vp->v_type == VMARKER)
859 vp = TAILQ_NEXT(vp, v_nmntvnodes);
863 * XXX LRU is completely broken for non-free vnodes. First
864 * by calling here in mountpoint order, then by moving
865 * unselected vnodes to the end here, and most grossly by
866 * removing the vlruvp() function that was supposed to
867 * maintain the order. (This function was born broken
868 * since syncer problems prevented it doing anything.) The
869 * order is closer to LRC (C = Created).
871 * LRU reclaiming of vnodes seems to have last worked in
872 * FreeBSD-3 where LRU wasn't mentioned under any spelling.
873 * Then there was no hold count, and inactive vnodes were
874 * simply put on the free list in LRU order. The separate
875 * lists also break LRU. We prefer to reclaim from the
876 * free list for technical reasons. This tends to thrash
877 * the free list to keep very unrecently used held vnodes.
878 * The problem is mitigated by keeping the free list large.
880 TAILQ_REMOVE(&mp->mnt_nvnodelist, vp, v_nmntvnodes);
881 TAILQ_INSERT_TAIL(&mp->mnt_nvnodelist, vp, v_nmntvnodes);
886 * If it's been deconstructed already, it's still
887 * referenced, or it exceeds the trigger, skip it.
888 * Also skip free vnodes. We are trying to make space
889 * to expand the free list, not reduce it.
891 if (vp->v_usecount ||
892 (!reclaim_nc_src && !LIST_EMPTY(&vp->v_cache_src)) ||
893 ((vp->v_iflag & VI_FREE) != 0) ||
894 (vp->v_iflag & VI_DOOMED) != 0 || (vp->v_object != NULL &&
895 vp->v_object->resident_page_count > trigger)) {
901 if (VOP_LOCK(vp, LK_INTERLOCK|LK_EXCLUSIVE|LK_NOWAIT)) {
903 goto next_iter_mntunlocked;
907 * v_usecount may have been bumped after VOP_LOCK() dropped
908 * the vnode interlock and before it was locked again.
910 * It is not necessary to recheck VI_DOOMED because it can
911 * only be set by another thread that holds both the vnode
912 * lock and vnode interlock. If another thread has the
913 * vnode lock before we get to VOP_LOCK() and obtains the
914 * vnode interlock after VOP_LOCK() drops the vnode
915 * interlock, the other thread will be unable to drop the
916 * vnode lock before our VOP_LOCK() call fails.
918 if (vp->v_usecount ||
919 (!reclaim_nc_src && !LIST_EMPTY(&vp->v_cache_src)) ||
920 (vp->v_iflag & VI_FREE) != 0 ||
921 (vp->v_object != NULL &&
922 vp->v_object->resident_page_count > trigger)) {
923 VOP_UNLOCK(vp, LK_INTERLOCK);
925 goto next_iter_mntunlocked;
927 KASSERT((vp->v_iflag & VI_DOOMED) == 0,
928 ("VI_DOOMED unexpectedly detected in vlrureclaim()"));
929 counter_u64_add(recycles_count, 1);
934 next_iter_mntunlocked:
943 kern_yield(PRI_USER);
948 vn_finished_write(mp);
952 static int max_vnlru_free = 10000; /* limit on vnode free requests per call */
953 SYSCTL_INT(_debug, OID_AUTO, max_vnlru_free, CTLFLAG_RW, &max_vnlru_free,
955 "limit on vnode free requests per call to the vnlru_free routine");
958 * Attempt to reduce the free list by the requested amount.
961 vnlru_free_locked(int count, struct vfsops *mnt_op)
967 tried_batches = false;
968 mtx_assert(&vnode_free_list_mtx, MA_OWNED);
969 if (count > max_vnlru_free)
970 count = max_vnlru_free;
971 for (; count > 0; count--) {
972 vp = TAILQ_FIRST(&vnode_free_list);
974 * The list can be modified while the free_list_mtx
975 * has been dropped and vp could be NULL here.
980 mtx_unlock(&vnode_free_list_mtx);
981 vnlru_return_batches(mnt_op);
982 tried_batches = true;
983 mtx_lock(&vnode_free_list_mtx);
987 VNASSERT(vp->v_op != NULL, vp,
988 ("vnlru_free: vnode already reclaimed."));
989 KASSERT((vp->v_iflag & VI_FREE) != 0,
990 ("Removing vnode not on freelist"));
991 KASSERT((vp->v_iflag & VI_ACTIVE) == 0,
992 ("Mangling active vnode"));
993 TAILQ_REMOVE(&vnode_free_list, vp, v_actfreelist);
996 * Don't recycle if our vnode is from different type
997 * of mount point. Note that mp is type-safe, the
998 * check does not reach unmapped address even if
999 * vnode is reclaimed.
1000 * Don't recycle if we can't get the interlock without
1003 if ((mnt_op != NULL && (mp = vp->v_mount) != NULL &&
1004 mp->mnt_op != mnt_op) || !VI_TRYLOCK(vp)) {
1005 TAILQ_INSERT_TAIL(&vnode_free_list, vp, v_actfreelist);
1008 VNASSERT((vp->v_iflag & VI_FREE) != 0 && vp->v_holdcnt == 0,
1009 vp, ("vp inconsistent on freelist"));
1012 * The clear of VI_FREE prevents activation of the
1013 * vnode. There is no sense in putting the vnode on
1014 * the mount point active list, only to remove it
1015 * later during recycling. Inline the relevant part
1016 * of vholdl(), to avoid triggering assertions or
1020 vp->v_iflag &= ~VI_FREE;
1021 refcount_acquire(&vp->v_holdcnt);
1023 mtx_unlock(&vnode_free_list_mtx);
1027 * If the recycled succeeded this vdrop will actually free
1028 * the vnode. If not it will simply place it back on
1032 mtx_lock(&vnode_free_list_mtx);
1037 vnlru_free(int count, struct vfsops *mnt_op)
1040 mtx_lock(&vnode_free_list_mtx);
1041 vnlru_free_locked(count, mnt_op);
1042 mtx_unlock(&vnode_free_list_mtx);
1046 /* XXX some names and initialization are bad for limits and watermarks. */
1052 gapvnodes = imax(desiredvnodes - wantfreevnodes, 100);
1053 vhiwat = gapvnodes / 11; /* 9% -- just under the 10% in vlrureclaim() */
1054 vlowat = vhiwat / 2;
1055 if (numvnodes > desiredvnodes)
1057 space = desiredvnodes - numvnodes;
1058 if (freevnodes > wantfreevnodes)
1059 space += freevnodes - wantfreevnodes;
1064 vnlru_return_batch_locked(struct mount *mp)
1068 mtx_assert(&mp->mnt_listmtx, MA_OWNED);
1070 if (mp->mnt_tmpfreevnodelistsize == 0)
1073 TAILQ_FOREACH(vp, &mp->mnt_tmpfreevnodelist, v_actfreelist) {
1074 VNASSERT((vp->v_mflag & VMP_TMPMNTFREELIST) != 0, vp,
1075 ("vnode without VMP_TMPMNTFREELIST on mnt_tmpfreevnodelist"));
1076 vp->v_mflag &= ~VMP_TMPMNTFREELIST;
1078 mtx_lock(&vnode_free_list_mtx);
1079 TAILQ_CONCAT(&vnode_free_list, &mp->mnt_tmpfreevnodelist, v_actfreelist);
1080 freevnodes += mp->mnt_tmpfreevnodelistsize;
1081 mtx_unlock(&vnode_free_list_mtx);
1082 mp->mnt_tmpfreevnodelistsize = 0;
1086 vnlru_return_batch(struct mount *mp)
1089 mtx_lock(&mp->mnt_listmtx);
1090 vnlru_return_batch_locked(mp);
1091 mtx_unlock(&mp->mnt_listmtx);
1095 vnlru_return_batches(struct vfsops *mnt_op)
1097 struct mount *mp, *nmp;
1100 mtx_lock(&mountlist_mtx);
1101 for (mp = TAILQ_FIRST(&mountlist); mp != NULL; mp = nmp) {
1102 need_unbusy = false;
1103 if (mnt_op != NULL && mp->mnt_op != mnt_op)
1105 if (mp->mnt_tmpfreevnodelistsize == 0)
1107 if (vfs_busy(mp, MBF_NOWAIT | MBF_MNTLSTLOCK) == 0) {
1108 vnlru_return_batch(mp);
1110 mtx_lock(&mountlist_mtx);
1113 nmp = TAILQ_NEXT(mp, mnt_list);
1117 mtx_unlock(&mountlist_mtx);
1121 * Attempt to recycle vnodes in a context that is always safe to block.
1122 * Calling vlrurecycle() from the bowels of filesystem code has some
1123 * interesting deadlock problems.
1125 static struct proc *vnlruproc;
1126 static int vnlruproc_sig;
1131 struct mount *mp, *nmp;
1132 unsigned long onumvnodes;
1133 int done, force, reclaim_nc_src, trigger, usevnodes;
1135 EVENTHANDLER_REGISTER(shutdown_pre_sync, kproc_shutdown, vnlruproc,
1136 SHUTDOWN_PRI_FIRST);
1140 kproc_suspend_check(vnlruproc);
1141 mtx_lock(&vnode_free_list_mtx);
1143 * If numvnodes is too large (due to desiredvnodes being
1144 * adjusted using its sysctl, or emergency growth), first
1145 * try to reduce it by discarding from the free list.
1147 if (numvnodes > desiredvnodes)
1148 vnlru_free_locked(numvnodes - desiredvnodes, NULL);
1150 * Sleep if the vnode cache is in a good state. This is
1151 * when it is not over-full and has space for about a 4%
1152 * or 9% expansion (by growing its size or inexcessively
1153 * reducing its free list). Otherwise, try to reclaim
1154 * space for a 10% expansion.
1156 if (vstir && force == 0) {
1160 if (vspace() >= vlowat && force == 0) {
1162 wakeup(&vnlruproc_sig);
1163 msleep(vnlruproc, &vnode_free_list_mtx,
1164 PVFS|PDROP, "vlruwt", hz);
1167 mtx_unlock(&vnode_free_list_mtx);
1169 onumvnodes = numvnodes;
1171 * Calculate parameters for recycling. These are the same
1172 * throughout the loop to give some semblance of fairness.
1173 * The trigger point is to avoid recycling vnodes with lots
1174 * of resident pages. We aren't trying to free memory; we
1175 * are trying to recycle or at least free vnodes.
1177 if (numvnodes <= desiredvnodes)
1178 usevnodes = numvnodes - freevnodes;
1180 usevnodes = numvnodes;
1184 * The trigger value is is chosen to give a conservatively
1185 * large value to ensure that it alone doesn't prevent
1186 * making progress. The value can easily be so large that
1187 * it is effectively infinite in some congested and
1188 * misconfigured cases, and this is necessary. Normally
1189 * it is about 8 to 100 (pages), which is quite large.
1191 trigger = vm_cnt.v_page_count * 2 / usevnodes;
1193 trigger = vsmalltrigger;
1194 reclaim_nc_src = force >= 3;
1195 mtx_lock(&mountlist_mtx);
1196 for (mp = TAILQ_FIRST(&mountlist); mp != NULL; mp = nmp) {
1197 if (vfs_busy(mp, MBF_NOWAIT | MBF_MNTLSTLOCK)) {
1198 nmp = TAILQ_NEXT(mp, mnt_list);
1201 done += vlrureclaim(mp, reclaim_nc_src, trigger);
1202 mtx_lock(&mountlist_mtx);
1203 nmp = TAILQ_NEXT(mp, mnt_list);
1206 mtx_unlock(&mountlist_mtx);
1207 if (onumvnodes > desiredvnodes && numvnodes <= desiredvnodes)
1210 if (force == 0 || force == 1) {
1220 tsleep(vnlruproc, PPAUSE, "vlrup", hz * 3);
1222 kern_yield(PRI_USER);
1224 * After becoming active to expand above low water, keep
1225 * active until above high water.
1227 force = vspace() < vhiwat;
1231 static struct kproc_desc vnlru_kp = {
1236 SYSINIT(vnlru, SI_SUB_KTHREAD_UPDATE, SI_ORDER_FIRST, kproc_start,
1240 * Routines having to do with the management of the vnode table.
1244 * Try to recycle a freed vnode. We abort if anyone picks up a reference
1245 * before we actually vgone(). This function must be called with the vnode
1246 * held to prevent the vnode from being returned to the free list midway
1250 vtryrecycle(struct vnode *vp)
1254 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
1255 VNASSERT(vp->v_holdcnt, vp,
1256 ("vtryrecycle: Recycling vp %p without a reference.", vp));
1258 * This vnode may found and locked via some other list, if so we
1259 * can't recycle it yet.
1261 if (VOP_LOCK(vp, LK_EXCLUSIVE | LK_NOWAIT) != 0) {
1263 "%s: impossible to recycle, vp %p lock is already held",
1265 return (EWOULDBLOCK);
1268 * Don't recycle if its filesystem is being suspended.
1270 if (vn_start_write(vp, &vnmp, V_NOWAIT) != 0) {
1273 "%s: impossible to recycle, cannot start the write for %p",
1278 * If we got this far, we need to acquire the interlock and see if
1279 * anyone picked up this vnode from another list. If not, we will
1280 * mark it with DOOMED via vgonel() so that anyone who does find it
1281 * will skip over it.
1284 if (vp->v_usecount) {
1285 VOP_UNLOCK(vp, LK_INTERLOCK);
1286 vn_finished_write(vnmp);
1288 "%s: impossible to recycle, %p is already referenced",
1292 if ((vp->v_iflag & VI_DOOMED) == 0) {
1293 counter_u64_add(recycles_count, 1);
1296 VOP_UNLOCK(vp, LK_INTERLOCK);
1297 vn_finished_write(vnmp);
1305 if (vspace() < vlowat && vnlruproc_sig == 0) {
1312 * Wait if necessary for space for a new vnode.
1315 getnewvnode_wait(int suspended)
1318 mtx_assert(&vnode_free_list_mtx, MA_OWNED);
1319 if (numvnodes >= desiredvnodes) {
1322 * The file system is being suspended. We cannot
1323 * risk a deadlock here, so allow allocation of
1324 * another vnode even if this would give too many.
1328 if (vnlruproc_sig == 0) {
1329 vnlruproc_sig = 1; /* avoid unnecessary wakeups */
1332 msleep(&vnlruproc_sig, &vnode_free_list_mtx, PVFS,
1335 /* Post-adjust like the pre-adjust in getnewvnode(). */
1336 if (numvnodes + 1 > desiredvnodes && freevnodes > 1)
1337 vnlru_free_locked(1, NULL);
1338 return (numvnodes >= desiredvnodes ? ENFILE : 0);
1342 * This hack is fragile, and probably not needed any more now that the
1343 * watermark handling works.
1346 getnewvnode_reserve(u_int count)
1350 /* Pre-adjust like the pre-adjust in getnewvnode(), with any count. */
1351 /* XXX no longer so quick, but this part is not racy. */
1352 mtx_lock(&vnode_free_list_mtx);
1353 if (numvnodes + count > desiredvnodes && freevnodes > wantfreevnodes)
1354 vnlru_free_locked(ulmin(numvnodes + count - desiredvnodes,
1355 freevnodes - wantfreevnodes), NULL);
1356 mtx_unlock(&vnode_free_list_mtx);
1359 /* First try to be quick and racy. */
1360 if (atomic_fetchadd_long(&numvnodes, count) + count <= desiredvnodes) {
1361 td->td_vp_reserv += count;
1362 vcheckspace(); /* XXX no longer so quick, but more racy */
1365 atomic_subtract_long(&numvnodes, count);
1367 mtx_lock(&vnode_free_list_mtx);
1369 if (getnewvnode_wait(0) == 0) {
1372 atomic_add_long(&numvnodes, 1);
1376 mtx_unlock(&vnode_free_list_mtx);
1380 * This hack is fragile, especially if desiredvnodes or wantvnodes are
1381 * misconfgured or changed significantly. Reducing desiredvnodes below
1382 * the reserved amount should cause bizarre behaviour like reducing it
1383 * below the number of active vnodes -- the system will try to reduce
1384 * numvnodes to match, but should fail, so the subtraction below should
1388 getnewvnode_drop_reserve(void)
1393 atomic_subtract_long(&numvnodes, td->td_vp_reserv);
1394 td->td_vp_reserv = 0;
1398 * Return the next vnode from the free list.
1401 getnewvnode(const char *tag, struct mount *mp, struct vop_vector *vops,
1406 struct lock_object *lo;
1407 static int cyclecount;
1410 CTR3(KTR_VFS, "%s: mp %p with tag %s", __func__, mp, tag);
1413 if (td->td_vp_reserv > 0) {
1414 td->td_vp_reserv -= 1;
1417 mtx_lock(&vnode_free_list_mtx);
1418 if (numvnodes < desiredvnodes)
1420 else if (cyclecount++ >= freevnodes) {
1425 * Grow the vnode cache if it will not be above its target max
1426 * after growing. Otherwise, if the free list is nonempty, try
1427 * to reclaim 1 item from it before growing the cache (possibly
1428 * above its target max if the reclamation failed or is delayed).
1429 * Otherwise, wait for some space. In all cases, schedule
1430 * vnlru_proc() if we are getting short of space. The watermarks
1431 * should be chosen so that we never wait or even reclaim from
1432 * the free list to below its target minimum.
1434 if (numvnodes + 1 <= desiredvnodes)
1436 else if (freevnodes > 0)
1437 vnlru_free_locked(1, NULL);
1439 error = getnewvnode_wait(mp != NULL && (mp->mnt_kern_flag &
1441 #if 0 /* XXX Not all VFS_VGET/ffs_vget callers check returns. */
1443 mtx_unlock(&vnode_free_list_mtx);
1449 atomic_add_long(&numvnodes, 1);
1450 mtx_unlock(&vnode_free_list_mtx);
1452 counter_u64_add(vnodes_created, 1);
1453 vp = (struct vnode *) uma_zalloc(vnode_zone, M_WAITOK);
1455 * Locks are given the generic name "vnode" when created.
1456 * Follow the historic practice of using the filesystem
1457 * name when they allocated, e.g., "zfs", "ufs", "nfs, etc.
1459 * Locks live in a witness group keyed on their name. Thus,
1460 * when a lock is renamed, it must also move from the witness
1461 * group of its old name to the witness group of its new name.
1463 * The change only needs to be made when the vnode moves
1464 * from one filesystem type to another. We ensure that each
1465 * filesystem use a single static name pointer for its tag so
1466 * that we can compare pointers rather than doing a strcmp().
1468 lo = &vp->v_vnlock->lock_object;
1469 if (lo->lo_name != tag) {
1471 WITNESS_DESTROY(lo);
1472 WITNESS_INIT(lo, tag);
1475 * By default, don't allow shared locks unless filesystems opt-in.
1477 vp->v_vnlock->lock_object.lo_flags |= LK_NOSHARE;
1479 * Finalize various vnode identity bits.
1481 KASSERT(vp->v_object == NULL, ("stale v_object %p", vp));
1482 KASSERT(vp->v_lockf == NULL, ("stale v_lockf %p", vp));
1483 KASSERT(vp->v_pollinfo == NULL, ("stale v_pollinfo %p", vp));
1487 v_init_counters(vp);
1488 vp->v_bufobj.bo_ops = &buf_ops_bio;
1490 if (mp == NULL && vops != &dead_vnodeops)
1491 printf("NULL mp in getnewvnode(9), tag %s\n", tag);
1495 if (mp != NULL && (mp->mnt_flag & MNT_MULTILABEL) == 0)
1496 mac_vnode_associate_singlelabel(mp, vp);
1499 vp->v_bufobj.bo_bsize = mp->mnt_stat.f_iosize;
1500 if ((mp->mnt_kern_flag & MNTK_NOKNOTE) != 0)
1501 vp->v_vflag |= VV_NOKNOTE;
1505 * For the filesystems which do not use vfs_hash_insert(),
1506 * still initialize v_hash to have vfs_hash_index() useful.
1507 * E.g., nullfs uses vfs_hash_index() on the lower vnode for
1510 vp->v_hash = (uintptr_t)vp >> vnsz2log;
1517 * Delete from old mount point vnode list, if on one.
1520 delmntque(struct vnode *vp)
1530 KASSERT(mp->mnt_activevnodelistsize <= mp->mnt_nvnodelistsize,
1531 ("Active vnode list size %d > Vnode list size %d",
1532 mp->mnt_activevnodelistsize, mp->mnt_nvnodelistsize));
1533 active = vp->v_iflag & VI_ACTIVE;
1534 vp->v_iflag &= ~VI_ACTIVE;
1536 mtx_lock(&mp->mnt_listmtx);
1537 TAILQ_REMOVE(&mp->mnt_activevnodelist, vp, v_actfreelist);
1538 mp->mnt_activevnodelistsize--;
1539 mtx_unlock(&mp->mnt_listmtx);
1543 VNASSERT(mp->mnt_nvnodelistsize > 0, vp,
1544 ("bad mount point vnode list size"));
1545 TAILQ_REMOVE(&mp->mnt_nvnodelist, vp, v_nmntvnodes);
1546 mp->mnt_nvnodelistsize--;
1552 insmntque_stddtr(struct vnode *vp, void *dtr_arg)
1556 vp->v_op = &dead_vnodeops;
1562 * Insert into list of vnodes for the new mount point, if available.
1565 insmntque1(struct vnode *vp, struct mount *mp,
1566 void (*dtr)(struct vnode *, void *), void *dtr_arg)
1569 KASSERT(vp->v_mount == NULL,
1570 ("insmntque: vnode already on per mount vnode list"));
1571 VNASSERT(mp != NULL, vp, ("Don't call insmntque(foo, NULL)"));
1572 ASSERT_VOP_ELOCKED(vp, "insmntque: non-locked vp");
1575 * We acquire the vnode interlock early to ensure that the
1576 * vnode cannot be recycled by another process releasing a
1577 * holdcnt on it before we get it on both the vnode list
1578 * and the active vnode list. The mount mutex protects only
1579 * manipulation of the vnode list and the vnode freelist
1580 * mutex protects only manipulation of the active vnode list.
1581 * Hence the need to hold the vnode interlock throughout.
1585 if (((mp->mnt_kern_flag & MNTK_NOINSMNTQ) != 0 &&
1586 ((mp->mnt_kern_flag & MNTK_UNMOUNTF) != 0 ||
1587 mp->mnt_nvnodelistsize == 0)) &&
1588 (vp->v_vflag & VV_FORCEINSMQ) == 0) {
1597 TAILQ_INSERT_TAIL(&mp->mnt_nvnodelist, vp, v_nmntvnodes);
1598 VNASSERT(mp->mnt_nvnodelistsize >= 0, vp,
1599 ("neg mount point vnode list size"));
1600 mp->mnt_nvnodelistsize++;
1601 KASSERT((vp->v_iflag & VI_ACTIVE) == 0,
1602 ("Activating already active vnode"));
1603 vp->v_iflag |= VI_ACTIVE;
1604 mtx_lock(&mp->mnt_listmtx);
1605 TAILQ_INSERT_HEAD(&mp->mnt_activevnodelist, vp, v_actfreelist);
1606 mp->mnt_activevnodelistsize++;
1607 mtx_unlock(&mp->mnt_listmtx);
1614 insmntque(struct vnode *vp, struct mount *mp)
1617 return (insmntque1(vp, mp, insmntque_stddtr, NULL));
1621 * Flush out and invalidate all buffers associated with a bufobj
1622 * Called with the underlying object locked.
1625 bufobj_invalbuf(struct bufobj *bo, int flags, int slpflag, int slptimeo)
1630 if (flags & V_SAVE) {
1631 error = bufobj_wwait(bo, slpflag, slptimeo);
1636 if (bo->bo_dirty.bv_cnt > 0) {
1638 if ((error = BO_SYNC(bo, MNT_WAIT)) != 0)
1641 * XXX We could save a lock/unlock if this was only
1642 * enabled under INVARIANTS
1645 if (bo->bo_numoutput > 0 || bo->bo_dirty.bv_cnt > 0)
1646 panic("vinvalbuf: dirty bufs");
1650 * If you alter this loop please notice that interlock is dropped and
1651 * reacquired in flushbuflist. Special care is needed to ensure that
1652 * no race conditions occur from this.
1655 error = flushbuflist(&bo->bo_clean,
1656 flags, bo, slpflag, slptimeo);
1657 if (error == 0 && !(flags & V_CLEANONLY))
1658 error = flushbuflist(&bo->bo_dirty,
1659 flags, bo, slpflag, slptimeo);
1660 if (error != 0 && error != EAGAIN) {
1664 } while (error != 0);
1667 * Wait for I/O to complete. XXX needs cleaning up. The vnode can
1668 * have write I/O in-progress but if there is a VM object then the
1669 * VM object can also have read-I/O in-progress.
1672 bufobj_wwait(bo, 0, 0);
1673 if ((flags & V_VMIO) == 0) {
1675 if (bo->bo_object != NULL) {
1676 VM_OBJECT_WLOCK(bo->bo_object);
1677 vm_object_pip_wait(bo->bo_object, "bovlbx");
1678 VM_OBJECT_WUNLOCK(bo->bo_object);
1682 } while (bo->bo_numoutput > 0);
1686 * Destroy the copy in the VM cache, too.
1688 if (bo->bo_object != NULL &&
1689 (flags & (V_ALT | V_NORMAL | V_CLEANONLY | V_VMIO)) == 0) {
1690 VM_OBJECT_WLOCK(bo->bo_object);
1691 vm_object_page_remove(bo->bo_object, 0, 0, (flags & V_SAVE) ?
1692 OBJPR_CLEANONLY : 0);
1693 VM_OBJECT_WUNLOCK(bo->bo_object);
1698 if ((flags & (V_ALT | V_NORMAL | V_CLEANONLY | V_VMIO |
1699 V_ALLOWCLEAN)) == 0 && (bo->bo_dirty.bv_cnt > 0 ||
1700 bo->bo_clean.bv_cnt > 0))
1701 panic("vinvalbuf: flush failed");
1702 if ((flags & (V_ALT | V_NORMAL | V_CLEANONLY | V_VMIO)) == 0 &&
1703 bo->bo_dirty.bv_cnt > 0)
1704 panic("vinvalbuf: flush dirty failed");
1711 * Flush out and invalidate all buffers associated with a vnode.
1712 * Called with the underlying object locked.
1715 vinvalbuf(struct vnode *vp, int flags, int slpflag, int slptimeo)
1718 CTR3(KTR_VFS, "%s: vp %p with flags %d", __func__, vp, flags);
1719 ASSERT_VOP_LOCKED(vp, "vinvalbuf");
1720 if (vp->v_object != NULL && vp->v_object->handle != vp)
1722 return (bufobj_invalbuf(&vp->v_bufobj, flags, slpflag, slptimeo));
1726 * Flush out buffers on the specified list.
1730 flushbuflist(struct bufv *bufv, int flags, struct bufobj *bo, int slpflag,
1733 struct buf *bp, *nbp;
1738 ASSERT_BO_WLOCKED(bo);
1741 TAILQ_FOREACH_SAFE(bp, &bufv->bv_hd, b_bobufs, nbp) {
1742 if (((flags & V_NORMAL) && (bp->b_xflags & BX_ALTDATA)) ||
1743 ((flags & V_ALT) && (bp->b_xflags & BX_ALTDATA) == 0)) {
1747 lblkno = nbp->b_lblkno;
1748 xflags = nbp->b_xflags & (BX_VNDIRTY | BX_VNCLEAN);
1751 error = BUF_TIMELOCK(bp,
1752 LK_EXCLUSIVE | LK_SLEEPFAIL | LK_INTERLOCK, BO_LOCKPTR(bo),
1753 "flushbuf", slpflag, slptimeo);
1756 return (error != ENOLCK ? error : EAGAIN);
1758 KASSERT(bp->b_bufobj == bo,
1759 ("bp %p wrong b_bufobj %p should be %p",
1760 bp, bp->b_bufobj, bo));
1762 * XXX Since there are no node locks for NFS, I
1763 * believe there is a slight chance that a delayed
1764 * write will occur while sleeping just above, so
1767 if (((bp->b_flags & (B_DELWRI | B_INVAL)) == B_DELWRI) &&
1770 bp->b_flags |= B_ASYNC;
1773 return (EAGAIN); /* XXX: why not loop ? */
1776 bp->b_flags |= (B_INVAL | B_RELBUF);
1777 bp->b_flags &= ~B_ASYNC;
1782 nbp = gbincore(bo, lblkno);
1783 if (nbp == NULL || (nbp->b_xflags & (BX_VNDIRTY | BX_VNCLEAN))
1785 break; /* nbp invalid */
1791 bnoreuselist(struct bufv *bufv, struct bufobj *bo, daddr_t startn, daddr_t endn)
1797 ASSERT_BO_LOCKED(bo);
1799 for (lblkno = startn;;) {
1801 bp = BUF_PCTRIE_LOOKUP_GE(&bufv->bv_root, lblkno);
1802 if (bp == NULL || bp->b_lblkno >= endn ||
1803 bp->b_lblkno < startn)
1805 error = BUF_TIMELOCK(bp, LK_EXCLUSIVE | LK_SLEEPFAIL |
1806 LK_INTERLOCK, BO_LOCKPTR(bo), "brlsfl", 0, 0);
1809 if (error == ENOLCK)
1813 KASSERT(bp->b_bufobj == bo,
1814 ("bp %p wrong b_bufobj %p should be %p",
1815 bp, bp->b_bufobj, bo));
1816 lblkno = bp->b_lblkno + 1;
1817 if ((bp->b_flags & B_MANAGED) == 0)
1819 bp->b_flags |= B_RELBUF;
1821 * In the VMIO case, use the B_NOREUSE flag to hint that the
1822 * pages backing each buffer in the range are unlikely to be
1823 * reused. Dirty buffers will have the hint applied once
1824 * they've been written.
1826 if (bp->b_vp->v_object != NULL)
1827 bp->b_flags |= B_NOREUSE;
1835 * Truncate a file's buffer and pages to a specified length. This
1836 * is in lieu of the old vinvalbuf mechanism, which performed unneeded
1840 vtruncbuf(struct vnode *vp, struct ucred *cred, off_t length, int blksize)
1842 struct buf *bp, *nbp;
1847 CTR5(KTR_VFS, "%s: vp %p with cred %p and block %d:%ju", __func__,
1848 vp, cred, blksize, (uintmax_t)length);
1851 * Round up to the *next* lbn.
1853 trunclbn = howmany(length, blksize);
1855 ASSERT_VOP_LOCKED(vp, "vtruncbuf");
1862 TAILQ_FOREACH_SAFE(bp, &bo->bo_clean.bv_hd, b_bobufs, nbp) {
1863 if (bp->b_lblkno < trunclbn)
1866 LK_EXCLUSIVE | LK_SLEEPFAIL | LK_INTERLOCK,
1867 BO_LOCKPTR(bo)) == ENOLCK)
1871 bp->b_flags |= (B_INVAL | B_RELBUF);
1872 bp->b_flags &= ~B_ASYNC;
1878 (((nbp->b_xflags & BX_VNCLEAN) == 0) ||
1879 (nbp->b_vp != vp) ||
1880 (nbp->b_flags & B_DELWRI))) {
1886 TAILQ_FOREACH_SAFE(bp, &bo->bo_dirty.bv_hd, b_bobufs, nbp) {
1887 if (bp->b_lblkno < trunclbn)
1890 LK_EXCLUSIVE | LK_SLEEPFAIL | LK_INTERLOCK,
1891 BO_LOCKPTR(bo)) == ENOLCK)
1894 bp->b_flags |= (B_INVAL | B_RELBUF);
1895 bp->b_flags &= ~B_ASYNC;
1901 (((nbp->b_xflags & BX_VNDIRTY) == 0) ||
1902 (nbp->b_vp != vp) ||
1903 (nbp->b_flags & B_DELWRI) == 0)) {
1912 TAILQ_FOREACH_SAFE(bp, &bo->bo_dirty.bv_hd, b_bobufs, nbp) {
1913 if (bp->b_lblkno > 0)
1916 * Since we hold the vnode lock this should only
1917 * fail if we're racing with the buf daemon.
1920 LK_EXCLUSIVE | LK_SLEEPFAIL | LK_INTERLOCK,
1921 BO_LOCKPTR(bo)) == ENOLCK) {
1924 VNASSERT((bp->b_flags & B_DELWRI), vp,
1925 ("buf(%p) on dirty queue without DELWRI", bp));
1934 bufobj_wwait(bo, 0, 0);
1936 vnode_pager_setsize(vp, length);
1942 buf_vlist_remove(struct buf *bp)
1946 KASSERT(bp->b_bufobj != NULL, ("No b_bufobj %p", bp));
1947 ASSERT_BO_WLOCKED(bp->b_bufobj);
1948 KASSERT((bp->b_xflags & (BX_VNDIRTY|BX_VNCLEAN)) !=
1949 (BX_VNDIRTY|BX_VNCLEAN),
1950 ("buf_vlist_remove: Buf %p is on two lists", bp));
1951 if (bp->b_xflags & BX_VNDIRTY)
1952 bv = &bp->b_bufobj->bo_dirty;
1954 bv = &bp->b_bufobj->bo_clean;
1955 BUF_PCTRIE_REMOVE(&bv->bv_root, bp->b_lblkno);
1956 TAILQ_REMOVE(&bv->bv_hd, bp, b_bobufs);
1958 bp->b_xflags &= ~(BX_VNDIRTY | BX_VNCLEAN);
1962 * Add the buffer to the sorted clean or dirty block list.
1964 * NOTE: xflags is passed as a constant, optimizing this inline function!
1967 buf_vlist_add(struct buf *bp, struct bufobj *bo, b_xflags_t xflags)
1973 ASSERT_BO_WLOCKED(bo);
1974 KASSERT((xflags & BX_VNDIRTY) == 0 || (bo->bo_flag & BO_DEAD) == 0,
1975 ("dead bo %p", bo));
1976 KASSERT((bp->b_xflags & (BX_VNDIRTY|BX_VNCLEAN)) == 0,
1977 ("buf_vlist_add: Buf %p has existing xflags %d", bp, bp->b_xflags));
1978 bp->b_xflags |= xflags;
1979 if (xflags & BX_VNDIRTY)
1985 * Keep the list ordered. Optimize empty list insertion. Assume
1986 * we tend to grow at the tail so lookup_le should usually be cheaper
1989 if (bv->bv_cnt == 0 ||
1990 bp->b_lblkno > TAILQ_LAST(&bv->bv_hd, buflists)->b_lblkno)
1991 TAILQ_INSERT_TAIL(&bv->bv_hd, bp, b_bobufs);
1992 else if ((n = BUF_PCTRIE_LOOKUP_LE(&bv->bv_root, bp->b_lblkno)) == NULL)
1993 TAILQ_INSERT_HEAD(&bv->bv_hd, bp, b_bobufs);
1995 TAILQ_INSERT_AFTER(&bv->bv_hd, n, bp, b_bobufs);
1996 error = BUF_PCTRIE_INSERT(&bv->bv_root, bp);
1998 panic("buf_vlist_add: Preallocated nodes insufficient.");
2003 * Look up a buffer using the buffer tries.
2006 gbincore(struct bufobj *bo, daddr_t lblkno)
2010 ASSERT_BO_LOCKED(bo);
2011 bp = BUF_PCTRIE_LOOKUP(&bo->bo_clean.bv_root, lblkno);
2014 return BUF_PCTRIE_LOOKUP(&bo->bo_dirty.bv_root, lblkno);
2018 * Associate a buffer with a vnode.
2021 bgetvp(struct vnode *vp, struct buf *bp)
2026 ASSERT_BO_WLOCKED(bo);
2027 VNASSERT(bp->b_vp == NULL, bp->b_vp, ("bgetvp: not free"));
2029 CTR3(KTR_BUF, "bgetvp(%p) vp %p flags %X", bp, vp, bp->b_flags);
2030 VNASSERT((bp->b_xflags & (BX_VNDIRTY|BX_VNCLEAN)) == 0, vp,
2031 ("bgetvp: bp already attached! %p", bp));
2037 * Insert onto list for new vnode.
2039 buf_vlist_add(bp, bo, BX_VNCLEAN);
2043 * Disassociate a buffer from a vnode.
2046 brelvp(struct buf *bp)
2051 CTR3(KTR_BUF, "brelvp(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags);
2052 KASSERT(bp->b_vp != NULL, ("brelvp: NULL"));
2055 * Delete from old vnode list, if on one.
2057 vp = bp->b_vp; /* XXX */
2060 if (bp->b_xflags & (BX_VNDIRTY | BX_VNCLEAN))
2061 buf_vlist_remove(bp);
2063 panic("brelvp: Buffer %p not on queue.", bp);
2064 if ((bo->bo_flag & BO_ONWORKLST) && bo->bo_dirty.bv_cnt == 0) {
2065 bo->bo_flag &= ~BO_ONWORKLST;
2066 mtx_lock(&sync_mtx);
2067 LIST_REMOVE(bo, bo_synclist);
2068 syncer_worklist_len--;
2069 mtx_unlock(&sync_mtx);
2072 bp->b_bufobj = NULL;
2078 * Add an item to the syncer work queue.
2081 vn_syncer_add_to_worklist(struct bufobj *bo, int delay)
2085 ASSERT_BO_WLOCKED(bo);
2087 mtx_lock(&sync_mtx);
2088 if (bo->bo_flag & BO_ONWORKLST)
2089 LIST_REMOVE(bo, bo_synclist);
2091 bo->bo_flag |= BO_ONWORKLST;
2092 syncer_worklist_len++;
2095 if (delay > syncer_maxdelay - 2)
2096 delay = syncer_maxdelay - 2;
2097 slot = (syncer_delayno + delay) & syncer_mask;
2099 LIST_INSERT_HEAD(&syncer_workitem_pending[slot], bo, bo_synclist);
2100 mtx_unlock(&sync_mtx);
2104 sysctl_vfs_worklist_len(SYSCTL_HANDLER_ARGS)
2108 mtx_lock(&sync_mtx);
2109 len = syncer_worklist_len - sync_vnode_count;
2110 mtx_unlock(&sync_mtx);
2111 error = SYSCTL_OUT(req, &len, sizeof(len));
2115 SYSCTL_PROC(_vfs, OID_AUTO, worklist_len, CTLTYPE_INT | CTLFLAG_RD, NULL, 0,
2116 sysctl_vfs_worklist_len, "I", "Syncer thread worklist length");
2118 static struct proc *updateproc;
2119 static void sched_sync(void);
2120 static struct kproc_desc up_kp = {
2125 SYSINIT(syncer, SI_SUB_KTHREAD_UPDATE, SI_ORDER_FIRST, kproc_start, &up_kp);
2128 sync_vnode(struct synclist *slp, struct bufobj **bo, struct thread *td)
2133 *bo = LIST_FIRST(slp);
2137 if (VOP_ISLOCKED(vp) != 0 || VI_TRYLOCK(vp) == 0)
2140 * We use vhold in case the vnode does not
2141 * successfully sync. vhold prevents the vnode from
2142 * going away when we unlock the sync_mtx so that
2143 * we can acquire the vnode interlock.
2146 mtx_unlock(&sync_mtx);
2148 if (vn_start_write(vp, &mp, V_NOWAIT) != 0) {
2150 mtx_lock(&sync_mtx);
2151 return (*bo == LIST_FIRST(slp));
2153 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
2154 (void) VOP_FSYNC(vp, MNT_LAZY, td);
2156 vn_finished_write(mp);
2158 if (((*bo)->bo_flag & BO_ONWORKLST) != 0) {
2160 * Put us back on the worklist. The worklist
2161 * routine will remove us from our current
2162 * position and then add us back in at a later
2165 vn_syncer_add_to_worklist(*bo, syncdelay);
2169 mtx_lock(&sync_mtx);
2173 static int first_printf = 1;
2176 * System filesystem synchronizer daemon.
2181 struct synclist *next, *slp;
2184 struct thread *td = curthread;
2186 int net_worklist_len;
2187 int syncer_final_iter;
2191 syncer_final_iter = 0;
2192 syncer_state = SYNCER_RUNNING;
2193 starttime = time_uptime;
2194 td->td_pflags |= TDP_NORUNNINGBUF;
2196 EVENTHANDLER_REGISTER(shutdown_pre_sync, syncer_shutdown, td->td_proc,
2199 mtx_lock(&sync_mtx);
2201 if (syncer_state == SYNCER_FINAL_DELAY &&
2202 syncer_final_iter == 0) {
2203 mtx_unlock(&sync_mtx);
2204 kproc_suspend_check(td->td_proc);
2205 mtx_lock(&sync_mtx);
2207 net_worklist_len = syncer_worklist_len - sync_vnode_count;
2208 if (syncer_state != SYNCER_RUNNING &&
2209 starttime != time_uptime) {
2211 printf("\nSyncing disks, vnodes remaining... ");
2214 printf("%d ", net_worklist_len);
2216 starttime = time_uptime;
2219 * Push files whose dirty time has expired. Be careful
2220 * of interrupt race on slp queue.
2222 * Skip over empty worklist slots when shutting down.
2225 slp = &syncer_workitem_pending[syncer_delayno];
2226 syncer_delayno += 1;
2227 if (syncer_delayno == syncer_maxdelay)
2229 next = &syncer_workitem_pending[syncer_delayno];
2231 * If the worklist has wrapped since the
2232 * it was emptied of all but syncer vnodes,
2233 * switch to the FINAL_DELAY state and run
2234 * for one more second.
2236 if (syncer_state == SYNCER_SHUTTING_DOWN &&
2237 net_worklist_len == 0 &&
2238 last_work_seen == syncer_delayno) {
2239 syncer_state = SYNCER_FINAL_DELAY;
2240 syncer_final_iter = SYNCER_SHUTDOWN_SPEEDUP;
2242 } while (syncer_state != SYNCER_RUNNING && LIST_EMPTY(slp) &&
2243 syncer_worklist_len > 0);
2246 * Keep track of the last time there was anything
2247 * on the worklist other than syncer vnodes.
2248 * Return to the SHUTTING_DOWN state if any
2251 if (net_worklist_len > 0 || syncer_state == SYNCER_RUNNING)
2252 last_work_seen = syncer_delayno;
2253 if (net_worklist_len > 0 && syncer_state == SYNCER_FINAL_DELAY)
2254 syncer_state = SYNCER_SHUTTING_DOWN;
2255 while (!LIST_EMPTY(slp)) {
2256 error = sync_vnode(slp, &bo, td);
2258 LIST_REMOVE(bo, bo_synclist);
2259 LIST_INSERT_HEAD(next, bo, bo_synclist);
2263 if (first_printf == 0) {
2265 * Drop the sync mutex, because some watchdog
2266 * drivers need to sleep while patting
2268 mtx_unlock(&sync_mtx);
2269 wdog_kern_pat(WD_LASTVAL);
2270 mtx_lock(&sync_mtx);
2274 if (syncer_state == SYNCER_FINAL_DELAY && syncer_final_iter > 0)
2275 syncer_final_iter--;
2277 * The variable rushjob allows the kernel to speed up the
2278 * processing of the filesystem syncer process. A rushjob
2279 * value of N tells the filesystem syncer to process the next
2280 * N seconds worth of work on its queue ASAP. Currently rushjob
2281 * is used by the soft update code to speed up the filesystem
2282 * syncer process when the incore state is getting so far
2283 * ahead of the disk that the kernel memory pool is being
2284 * threatened with exhaustion.
2291 * Just sleep for a short period of time between
2292 * iterations when shutting down to allow some I/O
2295 * If it has taken us less than a second to process the
2296 * current work, then wait. Otherwise start right over
2297 * again. We can still lose time if any single round
2298 * takes more than two seconds, but it does not really
2299 * matter as we are just trying to generally pace the
2300 * filesystem activity.
2302 if (syncer_state != SYNCER_RUNNING ||
2303 time_uptime == starttime) {
2305 sched_prio(td, PPAUSE);
2308 if (syncer_state != SYNCER_RUNNING)
2309 cv_timedwait(&sync_wakeup, &sync_mtx,
2310 hz / SYNCER_SHUTDOWN_SPEEDUP);
2311 else if (time_uptime == starttime)
2312 cv_timedwait(&sync_wakeup, &sync_mtx, hz);
2317 * Request the syncer daemon to speed up its work.
2318 * We never push it to speed up more than half of its
2319 * normal turn time, otherwise it could take over the cpu.
2322 speedup_syncer(void)
2326 mtx_lock(&sync_mtx);
2327 if (rushjob < syncdelay / 2) {
2329 stat_rush_requests += 1;
2332 mtx_unlock(&sync_mtx);
2333 cv_broadcast(&sync_wakeup);
2338 * Tell the syncer to speed up its work and run though its work
2339 * list several times, then tell it to shut down.
2342 syncer_shutdown(void *arg, int howto)
2345 if (howto & RB_NOSYNC)
2347 mtx_lock(&sync_mtx);
2348 syncer_state = SYNCER_SHUTTING_DOWN;
2350 mtx_unlock(&sync_mtx);
2351 cv_broadcast(&sync_wakeup);
2352 kproc_shutdown(arg, howto);
2356 syncer_suspend(void)
2359 syncer_shutdown(updateproc, 0);
2366 mtx_lock(&sync_mtx);
2368 syncer_state = SYNCER_RUNNING;
2369 mtx_unlock(&sync_mtx);
2370 cv_broadcast(&sync_wakeup);
2371 kproc_resume(updateproc);
2375 * Reassign a buffer from one vnode to another.
2376 * Used to assign file specific control information
2377 * (indirect blocks) to the vnode to which they belong.
2380 reassignbuf(struct buf *bp)
2393 CTR3(KTR_BUF, "reassignbuf(%p) vp %p flags %X",
2394 bp, bp->b_vp, bp->b_flags);
2396 * B_PAGING flagged buffers cannot be reassigned because their vp
2397 * is not fully linked in.
2399 if (bp->b_flags & B_PAGING)
2400 panic("cannot reassign paging buffer");
2403 * Delete from old vnode list, if on one.
2406 if (bp->b_xflags & (BX_VNDIRTY | BX_VNCLEAN))
2407 buf_vlist_remove(bp);
2409 panic("reassignbuf: Buffer %p not on queue.", bp);
2411 * If dirty, put on list of dirty buffers; otherwise insert onto list
2414 if (bp->b_flags & B_DELWRI) {
2415 if ((bo->bo_flag & BO_ONWORKLST) == 0) {
2416 switch (vp->v_type) {
2426 vn_syncer_add_to_worklist(bo, delay);
2428 buf_vlist_add(bp, bo, BX_VNDIRTY);
2430 buf_vlist_add(bp, bo, BX_VNCLEAN);
2432 if ((bo->bo_flag & BO_ONWORKLST) && bo->bo_dirty.bv_cnt == 0) {
2433 mtx_lock(&sync_mtx);
2434 LIST_REMOVE(bo, bo_synclist);
2435 syncer_worklist_len--;
2436 mtx_unlock(&sync_mtx);
2437 bo->bo_flag &= ~BO_ONWORKLST;
2442 bp = TAILQ_FIRST(&bv->bv_hd);
2443 KASSERT(bp == NULL || bp->b_bufobj == bo,
2444 ("bp %p wrong b_bufobj %p should be %p", bp, bp->b_bufobj, bo));
2445 bp = TAILQ_LAST(&bv->bv_hd, buflists);
2446 KASSERT(bp == NULL || bp->b_bufobj == bo,
2447 ("bp %p wrong b_bufobj %p should be %p", bp, bp->b_bufobj, bo));
2449 bp = TAILQ_FIRST(&bv->bv_hd);
2450 KASSERT(bp == NULL || bp->b_bufobj == bo,
2451 ("bp %p wrong b_bufobj %p should be %p", bp, bp->b_bufobj, bo));
2452 bp = TAILQ_LAST(&bv->bv_hd, buflists);
2453 KASSERT(bp == NULL || bp->b_bufobj == bo,
2454 ("bp %p wrong b_bufobj %p should be %p", bp, bp->b_bufobj, bo));
2460 v_init_counters(struct vnode *vp)
2463 VNASSERT(vp->v_type == VNON && vp->v_data == NULL && vp->v_iflag == 0,
2464 vp, ("%s called for an initialized vnode", __FUNCTION__));
2465 ASSERT_VI_UNLOCKED(vp, __FUNCTION__);
2467 refcount_init(&vp->v_holdcnt, 1);
2468 refcount_init(&vp->v_usecount, 1);
2472 v_incr_usecount_locked(struct vnode *vp)
2475 ASSERT_VI_LOCKED(vp, __func__);
2476 if ((vp->v_iflag & VI_OWEINACT) != 0) {
2477 VNASSERT(vp->v_usecount == 0, vp,
2478 ("vnode with usecount and VI_OWEINACT set"));
2479 vp->v_iflag &= ~VI_OWEINACT;
2481 refcount_acquire(&vp->v_usecount);
2482 v_incr_devcount(vp);
2486 * Increment the use count on the vnode, taking care to reference
2487 * the driver's usecount if this is a chardev.
2490 v_incr_usecount(struct vnode *vp)
2493 ASSERT_VI_UNLOCKED(vp, __func__);
2494 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
2496 if (vp->v_type != VCHR &&
2497 refcount_acquire_if_not_zero(&vp->v_usecount)) {
2498 VNASSERT((vp->v_iflag & VI_OWEINACT) == 0, vp,
2499 ("vnode with usecount and VI_OWEINACT set"));
2502 v_incr_usecount_locked(vp);
2508 * Increment si_usecount of the associated device, if any.
2511 v_incr_devcount(struct vnode *vp)
2514 ASSERT_VI_LOCKED(vp, __FUNCTION__);
2515 if (vp->v_type == VCHR && vp->v_rdev != NULL) {
2517 vp->v_rdev->si_usecount++;
2523 * Decrement si_usecount of the associated device, if any.
2526 v_decr_devcount(struct vnode *vp)
2529 ASSERT_VI_LOCKED(vp, __FUNCTION__);
2530 if (vp->v_type == VCHR && vp->v_rdev != NULL) {
2532 vp->v_rdev->si_usecount--;
2538 * Grab a particular vnode from the free list, increment its
2539 * reference count and lock it. VI_DOOMED is set if the vnode
2540 * is being destroyed. Only callers who specify LK_RETRY will
2541 * see doomed vnodes. If inactive processing was delayed in
2542 * vput try to do it here.
2544 * Notes on lockless counter manipulation:
2545 * _vhold, vputx and other routines make various decisions based
2546 * on either holdcnt or usecount being 0. As long as either counter
2547 * is not transitioning 0->1 nor 1->0, the manipulation can be done
2548 * with atomic operations. Otherwise the interlock is taken covering
2549 * both the atomic and additional actions.
2552 vget(struct vnode *vp, int flags, struct thread *td)
2554 int error, oweinact;
2556 VNASSERT((flags & LK_TYPE_MASK) != 0, vp,
2557 ("vget: invalid lock operation"));
2559 if ((flags & LK_INTERLOCK) != 0)
2560 ASSERT_VI_LOCKED(vp, __func__);
2562 ASSERT_VI_UNLOCKED(vp, __func__);
2563 if ((flags & LK_VNHELD) != 0)
2564 VNASSERT((vp->v_holdcnt > 0), vp,
2565 ("vget: LK_VNHELD passed but vnode not held"));
2567 CTR3(KTR_VFS, "%s: vp %p with flags %d", __func__, vp, flags);
2569 if ((flags & LK_VNHELD) == 0)
2570 _vhold(vp, (flags & LK_INTERLOCK) != 0);
2572 if ((error = vn_lock(vp, flags)) != 0) {
2574 CTR2(KTR_VFS, "%s: impossible to lock vnode %p", __func__,
2578 if (vp->v_iflag & VI_DOOMED && (flags & LK_RETRY) == 0)
2579 panic("vget: vn_lock failed to return ENOENT\n");
2581 * We don't guarantee that any particular close will
2582 * trigger inactive processing so just make a best effort
2583 * here at preventing a reference to a removed file. If
2584 * we don't succeed no harm is done.
2586 * Upgrade our holdcnt to a usecount.
2588 if (vp->v_type == VCHR ||
2589 !refcount_acquire_if_not_zero(&vp->v_usecount)) {
2591 if ((vp->v_iflag & VI_OWEINACT) == 0) {
2595 vp->v_iflag &= ~VI_OWEINACT;
2597 refcount_acquire(&vp->v_usecount);
2598 v_incr_devcount(vp);
2599 if (oweinact && VOP_ISLOCKED(vp) == LK_EXCLUSIVE &&
2600 (flags & LK_NOWAIT) == 0)
2608 * Increase the reference (use) and hold count of a vnode.
2609 * This will also remove the vnode from the free list if it is presently free.
2612 vref(struct vnode *vp)
2615 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
2617 v_incr_usecount(vp);
2621 vrefl(struct vnode *vp)
2624 ASSERT_VI_LOCKED(vp, __func__);
2625 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
2627 v_incr_usecount_locked(vp);
2631 vrefact(struct vnode *vp)
2634 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
2635 if (__predict_false(vp->v_type == VCHR)) {
2636 VNASSERT(vp->v_holdcnt > 0 && vp->v_usecount > 0, vp,
2637 ("%s: wrong ref counts", __func__));
2642 int old = atomic_fetchadd_int(&vp->v_holdcnt, 1);
2643 VNASSERT(old > 0, vp, ("%s: wrong hold count", __func__));
2644 old = atomic_fetchadd_int(&vp->v_usecount, 1);
2645 VNASSERT(old > 0, vp, ("%s: wrong use count", __func__));
2647 refcount_acquire(&vp->v_holdcnt);
2648 refcount_acquire(&vp->v_usecount);
2653 * Return reference count of a vnode.
2655 * The results of this call are only guaranteed when some mechanism is used to
2656 * stop other processes from gaining references to the vnode. This may be the
2657 * case if the caller holds the only reference. This is also useful when stale
2658 * data is acceptable as race conditions may be accounted for by some other
2662 vrefcnt(struct vnode *vp)
2665 return (vp->v_usecount);
2668 #define VPUTX_VRELE 1
2669 #define VPUTX_VPUT 2
2670 #define VPUTX_VUNREF 3
2673 * Decrement the use and hold counts for a vnode.
2675 * See an explanation near vget() as to why atomic operation is safe.
2678 vputx(struct vnode *vp, int func)
2682 KASSERT(vp != NULL, ("vputx: null vp"));
2683 if (func == VPUTX_VUNREF)
2684 ASSERT_VOP_LOCKED(vp, "vunref");
2685 else if (func == VPUTX_VPUT)
2686 ASSERT_VOP_LOCKED(vp, "vput");
2688 KASSERT(func == VPUTX_VRELE, ("vputx: wrong func"));
2689 ASSERT_VI_UNLOCKED(vp, __func__);
2690 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
2692 if (vp->v_type != VCHR &&
2693 refcount_release_if_not_last(&vp->v_usecount)) {
2694 if (func == VPUTX_VPUT)
2703 * We want to hold the vnode until the inactive finishes to
2704 * prevent vgone() races. We drop the use count here and the
2705 * hold count below when we're done.
2707 if (!refcount_release(&vp->v_usecount) ||
2708 (vp->v_iflag & VI_DOINGINACT)) {
2709 if (func == VPUTX_VPUT)
2711 v_decr_devcount(vp);
2716 v_decr_devcount(vp);
2720 if (vp->v_usecount != 0) {
2721 vn_printf(vp, "vputx: usecount not zero for vnode ");
2722 panic("vputx: usecount not zero");
2725 CTR2(KTR_VFS, "%s: return vnode %p to the freelist", __func__, vp);
2728 * We must call VOP_INACTIVE with the node locked. Mark
2729 * as VI_DOINGINACT to avoid recursion.
2731 vp->v_iflag |= VI_OWEINACT;
2734 error = vn_lock(vp, LK_EXCLUSIVE | LK_INTERLOCK);
2738 if (VOP_ISLOCKED(vp) != LK_EXCLUSIVE) {
2739 error = VOP_LOCK(vp, LK_UPGRADE | LK_INTERLOCK |
2745 if (VOP_ISLOCKED(vp) != LK_EXCLUSIVE) {
2746 error = VOP_LOCK(vp, LK_TRYUPGRADE | LK_INTERLOCK);
2751 VNASSERT(vp->v_usecount == 0 || (vp->v_iflag & VI_OWEINACT) == 0, vp,
2752 ("vnode with usecount and VI_OWEINACT set"));
2754 if (vp->v_iflag & VI_OWEINACT)
2755 vinactive(vp, curthread);
2756 if (func != VPUTX_VUNREF)
2763 * Vnode put/release.
2764 * If count drops to zero, call inactive routine and return to freelist.
2767 vrele(struct vnode *vp)
2770 vputx(vp, VPUTX_VRELE);
2774 * Release an already locked vnode. This give the same effects as
2775 * unlock+vrele(), but takes less time and avoids releasing and
2776 * re-aquiring the lock (as vrele() acquires the lock internally.)
2779 vput(struct vnode *vp)
2782 vputx(vp, VPUTX_VPUT);
2786 * Release an exclusively locked vnode. Do not unlock the vnode lock.
2789 vunref(struct vnode *vp)
2792 vputx(vp, VPUTX_VUNREF);
2796 * Increase the hold count and activate if this is the first reference.
2799 _vhold(struct vnode *vp, bool locked)
2804 ASSERT_VI_LOCKED(vp, __func__);
2806 ASSERT_VI_UNLOCKED(vp, __func__);
2807 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
2809 if (refcount_acquire_if_not_zero(&vp->v_holdcnt)) {
2810 VNASSERT((vp->v_iflag & VI_FREE) == 0, vp,
2811 ("_vhold: vnode with holdcnt is free"));
2816 if ((vp->v_iflag & VI_FREE) == 0) {
2817 refcount_acquire(&vp->v_holdcnt);
2822 VNASSERT(vp->v_holdcnt == 0, vp,
2823 ("%s: wrong hold count", __func__));
2824 VNASSERT(vp->v_op != NULL, vp,
2825 ("%s: vnode already reclaimed.", __func__));
2827 * Remove a vnode from the free list, mark it as in use,
2828 * and put it on the active list.
2830 VNASSERT(vp->v_mount != NULL, vp,
2831 ("_vhold: vnode not on per mount vnode list"));
2833 mtx_lock(&mp->mnt_listmtx);
2834 if ((vp->v_mflag & VMP_TMPMNTFREELIST) != 0) {
2835 TAILQ_REMOVE(&mp->mnt_tmpfreevnodelist, vp, v_actfreelist);
2836 mp->mnt_tmpfreevnodelistsize--;
2837 vp->v_mflag &= ~VMP_TMPMNTFREELIST;
2839 mtx_lock(&vnode_free_list_mtx);
2840 TAILQ_REMOVE(&vnode_free_list, vp, v_actfreelist);
2842 mtx_unlock(&vnode_free_list_mtx);
2844 KASSERT((vp->v_iflag & VI_ACTIVE) == 0,
2845 ("Activating already active vnode"));
2846 vp->v_iflag &= ~VI_FREE;
2847 vp->v_iflag |= VI_ACTIVE;
2848 TAILQ_INSERT_HEAD(&mp->mnt_activevnodelist, vp, v_actfreelist);
2849 mp->mnt_activevnodelistsize++;
2850 mtx_unlock(&mp->mnt_listmtx);
2851 refcount_acquire(&vp->v_holdcnt);
2857 * Drop the hold count of the vnode. If this is the last reference to
2858 * the vnode we place it on the free list unless it has been vgone'd
2859 * (marked VI_DOOMED) in which case we will free it.
2861 * Because the vnode vm object keeps a hold reference on the vnode if
2862 * there is at least one resident non-cached page, the vnode cannot
2863 * leave the active list without the page cleanup done.
2866 _vdrop(struct vnode *vp, bool locked)
2873 ASSERT_VI_LOCKED(vp, __func__);
2875 ASSERT_VI_UNLOCKED(vp, __func__);
2876 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
2877 if ((int)vp->v_holdcnt <= 0)
2878 panic("vdrop: holdcnt %d", vp->v_holdcnt);
2880 if (refcount_release_if_not_last(&vp->v_holdcnt))
2884 if (refcount_release(&vp->v_holdcnt) == 0) {
2888 if ((vp->v_iflag & VI_DOOMED) == 0) {
2890 * Mark a vnode as free: remove it from its active list
2891 * and put it up for recycling on the freelist.
2893 VNASSERT(vp->v_op != NULL, vp,
2894 ("vdropl: vnode already reclaimed."));
2895 VNASSERT((vp->v_iflag & VI_FREE) == 0, vp,
2896 ("vnode already free"));
2897 VNASSERT(vp->v_holdcnt == 0, vp,
2898 ("vdropl: freeing when we shouldn't"));
2899 active = vp->v_iflag & VI_ACTIVE;
2900 if ((vp->v_iflag & VI_OWEINACT) == 0) {
2901 vp->v_iflag &= ~VI_ACTIVE;
2904 mtx_lock(&mp->mnt_listmtx);
2906 TAILQ_REMOVE(&mp->mnt_activevnodelist,
2908 mp->mnt_activevnodelistsize--;
2910 TAILQ_INSERT_TAIL(&mp->mnt_tmpfreevnodelist,
2912 mp->mnt_tmpfreevnodelistsize++;
2913 vp->v_iflag |= VI_FREE;
2914 vp->v_mflag |= VMP_TMPMNTFREELIST;
2916 if (mp->mnt_tmpfreevnodelistsize >=
2917 mnt_free_list_batch)
2918 vnlru_return_batch_locked(mp);
2919 mtx_unlock(&mp->mnt_listmtx);
2921 VNASSERT(active == 0, vp,
2922 ("vdropl: active vnode not on per mount "
2924 mtx_lock(&vnode_free_list_mtx);
2925 TAILQ_INSERT_TAIL(&vnode_free_list, vp,
2928 vp->v_iflag |= VI_FREE;
2930 mtx_unlock(&vnode_free_list_mtx);
2934 counter_u64_add(free_owe_inact, 1);
2939 * The vnode has been marked for destruction, so free it.
2941 * The vnode will be returned to the zone where it will
2942 * normally remain until it is needed for another vnode. We
2943 * need to cleanup (or verify that the cleanup has already
2944 * been done) any residual data left from its current use
2945 * so as not to contaminate the freshly allocated vnode.
2947 CTR2(KTR_VFS, "%s: destroying the vnode %p", __func__, vp);
2948 atomic_subtract_long(&numvnodes, 1);
2950 VNASSERT((vp->v_iflag & VI_FREE) == 0, vp,
2951 ("cleaned vnode still on the free list."));
2952 VNASSERT(vp->v_data == NULL, vp, ("cleaned vnode isn't"));
2953 VNASSERT(vp->v_holdcnt == 0, vp, ("Non-zero hold count"));
2954 VNASSERT(vp->v_usecount == 0, vp, ("Non-zero use count"));
2955 VNASSERT(vp->v_writecount == 0, vp, ("Non-zero write count"));
2956 VNASSERT(bo->bo_numoutput == 0, vp, ("Clean vnode has pending I/O's"));
2957 VNASSERT(bo->bo_clean.bv_cnt == 0, vp, ("cleanbufcnt not 0"));
2958 VNASSERT(pctrie_is_empty(&bo->bo_clean.bv_root), vp,
2959 ("clean blk trie not empty"));
2960 VNASSERT(bo->bo_dirty.bv_cnt == 0, vp, ("dirtybufcnt not 0"));
2961 VNASSERT(pctrie_is_empty(&bo->bo_dirty.bv_root), vp,
2962 ("dirty blk trie not empty"));
2963 VNASSERT(TAILQ_EMPTY(&vp->v_cache_dst), vp, ("vp has namecache dst"));
2964 VNASSERT(LIST_EMPTY(&vp->v_cache_src), vp, ("vp has namecache src"));
2965 VNASSERT(vp->v_cache_dd == NULL, vp, ("vp has namecache for .."));
2966 VNASSERT(TAILQ_EMPTY(&vp->v_rl.rl_waiters), vp,
2967 ("Dangling rangelock waiters"));
2970 mac_vnode_destroy(vp);
2972 if (vp->v_pollinfo != NULL) {
2973 destroy_vpollinfo(vp->v_pollinfo);
2974 vp->v_pollinfo = NULL;
2977 /* XXX Elsewhere we detect an already freed vnode via NULL v_op. */
2980 vp->v_mountedhere = NULL;
2983 vp->v_fifoinfo = NULL;
2984 vp->v_lasta = vp->v_clen = vp->v_cstart = vp->v_lastw = 0;
2988 uma_zfree(vnode_zone, vp);
2992 * Call VOP_INACTIVE on the vnode and manage the DOINGINACT and OWEINACT
2993 * flags. DOINGINACT prevents us from recursing in calls to vinactive.
2994 * OWEINACT tracks whether a vnode missed a call to inactive due to a
2995 * failed lock upgrade.
2998 vinactive(struct vnode *vp, struct thread *td)
3000 struct vm_object *obj;
3002 ASSERT_VOP_ELOCKED(vp, "vinactive");
3003 ASSERT_VI_LOCKED(vp, "vinactive");
3004 VNASSERT((vp->v_iflag & VI_DOINGINACT) == 0, vp,
3005 ("vinactive: recursed on VI_DOINGINACT"));
3006 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
3007 vp->v_iflag |= VI_DOINGINACT;
3008 vp->v_iflag &= ~VI_OWEINACT;
3011 * Before moving off the active list, we must be sure that any
3012 * modified pages are converted into the vnode's dirty
3013 * buffers, since these will no longer be checked once the
3014 * vnode is on the inactive list.
3016 * The write-out of the dirty pages is asynchronous. At the
3017 * point that VOP_INACTIVE() is called, there could still be
3018 * pending I/O and dirty pages in the object.
3020 if ((obj = vp->v_object) != NULL && (vp->v_vflag & VV_NOSYNC) == 0 &&
3021 (obj->flags & OBJ_MIGHTBEDIRTY) != 0) {
3022 VM_OBJECT_WLOCK(obj);
3023 vm_object_page_clean(obj, 0, 0, 0);
3024 VM_OBJECT_WUNLOCK(obj);
3026 VOP_INACTIVE(vp, td);
3028 VNASSERT(vp->v_iflag & VI_DOINGINACT, vp,
3029 ("vinactive: lost VI_DOINGINACT"));
3030 vp->v_iflag &= ~VI_DOINGINACT;
3034 * Remove any vnodes in the vnode table belonging to mount point mp.
3036 * If FORCECLOSE is not specified, there should not be any active ones,
3037 * return error if any are found (nb: this is a user error, not a
3038 * system error). If FORCECLOSE is specified, detach any active vnodes
3041 * If WRITECLOSE is set, only flush out regular file vnodes open for
3044 * SKIPSYSTEM causes any vnodes marked VV_SYSTEM to be skipped.
3046 * `rootrefs' specifies the base reference count for the root vnode
3047 * of this filesystem. The root vnode is considered busy if its
3048 * v_usecount exceeds this value. On a successful return, vflush(, td)
3049 * will call vrele() on the root vnode exactly rootrefs times.
3050 * If the SKIPSYSTEM or WRITECLOSE flags are specified, rootrefs must
3054 static int busyprt = 0; /* print out busy vnodes */
3055 SYSCTL_INT(_debug, OID_AUTO, busyprt, CTLFLAG_RW, &busyprt, 0, "Print out busy vnodes");
3059 vflush(struct mount *mp, int rootrefs, int flags, struct thread *td)
3061 struct vnode *vp, *mvp, *rootvp = NULL;
3063 int busy = 0, error;
3065 CTR4(KTR_VFS, "%s: mp %p with rootrefs %d and flags %d", __func__, mp,
3068 KASSERT((flags & (SKIPSYSTEM | WRITECLOSE)) == 0,
3069 ("vflush: bad args"));
3071 * Get the filesystem root vnode. We can vput() it
3072 * immediately, since with rootrefs > 0, it won't go away.
3074 if ((error = VFS_ROOT(mp, LK_EXCLUSIVE, &rootvp)) != 0) {
3075 CTR2(KTR_VFS, "%s: vfs_root lookup failed with %d",
3082 MNT_VNODE_FOREACH_ALL(vp, mp, mvp) {
3084 error = vn_lock(vp, LK_INTERLOCK | LK_EXCLUSIVE);
3087 MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
3091 * Skip over a vnodes marked VV_SYSTEM.
3093 if ((flags & SKIPSYSTEM) && (vp->v_vflag & VV_SYSTEM)) {
3099 * If WRITECLOSE is set, flush out unlinked but still open
3100 * files (even if open only for reading) and regular file
3101 * vnodes open for writing.
3103 if (flags & WRITECLOSE) {
3104 if (vp->v_object != NULL) {
3105 VM_OBJECT_WLOCK(vp->v_object);
3106 vm_object_page_clean(vp->v_object, 0, 0, 0);
3107 VM_OBJECT_WUNLOCK(vp->v_object);
3109 error = VOP_FSYNC(vp, MNT_WAIT, td);
3113 MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
3116 error = VOP_GETATTR(vp, &vattr, td->td_ucred);
3119 if ((vp->v_type == VNON ||
3120 (error == 0 && vattr.va_nlink > 0)) &&
3121 (vp->v_writecount == 0 || vp->v_type != VREG)) {
3129 * With v_usecount == 0, all we need to do is clear out the
3130 * vnode data structures and we are done.
3132 * If FORCECLOSE is set, forcibly close the vnode.
3134 if (vp->v_usecount == 0 || (flags & FORCECLOSE)) {
3140 vn_printf(vp, "vflush: busy vnode ");
3146 if (rootrefs > 0 && (flags & FORCECLOSE) == 0) {
3148 * If just the root vnode is busy, and if its refcount
3149 * is equal to `rootrefs', then go ahead and kill it.
3152 KASSERT(busy > 0, ("vflush: not busy"));
3153 VNASSERT(rootvp->v_usecount >= rootrefs, rootvp,
3154 ("vflush: usecount %d < rootrefs %d",
3155 rootvp->v_usecount, rootrefs));
3156 if (busy == 1 && rootvp->v_usecount == rootrefs) {
3157 VOP_LOCK(rootvp, LK_EXCLUSIVE|LK_INTERLOCK);
3159 VOP_UNLOCK(rootvp, 0);
3165 CTR2(KTR_VFS, "%s: failing as %d vnodes are busy", __func__,
3169 for (; rootrefs > 0; rootrefs--)
3175 * Recycle an unused vnode to the front of the free list.
3178 vrecycle(struct vnode *vp)
3183 recycled = vrecyclel(vp);
3189 * vrecycle, with the vp interlock held.
3192 vrecyclel(struct vnode *vp)
3196 ASSERT_VOP_ELOCKED(vp, __func__);
3197 ASSERT_VI_LOCKED(vp, __func__);
3198 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
3200 if (vp->v_usecount == 0) {
3208 * Eliminate all activity associated with a vnode
3209 * in preparation for reuse.
3212 vgone(struct vnode *vp)
3220 notify_lowervp_vfs_dummy(struct mount *mp __unused,
3221 struct vnode *lowervp __unused)
3226 * Notify upper mounts about reclaimed or unlinked vnode.
3229 vfs_notify_upper(struct vnode *vp, int event)
3231 static struct vfsops vgonel_vfsops = {
3232 .vfs_reclaim_lowervp = notify_lowervp_vfs_dummy,
3233 .vfs_unlink_lowervp = notify_lowervp_vfs_dummy,
3235 struct mount *mp, *ump, *mmp;
3242 if (TAILQ_EMPTY(&mp->mnt_uppers))
3245 mmp = malloc(sizeof(struct mount), M_TEMP, M_WAITOK | M_ZERO);
3246 mmp->mnt_op = &vgonel_vfsops;
3247 mmp->mnt_kern_flag |= MNTK_MARKER;
3249 mp->mnt_kern_flag |= MNTK_VGONE_UPPER;
3250 for (ump = TAILQ_FIRST(&mp->mnt_uppers); ump != NULL;) {
3251 if ((ump->mnt_kern_flag & MNTK_MARKER) != 0) {
3252 ump = TAILQ_NEXT(ump, mnt_upper_link);
3255 TAILQ_INSERT_AFTER(&mp->mnt_uppers, ump, mmp, mnt_upper_link);
3258 case VFS_NOTIFY_UPPER_RECLAIM:
3259 VFS_RECLAIM_LOWERVP(ump, vp);
3261 case VFS_NOTIFY_UPPER_UNLINK:
3262 VFS_UNLINK_LOWERVP(ump, vp);
3265 KASSERT(0, ("invalid event %d", event));
3269 ump = TAILQ_NEXT(mmp, mnt_upper_link);
3270 TAILQ_REMOVE(&mp->mnt_uppers, mmp, mnt_upper_link);
3273 mp->mnt_kern_flag &= ~MNTK_VGONE_UPPER;
3274 if ((mp->mnt_kern_flag & MNTK_VGONE_WAITER) != 0) {
3275 mp->mnt_kern_flag &= ~MNTK_VGONE_WAITER;
3276 wakeup(&mp->mnt_uppers);
3283 * vgone, with the vp interlock held.
3286 vgonel(struct vnode *vp)
3293 ASSERT_VOP_ELOCKED(vp, "vgonel");
3294 ASSERT_VI_LOCKED(vp, "vgonel");
3295 VNASSERT(vp->v_holdcnt, vp,
3296 ("vgonel: vp %p has no reference.", vp));
3297 CTR2(KTR_VFS, "%s: vp %p", __func__, vp);
3301 * Don't vgonel if we're already doomed.
3303 if (vp->v_iflag & VI_DOOMED)
3305 vp->v_iflag |= VI_DOOMED;
3308 * Check to see if the vnode is in use. If so, we have to call
3309 * VOP_CLOSE() and VOP_INACTIVE().
3311 active = vp->v_usecount;
3312 oweinact = (vp->v_iflag & VI_OWEINACT);
3314 vfs_notify_upper(vp, VFS_NOTIFY_UPPER_RECLAIM);
3317 * If purging an active vnode, it must be closed and
3318 * deactivated before being reclaimed.
3321 VOP_CLOSE(vp, FNONBLOCK, NOCRED, td);
3322 if (oweinact || active) {
3324 if ((vp->v_iflag & VI_DOINGINACT) == 0)
3328 if (vp->v_type == VSOCK)
3329 vfs_unp_reclaim(vp);
3332 * Clean out any buffers associated with the vnode.
3333 * If the flush fails, just toss the buffers.
3336 if (!TAILQ_EMPTY(&vp->v_bufobj.bo_dirty.bv_hd))
3337 (void) vn_start_secondary_write(vp, &mp, V_WAIT);
3338 if (vinvalbuf(vp, V_SAVE, 0, 0) != 0) {
3339 while (vinvalbuf(vp, 0, 0, 0) != 0)
3343 BO_LOCK(&vp->v_bufobj);
3344 KASSERT(TAILQ_EMPTY(&vp->v_bufobj.bo_dirty.bv_hd) &&
3345 vp->v_bufobj.bo_dirty.bv_cnt == 0 &&
3346 TAILQ_EMPTY(&vp->v_bufobj.bo_clean.bv_hd) &&
3347 vp->v_bufobj.bo_clean.bv_cnt == 0,
3348 ("vp %p bufobj not invalidated", vp));
3351 * For VMIO bufobj, BO_DEAD is set in vm_object_terminate()
3352 * after the object's page queue is flushed.
3354 if (vp->v_bufobj.bo_object == NULL)
3355 vp->v_bufobj.bo_flag |= BO_DEAD;
3356 BO_UNLOCK(&vp->v_bufobj);
3359 * Reclaim the vnode.
3361 if (VOP_RECLAIM(vp, td))
3362 panic("vgone: cannot reclaim");
3364 vn_finished_secondary_write(mp);
3365 VNASSERT(vp->v_object == NULL, vp,
3366 ("vop_reclaim left v_object vp=%p, tag=%s", vp, vp->v_tag));
3368 * Clear the advisory locks and wake up waiting threads.
3370 (void)VOP_ADVLOCKPURGE(vp);
3373 * Delete from old mount point vnode list.
3378 * Done with purge, reset to the standard lock and invalidate
3382 vp->v_vnlock = &vp->v_lock;
3383 vp->v_op = &dead_vnodeops;
3389 * Calculate the total number of references to a special device.
3392 vcount(struct vnode *vp)
3397 count = vp->v_rdev->si_usecount;
3403 * Same as above, but using the struct cdev *as argument
3406 count_dev(struct cdev *dev)
3411 count = dev->si_usecount;
3417 * Print out a description of a vnode.
3419 static char *typename[] =
3420 {"VNON", "VREG", "VDIR", "VBLK", "VCHR", "VLNK", "VSOCK", "VFIFO", "VBAD",
3424 vn_printf(struct vnode *vp, const char *fmt, ...)
3427 char buf[256], buf2[16];
3433 printf("%p: ", (void *)vp);
3434 printf("tag %s, type %s\n", vp->v_tag, typename[vp->v_type]);
3435 printf(" usecount %d, writecount %d, refcount %d",
3436 vp->v_usecount, vp->v_writecount, vp->v_holdcnt);
3437 switch (vp->v_type) {
3439 printf(" mountedhere %p\n", vp->v_mountedhere);
3442 printf(" rdev %p\n", vp->v_rdev);
3445 printf(" socket %p\n", vp->v_unpcb);
3448 printf(" fifoinfo %p\n", vp->v_fifoinfo);
3456 if (vp->v_vflag & VV_ROOT)
3457 strlcat(buf, "|VV_ROOT", sizeof(buf));
3458 if (vp->v_vflag & VV_ISTTY)
3459 strlcat(buf, "|VV_ISTTY", sizeof(buf));
3460 if (vp->v_vflag & VV_NOSYNC)
3461 strlcat(buf, "|VV_NOSYNC", sizeof(buf));
3462 if (vp->v_vflag & VV_ETERNALDEV)
3463 strlcat(buf, "|VV_ETERNALDEV", sizeof(buf));
3464 if (vp->v_vflag & VV_CACHEDLABEL)
3465 strlcat(buf, "|VV_CACHEDLABEL", sizeof(buf));
3466 if (vp->v_vflag & VV_TEXT)
3467 strlcat(buf, "|VV_TEXT", sizeof(buf));
3468 if (vp->v_vflag & VV_COPYONWRITE)
3469 strlcat(buf, "|VV_COPYONWRITE", sizeof(buf));
3470 if (vp->v_vflag & VV_SYSTEM)
3471 strlcat(buf, "|VV_SYSTEM", sizeof(buf));
3472 if (vp->v_vflag & VV_PROCDEP)
3473 strlcat(buf, "|VV_PROCDEP", sizeof(buf));
3474 if (vp->v_vflag & VV_NOKNOTE)
3475 strlcat(buf, "|VV_NOKNOTE", sizeof(buf));
3476 if (vp->v_vflag & VV_DELETED)
3477 strlcat(buf, "|VV_DELETED", sizeof(buf));
3478 if (vp->v_vflag & VV_MD)
3479 strlcat(buf, "|VV_MD", sizeof(buf));
3480 if (vp->v_vflag & VV_FORCEINSMQ)
3481 strlcat(buf, "|VV_FORCEINSMQ", sizeof(buf));
3482 flags = vp->v_vflag & ~(VV_ROOT | VV_ISTTY | VV_NOSYNC | VV_ETERNALDEV |
3483 VV_CACHEDLABEL | VV_TEXT | VV_COPYONWRITE | VV_SYSTEM | VV_PROCDEP |
3484 VV_NOKNOTE | VV_DELETED | VV_MD | VV_FORCEINSMQ);
3486 snprintf(buf2, sizeof(buf2), "|VV(0x%lx)", flags);
3487 strlcat(buf, buf2, sizeof(buf));
3489 if (vp->v_iflag & VI_MOUNT)
3490 strlcat(buf, "|VI_MOUNT", sizeof(buf));
3491 if (vp->v_iflag & VI_DOOMED)
3492 strlcat(buf, "|VI_DOOMED", sizeof(buf));
3493 if (vp->v_iflag & VI_FREE)
3494 strlcat(buf, "|VI_FREE", sizeof(buf));
3495 if (vp->v_iflag & VI_ACTIVE)
3496 strlcat(buf, "|VI_ACTIVE", sizeof(buf));
3497 if (vp->v_iflag & VI_DOINGINACT)
3498 strlcat(buf, "|VI_DOINGINACT", sizeof(buf));
3499 if (vp->v_iflag & VI_OWEINACT)
3500 strlcat(buf, "|VI_OWEINACT", sizeof(buf));
3501 flags = vp->v_iflag & ~(VI_MOUNT | VI_DOOMED | VI_FREE |
3502 VI_ACTIVE | VI_DOINGINACT | VI_OWEINACT);
3504 snprintf(buf2, sizeof(buf2), "|VI(0x%lx)", flags);
3505 strlcat(buf, buf2, sizeof(buf));
3507 printf(" flags (%s)\n", buf + 1);
3508 if (mtx_owned(VI_MTX(vp)))
3509 printf(" VI_LOCKed");
3510 if (vp->v_object != NULL)
3511 printf(" v_object %p ref %d pages %d "
3512 "cleanbuf %d dirtybuf %d\n",
3513 vp->v_object, vp->v_object->ref_count,
3514 vp->v_object->resident_page_count,
3515 vp->v_bufobj.bo_clean.bv_cnt,
3516 vp->v_bufobj.bo_dirty.bv_cnt);
3518 lockmgr_printinfo(vp->v_vnlock);
3519 if (vp->v_data != NULL)
3525 * List all of the locked vnodes in the system.
3526 * Called when debugging the kernel.
3528 DB_SHOW_COMMAND(lockedvnods, lockedvnodes)
3534 * Note: because this is DDB, we can't obey the locking semantics
3535 * for these structures, which means we could catch an inconsistent
3536 * state and dereference a nasty pointer. Not much to be done
3539 db_printf("Locked vnodes\n");
3540 TAILQ_FOREACH(mp, &mountlist, mnt_list) {
3541 TAILQ_FOREACH(vp, &mp->mnt_nvnodelist, v_nmntvnodes) {
3542 if (vp->v_type != VMARKER && VOP_ISLOCKED(vp))
3543 vn_printf(vp, "vnode ");
3549 * Show details about the given vnode.
3551 DB_SHOW_COMMAND(vnode, db_show_vnode)
3557 vp = (struct vnode *)addr;
3558 vn_printf(vp, "vnode ");
3562 * Show details about the given mount point.
3564 DB_SHOW_COMMAND(mount, db_show_mount)
3575 /* No address given, print short info about all mount points. */
3576 TAILQ_FOREACH(mp, &mountlist, mnt_list) {
3577 db_printf("%p %s on %s (%s)\n", mp,
3578 mp->mnt_stat.f_mntfromname,
3579 mp->mnt_stat.f_mntonname,
3580 mp->mnt_stat.f_fstypename);
3584 db_printf("\nMore info: show mount <addr>\n");
3588 mp = (struct mount *)addr;
3589 db_printf("%p %s on %s (%s)\n", mp, mp->mnt_stat.f_mntfromname,
3590 mp->mnt_stat.f_mntonname, mp->mnt_stat.f_fstypename);
3593 mflags = mp->mnt_flag;
3594 #define MNT_FLAG(flag) do { \
3595 if (mflags & (flag)) { \
3596 if (buf[0] != '\0') \
3597 strlcat(buf, ", ", sizeof(buf)); \
3598 strlcat(buf, (#flag) + 4, sizeof(buf)); \
3599 mflags &= ~(flag); \
3602 MNT_FLAG(MNT_RDONLY);
3603 MNT_FLAG(MNT_SYNCHRONOUS);
3604 MNT_FLAG(MNT_NOEXEC);
3605 MNT_FLAG(MNT_NOSUID);
3606 MNT_FLAG(MNT_NFS4ACLS);
3607 MNT_FLAG(MNT_UNION);
3608 MNT_FLAG(MNT_ASYNC);
3609 MNT_FLAG(MNT_SUIDDIR);
3610 MNT_FLAG(MNT_SOFTDEP);
3611 MNT_FLAG(MNT_NOSYMFOLLOW);
3612 MNT_FLAG(MNT_GJOURNAL);
3613 MNT_FLAG(MNT_MULTILABEL);
3615 MNT_FLAG(MNT_NOATIME);
3616 MNT_FLAG(MNT_NOCLUSTERR);
3617 MNT_FLAG(MNT_NOCLUSTERW);
3619 MNT_FLAG(MNT_EXRDONLY);
3620 MNT_FLAG(MNT_EXPORTED);
3621 MNT_FLAG(MNT_DEFEXPORTED);
3622 MNT_FLAG(MNT_EXPORTANON);
3623 MNT_FLAG(MNT_EXKERB);
3624 MNT_FLAG(MNT_EXPUBLIC);
3625 MNT_FLAG(MNT_LOCAL);
3626 MNT_FLAG(MNT_QUOTA);
3627 MNT_FLAG(MNT_ROOTFS);
3629 MNT_FLAG(MNT_IGNORE);
3630 MNT_FLAG(MNT_UPDATE);
3631 MNT_FLAG(MNT_DELEXPORT);
3632 MNT_FLAG(MNT_RELOAD);
3633 MNT_FLAG(MNT_FORCE);
3634 MNT_FLAG(MNT_SNAPSHOT);
3635 MNT_FLAG(MNT_BYFSID);
3639 strlcat(buf, ", ", sizeof(buf));
3640 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
3641 "0x%016jx", mflags);
3643 db_printf(" mnt_flag = %s\n", buf);
3646 flags = mp->mnt_kern_flag;
3647 #define MNT_KERN_FLAG(flag) do { \
3648 if (flags & (flag)) { \
3649 if (buf[0] != '\0') \
3650 strlcat(buf, ", ", sizeof(buf)); \
3651 strlcat(buf, (#flag) + 5, sizeof(buf)); \
3655 MNT_KERN_FLAG(MNTK_UNMOUNTF);
3656 MNT_KERN_FLAG(MNTK_ASYNC);
3657 MNT_KERN_FLAG(MNTK_SOFTDEP);
3658 MNT_KERN_FLAG(MNTK_NOINSMNTQ);
3659 MNT_KERN_FLAG(MNTK_DRAINING);
3660 MNT_KERN_FLAG(MNTK_REFEXPIRE);
3661 MNT_KERN_FLAG(MNTK_EXTENDED_SHARED);
3662 MNT_KERN_FLAG(MNTK_SHARED_WRITES);
3663 MNT_KERN_FLAG(MNTK_NO_IOPF);
3664 MNT_KERN_FLAG(MNTK_VGONE_UPPER);
3665 MNT_KERN_FLAG(MNTK_VGONE_WAITER);
3666 MNT_KERN_FLAG(MNTK_LOOKUP_EXCL_DOTDOT);
3667 MNT_KERN_FLAG(MNTK_MARKER);
3668 MNT_KERN_FLAG(MNTK_USES_BCACHE);
3669 MNT_KERN_FLAG(MNTK_NOASYNC);
3670 MNT_KERN_FLAG(MNTK_UNMOUNT);
3671 MNT_KERN_FLAG(MNTK_MWAIT);
3672 MNT_KERN_FLAG(MNTK_SUSPEND);
3673 MNT_KERN_FLAG(MNTK_SUSPEND2);
3674 MNT_KERN_FLAG(MNTK_SUSPENDED);
3675 MNT_KERN_FLAG(MNTK_LOOKUP_SHARED);
3676 MNT_KERN_FLAG(MNTK_NOKNOTE);
3677 #undef MNT_KERN_FLAG
3680 strlcat(buf, ", ", sizeof(buf));
3681 snprintf(buf + strlen(buf), sizeof(buf) - strlen(buf),
3684 db_printf(" mnt_kern_flag = %s\n", buf);
3686 db_printf(" mnt_opt = ");
3687 opt = TAILQ_FIRST(mp->mnt_opt);
3689 db_printf("%s", opt->name);
3690 opt = TAILQ_NEXT(opt, link);
3691 while (opt != NULL) {
3692 db_printf(", %s", opt->name);
3693 opt = TAILQ_NEXT(opt, link);
3699 db_printf(" mnt_stat = { version=%u type=%u flags=0x%016jx "
3700 "bsize=%ju iosize=%ju blocks=%ju bfree=%ju bavail=%jd files=%ju "
3701 "ffree=%jd syncwrites=%ju asyncwrites=%ju syncreads=%ju "
3702 "asyncreads=%ju namemax=%u owner=%u fsid=[%d, %d] }\n",
3703 (u_int)sp->f_version, (u_int)sp->f_type, (uintmax_t)sp->f_flags,
3704 (uintmax_t)sp->f_bsize, (uintmax_t)sp->f_iosize,
3705 (uintmax_t)sp->f_blocks, (uintmax_t)sp->f_bfree,
3706 (intmax_t)sp->f_bavail, (uintmax_t)sp->f_files,
3707 (intmax_t)sp->f_ffree, (uintmax_t)sp->f_syncwrites,
3708 (uintmax_t)sp->f_asyncwrites, (uintmax_t)sp->f_syncreads,
3709 (uintmax_t)sp->f_asyncreads, (u_int)sp->f_namemax,
3710 (u_int)sp->f_owner, (int)sp->f_fsid.val[0], (int)sp->f_fsid.val[1]);
3712 db_printf(" mnt_cred = { uid=%u ruid=%u",
3713 (u_int)mp->mnt_cred->cr_uid, (u_int)mp->mnt_cred->cr_ruid);
3714 if (jailed(mp->mnt_cred))
3715 db_printf(", jail=%d", mp->mnt_cred->cr_prison->pr_id);
3717 db_printf(" mnt_ref = %d\n", mp->mnt_ref);
3718 db_printf(" mnt_gen = %d\n", mp->mnt_gen);
3719 db_printf(" mnt_nvnodelistsize = %d\n", mp->mnt_nvnodelistsize);
3720 db_printf(" mnt_activevnodelistsize = %d\n",
3721 mp->mnt_activevnodelistsize);
3722 db_printf(" mnt_writeopcount = %d\n", mp->mnt_writeopcount);
3723 db_printf(" mnt_maxsymlinklen = %d\n", mp->mnt_maxsymlinklen);
3724 db_printf(" mnt_iosize_max = %d\n", mp->mnt_iosize_max);
3725 db_printf(" mnt_hashseed = %u\n", mp->mnt_hashseed);
3726 db_printf(" mnt_lockref = %d\n", mp->mnt_lockref);
3727 db_printf(" mnt_secondary_writes = %d\n", mp->mnt_secondary_writes);
3728 db_printf(" mnt_secondary_accwrites = %d\n",
3729 mp->mnt_secondary_accwrites);
3730 db_printf(" mnt_gjprovider = %s\n",
3731 mp->mnt_gjprovider != NULL ? mp->mnt_gjprovider : "NULL");
3733 db_printf("\n\nList of active vnodes\n");
3734 TAILQ_FOREACH(vp, &mp->mnt_activevnodelist, v_actfreelist) {
3735 if (vp->v_type != VMARKER) {
3736 vn_printf(vp, "vnode ");
3741 db_printf("\n\nList of inactive vnodes\n");
3742 TAILQ_FOREACH(vp, &mp->mnt_nvnodelist, v_nmntvnodes) {
3743 if (vp->v_type != VMARKER && (vp->v_iflag & VI_ACTIVE) == 0) {
3744 vn_printf(vp, "vnode ");
3753 * Fill in a struct xvfsconf based on a struct vfsconf.
3756 vfsconf2x(struct sysctl_req *req, struct vfsconf *vfsp)
3758 struct xvfsconf xvfsp;
3760 bzero(&xvfsp, sizeof(xvfsp));
3761 strcpy(xvfsp.vfc_name, vfsp->vfc_name);
3762 xvfsp.vfc_typenum = vfsp->vfc_typenum;
3763 xvfsp.vfc_refcount = vfsp->vfc_refcount;
3764 xvfsp.vfc_flags = vfsp->vfc_flags;
3766 * These are unused in userland, we keep them
3767 * to not break binary compatibility.
3769 xvfsp.vfc_vfsops = NULL;
3770 xvfsp.vfc_next = NULL;
3771 return (SYSCTL_OUT(req, &xvfsp, sizeof(xvfsp)));
3774 #ifdef COMPAT_FREEBSD32
3776 uint32_t vfc_vfsops;
3777 char vfc_name[MFSNAMELEN];
3778 int32_t vfc_typenum;
3779 int32_t vfc_refcount;
3785 vfsconf2x32(struct sysctl_req *req, struct vfsconf *vfsp)
3787 struct xvfsconf32 xvfsp;
3789 bzero(&xvfsp, sizeof(xvfsp));
3790 strcpy(xvfsp.vfc_name, vfsp->vfc_name);
3791 xvfsp.vfc_typenum = vfsp->vfc_typenum;
3792 xvfsp.vfc_refcount = vfsp->vfc_refcount;
3793 xvfsp.vfc_flags = vfsp->vfc_flags;
3794 return (SYSCTL_OUT(req, &xvfsp, sizeof(xvfsp)));
3799 * Top level filesystem related information gathering.
3802 sysctl_vfs_conflist(SYSCTL_HANDLER_ARGS)
3804 struct vfsconf *vfsp;
3809 TAILQ_FOREACH(vfsp, &vfsconf, vfc_list) {
3810 #ifdef COMPAT_FREEBSD32
3811 if (req->flags & SCTL_MASK32)
3812 error = vfsconf2x32(req, vfsp);
3815 error = vfsconf2x(req, vfsp);
3823 SYSCTL_PROC(_vfs, OID_AUTO, conflist, CTLTYPE_OPAQUE | CTLFLAG_RD |
3824 CTLFLAG_MPSAFE, NULL, 0, sysctl_vfs_conflist,
3825 "S,xvfsconf", "List of all configured filesystems");
3827 #ifndef BURN_BRIDGES
3828 static int sysctl_ovfs_conf(SYSCTL_HANDLER_ARGS);
3831 vfs_sysctl(SYSCTL_HANDLER_ARGS)
3833 int *name = (int *)arg1 - 1; /* XXX */
3834 u_int namelen = arg2 + 1; /* XXX */
3835 struct vfsconf *vfsp;
3837 log(LOG_WARNING, "userland calling deprecated sysctl, "
3838 "please rebuild world\n");
3840 #if 1 || defined(COMPAT_PRELITE2)
3841 /* Resolve ambiguity between VFS_VFSCONF and VFS_GENERIC. */
3843 return (sysctl_ovfs_conf(oidp, arg1, arg2, req));
3847 case VFS_MAXTYPENUM:
3850 return (SYSCTL_OUT(req, &maxvfsconf, sizeof(int)));
3853 return (ENOTDIR); /* overloaded */
3855 TAILQ_FOREACH(vfsp, &vfsconf, vfc_list) {
3856 if (vfsp->vfc_typenum == name[2])
3861 return (EOPNOTSUPP);
3862 #ifdef COMPAT_FREEBSD32
3863 if (req->flags & SCTL_MASK32)
3864 return (vfsconf2x32(req, vfsp));
3867 return (vfsconf2x(req, vfsp));
3869 return (EOPNOTSUPP);
3872 static SYSCTL_NODE(_vfs, VFS_GENERIC, generic, CTLFLAG_RD | CTLFLAG_SKIP |
3873 CTLFLAG_MPSAFE, vfs_sysctl,
3874 "Generic filesystem");
3876 #if 1 || defined(COMPAT_PRELITE2)
3879 sysctl_ovfs_conf(SYSCTL_HANDLER_ARGS)
3882 struct vfsconf *vfsp;
3883 struct ovfsconf ovfs;
3886 TAILQ_FOREACH(vfsp, &vfsconf, vfc_list) {
3887 bzero(&ovfs, sizeof(ovfs));
3888 ovfs.vfc_vfsops = vfsp->vfc_vfsops; /* XXX used as flag */
3889 strcpy(ovfs.vfc_name, vfsp->vfc_name);
3890 ovfs.vfc_index = vfsp->vfc_typenum;
3891 ovfs.vfc_refcount = vfsp->vfc_refcount;
3892 ovfs.vfc_flags = vfsp->vfc_flags;
3893 error = SYSCTL_OUT(req, &ovfs, sizeof ovfs);
3903 #endif /* 1 || COMPAT_PRELITE2 */
3904 #endif /* !BURN_BRIDGES */
3906 #define KINFO_VNODESLOP 10
3909 * Dump vnode list (via sysctl).
3913 sysctl_vnode(SYSCTL_HANDLER_ARGS)
3921 * Stale numvnodes access is not fatal here.
3924 len = (numvnodes + KINFO_VNODESLOP) * sizeof *xvn;
3926 /* Make an estimate */
3927 return (SYSCTL_OUT(req, 0, len));
3929 error = sysctl_wire_old_buffer(req, 0);
3932 xvn = malloc(len, M_TEMP, M_ZERO | M_WAITOK);
3934 mtx_lock(&mountlist_mtx);
3935 TAILQ_FOREACH(mp, &mountlist, mnt_list) {
3936 if (vfs_busy(mp, MBF_NOWAIT | MBF_MNTLSTLOCK))
3939 TAILQ_FOREACH(vp, &mp->mnt_nvnodelist, v_nmntvnodes) {
3943 xvn[n].xv_size = sizeof *xvn;
3944 xvn[n].xv_vnode = vp;
3945 xvn[n].xv_id = 0; /* XXX compat */
3946 #define XV_COPY(field) xvn[n].xv_##field = vp->v_##field
3948 XV_COPY(writecount);
3954 xvn[n].xv_flag = vp->v_vflag;
3956 switch (vp->v_type) {
3963 if (vp->v_rdev == NULL) {
3967 xvn[n].xv_dev = dev2udev(vp->v_rdev);
3970 xvn[n].xv_socket = vp->v_socket;
3973 xvn[n].xv_fifo = vp->v_fifoinfo;
3978 /* shouldn't happen? */
3986 mtx_lock(&mountlist_mtx);
3991 mtx_unlock(&mountlist_mtx);
3993 error = SYSCTL_OUT(req, xvn, n * sizeof *xvn);
3998 SYSCTL_PROC(_kern, KERN_VNODE, vnode, CTLTYPE_OPAQUE | CTLFLAG_RD |
3999 CTLFLAG_MPSAFE, 0, 0, sysctl_vnode, "S,xvnode",
4004 unmount_or_warn(struct mount *mp)
4008 error = dounmount(mp, MNT_FORCE, curthread);
4010 printf("unmount of %s failed (", mp->mnt_stat.f_mntonname);
4014 printf("%d)\n", error);
4019 * Unmount all filesystems. The list is traversed in reverse order
4020 * of mounting to avoid dependencies.
4023 vfs_unmountall(void)
4025 struct mount *mp, *tmp;
4027 CTR1(KTR_VFS, "%s: unmounting all filesystems", __func__);
4030 * Since this only runs when rebooting, it is not interlocked.
4032 TAILQ_FOREACH_REVERSE_SAFE(mp, &mountlist, mntlist, mnt_list, tmp) {
4036 * Forcibly unmounting "/dev" before "/" would prevent clean
4037 * unmount of the latter.
4039 if (mp == rootdevmp)
4042 unmount_or_warn(mp);
4045 if (rootdevmp != NULL)
4046 unmount_or_warn(rootdevmp);
4050 * perform msync on all vnodes under a mount point
4051 * the mount point must be locked.
4054 vfs_msync(struct mount *mp, int flags)
4056 struct vnode *vp, *mvp;
4057 struct vm_object *obj;
4059 CTR2(KTR_VFS, "%s: mp %p", __func__, mp);
4061 vnlru_return_batch(mp);
4063 MNT_VNODE_FOREACH_ACTIVE(vp, mp, mvp) {
4065 if (obj != NULL && (obj->flags & OBJ_MIGHTBEDIRTY) != 0 &&
4066 (flags == MNT_WAIT || VOP_ISLOCKED(vp) == 0)) {
4068 LK_EXCLUSIVE | LK_RETRY | LK_INTERLOCK,
4070 if (vp->v_vflag & VV_NOSYNC) { /* unlinked */
4077 VM_OBJECT_WLOCK(obj);
4078 vm_object_page_clean(obj, 0, 0,
4080 OBJPC_SYNC : OBJPC_NOSYNC);
4081 VM_OBJECT_WUNLOCK(obj);
4091 destroy_vpollinfo_free(struct vpollinfo *vi)
4094 knlist_destroy(&vi->vpi_selinfo.si_note);
4095 mtx_destroy(&vi->vpi_lock);
4096 uma_zfree(vnodepoll_zone, vi);
4100 destroy_vpollinfo(struct vpollinfo *vi)
4103 knlist_clear(&vi->vpi_selinfo.si_note, 1);
4104 seldrain(&vi->vpi_selinfo);
4105 destroy_vpollinfo_free(vi);
4109 * Initialize per-vnode helper structure to hold poll-related state.
4112 v_addpollinfo(struct vnode *vp)
4114 struct vpollinfo *vi;
4116 if (vp->v_pollinfo != NULL)
4118 vi = uma_zalloc(vnodepoll_zone, M_WAITOK | M_ZERO);
4119 mtx_init(&vi->vpi_lock, "vnode pollinfo", NULL, MTX_DEF);
4120 knlist_init(&vi->vpi_selinfo.si_note, vp, vfs_knllock,
4121 vfs_knlunlock, vfs_knl_assert_locked, vfs_knl_assert_unlocked);
4123 if (vp->v_pollinfo != NULL) {
4125 destroy_vpollinfo_free(vi);
4128 vp->v_pollinfo = vi;
4133 * Record a process's interest in events which might happen to
4134 * a vnode. Because poll uses the historic select-style interface
4135 * internally, this routine serves as both the ``check for any
4136 * pending events'' and the ``record my interest in future events''
4137 * functions. (These are done together, while the lock is held,
4138 * to avoid race conditions.)
4141 vn_pollrecord(struct vnode *vp, struct thread *td, int events)
4145 mtx_lock(&vp->v_pollinfo->vpi_lock);
4146 if (vp->v_pollinfo->vpi_revents & events) {
4148 * This leaves events we are not interested
4149 * in available for the other process which
4150 * which presumably had requested them
4151 * (otherwise they would never have been
4154 events &= vp->v_pollinfo->vpi_revents;
4155 vp->v_pollinfo->vpi_revents &= ~events;
4157 mtx_unlock(&vp->v_pollinfo->vpi_lock);
4160 vp->v_pollinfo->vpi_events |= events;
4161 selrecord(td, &vp->v_pollinfo->vpi_selinfo);
4162 mtx_unlock(&vp->v_pollinfo->vpi_lock);
4167 * Routine to create and manage a filesystem syncer vnode.
4169 #define sync_close ((int (*)(struct vop_close_args *))nullop)
4170 static int sync_fsync(struct vop_fsync_args *);
4171 static int sync_inactive(struct vop_inactive_args *);
4172 static int sync_reclaim(struct vop_reclaim_args *);
4174 static struct vop_vector sync_vnodeops = {
4175 .vop_bypass = VOP_EOPNOTSUPP,
4176 .vop_close = sync_close, /* close */
4177 .vop_fsync = sync_fsync, /* fsync */
4178 .vop_inactive = sync_inactive, /* inactive */
4179 .vop_reclaim = sync_reclaim, /* reclaim */
4180 .vop_lock1 = vop_stdlock, /* lock */
4181 .vop_unlock = vop_stdunlock, /* unlock */
4182 .vop_islocked = vop_stdislocked, /* islocked */
4186 * Create a new filesystem syncer vnode for the specified mount point.
4189 vfs_allocate_syncvnode(struct mount *mp)
4193 static long start, incr, next;
4196 /* Allocate a new vnode */
4197 error = getnewvnode("syncer", mp, &sync_vnodeops, &vp);
4199 panic("vfs_allocate_syncvnode: getnewvnode() failed");
4201 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
4202 vp->v_vflag |= VV_FORCEINSMQ;
4203 error = insmntque(vp, mp);
4205 panic("vfs_allocate_syncvnode: insmntque() failed");
4206 vp->v_vflag &= ~VV_FORCEINSMQ;
4209 * Place the vnode onto the syncer worklist. We attempt to
4210 * scatter them about on the list so that they will go off
4211 * at evenly distributed times even if all the filesystems
4212 * are mounted at once.
4215 if (next == 0 || next > syncer_maxdelay) {
4219 start = syncer_maxdelay / 2;
4220 incr = syncer_maxdelay;
4226 vn_syncer_add_to_worklist(bo, syncdelay > 0 ? next % syncdelay : 0);
4227 /* XXX - vn_syncer_add_to_worklist() also grabs and drops sync_mtx. */
4228 mtx_lock(&sync_mtx);
4230 if (mp->mnt_syncer == NULL) {
4231 mp->mnt_syncer = vp;
4234 mtx_unlock(&sync_mtx);
4237 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
4244 vfs_deallocate_syncvnode(struct mount *mp)
4248 mtx_lock(&sync_mtx);
4249 vp = mp->mnt_syncer;
4251 mp->mnt_syncer = NULL;
4252 mtx_unlock(&sync_mtx);
4258 * Do a lazy sync of the filesystem.
4261 sync_fsync(struct vop_fsync_args *ap)
4263 struct vnode *syncvp = ap->a_vp;
4264 struct mount *mp = syncvp->v_mount;
4269 * We only need to do something if this is a lazy evaluation.
4271 if (ap->a_waitfor != MNT_LAZY)
4275 * Move ourselves to the back of the sync list.
4277 bo = &syncvp->v_bufobj;
4279 vn_syncer_add_to_worklist(bo, syncdelay);
4283 * Walk the list of vnodes pushing all that are dirty and
4284 * not already on the sync list.
4286 if (vfs_busy(mp, MBF_NOWAIT) != 0)
4288 if (vn_start_write(NULL, &mp, V_NOWAIT) != 0) {
4292 save = curthread_pflags_set(TDP_SYNCIO);
4293 vfs_msync(mp, MNT_NOWAIT);
4294 error = VFS_SYNC(mp, MNT_LAZY);
4295 curthread_pflags_restore(save);
4296 vn_finished_write(mp);
4302 * The syncer vnode is no referenced.
4305 sync_inactive(struct vop_inactive_args *ap)
4313 * The syncer vnode is no longer needed and is being decommissioned.
4315 * Modifications to the worklist must be protected by sync_mtx.
4318 sync_reclaim(struct vop_reclaim_args *ap)
4320 struct vnode *vp = ap->a_vp;
4325 mtx_lock(&sync_mtx);
4326 if (vp->v_mount->mnt_syncer == vp)
4327 vp->v_mount->mnt_syncer = NULL;
4328 if (bo->bo_flag & BO_ONWORKLST) {
4329 LIST_REMOVE(bo, bo_synclist);
4330 syncer_worklist_len--;
4332 bo->bo_flag &= ~BO_ONWORKLST;
4334 mtx_unlock(&sync_mtx);
4341 * Check if vnode represents a disk device
4344 vn_isdisk(struct vnode *vp, int *errp)
4348 if (vp->v_type != VCHR) {
4354 if (vp->v_rdev == NULL)
4356 else if (vp->v_rdev->si_devsw == NULL)
4358 else if (!(vp->v_rdev->si_devsw->d_flags & D_DISK))
4364 return (error == 0);
4368 * Common filesystem object access control check routine. Accepts a
4369 * vnode's type, "mode", uid and gid, requested access mode, credentials,
4370 * and optional call-by-reference privused argument allowing vaccess()
4371 * to indicate to the caller whether privilege was used to satisfy the
4372 * request (obsoleted). Returns 0 on success, or an errno on failure.
4375 vaccess(enum vtype type, mode_t file_mode, uid_t file_uid, gid_t file_gid,
4376 accmode_t accmode, struct ucred *cred, int *privused)
4378 accmode_t dac_granted;
4379 accmode_t priv_granted;
4381 KASSERT((accmode & ~(VEXEC | VWRITE | VREAD | VADMIN | VAPPEND)) == 0,
4382 ("invalid bit in accmode"));
4383 KASSERT((accmode & VAPPEND) == 0 || (accmode & VWRITE),
4384 ("VAPPEND without VWRITE"));
4387 * Look for a normal, non-privileged way to access the file/directory
4388 * as requested. If it exists, go with that.
4391 if (privused != NULL)
4396 /* Check the owner. */
4397 if (cred->cr_uid == file_uid) {
4398 dac_granted |= VADMIN;
4399 if (file_mode & S_IXUSR)
4400 dac_granted |= VEXEC;
4401 if (file_mode & S_IRUSR)
4402 dac_granted |= VREAD;
4403 if (file_mode & S_IWUSR)
4404 dac_granted |= (VWRITE | VAPPEND);
4406 if ((accmode & dac_granted) == accmode)
4412 /* Otherwise, check the groups (first match) */
4413 if (groupmember(file_gid, cred)) {
4414 if (file_mode & S_IXGRP)
4415 dac_granted |= VEXEC;
4416 if (file_mode & S_IRGRP)
4417 dac_granted |= VREAD;
4418 if (file_mode & S_IWGRP)
4419 dac_granted |= (VWRITE | VAPPEND);
4421 if ((accmode & dac_granted) == accmode)
4427 /* Otherwise, check everyone else. */
4428 if (file_mode & S_IXOTH)
4429 dac_granted |= VEXEC;
4430 if (file_mode & S_IROTH)
4431 dac_granted |= VREAD;
4432 if (file_mode & S_IWOTH)
4433 dac_granted |= (VWRITE | VAPPEND);
4434 if ((accmode & dac_granted) == accmode)
4439 * Build a privilege mask to determine if the set of privileges
4440 * satisfies the requirements when combined with the granted mask
4441 * from above. For each privilege, if the privilege is required,
4442 * bitwise or the request type onto the priv_granted mask.
4448 * For directories, use PRIV_VFS_LOOKUP to satisfy VEXEC
4449 * requests, instead of PRIV_VFS_EXEC.
4451 if ((accmode & VEXEC) && ((dac_granted & VEXEC) == 0) &&
4452 !priv_check_cred(cred, PRIV_VFS_LOOKUP, 0))
4453 priv_granted |= VEXEC;
4456 * Ensure that at least one execute bit is on. Otherwise,
4457 * a privileged user will always succeed, and we don't want
4458 * this to happen unless the file really is executable.
4460 if ((accmode & VEXEC) && ((dac_granted & VEXEC) == 0) &&
4461 (file_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0 &&
4462 !priv_check_cred(cred, PRIV_VFS_EXEC, 0))
4463 priv_granted |= VEXEC;
4466 if ((accmode & VREAD) && ((dac_granted & VREAD) == 0) &&
4467 !priv_check_cred(cred, PRIV_VFS_READ, 0))
4468 priv_granted |= VREAD;
4470 if ((accmode & VWRITE) && ((dac_granted & VWRITE) == 0) &&
4471 !priv_check_cred(cred, PRIV_VFS_WRITE, 0))
4472 priv_granted |= (VWRITE | VAPPEND);
4474 if ((accmode & VADMIN) && ((dac_granted & VADMIN) == 0) &&
4475 !priv_check_cred(cred, PRIV_VFS_ADMIN, 0))
4476 priv_granted |= VADMIN;
4478 if ((accmode & (priv_granted | dac_granted)) == accmode) {
4479 /* XXX audit: privilege used */
4480 if (privused != NULL)
4485 return ((accmode & VADMIN) ? EPERM : EACCES);
4489 * Credential check based on process requesting service, and per-attribute
4493 extattr_check_cred(struct vnode *vp, int attrnamespace, struct ucred *cred,
4494 struct thread *td, accmode_t accmode)
4498 * Kernel-invoked always succeeds.
4504 * Do not allow privileged processes in jail to directly manipulate
4505 * system attributes.
4507 switch (attrnamespace) {
4508 case EXTATTR_NAMESPACE_SYSTEM:
4509 /* Potentially should be: return (EPERM); */
4510 return (priv_check_cred(cred, PRIV_VFS_EXTATTR_SYSTEM, 0));
4511 case EXTATTR_NAMESPACE_USER:
4512 return (VOP_ACCESS(vp, accmode, cred, td));
4518 #ifdef DEBUG_VFS_LOCKS
4520 * This only exists to suppress warnings from unlocked specfs accesses. It is
4521 * no longer ok to have an unlocked VFS.
4523 #define IGNORE_LOCK(vp) (panicstr != NULL || (vp) == NULL || \
4524 (vp)->v_type == VCHR || (vp)->v_type == VBAD)
4526 int vfs_badlock_ddb = 1; /* Drop into debugger on violation. */
4527 SYSCTL_INT(_debug, OID_AUTO, vfs_badlock_ddb, CTLFLAG_RW, &vfs_badlock_ddb, 0,
4528 "Drop into debugger on lock violation");
4530 int vfs_badlock_mutex = 1; /* Check for interlock across VOPs. */
4531 SYSCTL_INT(_debug, OID_AUTO, vfs_badlock_mutex, CTLFLAG_RW, &vfs_badlock_mutex,
4532 0, "Check for interlock across VOPs");
4534 int vfs_badlock_print = 1; /* Print lock violations. */
4535 SYSCTL_INT(_debug, OID_AUTO, vfs_badlock_print, CTLFLAG_RW, &vfs_badlock_print,
4536 0, "Print lock violations");
4538 int vfs_badlock_vnode = 1; /* Print vnode details on lock violations. */
4539 SYSCTL_INT(_debug, OID_AUTO, vfs_badlock_vnode, CTLFLAG_RW, &vfs_badlock_vnode,
4540 0, "Print vnode details on lock violations");
4543 int vfs_badlock_backtrace = 1; /* Print backtrace at lock violations. */
4544 SYSCTL_INT(_debug, OID_AUTO, vfs_badlock_backtrace, CTLFLAG_RW,
4545 &vfs_badlock_backtrace, 0, "Print backtrace at lock violations");
4549 vfs_badlock(const char *msg, const char *str, struct vnode *vp)
4553 if (vfs_badlock_backtrace)
4556 if (vfs_badlock_vnode)
4557 vn_printf(vp, "vnode ");
4558 if (vfs_badlock_print)
4559 printf("%s: %p %s\n", str, (void *)vp, msg);
4560 if (vfs_badlock_ddb)
4561 kdb_enter(KDB_WHY_VFSLOCK, "lock violation");
4565 assert_vi_locked(struct vnode *vp, const char *str)
4568 if (vfs_badlock_mutex && !mtx_owned(VI_MTX(vp)))
4569 vfs_badlock("interlock is not locked but should be", str, vp);
4573 assert_vi_unlocked(struct vnode *vp, const char *str)
4576 if (vfs_badlock_mutex && mtx_owned(VI_MTX(vp)))
4577 vfs_badlock("interlock is locked but should not be", str, vp);
4581 assert_vop_locked(struct vnode *vp, const char *str)
4585 if (!IGNORE_LOCK(vp)) {
4586 locked = VOP_ISLOCKED(vp);
4587 if (locked == 0 || locked == LK_EXCLOTHER)
4588 vfs_badlock("is not locked but should be", str, vp);
4593 assert_vop_unlocked(struct vnode *vp, const char *str)
4596 if (!IGNORE_LOCK(vp) && VOP_ISLOCKED(vp) == LK_EXCLUSIVE)
4597 vfs_badlock("is locked but should not be", str, vp);
4601 assert_vop_elocked(struct vnode *vp, const char *str)
4604 if (!IGNORE_LOCK(vp) && VOP_ISLOCKED(vp) != LK_EXCLUSIVE)
4605 vfs_badlock("is not exclusive locked but should be", str, vp);
4607 #endif /* DEBUG_VFS_LOCKS */
4610 vop_rename_fail(struct vop_rename_args *ap)
4613 if (ap->a_tvp != NULL)
4615 if (ap->a_tdvp == ap->a_tvp)
4624 vop_rename_pre(void *ap)
4626 struct vop_rename_args *a = ap;
4628 #ifdef DEBUG_VFS_LOCKS
4630 ASSERT_VI_UNLOCKED(a->a_tvp, "VOP_RENAME");
4631 ASSERT_VI_UNLOCKED(a->a_tdvp, "VOP_RENAME");
4632 ASSERT_VI_UNLOCKED(a->a_fvp, "VOP_RENAME");
4633 ASSERT_VI_UNLOCKED(a->a_fdvp, "VOP_RENAME");
4635 /* Check the source (from). */
4636 if (a->a_tdvp->v_vnlock != a->a_fdvp->v_vnlock &&
4637 (a->a_tvp == NULL || a->a_tvp->v_vnlock != a->a_fdvp->v_vnlock))
4638 ASSERT_VOP_UNLOCKED(a->a_fdvp, "vop_rename: fdvp locked");
4639 if (a->a_tvp == NULL || a->a_tvp->v_vnlock != a->a_fvp->v_vnlock)
4640 ASSERT_VOP_UNLOCKED(a->a_fvp, "vop_rename: fvp locked");
4642 /* Check the target. */
4644 ASSERT_VOP_LOCKED(a->a_tvp, "vop_rename: tvp not locked");
4645 ASSERT_VOP_LOCKED(a->a_tdvp, "vop_rename: tdvp not locked");
4647 if (a->a_tdvp != a->a_fdvp)
4649 if (a->a_tvp != a->a_fvp)
4656 #ifdef DEBUG_VFS_LOCKS
4658 vop_strategy_pre(void *ap)
4660 struct vop_strategy_args *a;
4667 * Cluster ops lock their component buffers but not the IO container.
4669 if ((bp->b_flags & B_CLUSTER) != 0)
4672 if (panicstr == NULL && !BUF_ISLOCKED(bp)) {
4673 if (vfs_badlock_print)
4675 "VOP_STRATEGY: bp is not locked but should be\n");
4676 if (vfs_badlock_ddb)
4677 kdb_enter(KDB_WHY_VFSLOCK, "lock violation");
4682 vop_lock_pre(void *ap)
4684 struct vop_lock1_args *a = ap;
4686 if ((a->a_flags & LK_INTERLOCK) == 0)
4687 ASSERT_VI_UNLOCKED(a->a_vp, "VOP_LOCK");
4689 ASSERT_VI_LOCKED(a->a_vp, "VOP_LOCK");
4693 vop_lock_post(void *ap, int rc)
4695 struct vop_lock1_args *a = ap;
4697 ASSERT_VI_UNLOCKED(a->a_vp, "VOP_LOCK");
4698 if (rc == 0 && (a->a_flags & LK_EXCLOTHER) == 0)
4699 ASSERT_VOP_LOCKED(a->a_vp, "VOP_LOCK");
4703 vop_unlock_pre(void *ap)
4705 struct vop_unlock_args *a = ap;
4707 if (a->a_flags & LK_INTERLOCK)
4708 ASSERT_VI_LOCKED(a->a_vp, "VOP_UNLOCK");
4709 ASSERT_VOP_LOCKED(a->a_vp, "VOP_UNLOCK");
4713 vop_unlock_post(void *ap, int rc)
4715 struct vop_unlock_args *a = ap;
4717 if (a->a_flags & LK_INTERLOCK)
4718 ASSERT_VI_UNLOCKED(a->a_vp, "VOP_UNLOCK");
4723 vop_create_post(void *ap, int rc)
4725 struct vop_create_args *a = ap;
4728 VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE);
4732 vop_deleteextattr_post(void *ap, int rc)
4734 struct vop_deleteextattr_args *a = ap;
4737 VFS_KNOTE_LOCKED(a->a_vp, NOTE_ATTRIB);
4741 vop_link_post(void *ap, int rc)
4743 struct vop_link_args *a = ap;
4746 VFS_KNOTE_LOCKED(a->a_vp, NOTE_LINK);
4747 VFS_KNOTE_LOCKED(a->a_tdvp, NOTE_WRITE);
4752 vop_mkdir_post(void *ap, int rc)
4754 struct vop_mkdir_args *a = ap;
4757 VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE | NOTE_LINK);
4761 vop_mknod_post(void *ap, int rc)
4763 struct vop_mknod_args *a = ap;
4766 VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE);
4770 vop_reclaim_post(void *ap, int rc)
4772 struct vop_reclaim_args *a = ap;
4775 VFS_KNOTE_LOCKED(a->a_vp, NOTE_REVOKE);
4779 vop_remove_post(void *ap, int rc)
4781 struct vop_remove_args *a = ap;
4784 VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE);
4785 VFS_KNOTE_LOCKED(a->a_vp, NOTE_DELETE);
4790 vop_rename_post(void *ap, int rc)
4792 struct vop_rename_args *a = ap;
4797 if (a->a_fdvp == a->a_tdvp) {
4798 if (a->a_tvp != NULL && a->a_tvp->v_type == VDIR)
4800 VFS_KNOTE_UNLOCKED(a->a_fdvp, hint);
4801 VFS_KNOTE_UNLOCKED(a->a_tdvp, hint);
4803 hint |= NOTE_EXTEND;
4804 if (a->a_fvp->v_type == VDIR)
4806 VFS_KNOTE_UNLOCKED(a->a_fdvp, hint);
4808 if (a->a_fvp->v_type == VDIR && a->a_tvp != NULL &&
4809 a->a_tvp->v_type == VDIR)
4811 VFS_KNOTE_UNLOCKED(a->a_tdvp, hint);
4814 VFS_KNOTE_UNLOCKED(a->a_fvp, NOTE_RENAME);
4816 VFS_KNOTE_UNLOCKED(a->a_tvp, NOTE_DELETE);
4818 if (a->a_tdvp != a->a_fdvp)
4820 if (a->a_tvp != a->a_fvp)
4828 vop_rmdir_post(void *ap, int rc)
4830 struct vop_rmdir_args *a = ap;
4833 VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE | NOTE_LINK);
4834 VFS_KNOTE_LOCKED(a->a_vp, NOTE_DELETE);
4839 vop_setattr_post(void *ap, int rc)
4841 struct vop_setattr_args *a = ap;
4844 VFS_KNOTE_LOCKED(a->a_vp, NOTE_ATTRIB);
4848 vop_setextattr_post(void *ap, int rc)
4850 struct vop_setextattr_args *a = ap;
4853 VFS_KNOTE_LOCKED(a->a_vp, NOTE_ATTRIB);
4857 vop_symlink_post(void *ap, int rc)
4859 struct vop_symlink_args *a = ap;
4862 VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE);
4866 vop_open_post(void *ap, int rc)
4868 struct vop_open_args *a = ap;
4871 VFS_KNOTE_LOCKED(a->a_vp, NOTE_OPEN);
4875 vop_close_post(void *ap, int rc)
4877 struct vop_close_args *a = ap;
4879 if (!rc && (a->a_cred != NOCRED || /* filter out revokes */
4880 (a->a_vp->v_iflag & VI_DOOMED) == 0)) {
4881 VFS_KNOTE_LOCKED(a->a_vp, (a->a_fflag & FWRITE) != 0 ?
4882 NOTE_CLOSE_WRITE : NOTE_CLOSE);
4887 vop_read_post(void *ap, int rc)
4889 struct vop_read_args *a = ap;
4892 VFS_KNOTE_LOCKED(a->a_vp, NOTE_READ);
4896 vop_readdir_post(void *ap, int rc)
4898 struct vop_readdir_args *a = ap;
4901 VFS_KNOTE_LOCKED(a->a_vp, NOTE_READ);
4904 static struct knlist fs_knlist;
4907 vfs_event_init(void *arg)
4909 knlist_init_mtx(&fs_knlist, NULL);
4911 /* XXX - correct order? */
4912 SYSINIT(vfs_knlist, SI_SUB_VFS, SI_ORDER_ANY, vfs_event_init, NULL);
4915 vfs_event_signal(fsid_t *fsid, uint32_t event, intptr_t data __unused)
4918 KNOTE_UNLOCKED(&fs_knlist, event);
4921 static int filt_fsattach(struct knote *kn);
4922 static void filt_fsdetach(struct knote *kn);
4923 static int filt_fsevent(struct knote *kn, long hint);
4925 struct filterops fs_filtops = {
4927 .f_attach = filt_fsattach,
4928 .f_detach = filt_fsdetach,
4929 .f_event = filt_fsevent
4933 filt_fsattach(struct knote *kn)
4936 kn->kn_flags |= EV_CLEAR;
4937 knlist_add(&fs_knlist, kn, 0);
4942 filt_fsdetach(struct knote *kn)
4945 knlist_remove(&fs_knlist, kn, 0);
4949 filt_fsevent(struct knote *kn, long hint)
4952 kn->kn_fflags |= hint;
4953 return (kn->kn_fflags != 0);
4957 sysctl_vfs_ctl(SYSCTL_HANDLER_ARGS)
4963 error = SYSCTL_IN(req, &vc, sizeof(vc));
4966 if (vc.vc_vers != VFS_CTL_VERS1)
4968 mp = vfs_getvfs(&vc.vc_fsid);
4971 /* ensure that a specific sysctl goes to the right filesystem. */
4972 if (strcmp(vc.vc_fstypename, "*") != 0 &&
4973 strcmp(vc.vc_fstypename, mp->mnt_vfc->vfc_name) != 0) {
4977 VCTLTOREQ(&vc, req);
4978 error = VFS_SYSCTL(mp, vc.vc_op, req);
4983 SYSCTL_PROC(_vfs, OID_AUTO, ctl, CTLTYPE_OPAQUE | CTLFLAG_WR,
4984 NULL, 0, sysctl_vfs_ctl, "",
4988 * Function to initialize a va_filerev field sensibly.
4989 * XXX: Wouldn't a random number make a lot more sense ??
4992 init_va_filerev(void)
4997 return (((u_quad_t)bt.sec << 32LL) | (bt.frac >> 32LL));
5000 static int filt_vfsread(struct knote *kn, long hint);
5001 static int filt_vfswrite(struct knote *kn, long hint);
5002 static int filt_vfsvnode(struct knote *kn, long hint);
5003 static void filt_vfsdetach(struct knote *kn);
5004 static struct filterops vfsread_filtops = {
5006 .f_detach = filt_vfsdetach,
5007 .f_event = filt_vfsread
5009 static struct filterops vfswrite_filtops = {
5011 .f_detach = filt_vfsdetach,
5012 .f_event = filt_vfswrite
5014 static struct filterops vfsvnode_filtops = {
5016 .f_detach = filt_vfsdetach,
5017 .f_event = filt_vfsvnode
5021 vfs_knllock(void *arg)
5023 struct vnode *vp = arg;
5025 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
5029 vfs_knlunlock(void *arg)
5031 struct vnode *vp = arg;
5037 vfs_knl_assert_locked(void *arg)
5039 #ifdef DEBUG_VFS_LOCKS
5040 struct vnode *vp = arg;
5042 ASSERT_VOP_LOCKED(vp, "vfs_knl_assert_locked");
5047 vfs_knl_assert_unlocked(void *arg)
5049 #ifdef DEBUG_VFS_LOCKS
5050 struct vnode *vp = arg;
5052 ASSERT_VOP_UNLOCKED(vp, "vfs_knl_assert_unlocked");
5057 vfs_kqfilter(struct vop_kqfilter_args *ap)
5059 struct vnode *vp = ap->a_vp;
5060 struct knote *kn = ap->a_kn;
5063 switch (kn->kn_filter) {
5065 kn->kn_fop = &vfsread_filtops;
5068 kn->kn_fop = &vfswrite_filtops;
5071 kn->kn_fop = &vfsvnode_filtops;
5077 kn->kn_hook = (caddr_t)vp;
5080 if (vp->v_pollinfo == NULL)
5082 knl = &vp->v_pollinfo->vpi_selinfo.si_note;
5084 knlist_add(knl, kn, 0);
5090 * Detach knote from vnode
5093 filt_vfsdetach(struct knote *kn)
5095 struct vnode *vp = (struct vnode *)kn->kn_hook;
5097 KASSERT(vp->v_pollinfo != NULL, ("Missing v_pollinfo"));
5098 knlist_remove(&vp->v_pollinfo->vpi_selinfo.si_note, kn, 0);
5104 filt_vfsread(struct knote *kn, long hint)
5106 struct vnode *vp = (struct vnode *)kn->kn_hook;
5111 * filesystem is gone, so set the EOF flag and schedule
5112 * the knote for deletion.
5114 if (hint == NOTE_REVOKE || (hint == 0 && vp->v_type == VBAD)) {
5116 kn->kn_flags |= (EV_EOF | EV_ONESHOT);
5121 if (VOP_GETATTR(vp, &va, curthread->td_ucred))
5125 kn->kn_data = va.va_size - kn->kn_fp->f_offset;
5126 res = (kn->kn_sfflags & NOTE_FILE_POLL) != 0 || kn->kn_data != 0;
5133 filt_vfswrite(struct knote *kn, long hint)
5135 struct vnode *vp = (struct vnode *)kn->kn_hook;
5140 * filesystem is gone, so set the EOF flag and schedule
5141 * the knote for deletion.
5143 if (hint == NOTE_REVOKE || (hint == 0 && vp->v_type == VBAD))
5144 kn->kn_flags |= (EV_EOF | EV_ONESHOT);
5152 filt_vfsvnode(struct knote *kn, long hint)
5154 struct vnode *vp = (struct vnode *)kn->kn_hook;
5158 if (kn->kn_sfflags & hint)
5159 kn->kn_fflags |= hint;
5160 if (hint == NOTE_REVOKE || (hint == 0 && vp->v_type == VBAD)) {
5161 kn->kn_flags |= EV_EOF;
5165 res = (kn->kn_fflags != 0);
5171 vfs_read_dirent(struct vop_readdir_args *ap, struct dirent *dp, off_t off)
5175 if (dp->d_reclen > ap->a_uio->uio_resid)
5176 return (ENAMETOOLONG);
5177 error = uiomove(dp, dp->d_reclen, ap->a_uio);
5179 if (ap->a_ncookies != NULL) {
5180 if (ap->a_cookies != NULL)
5181 free(ap->a_cookies, M_TEMP);
5182 ap->a_cookies = NULL;
5183 *ap->a_ncookies = 0;
5187 if (ap->a_ncookies == NULL)
5190 KASSERT(ap->a_cookies,
5191 ("NULL ap->a_cookies value with non-NULL ap->a_ncookies!"));
5193 *ap->a_cookies = realloc(*ap->a_cookies,
5194 (*ap->a_ncookies + 1) * sizeof(u_long), M_TEMP, M_WAITOK | M_ZERO);
5195 (*ap->a_cookies)[*ap->a_ncookies] = off;
5196 *ap->a_ncookies += 1;
5201 * Mark for update the access time of the file if the filesystem
5202 * supports VOP_MARKATIME. This functionality is used by execve and
5203 * mmap, so we want to avoid the I/O implied by directly setting
5204 * va_atime for the sake of efficiency.
5207 vfs_mark_atime(struct vnode *vp, struct ucred *cred)
5212 ASSERT_VOP_LOCKED(vp, "vfs_mark_atime");
5213 if (mp != NULL && (mp->mnt_flag & (MNT_NOATIME | MNT_RDONLY)) == 0)
5214 (void)VOP_MARKATIME(vp);
5218 * The purpose of this routine is to remove granularity from accmode_t,
5219 * reducing it into standard unix access bits - VEXEC, VREAD, VWRITE,
5220 * VADMIN and VAPPEND.
5222 * If it returns 0, the caller is supposed to continue with the usual
5223 * access checks using 'accmode' as modified by this routine. If it
5224 * returns nonzero value, the caller is supposed to return that value
5227 * Note that after this routine runs, accmode may be zero.
5230 vfs_unixify_accmode(accmode_t *accmode)
5233 * There is no way to specify explicit "deny" rule using
5234 * file mode or POSIX.1e ACLs.
5236 if (*accmode & VEXPLICIT_DENY) {
5242 * None of these can be translated into usual access bits.
5243 * Also, the common case for NFSv4 ACLs is to not contain
5244 * either of these bits. Caller should check for VWRITE
5245 * on the containing directory instead.
5247 if (*accmode & (VDELETE_CHILD | VDELETE))
5250 if (*accmode & VADMIN_PERMS) {
5251 *accmode &= ~VADMIN_PERMS;
5256 * There is no way to deny VREAD_ATTRIBUTES, VREAD_ACL
5257 * or VSYNCHRONIZE using file mode or POSIX.1e ACL.
5259 *accmode &= ~(VSTAT_PERMS | VSYNCHRONIZE);
5265 * These are helper functions for filesystems to traverse all
5266 * their vnodes. See MNT_VNODE_FOREACH_ALL() in sys/mount.h.
5268 * This interface replaces MNT_VNODE_FOREACH.
5271 MALLOC_DEFINE(M_VNODE_MARKER, "vnodemarker", "vnode marker");
5274 __mnt_vnode_next_all(struct vnode **mvp, struct mount *mp)
5279 kern_yield(PRI_USER);
5281 KASSERT((*mvp)->v_mount == mp, ("marker vnode mount list mismatch"));
5282 for (vp = TAILQ_NEXT(*mvp, v_nmntvnodes); vp != NULL;
5283 vp = TAILQ_NEXT(vp, v_nmntvnodes)) {
5284 /* Allow a racy peek at VI_DOOMED to save a lock acquisition. */
5285 if (vp->v_type == VMARKER || (vp->v_iflag & VI_DOOMED) != 0)
5288 if ((vp->v_iflag & VI_DOOMED) != 0) {
5295 __mnt_vnode_markerfree_all(mvp, mp);
5296 /* MNT_IUNLOCK(mp); -- done in above function */
5297 mtx_assert(MNT_MTX(mp), MA_NOTOWNED);
5300 TAILQ_REMOVE(&mp->mnt_nvnodelist, *mvp, v_nmntvnodes);
5301 TAILQ_INSERT_AFTER(&mp->mnt_nvnodelist, vp, *mvp, v_nmntvnodes);
5307 __mnt_vnode_first_all(struct vnode **mvp, struct mount *mp)
5311 *mvp = malloc(sizeof(struct vnode), M_VNODE_MARKER, M_WAITOK | M_ZERO);
5314 (*mvp)->v_mount = mp;
5315 (*mvp)->v_type = VMARKER;
5317 TAILQ_FOREACH(vp, &mp->mnt_nvnodelist, v_nmntvnodes) {
5318 /* Allow a racy peek at VI_DOOMED to save a lock acquisition. */
5319 if (vp->v_type == VMARKER || (vp->v_iflag & VI_DOOMED) != 0)
5322 if ((vp->v_iflag & VI_DOOMED) != 0) {
5331 free(*mvp, M_VNODE_MARKER);
5335 TAILQ_INSERT_AFTER(&mp->mnt_nvnodelist, vp, *mvp, v_nmntvnodes);
5341 __mnt_vnode_markerfree_all(struct vnode **mvp, struct mount *mp)
5349 mtx_assert(MNT_MTX(mp), MA_OWNED);
5351 KASSERT((*mvp)->v_mount == mp, ("marker vnode mount list mismatch"));
5352 TAILQ_REMOVE(&mp->mnt_nvnodelist, *mvp, v_nmntvnodes);
5355 free(*mvp, M_VNODE_MARKER);
5360 * These are helper functions for filesystems to traverse their
5361 * active vnodes. See MNT_VNODE_FOREACH_ACTIVE() in sys/mount.h
5364 mnt_vnode_markerfree_active(struct vnode **mvp, struct mount *mp)
5367 KASSERT((*mvp)->v_mount == mp, ("marker vnode mount list mismatch"));
5372 free(*mvp, M_VNODE_MARKER);
5377 * Relock the mp mount vnode list lock with the vp vnode interlock in the
5378 * conventional lock order during mnt_vnode_next_active iteration.
5380 * On entry, the mount vnode list lock is held and the vnode interlock is not.
5381 * The list lock is dropped and reacquired. On success, both locks are held.
5382 * On failure, the mount vnode list lock is held but the vnode interlock is
5383 * not, and the procedure may have yielded.
5386 mnt_vnode_next_active_relock(struct vnode *mvp, struct mount *mp,
5389 const struct vnode *tmp;
5392 VNASSERT(mvp->v_mount == mp && mvp->v_type == VMARKER &&
5393 TAILQ_NEXT(mvp, v_actfreelist) != NULL, mvp,
5394 ("%s: bad marker", __func__));
5395 VNASSERT(vp->v_mount == mp && vp->v_type != VMARKER, vp,
5396 ("%s: inappropriate vnode", __func__));
5397 ASSERT_VI_UNLOCKED(vp, __func__);
5398 mtx_assert(&mp->mnt_listmtx, MA_OWNED);
5402 TAILQ_REMOVE(&mp->mnt_activevnodelist, mvp, v_actfreelist);
5403 TAILQ_INSERT_BEFORE(vp, mvp, v_actfreelist);
5406 * Use a hold to prevent vp from disappearing while the mount vnode
5407 * list lock is dropped and reacquired. Normally a hold would be
5408 * acquired with vhold(), but that might try to acquire the vnode
5409 * interlock, which would be a LOR with the mount vnode list lock.
5411 held = refcount_acquire_if_not_zero(&vp->v_holdcnt);
5412 mtx_unlock(&mp->mnt_listmtx);
5416 if (!refcount_release_if_not_last(&vp->v_holdcnt)) {
5420 mtx_lock(&mp->mnt_listmtx);
5423 * Determine whether the vnode is still the next one after the marker,
5424 * excepting any other markers. If the vnode has not been doomed by
5425 * vgone() then the hold should have ensured that it remained on the
5426 * active list. If it has been doomed but is still on the active list,
5427 * don't abort, but rather skip over it (avoid spinning on doomed
5432 tmp = TAILQ_NEXT(tmp, v_actfreelist);
5433 } while (tmp != NULL && tmp->v_type == VMARKER);
5435 mtx_unlock(&mp->mnt_listmtx);
5444 mtx_lock(&mp->mnt_listmtx);
5447 ASSERT_VI_LOCKED(vp, __func__);
5449 ASSERT_VI_UNLOCKED(vp, __func__);
5450 mtx_assert(&mp->mnt_listmtx, MA_OWNED);
5454 static struct vnode *
5455 mnt_vnode_next_active(struct vnode **mvp, struct mount *mp)
5457 struct vnode *vp, *nvp;
5459 mtx_assert(&mp->mnt_listmtx, MA_OWNED);
5460 KASSERT((*mvp)->v_mount == mp, ("marker vnode mount list mismatch"));
5462 vp = TAILQ_NEXT(*mvp, v_actfreelist);
5463 while (vp != NULL) {
5464 if (vp->v_type == VMARKER) {
5465 vp = TAILQ_NEXT(vp, v_actfreelist);
5469 * Try-lock because this is the wrong lock order. If that does
5470 * not succeed, drop the mount vnode list lock and try to
5471 * reacquire it and the vnode interlock in the right order.
5473 if (!VI_TRYLOCK(vp) &&
5474 !mnt_vnode_next_active_relock(*mvp, mp, vp))
5476 KASSERT(vp->v_type != VMARKER, ("locked marker %p", vp));
5477 KASSERT(vp->v_mount == mp || vp->v_mount == NULL,
5478 ("alien vnode on the active list %p %p", vp, mp));
5479 if (vp->v_mount == mp && (vp->v_iflag & VI_DOOMED) == 0)
5481 nvp = TAILQ_NEXT(vp, v_actfreelist);
5485 TAILQ_REMOVE(&mp->mnt_activevnodelist, *mvp, v_actfreelist);
5487 /* Check if we are done */
5489 mtx_unlock(&mp->mnt_listmtx);
5490 mnt_vnode_markerfree_active(mvp, mp);
5493 TAILQ_INSERT_AFTER(&mp->mnt_activevnodelist, vp, *mvp, v_actfreelist);
5494 mtx_unlock(&mp->mnt_listmtx);
5495 ASSERT_VI_LOCKED(vp, "active iter");
5496 KASSERT((vp->v_iflag & VI_ACTIVE) != 0, ("Non-active vp %p", vp));
5501 __mnt_vnode_next_active(struct vnode **mvp, struct mount *mp)
5505 kern_yield(PRI_USER);
5506 mtx_lock(&mp->mnt_listmtx);
5507 return (mnt_vnode_next_active(mvp, mp));
5511 __mnt_vnode_first_active(struct vnode **mvp, struct mount *mp)
5515 *mvp = malloc(sizeof(struct vnode), M_VNODE_MARKER, M_WAITOK | M_ZERO);
5519 (*mvp)->v_type = VMARKER;
5520 (*mvp)->v_mount = mp;
5522 mtx_lock(&mp->mnt_listmtx);
5523 vp = TAILQ_FIRST(&mp->mnt_activevnodelist);
5525 mtx_unlock(&mp->mnt_listmtx);
5526 mnt_vnode_markerfree_active(mvp, mp);
5529 TAILQ_INSERT_BEFORE(vp, *mvp, v_actfreelist);
5530 return (mnt_vnode_next_active(mvp, mp));
5534 __mnt_vnode_markerfree_active(struct vnode **mvp, struct mount *mp)
5540 mtx_lock(&mp->mnt_listmtx);
5541 TAILQ_REMOVE(&mp->mnt_activevnodelist, *mvp, v_actfreelist);
5542 mtx_unlock(&mp->mnt_listmtx);
5543 mnt_vnode_markerfree_active(mvp, mp);