Add vfs_ref(mp) and vfs_rele(mp) to add or remove a reference to

struct mount.  Rename vfs_destroy(mp) to vfs_rele(mp) and replace
incrementing mp->mnt_refcnt with vfs_ref(mp).
This commit is contained in:
hannken 2017-04-17 08:31:01 +00:00
parent 256581e1f9
commit ebb8f73b4b
16 changed files with 82 additions and 69 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: cd9660_vfsops.c,v 1.91 2017/02/17 08:31:24 hannken Exp $ */
/* $NetBSD: cd9660_vfsops.c,v 1.92 2017/04/17 08:31:01 hannken Exp $ */
/*-
* Copyright (c) 1994
@ -37,7 +37,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.91 2017/02/17 08:31:24 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.92 2017/04/17 08:31:01 hannken Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@ -192,7 +192,7 @@ cd9660_mountroot(void)
args.flags = ISOFSMNT_ROOT;
if ((error = iso_mountfs(rootvp, mp, l, &args)) != 0) {
vfs_unbusy(mp, false, NULL);
vfs_destroy(mp);
vfs_rele(mp);
return (error);
}
mountlist_append(mp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: filecore_vfsops.c,v 1.79 2017/02/17 08:31:24 hannken Exp $ */
/* $NetBSD: filecore_vfsops.c,v 1.80 2017/04/17 08:31:01 hannken Exp $ */
/*-
* Copyright (c) 1994 The Regents of the University of California.
@ -66,7 +66,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.79 2017/02/17 08:31:24 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.80 2017/04/17 08:31:01 hannken Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@ -202,7 +202,7 @@ filecore_mountroot(void)
args.flags = FILECOREMNT_ROOT;
if ((error = filecore_mountfs(rootvp, mp, p, &args)) != 0) {
vfs_unbusy(mp, false, NULL);
vfs_destroy(mp);
vfs_rele(mp);
return (error);
}
mountlist_append(mp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: msdosfs_vfsops.c,v 1.125 2017/04/01 19:35:56 riastradh Exp $ */
/* $NetBSD: msdosfs_vfsops.c,v 1.126 2017/04/17 08:31:01 hannken 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.125 2017/04/01 19:35:56 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.126 2017/04/17 08:31:01 hannken Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@ -248,14 +248,14 @@ msdosfs_mountroot(void)
if ((error = msdosfs_mountfs(rootvp, mp, l, &args)) != 0) {
vfs_unbusy(mp, false, NULL);
vfs_destroy(mp);
vfs_rele(mp);
return (error);
}
if ((error = update_mp(mp, &args)) != 0) {
(void)msdosfs_unmount(mp, 0);
vfs_unbusy(mp, false, NULL);
vfs_destroy(mp);
vfs_rele(mp);
vrele(rootvp);
return (error);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: ntfs_vfsops.c,v 1.105 2017/02/17 08:31:24 hannken Exp $ */
/* $NetBSD: ntfs_vfsops.c,v 1.106 2017/04/17 08:31:01 hannken Exp $ */
/*-
* Copyright (c) 1998, 1999 Semen Ustimenko
@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ntfs_vfsops.c,v 1.105 2017/02/17 08:31:24 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: ntfs_vfsops.c,v 1.106 2017/04/17 08:31:01 hannken Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -116,7 +116,7 @@ ntfs_mountroot(void)
if ((error = ntfs_mountfs(rootvp, mp, &args, l)) != 0) {
vfs_unbusy(mp, false, NULL);
vfs_destroy(mp);
vfs_rele(mp);
return (error);
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: puffs_msgif.c,v 1.100 2016/12/26 08:21:09 skrll Exp $ */
/* $NetBSD: puffs_msgif.c,v 1.101 2017/04/17 08:31:01 hannken Exp $ */
/*
* Copyright (c) 2005, 2006, 2007 Antti Kantee. All Rights Reserved.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: puffs_msgif.c,v 1.100 2016/12/26 08:21:09 skrll Exp $");
__KERNEL_RCSID(0, "$NetBSD: puffs_msgif.c,v 1.101 2017/04/17 08:31:01 hannken Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -1097,7 +1097,7 @@ puffs_sop_thread(void *arg)
* We know the mountpoint is still alive because
* the thread that is us (poetic?) is still alive.
*/
atomic_inc_uint((unsigned int*)&mp->mnt_refcnt);
vfs_ref(mp);
break;
}
@ -1137,7 +1137,7 @@ puffs_sop_thread(void *arg)
*/
if (unmountme) {
(void)dounmount(mp, MNT_FORCE, curlwp);
vfs_destroy(mp);
vfs_rele(mp);
}
kthread_exit(0);
@ -1182,13 +1182,13 @@ puffs_msgif_close(void *ctx)
}
/* Won't access pmp from here anymore */
atomic_inc_uint((unsigned int*)&mp->mnt_refcnt);
vfs_ref(mp);
puffs_mp_release(pmp);
mutex_exit(&pmp->pmp_lock);
/* Detach from VFS. */
(void)dounmount(mp, MNT_FORCE, curlwp);
vfs_destroy(mp);
vfs_rele(mp);
return 0;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: v7fs_vfsops.c,v 1.13 2017/04/01 19:35:57 riastradh Exp $ */
/* $NetBSD: v7fs_vfsops.c,v 1.14 2017/04/17 08:31:02 hannken Exp $ */
/*-
* Copyright (c) 2004, 2011 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: v7fs_vfsops.c,v 1.13 2017/04/01 19:35:57 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: v7fs_vfsops.c,v 1.14 2017/04/17 08:31:02 hannken Exp $");
#if defined _KERNEL_OPT
#include "opt_v7fs.h"
#endif
@ -580,7 +580,7 @@ v7fs_mountroot(void)
if ((error = v7fs_mountfs(rootvp, mp, _BYTE_ORDER))) {
DPRINTF("mountfs error=%d\n", error);
vfs_unbusy(mp, false, NULL);
vfs_destroy(mp);
vfs_rele(mp);
return error;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_mount.c,v 1.54 2017/04/17 08:29:58 hannken Exp $ */
/* $NetBSD: vfs_mount.c,v 1.55 2017/04/17 08:31:02 hannken Exp $ */
/*-
* Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.54 2017/04/17 08:29:58 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.55 2017/04/17 08:31:02 hannken Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -263,11 +263,23 @@ vfs_getvfs(fsid_t *fsid)
return NULL;
}
/*
* Take a reference to a mount structure.
*/
void
vfs_ref(struct mount *mp)
{
KASSERT(mp->mnt_refcnt > 0 || mutex_owned(&mountlist_lock));
atomic_inc_uint(&mp->mnt_refcnt);
}
/*
* Drop a reference to a mount structure, freeing if the last reference.
*/
void
vfs_destroy(struct mount *mp)
vfs_rele(struct mount *mp)
{
if (__predict_true((int)atomic_dec_uint_nv(&mp->mnt_refcnt) > 0)) {
@ -315,7 +327,7 @@ vfs_busy(struct mount *mp, struct mount **nextp)
++mp->mnt_busynest;
KASSERT(mp->mnt_busynest != 0);
mutex_exit(&mp->mnt_unmounting);
atomic_inc_uint(&mp->mnt_refcnt);
vfs_ref(mp);
return 0;
}
@ -340,7 +352,7 @@ vfs_unbusy(struct mount *mp, bool keepref, struct mount **nextp)
mp->mnt_busynest--;
mutex_exit(&mp->mnt_unmounting);
if (!keepref) {
vfs_destroy(mp);
vfs_rele(mp);
}
}
@ -460,7 +472,7 @@ vfs_insmntque(vnode_t *vp, struct mount *mp)
if (omp != NULL) {
/* Release reference to old mount. */
vfs_destroy(omp);
vfs_rele(omp);
}
}
@ -716,7 +728,7 @@ mount_domount(struct lwp *l, vnode_t **vpp, struct vfsops *vfsops,
if ((error = fstrans_mount(mp)) != 0) {
vfs_unbusy(mp, false, NULL);
vfs_destroy(mp);
vfs_rele(mp);
return error;
}
@ -791,7 +803,7 @@ mount_domount(struct lwp *l, vnode_t **vpp, struct vfsops *vfsops,
(void)start_extattr(mp);
}
/* Drop reference held for VFS_START(). */
vfs_destroy(mp);
vfs_rele(mp);
*vpp = NULL;
return error;
@ -804,7 +816,7 @@ err_unmounted:
mutex_exit(&mp->mnt_updating);
fstrans_unmount(mp);
vfs_unbusy(mp, false, NULL);
vfs_destroy(mp);
vfs_rele(mp);
return error;
}
@ -941,7 +953,7 @@ dounmount(struct mount *mp, int flags, struct lwp *l)
vfs_hooks_unmount(mp);
fstrans_unmount(mp);
vfs_destroy(mp); /* reference from mount() */
vfs_rele(mp); /* reference from mount() */
if (coveredvp != NULLVP) {
vrele(coveredvp);
}
@ -986,9 +998,9 @@ vfs_unmount_next(uint64_t gen)
if ((nmp == NULL || mp->mnt_gen > nmp->mnt_gen) &&
mp->mnt_gen < gen) {
if (nmp != NULL)
vfs_destroy(nmp);
vfs_rele(nmp);
nmp = mp;
atomic_inc_uint(&nmp->mnt_refcnt);
vfs_ref(nmp);
}
}
mountlist_iterator_destroy(iter);
@ -1015,7 +1027,7 @@ vfs_unmount_forceone(struct lwp *l)
vfs_unmount_print(mp, "forcefully ");
return true;
} else {
vfs_destroy(mp);
vfs_rele(mp);
}
#ifdef DEBUG
@ -1050,7 +1062,7 @@ vfs_unmountall1(struct lwp *l, bool force, bool verbose)
vfs_unmount_print(mp, "");
progress = true;
} else {
vfs_destroy(mp);
vfs_rele(mp);
if (verbose) {
printf("unmount of %s failed with error %d\n",
mp->mnt_stat.f_mntonname, error);
@ -1551,16 +1563,16 @@ mountlist_iterator_next(mount_iterator_t *mi)
/* Take an initial reference for vfs_busy() below. */
mp = me->me_mount;
KASSERT(mp != NULL);
atomic_inc_uint(&mp->mnt_refcnt);
vfs_ref(mp);
mutex_exit(&mountlist_lock);
/* Try to mark this mount busy and return on success. */
if (vfs_busy(mp, NULL) == 0) {
vfs_destroy(mp);
vfs_rele(mp);
marker->me_mount = mp;
return mp;
}
vfs_destroy(mp);
vfs_rele(mp);
mutex_enter(&mountlist_lock);
}
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_syscalls.c,v 1.510 2017/04/12 10:28:39 hannken Exp $ */
/* $NetBSD: vfs_syscalls.c,v 1.511 2017/04/17 08:31:02 hannken Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@ -70,7 +70,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.510 2017/04/12 10:28:39 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.511 2017/04/17 08:31:02 hannken Exp $");
#ifdef _KERNEL_OPT
#include "opt_fileassoc.h"
@ -595,14 +595,14 @@ sys_unmount(struct lwp *l, const struct sys_unmount_args *uap, register_t *retva
pathbuf_destroy(pb);
mp = vp->v_mount;
atomic_inc_uint(&mp->mnt_refcnt);
vfs_ref(mp);
VOP_UNLOCK(vp);
error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT,
KAUTH_REQ_SYSTEM_MOUNT_UNMOUNT, mp, NULL, NULL);
if (error) {
vrele(vp);
vfs_destroy(mp);
vfs_rele(mp);
return (error);
}
@ -611,7 +611,7 @@ sys_unmount(struct lwp *l, const struct sys_unmount_args *uap, register_t *retva
*/
if (mp->mnt_flag & MNT_ROOTFS) {
vrele(vp);
vfs_destroy(mp);
vfs_rele(mp);
return (EINVAL);
}
@ -620,13 +620,13 @@ sys_unmount(struct lwp *l, const struct sys_unmount_args *uap, register_t *retva
*/
if ((vp->v_vflag & VV_ROOT) == 0) {
vrele(vp);
vfs_destroy(mp);
vfs_rele(mp);
return (EINVAL);
}
vrele(vp);
error = dounmount(mp, SCARG(uap, flags), l);
vfs_destroy(mp);
vfs_rele(mp);
return error;
}

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_trans.c,v 1.41 2017/04/12 10:23:35 hannken Exp $ */
/* $NetBSD: vfs_trans.c,v 1.42 2017/04/17 08:31:02 hannken Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.41 2017/04/12 10:23:35 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.42 2017/04/17 08:31:02 hannken Exp $");
/*
* File system transaction operations.
@ -179,7 +179,7 @@ fstrans_mount_dtor(struct mount *mp)
mutex_exit(&fstrans_mount_lock);
kmem_free(fmi, sizeof(*fmi));
vfs_destroy(mp);
vfs_rele(mp);
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_vnode.c,v 1.85 2017/04/16 16:48:08 riastradh Exp $ */
/* $NetBSD: vfs_vnode.c,v 1.86 2017/04/17 08:31:02 hannken Exp $ */
/*-
* Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@ -156,7 +156,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.85 2017/04/16 16:48:08 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_vnode.c,v 1.86 2017/04/17 08:31:02 hannken Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -1595,7 +1595,7 @@ vcache_reclaim(vnode_t *vp)
* operations vector. See sys/kern/vnode_if.c.
*/
vp->v_vflag &= ~VV_ROOT;
atomic_inc_uint(&dead_rootmount->mnt_refcnt);
vfs_ref(dead_rootmount);
vfs_insmntque(vp, dead_rootmount);
mutex_enter(vp->v_interlock);

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfs_vfsops.c,v 1.233 2017/04/01 19:35:57 riastradh Exp $ */
/* $NetBSD: nfs_vfsops.c,v 1.234 2017/04/17 08:31:02 hannken Exp $ */
/*
* Copyright (c) 1989, 1993, 1995
@ -35,7 +35,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.233 2017/04/01 19:35:57 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.234 2017/04/17 08:31:02 hannken Exp $");
#if defined(_KERNEL_OPT)
#include "opt_nfs.h"
@ -436,7 +436,7 @@ nfs_mount_diskless(struct nfs_dlmount *ndmntp, const char *mntname, struct mount
ndmntp->ndm_args.hostname, vpp, l);
if (error) {
vfs_unbusy(mp, false, NULL);
vfs_destroy(mp);
vfs_rele(mp);
printf("nfs_mountroot: mount %s failed: %d\n",
mntname, error);
} else

View File

@ -1,4 +1,4 @@
/* $NetBSD: mount.h,v 1.223 2017/04/17 08:29:58 hannken Exp $ */
/* $NetBSD: mount.h,v 1.224 2017/04/17 08:31:02 hannken Exp $ */
/*
* Copyright (c) 1989, 1991, 1993
@ -424,7 +424,8 @@ int vfs_detach(struct vfsops *);
void vfs_reinit(void);
struct vfsops *vfs_getopsbyname(const char *);
void vfs_delref(struct vfsops *);
void vfs_destroy(struct mount *);
void vfs_ref(struct mount *);
void vfs_rele(struct mount *);
struct mount *vfs_mountalloc(struct vfsops *, struct vnode *);
int vfs_stdextattrctl(struct mount *, int, struct vnode *,
int, const char *);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ext2fs_vfsops.c,v 1.206 2017/04/01 19:35:57 riastradh Exp $ */
/* $NetBSD: ext2fs_vfsops.c,v 1.207 2017/04/17 08:31:02 hannken Exp $ */
/*
* Copyright (c) 1989, 1991, 1993, 1994
@ -60,7 +60,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.206 2017/04/01 19:35:57 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.207 2017/04/17 08:31:02 hannken Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@ -280,7 +280,7 @@ ext2fs_mountroot(void)
if ((error = ext2fs_mountfs(rootvp, mp)) != 0) {
vfs_unbusy(mp, false, NULL);
vfs_destroy(mp);
vfs_rele(mp);
return error;
}
mountlist_append(mp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_vfsops.c,v 1.351 2017/04/01 19:35:56 riastradh Exp $ */
/* $NetBSD: ffs_vfsops.c,v 1.352 2017/04/17 08:31:02 hannken Exp $ */
/*-
* Copyright (c) 2008, 2009 The NetBSD Foundation, Inc.
@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.351 2017/04/01 19:35:56 riastradh Exp $");
__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.352 2017/04/17 08:31:02 hannken Exp $");
#if defined(_KERNEL_OPT)
#include "opt_ffs.h"
@ -378,7 +378,7 @@ ffs_mountroot(void)
mp->mnt_flag |= MNT_FORCE;
if ((error = ffs_mountfs(rootvp, mp, l)) != 0) {
vfs_unbusy(mp, false, NULL);
vfs_destroy(mp);
vfs_rele(mp);
return (error);
}
mp->mnt_flag &= ~MNT_FORCE;

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_vfsops.c,v 1.357 2017/04/13 09:57:28 hannken Exp $ */
/* $NetBSD: lfs_vfsops.c,v 1.358 2017/04/17 08:31:02 hannken Exp $ */
/*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
@ -61,7 +61,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.357 2017/04/13 09:57:28 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.358 2017/04/17 08:31:02 hannken Exp $");
#if defined(_KERNEL_OPT)
#include "opt_lfs.h"
@ -596,7 +596,7 @@ lfs_mountroot(void)
}
if ((error = lfs_mountfs(rootvp, mp, l))) {
vfs_unbusy(mp, false, NULL);
vfs_destroy(mp);
vfs_rele(mp);
return (error);
}
mountlist_append(mp);

View File

@ -1,4 +1,4 @@
/* $NetBSD: mfs_vfsops.c,v 1.111 2017/02/17 08:31:26 hannken Exp $ */
/* $NetBSD: mfs_vfsops.c,v 1.112 2017/04/17 08:31:02 hannken Exp $ */
/*
* Copyright (c) 1989, 1990, 1993, 1994
@ -32,7 +32,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mfs_vfsops.c,v 1.111 2017/02/17 08:31:26 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: mfs_vfsops.c,v 1.112 2017/04/17 08:31:02 hannken Exp $");
#if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h"
@ -217,7 +217,7 @@ mfs_mountroot(void)
if ((error = ffs_mountfs(rootvp, mp, l)) != 0) {
vfs_unbusy(mp, false, NULL);
bufq_free(mfsp->mfs_buflist);
vfs_destroy(mp);
vfs_rele(mp);
kmem_free(mfsp, sizeof(*mfsp));
return (error);
}