PR kern/38135 vfs_busy/vfs_trybusy confusion

The previous fix worked, but it opened a window where mounts could have
disappeared from mountlist while the caller was traversing it using
vfs_trybusy(). Fix that.
This commit is contained in:
ad 2008-04-30 12:49:16 +00:00
parent 83bf8c56bb
commit 928a6b2096
27 changed files with 210 additions and 163 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_syscalls_20.c,v 1.27 2008/04/29 23:51:04 ad Exp $ */ /* $NetBSD: vfs_syscalls_20.c,v 1.28 2008/04/30 12:49:16 ad Exp $ */
/* /*
* Copyright (c) 1989, 1993 * Copyright (c) 1989, 1993
@ -37,7 +37,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_20.c,v 1.27 2008/04/29 23:51:04 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_20.c,v 1.28 2008/04/30 12:49:16 ad Exp $");
#include "opt_compat_netbsd.h" #include "opt_compat_netbsd.h"
#include "opt_compat_43.h" #include "opt_compat_43.h"
@ -229,13 +229,12 @@ compat_20_sys_getfsstat(struct lwp *l, const struct compat_20_sys_getfsstat_args
error = dostatvfs(mp, sbuf, l, SCARG(uap, flags), 0); error = dostatvfs(mp, sbuf, l, SCARG(uap, flags), 0);
if (error) { if (error) {
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
nmp = CIRCLEQ_NEXT(mp, mnt_list); vfs_unbusy(mp, false, &nmp);
vfs_unbusy(mp, false);
continue; continue;
} }
error = vfs2fs(sfsp, sbuf); error = vfs2fs(sfsp, sbuf);
if (error) { if (error) {
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
goto out; goto out;
} }
sfsp++; sfsp++;
@ -243,8 +242,7 @@ compat_20_sys_getfsstat(struct lwp *l, const struct compat_20_sys_getfsstat_args
} }
count++; count++;
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
nmp = CIRCLEQ_NEXT(mp, mnt_list); vfs_unbusy(mp, false, &nmp);
vfs_unbusy(mp, false);
} }
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
if (root == 0 && l->l_proc->p_cwdi->cwdi_rdir) { if (root == 0 && l->l_proc->p_cwdi->cwdi_rdir) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: netbsd32_compat_20.c,v 1.22 2008/04/30 06:49:23 jmmv Exp $ */ /* $NetBSD: netbsd32_compat_20.c,v 1.23 2008/04/30 12:49:16 ad Exp $ */
/* /*
* Copyright (c) 1998, 2001 Matthew R. Green * Copyright (c) 1998, 2001 Matthew R. Green
@ -29,7 +29,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_20.c,v 1.22 2008/04/30 06:49:23 jmmv Exp $"); __KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_20.c,v 1.23 2008/04/30 12:49:16 ad Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
@ -122,23 +122,21 @@ compat_20_netbsd32_getfsstat(struct lwp *l, const struct compat_20_netbsd32_getf
SCARG(uap, flags) == 0) && SCARG(uap, flags) == 0) &&
(error = VFS_STATVFS(mp, sp)) != 0) { (error = VFS_STATVFS(mp, sp)) != 0) {
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
nmp = mp->mnt_list.cqe_next; vfs_unbusy(mp, false, &nmp);
vfs_unbusy(mp, false);
continue; continue;
} }
sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK; sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
compat_20_netbsd32_from_statvfs(sp, &sb32); compat_20_netbsd32_from_statvfs(sp, &sb32);
error = copyout(&sb32, sfsp, sizeof(sb32)); error = copyout(&sb32, sfsp, sizeof(sb32));
if (error) { if (error) {
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
return (error); return (error);
} }
sfsp = (char *)sfsp + sizeof(sb32); sfsp = (char *)sfsp + sizeof(sb32);
} }
count++; count++;
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
nmp = mp->mnt_list.cqe_next; vfs_unbusy(mp, false, &nmp);
vfs_unbusy(mp, false);
} }
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
if (sfsp && count > maxcount) if (sfsp && count > maxcount)

View File

@ -1,4 +1,4 @@
/* $NetBSD: osf1_mount.c,v 1.42 2008/04/30 06:49:23 jmmv Exp $ */ /* $NetBSD: osf1_mount.c,v 1.43 2008/04/30 12:49:16 ad Exp $ */
/* /*
* Copyright (c) 1999 Christopher G. Demetriou. All rights reserved. * Copyright (c) 1999 Christopher G. Demetriou. All rights reserved.
@ -58,7 +58,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: osf1_mount.c,v 1.42 2008/04/30 06:49:23 jmmv Exp $"); __KERNEL_RCSID(0, "$NetBSD: osf1_mount.c,v 1.43 2008/04/30 12:49:16 ad Exp $");
#if defined(_KERNEL_OPT) #if defined(_KERNEL_OPT)
#include "fs_nfs.h" #include "fs_nfs.h"
@ -167,7 +167,7 @@ osf1_sys_getfsstat(struct lwp *l, const struct osf1_sys_getfsstat_args *uap, reg
osf1_cvt_statfs_from_native(sp, &osfs); osf1_cvt_statfs_from_native(sp, &osfs);
if ((error = copyout(&osfs, osf_sfsp, if ((error = copyout(&osfs, osf_sfsp,
sizeof (struct osf1_statfs)))) { sizeof (struct osf1_statfs)))) {
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
return (error); return (error);
} }
osf_sfsp += sizeof (struct osf1_statfs); osf_sfsp += sizeof (struct osf1_statfs);
@ -175,8 +175,7 @@ osf1_sys_getfsstat(struct lwp *l, const struct osf1_sys_getfsstat_args *uap, reg
} }
count++; count++;
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
nmp = mp->mnt_list.cqe_next; vfs_unbusy(mp, false, &nmp);
vfs_unbusy(mp, false);
} }
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
if (osf_sfsp && count > maxcount) if (osf_sfsp && count > maxcount)

View File

@ -1,4 +1,4 @@
/* $NetBSD: ultrix_fs.c,v 1.47 2008/04/30 06:49:23 jmmv Exp $ */ /* $NetBSD: ultrix_fs.c,v 1.48 2008/04/30 12:49:16 ad Exp $ */
/* /*
* Copyright (c) 1995, 1997 Jonathan Stone * Copyright (c) 1995, 1997 Jonathan Stone
@ -33,7 +33,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ultrix_fs.c,v 1.47 2008/04/30 06:49:23 jmmv Exp $"); __KERNEL_RCSID(0, "$NetBSD: ultrix_fs.c,v 1.48 2008/04/30 12:49:16 ad Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
@ -280,7 +280,7 @@ ultrix_sys_getmnt(struct lwp *l, const struct ultrix_sys_getmnt_args *uap, regis
make_ultrix_mntent(sp, &tem); make_ultrix_mntent(sp, &tem);
if ((error = copyout((void *)&tem, sfsp, if ((error = copyout((void *)&tem, sfsp,
sizeof(tem))) != 0) { sizeof(tem))) != 0) {
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
goto bad; goto bad;
} }
sfsp++; sfsp++;
@ -288,8 +288,7 @@ ultrix_sys_getmnt(struct lwp *l, const struct ultrix_sys_getmnt_args *uap, regis
} }
} }
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
nmp = mp->mnt_list.cqe_next; vfs_unbusy(mp, false, &nmp);
vfs_unbusy(mp, false);
} }
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);

View File

@ -1,4 +1,4 @@
/* $NetBSD: cd9660_vfsops.c,v 1.58 2008/04/29 18:18:08 ad Exp $ */ /* $NetBSD: cd9660_vfsops.c,v 1.59 2008/04/30 12:49:16 ad Exp $ */
/*- /*-
* Copyright (c) 1994 * Copyright (c) 1994
@ -37,7 +37,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.58 2008/04/29 18:18:08 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.59 2008/04/30 12:49:16 ad Exp $");
#if defined(_KERNEL_OPT) #if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h" #include "opt_compat_netbsd.h"
@ -149,15 +149,16 @@ cd9660_mountroot(void)
args.flags = ISOFSMNT_ROOT; args.flags = ISOFSMNT_ROOT;
if ((error = iso_mountfs(rootvp, mp, l, &args)) != 0) { if ((error = iso_mountfs(rootvp, mp, l, &args)) != 0) {
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
vfs_destroy(mp); vfs_destroy(mp, false);
return (error); return (error);
} }
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list); CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
mp->mnt_iflag |= IMNT_ONLIST;
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
(void)cd9660_statvfs(mp, &mp->mnt_stat); (void)cd9660_statvfs(mp, &mp->mnt_stat);
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
return (0); return (0);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: filecore_vfsops.c,v 1.50 2008/04/29 18:18:08 ad Exp $ */ /* $NetBSD: filecore_vfsops.c,v 1.51 2008/04/30 12:49:16 ad Exp $ */
/*- /*-
* Copyright (c) 1994 The Regents of the University of California. * Copyright (c) 1994 The Regents of the University of California.
@ -66,7 +66,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.50 2008/04/29 18:18:08 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.51 2008/04/30 12:49:16 ad Exp $");
#if defined(_KERNEL_OPT) #if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h" #include "opt_compat_netbsd.h"
@ -173,15 +173,16 @@ filecore_mountroot()
args.flags = FILECOREMNT_ROOT; args.flags = FILECOREMNT_ROOT;
if ((error = filecore_mountfs(rootvp, mp, p, &args)) != 0) { if ((error = filecore_mountfs(rootvp, mp, p, &args)) != 0) {
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
vfs_destroy(mp); vfs_destroy(mp, false);
return (error); return (error);
} }
simple_lock(&mountlist_slock); simple_lock(&mountlist_slock);
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list); CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
mp->mnt_iflag |= IMNT_ONLIST;
simple_unlock(&mountlist_slock); simple_unlock(&mountlist_slock);
(void)filecore_statvfs(mp, &mp->mnt_stat, p); (void)filecore_statvfs(mp, &mp->mnt_stat, p);
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
return (0); return (0);
} }
#endif #endif

View File

@ -1,4 +1,4 @@
/* $NetBSD: msdosfs_vfsops.c,v 1.62 2008/04/29 18:18:08 ad Exp $ */ /* $NetBSD: msdosfs_vfsops.c,v 1.63 2008/04/30 12:49:16 ad Exp $ */
/*- /*-
* Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank. * Copyright (C) 1994, 1995, 1997 Wolfgang Solfrank.
@ -48,7 +48,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.62 2008/04/29 18:18:08 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.63 2008/04/30 12:49:16 ad Exp $");
#if defined(_KERNEL_OPT) #if defined(_KERNEL_OPT)
#include "opt_quota.h" #include "opt_quota.h"
@ -213,24 +213,25 @@ msdosfs_mountroot()
args.dirmask = 0777; args.dirmask = 0777;
if ((error = msdosfs_mountfs(rootvp, mp, l, &args)) != 0) { if ((error = msdosfs_mountfs(rootvp, mp, l, &args)) != 0) {
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
vfs_destroy(mp); vfs_destroy(mp, false);
return (error); return (error);
} }
if ((error = update_mp(mp, &args)) != 0) { if ((error = update_mp(mp, &args)) != 0) {
(void)msdosfs_unmount(mp, 0); (void)msdosfs_unmount(mp, 0);
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
vfs_destroy(mp); vfs_destroy(mp, false);
vrele(rootvp); vrele(rootvp);
return (error); return (error);
} }
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list); CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
mp->mnt_iflag |= IMNT_ONLIST;
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
(void)msdosfs_statvfs(mp, &mp->mnt_stat); (void)msdosfs_statvfs(mp, &mp->mnt_stat);
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
return (0); return (0);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: ntfs_vfsops.c,v 1.66 2008/04/29 18:18:08 ad Exp $ */ /* $NetBSD: ntfs_vfsops.c,v 1.67 2008/04/30 12:49:16 ad Exp $ */
/*- /*-
* Copyright (c) 1998, 1999 Semen Ustimenko * Copyright (c) 1998, 1999 Semen Ustimenko
@ -29,7 +29,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ntfs_vfsops.c,v 1.66 2008/04/29 18:18:08 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: ntfs_vfsops.c,v 1.67 2008/04/30 12:49:16 ad Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
@ -129,16 +129,17 @@ ntfs_mountroot()
args.mode = 0777; args.mode = 0777;
if ((error = ntfs_mountfs(rootvp, mp, &args, l)) != 0) { if ((error = ntfs_mountfs(rootvp, mp, &args, l)) != 0) {
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
vfs_destroy(mp); vfs_destroy(mp, false);
return (error); return (error);
} }
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list); CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
mp->mnt_iflag |= IMNT_ONLIST;
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
(void)ntfs_statvfs(mp, &mp->mnt_stat); (void)ntfs_statvfs(mp, &mp->mnt_stat);
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
return (0); return (0);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: puffs_msgif.c,v 1.69 2008/04/29 23:51:04 ad Exp $ */ /* $NetBSD: puffs_msgif.c,v 1.70 2008/04/30 12:49:16 ad Exp $ */
/* /*
* Copyright (c) 2005, 2006, 2007 Antti Kantee. All Rights Reserved. * Copyright (c) 2005, 2006, 2007 Antti Kantee. All Rights Reserved.
@ -30,7 +30,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: puffs_msgif.c,v 1.69 2008/04/29 23:51:04 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: puffs_msgif.c,v 1.70 2008/04/30 12:49:16 ad Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/atomic.h> #include <sys/atomic.h>
@ -1036,7 +1036,7 @@ puffs_msgif_close(void *this)
mutex_enter(&syncer_mutex); mutex_enter(&syncer_mutex);
if (mp->mnt_iflag & IMNT_GONE) { if (mp->mnt_iflag & IMNT_GONE) {
mutex_exit(&syncer_mutex); mutex_exit(&syncer_mutex);
vfs_destroy(mp); vfs_destroy(mp, false);
return 0; return 0;
} }
@ -1053,7 +1053,7 @@ puffs_msgif_close(void *this)
*/ */
if (vfs_busy(mp, RW_WRITER)) { if (vfs_busy(mp, RW_WRITER)) {
mutex_exit(&syncer_mutex); mutex_exit(&syncer_mutex);
vfs_destroy(mp); vfs_destroy(mp, false);
return 0; return 0;
} }
@ -1064,7 +1064,7 @@ puffs_msgif_close(void *this)
*/ */
rv = dounmount(mp, MNT_FORCE, curlwp); rv = dounmount(mp, MNT_FORCE, curlwp);
KASSERT(rv == 0); KASSERT(rv == 0);
vfs_destroy(mp); vfs_destroy(mp, false);
return 0; return 0;
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: union_vnops.c,v 1.31 2008/04/29 23:51:04 ad Exp $ */ /* $NetBSD: union_vnops.c,v 1.32 2008/04/30 12:49:16 ad Exp $ */
/* /*
* Copyright (c) 1992, 1993, 1994, 1995 * Copyright (c) 1992, 1993, 1994, 1995
@ -72,7 +72,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.31 2008/04/29 23:51:04 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.32 2008/04/30 12:49:16 ad Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
@ -253,7 +253,7 @@ union_lookup1(struct vnode *udvp, struct vnode **dvpp, struct vnode **vpp,
continue; continue;
vput(dvp); vput(dvp);
error = VFS_ROOT(mp, &tdvp); error = VFS_ROOT(mp, &tdvp);
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
if (error) { if (error) {
return (error); return (error);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_lookup.c,v 1.105 2008/04/29 23:51:04 ad Exp $ */ /* $NetBSD: vfs_lookup.c,v 1.106 2008/04/30 12:49:16 ad Exp $ */
/* /*
* Copyright (c) 1982, 1986, 1989, 1993 * Copyright (c) 1982, 1986, 1989, 1993
@ -37,7 +37,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.105 2008/04/29 23:51:04 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.106 2008/04/30 12:49:16 ad Exp $");
#include "opt_magiclinks.h" #include "opt_magiclinks.h"
@ -783,7 +783,7 @@ unionlookup:
VOP_UNLOCK(ndp->ni_dvp, 0); VOP_UNLOCK(ndp->ni_dvp, 0);
vput(dp); vput(dp);
error = VFS_ROOT(mp, &tdp); error = VFS_ROOT(mp, &tdp);
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
if (error) { if (error) {
vn_lock(ndp->ni_dvp, LK_EXCLUSIVE | LK_RETRY); vn_lock(ndp->ni_dvp, LK_EXCLUSIVE | LK_RETRY);
goto bad; goto bad;

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_subr.c,v 1.338 2008/04/29 23:51:04 ad Exp $ */ /* $NetBSD: vfs_subr.c,v 1.339 2008/04/30 12:49:16 ad Exp $ */
/*- /*-
* Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc. * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc.
@ -75,7 +75,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.338 2008/04/29 23:51:04 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.339 2008/04/30 12:49:16 ad Exp $");
#include "opt_ddb.h" #include "opt_ddb.h"
#include "opt_compat_netbsd.h" #include "opt_compat_netbsd.h"
@ -304,9 +304,8 @@ vfs_dobusy(struct mount *mp, const krw_t op, struct mount **nextp)
if (__predict_false((mp->mnt_iflag & IMNT_GONE) != 0)) { if (__predict_false((mp->mnt_iflag & IMNT_GONE) != 0)) {
if (nextp != NULL) { if (nextp != NULL) {
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
*nextp = CIRCLEQ_NEXT(mp, mnt_list);
} }
vfs_unbusy(mp, false); vfs_unbusy(mp, false, nextp);
return ENOENT; return ENOENT;
} }
@ -317,7 +316,7 @@ vfs_dobusy(struct mount *mp, const krw_t op, struct mount **nextp)
* Mark a mount point as busy, and gain a new reference to it. Used to * Mark a mount point as busy, and gain a new reference to it. Used to
* synchronize access and to delay unmounting. * synchronize access and to delay unmounting.
* *
* => The caller is expected to hold a reference to the mount. * => The caller must hold a pre-existing reference to the mount.
*/ */
int int
vfs_busy(struct mount *mp, const krw_t op) vfs_busy(struct mount *mp, const krw_t op)
@ -334,7 +333,7 @@ vfs_busy(struct mount *mp, const krw_t op)
} }
mutex_enter(&mount_lock); mutex_enter(&mount_lock);
if (mp->mnt_unmounter != NULL) { if (mp->mnt_unmounter != NULL) {
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
cv_wait(&mount_cv, &mount_lock); cv_wait(&mount_cv, &mount_lock);
} }
mutex_exit(&mount_lock); mutex_exit(&mount_lock);
@ -345,10 +344,11 @@ vfs_busy(struct mount *mp, const krw_t op)
* As vfs_busy(), but return error if the file system is being * As vfs_busy(), but return error if the file system is being
* unmounted (and do not wait for the unmount). * unmounted (and do not wait for the unmount).
* *
* => If namep != NULL, mountlist_lock is understood to be held. On * => If nextp != NULL, mountlist_lock is understood to be held. On
* failure a pointer to the next mount will be returned via namep. * failure a pointer to the next mount will be returned via nextp.
* The caller need not hold a reference to the mount.
* *
* => If namep == NULL, the caller is expected to hold a reference * => If nextp == NULL, the caller is expected to hold a reference
* to the mount. * to the mount.
*/ */
int int
@ -359,14 +359,31 @@ vfs_trybusy(struct mount *mp, krw_t op, struct mount **nextp)
KASSERT(nextp == NULL || mutex_owned(&mountlist_lock)); KASSERT(nextp == NULL || mutex_owned(&mountlist_lock));
if (nextp != NULL) {
/*
* We need to prevent adding a reference to the mount
* if it is already on the way out: the reference count
* could be zero, and as a result another thread could
* be in vfs_destroy() trying to throw away the mount.
*
* mnt_iflag is protected by mnt_lock, but this check is
* safe if mountlist_lock is held. mountlist_lock will
* be held by vfs_destroy() before removing the mount
* from mountlist.
*/
if (__predict_false((mp->mnt_iflag & IMNT_GONE) != 0)) {
*nextp = CIRCLEQ_NEXT(mp, mnt_list);
return ENOENT;
}
}
error = vfs_dobusy(mp, op, nextp); error = vfs_dobusy(mp, op, nextp);
l = mp->mnt_unmounter; l = mp->mnt_unmounter;
if (error == 0 && (l != NULL && l != curlwp)) { if (error == 0 && (l != NULL && l != curlwp)) {
if (nextp != NULL) { if (nextp != NULL) {
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
*nextp = CIRCLEQ_NEXT(mp, mnt_list);
} }
vfs_unbusy(mp, false); vfs_unbusy(mp, false, nextp);
error = EBUSY; error = EBUSY;
} }
return error; return error;
@ -375,9 +392,12 @@ vfs_trybusy(struct mount *mp, krw_t op, struct mount **nextp)
/* /*
* Unlock a busy filesystem and drop reference to it. If 'keepref' is * Unlock a busy filesystem and drop reference to it. If 'keepref' is
* true, unlock but preserve the reference. * true, unlock but preserve the reference.
*
* => If nextp != NULL, mountlist_lock is understood to be held. On
* failure a pointer to the next mount will be returned via nextp.
*/ */
void void
vfs_unbusy(struct mount *mp, bool keepref) vfs_unbusy(struct mount *mp, bool keepref, struct mount **nextp)
{ {
KASSERT(mp->mnt_refcnt > 0); KASSERT(mp->mnt_refcnt > 0);
@ -393,8 +413,11 @@ vfs_unbusy(struct mount *mp, bool keepref)
} else { } else {
rw_exit(&mp->mnt_lock); rw_exit(&mp->mnt_lock);
} }
if (nextp != NULL) {
*nextp = CIRCLEQ_NEXT(mp, mnt_list);
}
if (!keepref) { if (!keepref) {
vfs_destroy(mp); vfs_destroy(mp, nextp != NULL);
} }
} }
@ -520,7 +543,7 @@ getnewvnode(enum vtagtype tag, struct mount *mp, int (**vops)(void *),
vp = getcleanvnode(); vp = getcleanvnode();
if (vp == NULL) { if (vp == NULL) {
if (mp != NULL) { if (mp != NULL) {
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
} }
if (tryalloc) { if (tryalloc) {
printf("WARNING: unable to allocate new " printf("WARNING: unable to allocate new "
@ -564,7 +587,7 @@ getnewvnode(enum vtagtype tag, struct mount *mp, int (**vops)(void *),
if (mp != NULL) { if (mp != NULL) {
if ((mp->mnt_iflag & IMNT_MPSAFE) != 0) if ((mp->mnt_iflag & IMNT_MPSAFE) != 0)
vp->v_vflag |= VV_MPSAFE; vp->v_vflag |= VV_MPSAFE;
vfs_unbusy(mp, true); vfs_unbusy(mp, true, NULL);
} }
return (0); return (0);
@ -702,7 +725,7 @@ insmntque(vnode_t *vp, struct mount *mp)
if (omp != NULL) { if (omp != NULL) {
/* Release reference to old mount. */ /* Release reference to old mount. */
vfs_destroy(omp); vfs_destroy(omp, false);
} }
} }
@ -1691,8 +1714,7 @@ sysctl_kern_vnode(SYSCTLFN_ARGS)
} }
mutex_exit(&mntvnode_lock); mutex_exit(&mntvnode_lock);
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
nmp = CIRCLEQ_NEXT(mp, mnt_list); vfs_unbusy(mp, false, &nmp);
vfs_unbusy(mp, false);
vnfree(mvp); vnfree(mvp);
} }
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
@ -1720,7 +1742,7 @@ vfs_scrubvnlist(struct mount *mp)
vp->v_mount = NULL; vp->v_mount = NULL;
mutex_exit(&mntvnode_lock); mutex_exit(&mntvnode_lock);
mutex_exit(&vp->v_interlock); mutex_exit(&vp->v_interlock);
vfs_destroy(mp); vfs_destroy(mp, false);
goto retry; goto retry;
} }
mutex_exit(&vp->v_interlock); mutex_exit(&vp->v_interlock);

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_subr2.c,v 1.21 2008/04/29 23:51:04 ad Exp $ */ /* $NetBSD: vfs_subr2.c,v 1.22 2008/04/30 12:49:17 ad Exp $ */
/*- /*-
* Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc. * Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc.
@ -75,7 +75,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_subr2.c,v 1.21 2008/04/29 23:51:04 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: vfs_subr2.c,v 1.22 2008/04/30 12:49:17 ad Exp $");
#include "opt_ddb.h" #include "opt_ddb.h"
@ -190,15 +190,43 @@ vfs_getvfs(fsid_t *fsid)
/* /*
* Drop a reference to a mount structure, freeing if the last reference. * Drop a reference to a mount structure, freeing if the last reference.
*
* => If nextp != NULL, the caller holds mountlist_lock.
*
* => If nextp == NULL, it must be safe to take mountlist_lock.
*/ */
void void
vfs_destroy(struct mount *mp) vfs_destroy(struct mount *mp, bool interlocked)
{ {
if (atomic_dec_uint_nv(&mp->mnt_refcnt) > 0) { KASSERT(!interlocked || mutex_owned(&mountlist_lock));
if (__predict_true(atomic_dec_uint_nv(&mp->mnt_refcnt) > 0)) {
return; return;
} }
KASSERT(mp->mnt_unmounter == NULL); KASSERT(mp->mnt_unmounter == NULL);
/*
* Remove it from the mountlist. We must interlock with
* threads traversing the mountlist. See vfs_trybusy().
*/
if ((mp->mnt_iflag & IMNT_ONLIST) != 0) {
if (!interlocked) {
mutex_enter(&mountlist_lock);
}
CIRCLEQ_REMOVE(&mountlist, mp, mnt_list);
if (!interlocked) {
mutex_exit(&mountlist_lock);
}
} else {
KASSERT((mp->mnt_iflag & IMNT_GONE) != 0);
}
/*
* Nothing else has visibility of the mount: we can now
* free the data structures.
*/
specificdata_fini(mount_specificdata_domain, &mp->mnt_specdataref); specificdata_fini(mount_specificdata_domain, &mp->mnt_specdataref);
rw_destroy(&mp->mnt_lock); rw_destroy(&mp->mnt_lock);
if (mp->mnt_op != NULL) { if (mp->mnt_op != NULL) {
@ -729,8 +757,7 @@ printlockedvnodes(void)
vprint(NULL, vp); vprint(NULL, vp);
} }
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
nmp = CIRCLEQ_NEXT(mp, mnt_list); vfs_unbusy(mp, false, &nmp);
vfs_unbusy(mp, false);
} }
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_syscalls.c,v 1.353 2008/04/29 23:51:04 ad Exp $ */ /* $NetBSD: vfs_syscalls.c,v 1.354 2008/04/30 12:49:17 ad Exp $ */
/*- /*-
* Copyright (c) 2008 The NetBSD Foundation, Inc. * Copyright (c) 2008 The NetBSD Foundation, Inc.
@ -63,7 +63,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.353 2008/04/29 23:51:04 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.354 2008/04/30 12:49:17 ad Exp $");
#include "opt_compat_netbsd.h" #include "opt_compat_netbsd.h"
#include "opt_compat_43.h" #include "opt_compat_43.h"
@ -242,7 +242,7 @@ mount_update(struct lwp *l, struct vnode *vp, const char *path, int flags,
if (mp->mnt_syncer != NULL) if (mp->mnt_syncer != NULL)
vfs_deallocate_syncvnode(mp); vfs_deallocate_syncvnode(mp);
} }
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
out: out:
return (error); return (error);
@ -364,9 +364,8 @@ mount_domount(struct lwp *l, struct vnode **vpp, struct vfsops *vfsops,
cache_purge(vp); cache_purge(vp);
if (error != 0) { if (error != 0) {
vp->v_mountedhere = NULL; vp->v_mountedhere = NULL;
mp->mnt_op->vfs_refcount--; vfs_unbusy(mp, false, NULL);
vfs_unbusy(mp, false); vfs_destroy(mp, false);
vfs_destroy(mp);
return error; return error;
} }
@ -374,6 +373,7 @@ mount_domount(struct lwp *l, struct vnode **vpp, struct vfsops *vfsops,
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
vp->v_mountedhere = mp; vp->v_mountedhere = mp;
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list); CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
mp->mnt_iflag |= IMNT_ONLIST;
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
vn_restorerecurse(vp, recurse); vn_restorerecurse(vp, recurse);
VOP_UNLOCK(vp, 0); VOP_UNLOCK(vp, 0);
@ -381,15 +381,15 @@ mount_domount(struct lwp *l, struct vnode **vpp, struct vfsops *vfsops,
if ((mp->mnt_flag & (MNT_RDONLY | MNT_ASYNC)) == 0) if ((mp->mnt_flag & (MNT_RDONLY | MNT_ASYNC)) == 0)
error = vfs_allocate_syncvnode(mp); error = vfs_allocate_syncvnode(mp);
/* Hold an additional reference to the mount across VFS_START(). */ /* Hold an additional reference to the mount across VFS_START(). */
vfs_unbusy(mp, true); vfs_unbusy(mp, true, NULL);
(void) VFS_STATVFS(mp, &mp->mnt_stat); (void) VFS_STATVFS(mp, &mp->mnt_stat);
error = VFS_START(mp, 0); error = VFS_START(mp, 0);
if (error) { if (error) {
vrele(vp); vrele(vp);
vfs_destroy(mp); vfs_destroy(mp, false);
} }
/* Drop reference held for VFS_START(). */ /* Drop reference held for VFS_START(). */
vfs_destroy(mp); vfs_destroy(mp, false);
*vpp = NULL; *vpp = NULL;
return error; return error;
} }
@ -424,7 +424,7 @@ mount_getargs(struct lwp *l, struct vnode *vp, const char *path, int flags,
error = VFS_MOUNT(mp, path, data, data_len); error = VFS_MOUNT(mp, path, data, data_len);
mp->mnt_flag &= ~MNT_OP_FLAGS; mp->mnt_flag &= ~MNT_OP_FLAGS;
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
return (error); return (error);
} }
@ -674,7 +674,7 @@ dounmount_lock(struct mount *mp)
KASSERT(mp->mnt_unmounter == NULL); KASSERT(mp->mnt_unmounter == NULL);
mp->mnt_unmounter = curlwp; mp->mnt_unmounter = curlwp;
vfs_unbusy(mp, true); vfs_unbusy(mp, true, NULL);
} }
/* /*
@ -684,11 +684,13 @@ static void
dounmount_unlock(struct mount *mp) dounmount_unlock(struct mount *mp)
{ {
KASSERT(mp->mnt_unmounter == curlwp);
mutex_enter(&mount_lock); mutex_enter(&mount_lock);
mp->mnt_unmounter = NULL; mp->mnt_unmounter = NULL;
cv_broadcast(&mount_cv); cv_broadcast(&mount_cv);
mutex_exit(&mount_lock); mutex_exit(&mount_lock);
vfs_destroy(mp); vfs_destroy(mp, false);
} }
/* /*
@ -759,11 +761,8 @@ dounmount(struct mount *mp, int flags, struct lwp *l)
return (error); return (error);
} }
vfs_scrubvnlist(mp); vfs_scrubvnlist(mp);
mutex_enter(&mountlist_lock);
CIRCLEQ_REMOVE(&mountlist, mp, mnt_list);
if ((coveredvp = mp->mnt_vnodecovered) != NULLVP) if ((coveredvp = mp->mnt_vnodecovered) != NULLVP)
coveredvp->v_mountedhere = NULL; coveredvp->v_mountedhere = NULL;
mutex_exit(&mountlist_lock);
if (TAILQ_FIRST(&mp->mnt_vnodelist) != NULL) if (TAILQ_FIRST(&mp->mnt_vnodelist) != NULL)
panic("unmount: dangling vnode"); panic("unmount: dangling vnode");
mp->mnt_iflag |= IMNT_GONE; mp->mnt_iflag |= IMNT_GONE;
@ -771,7 +770,7 @@ dounmount(struct mount *mp, int flags, struct lwp *l)
mutex_exit(&syncer_mutex); mutex_exit(&syncer_mutex);
vfs_hooks_unmount(mp); vfs_hooks_unmount(mp);
dounmount_unlock(mp); dounmount_unlock(mp);
vfs_destroy(mp); vfs_destroy(mp, false);
if (coveredvp != NULLVP) if (coveredvp != NULLVP)
vrele(coveredvp); vrele(coveredvp);
return (0); return (0);
@ -809,8 +808,7 @@ sys_sync(struct lwp *l, const void *v, register_t *retval)
mp->mnt_flag |= MNT_ASYNC; mp->mnt_flag |= MNT_ASYNC;
} }
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
nmp = mp->mnt_list.cqe_next; vfs_unbusy(mp, false, &nmp);
vfs_unbusy(mp, false);
} }
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
@ -1024,13 +1022,12 @@ do_sys_getvfsstat(struct lwp *l, void *sfsp, size_t bufsize, int flags,
error = dostatvfs(mp, sb, l, flags, 0); error = dostatvfs(mp, sb, l, flags, 0);
if (error) { if (error) {
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
nmp = CIRCLEQ_NEXT(mp, mnt_list); vfs_unbusy(mp, false, &nmp);
vfs_unbusy(mp, false);
continue; continue;
} }
error = copyfn(sb, sfsp, entry_sz); error = copyfn(sb, sfsp, entry_sz);
if (error) { if (error) {
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
goto out; goto out;
} }
sfsp = (char *)sfsp + entry_sz; sfsp = (char *)sfsp + entry_sz;
@ -1038,8 +1035,7 @@ do_sys_getvfsstat(struct lwp *l, void *sfsp, size_t bufsize, int flags,
} }
count++; count++;
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
nmp = CIRCLEQ_NEXT(mp, mnt_list); vfs_unbusy(mp, false, &nmp);
vfs_unbusy(mp, false);
} }
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
@ -1115,7 +1111,7 @@ sys_fchdir(struct lwp *l, const struct sys_fchdir_args *uap, register_t *retval)
continue; continue;
vput(vp); vput(vp);
error = VFS_ROOT(mp, &tdp); error = VFS_ROOT(mp, &tdp);
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
if (error) if (error)
goto out; goto out;
vp = tdp; vp = tdp;

View File

@ -1,4 +1,4 @@
/* $NetBSD: procfs_linux.c,v 1.51 2008/04/29 23:51:05 ad Exp $ */ /* $NetBSD: procfs_linux.c,v 1.52 2008/04/30 12:49:17 ad Exp $ */
/* /*
* Copyright (c) 2001 Wasabi Systems, Inc. * Copyright (c) 2001 Wasabi Systems, Inc.
@ -36,7 +36,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: procfs_linux.c,v 1.51 2008/04/29 23:51:05 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: procfs_linux.c,v 1.52 2008/04/30 12:49:17 ad Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
@ -589,8 +589,7 @@ procfs_domounts(struct lwp *curl, struct proc *p,
mtabsz += len; mtabsz += len;
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
nmp = CIRCLEQ_NEXT(mp, mnt_list); vfs_unbusy(mp, false, &nmp);
vfs_unbusy(mp, false);
} }
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
free(bf, M_TEMP); free(bf, M_TEMP);

View File

@ -1,4 +1,4 @@
/* $NetBSD: sync_vnops.c,v 1.23 2008/04/29 23:51:05 ad Exp $ */ /* $NetBSD: sync_vnops.c,v 1.24 2008/04/30 12:49:17 ad Exp $ */
/* /*
* Copyright 1997 Marshall Kirk McKusick. All Rights Reserved. * Copyright 1997 Marshall Kirk McKusick. All Rights Reserved.
@ -32,7 +32,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: sync_vnops.c,v 1.23 2008/04/29 23:51:05 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: sync_vnops.c,v 1.24 2008/04/30 12:49:17 ad Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/proc.h> #include <sys/proc.h>
@ -163,7 +163,7 @@ sync_fsync(v)
VFS_SYNC(mp, MNT_LAZY, ap->a_cred); VFS_SYNC(mp, MNT_LAZY, ap->a_cred);
if (asyncflag) if (asyncflag)
mp->mnt_flag |= MNT_ASYNC; mp->mnt_flag |= MNT_ASYNC;
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
} }
return (0); return (0);
} }

View File

@ -1,7 +1,7 @@
/* $NetBSD: nfs_export.c,v 1.35 2008/04/29 23:51:05 ad Exp $ */ /* $NetBSD: nfs_export.c,v 1.36 2008/04/30 12:49:17 ad Exp $ */
/*- /*-
* Copyright (c) 1997, 1998, 2004, 2005 The NetBSD Foundation, Inc. * Copyright (c) 1997, 1998, 2004, 2005, 2008 The NetBSD Foundation, Inc.
* All rights reserved. * All rights reserved.
* *
* This code is derived from software contributed to The NetBSD Foundation * This code is derived from software contributed to The NetBSD Foundation
@ -75,7 +75,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: nfs_export.c,v 1.35 2008/04/29 23:51:05 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: nfs_export.c,v 1.36 2008/04/30 12:49:17 ad Exp $");
#include "opt_compat_netbsd.h" #include "opt_compat_netbsd.h"
#include "opt_inet.h" #include "opt_inet.h"
@ -287,7 +287,7 @@ mountd_set_exports_list(const struct mountd_exports_list *mel, struct lwp *l)
out: out:
netexport_wrunlock(); netexport_wrunlock();
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
return error; return error;
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: nfs_vfsops.c,v 1.197 2008/04/29 18:18:09 ad Exp $ */ /* $NetBSD: nfs_vfsops.c,v 1.198 2008/04/30 12:49:17 ad Exp $ */
/* /*
* Copyright (c) 1989, 1993, 1995 * Copyright (c) 1989, 1993, 1995
@ -35,7 +35,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.197 2008/04/29 18:18:09 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.198 2008/04/30 12:49:17 ad Exp $");
#if defined(_KERNEL_OPT) #if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h" #include "opt_compat_netbsd.h"
@ -360,10 +360,11 @@ nfs_mountroot()
*/ */
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list); CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
mp->mnt_iflag |= IMNT_ONLIST;
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
rootvp = vp; rootvp = vp;
mp->mnt_vnodecovered = NULLVP; mp->mnt_vnodecovered = NULLVP;
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
/* Get root attributes (for the time). */ /* Get root attributes (for the time). */
error = VOP_GETATTR(vp, &attr, l->l_cred); error = VOP_GETATTR(vp, &attr, l->l_cred);
@ -420,8 +421,8 @@ nfs_mount_diskless(ndmntp, mntname, mpp, vpp, l)
error = mountnfs(&ndmntp->ndm_args, mp, m, mntname, error = mountnfs(&ndmntp->ndm_args, mp, m, mntname,
ndmntp->ndm_args.hostname, vpp, l); ndmntp->ndm_args.hostname, vpp, l);
if (error) { if (error) {
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
vfs_destroy(mp); vfs_destroy(mp, false);
printf("nfs_mountroot: mount %s failed: %d\n", printf("nfs_mountroot: mount %s failed: %d\n",
mntname, error); mntname, error);
} else } else

View File

@ -1,4 +1,4 @@
/* $NetBSD: fstypes.h,v 1.21 2007/10/10 20:42:32 ad Exp $ */ /* $NetBSD: fstypes.h,v 1.22 2008/04/30 12:49:17 ad Exp $ */
/* /*
* Copyright (c) 1989, 1991, 1993 * Copyright (c) 1989, 1991, 1993
@ -208,6 +208,7 @@ typedef struct fhandle fhandle_t;
#define IMNT_DTYPE 0x00000040 /* returns d_type fields */ #define IMNT_DTYPE 0x00000040 /* returns d_type fields */
#define IMNT_HAS_TRANS 0x00000080 /* supports transactions */ #define IMNT_HAS_TRANS 0x00000080 /* supports transactions */
#define IMNT_MPSAFE 0x00000100 /* file system code MP safe */ #define IMNT_MPSAFE 0x00000100 /* file system code MP safe */
#define IMNT_ONLIST 0x00000200 /* queued on 'mountlist' */
#define __MNT_FLAGS \ #define __MNT_FLAGS \
__MNT_BASIC_FLAGS \ __MNT_BASIC_FLAGS \
@ -252,6 +253,7 @@ typedef struct fhandle fhandle_t;
#define __IMNT_FLAG_BITS \ #define __IMNT_FLAG_BITS \
"\20" \ "\20" \
"\30IMNT_ONLIST" \
"\20IMNT_MPSAFE" \ "\20IMNT_MPSAFE" \
"\10IMNT_HAS_TRANS" \ "\10IMNT_HAS_TRANS" \
"\07IMNT_DTYPE" \ "\07IMNT_DTYPE" \

View File

@ -1,4 +1,4 @@
/* $NetBSD: mount.h,v 1.175 2008/04/29 23:51:05 ad Exp $ */ /* $NetBSD: mount.h,v 1.176 2008/04/30 12:49:17 ad Exp $ */
/* /*
* Copyright (c) 1989, 1991, 1993 * Copyright (c) 1989, 1991, 1993
@ -337,13 +337,13 @@ void vfs_unmountall(struct lwp *); /* unmount file systems */
int vfs_busy(struct mount *, const krw_t); int vfs_busy(struct mount *, const krw_t);
int vfs_trybusy(struct mount *, const krw_t, struct mount **); int vfs_trybusy(struct mount *, const krw_t, struct mount **);
int vfs_rootmountalloc(const char *, const char *, struct mount **); int vfs_rootmountalloc(const char *, const char *, struct mount **);
void vfs_unbusy(struct mount *, bool); void vfs_unbusy(struct mount *, bool, struct mount **);
int vfs_attach(struct vfsops *); int vfs_attach(struct vfsops *);
int vfs_detach(struct vfsops *); int vfs_detach(struct vfsops *);
void vfs_reinit(void); void vfs_reinit(void);
struct vfsops *vfs_getopsbyname(const char *); struct vfsops *vfs_getopsbyname(const char *);
void vfs_delref(struct vfsops *); void vfs_delref(struct vfsops *);
void vfs_destroy(struct mount *); void vfs_destroy(struct mount *, bool);
void vfs_scrubvnlist(struct mount *); void vfs_scrubvnlist(struct mount *);
int vfs_stdextattrctl(struct mount *, int, struct vnode *, int vfs_stdextattrctl(struct mount *, int, struct vnode *,

View File

@ -1,4 +1,4 @@
/* $NetBSD: ext2fs_vfsops.c,v 1.132 2008/04/29 18:18:09 ad Exp $ */ /* $NetBSD: ext2fs_vfsops.c,v 1.133 2008/04/30 12:49:17 ad Exp $ */
/* /*
* Copyright (c) 1989, 1991, 1993, 1994 * Copyright (c) 1989, 1991, 1993, 1994
@ -65,7 +65,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.132 2008/04/29 18:18:09 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.133 2008/04/30 12:49:17 ad Exp $");
#if defined(_KERNEL_OPT) #if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h" #include "opt_compat_netbsd.h"
@ -223,12 +223,13 @@ ext2fs_mountroot(void)
} }
if ((error = ext2fs_mountfs(rootvp, mp)) != 0) { if ((error = ext2fs_mountfs(rootvp, mp)) != 0) {
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
vfs_destroy(mp); vfs_destroy(mp, false);
return (error); return (error);
} }
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list); CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
mp->mnt_iflag |= IMNT_ONLIST;
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
ump = VFSTOUFS(mp); ump = VFSTOUFS(mp);
fs = ump->um_e2fs; fs = ump->um_e2fs;
@ -241,7 +242,7 @@ ext2fs_mountroot(void)
sizeof(fs->e2fs.e2fs_fsmnt) - 1, 0); sizeof(fs->e2fs.e2fs_fsmnt) - 1, 0);
} }
(void)ext2fs_statvfs(mp, &mp->mnt_stat); (void)ext2fs_statvfs(mp, &mp->mnt_stat);
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
setrootfstime((time_t)fs->e2fs.e2fs_wtime); setrootfstime((time_t)fs->e2fs.e2fs_wtime);
return (0); return (0);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: ffs_vfsops.c,v 1.224 2008/04/29 18:18:09 ad Exp $ */ /* $NetBSD: ffs_vfsops.c,v 1.225 2008/04/30 12:49:17 ad Exp $ */
/* /*
* Copyright (c) 1989, 1991, 1993, 1994 * Copyright (c) 1989, 1991, 1993, 1994
@ -32,7 +32,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.224 2008/04/29 18:18:09 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.225 2008/04/30 12:49:17 ad Exp $");
#if defined(_KERNEL_OPT) #if defined(_KERNEL_OPT)
#include "opt_ffs.h" #include "opt_ffs.h"
@ -165,19 +165,20 @@ ffs_mountroot(void)
return (error); return (error);
} }
if ((error = ffs_mountfs(rootvp, mp, l)) != 0) { if ((error = ffs_mountfs(rootvp, mp, l)) != 0) {
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
vfs_destroy(mp); vfs_destroy(mp, false);
return (error); return (error);
} }
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list); CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
mp->mnt_iflag |= IMNT_ONLIST;
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
ump = VFSTOUFS(mp); ump = VFSTOUFS(mp);
fs = ump->um_fs; fs = ump->um_fs;
memset(fs->fs_fsmnt, 0, sizeof(fs->fs_fsmnt)); memset(fs->fs_fsmnt, 0, sizeof(fs->fs_fsmnt));
(void)copystr(mp->mnt_stat.f_mntonname, fs->fs_fsmnt, MNAMELEN - 1, 0); (void)copystr(mp->mnt_stat.f_mntonname, fs->fs_fsmnt, MNAMELEN - 1, 0);
(void)ffs_statvfs(mp, &mp->mnt_stat); (void)ffs_statvfs(mp, &mp->mnt_stat);
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
setrootfstime((time_t)fs->fs_time); setrootfstime((time_t)fs->fs_time);
return (0); return (0);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_bio.c,v 1.112 2008/04/29 23:51:05 ad Exp $ */ /* $NetBSD: lfs_bio.c,v 1.113 2008/04/30 12:49:17 ad Exp $ */
/*- /*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc. * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc.
@ -60,7 +60,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.112 2008/04/29 23:51:05 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.113 2008/04/30 12:49:17 ad Exp $");
#include <sys/param.h> #include <sys/param.h>
#include <sys/systm.h> #include <sys/systm.h>
@ -581,7 +581,7 @@ lfs_flush(struct lfs *fs, int flags, int only_onefs)
mutex_enter(&lfs_lock); mutex_enter(&lfs_lock);
lfs_flush_fs(fs, flags); lfs_flush_fs(fs, flags);
mutex_exit(&lfs_lock); mutex_exit(&lfs_lock);
vfs_unbusy(fs->lfs_ivnode->v_mount, false); vfs_unbusy(fs->lfs_ivnode->v_mount, false, NULL);
} else { } else {
locked_fakequeue_count = 0; locked_fakequeue_count = 0;
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
@ -599,8 +599,7 @@ lfs_flush(struct lfs *fs, int flags, int only_onefs)
mutex_exit(&lfs_lock); mutex_exit(&lfs_lock);
} }
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
nmp = CIRCLEQ_NEXT(mp, mnt_list); vfs_unbusy(mp, false, &nmp);
vfs_unbusy(mp, false);
} }
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_syscalls.c,v 1.130 2008/04/28 20:24:11 martin Exp $ */ /* $NetBSD: lfs_syscalls.c,v 1.131 2008/04/30 12:49:17 ad Exp $ */
/*- /*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007, 2008 * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007, 2008
@ -61,7 +61,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_syscalls.c,v 1.130 2008/04/28 20:24:11 martin Exp $"); __KERNEL_RCSID(0, "$NetBSD: lfs_syscalls.c,v 1.131 2008/04/30 12:49:17 ad Exp $");
#ifndef LFS #ifndef LFS
# define LFS /* for prototypes in syscallargs.h */ # define LFS /* for prototypes in syscallargs.h */
@ -503,7 +503,7 @@ lfs_markv(struct proc *p, fsid_t *fsidp, BLOCK_INFO *blkiov,
lfs_segunlock(fs); lfs_segunlock(fs);
vfs_unbusy(mntp, false); vfs_unbusy(mntp, false, NULL);
if (error) if (error)
return (error); return (error);
else if (do_again) else if (do_again)
@ -532,7 +532,7 @@ err3:
} }
lfs_segunlock(fs); lfs_segunlock(fs);
vfs_unbusy(mntp, false); vfs_unbusy(mntp, false, NULL);
#ifdef DIAGNOSTIC #ifdef DIAGNOSTIC
if (numrefed != 0) if (numrefed != 0)
panic("lfs_markv: numrefed=%d", numrefed); panic("lfs_markv: numrefed=%d", numrefed);
@ -822,7 +822,7 @@ lfs_bmapv(struct proc *p, fsid_t *fsidp, BLOCK_INFO *blkiov, int blkcnt)
panic("lfs_bmapv: numrefed=%d", numrefed); panic("lfs_bmapv: numrefed=%d", numrefed);
#endif #endif
vfs_unbusy(mntp, false); vfs_unbusy(mntp, false, NULL);
return 0; return 0;
} }
@ -868,7 +868,7 @@ sys_lfs_segclean(struct lwp *l, const struct sys_lfs_segclean_args *uap, registe
error = lfs_do_segclean(fs, segnum); error = lfs_do_segclean(fs, segnum);
lfs_segunlock(fs); lfs_segunlock(fs);
KERNEL_UNLOCK_ONE(NULL); KERNEL_UNLOCK_ONE(NULL);
vfs_unbusy(mntp, false); vfs_unbusy(mntp, false, NULL);
return error; return error;
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: lfs_vfsops.c,v 1.258 2008/04/29 23:51:05 ad Exp $ */ /* $NetBSD: lfs_vfsops.c,v 1.259 2008/04/30 12:49:17 ad Exp $ */
/*- /*-
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007 * Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
@ -61,7 +61,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.258 2008/04/29 23:51:05 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.259 2008/04/30 12:49:17 ad Exp $");
#if defined(_KERNEL_OPT) #if defined(_KERNEL_OPT)
#include "opt_lfs.h" #include "opt_lfs.h"
@ -241,8 +241,7 @@ lfs_writerd(void *arg)
} }
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
nmp = CIRCLEQ_NEXT(mp, mnt_list); vfs_unbusy(mp, false, &nmp);
vfs_unbusy(mp, false);
} }
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
@ -345,15 +344,16 @@ lfs_mountroot()
return (error); return (error);
} }
if ((error = lfs_mountfs(rootvp, mp, l))) { if ((error = lfs_mountfs(rootvp, mp, l))) {
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
vfs_destroy(mp); vfs_destroy(mp, false);
return (error); return (error);
} }
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list); CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
mp->mnt_iflag |= IMNT_ONLIST;
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
(void)lfs_statvfs(mp, &mp->mnt_stat); (void)lfs_statvfs(mp, &mp->mnt_stat);
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
setrootfstime((time_t)(VFSTOUFS(mp)->um_lfs->lfs_tstamp)); setrootfstime((time_t)(VFSTOUFS(mp)->um_lfs->lfs_tstamp));
return (0); return (0);
} }

View File

@ -1,4 +1,4 @@
/* $NetBSD: mfs_vfsops.c,v 1.94 2008/04/29 23:51:05 ad Exp $ */ /* $NetBSD: mfs_vfsops.c,v 1.95 2008/04/30 12:49:17 ad Exp $ */
/* /*
* Copyright (c) 1989, 1990, 1993, 1994 * Copyright (c) 1989, 1990, 1993, 1994
@ -32,7 +32,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: mfs_vfsops.c,v 1.94 2008/04/29 23:51:05 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: mfs_vfsops.c,v 1.95 2008/04/30 12:49:17 ad Exp $");
#if defined(_KERNEL_OPT) #if defined(_KERNEL_OPT)
#include "opt_compat_netbsd.h" #include "opt_compat_netbsd.h"
@ -199,21 +199,22 @@ mfs_mountroot(void)
mfsp->mfs_refcnt = 1; mfsp->mfs_refcnt = 1;
bufq_alloc(&mfsp->mfs_buflist, "fcfs", 0); bufq_alloc(&mfsp->mfs_buflist, "fcfs", 0);
if ((error = ffs_mountfs(rootvp, mp, l)) != 0) { if ((error = ffs_mountfs(rootvp, mp, l)) != 0) {
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
bufq_free(mfsp->mfs_buflist); bufq_free(mfsp->mfs_buflist);
vfs_destroy(mp); vfs_destroy(mp, false);
kmem_free(mfsp, sizeof(*mfsp)); kmem_free(mfsp, sizeof(*mfsp));
return (error); return (error);
} }
mutex_enter(&mountlist_lock); mutex_enter(&mountlist_lock);
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list); CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
mp->mnt_iflag |= IMNT_ONLIST;
mutex_exit(&mountlist_lock); mutex_exit(&mountlist_lock);
mp->mnt_vnodecovered = NULLVP; mp->mnt_vnodecovered = NULLVP;
ump = VFSTOUFS(mp); ump = VFSTOUFS(mp);
fs = ump->um_fs; fs = ump->um_fs;
(void) copystr(mp->mnt_stat.f_mntonname, fs->fs_fsmnt, MNAMELEN - 1, 0); (void) copystr(mp->mnt_stat.f_mntonname, fs->fs_fsmnt, MNAMELEN - 1, 0);
(void)ffs_statvfs(mp, &mp->mnt_stat); (void)ffs_statvfs(mp, &mp->mnt_stat);
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
return (0); return (0);
} }
@ -380,7 +381,7 @@ mfs_start(struct mount *mp, int flags)
mutex_enter(&mfs_lock); mutex_enter(&mfs_lock);
mfsp->mfs_refcnt++; mfsp->mfs_refcnt++;
mutex_exit(&mfs_lock); mutex_exit(&mfs_lock);
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
base = mfsp->mfs_baseoff; base = mfsp->mfs_baseoff;
mutex_enter(&mfs_lock); mutex_enter(&mfs_lock);

View File

@ -1,4 +1,4 @@
/* $NetBSD: ufs_vfsops.c,v 1.37 2008/01/30 11:47:05 ad Exp $ */ /* $NetBSD: ufs_vfsops.c,v 1.38 2008/04/30 12:49:17 ad Exp $ */
/* /*
* Copyright (c) 1991, 1993, 1994 * Copyright (c) 1991, 1993, 1994
@ -37,7 +37,7 @@
*/ */
#include <sys/cdefs.h> #include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: ufs_vfsops.c,v 1.37 2008/01/30 11:47:05 ad Exp $"); __KERNEL_RCSID(0, "$NetBSD: ufs_vfsops.c,v 1.38 2008/04/30 12:49:17 ad Exp $");
#if defined(_KERNEL_OPT) #if defined(_KERNEL_OPT)
#include "opt_ffs.h" #include "opt_ffs.h"
@ -166,7 +166,7 @@ ufs_quotactl(struct mount *mp, int cmds, uid_t uid, void *arg)
default: default:
error = EINVAL; error = EINVAL;
} }
vfs_unbusy(mp, false); vfs_unbusy(mp, false, NULL);
return (error); return (error);
#endif #endif
} }