41 #include <sys/cdefs.h>
44 #include "opt_compat.h"
46 #include "opt_watchdog.h"
48 #include <sys/param.h>
49 #include <sys/systm.h>
52 #include <sys/condvar.h>
54 #include <sys/dirent.h>
55 #include <sys/event.h>
56 #include <sys/eventhandler.h>
57 #include <sys/extattr.h>
59 #include <sys/fcntl.h>
62 #include <sys/kernel.h>
63 #include <sys/kthread.h>
64 #include <sys/lockf.h>
65 #include <sys/malloc.h>
66 #include <sys/mount.h>
67 #include <sys/namei.h>
69 #include <sys/reboot.h>
70 #include <sys/sched.h>
71 #include <sys/sleepqueue.h>
74 #include <sys/sysctl.h>
75 #include <sys/syslog.h>
76 #include <sys/vmmeter.h>
77 #include <sys/vnode.h>
78 #include <sys/watchdog.h>
80 #include <machine/stdarg.h>
82 #include <security/mac/mac_framework.h>
85 #include <vm/vm_object.h>
86 #include <vm/vm_extern.h>
88 #include <vm/vm_map.h>
89 #include <vm/vm_page.h>
90 #include <vm/vm_kern.h>
101 static int flushbuflist(
struct bufv *bufv,
int flags,
struct bufobj *bo,
102 int slpflag,
int slptimeo);
110 static void vgonel(
struct vnode *);
124 "Number of vnodes in existence");
128 0,
"Number of vnodes created by getnewvnode");
135 VNON, VFIFO, VCHR, VNON, VDIR, VNON, VBLK, VNON,
136 VREG, VNON, VLNK, VNON, VSOCK, VNON, VNON, VBAD,
139 0, S_IFREG, S_IFDIR, S_IFBLK, S_IFCHR, S_IFLNK,
140 S_IFSOCK, S_IFIFO, S_IFMT, S_IFMT
153 static u_long wantfreevnodes;
154 SYSCTL_ULONG(_vfs, OID_AUTO, wantfreevnodes, CTLFLAG_RW, &wantfreevnodes, 0, "");
156 static u_long freevnodes;
157 SYSCTL_ULONG(_vfs, OID_AUTO, freevnodes, CTLFLAG_RD, &freevnodes, 0,
158 "Number of vnodes in the
free list");
160 static
int vlru_allow_cache_src;
161 SYSCTL_INT(_vfs, OID_AUTO, vlru_allow_cache_src, CTLFLAG_RW,
162 &vlru_allow_cache_src, 0, "Allow vlru to reclaim source vnode");
164 static u_long recycles_count;
165 SYSCTL_ULONG(_vfs, OID_AUTO, recycles, CTLFLAG_RD, &recycles_count, 0,
166 "Number of vnodes recycled to avoid exceding kern.maxvnodes");
173 static
int reassignbufcalls;
174 SYSCTL_INT(_vfs, OID_AUTO, reassignbufcalls, CTLFLAG_RW, &reassignbufcalls, 0,
181 int nfs_mount_type = -1;
184 static struct mtx mntid_mtx;
192 static struct mtx vnode_free_list_mtx;
195 struct nfs_public nfs_pub;
198 static uma_zone_t vnode_zone;
199 static uma_zone_t vnodepoll_zone;
226 static
int syncer_delayno;
227 static
long syncer_mask;
229 static struct synclist *syncer_workitem_pending[2];
240 static struct mtx sync_mtx;
241 static struct cv sync_wakeup;
243 #define SYNCER_MAXDELAY 32
245 static int syncdelay = 30;
246 static int filedelay = 30;
247 SYSCTL_INT(_kern, OID_AUTO, filedelay, CTLFLAG_RW, &filedelay, 0,
248 "Time to delay syncing files (in seconds)");
249 static int dirdelay = 29;
250 SYSCTL_INT(_kern, OID_AUTO, dirdelay, CTLFLAG_RW, &dirdelay, 0,
251 "Time to delay syncing directories (in seconds)");
252 static int metadelay = 28;
253 SYSCTL_INT(_kern, OID_AUTO, metadelay, CTLFLAG_RW, &metadelay, 0,
254 "Time to delay syncing metadata (in seconds)");
256 static int stat_rush_requests;
257 SYSCTL_INT(_debug, OID_AUTO, rush_requests, CTLFLAG_RW, &stat_rush_requests, 0,
258 "Number of times I/O speeded up (rush requests)");
263 #define SYNCER_SHUTDOWN_SPEEDUP 4
264 static int sync_vnode_count;
265 static int syncer_worklist_len;
266 static enum { SYNCER_RUNNING, SYNCER_SHUTTING_DOWN, SYNCER_FINAL_DELAY }
277 SYSCTL_INT(_kern, KERN_MAXVNODES, maxvnodes, CTLFLAG_RW,
278 &desiredvnodes, 0,
"Maximum number of vnodes");
280 &wantfreevnodes, 0,
"Minimum number of vnodes (legacy)");
282 SYSCTL_INT(_debug, OID_AUTO, vnlru_nowhere, CTLFLAG_RW,
283 &vnlru_nowhere, 0,
"Number of times the vnlru process ran without success");
289 #define VCANRECYCLE(vp) (((vp)->v_iflag & VI_FREE) && !(vp)->v_holdcnt)
290 #define VSHOULDFREE(vp) (!((vp)->v_iflag & VI_FREE) && !(vp)->v_holdcnt)
291 #define VSHOULDBUSY(vp) (((vp)->v_iflag & VI_FREE) && (vp)->v_holdcnt)
303 #ifndef MAXVNODES_MAX
304 #define MAXVNODES_MAX (512 * (1024 * 1024 * 1024 / (int)PAGE_SIZE / 16))
310 int physvnodes, virtvnodes;
322 physvnodes =
maxproc + cnt.v_page_count / 16 + 3 * min(98304 * 4,
323 cnt.v_page_count) / 16;
324 virtvnodes =
vm_kmem_size / (7 * (
sizeof(
struct vm_object) +
325 sizeof(struct vnode)));
326 desiredvnodes = min(physvnodes, virtvnodes);
329 printf(
"Reducing kern.maxvnodes %d -> %d\n",
333 wantfreevnodes = desiredvnodes / 4;
334 mtx_init(&mntid_mtx,
"mntid", NULL, MTX_DEF);
335 TAILQ_INIT(&vnode_free_list);
336 mtx_init(&vnode_free_list_mtx,
"vnode_free_list", NULL, MTX_DEF);
337 vnode_zone = uma_zcreate(
"VNODE",
sizeof (
struct vnode), NULL, NULL,
338 NULL, NULL, UMA_ALIGN_PTR, 0);
339 vnodepoll_zone = uma_zcreate(
"VNODEPOLL",
sizeof (
struct vpollinfo),
340 NULL, NULL, NULL, NULL, UMA_ALIGN_PTR, 0);
348 syncer_maxdelay = syncer_mask + 1;
349 mtx_init(&sync_mtx,
"Syncer mtx", NULL, MTX_DEF);
350 cv_init(&sync_wakeup,
"syncer");
351 for (i = 1; i <=
sizeof(
struct vnode); i <<= 1)
398 MPASS((flags & ~MBF_MASK) == 0);
399 CTR3(KTR_VFS,
"%s: mp %p with flags %d", __func__, mp, flags);
415 while (mp->mnt_kern_flag & MNTK_UNMOUNT) {
416 if (flags & MBF_NOWAIT || mp->mnt_kern_flag & MNTK_REFEXPIRE) {
419 CTR1(KTR_VFS,
"%s: failed busying before sleeping",
423 if (flags & MBF_MNTLSTLOCK)
425 mp->mnt_kern_flag |= MNTK_MWAIT;
426 msleep(mp, MNT_MTX(mp), PVFS | PDROP,
"vfs_busy", 0);
427 if (flags & MBF_MNTLSTLOCK)
431 if (flags & MBF_MNTLSTLOCK)
445 CTR2(KTR_VFS,
"%s: mp %p", __func__, mp);
448 KASSERT(mp->mnt_lockref > 0, (
"negative mnt_lockref"));
450 if (mp->mnt_lockref == 0 && (mp->mnt_kern_flag & MNTK_DRAINING) != 0) {
451 MPASS(mp->mnt_kern_flag & MNTK_UNMOUNT);
452 CTR1(KTR_VFS,
"%s: waking up waiters", __func__);
453 mp->mnt_kern_flag &= ~MNTK_DRAINING;
467 CTR2(KTR_VFS,
"%s: fsid %p", __func__, fsid);
469 TAILQ_FOREACH(mp, &
mountlist, mnt_list) {
470 if (mp->mnt_stat.f_fsid.val[0] == fsid->val[0] &&
471 mp->mnt_stat.f_fsid.val[1] == fsid->val[1]) {
478 CTR2(KTR_VFS,
"%s: lookup failed for %p id", __func__, fsid);
479 return ((
struct mount *) 0);
495 #define FSID_CACHE_SIZE 256
496 typedef struct mount *
volatile vmp_t;
502 CTR2(KTR_VFS,
"%s: fsid %p", __func__, fsid);
503 hash = fsid->val[0] ^ fsid->val[1];
507 mp->mnt_stat.f_fsid.val[0] != fsid->val[0] ||
508 mp->mnt_stat.f_fsid.val[1] != fsid->val[1])
514 if (mp->mnt_stat.f_fsid.val[0] == fsid->val[0] &&
515 mp->mnt_stat.f_fsid.val[1] == fsid->val[1])
522 TAILQ_FOREACH(mp, &
mountlist, mnt_list) {
523 if (mp->mnt_stat.f_fsid.val[0] == fsid->val[0] &&
524 mp->mnt_stat.f_fsid.val[1] == fsid->val[1]) {
525 error =
vfs_busy(mp, MBF_MNTLSTLOCK);
535 CTR2(KTR_VFS,
"%s: lookup failed for %p id", __func__, fsid);
537 return ((
struct mount *) 0);
552 if (!(mp->mnt_vfc->vfc_flags & VFCF_JAIL) &&
jailed(td->td_ucred))
569 if (!(mp->mnt_vfc->vfc_flags & VFCF_DELEGADMIN) &&
570 mp->mnt_cred->cr_uid != td->td_ucred->cr_uid) {
571 if ((error =
priv_check(td, PRIV_VFS_MOUNT_OWNER)) != 0)
592 static uint16_t mntid_base;
597 CTR2(KTR_VFS,
"%s: mp %p", __func__, mp);
598 mtx_lock(&mntid_mtx);
599 mtype = mp->mnt_vfc->vfc_typenum;
600 tfsid.val[1] = mtype;
601 mtype = (mtype & 0xFF) << 24;
603 tfsid.val[0] = makedev(255,
604 mtype | ((mntid_base & 0xFF00) << 8) | (mntid_base & 0xFF));
610 mp->mnt_stat.f_fsid.val[0] = tfsid.val[0];
611 mp->mnt_stat.f_fsid.val[1] = tfsid.val[1];
612 mtx_unlock(&mntid_mtx);
626 SYSCTL_INT(_vfs, OID_AUTO, timestamp_precision, CTLFLAG_RW,
627 ×tamp_precision, 0,
"File timestamp precision (0: seconds, "
628 "1: sec + ns accurate to 1/HZ, 2: sec + ns truncated to ms, "
629 "3+: sec + ns (max. precision))");
639 switch (timestamp_precision) {
649 TIMEVAL_TO_TIMESPEC(&tv, tsp);
666 vap->va_size = VNOVAL;
667 vap->va_bytes = VNOVAL;
668 vap->va_mode = VNOVAL;
669 vap->va_nlink = VNOVAL;
670 vap->va_uid = VNOVAL;
671 vap->va_gid = VNOVAL;
672 vap->va_fsid = VNOVAL;
673 vap->va_fileid = VNOVAL;
674 vap->va_blocksize = VNOVAL;
675 vap->va_rdev = VNOVAL;
676 vap->va_atime.tv_sec = VNOVAL;
677 vap->va_atime.tv_nsec = VNOVAL;
678 vap->va_mtime.tv_sec = VNOVAL;
679 vap->va_mtime.tv_nsec = VNOVAL;
680 vap->va_ctime.tv_sec = VNOVAL;
681 vap->va_ctime.tv_nsec = VNOVAL;
682 vap->va_birthtime.tv_sec = VNOVAL;
683 vap->va_birthtime.tv_nsec = VNOVAL;
684 vap->va_flags = VNOVAL;
685 vap->va_gen = VNOVAL;
723 trigger = cnt.v_page_count * 2 / usevnodes;
727 count = mp->mnt_nvnodelistsize / 10 + 1;
729 vp = TAILQ_FIRST(&mp->mnt_nvnodelist);
730 while (vp != NULL && vp->v_type == VMARKER)
731 vp = TAILQ_NEXT(vp, v_nmntvnodes);
734 TAILQ_REMOVE(&mp->mnt_nvnodelist, vp, v_nmntvnodes);
735 TAILQ_INSERT_TAIL(&mp->mnt_nvnodelist, vp, v_nmntvnodes);
743 if (vp->v_usecount ||
744 (!vlru_allow_cache_src &&
745 !LIST_EMPTY(&(vp)->v_cache_src)) ||
746 (vp->v_iflag & VI_DOOMED) != 0 || (vp->v_object != NULL &&
747 vp->v_object->resident_page_count > trigger)) {
753 if (VOP_LOCK(vp, LK_INTERLOCK|LK_EXCLUSIVE|LK_NOWAIT)) {
755 goto next_iter_mntunlocked;
770 if (vp->v_usecount ||
771 (!vlru_allow_cache_src &&
772 !LIST_EMPTY(&(vp)->v_cache_src)) ||
773 (vp->v_object != NULL &&
774 vp->v_object->resident_page_count > trigger)) {
775 VOP_UNLOCK(vp, LK_INTERLOCK);
776 goto next_iter_mntunlocked;
778 KASSERT((vp->v_iflag & VI_DOOMED) == 0,
779 (
"VI_DOOMED unexpectedly detected in vlrureclaim()"));
780 atomic_add_long(&recycles_count, 1);
785 next_iter_mntunlocked:
812 mtx_assert(&vnode_free_list_mtx, MA_OWNED);
813 for (; count > 0; count--) {
814 vp = TAILQ_FIRST(&vnode_free_list);
821 VNASSERT(vp->v_op != NULL, vp,
822 (
"vnlru_free: vnode already reclaimed."));
823 KASSERT((vp->v_iflag & VI_FREE) != 0,
824 (
"Removing vnode not on freelist"));
825 KASSERT((vp->v_iflag & VI_ACTIVE) == 0,
826 (
"Mangling active vnode"));
827 TAILQ_REMOVE(&vnode_free_list, vp, v_actfreelist);
831 if (!VI_TRYLOCK(vp)) {
832 TAILQ_INSERT_TAIL(&vnode_free_list, vp, v_actfreelist);
836 (
"vp inconsistent on freelist"));
838 vp->v_iflag &= ~VI_FREE;
840 mtx_unlock(&vnode_free_list_mtx);
842 vfslocked = VFS_LOCK_GIANT(vp->v_mount);
844 VFS_UNLOCK_GIANT(vfslocked);
851 mtx_lock(&vnode_free_list_mtx);
865 struct mount *mp, *nmp;
874 mtx_lock(&vnode_free_list_mtx);
875 if (freevnodes > wantfreevnodes)
877 if (
numvnodes <= desiredvnodes * 9 / 10) {
880 msleep(vnlruproc, &vnode_free_list_mtx,
881 PVFS|PDROP,
"vlruwt",
hz);
884 mtx_unlock(&vnode_free_list_mtx);
887 for (mp = TAILQ_FIRST(&
mountlist); mp != NULL; mp = nmp) {
888 if (
vfs_busy(mp, MBF_NOWAIT | MBF_MNTLSTLOCK)) {
889 nmp = TAILQ_NEXT(mp, mnt_list);
892 vfslocked = VFS_LOCK_GIANT(mp);
894 VFS_UNLOCK_GIANT(vfslocked);
896 nmp = TAILQ_NEXT(mp, mnt_list);
903 if (vnlru_nowhere < 5)
904 printf(
"vnlru process getting nowhere..\n");
905 else if (vnlru_nowhere == 5)
906 printf(
"vnlru process messages stopped.\n");
909 tsleep(vnlruproc, PPAUSE,
"vlrup",
hz * 3);
938 CTR2(KTR_VFS,
"%s: vp %p", __func__, vp);
939 VNASSERT(vp->v_holdcnt, vp,
940 (
"vtryrecycle: Recycling vp %p without a reference.", vp));
945 if (VOP_LOCK(vp, LK_EXCLUSIVE | LK_NOWAIT) != 0) {
947 "%s: impossible to recycle, vp %p lock is already held",
949 return (EWOULDBLOCK);
957 "%s: impossible to recycle, cannot start the write for %p",
968 if (vp->v_usecount) {
969 VOP_UNLOCK(vp, LK_INTERLOCK);
972 "%s: impossible to recycle, %p is already referenced",
976 if ((vp->v_iflag & VI_DOOMED) == 0) {
977 atomic_add_long(&recycles_count, 1);
980 VOP_UNLOCK(vp, LK_INTERLOCK);
992 mtx_assert(&vnode_free_list_mtx, MA_OWNED);
999 if (freevnodes > wantfreevnodes)
1003 if (vnlruproc_sig == 0) {
1007 msleep(&vnlruproc_sig, &vnode_free_list_mtx, PVFS,
1010 return (
numvnodes > desiredvnodes ? ENFILE : 0);
1020 if (atomic_fetchadd_long(&
numvnodes, count) + count <= desiredvnodes) {
1021 td->td_vp_reserv +=
count;
1024 atomic_subtract_long(&
numvnodes, count);
1026 mtx_lock(&vnode_free_list_mtx);
1034 mtx_unlock(&vnode_free_list_mtx);
1043 atomic_subtract_long(&
numvnodes, td->td_vp_reserv);
1044 td->td_vp_reserv = 0;
1051 getnewvnode(
const char *tag,
struct mount *mp,
struct vop_vector *vops,
1059 CTR3(KTR_VFS,
"%s: mp %p with tag %s", __func__, mp, tag);
1062 if (td->td_vp_reserv > 0) {
1063 td->td_vp_reserv -= 1;
1066 mtx_lock(&vnode_free_list_mtx);
1070 if (freevnodes > wantfreevnodes)
1076 mtx_unlock(&vnode_free_list_mtx);
1081 mtx_unlock(&vnode_free_list_mtx);
1084 vp = (
struct vnode *) uma_zalloc(vnode_zone, M_WAITOK|M_ZERO);
1088 vp->v_vnlock = &vp->v_lock;
1089 mtx_init(&vp->v_interlock,
"vnode interlock", NULL, MTX_DEF);
1094 lockinit(vp->v_vnlock, PVFS, tag, VLKTIMEOUT, LK_NOSHARE);
1099 bo->__bo_vnode = vp;
1100 mtx_init(BO_MTX(bo),
"bufobj interlock", NULL, MTX_DEF);
1102 bo->bo_private = vp;
1103 TAILQ_INIT(&bo->bo_clean.bv_hd);
1104 TAILQ_INIT(&bo->bo_dirty.bv_hd);
1108 LIST_INIT(&vp->v_cache_src);
1109 TAILQ_INIT(&vp->v_cache_dst);
1120 if (mp != NULL && (mp->mnt_flag & MNT_MULTILABEL) == 0)
1121 mac_vnode_associate_singlelabel(mp, vp);
1122 else if (mp == NULL && vops != &dead_vnodeops)
1123 printf(
"NULL mp in getnewvnode()\n");
1126 bo->bo_bsize = mp->mnt_stat.f_iosize;
1127 if ((mp->mnt_kern_flag & MNTK_NOKNOTE) != 0)
1128 vp->v_vflag |= VV_NOKNOTE;
1138 vp->v_hash = (uintptr_t)vp >> vnsz2log;
1158 KASSERT(mp->mnt_activevnodelistsize <= mp->mnt_nvnodelistsize,
1159 (
"Active vnode list size %d > Vnode list size %d",
1160 mp->mnt_activevnodelistsize, mp->mnt_nvnodelistsize));
1161 active = vp->v_iflag & VI_ACTIVE;
1162 vp->v_iflag &= ~VI_ACTIVE;
1164 mtx_lock(&vnode_free_list_mtx);
1165 TAILQ_REMOVE(&mp->mnt_activevnodelist, vp, v_actfreelist);
1166 mp->mnt_activevnodelistsize--;
1167 mtx_unlock(&vnode_free_list_mtx);
1171 VNASSERT(mp->mnt_nvnodelistsize > 0, vp,
1172 (
"bad mount point vnode list size"));
1173 TAILQ_REMOVE(&mp->mnt_nvnodelist, vp, v_nmntvnodes);
1174 mp->mnt_nvnodelistsize--;
1184 vp->v_op = &dead_vnodeops;
1187 if (!VOP_ISLOCKED(vp))
1188 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1198 void (*dtr)(
struct vnode *,
void *),
void *dtr_arg)
1202 KASSERT(vp->v_mount == NULL,
1203 (
"insmntque: vnode already on per mount vnode list"));
1204 VNASSERT(mp != NULL, vp, (
"Don't call insmntque(foo, NULL)"));
1205 #ifdef DEBUG_VFS_LOCKS
1206 if (!VFS_NEEDSGIANT(mp))
1207 ASSERT_VOP_ELOCKED(vp,
1208 "insmntque: mp-safe fs and non-locked vp");
1221 if ((mp->mnt_kern_flag & MNTK_NOINSMNTQ) != 0 &&
1222 ((mp->mnt_kern_flag & MNTK_UNMOUNTF) != 0 ||
1223 mp->mnt_nvnodelistsize == 0)) {
1224 locked = VOP_ISLOCKED(vp);
1225 if (!locked || (locked == LK_EXCLUSIVE &&
1226 (vp->v_vflag & VV_FORCEINSMQ) == 0)) {
1236 TAILQ_INSERT_TAIL(&mp->mnt_nvnodelist, vp, v_nmntvnodes);
1237 VNASSERT(mp->mnt_nvnodelistsize >= 0, vp,
1238 (
"neg mount point vnode list size"));
1239 mp->mnt_nvnodelistsize++;
1240 KASSERT((vp->v_iflag & VI_ACTIVE) == 0,
1241 (
"Activating already active vnode"));
1242 vp->v_iflag |= VI_ACTIVE;
1243 mtx_lock(&vnode_free_list_mtx);
1244 TAILQ_INSERT_HEAD(&mp->mnt_activevnodelist, vp, v_actfreelist);
1245 mp->mnt_activevnodelistsize++;
1246 mtx_unlock(&vnode_free_list_mtx);
1269 if (flags & V_SAVE) {
1275 if (bo->bo_dirty.bv_cnt > 0) {
1277 if ((error = BO_SYNC(bo, MNT_WAIT)) != 0)
1284 if (bo->bo_numoutput > 0 || bo->bo_dirty.bv_cnt > 0)
1285 panic(
"vinvalbuf: dirty bufs");
1295 flags, bo, slpflag, slptimeo);
1296 if (error == 0 && !(flags & V_CLEANONLY))
1298 flags, bo, slpflag, slptimeo);
1299 if (error != 0 && error != EAGAIN) {
1303 }
while (error != 0);
1313 if (bo->bo_object != NULL) {
1314 VM_OBJECT_LOCK(bo->bo_object);
1315 vm_object_pip_wait(bo->bo_object,
"bovlbx");
1316 VM_OBJECT_UNLOCK(bo->bo_object);
1319 }
while (bo->bo_numoutput > 0);
1325 if (bo->bo_object != NULL &&
1326 (flags & (V_ALT | V_NORMAL | V_CLEANONLY)) == 0) {
1327 VM_OBJECT_LOCK(bo->bo_object);
1328 vm_object_page_remove(bo->bo_object, 0, 0, (flags & V_SAVE) ?
1329 OBJPR_CLEANONLY : 0);
1330 VM_OBJECT_UNLOCK(bo->bo_object);
1335 if ((flags & (V_ALT | V_NORMAL | V_CLEANONLY)) == 0 &&
1336 (bo->bo_dirty.bv_cnt > 0 || bo->bo_clean.bv_cnt > 0))
1337 panic(
"vinvalbuf: flush failed");
1348 vinvalbuf(
struct vnode *vp,
int flags,
int slpflag,
int slptimeo)
1351 CTR3(KTR_VFS,
"%s: vp %p with flags %d", __func__, vp, flags);
1352 ASSERT_VOP_LOCKED(vp,
"vinvalbuf");
1353 if (vp->v_object != NULL && vp->v_object->handle != vp)
1363 flushbuflist(
struct bufv *bufv,
int flags,
struct bufobj *bo,
int slpflag,
1366 struct buf *bp, *nbp;
1371 ASSERT_BO_LOCKED(bo);
1374 TAILQ_FOREACH_SAFE(bp, &bufv->bv_hd, b_bobufs, nbp) {
1375 if (((flags & V_NORMAL) && (bp->b_xflags & BX_ALTDATA)) ||
1376 ((flags & V_ALT) && (bp->b_xflags & BX_ALTDATA) == 0)) {
1382 lblkno = nbp->b_lblkno;
1383 xflags = nbp->b_xflags &
1384 (BX_BKGRDMARKER | BX_VNDIRTY | BX_VNCLEAN);
1387 error = BUF_TIMELOCK(bp,
1388 LK_EXCLUSIVE | LK_SLEEPFAIL | LK_INTERLOCK, BO_MTX(bo),
1389 "flushbuf", slpflag, slptimeo);
1392 return (error != ENOLCK ? error : EAGAIN);
1394 KASSERT(bp->b_bufobj == bo,
1395 (
"bp %p wrong b_bufobj %p should be %p",
1396 bp, bp->b_bufobj, bo));
1397 if (bp->b_bufobj != bo) {
1408 if (((bp->b_flags & (B_DELWRI | B_INVAL)) == B_DELWRI) &&
1413 bp->b_flags |= B_ASYNC;
1421 bp->b_flags |= (B_INVAL | B_RELBUF);
1422 bp->b_flags &= ~B_ASYNC;
1426 (nbp->b_bufobj != bo ||
1427 nbp->b_lblkno != lblkno ||
1429 (BX_BKGRDMARKER | BX_VNDIRTY | BX_VNCLEAN)) != xflags))
1441 vtruncbuf(
struct vnode *vp,
struct ucred *cred,
struct thread *td,
1442 off_t length,
int blksize)
1444 struct buf *bp, *nbp;
1449 CTR5(KTR_VFS,
"%s: vp %p with cred %p and block %d:%ju", __func__,
1450 vp, cred, blksize, (uintmax_t)length);
1455 trunclbn = (length + blksize - 1) / blksize;
1457 ASSERT_VOP_LOCKED(vp,
"vtruncbuf");
1464 TAILQ_FOREACH_SAFE(bp, &bo->bo_clean.bv_hd, b_bobufs, nbp) {
1465 if (bp->b_lblkno < trunclbn)
1468 LK_EXCLUSIVE | LK_SLEEPFAIL | LK_INTERLOCK,
1469 BO_MTX(bo)) == ENOLCK)
1475 bp->b_flags |= (B_INVAL | B_RELBUF);
1476 bp->b_flags &= ~B_ASYNC;
1482 (((nbp->b_xflags & BX_VNCLEAN) == 0) ||
1483 (nbp->b_vp != vp) ||
1484 (nbp->b_flags & B_DELWRI))) {
1490 TAILQ_FOREACH_SAFE(bp, &bo->bo_dirty.bv_hd, b_bobufs, nbp) {
1491 if (bp->b_lblkno < trunclbn)
1494 LK_EXCLUSIVE | LK_SLEEPFAIL | LK_INTERLOCK,
1495 BO_MTX(bo)) == ENOLCK)
1500 bp->b_flags |= (B_INVAL | B_RELBUF);
1501 bp->b_flags &= ~B_ASYNC;
1507 (((nbp->b_xflags & BX_VNDIRTY) == 0) ||
1508 (nbp->b_vp != vp) ||
1509 (nbp->b_flags & B_DELWRI) == 0)) {
1518 TAILQ_FOREACH_SAFE(bp, &bo->bo_dirty.bv_hd, b_bobufs, nbp) {
1519 if (bp->b_lblkno > 0)
1526 LK_EXCLUSIVE | LK_SLEEPFAIL | LK_INTERLOCK,
1527 BO_MTX(bo)) == ENOLCK) {
1530 VNASSERT((bp->b_flags & B_DELWRI), vp,
1531 (
"buf(%p) on dirty queue without DELWRI", bp));
1544 vnode_pager_setsize(vp, length);
1567 struct buf *lefttreemax, *righttreemin, *y;
1571 lefttreemax = righttreemin = &
dummy;
1573 if (lblkno < root->b_lblkno ||
1574 (lblkno == root->b_lblkno &&
1575 (xflags & BX_BKGRDMARKER) < (root->b_xflags & BX_BKGRDMARKER))) {
1576 if ((y = root->b_left) == NULL)
1578 if (lblkno < y->b_lblkno) {
1580 root->b_left = y->b_right;
1583 if ((y = root->b_left) == NULL)
1587 righttreemin->b_left = root;
1588 righttreemin = root;
1589 }
else if (lblkno > root->b_lblkno ||
1590 (lblkno == root->b_lblkno &&
1591 (xflags & BX_BKGRDMARKER) > (root->b_xflags & BX_BKGRDMARKER))) {
1592 if ((y = root->b_right) == NULL)
1594 if (lblkno > y->b_lblkno) {
1596 root->b_right = y->b_left;
1599 if ((y = root->b_right) == NULL)
1603 lefttreemax->b_right = root;
1611 lefttreemax->b_right = root->b_left;
1612 righttreemin->b_left = root->b_right;
1613 root->b_left = dummy.b_right;
1614 root->b_right = dummy.b_left;
1624 KASSERT(bp->b_bufobj != NULL, (
"No b_bufobj %p", bp));
1625 ASSERT_BO_LOCKED(bp->b_bufobj);
1626 KASSERT((bp->b_xflags & (BX_VNDIRTY|BX_VNCLEAN)) !=
1627 (BX_VNDIRTY|BX_VNCLEAN),
1628 (
"buf_vlist_remove: Buf %p is on two lists", bp));
1629 if (bp->b_xflags & BX_VNDIRTY)
1630 bv = &bp->b_bufobj->bo_dirty;
1632 bv = &bp->b_bufobj->bo_clean;
1633 if (bp != bv->bv_root) {
1634 root =
buf_splay(bp->b_lblkno, bp->b_xflags, bv->bv_root);
1635 KASSERT(root == bp, (
"splay lookup failed in remove"));
1637 if (bp->b_left == NULL) {
1640 root =
buf_splay(bp->b_lblkno, bp->b_xflags, bp->b_left);
1641 root->b_right = bp->b_right;
1644 TAILQ_REMOVE(&bv->bv_hd, bp, b_bobufs);
1646 bp->b_xflags &= ~(BX_VNDIRTY | BX_VNCLEAN);
1661 ASSERT_BO_LOCKED(bo);
1662 KASSERT((bp->b_xflags & (BX_VNDIRTY|BX_VNCLEAN)) == 0,
1663 (
"buf_vlist_add: Buf %p has existing xflags %d", bp, bp->b_xflags));
1664 bp->b_xflags |= xflags;
1665 if (xflags & BX_VNDIRTY)
1670 root =
buf_splay(bp->b_lblkno, bp->b_xflags, bv->bv_root);
1674 TAILQ_INSERT_TAIL(&bv->bv_hd, bp, b_bobufs);
1675 }
else if (bp->b_lblkno < root->b_lblkno ||
1676 (bp->b_lblkno == root->b_lblkno &&
1677 (bp->b_xflags & BX_BKGRDMARKER) < (root->b_xflags & BX_BKGRDMARKER))) {
1678 bp->b_left = root->b_left;
1680 root->b_left = NULL;
1681 TAILQ_INSERT_BEFORE(root, bp, b_bobufs);
1683 bp->b_right = root->b_right;
1685 root->b_right = NULL;
1686 TAILQ_INSERT_AFTER(&bv->bv_hd, root, bp, b_bobufs);
1709 ASSERT_BO_LOCKED(bo);
1710 if ((bp = bo->bo_clean.bv_root) != NULL &&
1711 bp->b_lblkno == lblkno && !(bp->b_xflags & BX_BKGRDMARKER))
1713 if ((bp = bo->bo_dirty.bv_root) != NULL &&
1714 bp->b_lblkno == lblkno && !(bp->b_xflags & BX_BKGRDMARKER))
1716 if ((bp = bo->bo_clean.bv_root) != NULL) {
1717 bo->bo_clean.bv_root = bp =
buf_splay(lblkno, 0, bp);
1718 if (bp->b_lblkno == lblkno && !(bp->b_xflags & BX_BKGRDMARKER))
1721 if ((bp = bo->bo_dirty.bv_root) != NULL) {
1722 bo->bo_dirty.bv_root = bp =
buf_splay(lblkno, 0, bp);
1723 if (bp->b_lblkno == lblkno && !(bp->b_xflags & BX_BKGRDMARKER))
1738 ASSERT_BO_LOCKED(bo);
1739 VNASSERT(bp->b_vp == NULL, bp->b_vp, (
"bgetvp: not free"));
1741 CTR3(KTR_BUF,
"bgetvp(%p) vp %p flags %X", bp, vp, bp->b_flags);
1742 VNASSERT((bp->b_xflags & (BX_VNDIRTY|BX_VNCLEAN)) == 0, vp,
1743 (
"bgetvp: bp already attached! %p", bp));
1746 if (VFS_NEEDSGIANT(vp->v_mount) || bo->bo_flag & BO_NEEDSGIANT)
1747 bp->b_flags |= B_NEEDSGIANT;
1765 CTR3(KTR_BUF,
"brelvp(%p) vp %p flags %X", bp, bp->b_vp, bp->b_flags);
1766 KASSERT(bp->b_vp != NULL, (
"brelvp: NULL"));
1774 if (bp->b_xflags & (BX_VNDIRTY | BX_VNCLEAN))
1777 panic(
"brelvp: Buffer %p not on queue.", bp);
1778 if ((bo->bo_flag & BO_ONWORKLST) && bo->bo_dirty.bv_cnt == 0) {
1779 bo->bo_flag &= ~BO_ONWORKLST;
1780 mtx_lock(&sync_mtx);
1781 LIST_REMOVE(bo, bo_synclist);
1782 syncer_worklist_len--;
1783 mtx_unlock(&sync_mtx);
1785 bp->b_flags &= ~B_NEEDSGIANT;
1787 bp->b_bufobj = NULL;
1800 ASSERT_BO_LOCKED(bo);
1802 mtx_lock(&sync_mtx);
1803 if (bo->bo_flag & BO_ONWORKLST)
1804 LIST_REMOVE(bo, bo_synclist);
1806 bo->bo_flag |= BO_ONWORKLST;
1807 syncer_worklist_len++;
1810 if (delay > syncer_maxdelay - 2)
1811 delay = syncer_maxdelay - 2;
1812 slot = (syncer_delayno + delay) & syncer_mask;
1814 queue = VFS_NEEDSGIANT(bo->__bo_vnode->v_mount) ?
WI_GIANTQ :
1816 LIST_INSERT_HEAD(&syncer_workitem_pending[queue][slot], bo,
1818 mtx_unlock(&sync_mtx);
1826 mtx_lock(&sync_mtx);
1827 len = syncer_worklist_len - sync_vnode_count;
1828 mtx_unlock(&sync_mtx);
1829 error = SYSCTL_OUT(req, &len,
sizeof(len));
1833 SYSCTL_PROC(_vfs, OID_AUTO, worklist_len, CTLTYPE_INT | CTLFLAG_RD, NULL, 0,
1846 sync_vnode(
struct synclist *slp,
struct bufobj **bo,
struct thread *td)
1851 *bo = LIST_FIRST(slp);
1854 vp = (*bo)->__bo_vnode;
1855 if (VOP_ISLOCKED(vp) != 0 || VI_TRYLOCK(vp) == 0)
1864 mtx_unlock(&sync_mtx);
1868 mtx_lock(&sync_mtx);
1869 return (*bo == LIST_FIRST(slp));
1871 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
1872 (void) VOP_FSYNC(vp, MNT_LAZY, td);
1876 if (((*bo)->bo_flag & BO_ONWORKLST) != 0) {
1887 mtx_lock(&sync_mtx);
1897 struct synclist *gnext, *next;
1898 struct synclist *gslp, *slp;
1901 struct thread *td = curthread;
1903 int net_worklist_len;
1904 int syncer_final_iter;
1909 syncer_final_iter = 0;
1913 td->td_pflags |= TDP_NORUNNINGBUF;
1915 EVENTHANDLER_REGISTER(shutdown_pre_sync,
syncer_shutdown, td->td_proc,
1918 mtx_lock(&sync_mtx);
1921 syncer_final_iter == 0) {
1922 mtx_unlock(&sync_mtx);
1924 mtx_lock(&sync_mtx);
1926 net_worklist_len = syncer_worklist_len - sync_vnode_count;
1930 printf(
"\nSyncing disks, vnodes remaining...");
1933 printf(
"%d ", net_worklist_len);
1944 slp = &syncer_workitem_pending[
WI_MPSAFEQ][syncer_delayno];
1945 gslp = &syncer_workitem_pending[
WI_GIANTQ][syncer_delayno];
1946 syncer_delayno += 1;
1947 if (syncer_delayno == syncer_maxdelay)
1949 next = &syncer_workitem_pending[
WI_MPSAFEQ][syncer_delayno];
1950 gnext = &syncer_workitem_pending[
WI_GIANTQ][syncer_delayno];
1958 net_worklist_len == 0 &&
1959 last_work_seen == syncer_delayno) {
1963 }
while (
syncer_state != SYNCER_RUNNING && LIST_EMPTY(slp) &&
1964 LIST_EMPTY(gslp) && syncer_worklist_len > 0);
1972 if (net_worklist_len > 0 ||
syncer_state == SYNCER_RUNNING)
1973 last_work_seen = syncer_delayno;
1974 if (net_worklist_len > 0 &&
syncer_state == SYNCER_FINAL_DELAY)
1976 while (!LIST_EMPTY(slp)) {
1979 LIST_REMOVE(bo, bo_synclist);
1980 LIST_INSERT_HEAD(next, bo, bo_synclist);
1984 if (first_printf == 0)
1985 wdog_kern_pat(WD_LASTVAL);
1988 if (!LIST_EMPTY(gslp)) {
1989 mtx_unlock(&sync_mtx);
1991 mtx_lock(&sync_mtx);
1992 while (!LIST_EMPTY(gslp)) {
1995 LIST_REMOVE(bo, bo_synclist);
1996 LIST_INSERT_HEAD(gnext, bo,
2003 if (
syncer_state == SYNCER_FINAL_DELAY && syncer_final_iter > 0)
2004 syncer_final_iter--;
2038 cv_timedwait(&sync_wakeup, &sync_mtx,
2041 cv_timedwait(&sync_wakeup, &sync_mtx,
hz);
2055 mtx_lock(&sync_mtx);
2056 if (rushjob < syncdelay / 2) {
2058 stat_rush_requests += 1;
2061 mtx_unlock(&sync_mtx);
2062 cv_broadcast(&sync_wakeup);
2074 if (howto & RB_NOSYNC)
2076 mtx_lock(&sync_mtx);
2079 mtx_unlock(&sync_mtx);
2080 cv_broadcast(&sync_wakeup);
2103 CTR3(KTR_BUF,
"reassignbuf(%p) vp %p flags %X",
2104 bp, bp->b_vp, bp->b_flags);
2109 if (bp->b_flags & B_PAGING)
2110 panic(
"cannot reassign paging buffer");
2116 if (bp->b_xflags & (BX_VNDIRTY | BX_VNCLEAN))
2119 panic(
"reassignbuf: Buffer %p not on queue.", bp);
2124 if (bp->b_flags & B_DELWRI) {
2125 if ((bo->bo_flag & BO_ONWORKLST) == 0) {
2126 switch (vp->v_type) {
2142 if ((bo->bo_flag & BO_ONWORKLST) && bo->bo_dirty.bv_cnt == 0) {
2143 mtx_lock(&sync_mtx);
2144 LIST_REMOVE(bo, bo_synclist);
2145 syncer_worklist_len--;
2146 mtx_unlock(&sync_mtx);
2147 bo->bo_flag &= ~BO_ONWORKLST;
2152 bp = TAILQ_FIRST(&bv->bv_hd);
2153 KASSERT(bp == NULL || bp->b_bufobj == bo,
2154 (
"bp %p wrong b_bufobj %p should be %p", bp, bp->b_bufobj, bo));
2155 bp = TAILQ_LAST(&bv->bv_hd, buflists);
2156 KASSERT(bp == NULL || bp->b_bufobj == bo,
2157 (
"bp %p wrong b_bufobj %p should be %p", bp, bp->b_bufobj, bo));
2159 bp = TAILQ_FIRST(&bv->bv_hd);
2160 KASSERT(bp == NULL || bp->b_bufobj == bo,
2161 (
"bp %p wrong b_bufobj %p should be %p", bp, bp->b_bufobj, bo));
2162 bp = TAILQ_LAST(&bv->bv_hd, buflists);
2163 KASSERT(bp == NULL || bp->b_bufobj == bo,
2164 (
"bp %p wrong b_bufobj %p should be %p", bp, bp->b_bufobj, bo));
2179 CTR2(KTR_VFS,
"%s: vp %p", __func__, vp);
2181 if (vp->v_type == VCHR && vp->v_rdev != NULL) {
2183 vp->v_rdev->si_usecount++;
2197 CTR2(KTR_VFS,
"%s: vp %p", __func__, vp);
2199 if (vp->v_type == VCHR && vp->v_rdev != NULL) {
2201 vp->v_rdev->si_usecount++;
2215 ASSERT_VI_LOCKED(vp, __FUNCTION__);
2216 VNASSERT(vp->v_usecount > 0, vp,
2217 (
"v_decr_usecount: negative usecount"));
2218 CTR2(KTR_VFS,
"%s: vp %p", __func__, vp);
2220 if (vp->v_type == VCHR && vp->v_rdev != NULL) {
2222 vp->v_rdev->si_usecount--;
2238 ASSERT_VI_LOCKED(vp, __FUNCTION__);
2239 VNASSERT(vp->v_usecount > 0, vp,
2240 (
"v_decr_useonly: negative usecount"));
2241 CTR2(KTR_VFS,
"%s: vp %p", __func__, vp);
2243 if (vp->v_type == VCHR && vp->v_rdev != NULL) {
2245 vp->v_rdev->si_usecount--;
2258 vget(
struct vnode *vp,
int flags,
struct thread *td)
2263 VFS_ASSERT_GIANT(vp->v_mount);
2264 VNASSERT((flags & LK_TYPE_MASK) != 0, vp,
2265 (
"vget: invalid lock operation"));
2266 CTR3(KTR_VFS,
"%s: vp %p with flags %d", __func__, vp, flags);
2268 if ((flags & LK_INTERLOCK) == 0)
2271 if ((error = vn_lock(vp, flags | LK_INTERLOCK)) != 0) {
2273 CTR2(KTR_VFS,
"%s: impossible to lock vnode %p", __func__,
2277 if (vp->v_iflag & VI_DOOMED && (flags & LK_RETRY) == 0)
2278 panic(
"vget: vn_lock failed to return ENOENT\n");
2288 if (vp->v_iflag & VI_OWEINACT) {
2289 if (VOP_ISLOCKED(vp) == LK_EXCLUSIVE &&
2290 (flags & LK_NOWAIT) == 0)
2292 vp->v_iflag &= ~VI_OWEINACT;
2305 CTR2(KTR_VFS,
"%s: vp %p", __func__, vp);
2326 usecnt = vp->v_usecount;
2332 #define VPUTX_VRELE 1
2333 #define VPUTX_VPUT 2
2334 #define VPUTX_VUNREF 3
2341 KASSERT(vp != NULL, (
"vputx: null vp"));
2343 ASSERT_VOP_LOCKED(vp,
"vunref");
2345 ASSERT_VOP_LOCKED(vp,
"vput");
2347 KASSERT(func ==
VPUTX_VRELE, (
"vputx: wrong func"));
2348 VFS_ASSERT_GIANT(vp->v_mount);
2349 CTR2(KTR_VFS,
"%s: vp %p", __func__, vp);
2353 VNASSERT(vp->v_writecount < vp->v_usecount || vp->v_usecount < 1, vp,
2354 (
"vputx: missed vn_close"));
2357 if (vp->v_usecount > 1 || ((vp->v_iflag & VI_DOINGINACT) &&
2358 vp->v_usecount == 1)) {
2365 if (vp->v_usecount != 1) {
2366 vprint(
"vputx: negative ref count", vp);
2367 panic(
"vputx: negative ref cnt");
2369 CTR2(KTR_VFS,
"%s: return vnode %p to the freelist", __func__, vp);
2380 vp->v_iflag |= VI_OWEINACT;
2383 error = vn_lock(vp, LK_EXCLUSIVE | LK_INTERLOCK);
2387 if (VOP_ISLOCKED(vp) != LK_EXCLUSIVE) {
2388 error = VOP_LOCK(vp, LK_UPGRADE | LK_INTERLOCK |
2394 if (VOP_ISLOCKED(vp) != LK_EXCLUSIVE) {
2395 error = VOP_LOCK(vp, LK_TRYUPGRADE | LK_INTERLOCK);
2400 if (vp->v_usecount > 0)
2401 vp->v_iflag &= ~VI_OWEINACT;
2403 if (vp->v_iflag & VI_OWEINACT)
2464 CTR2(KTR_VFS,
"%s: vp %p", __func__, vp);
2468 ASSERT_VI_LOCKED(vp,
"vholdl");
2469 VNASSERT((vp->v_iflag & VI_FREE) != 0, vp, (
"vnode not free"));
2470 VNASSERT(vp->v_op != NULL, vp, (
"vholdl: vnode already reclaimed."));
2475 mtx_lock(&vnode_free_list_mtx);
2476 TAILQ_REMOVE(&vnode_free_list, vp, v_actfreelist);
2478 vp->v_iflag &= ~(VI_FREE|VI_AGE);
2479 KASSERT((vp->v_iflag & VI_ACTIVE) == 0,
2480 (
"Activating already active vnode"));
2481 vp->v_iflag |= VI_ACTIVE;
2483 TAILQ_INSERT_HEAD(&mp->mnt_activevnodelist, vp, v_actfreelist);
2484 mp->mnt_activevnodelistsize++;
2485 mtx_unlock(&vnode_free_list_mtx);
2512 ASSERT_VI_LOCKED(vp,
"vdropl");
2513 CTR2(KTR_VFS,
"%s: vp %p", __func__, vp);
2514 if (vp->v_holdcnt <= 0)
2515 panic(
"vdrop: holdcnt %d", vp->v_holdcnt);
2517 if (vp->v_holdcnt > 0) {
2521 if ((vp->v_iflag & VI_DOOMED) == 0) {
2526 VNASSERT(vp->v_op != NULL, vp,
2527 (
"vdropl: vnode already reclaimed."));
2528 VNASSERT((vp->v_iflag & VI_FREE) == 0, vp,
2529 (
"vnode already free"));
2531 (
"vdropl: freeing when we shouldn't"));
2532 active = vp->v_iflag & VI_ACTIVE;
2533 vp->v_iflag &= ~VI_ACTIVE;
2535 mtx_lock(&vnode_free_list_mtx);
2537 TAILQ_REMOVE(&mp->mnt_activevnodelist, vp,
2539 mp->mnt_activevnodelistsize--;
2541 if (vp->v_iflag & VI_AGE) {
2542 TAILQ_INSERT_HEAD(&vnode_free_list, vp, v_actfreelist);
2544 TAILQ_INSERT_TAIL(&vnode_free_list, vp, v_actfreelist);
2547 vp->v_iflag &= ~VI_AGE;
2548 vp->v_iflag |= VI_FREE;
2549 mtx_unlock(&vnode_free_list_mtx);
2556 CTR2(KTR_VFS,
"%s: destroying the vnode %p", __func__, vp);
2559 VNASSERT((vp->v_iflag & VI_FREE) == 0, vp,
2560 (
"cleaned vnode still on the free list."));
2561 VNASSERT(vp->v_data == NULL, vp, (
"cleaned vnode isn't"));
2562 VNASSERT(vp->v_holdcnt == 0, vp, (
"Non-zero hold count"));
2563 VNASSERT(vp->v_usecount == 0, vp, (
"Non-zero use count"));
2564 VNASSERT(vp->v_writecount == 0, vp, (
"Non-zero write count"));
2565 VNASSERT(bo->bo_numoutput == 0, vp, (
"Clean vnode has pending I/O's"));
2566 VNASSERT(bo->bo_clean.bv_cnt == 0, vp, (
"cleanbufcnt not 0"));
2567 VNASSERT(bo->bo_clean.bv_root == NULL, vp, (
"cleanblkroot not NULL"));
2568 VNASSERT(bo->bo_dirty.bv_cnt == 0, vp, (
"dirtybufcnt not 0"));
2569 VNASSERT(bo->bo_dirty.bv_root == NULL, vp, (
"dirtyblkroot not NULL"));
2570 VNASSERT(TAILQ_EMPTY(&vp->v_cache_dst), vp, (
"vp has namecache dst"));
2571 VNASSERT(LIST_EMPTY(&vp->v_cache_src), vp, (
"vp has namecache src"));
2572 VNASSERT(vp->v_cache_dd == NULL, vp, (
"vp has namecache for .."));
2575 mac_vnode_destroy(vp);
2577 if (vp->v_pollinfo != NULL)
2587 uma_zfree(vnode_zone, vp);
2599 struct vm_object *obj;
2601 ASSERT_VOP_ELOCKED(vp,
"vinactive");
2602 ASSERT_VI_LOCKED(vp,
"vinactive");
2603 VNASSERT((vp->v_iflag & VI_DOINGINACT) == 0, vp,
2604 (
"vinactive: recursed on VI_DOINGINACT"));
2605 CTR2(KTR_VFS,
"%s: vp %p", __func__, vp);
2606 vp->v_iflag |= VI_DOINGINACT;
2607 vp->v_iflag &= ~VI_OWEINACT;
2618 if (obj != NULL && (obj->flags & OBJ_MIGHTBEDIRTY) != 0) {
2619 VM_OBJECT_LOCK(obj);
2620 vm_object_page_clean(obj, 0, 0, OBJPC_NOSYNC);
2621 VM_OBJECT_UNLOCK(obj);
2623 VOP_INACTIVE(vp, td);
2625 VNASSERT(vp->v_iflag & VI_DOINGINACT, vp,
2626 (
"vinactive: lost VI_DOINGINACT"));
2627 vp->v_iflag &= ~VI_DOINGINACT;
2651 static int busyprt = 0;
2652 SYSCTL_INT(_debug, OID_AUTO, busyprt, CTLFLAG_RW, &busyprt, 0,
"Print out busy vnodes");
2656 vflush(
struct mount *mp,
int rootrefs,
int flags,
struct thread *td)
2658 struct vnode *vp, *mvp, *rootvp = NULL;
2660 int busy = 0, error;
2662 CTR4(KTR_VFS,
"%s: mp %p with rootrefs %d and flags %d", __func__, mp,
2665 KASSERT((flags & (SKIPSYSTEM | WRITECLOSE)) == 0,
2666 (
"vflush: bad args"));
2671 if ((error = VFS_ROOT(mp, LK_EXCLUSIVE, &rootvp)) != 0) {
2672 CTR2(KTR_VFS,
"%s: vfs_root lookup failed with %d",
2679 MNT_VNODE_FOREACH_ALL(vp, mp, mvp) {
2681 error = vn_lock(vp, LK_INTERLOCK | LK_EXCLUSIVE);
2684 MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
2690 if ((flags & SKIPSYSTEM) && (vp->v_vflag & VV_SYSTEM)) {
2700 if (flags & WRITECLOSE) {
2701 if (vp->v_object != NULL) {
2702 VM_OBJECT_LOCK(vp->v_object);
2703 vm_object_page_clean(vp->v_object, 0, 0, 0);
2704 VM_OBJECT_UNLOCK(vp->v_object);
2706 error = VOP_FSYNC(vp, MNT_WAIT, td);
2710 MNT_VNODE_FOREACH_ALL_ABORT(mp, mvp);
2713 error = VOP_GETATTR(vp, &vattr, td->td_ucred);
2716 if ((vp->v_type == VNON ||
2717 (error == 0 && vattr.va_nlink > 0)) &&
2718 (vp->v_writecount == 0 || vp->v_type != VREG)) {
2731 if (vp->v_usecount == 0 || (flags & FORCECLOSE)) {
2732 VNASSERT(vp->v_usecount == 0 ||
2733 (vp->v_type != VCHR && vp->v_type != VBLK), vp,
2734 (
"device VNODE %p is FORCECLOSED", vp));
2740 vprint(
"vflush: busy vnode", vp);
2746 if (rootrefs > 0 && (flags & FORCECLOSE) == 0) {
2752 KASSERT(busy > 0, (
"vflush: not busy"));
2753 VNASSERT(rootvp->v_usecount >= rootrefs, rootvp,
2754 (
"vflush: usecount %d < rootrefs %d",
2755 rootvp->v_usecount, rootrefs));
2756 if (busy == 1 && rootvp->v_usecount == rootrefs) {
2757 VOP_LOCK(rootvp, LK_EXCLUSIVE|LK_INTERLOCK);
2759 VOP_UNLOCK(rootvp, 0);
2765 CTR2(KTR_VFS,
"%s: failing as %d vnodes are busy", __func__,
2769 for (; rootrefs > 0; rootrefs--)
2782 ASSERT_VOP_ELOCKED(vp,
"vrecycle");
2783 CTR2(KTR_VFS,
"%s: vp %p", __func__, vp);
2786 if (vp->v_usecount == 0) {
2808 struct vnode *lowervp __unused)
2818 static struct vfsops vgonel_vfsops = {
2822 struct mount *mp, *ump, *mmp;
2829 if (TAILQ_EMPTY(&mp->mnt_uppers))
2832 mmp =
malloc(
sizeof(
struct mount), M_TEMP, M_WAITOK | M_ZERO);
2833 mmp->mnt_op = &vgonel_vfsops;
2834 mmp->mnt_kern_flag |= MNTK_MARKER;
2836 mp->mnt_kern_flag |= MNTK_VGONE_UPPER;
2837 for (ump = TAILQ_FIRST(&mp->mnt_uppers); ump != NULL;) {
2838 if ((ump->mnt_kern_flag & MNTK_MARKER) != 0) {
2839 ump = TAILQ_NEXT(ump, mnt_upper_link);
2842 TAILQ_INSERT_AFTER(&mp->mnt_uppers, ump, mmp, mnt_upper_link);
2845 case VFS_NOTIFY_UPPER_RECLAIM:
2846 VFS_RECLAIM_LOWERVP(ump, vp);
2848 case VFS_NOTIFY_UPPER_UNLINK:
2849 VFS_UNLINK_LOWERVP(ump, vp);
2852 KASSERT(0, (
"invalid event %d", event));
2856 ump = TAILQ_NEXT(mmp, mnt_upper_link);
2857 TAILQ_REMOVE(&mp->mnt_uppers, mmp, mnt_upper_link);
2860 mp->mnt_kern_flag &= ~MNTK_VGONE_UPPER;
2861 if ((mp->mnt_kern_flag & MNTK_VGONE_WAITER) != 0) {
2862 mp->mnt_kern_flag &= ~MNTK_VGONE_WAITER;
2880 ASSERT_VOP_ELOCKED(vp,
"vgonel");
2881 ASSERT_VI_LOCKED(vp,
"vgonel");
2882 VNASSERT(vp->v_holdcnt, vp,
2883 (
"vgonel: vp %p has no reference.", vp));
2884 CTR2(KTR_VFS,
"%s: vp %p", __func__, vp);
2890 if (vp->v_iflag & VI_DOOMED)
2892 vp->v_iflag |= VI_DOOMED;
2898 active = vp->v_usecount;
2899 oweinact = (vp->v_iflag & VI_OWEINACT);
2908 if (!TAILQ_EMPTY(&vp->v_bufobj.bo_dirty.bv_hd))
2918 VOP_CLOSE(vp, FNONBLOCK, NOCRED, td);
2919 if (oweinact || active) {
2921 if ((vp->v_iflag & VI_DOINGINACT) == 0)
2925 if (vp->v_type == VSOCK)
2930 if (VOP_RECLAIM(vp, td))
2931 panic(
"vgone: cannot reclaim");
2934 VNASSERT(vp->v_object == NULL, vp,
2935 (
"vop_reclaim left v_object vp=%p, tag=%s", vp, vp->v_tag));
2939 (void)VOP_ADVLOCKPURGE(vp);
2950 vp->v_vnlock = &vp->v_lock;
2951 vp->v_op = &dead_vnodeops;
2965 count = vp->v_rdev->si_usecount;
2979 count = dev->si_usecount;
2987 static char *
typename[] =
2988 {
"VNON",
"VREG",
"VDIR",
"VBLK",
"VCHR",
"VLNK",
"VSOCK",
"VFIFO",
"VBAD",
2995 char buf[256], buf2[16];
3001 printf(
"%p: ", (
void *)vp);
3002 printf(
"tag %s, type %s\n", vp->v_tag,
typename[vp->v_type]);
3003 printf(
" usecount %d, writecount %d, refcount %d mountedhere %p\n",
3004 vp->v_usecount, vp->v_writecount, vp->v_holdcnt, vp->v_mountedhere);
3007 if (vp->v_vflag & VV_ROOT)
3008 strlcat(buf,
"|VV_ROOT",
sizeof(buf));
3009 if (vp->v_vflag & VV_ISTTY)
3010 strlcat(buf,
"|VV_ISTTY",
sizeof(buf));
3011 if (vp->v_vflag & VV_NOSYNC)
3012 strlcat(buf,
"|VV_NOSYNC",
sizeof(buf));
3013 if (vp->v_vflag & VV_ETERNALDEV)
3014 strlcat(buf,
"|VV_ETERNALDEV",
sizeof(buf));
3015 if (vp->v_vflag & VV_CACHEDLABEL)
3016 strlcat(buf,
"|VV_CACHEDLABEL",
sizeof(buf));
3017 if (vp->v_vflag & VV_TEXT)
3018 strlcat(buf,
"|VV_TEXT",
sizeof(buf));
3019 if (vp->v_vflag & VV_COPYONWRITE)
3020 strlcat(buf,
"|VV_COPYONWRITE",
sizeof(buf));
3021 if (vp->v_vflag & VV_SYSTEM)
3022 strlcat(buf,
"|VV_SYSTEM",
sizeof(buf));
3023 if (vp->v_vflag & VV_PROCDEP)
3024 strlcat(buf,
"|VV_PROCDEP",
sizeof(buf));
3025 if (vp->v_vflag & VV_NOKNOTE)
3026 strlcat(buf,
"|VV_NOKNOTE",
sizeof(buf));
3027 if (vp->v_vflag & VV_DELETED)
3028 strlcat(buf,
"|VV_DELETED",
sizeof(buf));
3029 if (vp->v_vflag & VV_MD)
3030 strlcat(buf,
"|VV_MD",
sizeof(buf));
3031 if (vp->v_vflag & VV_FORCEINSMQ)
3032 strlcat(buf,
"|VV_FORCEINSMQ",
sizeof(buf));
3033 flags = vp->v_vflag & ~(VV_ROOT | VV_ISTTY | VV_NOSYNC | VV_ETERNALDEV |
3034 VV_CACHEDLABEL | VV_TEXT | VV_COPYONWRITE | VV_SYSTEM | VV_PROCDEP |
3035 VV_NOKNOTE | VV_DELETED | VV_MD | VV_FORCEINSMQ);
3037 snprintf(buf2,
sizeof(buf2),
"|VV(0x%lx)", flags);
3038 strlcat(buf, buf2,
sizeof(buf));
3040 if (vp->v_iflag & VI_MOUNT)
3041 strlcat(buf,
"|VI_MOUNT",
sizeof(buf));
3042 if (vp->v_iflag & VI_AGE)
3043 strlcat(buf,
"|VI_AGE",
sizeof(buf));
3044 if (vp->v_iflag & VI_DOOMED)
3045 strlcat(buf,
"|VI_DOOMED",
sizeof(buf));
3046 if (vp->v_iflag & VI_FREE)
3047 strlcat(buf,
"|VI_FREE",
sizeof(buf));
3048 if (vp->v_iflag & VI_ACTIVE)
3049 strlcat(buf,
"|VI_ACTIVE",
sizeof(buf));
3050 if (vp->v_iflag & VI_DOINGINACT)
3051 strlcat(buf,
"|VI_DOINGINACT",
sizeof(buf));
3052 if (vp->v_iflag & VI_OWEINACT)
3053 strlcat(buf,
"|VI_OWEINACT",
sizeof(buf));
3054 flags = vp->v_iflag & ~(VI_MOUNT | VI_AGE | VI_DOOMED | VI_FREE |
3055 VI_ACTIVE | VI_DOINGINACT | VI_OWEINACT);
3057 snprintf(buf2,
sizeof(buf2),
"|VI(0x%lx)", flags);
3058 strlcat(buf, buf2,
sizeof(buf));
3060 printf(
" flags (%s)\n", buf + 1);
3061 if (mtx_owned(VI_MTX(vp)))
3063 if (vp->v_object != NULL)
3064 printf(
" v_object %p ref %d pages %d "
3065 "cleanbuf %d dirtybuf %d\n",
3066 vp->v_object, vp->v_object->ref_count,
3067 vp->v_object->resident_page_count,
3068 vp->v_bufobj.bo_dirty.bv_cnt,
3069 vp->v_bufobj.bo_clean.bv_cnt);
3072 if (vp->v_data != NULL)
3081 DB_SHOW_COMMAND(lockedvnods, lockedvnodes)
3083 struct mount *mp, *nmp;
3092 db_printf(
"Locked vnodes\n");
3093 for (mp = TAILQ_FIRST(&
mountlist); mp != NULL; mp = nmp) {
3094 nmp = TAILQ_NEXT(mp, mnt_list);
3095 TAILQ_FOREACH(vp, &mp->mnt_nvnodelist, v_nmntvnodes) {
3096 if (vp->v_type != VMARKER &&
3100 nmp = TAILQ_NEXT(mp, mnt_list);
3107 DB_SHOW_COMMAND(vnode, db_show_vnode)
3113 vp = (
struct vnode *)addr;
3120 DB_SHOW_COMMAND(mount, db_show_mount)
3132 TAILQ_FOREACH(mp, &
mountlist, mnt_list) {
3133 db_printf(
"%p %s on %s (%s)\n", mp,
3134 mp->mnt_stat.f_mntfromname,
3135 mp->mnt_stat.f_mntonname,
3136 mp->mnt_stat.f_fstypename);
3140 db_printf(
"\nMore info: show mount <addr>\n");
3144 mp = (
struct mount *)addr;
3145 db_printf(
"%p %s on %s (%s)\n", mp, mp->mnt_stat.f_mntfromname,
3146 mp->mnt_stat.f_mntonname, mp->mnt_stat.f_fstypename);
3149 mflags = mp->mnt_flag;
3150 #define MNT_FLAG(flag) do { \
3151 if (mflags & (flag)) { \
3152 if (buf[0] != '\0') \
3153 strlcat(buf, ", ", sizeof(buf)); \
3154 strlcat(buf, (#flag) + 4, sizeof(buf)); \
3155 mflags &= ~(flag); \
3158 MNT_FLAG(MNT_RDONLY);
3159 MNT_FLAG(MNT_SYNCHRONOUS);
3160 MNT_FLAG(MNT_NOEXEC);
3161 MNT_FLAG(MNT_NOSUID);
3162 MNT_FLAG(MNT_NFS4ACLS);
3163 MNT_FLAG(MNT_UNION);
3164 MNT_FLAG(MNT_ASYNC);
3165 MNT_FLAG(MNT_SUIDDIR);
3166 MNT_FLAG(MNT_SOFTDEP);
3167 MNT_FLAG(MNT_NOSYMFOLLOW);
3168 MNT_FLAG(MNT_GJOURNAL);
3169 MNT_FLAG(MNT_MULTILABEL);
3171 MNT_FLAG(MNT_NOATIME);
3172 MNT_FLAG(MNT_NOCLUSTERR);
3173 MNT_FLAG(MNT_NOCLUSTERW);
3175 MNT_FLAG(MNT_EXRDONLY);
3176 MNT_FLAG(MNT_EXPORTED);
3177 MNT_FLAG(MNT_DEFEXPORTED);
3178 MNT_FLAG(MNT_EXPORTANON);
3179 MNT_FLAG(MNT_EXKERB);
3180 MNT_FLAG(MNT_EXPUBLIC);
3181 MNT_FLAG(MNT_LOCAL);
3182 MNT_FLAG(MNT_QUOTA);
3183 MNT_FLAG(MNT_ROOTFS);
3185 MNT_FLAG(MNT_IGNORE);
3186 MNT_FLAG(MNT_UPDATE);
3187 MNT_FLAG(MNT_DELEXPORT);
3188 MNT_FLAG(MNT_RELOAD);
3189 MNT_FLAG(MNT_FORCE);
3190 MNT_FLAG(MNT_SNAPSHOT);
3191 MNT_FLAG(MNT_BYFSID);
3195 strlcat(buf,
", ",
sizeof(buf));
3196 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
3197 "0x%016jx", mflags);
3199 db_printf(
" mnt_flag = %s\n", buf);
3202 flags = mp->mnt_kern_flag;
3203 #define MNT_KERN_FLAG(flag) do { \
3204 if (flags & (flag)) { \
3205 if (buf[0] != '\0') \
3206 strlcat(buf, ", ", sizeof(buf)); \
3207 strlcat(buf, (#flag) + 5, sizeof(buf)); \
3211 MNT_KERN_FLAG(MNTK_UNMOUNTF);
3212 MNT_KERN_FLAG(MNTK_ASYNC);
3213 MNT_KERN_FLAG(MNTK_SOFTDEP);
3214 MNT_KERN_FLAG(MNTK_NOINSMNTQ);
3215 MNT_KERN_FLAG(MNTK_DRAINING);
3216 MNT_KERN_FLAG(MNTK_REFEXPIRE);
3217 MNT_KERN_FLAG(MNTK_EXTENDED_SHARED);
3218 MNT_KERN_FLAG(MNTK_SHARED_WRITES);
3219 MNT_KERN_FLAG(MNTK_NO_IOPF);
3220 MNT_KERN_FLAG(MNTK_VGONE_UPPER);
3221 MNT_KERN_FLAG(MNTK_VGONE_WAITER);
3222 MNT_KERN_FLAG(MNTK_LOOKUP_EXCL_DOTDOT);
3223 MNT_KERN_FLAG(MNTK_MARKER);
3224 MNT_KERN_FLAG(MNTK_NOASYNC);
3225 MNT_KERN_FLAG(MNTK_UNMOUNT);
3226 MNT_KERN_FLAG(MNTK_MWAIT);
3227 MNT_KERN_FLAG(MNTK_SUSPEND);
3228 MNT_KERN_FLAG(MNTK_SUSPEND2);
3229 MNT_KERN_FLAG(MNTK_SUSPENDED);
3230 MNT_KERN_FLAG(MNTK_MPSAFE);
3231 MNT_KERN_FLAG(MNTK_LOOKUP_SHARED);
3232 MNT_KERN_FLAG(MNTK_NOKNOTE);
3233 #undef MNT_KERN_FLAG
3236 strlcat(buf,
", ",
sizeof(buf));
3237 snprintf(buf + strlen(buf),
sizeof(buf) - strlen(buf),
3240 db_printf(
" mnt_kern_flag = %s\n", buf);
3242 db_printf(
" mnt_opt = ");
3243 opt = TAILQ_FIRST(mp->mnt_opt);
3245 db_printf(
"%s", opt->name);
3246 opt = TAILQ_NEXT(opt, link);
3247 while (opt != NULL) {
3248 db_printf(
", %s", opt->name);
3249 opt = TAILQ_NEXT(opt, link);
3255 db_printf(
" mnt_stat = { version=%u type=%u flags=0x%016jx "
3256 "bsize=%ju iosize=%ju blocks=%ju bfree=%ju bavail=%jd files=%ju "
3257 "ffree=%jd syncwrites=%ju asyncwrites=%ju syncreads=%ju "
3258 "asyncreads=%ju namemax=%u owner=%u fsid=[%d, %d] }\n",
3259 (u_int)sp->f_version, (u_int)sp->f_type, (uintmax_t)sp->f_flags,
3260 (uintmax_t)sp->f_bsize, (uintmax_t)sp->f_iosize,
3261 (uintmax_t)sp->f_blocks, (uintmax_t)sp->f_bfree,
3262 (intmax_t)sp->f_bavail, (uintmax_t)sp->f_files,
3263 (intmax_t)sp->f_ffree, (uintmax_t)sp->f_syncwrites,
3264 (uintmax_t)sp->f_asyncwrites, (uintmax_t)sp->f_syncreads,
3265 (uintmax_t)sp->f_asyncreads, (u_int)sp->f_namemax,
3266 (u_int)sp->f_owner, (
int)sp->f_fsid.val[0], (
int)sp->f_fsid.val[1]);
3268 db_printf(
" mnt_cred = { uid=%u ruid=%u",
3269 (u_int)mp->mnt_cred->cr_uid, (u_int)mp->mnt_cred->cr_ruid);
3270 if (
jailed(mp->mnt_cred))
3271 db_printf(
", jail=%d", mp->mnt_cred->cr_prison->pr_id);
3273 db_printf(
" mnt_ref = %d\n", mp->mnt_ref);
3274 db_printf(
" mnt_gen = %d\n", mp->mnt_gen);
3275 db_printf(
" mnt_nvnodelistsize = %d\n", mp->mnt_nvnodelistsize);
3276 db_printf(
" mnt_activevnodelistsize = %d\n",
3277 mp->mnt_activevnodelistsize);
3278 db_printf(
" mnt_writeopcount = %d\n", mp->mnt_writeopcount);
3279 db_printf(
" mnt_maxsymlinklen = %d\n", mp->mnt_maxsymlinklen);
3280 db_printf(
" mnt_iosize_max = %d\n", mp->mnt_iosize_max);
3281 db_printf(
" mnt_hashseed = %u\n", mp->mnt_hashseed);
3282 db_printf(
" mnt_lockref = %d\n", mp->mnt_lockref);
3283 db_printf(
" mnt_secondary_writes = %d\n", mp->mnt_secondary_writes);
3284 db_printf(
" mnt_secondary_accwrites = %d\n",
3285 mp->mnt_secondary_accwrites);
3286 db_printf(
" mnt_gjprovider = %s\n",
3287 mp->mnt_gjprovider != NULL ? mp->mnt_gjprovider :
"NULL");
3289 db_printf(
"\n\nList of active vnodes\n");
3290 TAILQ_FOREACH(vp, &mp->mnt_activevnodelist, v_actfreelist) {
3291 if (vp->v_type != VMARKER) {
3297 db_printf(
"\n\nList of inactive vnodes\n");
3298 TAILQ_FOREACH(vp, &mp->mnt_nvnodelist, v_nmntvnodes) {
3299 if (vp->v_type != VMARKER && (vp->v_iflag & VI_ACTIVE) == 0) {
3314 struct xvfsconf xvfsp;
3316 bzero(&xvfsp,
sizeof(xvfsp));
3317 strcpy(xvfsp.vfc_name, vfsp->vfc_name);
3318 xvfsp.vfc_typenum = vfsp->vfc_typenum;
3319 xvfsp.vfc_refcount = vfsp->vfc_refcount;
3320 xvfsp.vfc_flags = vfsp->vfc_flags;
3325 xvfsp.vfc_vfsops = NULL;
3326 xvfsp.vfc_next = NULL;
3327 return (SYSCTL_OUT(req, &xvfsp,
sizeof(xvfsp)));
3332 uint32_t vfc_vfsops;
3333 char vfc_name[MFSNAMELEN];
3334 int32_t vfc_typenum;
3335 int32_t vfc_refcount;
3341 vfsconf2x32(
struct sysctl_req *req,
struct vfsconf *vfsp)
3343 struct xvfsconf32 xvfsp;
3345 strcpy(xvfsp.vfc_name, vfsp->vfc_name);
3346 xvfsp.vfc_typenum = vfsp->vfc_typenum;
3347 xvfsp.vfc_refcount = vfsp->vfc_refcount;
3348 xvfsp.vfc_flags = vfsp->vfc_flags;
3349 xvfsp.vfc_vfsops = 0;
3351 return (SYSCTL_OUT(req, &xvfsp,
sizeof(xvfsp)));
3365 TAILQ_FOREACH(vfsp, &
vfsconf, vfc_list) {
3367 if (req->flags & SCTL_MASK32)
3368 error = vfsconf2x32(req, vfsp);
3378 SYSCTL_PROC(_vfs, OID_AUTO, conflist, CTLTYPE_OPAQUE | CTLFLAG_RD,
3380 "S,xvfsconf",
"List of all configured filesystems");
3382 #ifndef BURN_BRIDGES
3388 int *
name = (
int *)arg1 - 1;
3389 u_int namelen = arg2 + 1;
3392 printf(
"WARNING: userland calling deprecated sysctl, "
3393 "please rebuild world\n");
3395 #if 1 || defined(COMPAT_PRELITE2)
3402 case VFS_MAXTYPENUM:
3405 return (SYSCTL_OUT(req, &
maxvfsconf,
sizeof(
int)));
3409 TAILQ_FOREACH(vfsp, &
vfsconf, vfc_list)
3410 if (vfsp->vfc_typenum == name[2])
3413 return (EOPNOTSUPP);
3415 if (req->flags & SCTL_MASK32)
3416 return (vfsconf2x32(req, vfsp));
3421 return (EOPNOTSUPP);
3424 static SYSCTL_NODE(_vfs, VFS_GENERIC,
generic, CTLFLAG_RD | CTLFLAG_SKIP,
3427 #if 1 || defined(COMPAT_PRELITE2)
3434 struct ovfsconf ovfs;
3436 TAILQ_FOREACH(vfsp, &
vfsconf, vfc_list) {
3437 bzero(&ovfs,
sizeof(ovfs));
3438 ovfs.vfc_vfsops = vfsp->vfc_vfsops;
3439 strcpy(ovfs.vfc_name, vfsp->vfc_name);
3440 ovfs.vfc_index = vfsp->vfc_typenum;
3441 ovfs.vfc_refcount = vfsp->vfc_refcount;
3442 ovfs.vfc_flags = vfsp->vfc_flags;
3443 error = SYSCTL_OUT(req, &ovfs,
sizeof ovfs);
3453 #define KINFO_VNODESLOP 10
3460 sysctl_vnode(SYSCTL_HANDLER_ARGS)
3474 return (SYSCTL_OUT(req, 0, len));
3479 xvn =
malloc(len, M_TEMP, M_ZERO | M_WAITOK);
3482 TAILQ_FOREACH(mp, &
mountlist, mnt_list) {
3483 if (
vfs_busy(mp, MBF_NOWAIT | MBF_MNTLSTLOCK))
3486 TAILQ_FOREACH(vp, &mp->mnt_nvnodelist, v_nmntvnodes) {
3490 xvn[n].xv_size =
sizeof *xvn;
3491 xvn[n].xv_vnode = vp;
3493 #define XV_COPY(field) xvn[n].xv_##field = vp->v_##field
3495 XV_COPY(writecount);
3501 xvn[n].xv_flag = vp->v_vflag;
3503 switch (vp->v_type) {
3510 if (vp->v_rdev == NULL) {
3514 xvn[n].xv_dev = dev2udev(vp->v_rdev);
3517 xvn[n].xv_socket = vp->v_socket;
3520 xvn[n].xv_fifo = vp->v_fifoinfo;
3540 error = SYSCTL_OUT(req, xvn, n *
sizeof *xvn);
3545 SYSCTL_PROC(_kern, KERN_VNODE, vnode, CTLTYPE_OPAQUE|CTLFLAG_RD,
3546 0, 0, sysctl_vnode,
"S,xvnode",
"");
3560 CTR1(KTR_VFS,
"%s: unmounting all filesystems", __func__);
3579 if (strcmp(mp->mnt_vfc->vfc_name,
"devfs") != 0) {
3580 printf(
"unmount of %s failed (",
3581 mp->mnt_stat.f_mntonname);
3600 struct vnode *vp, *mvp;
3601 struct vm_object *obj;
3603 CTR2(KTR_VFS,
"%s: mp %p", __func__, mp);
3604 MNT_VNODE_FOREACH_ACTIVE(vp, mp, mvp) {
3606 if (obj != NULL && (obj->flags & OBJ_MIGHTBEDIRTY) != 0 &&
3607 (flags == MNT_WAIT || VOP_ISLOCKED(vp) == 0)) {
3609 LK_EXCLUSIVE | LK_RETRY | LK_INTERLOCK,
3611 if (vp->v_vflag & VV_NOSYNC) {
3618 VM_OBJECT_LOCK(obj);
3619 vm_object_page_clean(obj, 0, 0,
3621 OBJPC_SYNC : OBJPC_NOSYNC);
3622 VM_OBJECT_UNLOCK(obj);
3637 uma_zfree(vnodepoll_zone, vi);
3644 knlist_clear(&vi->vpi_selinfo.si_note, 1);
3655 struct vpollinfo *vi;
3657 if (vp->v_pollinfo != NULL)
3659 vi = uma_zalloc(vnodepoll_zone, M_WAITOK);
3660 mtx_init(&vi->vpi_lock,
"vnode pollinfo", NULL, MTX_DEF);
3664 if (vp->v_pollinfo != NULL) {
3669 vp->v_pollinfo = vi;
3686 mtx_lock(&vp->v_pollinfo->vpi_lock);
3687 if (vp->v_pollinfo->vpi_revents & events) {
3695 events &= vp->v_pollinfo->vpi_revents;
3696 vp->v_pollinfo->vpi_revents &= ~events;
3698 mtx_unlock(&vp->v_pollinfo->vpi_lock);
3701 vp->v_pollinfo->vpi_events |= events;
3702 selrecord(td, &vp->v_pollinfo->vpi_selinfo);
3703 mtx_unlock(&vp->v_pollinfo->vpi_lock);
3710 #define sync_close ((int (*)(struct vop_close_args *))nullop)
3711 static int sync_fsync(
struct vop_fsync_args *);
3716 .vop_bypass = VOP_EOPNOTSUPP,
3734 static long start, incr, next;
3738 error =
getnewvnode(
"syncer", mp, &sync_vnodeops, &vp);
3740 panic(
"vfs_allocate_syncvnode: getnewvnode() failed");
3742 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
3743 vp->v_vflag |= VV_FORCEINSMQ;
3746 panic(
"vfs_allocate_syncvnode: insmntque() failed");
3747 vp->v_vflag &= ~VV_FORCEINSMQ;
3756 if (next == 0 || next > syncer_maxdelay) {
3760 start = syncer_maxdelay / 2;
3761 incr = syncer_maxdelay;
3769 mtx_lock(&sync_mtx);
3771 if (mp->mnt_syncer == NULL) {
3772 mp->mnt_syncer = vp;
3775 mtx_unlock(&sync_mtx);
3778 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
3789 mtx_lock(&sync_mtx);
3790 vp = mp->mnt_syncer;
3792 mp->mnt_syncer = NULL;
3793 mtx_unlock(&sync_mtx);
3804 struct vnode *syncvp = ap->a_vp;
3805 struct mount *mp = syncvp->v_mount;
3812 if (ap->a_waitfor != MNT_LAZY)
3818 bo = &syncvp->v_bufobj;
3833 save = curthread_pflags_set(TDP_SYNCIO);
3835 error = VFS_SYNC(mp, MNT_LAZY);
3836 curthread_pflags_restore(save);
3861 struct vnode *vp = ap->a_vp;
3866 mtx_lock(&sync_mtx);
3867 if (vp->v_mount->mnt_syncer == vp)
3868 vp->v_mount->mnt_syncer = NULL;
3869 if (bo->bo_flag & BO_ONWORKLST) {
3870 LIST_REMOVE(bo, bo_synclist);
3871 syncer_worklist_len--;
3873 bo->bo_flag &= ~BO_ONWORKLST;
3875 mtx_unlock(&sync_mtx);
3891 if (vp->v_type != VCHR)
3893 else if (vp->v_rdev == NULL)
3895 else if (vp->v_rdev->si_devsw == NULL)
3897 else if (!(vp->v_rdev->si_devsw->d_flags & D_DISK))
3902 return (error == 0);
3913 vaccess(
enum vtype
type, mode_t file_mode, uid_t file_uid, gid_t file_gid,
3914 accmode_t
accmode,
struct ucred *cred,
int *privused)
3916 accmode_t dac_granted;
3917 accmode_t priv_granted;
3919 KASSERT((accmode & ~(VEXEC | VWRITE | VREAD | VADMIN | VAPPEND)) == 0,
3920 (
"invalid bit in accmode"));
3921 KASSERT((accmode & VAPPEND) == 0 || (accmode & VWRITE),
3922 (
"VAPPEND without VWRITE"));
3929 if (privused != NULL)
3935 if (cred->cr_uid == file_uid) {
3936 dac_granted |= VADMIN;
3937 if (file_mode & S_IXUSR)
3938 dac_granted |= VEXEC;
3939 if (file_mode & S_IRUSR)
3940 dac_granted |= VREAD;
3941 if (file_mode & S_IWUSR)
3942 dac_granted |= (VWRITE | VAPPEND);
3944 if ((accmode & dac_granted) ==
accmode)
3952 if (file_mode & S_IXGRP)
3953 dac_granted |= VEXEC;
3954 if (file_mode & S_IRGRP)
3955 dac_granted |= VREAD;
3956 if (file_mode & S_IWGRP)
3957 dac_granted |= (VWRITE | VAPPEND);
3959 if ((accmode & dac_granted) ==
accmode)
3966 if (file_mode & S_IXOTH)
3967 dac_granted |= VEXEC;
3968 if (file_mode & S_IROTH)
3969 dac_granted |= VREAD;
3970 if (file_mode & S_IWOTH)
3971 dac_granted |= (VWRITE | VAPPEND);
3972 if ((accmode & dac_granted) ==
accmode)
3989 if ((accmode & VEXEC) && ((dac_granted & VEXEC) == 0) &&
3991 priv_granted |= VEXEC;
3998 if ((accmode & VEXEC) && ((dac_granted & VEXEC) == 0) &&
3999 (file_mode & (S_IXUSR | S_IXGRP | S_IXOTH)) != 0 &&
4001 priv_granted |= VEXEC;
4004 if ((accmode & VREAD) && ((dac_granted & VREAD) == 0) &&
4006 priv_granted |= VREAD;
4008 if ((accmode & VWRITE) && ((dac_granted & VWRITE) == 0) &&
4010 priv_granted |= (VWRITE | VAPPEND);
4012 if ((accmode & VADMIN) && ((dac_granted & VADMIN) == 0) &&
4014 priv_granted |= VADMIN;
4016 if ((accmode & (priv_granted | dac_granted)) ==
accmode) {
4018 if (privused != NULL)
4023 return ((accmode & VADMIN) ? EPERM : EACCES);
4032 struct thread *td, accmode_t
accmode)
4045 switch (attrnamespace) {
4046 case EXTATTR_NAMESPACE_SYSTEM:
4049 case EXTATTR_NAMESPACE_USER:
4050 return (VOP_ACCESS(vp, accmode, cred, td));
4056 #ifdef DEBUG_VFS_LOCKS
4061 #define IGNORE_LOCK(vp) (panicstr != NULL || (vp) == NULL || \
4062 (vp)->v_type == VCHR || (vp)->v_type == VBAD)
4064 int vfs_badlock_ddb = 1;
4065 SYSCTL_INT(_debug, OID_AUTO, vfs_badlock_ddb, CTLFLAG_RW, &vfs_badlock_ddb, 0,
4066 "Drop into debugger on lock violation");
4068 int vfs_badlock_mutex = 1;
4069 SYSCTL_INT(_debug, OID_AUTO, vfs_badlock_mutex, CTLFLAG_RW, &vfs_badlock_mutex,
4070 0,
"Check for interlock across VOPs");
4072 int vfs_badlock_print = 1;
4073 SYSCTL_INT(_debug, OID_AUTO, vfs_badlock_print, CTLFLAG_RW, &vfs_badlock_print,
4074 0,
"Print lock violations");
4077 int vfs_badlock_backtrace = 1;
4078 SYSCTL_INT(_debug, OID_AUTO, vfs_badlock_backtrace, CTLFLAG_RW,
4079 &vfs_badlock_backtrace, 0,
"Print backtrace at lock violations");
4083 vfs_badlock(
const char *msg,
const char *str,
struct vnode *vp)
4087 if (vfs_badlock_backtrace)
4090 if (vfs_badlock_print)
4091 printf(
"%s: %p %s\n", str, (
void *)vp, msg);
4092 if (vfs_badlock_ddb)
4093 kdb_enter(KDB_WHY_VFSLOCK,
"lock violation");
4097 assert_vi_locked(
struct vnode *vp,
const char *str)
4100 if (vfs_badlock_mutex && !mtx_owned(VI_MTX(vp)))
4101 vfs_badlock(
"interlock is not locked but should be", str, vp);
4105 assert_vi_unlocked(
struct vnode *vp,
const char *str)
4108 if (vfs_badlock_mutex && mtx_owned(VI_MTX(vp)))
4109 vfs_badlock(
"interlock is locked but should not be", str, vp);
4113 assert_vop_locked(
struct vnode *vp,
const char *str)
4117 if (!IGNORE_LOCK(vp)) {
4118 locked = VOP_ISLOCKED(vp);
4119 if (locked == 0 || locked == LK_EXCLOTHER)
4120 vfs_badlock(
"is not locked but should be", str, vp);
4125 assert_vop_unlocked(
struct vnode *vp,
const char *str)
4128 if (!IGNORE_LOCK(vp) && VOP_ISLOCKED(vp) == LK_EXCLUSIVE)
4129 vfs_badlock(
"is locked but should not be", str, vp);
4133 assert_vop_elocked(
struct vnode *vp,
const char *str)
4136 if (!IGNORE_LOCK(vp) && VOP_ISLOCKED(vp) != LK_EXCLUSIVE)
4137 vfs_badlock(
"is not exclusive locked but should be", str, vp);
4142 assert_vop_elocked_other(
struct vnode *vp,
const char *str)
4145 if (!IGNORE_LOCK(vp) && VOP_ISLOCKED(vp) != LK_EXCLOTHER)
4146 vfs_badlock(
"is not exclusive locked by another thread",
4151 assert_vop_slocked(
struct vnode *vp,
const char *str)
4154 if (!IGNORE_LOCK(vp) && VOP_ISLOCKED(vp) != LK_SHARED)
4155 vfs_badlock(
"is not locked shared but should be", str, vp);
4164 if (ap->a_tvp != NULL)
4166 if (ap->a_tdvp == ap->a_tvp)
4177 struct vop_rename_args *a = ap;
4179 #ifdef DEBUG_VFS_LOCKS
4181 ASSERT_VI_UNLOCKED(a->a_tvp,
"VOP_RENAME");
4182 ASSERT_VI_UNLOCKED(a->a_tdvp,
"VOP_RENAME");
4183 ASSERT_VI_UNLOCKED(a->a_fvp,
"VOP_RENAME");
4184 ASSERT_VI_UNLOCKED(a->a_fdvp,
"VOP_RENAME");
4187 if (a->a_tdvp->v_vnlock != a->a_fdvp->v_vnlock &&
4188 (a->a_tvp == NULL || a->a_tvp->v_vnlock != a->a_fdvp->v_vnlock))
4189 ASSERT_VOP_UNLOCKED(a->a_fdvp,
"vop_rename: fdvp locked");
4190 if (a->a_tvp == NULL || a->a_tvp->v_vnlock != a->a_fvp->v_vnlock)
4191 ASSERT_VOP_UNLOCKED(a->a_fvp,
"vop_rename: fvp locked");
4195 ASSERT_VOP_LOCKED(a->a_tvp,
"vop_rename: tvp not locked");
4196 ASSERT_VOP_LOCKED(a->a_tdvp,
"vop_rename: tdvp not locked");
4198 if (a->a_tdvp != a->a_fdvp)
4200 if (a->a_tvp != a->a_fvp)
4210 #ifdef DEBUG_VFS_LOCKS
4211 struct vop_strategy_args *a;
4220 if ((bp->b_flags & B_CLUSTER) != 0)
4223 if (
panicstr == NULL && !BUF_ISLOCKED(bp)) {
4224 if (vfs_badlock_print)
4226 "VOP_STRATEGY: bp is not locked but should be\n");
4227 if (vfs_badlock_ddb)
4228 kdb_enter(KDB_WHY_VFSLOCK,
"lock violation");
4236 #ifdef DEBUG_VFS_LOCKS
4237 struct vop_lock1_args *a = ap;
4239 if ((a->a_flags & LK_INTERLOCK) == 0)
4240 ASSERT_VI_UNLOCKED(a->a_vp,
"VOP_LOCK");
4242 ASSERT_VI_LOCKED(a->a_vp,
"VOP_LOCK");
4249 #ifdef DEBUG_VFS_LOCKS
4250 struct vop_lock1_args *a = ap;
4252 ASSERT_VI_UNLOCKED(a->a_vp,
"VOP_LOCK");
4253 if (rc == 0 && (a->a_flags & LK_EXCLOTHER) == 0)
4254 ASSERT_VOP_LOCKED(a->a_vp,
"VOP_LOCK");
4261 #ifdef DEBUG_VFS_LOCKS
4262 struct vop_unlock_args *a = ap;
4264 if (a->a_flags & LK_INTERLOCK)
4265 ASSERT_VI_LOCKED(a->a_vp,
"VOP_UNLOCK");
4266 ASSERT_VOP_LOCKED(a->a_vp,
"VOP_UNLOCK");
4273 #ifdef DEBUG_VFS_LOCKS
4274 struct vop_unlock_args *a = ap;
4276 if (a->a_flags & LK_INTERLOCK)
4277 ASSERT_VI_UNLOCKED(a->a_vp,
"VOP_UNLOCK");
4284 struct vop_create_args *a = ap;
4287 VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE);
4293 struct vop_deleteextattr_args *a = ap;
4296 VFS_KNOTE_LOCKED(a->a_vp, NOTE_ATTRIB);
4302 struct vop_link_args *a = ap;
4305 VFS_KNOTE_LOCKED(a->a_vp, NOTE_LINK);
4306 VFS_KNOTE_LOCKED(a->a_tdvp, NOTE_WRITE);
4313 struct vop_mkdir_args *a = ap;
4316 VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE | NOTE_LINK);
4322 struct vop_mknod_args *a = ap;
4325 VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE);
4331 struct vop_remove_args *a = ap;
4334 VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE);
4335 VFS_KNOTE_LOCKED(a->a_vp, NOTE_DELETE);
4342 struct vop_rename_args *a = ap;
4345 VFS_KNOTE_UNLOCKED(a->a_fdvp, NOTE_WRITE);
4346 VFS_KNOTE_UNLOCKED(a->a_tdvp, NOTE_WRITE);
4347 VFS_KNOTE_UNLOCKED(a->a_fvp, NOTE_RENAME);
4349 VFS_KNOTE_UNLOCKED(a->a_tvp, NOTE_DELETE);
4351 if (a->a_tdvp != a->a_fdvp)
4353 if (a->a_tvp != a->a_fvp)
4363 struct vop_rmdir_args *a = ap;
4366 VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE | NOTE_LINK);
4367 VFS_KNOTE_LOCKED(a->a_vp, NOTE_DELETE);
4374 struct vop_setattr_args *a = ap;
4377 VFS_KNOTE_LOCKED(a->a_vp, NOTE_ATTRIB);
4383 struct vop_setextattr_args *a = ap;
4386 VFS_KNOTE_LOCKED(a->a_vp, NOTE_ATTRIB);
4392 struct vop_symlink_args *a = ap;
4395 VFS_KNOTE_LOCKED(a->a_dvp, NOTE_WRITE);
4430 kn->kn_flags |= EV_CLEAR;
4446 kn->kn_fflags |= hint;
4447 return (kn->kn_fflags != 0);
4457 error = SYSCTL_IN(req, &vc,
sizeof(vc));
4460 if (vc.vc_vers != VFS_CTL_VERS1)
4466 if (strcmp(vc.vc_fstypename,
"*") != 0 &&
4467 strcmp(vc.vc_fstypename, mp->mnt_vfc->vfc_name) != 0) {
4471 VCTLTOREQ(&vc, req);
4472 error = VFS_SYSCTL(mp, vc.vc_op, req);
4477 SYSCTL_PROC(_vfs, OID_AUTO, ctl, CTLTYPE_OPAQUE | CTLFLAG_WR,
4491 return (((u_quad_t)bt.sec << 32LL) | (bt.frac >> 32LL));
4517 struct vnode *vp = arg;
4519 vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
4525 struct vnode *vp = arg;
4533 #ifdef DEBUG_VFS_LOCKS
4534 struct vnode *vp = arg;
4536 ASSERT_VOP_LOCKED(vp,
"vfs_knl_assert_locked");
4543 #ifdef DEBUG_VFS_LOCKS
4544 struct vnode *vp = arg;
4546 ASSERT_VOP_UNLOCKED(vp,
"vfs_knl_assert_unlocked");
4553 struct vnode *vp = ap->a_vp;
4554 struct knote *kn = ap->a_kn;
4557 switch (kn->kn_filter) {
4571 kn->kn_hook = (caddr_t)vp;
4574 if (vp->v_pollinfo == NULL)
4576 knl = &vp->v_pollinfo->vpi_selinfo.si_note;
4589 struct vnode *vp = (
struct vnode *)kn->kn_hook;
4591 KASSERT(vp->v_pollinfo != NULL, (
"Missing v_pollinfo"));
4600 struct vnode *vp = (
struct vnode *)kn->kn_hook;
4608 if (hint == NOTE_REVOKE) {
4610 kn->kn_flags |= (EV_EOF | EV_ONESHOT);
4615 if (VOP_GETATTR(vp, &va, curthread->td_ucred))
4619 kn->kn_data = va.va_size - kn->kn_fp->f_offset;
4620 res = (kn->kn_data != 0);
4629 struct vnode *vp = (
struct vnode *)kn->kn_hook;
4637 if (hint == NOTE_REVOKE)
4638 kn->kn_flags |= (EV_EOF | EV_ONESHOT);
4648 struct vnode *vp = (
struct vnode *)kn->kn_hook;
4652 if (kn->kn_sfflags & hint)
4653 kn->kn_fflags |= hint;
4654 if (hint == NOTE_REVOKE) {
4655 kn->kn_flags |= EV_EOF;
4659 res = (kn->kn_fflags != 0);
4669 if (dp->d_reclen > ap->a_uio->uio_resid)
4670 return (ENAMETOOLONG);
4671 error =
uiomove(dp, dp->d_reclen, ap->a_uio);
4673 if (ap->a_ncookies != NULL) {
4674 if (ap->a_cookies != NULL)
4675 free(ap->a_cookies, M_TEMP);
4676 ap->a_cookies = NULL;
4677 *ap->a_ncookies = 0;
4681 if (ap->a_ncookies == NULL)
4684 KASSERT(ap->a_cookies,
4685 (
"NULL ap->a_cookies value with non-NULL ap->a_ncookies!"));
4687 *ap->a_cookies =
realloc(*ap->a_cookies,
4688 (*ap->a_ncookies + 1) *
sizeof(u_long), M_TEMP, M_WAITOK | M_ZERO);
4689 (*ap->a_cookies)[*ap->a_ncookies] = off;
4690 *ap->a_ncookies += 1;
4706 VFS_ASSERT_GIANT(mp);
4707 ASSERT_VOP_LOCKED(vp,
"vfs_mark_atime");
4708 if (mp != NULL && (mp->mnt_flag & (MNT_NOATIME | MNT_RDONLY)) == 0)
4709 (void)VOP_MARKATIME(vp);
4731 if (*accmode & VEXPLICIT_DENY) {
4742 if (*accmode & (VDELETE_CHILD | VDELETE))
4745 if (*accmode & VADMIN_PERMS) {
4746 *accmode &= ~VADMIN_PERMS;
4754 *accmode &= ~(VSTAT_PERMS | VSYNCHRONIZE);
4766 MALLOC_DEFINE(M_VNODE_MARKER,
"vnodemarker",
"vnode marker");
4776 KASSERT((*mvp)->v_mount == mp, (
"marker vnode mount list mismatch"));
4777 vp = TAILQ_NEXT(*mvp, v_nmntvnodes);
4778 while (vp != NULL && (vp->v_type == VMARKER ||
4779 (vp->v_iflag & VI_DOOMED) != 0))
4780 vp = TAILQ_NEXT(vp, v_nmntvnodes);
4786 mtx_assert(MNT_MTX(mp), MA_NOTOWNED);
4789 TAILQ_REMOVE(&mp->mnt_nvnodelist, *mvp, v_nmntvnodes);
4790 TAILQ_INSERT_AFTER(&mp->mnt_nvnodelist, vp, *mvp, v_nmntvnodes);
4801 *mvp =
malloc(
sizeof(
struct vnode), M_VNODE_MARKER, M_WAITOK | M_ZERO);
4804 (*mvp)->v_type = VMARKER;
4806 vp = TAILQ_FIRST(&mp->mnt_nvnodelist);
4807 while (vp != NULL && (vp->v_type == VMARKER ||
4808 (vp->v_iflag & VI_DOOMED) != 0))
4809 vp = TAILQ_NEXT(vp, v_nmntvnodes);
4815 free(*mvp, M_VNODE_MARKER);
4819 (*mvp)->v_mount = mp;
4820 TAILQ_INSERT_AFTER(&mp->mnt_nvnodelist, vp, *mvp, v_nmntvnodes);
4836 mtx_assert(MNT_MTX(mp), MA_OWNED);
4838 KASSERT((*mvp)->v_mount == mp, (
"marker vnode mount list mismatch"));
4839 TAILQ_REMOVE(&mp->mnt_nvnodelist, *mvp, v_nmntvnodes);
4842 free(*mvp, M_VNODE_MARKER);
4854 KASSERT((*mvp)->v_mount == mp, (
"marker vnode mount list mismatch"));
4859 free(*mvp, M_VNODE_MARKER);
4864 #define ALWAYS_YIELD (mp_ncpus == 1)
4866 #define ALWAYS_YIELD 1
4869 static struct vnode *
4872 struct vnode *vp, *nvp;
4874 mtx_assert(&vnode_free_list_mtx, MA_OWNED);
4875 KASSERT((*mvp)->v_mount == mp, (
"marker vnode mount list mismatch"));
4877 vp = TAILQ_NEXT(*mvp, v_actfreelist);
4878 TAILQ_REMOVE(&mp->mnt_activevnodelist, *mvp, v_actfreelist);
4879 while (vp != NULL) {
4880 if (vp->v_type == VMARKER) {
4881 vp = TAILQ_NEXT(vp, v_actfreelist);
4884 if (!VI_TRYLOCK(vp)) {
4886 TAILQ_INSERT_BEFORE(vp, *mvp, v_actfreelist);
4887 mtx_unlock(&vnode_free_list_mtx);
4889 mtx_lock(&vnode_free_list_mtx);
4894 KASSERT(vp->v_type != VMARKER, (
"locked marker %p", vp));
4895 KASSERT(vp->v_mount == mp || vp->v_mount == NULL,
4896 (
"alien vnode on the active list %p %p", vp, mp));
4897 if (vp->v_mount == mp && (vp->v_iflag & VI_DOOMED) == 0)
4899 nvp = TAILQ_NEXT(vp, v_actfreelist);
4906 mtx_unlock(&vnode_free_list_mtx);
4910 TAILQ_INSERT_AFTER(&mp->mnt_activevnodelist, vp, *mvp, v_actfreelist);
4911 mtx_unlock(&vnode_free_list_mtx);
4912 ASSERT_VI_LOCKED(vp,
"active iter");
4913 KASSERT((vp->v_iflag & VI_ACTIVE) != 0, (
"Non-active vp %p", vp));
4924 mtx_lock(&vnode_free_list_mtx);
4933 *mvp =
malloc(
sizeof(
struct vnode), M_VNODE_MARKER, M_WAITOK | M_ZERO);
4937 (*mvp)->v_type = VMARKER;
4938 (*mvp)->v_mount = mp;
4940 mtx_lock(&vnode_free_list_mtx);
4941 vp = TAILQ_FIRST(&mp->mnt_activevnodelist);
4943 mtx_unlock(&vnode_free_list_mtx);
4947 TAILQ_INSERT_BEFORE(vp, *mvp, v_actfreelist);
4958 mtx_lock(&vnode_free_list_mtx);
4959 TAILQ_REMOVE(&mp->mnt_activevnodelist, *mvp, v_actfreelist);
4960 mtx_unlock(&vnode_free_list_mtx);
static void vnlru_free(int)
void lockdestroy(struct lock *lk)
static int vlrureclaim(struct mount *mp)
void vfs_event_signal(fsid_t *fsid, uint32_t event, intptr_t data __unused)
int vfs_suser(struct mount *mp, struct thread *td)
int count_dev(struct cdev *dev)
void vfs_allocate_syncvnode(struct mount *mp)
int vinvalbuf(struct vnode *vp, int flags, int slpflag, int slptimeo)
static void mnt_vnode_markerfree_active(struct vnode **mvp, struct mount *mp)
volatile time_t time_second
static int sysctl_vfs_conflist(SYSCTL_HANDLER_ARGS)
static int vfs_sysctl(SYSCTL_HANDLER_ARGS)
void * realloc(void *addr, unsigned long size, struct malloc_type *mtp, int flags)
void sched_prio(struct thread *td, u_char prio)
void * hashinit(int elements, struct malloc_type *type, u_long *hashmask)
static void insmntque_stddtr(struct vnode *vp, void *dtr_arg)
static int sysctl_vfs_ctl(SYSCTL_HANDLER_ARGS)
int bufobj_wwait(struct bufobj *bo, int slpflag, int timeo)
static void filt_fsdetach(struct knote *kn)
static void v_upgrade_usecount(struct vnode *)
int snprintf(char *str, size_t size, const char *format,...)
void vfs_deallocate_syncvnode(struct mount *mp)
int priv_check_cred(struct ucred *cred, int priv, int flags)
void selrecord(struct thread *selector, struct selinfo *sip)
void vfs_rel(struct mount *mp)
static int filt_fsattach(struct knote *kn)
static int flushbuflist(struct bufv *bufv, int flags, struct bufobj *bo, int slpflag, int slptimeo)
static void vputx(struct vnode *vp, int func)
void * malloc(unsigned long size, struct malloc_type *mtp, int flags)
enum vtype iftovt_tab[16]
void vop_symlink_post(void *ap, int rc)
void cache_purge(struct vnode *vp)
void rangelock_destroy(struct rangelock *lock)
static void v_decr_useonly(struct vnode *)
static void destroy_vpollinfo(struct vpollinfo *vi)
void __mnt_vnode_markerfree_active(struct vnode **mvp, struct mount *mp)
void panic(const char *fmt,...)
int vget(struct vnode *vp, int flags, struct thread *td)
void vop_unlock_pre(void *ap)
void vn_finished_write(struct mount *mp)
static struct vop_vector sync_vnodeops
void knote(struct knlist *list, long hint, int lockflags)
void kproc_shutdown(void *arg, int howto)
int prison_check(struct ucred *cred1, struct ucred *cred2)
void vop_create_post(void *ap, int rc)
static int sync_reclaim(struct vop_reclaim_args *)
void vattr_null(struct vattr *vap)
static int getnewvnode_wait(int suspended)
static struct kproc_desc vnlru_kp
int vfs_kqfilter(struct vop_kqfilter_args *ap)
static void filt_vfsdetach(struct knote *kn)
void brelse(struct buf *bp)
int dounmount(struct mount *mp, int flags, struct thread *td)
void vfs_notify_upper(struct vnode *vp, int event)
SYSCTL_PROC(_vfs, OID_AUTO, worklist_len, CTLTYPE_INT|CTLFLAG_RD, NULL, 0, sysctl_vfs_worklist_len,"I","Syncer thread worklist length")
static struct filterops vfsvnode_filtops
int vrefcnt(struct vnode *vp)
int vop_stdislocked(struct vop_islocked_args *ap)
void knlist_destroy(struct knlist *knl)
void vop_rename_fail(struct vop_rename_args *ap)
void vop_setattr_post(void *ap, int rc)
int vaccess(enum vtype type, mode_t file_mode, uid_t file_uid, gid_t file_gid, accmode_t accmode, struct ucred *cred, int *privused)
static void v_incr_usecount(struct vnode *)
static void buf_vlist_add(struct buf *bp, struct bufobj *bo, b_xflags_t xflags)
static struct kproc_desc up_kp
static void notify_lowervp_vfs_dummy(struct mount *mp __unused, struct vnode *lowervp __unused)
struct vfsconfhead vfsconf
struct vnode * __mnt_vnode_first_active(struct vnode **mvp, struct mount *mp)
void vdrop(struct vnode *vp)
int insmntque1(struct vnode *vp, struct mount *mp, void(*dtr)(struct vnode *, void *), void *dtr_arg)
static struct proc * updateproc
void vfs_timestamp(struct timespec *tsp)
static void vnlru_proc(void)
struct vnode * __mnt_vnode_first_all(struct vnode **mvp, struct mount *mp)
int priv_check(struct thread *td, int priv)
static SYSCTL_NODE(_vfs, VFS_GENERIC, generic, CTLFLAG_RD|CTLFLAG_SKIP, vfs_sysctl,"Generic filesystem")
void vref(struct vnode *vp)
SYSCTL_ULONG(_vfs, OID_AUTO, numvnodes, CTLFLAG_RD,&numvnodes, 0,"Number of vnodes in existence")
void vput(struct vnode *vp)
static void destroy_vpollinfo_free(struct vpollinfo *vi)
int extattr_check_cred(struct vnode *vp, int attrnamespace, struct ucred *cred, struct thread *td, accmode_t accmode)
void vinactive(struct vnode *vp, struct thread *td)
void reassignbuf(struct buf *bp)
static struct filterops vfswrite_filtops
int vrecycle(struct vnode *vp, struct thread *td)
void vfs_getnewfsid(struct mount *mp)
static struct buf * buf_splay(daddr_t lblkno, b_xflags_t xflags, struct buf *root)
void vfs_ref(struct mount *mp)
void knlist_remove(struct knlist *knl, struct knote *kn, int islocked)
void knlist_init(struct knlist *knl, void *lock, void(*kl_lock)(void *), void(*kl_unlock)(void *), void(*kl_assert_locked)(void *), void(*kl_assert_unlocked)(void *))
int vfs_unixify_accmode(accmode_t *accmode)
void vdropl(struct vnode *vp)
static void vn_syncer_add_to_worklist(struct bufobj *bo, int delay)
void vn_printf(struct vnode *vp, const char *fmt,...)
static void vfs_event_init(void *arg)
void vop_rename_post(void *ap, int rc)
int jailed(struct ucred *cred)
void vfs_unbusy(struct mount *mp)
void vop_strategy_pre(void *ap)
void vunref(struct vnode *vp)
void seldrain(struct selinfo *sip)
static TAILQ_HEAD(freelst, vnode)
MALLOC_DEFINE(M_VNODE_MARKER,"vnodemarker","vnode marker")
void vop_mkdir_post(void *ap, int rc)
static int sync_fsync(struct vop_fsync_args *)
struct buf_ops buf_ops_bio
void vholdl(struct vnode *vp)
static void vntblinit(void *dummy __unused)
void getnewvnode_reserve(u_int count)
void rangelock_init(struct rangelock *lock)
int vcount(struct vnode *vp)
void vop_remove_post(void *ap, int rc)
void nanotime(struct timespec *tsp)
struct mount * vfs_busyfs(fsid_t *fsid)
int vn_pollrecord(struct vnode *vp, struct thread *td, int events)
void knlist_add(struct knlist *knl, struct knote *kn, int islocked)
int vtruncbuf(struct vnode *vp, struct ucred *cred, struct thread *td, off_t length, int blksize)
SYSCTL_INT(_kern, KERN_MAXVNODES, maxvnodes, CTLFLAG_RW,&desiredvnodes, 0,"Maximum number of vnodes")
static int vtryrecycle(struct vnode *vp)
void vop_unlock_post(void *ap, int rc)
static struct filterops vfsread_filtops
void vop_lock_post(void *ap, int rc)
int getnewvnode(const char *tag, struct mount *mp, struct vop_vector *vops, struct vnode **vpp)
static void sched_sync(void)
int vop_stdlock(struct vop_lock1_args *ap)
void v_addpollinfo(struct vnode *vp)
void getnanotime(struct timespec *tsp)
void cv_init(struct cv *cvp, const char *desc)
static int vfsconf2x(struct sysctl_req *req, struct vfsconf *vfsp)
void bawrite(struct buf *bp)
void vfs_unp_reclaim(struct vnode *vp)
int groupmember(gid_t gid, struct ucred *cred)
int uiomove(void *cp, int n, struct uio *uio)
struct filterops fs_filtops
static void vgonel(struct vnode *)
static int sysctl_vfs_worklist_len(SYSCTL_HANDLER_ARGS)
static void vfs_knl_assert_unlocked(void *arg)
u_quad_t init_va_filerev(void)
int vflush(struct mount *mp, int rootrefs, int flags, struct thread *td)
int pause(const char *wmesg, int timo)
void free(void *addr, struct malloc_type *mtp)
void kdb_enter(const char *why, const char *msg)
struct buf * gbincore(struct bufobj *bo, daddr_t lblkno)
int printf(const char *fmt,...)
struct vnode * __mnt_vnode_next_all(struct vnode **mvp, struct mount *mp)
static void delmntque(struct vnode *vp)
int vfs_busy(struct mount *mp, int flags)
static int sync_vnode(struct synclist *slp, struct bufobj **bo, struct thread *td)
void kproc_suspend_check(struct proc *p)
static int filt_fsevent(struct knote *kn, long hint)
int vop_stdunlock(struct vop_unlock_args *ap)
void kern_yield(int prio)
void __mnt_vnode_markerfree_all(struct vnode **mvp, struct mount *mp)
int sysctl_wire_old_buffer(struct sysctl_req *req, size_t len)
static int sysctl_ovfs_conf(SYSCTL_HANDLER_ARGS)
void vn_finished_secondary_write(struct mount *mp)
static void vfs_knlunlock(void *arg)
void bintime(struct bintime *bt)
void vhold(struct vnode *vp)
void mtx_init(struct mtx *m, const char *name, const char *type, int opts)
void lockmgr_printinfo(struct lock *lk)
int insmntque(struct vnode *vp, struct mount *mp)
void vrele(struct vnode *vp)
int vn_start_write(struct vnode *vp, struct mount **mpp, int flags)
static int timestamp_precision
void getbinuptime(struct bintime *bt)
void kproc_start(void *udata) const
void vop_setextattr_post(void *ap, int rc)
static struct knlist fs_knlist
struct mount * vfs_getvfs(fsid_t *fsid)
static void buf_vlist_remove(struct buf *bp)
void vgone(struct vnode *vp)
static int filt_vfswrite(struct knote *kn, long hint)
void bgetvp(struct vnode *vp, struct buf *bp)
int vprintf(const char *fmt, va_list ap)
static struct proc * vnlruproc
int vn_isdisk(struct vnode *vp, int *errp)
SYSINIT(vfs, SI_SUB_VFS, SI_ORDER_FIRST, vntblinit, NULL)
static int filt_vfsvnode(struct knote *kn, long hint)
volatile time_t time_uptime
static void vfs_knllock(void *arg)
void vfs_unmountall(void)
int bufobj_invalbuf(struct bufobj *bo, int flags, int slpflag, int slptimeo)
void bremfree(struct buf *bp)
void microtime(struct timeval *tvp)
void vop_deleteextattr_post(void *ap, int rc)
int vfs_read_dirent(struct vop_readdir_args *ap, struct dirent *dp, off_t off)
void vfs_mark_atime(struct vnode *vp, struct ucred *cred)
void vop_link_post(void *ap, int rc)
void mtx_destroy(struct mtx *m)
static int filt_vfsread(struct knote *kn, long hint)
void vop_lock_pre(void *ap)
static u_long vnodes_created
void vop_mknod_post(void *ap, int rc)
static int sync_inactive(struct vop_inactive_args *)
void vfs_msync(struct mount *mp, int flags)
struct vnode * __mnt_vnode_next_active(struct vnode **mvp, struct mount *mp)
void knlist_init_mtx(struct knlist *knl, struct mtx *lock)
void getnewvnode_drop_reserve(void)
static struct vnode * mnt_vnode_next_active(struct vnode **mvp, struct mount *mp)
#define SYNCER_SHUTDOWN_SPEEDUP
static void syncer_shutdown(void *arg, int howto)
void vop_rmdir_post(void *ap, int rc)
static void vfs_knl_assert_locked(void *arg)
void vop_rename_pre(void *ap)
void brelvp(struct buf *bp)
static unsigned long numvnodes
void lockinit(struct lock *lk, int pri, const char *wmesg, int timo, int flags)
int vn_start_secondary_write(struct vnode *vp, struct mount **mpp, int flags)
static void v_decr_usecount(struct vnode *)