Replace most uses of vp->v_usecount with a call to vrefcnt(vp), a function

that hides the details and does atomic_load_relaxed().  Signature matches
FreeBSD.
This commit is contained in:
ad 2020-04-13 19:23:17 +00:00
parent 99e7b5aaf0
commit 23bf88000c
35 changed files with 173 additions and 161 deletions

View File

@ -1994,7 +1994,7 @@ zfs_mount(vfs_t *vfsp, const char *path, void *data, size_t *data_len)
mutex_enter(mvp->v_interlock);
if ((uap->flags & MS_REMOUNT) == 0 &&
(uap->flags & MS_OVERLAY) == 0 &&
(mvp->v_count != 1 || (mvp->v_flag & VROOT))) {
(vrefcnt(mvp) != 1 || (mvp->v_flag & VROOT))) {
mutex_exit(mvp->v_interlock);
return (SET_ERROR(EBUSY));
}

View File

@ -1,5 +1,4 @@
/* $NetBSD: vnode.h,v 1.15 2019/01/12 10:44:36 hannken Exp $ */
/* $NetBSD: vnode.h,v 1.16 2020/04/13 19:23:17 ad Exp $ */
/*
* CDDL HEADER START
@ -156,7 +155,7 @@ int vn_is_readonly(vnode_t *);
#define vn_vfsunlock(vp) do { } while (0)
#define vn_ismntpt(vp) ((vp)->v_type == VDIR && (vp)->v_mountedhere != NULL)
#define vn_mountedvfs(vp) ((vp)->v_mountedhere)
#define vn_has_cached_data(vp) ((vp)->v_uobj.uo_npages != 0)
#define vn_has_cached_data(vp) (((vp)->v_iflag & VI_PAGES) != 0)
#define vn_exists(vp) do { } while (0)
#define vn_invalid(vp) do { } while (0)
#define vn_free(vp) do { } while (0)
@ -166,7 +165,7 @@ int vn_is_readonly(vnode_t *);
#define VN_HOLD(v) vref(v)
#define VN_RELE(v) \
do { \
if ((v)->v_usecount == 0) { \
if (vrefcnt(v) == 0) { \
printf("VN_RELE(%s,%d): %p unused\n", __FILE__, __LINE__, v); \
vprint("VN_RELE", (v)); \
panic("VN_RELE"); \

View File

@ -1,4 +1,4 @@
/* $NetBSD: coda_namecache.c,v 1.26 2014/10/18 08:33:27 snj Exp $ */
/* $NetBSD: coda_namecache.c,v 1.27 2020/04/13 19:23:17 ad Exp $ */
/*
*
@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: coda_namecache.c,v 1.26 2014/10/18 08:33:27 snj Exp $");
__KERNEL_RCSID(0, "$NetBSD: coda_namecache.c,v 1.27 2020/04/13 19:23:17 ad Exp $");
#include <sys/param.h>
#include <sys/errno.h>
@ -348,12 +348,12 @@ coda_nc_remove(struct coda_cache *cncp, enum dc_status dcstat)
LIST_REMOVE(cncp, hash);
memset(&cncp->hash, 0, sizeof(cncp->hash));
if ((dcstat == IS_DOWNCALL) && (CTOV(cncp->dcp)->v_usecount == 1)) {
if ((dcstat == IS_DOWNCALL) && (vrefcnt(CTOV(cncp->dcp)) == 1)) {
cncp->dcp->c_flags |= C_PURGING;
}
vrele(CTOV(cncp->dcp));
if ((dcstat == IS_DOWNCALL) && (CTOV(cncp->cp)->v_usecount == 1)) {
if ((dcstat == IS_DOWNCALL) && (vrefcnt(CTOV(cncp->cp)) == 1)) {
cncp->cp->c_flags |= C_PURGING;
}
vrele(CTOV(cncp->cp));
@ -570,7 +570,7 @@ coda_nc_flush(enum dc_status dcstat)
memset(&cncp->hash, 0, sizeof(cncp->hash));
if ((dcstat == IS_DOWNCALL)
&& (CTOV(cncp->dcp)->v_usecount == 1))
&& (vrefcnt(CTOV(cncp->dcp)) == 1))
{
cncp->dcp->c_flags |= C_PURGING;
}
@ -584,7 +584,7 @@ coda_nc_flush(enum dc_status dcstat)
}
if ((dcstat == IS_DOWNCALL)
&& (CTOV(cncp->cp)->v_usecount == 1))
&& (vrefcnt(CTOV(cncp->cp)) == 1))
{
cncp->cp->c_flags |= C_PURGING;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: coda_subr.c,v 1.31 2015/01/06 11:24:46 hannken Exp $ */
/* $NetBSD: coda_subr.c,v 1.32 2020/04/13 19:23:17 ad Exp $ */
/*
*
@ -55,7 +55,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: coda_subr.c,v 1.31 2015/01/06 11:24:46 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: coda_subr.c,v 1.32 2020/04/13 19:23:17 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -220,7 +220,7 @@ coda_testflush_selector(void *cl, struct vnode *vp)
if (cp != NULL)
myprintf(("Live cnode fid %s count %d\n",
coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount));
coda_f2s(&cp->c_fid), vrefcnt(CTOV(cp))));
return false;
}
@ -370,8 +370,8 @@ int handleDownCall(int opcode, union outputArgs *out)
error = coda_vmflush(cp);
CODADEBUG(CODA_ZAPFILE, myprintf((
"zapfile: fid = %s, refcnt = %d, error = %d\n",
coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount - 1, error)););
if (CTOV(cp)->v_usecount == 1) {
coda_f2s(&cp->c_fid), vrefcnt(CTOV(cp)) - 1, error)););
if (vrefcnt(CTOV(cp)) == 1) {
cp->c_flags |= C_PURGING;
}
mutex_exit(&cp->c_lock);
@ -394,8 +394,8 @@ int handleDownCall(int opcode, union outputArgs *out)
CODADEBUG(CODA_ZAPDIR, myprintf((
"zapdir: fid = %s, refcnt = %d\n",
coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount - 1)););
if (CTOV(cp)->v_usecount == 1) {
coda_f2s(&cp->c_fid), vrefcnt(CTOV(cp)) - 1)););
if (vrefcnt(CTOV(cp)) == 1) {
cp->c_flags |= C_PURGING;
}
mutex_exit(&cp->c_lock);
@ -427,8 +427,8 @@ int handleDownCall(int opcode, union outputArgs *out)
}
CODADEBUG(CODA_PURGEFID, myprintf((
"purgefid: fid = %s, refcnt = %d, error = %d\n",
coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount - 1, error)););
if (CTOV(cp)->v_usecount == 1) {
coda_f2s(&cp->c_fid), vrefcnt(CTOV(cp)) - 1, error)););
if (vrefcnt(CTOV(cp)) == 1) {
cp->c_flags |= C_PURGING;
}
mutex_exit(&cp->c_lock);

View File

@ -1,4 +1,4 @@
/* $NetBSD: coda_vnops.c,v 1.110 2020/02/24 20:53:11 ad Exp $ */
/* $NetBSD: coda_vnops.c,v 1.111 2020/04/13 19:23:17 ad Exp $ */
/*
*
@ -46,7 +46,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: coda_vnops.c,v 1.110 2020/02/24 20:53:11 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: coda_vnops.c,v 1.111 2020/04/13 19:23:17 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -329,7 +329,7 @@ coda_close(void *v)
if (cp->c_ovp) {
#ifdef CODA_VERBOSE
printf("%s: destroying container %d, ufs vp %p of vp %p/cp %p\n",
__func__, vp->v_usecount, cp->c_ovp, vp, cp);
__func__, vrefcnt(vp), cp->c_ovp, vp, cp);
#endif
#ifdef hmm
vgone(cp->c_ovp);
@ -465,7 +465,7 @@ coda_rdwr(vnode_t *vp, struct uio *uiop, enum uio_rw rw, int ioflag,
/* Have UFS handle the call. */
CODADEBUG(CODA_RDWR, myprintf(("%s: fid = %s, refcnt = %d\n", __func__,
coda_f2s(&cp->c_fid), CTOV(cp)->v_usecount)); )
coda_f2s(&cp->c_fid), vrefcnt(CTOV(cp)))); )
if (rw == UIO_READ) {
error = VOP_READ(cfvp, uiop, ioflag, cred);
@ -850,8 +850,8 @@ coda_inactive(void *v)
#ifdef CODA_VERBOSE
/* Sanity checks that perhaps should be panic. */
if (vp->v_usecount > 1)
printf("%s: %p usecount %d\n", __func__, vp, vp->v_usecount);
if (vrefcnt(vp) > 1)
printf("%s: %p usecount %d\n", __func__, vp, vrefcnt(vp));
if (cp->c_ovp != NULL)
printf("%s: %p ovp != NULL\n", __func__, vp);
#endif
@ -1569,7 +1569,7 @@ coda_readdir(void *v)
/* Have UFS handle the call. */
CODADEBUG(CODA_READDIR, myprintf(("%s: fid = %s, refcnt = %d\n",
__func__, coda_f2s(&cp->c_fid), vp->v_usecount)); )
__func__, coda_f2s(&cp->c_fid), vrefcnt(vp))); )
saved_type = vp->v_type;
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
vp->v_type = VDIR; /* pretend the container file is a dir */
@ -1661,7 +1661,7 @@ coda_reclaim(void *v)
#endif
} else {
#ifdef OLD_DIAGNOSTIC
if (vp->v_usecount != 0)
if (vrefcnt(vp) != 0)
print("%s: pushing active %p\n", __func__, vp);
if (VTOC(vp)->c_ovp) {
panic("%s: c_ovp not void", __func__);

View File

@ -1,4 +1,4 @@
/* $NetBSD: msdosfs_denode.c,v 1.57 2018/05/28 21:04:37 chs Exp $ */
/* $NetBSD: msdosfs_denode.c,v 1.58 2020/04/13 19:23:17 ad Exp $ */
/*-
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: msdosfs_denode.c,v 1.57 2018/05/28 21:04:37 chs Exp $");
__KERNEL_RCSID(0, "$NetBSD: msdosfs_denode.c,v 1.58 2020/04/13 19:23:17 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -611,8 +611,8 @@ out:
* so that it can be reused immediately.
*/
#ifdef MSDOSFS_DEBUG
printf("msdosfs_inactive(): v_usecount %d, de_Name[0] %x\n",
vp->v_usecount, dep->de_Name[0]);
printf("msdosfs_inactive(): usecount %d, de_Name[0] %x\n",
vrefcnt(vp), dep->de_Name[0]);
#endif
*ap->a_recycle = (dep->de_Name[0] == SLOT_DELETED);

View File

@ -1,4 +1,4 @@
/* $NetBSD: msdosfs_vfsops.c,v 1.134 2020/04/04 20:49:30 ad Exp $ */
/* $NetBSD: msdosfs_vfsops.c,v 1.135 2020/04/13 19:23:17 ad Exp $ */
/*-
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.134 2020/04/04 20:49:30 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.135 2020/04/13 19:23:17 ad Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@ -926,7 +926,7 @@ msdosfs_unmount(struct mount *mp, int mntflags)
printf("msdosfs_umount(): just before calling VOP_CLOSE()\n");
printf("flag %08x, usecount %d, writecount %d, holdcnt %d\n",
vp->v_vflag | vp->v_iflag | vp->v_uflag, vp->v_usecount,
vp->v_vflag | vp->v_iflag | vp->v_uflag, vrefcnt(vp),
vp->v_writecount, vp->v_holdcnt);
printf("mount %p, op %p\n",
vp->v_mount, vp->v_op);

View File

@ -1,4 +1,4 @@
/* $NetBSD: msdosfs_vnops.c,v 1.100 2020/02/23 15:46:40 ad Exp $ */
/* $NetBSD: msdosfs_vnops.c,v 1.101 2020/04/13 19:23:17 ad Exp $ */
/*-
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@ -48,7 +48,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vnops.c,v 1.100 2020/02/23 15:46:40 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vnops.c,v 1.101 2020/04/13 19:23:17 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -173,7 +173,7 @@ msdosfs_close(void *v)
struct denode *dep = VTODE(vp);
mutex_enter(vp->v_interlock);
if (vp->v_usecount > 1)
if (vrefcnt(vp) > 1)
DETIMES(dep, NULL, NULL, NULL, dep->de_pmp->pm_gmtoff);
mutex_exit(vp->v_interlock);
return (0);
@ -731,8 +731,8 @@ msdosfs_remove(void *v)
else
error = removede(ddep, dep);
#ifdef MSDOSFS_DEBUG
printf("msdosfs_remove(), dep %p, v_usecount %d\n",
dep, ap->a_vp->v_usecount);
printf("msdosfs_remove(), dep %p, usecount %d\n",
dep, vrefcnt(ap->a_vp));
#endif
VN_KNOTE(ap->a_vp, NOTE_DELETE);
VN_KNOTE(ap->a_dvp, NOTE_WRITE);

View File

@ -1,4 +1,4 @@
/* $NetBSD: nilfs_vnops.c,v 1.38 2019/12/27 09:41:51 msaitoh Exp $ */
/* $NetBSD: nilfs_vnops.c,v 1.39 2020/04/13 19:23:18 ad Exp $ */
/*
* Copyright (c) 2008, 2009 Reinoud Zandijk
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
__KERNEL_RCSID(0, "$NetBSD: nilfs_vnops.c,v 1.38 2019/12/27 09:41:51 msaitoh Exp $");
__KERNEL_RCSID(0, "$NetBSD: nilfs_vnops.c,v 1.39 2020/04/13 19:23:18 ad Exp $");
#endif /* not lint */
@ -976,8 +976,8 @@ nilfs_close(void *v)
nilfs_node = nilfs_node; /* shut up gcc */
mutex_enter(vp->v_interlock);
if (vp->v_usecount > 1)
nilfs_itimes(nilfs_node, NULL, NULL, NULL);
if (vrefcnt(vp) > 1)
nilfs_itimes(nilfs_node, NULL, NULL, NULL);
mutex_exit(vp->v_interlock);
return 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: ntfs_vfsops.c,v 1.109 2020/01/17 20:08:08 ad Exp $ */
/* $NetBSD: ntfs_vfsops.c,v 1.110 2020/04/13 19:23:18 ad Exp $ */
/*-
* Copyright (c) 1998, 1999 Semen Ustimenko
@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ntfs_vfsops.c,v 1.109 2020/01/17 20:08:08 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: ntfs_vfsops.c,v 1.110 2020/04/13 19:23:18 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -526,7 +526,7 @@ ntfs_unmount(struct mount *mp, int mntflags)
/* Check if only system vnodes are rest */
for (i = 0; i < NTFS_SYSNODESNUM; i++)
if ((ntmp->ntm_sysvn[i]) &&
(ntmp->ntm_sysvn[i]->v_usecount > 1))
(vrefcnt(ntmp->ntm_sysvn[i]) > 1))
return (EBUSY);
/* Dereference all system vnodes */

View File

@ -1,4 +1,4 @@
/* $NetBSD: ptyfs_vnops.c,v 1.57 2019/09/26 20:57:19 christos Exp $ */
/* $NetBSD: ptyfs_vnops.c,v 1.58 2020/04/13 19:23:18 ad Exp $ */
/*
* Copyright (c) 1993, 1995
@ -76,7 +76,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ptyfs_vnops.c,v 1.57 2019/09/26 20:57:19 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: ptyfs_vnops.c,v 1.58 2020/04/13 19:23:18 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -798,7 +798,7 @@ ptyfs_close(void *v)
struct ptyfsnode *ptyfs = VTOPTYFS(vp);
mutex_enter(vp->v_interlock);
if (vp->v_usecount > 1)
if (vrefcnt(vp) > 1)
PTYFS_ITIMES(ptyfs, NULL, NULL, NULL);
mutex_exit(vp->v_interlock);

View File

@ -1,4 +1,4 @@
/* $NetBSD: udf_vfsops.c,v 1.78 2020/03/16 21:20:10 pgoyette Exp $ */
/* $NetBSD: udf_vfsops.c,v 1.79 2020/04/13 19:23:18 ad Exp $ */
/*
* Copyright (c) 2006, 2008 Reinoud Zandijk
@ -28,7 +28,7 @@
#include <sys/cdefs.h>
#ifndef lint
__KERNEL_RCSID(0, "$NetBSD: udf_vfsops.c,v 1.78 2020/03/16 21:20:10 pgoyette Exp $");
__KERNEL_RCSID(0, "$NetBSD: udf_vfsops.c,v 1.79 2020/04/13 19:23:18 ad Exp $");
#endif /* not lint */
@ -445,8 +445,8 @@ udf_sanity_selector(void *cl, struct vnode *vp)
if (VOP_ISLOCKED(vp) == LK_EXCLUSIVE) {
printf(" is locked\n");
}
if (vp->v_usecount > 1)
printf(" more than one usecount %d\n", vp->v_usecount);
if (vrefcnt(vp) > 1)
printf(" more than one usecount %d\n", vrefcnt(vp));
return false;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: udf_vnops.c,v 1.109 2020/02/23 15:46:41 ad Exp $ */
/* $NetBSD: udf_vnops.c,v 1.110 2020/04/13 19:23:18 ad Exp $ */
/*
* Copyright (c) 2006, 2008 Reinoud Zandijk
@ -32,7 +32,7 @@
#include <sys/cdefs.h>
#ifndef lint
__KERNEL_RCSID(0, "$NetBSD: udf_vnops.c,v 1.109 2020/02/23 15:46:41 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: udf_vnops.c,v 1.110 2020/04/13 19:23:18 ad Exp $");
#endif /* not lint */
@ -1386,8 +1386,8 @@ udf_close(void *v)
}
mutex_enter(vp->v_interlock);
if (vp->v_usecount > 1)
udf_itimes(udf_node, NULL, NULL, NULL);
if (vrefcnt(vp) > 1)
udf_itimes(udf_node, NULL, NULL, NULL);
mutex_exit(vp->v_interlock);
return 0;

View File

@ -1,4 +1,4 @@
/* $NetBSD: v7fs_vnops.c,v 1.27 2020/01/17 20:08:09 ad Exp $ */
/* $NetBSD: v7fs_vnops.c,v 1.28 2020/04/13 19:23:18 ad Exp $ */
/*-
* Copyright (c) 2004, 2011 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: v7fs_vnops.c,v 1.27 2020/01/17 20:08:09 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: v7fs_vnops.c,v 1.28 2020/04/13 19:23:18 ad Exp $");
#if defined _KERNEL_OPT
#include "opt_v7fs.h"
#endif
@ -138,7 +138,7 @@ v7fs_lookup(void *v)
if ((nameiop == RENAME) && islastcn) {
return EISDIR; /* t_vnops rename_dir(3) */
}
vref(dvp); /* v_usecount++ */
vref(dvp); /* usecount++ */
*a->a_vpp = dvp;
DPRINTF("done.(.)\n");
return 0;
@ -717,9 +717,9 @@ v7fs_remove(void *v)
out:
if (dvp == vp)
vrele(vp); /* v_usecount-- of unlocked vp */
vrele(vp); /* usecount-- of unlocked vp */
else
vput(vp); /* unlock vp and then v_usecount-- */
vput(vp); /* unlock vp and then usecount-- */
return error;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: exec_subr.c,v 1.83 2020/01/12 18:30:58 ad Exp $ */
/* $NetBSD: exec_subr.c,v 1.84 2020/04/13 19:23:18 ad Exp $ */
/*
* Copyright (c) 1993, 1994, 1996 Christopher G. Demetriou
@ -31,7 +31,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: exec_subr.c,v 1.83 2020/01/12 18:30:58 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: exec_subr.c,v 1.84 2020/04/13 19:23:18 ad Exp $");
#include "opt_pax.h"
@ -87,7 +87,7 @@ new_vmcmd(struct exec_vmcmd_set *evsp,
VMCMD_EVCNT_INCR(calls);
KASSERT(proc != vmcmd_map_pagedvn || (vp->v_iflag & VI_TEXT));
KASSERT(vp == NULL || vp->v_usecount > 0);
KASSERT(vp == NULL || vrefcnt(vp) > 0);
if (evsp->evs_used >= evsp->evs_cnt)
vmcmdset_extend(evsp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_cache.c,v 1.138 2020/04/10 16:55:40 ad Exp $ */
/* $NetBSD: vfs_cache.c,v 1.139 2020/04/13 19:23:18 ad Exp $ */
/*-
* Copyright (c) 2008, 2019, 2020 The NetBSD Foundation, Inc.
@ -172,7 +172,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.138 2020/04/10 16:55:40 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_cache.c,v 1.139 2020/04/13 19:23:18 ad Exp $");
#define __NAMECACHE_PRIVATE
#ifdef _KERNEL_OPT
@ -673,7 +673,7 @@ cache_lookup_linked(struct vnode *dvp, const char *name, size_t namelen,
}
*plock = &dvi->vi_nc_lock;
} else if (*plock == NULL) {
KASSERT(dvp->v_usecount > 0);
KASSERT(vrefcnt(dvp) > 0);
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_getcwd.c,v 1.57 2020/04/04 20:49:30 ad Exp $ */
/* $NetBSD: vfs_getcwd.c,v 1.58 2020/04/13 19:23:18 ad Exp $ */
/*-
* Copyright (c) 1999, 2020 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_getcwd.c,v 1.57 2020/04/04 20:49:30 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_getcwd.c,v 1.58 2020/04/13 19:23:18 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -527,7 +527,7 @@ vnode_to_path(char *path, size_t len, struct vnode *vp, struct lwp *curl,
char *bp, *bend;
struct vnode *dvp;
KASSERT(vp->v_usecount > 0);
KASSERT(vrefcnt(vp) > 0);
bp = bend = &path[len];
*(--bp) = '\0';

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_mount.c,v 1.77 2020/04/13 15:54:45 maxv Exp $ */
/* $NetBSD: vfs_mount.c,v 1.78 2020/04/13 19:23:18 ad Exp $ */
/*-
* Copyright (c) 1997-2020 The NetBSD Foundation, Inc.
@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.77 2020/04/13 15:54:45 maxv Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.78 2020/04/13 19:23:18 ad Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -395,7 +395,7 @@ vfs_vnode_iterator_destroy(struct vnode_iterator *vni)
kmutex_t *lock;
KASSERT(vnis_marker(mvp));
if (mvp->v_usecount != 0) {
if (vrefcnt(mvp) != 0) {
lock = mvp->v_mount->mnt_vnodelock;
mutex_enter(lock);
TAILQ_REMOVE(&mvp->v_mount->mnt_vnodelist, mvip, vi_mntvnodes);
@ -581,7 +581,7 @@ vflush_one(vnode_t *vp, vnode_t *skipvp, int flags)
* kill them.
*/
if (flags & FORCECLOSE) {
if (vp->v_usecount > 1 &&
if (vrefcnt(vp) > 1 &&
(vp->v_type == VBLK || vp->v_type == VCHR))
vcache_make_anon(vp);
else
@ -651,7 +651,7 @@ mount_checkdirs(vnode_t *olddp)
struct proc *p;
bool retry;
if (olddp->v_usecount == 1) {
if (vrefcnt(olddp) == 1) {
return;
}
if (VFS_ROOT(olddp->v_mountedhere, LK_EXCLUSIVE, &newdp))

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_subr.c,v 1.484 2020/03/14 20:45:23 ad Exp $ */
/* $NetBSD: vfs_subr.c,v 1.485 2020/04/13 19:23:18 ad Exp $ */
/*-
* Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008, 2019, 2020
@ -69,7 +69,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.484 2020/03/14 20:45:23 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.485 2020/04/13 19:23:18 ad Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@ -1104,7 +1104,7 @@ vprint_common(struct vnode *vp, const char *prefix,
ARRAY_PRINT(vp->v_type, vnode_types), vp->v_type,
vp->v_mount, vp->v_mountedhere);
(*pr)("%susecount %d writecount %d holdcount %d\n", prefix,
vp->v_usecount, vp->v_writecount, vp->v_holdcnt);
vrefcnt(vp), vp->v_writecount, vp->v_holdcnt);
(*pr)("%ssize %" PRIx64 " writesize %" PRIx64 " numoutput %d\n",
prefix, vp->v_size, vp->v_writesize, vp->v_numoutput);
(*pr)("%sdata %p lock %p\n", prefix, vp->v_data, &vip->vi_lock);

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_vnode.c,v 1.119 2020/04/13 15:54:45 maxv Exp $ */
/* $NetBSD: vfs_vnode.c,v 1.120 2020/04/13 19:23:18 ad Exp $ */
/*-
* Copyright (c) 1997-2011, 2019, 2020 The NetBSD Foundation, Inc.
@ -155,7 +155,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.119 2020/04/13 15:54:45 maxv Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.120 2020/04/13 19:23:18 ad Exp $");
#ifdef _KERNEL_OPT
#include "opt_pax.h"
@ -236,6 +236,16 @@ extern int (**dead_vnodeop_p)(void *);
extern int (**spec_vnodeop_p)(void *);
extern struct vfsops dead_vfsops;
/*
* Return the current usecount of a vnode.
*/
inline int
vrefcnt(struct vnode *vp)
{
return atomic_load_relaxed(&vp->v_usecount);
}
/* Vnode state operations and diagnostics. */
#if defined(DIAGNOSTIC)
@ -254,6 +264,7 @@ _vstate_assert(vnode_t *vp, enum vnode_state state, const char *func, int line,
bool has_lock)
{
vnode_impl_t *vip = VNODE_TO_VIMPL(vp);
int refcnt = vrefcnt(vp);
if (!has_lock) {
/*
@ -261,7 +272,7 @@ _vstate_assert(vnode_t *vp, enum vnode_state state, const char *func, int line,
* without loooking first.
*/
membar_enter();
if (state == VS_ACTIVE && vp->v_usecount > 0 &&
if (state == VS_ACTIVE && refcnt > 0 &&
(vip->vi_state == VS_LOADED || vip->vi_state == VS_BLOCKED))
return;
if (vip->vi_state == state)
@ -271,7 +282,7 @@ _vstate_assert(vnode_t *vp, enum vnode_state state, const char *func, int line,
KASSERTMSG(mutex_owned(vp->v_interlock), "at %s:%d", func, line);
if ((state == VS_ACTIVE && vp->v_usecount > 0 &&
if ((state == VS_ACTIVE && refcnt > 0 &&
(vip->vi_state == VS_LOADED || vip->vi_state == VS_BLOCKED)) ||
vip->vi_state == state) {
if (!has_lock)
@ -279,7 +290,7 @@ _vstate_assert(vnode_t *vp, enum vnode_state state, const char *func, int line,
return;
}
vnpanic(vp, "state is %s, usecount %d, expected %s at %s:%d",
vstate_name(vip->vi_state), vp->v_usecount,
vstate_name(vip->vi_state), refcnt,
vstate_name(state), func, line);
}
@ -319,6 +330,7 @@ vstate_assert_change(vnode_t *vp, enum vnode_state from, enum vnode_state to,
const char *func, int line)
{
vnode_impl_t *vip = VNODE_TO_VIMPL(vp);
int refcnt = vrefcnt(vp);
KASSERTMSG(mutex_owned(vp->v_interlock), "at %s:%d", func, line);
if (from == VS_LOADING)
@ -333,9 +345,9 @@ vstate_assert_change(vnode_t *vp, enum vnode_state from, enum vnode_state to,
if (vip->vi_state != from)
vnpanic(vp, "from is %s, expected %s at %s:%d\n",
vstate_name(vip->vi_state), vstate_name(from), func, line);
if ((from == VS_BLOCKED || to == VS_BLOCKED) && vp->v_usecount != 1)
if ((from == VS_BLOCKED || to == VS_BLOCKED) && refcnt != 1)
vnpanic(vp, "%s to %s with usecount %d at %s:%d",
vstate_name(from), vstate_name(to), vp->v_usecount,
vstate_name(from), vstate_name(to), refcnt,
func, line);
vip->vi_state = to;
@ -568,13 +580,13 @@ vdrain_remove(vnode_t *vp)
KASSERT(mutex_owned(&vdrain_lock));
/* Probe usecount (unlocked). */
if (vp->v_usecount > 0)
if (vrefcnt(vp) > 0)
return;
/* Try v_interlock -- we lock the wrong direction! */
if (!mutex_tryenter(vp->v_interlock))
return;
/* Probe usecount and state. */
if (vp->v_usecount > 0 || VSTATE_GET(vp) != VS_LOADED) {
if (vrefcnt(vp) > 0 || VSTATE_GET(vp) != VS_LOADED) {
mutex_exit(vp->v_interlock);
return;
}
@ -617,7 +629,7 @@ vdrain_vrele(vnode_t *vp)
* First remove the vnode from the vrele list.
* Put it on the last lru list, the last vrele()
* will put it back onto the right list before
* its v_usecount reaches zero.
* its usecount reaches zero.
*/
KASSERT(vip->vi_lrulisthd == &lru_list[LRU_VRELE]);
TAILQ_REMOVE(vip->vi_lrulisthd, vip, vi_lrulist);
@ -715,13 +727,13 @@ vput(vnode_t *vp)
int lktype;
/*
* Do an unlocked check of v_usecount. If it looks like we're not
* Do an unlocked check of the usecount. If it looks like we're not
* about to drop the last reference, then unlock the vnode and try
* to drop the reference. If it ends up being the last reference
* after all, vrelel() can fix it all up. Most of the time this
* will all go to plan.
*/
if (atomic_load_relaxed(&vp->v_usecount) > 1) {
if (vrefcnt(vp) > 1) {
VOP_UNLOCK(vp);
if (vtryrele(vp)) {
return;
@ -768,7 +780,7 @@ vrelel(vnode_t *vp, int flags, int lktype)
mutex_exit(vp->v_interlock);
return;
}
if (vp->v_usecount <= 0 || vp->v_writecount != 0) {
if (vrefcnt(vp) <= 0 || vp->v_writecount != 0) {
vnpanic(vp, "%s: bad ref count", __func__);
}
@ -869,7 +881,7 @@ vrelel(vnode_t *vp, int flags, int lktype)
} else {
VOP_UNLOCK(vp);
}
KASSERT(vp->v_usecount > 0);
KASSERT(vrefcnt(vp) > 0);
}
if (atomic_dec_uint_nv(&vp->v_usecount) != 0) {
@ -930,7 +942,7 @@ void
vref(vnode_t *vp)
{
KASSERT(atomic_load_relaxed(&vp->v_usecount) != 0);
KASSERT(vrefcnt(vp) > 0);
atomic_inc_uint(&vp->v_usecount);
}
@ -945,7 +957,7 @@ vholdl(vnode_t *vp)
KASSERT(mutex_owned(vp->v_interlock));
if (vp->v_holdcnt++ == 0 && vp->v_usecount == 0)
if (vp->v_holdcnt++ == 0 && vrefcnt(vp) == 0)
lru_requeue(vp, lru_which(vp));
}
@ -976,7 +988,7 @@ holdrelel(vnode_t *vp)
}
vp->v_holdcnt--;
if (vp->v_holdcnt == 0 && vp->v_usecount == 0)
if (vp->v_holdcnt == 0 && vrefcnt(vp) == 0)
lru_requeue(vp, lru_which(vp));
}
@ -1004,7 +1016,7 @@ vrecycle(vnode_t *vp)
/* Make sure we hold the last reference. */
VSTATE_WAIT_STABLE(vp);
if (vp->v_usecount != 1) {
if (vrefcnt(vp) != 1) {
mutex_exit(vp->v_interlock);
return false;
}
@ -1036,7 +1048,7 @@ vrecycle(vnode_t *vp)
return false;
}
KASSERT(vp->v_usecount == 1);
KASSERT(vrefcnt(vp) == 1);
vcache_reclaim(vp);
vrelel(vp, 0, LK_NONE);
@ -1085,7 +1097,7 @@ vrevoke(vnode_t *vp)
enum vtype type;
dev_t dev;
KASSERT(vp->v_usecount > 0);
KASSERT(vrefcnt(vp) > 0);
mp = vrevoke_suspend_next(NULL, vp->v_mount);
@ -1273,7 +1285,7 @@ vcache_free(vnode_impl_t *vip)
vp = VIMPL_TO_VNODE(vip);
KASSERT(mutex_owned(vp->v_interlock));
KASSERT(vp->v_usecount == 0);
KASSERT(vrefcnt(vp) == 0);
KASSERT(vp->v_holdcnt == 0);
KASSERT(vp->v_writecount == 0);
lru_requeue(vp, NULL);
@ -1339,7 +1351,7 @@ vcache_vget(vnode_t *vp)
/* If this was the last reference to a reclaimed vnode free it now. */
if (__predict_false(VSTATE_GET(vp) == VS_RECLAIMED)) {
if (vp->v_holdcnt == 0 && vp->v_usecount == 0)
if (vp->v_holdcnt == 0 && vrefcnt(vp) == 0)
vcache_free(VNODE_TO_VIMPL(vp));
else
mutex_exit(vp->v_interlock);
@ -1654,9 +1666,9 @@ vcache_reclaim(vnode_t *vp)
KASSERT((vp->v_vflag & VV_LOCKSWORK) == 0 ||
VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
KASSERT(mutex_owned(vp->v_interlock));
KASSERT(vp->v_usecount != 0);
KASSERT(vrefcnt(vp) != 0);
active = (vp->v_usecount > 1);
active = (vrefcnt(vp) > 1);
temp_key_len = vip->vi_key.vk_key_len;
/*
* Prevent the vnode from being recycled or brought into use

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_vnops.c,v 1.210 2020/04/12 19:56:14 christos Exp $ */
/* $NetBSD: vfs_vnops.c,v 1.211 2020/04/13 19:23:18 ad Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.210 2020/04/12 19:56:14 christos Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_vnops.c,v 1.211 2020/04/13 19:23:18 ad Exp $");
#include "veriexec.h"
@ -1041,7 +1041,7 @@ vn_lock(struct vnode *vp, int flags)
int error;
#if 0
KASSERT(vp->v_usecount > 0 || (vp->v_iflag & VI_ONWORKLST) != 0);
KASSERT(vrefcnt(vp) > 0 || (vp->v_iflag & VI_ONWORKLST) != 0);
#endif
KASSERT((flags & ~(LK_SHARED|LK_EXCLUSIVE|LK_NOWAIT|LK_RETRY|
LK_UPGRADE|LK_DOWNGRADE)) == 0);

View File

@ -1,4 +1,4 @@
/* $NetBSD: fdesc_vfsops.c,v 1.95 2020/03/21 16:30:39 pgoyette Exp $ */
/* $NetBSD: fdesc_vfsops.c,v 1.96 2020/04/13 19:23:18 ad Exp $ */
/*
* Copyright (c) 1992, 1993, 1995
@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: fdesc_vfsops.c,v 1.95 2020/03/21 16:30:39 pgoyette Exp $");
__KERNEL_RCSID(0, "$NetBSD: fdesc_vfsops.c,v 1.96 2020/04/13 19:23:18 ad Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@ -119,7 +119,7 @@ fdesc_unmount(struct mount *mp, int mntflags)
if (mntflags & MNT_FORCE)
flags |= FORCECLOSE;
if (rtvp->v_usecount > 1 && (mntflags & MNT_FORCE) == 0)
if (vrefcnt(rtvp) > 1 && (mntflags & MNT_FORCE) == 0)
return (EBUSY);
if ((error = vflush(mp, rtvp, flags)) != 0)
return (error);

View File

@ -1,4 +1,4 @@
/* $NetBSD: layer_subr.c,v 1.37 2014/11/09 18:08:07 maxv Exp $ */
/* $NetBSD: layer_subr.c,v 1.38 2020/04/13 19:23:19 ad Exp $ */
/*
* Copyright (c) 1999 National Aeronautics & Space Administration
@ -69,7 +69,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: layer_subr.c,v 1.37 2014/11/09 18:08:07 maxv Exp $");
__KERNEL_RCSID(0, "$NetBSD: layer_subr.c,v 1.38 2020/04/13 19:23:19 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -127,7 +127,7 @@ layer_node_create(struct mount *mp, struct vnode *lowervp, struct vnode **nvpp)
* reference to the lower node.
*/
vrele(lowervp);
KASSERT(lowervp->v_usecount > 0);
KASSERT(vrefcnt(lowervp) > 0);
#ifdef LAYERFS_DIAGNOSTIC
if (layerfs_debug)
@ -167,7 +167,7 @@ layer_checkvp(struct vnode *vp, const char *fil, int lno)
/* wait for debugger */
panic("layer_checkvp");
}
if (a->layer_lowervp->v_usecount < 1) {
if (vrefcnt(a->layer_lowervp) < 1) {
int i; u_long *p;
printf("vp = %p, unref'ed lowervp\n", vp);
for (p = (u_long *) a, i = 0; i < 8; i++)
@ -178,8 +178,8 @@ layer_checkvp(struct vnode *vp, const char *fil, int lno)
};
#ifdef notnow
printf("layer %p/%d -> %p/%d [%s, %d]\n",
LAYERTOV(a), LAYERTOV(a)->v_usecount,
a->layer_lowervp, a->layer_lowervp->v_usecount,
LAYERTOV(a), vrefcnt(LAYERTOV(a)),
a->layer_lowervp, vrefcnt(a->layer_lowervp),
fil, lno);
#endif
return a->layer_lowervp;

View File

@ -1,4 +1,4 @@
/* $NetBSD: layer_vnops.c,v 1.69 2020/04/04 20:49:30 ad Exp $ */
/* $NetBSD: layer_vnops.c,v 1.70 2020/04/13 19:23:19 ad Exp $ */
/*
* Copyright (c) 1999 National Aeronautics & Space Administration
@ -170,7 +170,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: layer_vnops.c,v 1.69 2020/04/04 20:49:30 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: layer_vnops.c,v 1.70 2020/04/13 19:23:19 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -692,7 +692,7 @@ layer_revoke(void *v)
int error;
/*
* We will most likely end up in vclean which uses the v_usecount
* We will most likely end up in vclean which uses the usecount
* to determine if a vnode is active. Take an extra reference on
* the lower vnode so it will always close and inactivate.
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: null_vfsops.c,v 1.98 2020/04/04 20:49:30 ad Exp $ */
/* $NetBSD: null_vfsops.c,v 1.99 2020/04/13 19:23:19 ad Exp $ */
/*
* Copyright (c) 1999 National Aeronautics & Space Administration
@ -76,7 +76,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: null_vfsops.c,v 1.98 2020/04/04 20:49:30 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: null_vfsops.c,v 1.99 2020/04/13 19:23:19 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -190,7 +190,7 @@ nullfs_unmount(struct mount *mp, int mntflags)
if (mntflags & MNT_FORCE)
flags |= FORCECLOSE;
if (null_rootvp->v_usecount > 1 && (mntflags & MNT_FORCE) == 0)
if (vrefcnt(null_rootvp) > 1 && (mntflags & MNT_FORCE) == 0)
return EBUSY;
if ((error = vflush(mp, null_rootvp, flags)) != 0)

View File

@ -1,4 +1,4 @@
/* $NetBSD: overlay_vfsops.c,v 1.70 2020/03/21 16:30:39 pgoyette Exp $ */
/* $NetBSD: overlay_vfsops.c,v 1.71 2020/04/13 19:23:19 ad Exp $ */
/*
* Copyright (c) 1999, 2000 National Aeronautics & Space Administration
@ -74,7 +74,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: overlay_vfsops.c,v 1.70 2020/03/21 16:30:39 pgoyette Exp $");
__KERNEL_RCSID(0, "$NetBSD: overlay_vfsops.c,v 1.71 2020/04/13 19:23:19 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -215,7 +215,7 @@ ov_unmount(struct mount *mp, int mntflags)
if (mntflags & MNT_FORCE)
flags |= FORCECLOSE;
if (overlay_rootvp->v_usecount > 1 && (mntflags & MNT_FORCE) == 0)
if (vrefcnt(overlay_rootvp) > 1 && (mntflags & MNT_FORCE) == 0)
return (EBUSY);
if ((error = vflush(mp, overlay_rootvp, flags)) != 0)
return (error);

View File

@ -1,4 +1,4 @@
/* $NetBSD: umap_vfsops.c,v 1.102 2020/03/16 21:20:11 pgoyette Exp $ */
/* $NetBSD: umap_vfsops.c,v 1.103 2020/04/13 19:23:19 ad Exp $ */
/*
* Copyright (c) 1992, 1993
@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: umap_vfsops.c,v 1.102 2020/03/16 21:20:11 pgoyette Exp $");
__KERNEL_RCSID(0, "$NetBSD: umap_vfsops.c,v 1.103 2020/04/13 19:23:19 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -274,7 +274,7 @@ umapfs_unmount(struct mount *mp, int mntflags)
if (mntflags & MNT_FORCE)
flags |= FORCECLOSE;
if (rtvp->v_usecount > 1 && (mntflags & MNT_FORCE) == 0)
if (vrefcnt(rtvp) > 1 && (mntflags & MNT_FORCE) == 0)
return (EBUSY);
if ((error = vflush(mp, rtvp, flags)) != 0)
return (error);

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfs_vfsops.c,v 1.240 2020/03/16 21:20:11 pgoyette Exp $ */
/* $NetBSD: nfs_vfsops.c,v 1.241 2020/04/13 19:23:20 ad Exp $ */
/*
* Copyright (c) 1989, 1993, 1995
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.240 2020/03/16 21:20:11 pgoyette Exp $");
__KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.241 2020/04/13 19:23:20 ad Exp $");
#if defined(_KERNEL_OPT)
#include "opt_nfs.h"
@ -863,7 +863,7 @@ nfs_unmount(struct mount *mp, int mntflags)
if (error != 0)
goto err;
if ((mntflags & MNT_FORCE) == 0 && vp->v_usecount > 1) {
if ((mntflags & MNT_FORCE) == 0 && vrefcnt(vp) > 1) {
VOP_UNLOCK(vp);
error = EBUSY;
goto err;

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfs_vnops.c,v 1.313 2020/02/23 15:46:41 ad Exp $ */
/* $NetBSD: nfs_vnops.c,v 1.314 2020/04/13 19:23:20 ad Exp $ */
/*
* Copyright (c) 1989, 1993
@ -39,7 +39,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: nfs_vnops.c,v 1.313 2020/02/23 15:46:41 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: nfs_vnops.c,v 1.314 2020/04/13 19:23:20 ad Exp $");
#ifdef _KERNEL_OPT
#include "opt_nfs.h"
@ -1729,7 +1729,7 @@ again:
* To try and make nfs semantics closer to ufs semantics, a file that has
* other processes using the vnode is renamed instead of removed and then
* removed later on the last close.
* - If v_usecount > 1
* - If vrefcnt(vp) > 1
* If a rename is not already in the works
* call nfs_sillyrename() to set it up
* else
@ -1752,12 +1752,12 @@ nfs_remove(void *v)
struct vattr vattr;
#ifndef DIAGNOSTIC
if (vp->v_usecount < 1)
panic("nfs_remove: bad v_usecount");
if (vrefcnt(vp) < 1)
panic("nfs_remove: bad vrefcnt(vp)");
#endif
if (vp->v_type == VDIR)
error = EPERM;
else if (vp->v_usecount == 1 || (np->n_sillyrename &&
else if (vrefcnt(vp) == 1 || (np->n_sillyrename &&
VOP_GETATTR(vp, &vattr, cnp->cn_cred) == 0 &&
vattr.va_nlink > 1)) {
/*
@ -1886,7 +1886,7 @@ nfs_rename(void *v)
* so that we don't lose the file if the rename fails, and so
* that there's no window when the "to" file doesn't exist.
*/
if (tvp && tvp->v_usecount > 1 && !VTONFS(tvp)->n_sillyrename &&
if (tvp && vrefcnt(tvp) > 1 && !VTONFS(tvp)->n_sillyrename &&
tvp->v_type != VDIR && !nfs_sillyrename(tdvp, tvp, tcnp, true)) {
VN_KNOTE(tvp, NOTE_DELETE);
vput(tvp);
@ -3443,7 +3443,7 @@ nfsspec_close(void *v)
if (np->n_flag & (NACC | NUPD)) {
np->n_flag |= NCHG;
if (vp->v_usecount == 1 &&
if (vrefcnt(vp) == 1 &&
(vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
vattr_null(&vattr);
if (np->n_flag & NACC)
@ -3527,7 +3527,7 @@ nfsfifo_close(void *v)
if (np->n_flag & NUPD)
np->n_mtim = ts;
np->n_flag |= NCHG;
if (vp->v_usecount == 1 &&
if (vrefcnt(vp) == 1 &&
(vp->v_mount->mnt_flag & MNT_RDONLY) == 0) {
vattr_null(&vattr);
if (np->n_flag & NACC)

View File

@ -1,4 +1,4 @@
/* $NetBSD: rump_vfs.c,v 1.90 2020/02/23 15:46:42 ad Exp $ */
/* $NetBSD: rump_vfs.c,v 1.91 2020/04/13 19:23:20 ad Exp $ */
/*
* Copyright (c) 2008 Antti Kantee. All Rights Reserved.
@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rump_vfs.c,v 1.90 2020/02/23 15:46:42 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: rump_vfs.c,v 1.91 2020/04/13 19:23:20 ad Exp $");
#include <sys/param.h>
#include <sys/buf.h>
@ -382,7 +382,7 @@ int
rump_vp_getref(struct vnode *vp)
{
return vp->v_usecount;
return vrefcnt(vp);
}
void

View File

@ -1,4 +1,4 @@
/* $NetBSD: rumpfs.c,v 1.155 2020/04/04 19:24:51 kamil Exp $ */
/* $NetBSD: rumpfs.c,v 1.156 2020/04/13 19:23:20 ad Exp $ */
/*
* Copyright (c) 2009, 2010, 2011 Antti Kantee. All Rights Reserved.
@ -26,7 +26,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.155 2020/04/04 19:24:51 kamil Exp $");
__KERNEL_RCSID(0, "$NetBSD: rumpfs.c,v 1.156 2020/04/13 19:23:20 ad Exp $");
#include <sys/param.h>
#include <sys/atomic.h>
@ -1906,7 +1906,7 @@ rumpfs_unmount(struct mount *mp, int mntflags)
if (panicstr || mntflags & MNT_FORCE)
flags |= FORCECLOSE;
if (rfsmp->rfsmp_rvp->v_usecount > 1 && (flags & FORCECLOSE) == 0)
if (vrefcnt(rfsmp->rfsmp_rvp) > 1 && (flags & FORCECLOSE) == 0)
return EBUSY;
if ((error = vflush(mp, rfsmp->rfsmp_rvp, flags)) != 0)

View File

@ -1,7 +1,7 @@
/* $NetBSD: vnode.h,v 1.294 2020/03/22 18:32:42 ad Exp $ */
/* $NetBSD: vnode.h,v 1.295 2020/04/13 19:23:20 ad Exp $ */
/*-
* Copyright (c) 2008 The NetBSD Foundation, Inc.
* Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@ -516,6 +516,7 @@ int vdead_check(struct vnode *, int);
void vrevoke(struct vnode *);
void vremfree(struct vnode *);
void vshareilock(struct vnode *, struct vnode *);
int vrefcnt(struct vnode *);
int vcache_get(struct mount *, const void *, size_t, struct vnode **);
int vcache_new(struct mount *, struct vnode *,
struct vattr *, kauth_cred_t, void *, struct vnode **);

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_vnops.c,v 1.331 2020/02/23 15:46:42 ad Exp $ */
/* $NetBSD: lfs_vnops.c,v 1.332 2020/04/13 19:23:20 ad Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
@ -125,7 +125,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.331 2020/02/23 15:46:42 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_vnops.c,v 1.332 2020/04/13 19:23:20 ad Exp $");
#ifdef _KERNEL_OPT
#include "opt_compat_netbsd.h"
@ -1346,7 +1346,7 @@ lfs_close(void *v)
vp->v_mount->mnt_iflag & IMNT_UNMOUNT)
return 0;
if (vp->v_usecount > 1 && vp != ip->i_lfs->lfs_ivnode) {
if (vrefcnt(vp) > 1 && vp != ip->i_lfs->lfs_ivnode) {
LFS_ITIMES(ip, NULL, NULL, NULL);
}
return (0);
@ -1373,7 +1373,7 @@ lfsspec_close(void *v)
KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
ip = VTOI(vp);
if (vp->v_usecount > 1) {
if (vrefcnt(vp) > 1) {
LFS_ITIMES(ip, NULL, NULL, NULL);
}
return (VOCALL (spec_vnodeop_p, VOFFSET(vop_close), ap));
@ -1400,7 +1400,7 @@ lfsfifo_close(void *v)
KASSERT(VOP_ISLOCKED(vp) == LK_EXCLUSIVE);
ip = VTOI(vp);
if (ap->a_vp->v_usecount > 1) {
if (vrefcnt(ap->a_vp) > 1) {
LFS_ITIMES(ip, NULL, NULL, NULL);
}
return (VOCALL (fifo_vnodeop_p, VOFFSET(vop_close), ap));

View File

@ -1,4 +1,4 @@
/* $NetBSD: mfs_vnops.c,v 1.59 2019/02/20 10:03:55 hannken Exp $ */
/* $NetBSD: mfs_vnops.c,v 1.60 2020/04/13 19:23:20 ad Exp $ */
/*
* Copyright (c) 1989, 1993
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mfs_vnops.c,v 1.59 2019/02/20 10:03:55 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: mfs_vnops.c,v 1.60 2020/04/13 19:23:20 ad Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -140,7 +140,7 @@ mfs_strategy(void *v)
struct buf *bp = ap->a_bp;
struct mfsnode *mfsp;
if (vp->v_type != VBLK || vp->v_usecount == 0)
if (vp->v_type != VBLK || vrefcnt(vp) == 0)
panic("mfs_strategy: bad dev");
mfsp = VTOMFS(vp);
/* check for mini-root access */

View File

@ -1,4 +1,4 @@
/* $NetBSD: ufs_vnops.c,v 1.250 2020/04/04 20:49:31 ad Exp $ */
/* $NetBSD: ufs_vnops.c,v 1.251 2020/04/13 19:23:20 ad Exp $ */
/*-
* Copyright (c) 2008, 2020 The NetBSD Foundation, Inc.
@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.250 2020/04/04 20:49:31 ad Exp $");
__KERNEL_RCSID(0, "$NetBSD: ufs_vnops.c,v 1.251 2020/04/13 19:23:20 ad Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ffs.h"
@ -250,7 +250,7 @@ ufs_close(void *v)
struct vnode *vp;
vp = ap->a_vp;
if (vp->v_usecount > 1)
if (vrefcnt(vp) > 1)
UFS_ITIMES(vp, NULL, NULL, NULL);
return (0);
}
@ -1669,7 +1669,7 @@ ufsspec_close(void *v)
struct vnode *vp;
vp = ap->a_vp;
if (vp->v_usecount > 1)
if (vrefcnt(vp) > 1)
UFS_ITIMES(vp, NULL, NULL, NULL);
return (VOCALL (spec_vnodeop_p, VOFFSET(vop_close), ap));
}
@ -1730,7 +1730,7 @@ ufsfifo_close(void *v)
struct vnode *vp;
vp = ap->a_vp;
if (ap->a_vp->v_usecount > 1)
if (vrefcnt(ap->a_vp) > 1)
UFS_ITIMES(vp, NULL, NULL, NULL);
return (VOCALL (fifo_vnodeop_p, VOFFSET(vop_close), ap));
}