PR kern/37706 (forced unmount of file systems is unsafe):
- Do reference counting for 'struct mount'. Each vnode associated with a mount takes a reference, and in turn the mount takes a reference to the vfsops. - Now that mounts are reference counted, replace the overcomplicated mount locking inherited from 4.4BSD with a recursable rwlock.
This commit is contained in:
parent
508b2997d7
commit
25153c3ec9
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: coda_psdev.c,v 1.37 2007/12/05 17:19:46 pooka Exp $ */
|
||||
/* $NetBSD: coda_psdev.c,v 1.38 2008/01/30 11:46:59 ad Exp $ */
|
||||
|
||||
/*
|
||||
*
|
||||
|
@ -54,7 +54,7 @@
|
|||
/* These routines are the device entry points for Venus. */
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: coda_psdev.c,v 1.37 2007/12/05 17:19:46 pooka Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: coda_psdev.c,v 1.38 2008/01/30 11:46:59 ad Exp $");
|
||||
|
||||
extern int coda_nc_initialized; /* Set if cache has been initialized */
|
||||
|
||||
|
@ -202,7 +202,7 @@ vc_nb_close(dev_t dev, int flag, int mode, struct lwp *l)
|
|||
*/
|
||||
mutex_enter(&syncer_mutex);
|
||||
VTOC(mi->mi_rootvp)->c_flags |= C_UNMOUNTING;
|
||||
if (vfs_busy(mi->mi_vfsp, 0, 0)) {
|
||||
if (vfs_busy(mi->mi_vfsp, RW_WRITER, NULL)) {
|
||||
mutex_exit(&syncer_mutex);
|
||||
return (EBUSY);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: vfs_syscalls_20.c,v 1.24 2008/01/07 16:08:46 ad Exp $ */
|
||||
/* $NetBSD: vfs_syscalls_20.c,v 1.25 2008/01/30 11:46:59 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_20.c,v 1.24 2008/01/07 16:08:46 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls_20.c,v 1.25 2008/01/30 11:46:59 ad Exp $");
|
||||
|
||||
#include "opt_compat_netbsd.h"
|
||||
#include "opt_compat_43.h"
|
||||
|
@ -223,7 +223,7 @@ compat_20_sys_getfsstat(struct lwp *l, const struct compat_20_sys_getfsstat_args
|
|||
count = 0;
|
||||
for (mp = CIRCLEQ_FIRST(&mountlist); mp != (void *)&mountlist;
|
||||
mp = nmp) {
|
||||
if (vfs_busy(mp, LK_NOWAIT, &mountlist_lock)) {
|
||||
if (vfs_trybusy(mp, RW_READER, &mountlist_lock)) {
|
||||
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
||||
continue;
|
||||
}
|
||||
|
@ -232,12 +232,12 @@ compat_20_sys_getfsstat(struct lwp *l, const struct compat_20_sys_getfsstat_args
|
|||
if (error) {
|
||||
mutex_enter(&mountlist_lock);
|
||||
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
continue;
|
||||
}
|
||||
error = vfs2fs(sfsp, sbuf);
|
||||
if (error) {
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
goto out;
|
||||
}
|
||||
sfsp++;
|
||||
|
@ -246,7 +246,7 @@ compat_20_sys_getfsstat(struct lwp *l, const struct compat_20_sys_getfsstat_args
|
|||
count++;
|
||||
mutex_enter(&mountlist_lock);
|
||||
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
}
|
||||
mutex_exit(&mountlist_lock);
|
||||
if (root == 0 && l->l_proc->p_cwdi->cwdi_rdir) {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: netbsd32_compat_20.c,v 1.19 2007/12/20 23:03:01 dsl Exp $ */
|
||||
/* $NetBSD: netbsd32_compat_20.c,v 1.20 2008/01/30 11:46:59 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1998, 2001 Matthew R. Green
|
||||
|
@ -29,7 +29,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_20.c,v 1.19 2007/12/20 23:03:01 dsl Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: netbsd32_compat_20.c,v 1.20 2008/01/30 11:46:59 ad Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -106,7 +106,7 @@ compat_20_netbsd32_getfsstat(struct lwp *l, const struct compat_20_netbsd32_getf
|
|||
mutex_enter(&mountlist_lock);
|
||||
count = 0;
|
||||
for (mp = mountlist.cqh_first; mp != (void *)&mountlist; mp = nmp) {
|
||||
if (vfs_busy(mp, LK_NOWAIT, &mountlist_lock)) {
|
||||
if (vfs_trybusy(mp, RW_READER, &mountlist_lock)) {
|
||||
nmp = mp->mnt_list.cqe_next;
|
||||
continue;
|
||||
}
|
||||
|
@ -124,14 +124,14 @@ compat_20_netbsd32_getfsstat(struct lwp *l, const struct compat_20_netbsd32_getf
|
|||
(error = VFS_STATVFS(mp, sp)) != 0) {
|
||||
mutex_enter(&mountlist_lock);
|
||||
nmp = mp->mnt_list.cqe_next;
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
continue;
|
||||
}
|
||||
sp->f_flag = mp->mnt_flag & MNT_VISFLAGMASK;
|
||||
compat_20_netbsd32_from_statvfs(sp, &sb32);
|
||||
error = copyout(&sb32, sfsp, sizeof(sb32));
|
||||
if (error) {
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
return (error);
|
||||
}
|
||||
sfsp = (char *)sfsp + sizeof(sb32);
|
||||
|
@ -139,7 +139,7 @@ compat_20_netbsd32_getfsstat(struct lwp *l, const struct compat_20_netbsd32_getf
|
|||
count++;
|
||||
mutex_enter(&mountlist_lock);
|
||||
nmp = mp->mnt_list.cqe_next;
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
}
|
||||
mutex_exit(&mountlist_lock);
|
||||
if (sfsp && count > maxcount)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ultrix_fs.c,v 1.45 2007/12/27 17:18:11 christos Exp $ */
|
||||
/* $NetBSD: ultrix_fs.c,v 1.46 2008/01/30 11:46:59 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1995, 1997 Jonathan Stone
|
||||
|
@ -33,7 +33,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ultrix_fs.c,v 1.45 2007/12/27 17:18:11 christos Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ultrix_fs.c,v 1.46 2008/01/30 11:46:59 ad Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -257,7 +257,7 @@ ultrix_sys_getmnt(struct lwp *l, const struct ultrix_sys_getmnt_args *uap, regis
|
|||
mutex_enter(&mountlist_lock);
|
||||
for (count = 0, mp = mountlist.cqh_first;
|
||||
mp != (void*)&mountlist && count < maxcount; mp = nmp) {
|
||||
if (vfs_busy(mp, LK_NOWAIT, &mountlist_lock)) {
|
||||
if (vfs_trybusy(mp, RW_READER, &mountlist_lock)) {
|
||||
nmp = mp->mnt_list.cqe_next;
|
||||
continue;
|
||||
}
|
||||
|
@ -280,15 +280,17 @@ ultrix_sys_getmnt(struct lwp *l, const struct ultrix_sys_getmnt_args *uap, regis
|
|||
strcmp(path, sp->f_mntonname) == 0) {
|
||||
make_ultrix_mntent(sp, &tem);
|
||||
if ((error = copyout((void *)&tem, sfsp,
|
||||
sizeof(tem))) != 0)
|
||||
sizeof(tem))) != 0) {
|
||||
vfs_unbusy(mp, false);
|
||||
goto bad;
|
||||
}
|
||||
sfsp++;
|
||||
count++;
|
||||
}
|
||||
}
|
||||
mutex_enter(&mountlist_lock);
|
||||
nmp = mp->mnt_list.cqe_next;
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
}
|
||||
mutex_exit(&mountlist_lock);
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: cd9660_vfsops.c,v 1.55 2008/01/28 14:31:16 dholland Exp $ */
|
||||
/* $NetBSD: cd9660_vfsops.c,v 1.56 2008/01/30 11:46:59 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1994
|
||||
|
@ -37,7 +37,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.55 2008/01/28 14:31:16 dholland Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: cd9660_vfsops.c,v 1.56 2008/01/30 11:46:59 ad Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_compat_netbsd.h"
|
||||
|
@ -148,8 +148,7 @@ cd9660_mountroot()
|
|||
|
||||
args.flags = ISOFSMNT_ROOT;
|
||||
if ((error = iso_mountfs(rootvp, mp, l, &args)) != 0) {
|
||||
mp->mnt_op->vfs_refcount--;
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
vfs_destroy(mp);
|
||||
return (error);
|
||||
}
|
||||
|
@ -157,7 +156,7 @@ cd9660_mountroot()
|
|||
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
|
||||
mutex_exit(&mountlist_lock);
|
||||
(void)cd9660_statvfs(mp, &mp->mnt_stat);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: filecore_vfsops.c,v 1.47 2008/01/28 14:31:16 dholland Exp $ */
|
||||
/* $NetBSD: filecore_vfsops.c,v 1.48 2008/01/30 11:46:59 ad 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.47 2008/01/28 14:31:16 dholland Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: filecore_vfsops.c,v 1.48 2008/01/30 11:46:59 ad Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_compat_netbsd.h"
|
||||
|
@ -172,8 +172,7 @@ filecore_mountroot()
|
|||
|
||||
args.flags = FILECOREMNT_ROOT;
|
||||
if ((error = filecore_mountfs(rootvp, mp, p, &args)) != 0) {
|
||||
mp->mnt_op->vfs_refcount--;
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
vfs_destroy(mp);
|
||||
return (error);
|
||||
}
|
||||
|
@ -181,7 +180,7 @@ filecore_mountroot()
|
|||
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
|
||||
simple_unlock(&mountlist_slock);
|
||||
(void)filecore_statvfs(mp, &mp->mnt_stat, p);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
return (0);
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: msdosfs_vfsops.c,v 1.60 2008/01/28 14:31:16 dholland Exp $ */
|
||||
/* $NetBSD: msdosfs_vfsops.c,v 1.61 2008/01/30 11:47:00 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.60 2008/01/28 14:31:16 dholland Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: msdosfs_vfsops.c,v 1.61 2008/01/30 11:47:00 ad Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_quota.h"
|
||||
|
@ -212,15 +212,14 @@ msdosfs_mountroot()
|
|||
args.dirmask = 0777;
|
||||
|
||||
if ((error = msdosfs_mountfs(rootvp, mp, l, &args)) != 0) {
|
||||
mp->mnt_op->vfs_refcount--;
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
vfs_destroy(mp);
|
||||
return (error);
|
||||
}
|
||||
|
||||
if ((error = update_mp(mp, &args)) != 0) {
|
||||
(void)msdosfs_unmount(mp, 0);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
vfs_destroy(mp);
|
||||
vrele(rootvp);
|
||||
return (error);
|
||||
|
@ -230,7 +229,7 @@ msdosfs_mountroot()
|
|||
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
|
||||
mutex_exit(&mountlist_lock);
|
||||
(void)msdosfs_statvfs(mp, &mp->mnt_stat);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ntfs_vfsops.c,v 1.64 2008/01/29 18:22:24 pooka Exp $ */
|
||||
/* $NetBSD: ntfs_vfsops.c,v 1.65 2008/01/30 11:47:00 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.64 2008/01/29 18:22:24 pooka Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ntfs_vfsops.c,v 1.65 2008/01/30 11:47:00 ad Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -129,8 +129,7 @@ ntfs_mountroot()
|
|||
args.mode = 0777;
|
||||
|
||||
if ((error = ntfs_mountfs(rootvp, mp, &args, l)) != 0) {
|
||||
mp->mnt_op->vfs_refcount--;
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
vfs_destroy(mp);
|
||||
return (error);
|
||||
}
|
||||
|
@ -139,7 +138,7 @@ ntfs_mountroot()
|
|||
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
|
||||
mutex_exit(&mountlist_lock);
|
||||
(void)ntfs_statvfs(mp, &mp->mnt_stat);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: puffs_msgif.c,v 1.64 2008/01/28 21:06:36 pooka Exp $ */
|
||||
/* $NetBSD: puffs_msgif.c,v 1.65 2008/01/30 11:47:00 ad 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.64 2008/01/28 21:06:36 pooka Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: puffs_msgif.c,v 1.65 2008/01/30 11:47:00 ad Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/fstrans.h>
|
||||
|
@ -1061,7 +1061,7 @@ puffs_msgif_close(void *this)
|
|||
* is already a goner.
|
||||
* XXX: skating on the thin ice of modern calling conventions ...
|
||||
*/
|
||||
if (vfs_busy(mp, 0, 0)) {
|
||||
if (vfs_busy(mp, RW_WRITER, NULL)) {
|
||||
mutex_exit(&syncer_mutex);
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: union_vnops.c,v 1.27 2008/01/25 14:32:14 ad Exp $ */
|
||||
/* $NetBSD: union_vnops.c,v 1.28 2008/01/30 11:47:00 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1992, 1993, 1994, 1995
|
||||
|
@ -72,7 +72,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.27 2008/01/25 14:32:14 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: union_vnops.c,v 1.28 2008/01/30 11:47:00 ad Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -253,13 +253,11 @@ union_lookup1(udvp, dvpp, vpp, cnp)
|
|||
*/
|
||||
while (dvp != udvp && (dvp->v_type == VDIR) &&
|
||||
(mp = dvp->v_mountedhere)) {
|
||||
|
||||
if (vfs_busy(mp, 0, 0))
|
||||
if (vfs_busy(mp, RW_READER, 0))
|
||||
continue;
|
||||
|
||||
vput(dvp);
|
||||
error = VFS_ROOT(mp, &tdvp);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
if (error) {
|
||||
return (error);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: vfs_lookup.c,v 1.103 2007/12/31 15:32:13 ad Exp $ */
|
||||
/* $NetBSD: vfs_lookup.c,v 1.104 2008/01/30 11:47:00 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1982, 1986, 1989, 1993
|
||||
|
@ -37,7 +37,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.103 2007/12/31 15:32:13 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: vfs_lookup.c,v 1.104 2008/01/30 11:47:00 ad Exp $");
|
||||
|
||||
#include "opt_magiclinks.h"
|
||||
|
||||
|
@ -776,14 +776,14 @@ unionlookup:
|
|||
*/
|
||||
while (dp->v_type == VDIR && (mp = dp->v_mountedhere) &&
|
||||
(cnp->cn_flags & NOCROSSMOUNT) == 0) {
|
||||
if (vfs_busy(mp, 0, 0))
|
||||
if (vfs_busy(mp, RW_READER, 0))
|
||||
continue;
|
||||
|
||||
KASSERT(ndp->ni_dvp != dp);
|
||||
VOP_UNLOCK(ndp->ni_dvp, 0);
|
||||
vput(dp);
|
||||
error = VFS_ROOT(mp, &tdp);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
if (error) {
|
||||
vn_lock(ndp->ni_dvp, LK_EXCLUSIVE | LK_RETRY);
|
||||
goto bad;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: vfs_subr.c,v 1.326 2008/01/30 09:50:22 ad Exp $ */
|
||||
/* $NetBSD: vfs_subr.c,v 1.327 2008/01/30 11:47:01 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc.
|
||||
|
@ -82,7 +82,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.326 2008/01/30 09:50:22 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: vfs_subr.c,v 1.327 2008/01/30 11:47:01 ad Exp $");
|
||||
|
||||
#include "opt_ddb.h"
|
||||
#include "opt_compat_netbsd.h"
|
||||
|
@ -290,60 +290,101 @@ try_nextlist:
|
|||
}
|
||||
|
||||
/*
|
||||
* Mark a mount point as busy. Used to synchronize access and to delay
|
||||
* unmounting. Interlock is not released on failure.
|
||||
* Mark a mount point as busy, and gain a new reference to it. Used to
|
||||
* synchronize access and to delay unmounting.
|
||||
*
|
||||
* => Interlock is not released on failure.
|
||||
* => If no interlock, the caller is expected to already hold a reference
|
||||
* on the mount.
|
||||
* => If interlocked, the interlock must prevent the last reference to
|
||||
* the mount from disappearing.
|
||||
*/
|
||||
int
|
||||
vfs_busy(struct mount *mp, int flags, kmutex_t *interlkp)
|
||||
vfs_busy(struct mount *mp, const krw_t op, kmutex_t *interlock)
|
||||
{
|
||||
int lkflags;
|
||||
|
||||
while (mp->mnt_iflag & IMNT_UNMOUNT) {
|
||||
int gone, n;
|
||||
KASSERT(mp->mnt_refcnt > 0);
|
||||
|
||||
if (flags & LK_NOWAIT)
|
||||
return (ENOENT);
|
||||
if ((flags & LK_RECURSEFAIL) && mp->mnt_unmounter != NULL
|
||||
&& mp->mnt_unmounter == curlwp)
|
||||
return (EDEADLK);
|
||||
if (interlkp)
|
||||
mutex_exit(interlkp);
|
||||
/*
|
||||
* Since all busy locks are shared except the exclusive
|
||||
* lock granted when unmounting, the only place that a
|
||||
* wakeup needs to be done is at the release of the
|
||||
* exclusive lock at the end of dounmount.
|
||||
*/
|
||||
mutex_enter(&mp->mnt_mutex);
|
||||
mp->mnt_wcnt++;
|
||||
mtsleep((void *)mp, PVFS, "vfs_busy", 0, &mp->mnt_mutex);
|
||||
n = --mp->mnt_wcnt;
|
||||
mutex_exit(&mp->mnt_mutex);
|
||||
gone = mp->mnt_iflag & IMNT_GONE;
|
||||
|
||||
if (n == 0)
|
||||
wakeup(&mp->mnt_wcnt);
|
||||
if (interlkp)
|
||||
mutex_enter(interlkp);
|
||||
if (gone)
|
||||
return (ENOENT);
|
||||
atomic_inc_uint(&mp->mnt_refcnt);
|
||||
if (interlock != NULL) {
|
||||
mutex_exit(interlock);
|
||||
}
|
||||
lkflags = LK_SHARED;
|
||||
if (interlkp)
|
||||
lkflags |= LK_INTERLOCK;
|
||||
if (lockmgr(&mp->mnt_lock, lkflags, interlkp))
|
||||
panic("vfs_busy: unexpected lock failure");
|
||||
return (0);
|
||||
if (mp->mnt_writer == curlwp) {
|
||||
mp->mnt_recursecnt++;
|
||||
} else {
|
||||
rw_enter(&mp->mnt_lock, op);
|
||||
if (op == RW_WRITER) {
|
||||
KASSERT(mp->mnt_writer == NULL);
|
||||
mp->mnt_writer = curlwp;
|
||||
}
|
||||
}
|
||||
if ((mp->mnt_iflag & IMNT_GONE) != 0) {
|
||||
vfs_unbusy(mp, false);
|
||||
if (interlock != NULL) {
|
||||
mutex_enter(interlock);
|
||||
}
|
||||
return ENOENT;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Free a busy filesystem.
|
||||
* As vfs_busy(), but return immediatley if the mount cannot be
|
||||
* locked without waiting.
|
||||
*/
|
||||
void
|
||||
vfs_unbusy(struct mount *mp)
|
||||
int
|
||||
vfs_trybusy(struct mount *mp, krw_t op, kmutex_t *interlock)
|
||||
{
|
||||
|
||||
lockmgr(&mp->mnt_lock, LK_RELEASE, NULL);
|
||||
KASSERT(mp->mnt_refcnt > 0);
|
||||
|
||||
if (mp->mnt_writer == curlwp) {
|
||||
mp->mnt_recursecnt++;
|
||||
} else {
|
||||
if (!rw_tryenter(&mp->mnt_lock, op)) {
|
||||
return EBUSY;
|
||||
}
|
||||
if (op == RW_WRITER) {
|
||||
KASSERT(mp->mnt_writer == NULL);
|
||||
mp->mnt_writer = curlwp;
|
||||
}
|
||||
}
|
||||
atomic_inc_uint(&mp->mnt_refcnt);
|
||||
if ((mp->mnt_iflag & IMNT_GONE) != 0) {
|
||||
vfs_unbusy(mp, false);
|
||||
return ENOENT;
|
||||
}
|
||||
if (interlock != NULL) {
|
||||
mutex_exit(interlock);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Unlock a busy filesystem and drop reference to it. If 'keepref' is
|
||||
* true, unlock but preserve the reference.
|
||||
*/
|
||||
void
|
||||
vfs_unbusy(struct mount *mp, bool keepref)
|
||||
{
|
||||
|
||||
KASSERT(mp->mnt_refcnt > 0);
|
||||
|
||||
if (mp->mnt_writer == curlwp) {
|
||||
KASSERT(rw_write_held(&mp->mnt_lock));
|
||||
if (mp->mnt_recursecnt != 0) {
|
||||
mp->mnt_recursecnt--;
|
||||
} else {
|
||||
mp->mnt_writer = NULL;
|
||||
rw_exit(&mp->mnt_lock);
|
||||
}
|
||||
} else {
|
||||
rw_exit(&mp->mnt_lock);
|
||||
}
|
||||
if (!keepref) {
|
||||
vfs_destroy(mp);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -371,11 +412,12 @@ vfs_rootmountalloc(const char *fstypename, const char *devname,
|
|||
vfsp->vfs_refcount++;
|
||||
mutex_exit(&vfs_list_lock);
|
||||
|
||||
mp = malloc((u_long)sizeof(struct mount), M_MOUNT, M_WAITOK);
|
||||
memset((char *)mp, 0, (u_long)sizeof(struct mount));
|
||||
lockinit(&mp->mnt_lock, PVFS, "vfslock", 0, 0);
|
||||
mutex_init(&mp->mnt_mutex, MUTEX_DEFAULT, IPL_NONE);
|
||||
(void)vfs_busy(mp, LK_NOWAIT, 0);
|
||||
mp = kmem_zalloc(sizeof(*mp), KM_SLEEP);
|
||||
if (mp == NULL)
|
||||
return ENOMEM;
|
||||
mp->mnt_refcnt = 1;
|
||||
rw_init(&mp->mnt_lock);
|
||||
(void)vfs_busy(mp, RW_WRITER, NULL);
|
||||
TAILQ_INIT(&mp->mnt_vnodelist);
|
||||
mp->mnt_op = vfsp;
|
||||
mp->mnt_flag = MNT_RDONLY;
|
||||
|
@ -411,18 +453,16 @@ getnewvnode(enum vtagtype tag, struct mount *mp, int (**vops)(void *),
|
|||
int error = 0, tryalloc;
|
||||
|
||||
try_again:
|
||||
if (mp) {
|
||||
if (mp != NULL) {
|
||||
/*
|
||||
* Mark filesystem busy while we're creating a vnode.
|
||||
* If unmount is in progress, this will wait; if the
|
||||
* unmount succeeds (only if umount -f), this will
|
||||
* return an error. If the unmount fails, we'll keep
|
||||
* going afterwards.
|
||||
* (This puts the per-mount vnode list logically under
|
||||
* the protection of the vfs_busy lock).
|
||||
* Mark filesystem busy while we're creating a
|
||||
* vnode. If unmount is in progress, this will
|
||||
* wait; if the unmount succeeds (only if umount
|
||||
* -f), this will return an error. If the
|
||||
* unmount fails, we'll keep going afterwards.
|
||||
*/
|
||||
error = vfs_busy(mp, LK_RECURSEFAIL, 0);
|
||||
if (error && error != EDEADLK)
|
||||
error = vfs_busy(mp, RW_READER, NULL);
|
||||
if (error)
|
||||
return error;
|
||||
}
|
||||
|
||||
|
@ -467,8 +507,9 @@ getnewvnode(enum vtagtype tag, struct mount *mp, int (**vops)(void *),
|
|||
if (vp == NULL) {
|
||||
vp = getcleanvnode();
|
||||
if (vp == NULL) {
|
||||
if (mp && error != EDEADLK)
|
||||
vfs_unbusy(mp);
|
||||
if (mp != NULL) {
|
||||
vfs_unbusy(mp, false);
|
||||
}
|
||||
if (tryalloc) {
|
||||
printf("WARNING: unable to allocate new "
|
||||
"vnode, retrying...\n");
|
||||
|
@ -511,8 +552,7 @@ getnewvnode(enum vtagtype tag, struct mount *mp, int (**vops)(void *),
|
|||
if (mp != NULL) {
|
||||
if ((mp->mnt_iflag & IMNT_MPSAFE) != 0)
|
||||
vp->v_vflag |= VV_MPSAFE;
|
||||
if (error != EDEADLK)
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, true);
|
||||
}
|
||||
|
||||
return (0);
|
||||
|
@ -622,6 +662,7 @@ vremfree(vnode_t *vp)
|
|||
static void
|
||||
insmntque(vnode_t *vp, struct mount *mp)
|
||||
{
|
||||
struct mount *omp;
|
||||
|
||||
#ifdef DIAGNOSTIC
|
||||
if ((mp != NULL) &&
|
||||
|
@ -636,14 +677,21 @@ insmntque(vnode_t *vp, struct mount *mp)
|
|||
/*
|
||||
* Delete from old mount point vnode list, if on one.
|
||||
*/
|
||||
if (vp->v_mount != NULL)
|
||||
if ((omp = vp->v_mount) != NULL)
|
||||
TAILQ_REMOVE(&vp->v_mount->mnt_vnodelist, vp, v_mntvnodes);
|
||||
/*
|
||||
* Insert into list of vnodes for the new mount point, if available.
|
||||
* Insert into list of vnodes for the new mount point, if
|
||||
* available. The caller must take a reference on the mount
|
||||
* structure and donate to the vnode.
|
||||
*/
|
||||
if ((vp->v_mount = mp) != NULL)
|
||||
TAILQ_INSERT_TAIL(&mp->mnt_vnodelist, vp, v_mntvnodes);
|
||||
mutex_exit(&mntvnode_lock);
|
||||
|
||||
if (omp != NULL) {
|
||||
/* Release reference to old mount. */
|
||||
vfs_destroy(omp);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -1571,7 +1619,7 @@ sysctl_kern_vnode(SYSCTLFN_ARGS)
|
|||
mutex_enter(&mountlist_lock);
|
||||
for (mp = CIRCLEQ_FIRST(&mountlist); mp != (void *)&mountlist;
|
||||
mp = nmp) {
|
||||
if (vfs_busy(mp, LK_NOWAIT, &mountlist_lock)) {
|
||||
if (vfs_trybusy(mp, RW_READER, &mountlist_lock)) {
|
||||
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
||||
continue;
|
||||
}
|
||||
|
@ -1616,7 +1664,7 @@ sysctl_kern_vnode(SYSCTLFN_ARGS)
|
|||
mutex_exit(&mntvnode_lock);
|
||||
mutex_enter(&mountlist_lock);
|
||||
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
vnfree(mvp);
|
||||
}
|
||||
mutex_exit(&mountlist_lock);
|
||||
|
@ -1634,6 +1682,7 @@ vfs_scrubvnlist(struct mount *mp)
|
|||
{
|
||||
vnode_t *vp, *nvp;
|
||||
|
||||
retry:
|
||||
mutex_enter(&mntvnode_lock);
|
||||
for (vp = TAILQ_FIRST(&mp->mnt_vnodelist); vp; vp = nvp) {
|
||||
nvp = TAILQ_NEXT(vp, v_mntvnodes);
|
||||
|
@ -1641,6 +1690,10 @@ vfs_scrubvnlist(struct mount *mp)
|
|||
if ((vp->v_iflag & VI_CLEAN) != 0) {
|
||||
TAILQ_REMOVE(&mp->mnt_vnodelist, vp, v_mntvnodes);
|
||||
vp->v_mount = NULL;
|
||||
mutex_exit(&mntvnode_lock);
|
||||
mutex_exit(&vp->v_interlock);
|
||||
vfs_destroy(mp);
|
||||
goto retry;
|
||||
}
|
||||
mutex_exit(&vp->v_interlock);
|
||||
}
|
||||
|
@ -1699,7 +1752,7 @@ vfs_unmountall(struct lwp *l)
|
|||
* mount point. See dounmount() for details.
|
||||
*/
|
||||
mutex_enter(&syncer_mutex);
|
||||
if (vfs_busy(mp, 0, 0)) {
|
||||
if (vfs_busy(mp, RW_WRITER, NULL)) {
|
||||
mutex_exit(&syncer_mutex);
|
||||
continue;
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: vfs_subr2.c,v 1.15 2008/01/30 09:50:22 ad Exp $ */
|
||||
/* $NetBSD: vfs_subr2.c,v 1.16 2008/01/30 11:47:01 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998, 2004, 2005, 2007, 2008 The NetBSD Foundation, Inc.
|
||||
|
@ -82,7 +82,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: vfs_subr2.c,v 1.15 2008/01/30 09:50:22 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: vfs_subr2.c,v 1.16 2008/01/30 11:47:01 ad Exp $");
|
||||
|
||||
#include "opt_ddb.h"
|
||||
|
||||
|
@ -191,17 +191,22 @@ vfs_getvfs(fsid_t *fsid)
|
|||
}
|
||||
|
||||
/*
|
||||
* Free a mount structure.
|
||||
* Drop a reference to a mount structure, freeing if the last reference.
|
||||
*/
|
||||
void
|
||||
vfs_destroy(struct mount *mp)
|
||||
{
|
||||
|
||||
if (atomic_dec_uint_nv(&mp->mnt_refcnt) > 0) {
|
||||
return;
|
||||
}
|
||||
specificdata_fini(mount_specificdata_domain, &mp->mnt_specdataref);
|
||||
rw_destroy(&mp->mnt_lock);
|
||||
if (mp->mnt_op != NULL) {
|
||||
vfs_delref(mp->mnt_op);
|
||||
}
|
||||
mutex_destroy(&mp->mnt_renamelock);
|
||||
mutex_destroy(&mp->mnt_mutex);
|
||||
lockdestroy(&mp->mnt_lock);
|
||||
free(mp, M_MOUNT);
|
||||
kmem_free(mp, sizeof(*mp));
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -717,7 +722,7 @@ printlockedvnodes(void)
|
|||
mutex_enter(&mountlist_lock);
|
||||
for (mp = CIRCLEQ_FIRST(&mountlist); mp != (void *)&mountlist;
|
||||
mp = nmp) {
|
||||
if (vfs_busy(mp, LK_NOWAIT, &mountlist_lock)) {
|
||||
if (vfs_trybusy(mp, RW_READER, &mountlist_lock)) {
|
||||
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
||||
continue;
|
||||
}
|
||||
|
@ -727,7 +732,7 @@ printlockedvnodes(void)
|
|||
}
|
||||
mutex_enter(&mountlist_lock);
|
||||
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
}
|
||||
mutex_exit(&mountlist_lock);
|
||||
}
|
||||
|
@ -1255,25 +1260,8 @@ vfs_mount_print(struct mount *mp, int full, void (*pr)(const char *, ...))
|
|||
bitmask_snprintf(mp->mnt_iflag, __IMNT_FLAG_BITS, sbuf, sizeof(sbuf));
|
||||
(*pr)("iflag = %s\n", sbuf);
|
||||
|
||||
/* XXX use lockmgr_printinfo */
|
||||
if (mp->mnt_lock.lk_sharecount)
|
||||
(*pr)(" lock type %s: SHARED (count %d)", mp->mnt_lock.lk_wmesg,
|
||||
mp->mnt_lock.lk_sharecount);
|
||||
else if (mp->mnt_lock.lk_flags & LK_HAVE_EXCL) {
|
||||
(*pr)(" lock type %s: EXCL (count %d) by ",
|
||||
mp->mnt_lock.lk_wmesg, mp->mnt_lock.lk_exclusivecount);
|
||||
(*pr)("pid %d.%d", mp->mnt_lock.lk_lockholder,
|
||||
mp->mnt_lock.lk_locklwp);
|
||||
} else
|
||||
(*pr)(" not locked");
|
||||
if (mp->mnt_lock.lk_waitcount > 0)
|
||||
(*pr)(" with %d pending", mp->mnt_lock.lk_waitcount);
|
||||
|
||||
(*pr)("\n");
|
||||
|
||||
if (mp->mnt_unmounter) {
|
||||
(*pr)("unmounter pid = %d ",mp->mnt_unmounter->l_proc);
|
||||
}
|
||||
(*pr)("refcnt = %d lock @ %p writer = %p\n", mp->mnt_refcnt,
|
||||
&mp->mnt_lock, mp->mnt_writer);
|
||||
|
||||
(*pr)("statvfs cache:\n");
|
||||
(*pr)("\tbsize = %lu\n",mp->mnt_stat.f_bsize);
|
||||
|
@ -1312,7 +1300,6 @@ vfs_mount_print(struct mount *mp, int full, void (*pr)(const char *, ...))
|
|||
int cnt = 0;
|
||||
struct vnode *vp;
|
||||
(*pr)("locked vnodes =");
|
||||
/* XXX would take mountlist lock, except ddb may not have context */
|
||||
TAILQ_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) {
|
||||
if (VOP_ISLOCKED(vp)) {
|
||||
if ((++cnt % 6) == 0) {
|
||||
|
@ -1329,7 +1316,6 @@ vfs_mount_print(struct mount *mp, int full, void (*pr)(const char *, ...))
|
|||
int cnt = 0;
|
||||
struct vnode *vp;
|
||||
(*pr)("all vnodes =");
|
||||
/* XXX would take mountlist lock, except ddb may not have context */
|
||||
TAILQ_FOREACH(vp, &mp->mnt_vnodelist, v_mntvnodes) {
|
||||
if (!TAILQ_NEXT(vp, v_mntvnodes)) {
|
||||
(*pr)(" %p", vp);
|
||||
|
|
|
@ -1,4 +1,37 @@
|
|||
/* $NetBSD: vfs_syscalls.c,v 1.344 2008/01/28 14:31:18 dholland Exp $ */
|
||||
/* $NetBSD: vfs_syscalls.c,v 1.345 2008/01/30 11:47:01 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2008 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the NetBSD
|
||||
* Foundation, Inc. and its contributors.
|
||||
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
||||
* contributors may be used to endorse or promote products derived
|
||||
* from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
||||
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
||||
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
||||
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
||||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
||||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
||||
* POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993
|
||||
|
@ -37,7 +70,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.344 2008/01/28 14:31:18 dholland Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: vfs_syscalls.c,v 1.345 2008/01/30 11:47:01 ad Exp $");
|
||||
|
||||
#include "opt_compat_netbsd.h"
|
||||
#include "opt_compat_43.h"
|
||||
|
@ -160,7 +193,7 @@ mount_update(struct lwp *l, struct vnode *vp, const char *path, int flags,
|
|||
if (error)
|
||||
goto out;
|
||||
|
||||
if (vfs_busy(mp, LK_NOWAIT, 0)) {
|
||||
if (vfs_trybusy(mp, RW_WRITER, 0)) {
|
||||
error = EPERM;
|
||||
goto out;
|
||||
}
|
||||
|
@ -215,7 +248,7 @@ mount_update(struct lwp *l, struct vnode *vp, const char *path, int flags,
|
|||
if (mp->mnt_syncer != NULL)
|
||||
vfs_deallocate_syncvnode(mp);
|
||||
}
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
|
||||
out:
|
||||
return (error);
|
||||
|
@ -300,19 +333,20 @@ mount_domount(struct lwp *l, struct vnode **vpp, struct vfsops *vfsops,
|
|||
if (vp->v_mountedhere != NULL)
|
||||
return EBUSY;
|
||||
|
||||
mp = malloc(sizeof(*mp), M_MOUNT, M_WAITOK|M_ZERO);
|
||||
mp = kmem_zalloc(sizeof(*mp), KM_SLEEP);
|
||||
if (mp == NULL)
|
||||
return ENOMEM;
|
||||
|
||||
mp->mnt_op = vfsops;
|
||||
mp->mnt_refcnt = 1;
|
||||
|
||||
TAILQ_INIT(&mp->mnt_vnodelist);
|
||||
lockinit(&mp->mnt_lock, PVFS, "vfslock", 0, 0);
|
||||
mutex_init(&mp->mnt_mutex, MUTEX_DEFAULT, IPL_NONE);
|
||||
rw_init(&mp->mnt_lock);
|
||||
mutex_init(&mp->mnt_renamelock, MUTEX_DEFAULT, IPL_NONE);
|
||||
(void)vfs_busy(mp, LK_NOWAIT, 0);
|
||||
(void)vfs_busy(mp, RW_WRITER, 0);
|
||||
|
||||
mp->mnt_vnodecovered = vp;
|
||||
mp->mnt_stat.f_owner = kauth_cred_geteuid(l->l_cred);
|
||||
mp->mnt_unmounter = NULL;
|
||||
mount_initspecific(mp);
|
||||
|
||||
/*
|
||||
|
@ -337,14 +371,14 @@ mount_domount(struct lwp *l, struct vnode **vpp, struct vfsops *vfsops,
|
|||
if (error != 0) {
|
||||
vp->v_mountedhere = NULL;
|
||||
mp->mnt_op->vfs_refcount--;
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
vfs_destroy(mp);
|
||||
return error;
|
||||
}
|
||||
|
||||
mp->mnt_iflag &= ~IMNT_WANTRDWR;
|
||||
vp->v_mountedhere = mp;
|
||||
mutex_enter(&mountlist_lock);
|
||||
vp->v_mountedhere = mp;
|
||||
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
|
||||
mutex_exit(&mountlist_lock);
|
||||
vn_restorerecurse(vp, recurse);
|
||||
|
@ -352,11 +386,13 @@ mount_domount(struct lwp *l, struct vnode **vpp, struct vfsops *vfsops,
|
|||
checkdirs(vp);
|
||||
if ((mp->mnt_flag & (MNT_RDONLY | MNT_ASYNC)) == 0)
|
||||
error = vfs_allocate_syncvnode(mp);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
(void) VFS_STATVFS(mp, &mp->mnt_stat);
|
||||
error = VFS_START(mp, 0);
|
||||
if (error)
|
||||
if (error) {
|
||||
vrele(vp);
|
||||
vfs_destroy(mp);
|
||||
}
|
||||
*vpp = NULL;
|
||||
return error;
|
||||
}
|
||||
|
@ -383,7 +419,7 @@ mount_getargs(struct lwp *l, struct vnode *vp, const char *path, int flags,
|
|||
if ((vp->v_vflag & VV_ROOT) == 0)
|
||||
return EINVAL;
|
||||
|
||||
if (vfs_busy(mp, LK_NOWAIT, 0))
|
||||
if (vfs_trybusy(mp, RW_WRITER, NULL))
|
||||
return EPERM;
|
||||
|
||||
mp->mnt_flag &= ~MNT_OP_FLAGS;
|
||||
|
@ -391,7 +427,7 @@ mount_getargs(struct lwp *l, struct vnode *vp, const char *path, int flags,
|
|||
error = VFS_MOUNT(mp, path, data, data_len);
|
||||
mp->mnt_flag &= ~MNT_OP_FLAGS;
|
||||
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
return (error);
|
||||
}
|
||||
|
||||
|
@ -587,11 +623,12 @@ sys_unmount(struct lwp *l, const struct sys_unmount_args *uap, register_t *retva
|
|||
return (error);
|
||||
vp = nd.ni_vp;
|
||||
mp = vp->v_mount;
|
||||
VOP_UNLOCK(vp, 0);
|
||||
|
||||
error = kauth_authorize_system(l->l_cred, KAUTH_SYSTEM_MOUNT,
|
||||
KAUTH_REQ_SYSTEM_MOUNT_UNMOUNT, mp, NULL, NULL);
|
||||
if (error) {
|
||||
vput(vp);
|
||||
vrele(vp);
|
||||
return (error);
|
||||
}
|
||||
|
||||
|
@ -599,7 +636,7 @@ sys_unmount(struct lwp *l, const struct sys_unmount_args *uap, register_t *retva
|
|||
* Don't allow unmounting the root file system.
|
||||
*/
|
||||
if (mp->mnt_flag & MNT_ROOTFS) {
|
||||
vput(vp);
|
||||
vrele(vp);
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
|
@ -607,20 +644,20 @@ sys_unmount(struct lwp *l, const struct sys_unmount_args *uap, register_t *retva
|
|||
* Must be the root of the filesystem
|
||||
*/
|
||||
if ((vp->v_vflag & VV_ROOT) == 0) {
|
||||
vput(vp);
|
||||
vrele(vp);
|
||||
return (EINVAL);
|
||||
}
|
||||
vput(vp);
|
||||
|
||||
/*
|
||||
* XXX Freeze syncer. Must do this before locking the
|
||||
* mount point. See dounmount() for details.
|
||||
*/
|
||||
mutex_enter(&syncer_mutex);
|
||||
|
||||
if (vfs_busy(mp, 0, 0)) {
|
||||
error = vfs_busy(mp, RW_WRITER, NULL);
|
||||
vrele(vp);
|
||||
if (error != 0) {
|
||||
mutex_exit(&syncer_mutex);
|
||||
return (EBUSY);
|
||||
return (error);
|
||||
}
|
||||
|
||||
return (dounmount(mp, SCARG(uap, flags), l));
|
||||
|
@ -638,14 +675,14 @@ dounmount(struct mount *mp, int flags, struct lwp *l)
|
|||
int async;
|
||||
int used_syncer;
|
||||
|
||||
KASSERT(rw_write_held(&mp->mnt_lock));
|
||||
|
||||
#if NVERIEXEC > 0
|
||||
error = veriexec_unmountchk(mp);
|
||||
if (error)
|
||||
return (error);
|
||||
#endif /* NVERIEXEC > 0 */
|
||||
|
||||
mutex_enter(&mountlist_lock);
|
||||
vfs_unbusy(mp);
|
||||
used_syncer = (mp->mnt_syncer != NULL);
|
||||
|
||||
/*
|
||||
|
@ -666,9 +703,6 @@ dounmount(struct mount *mp, int flags, struct lwp *l)
|
|||
mutex_exit(&syncer_mutex);
|
||||
|
||||
mp->mnt_iflag |= IMNT_UNMOUNT;
|
||||
mp->mnt_unmounter = l;
|
||||
lockmgr(&mp->mnt_lock, LK_DRAIN | LK_INTERLOCK, &mountlist_lock);
|
||||
|
||||
async = mp->mnt_flag & MNT_ASYNC;
|
||||
mp->mnt_flag &= ~MNT_ASYNC;
|
||||
cache_purgevfs(mp); /* remove cache entries for this file sys */
|
||||
|
@ -688,21 +722,11 @@ dounmount(struct mount *mp, int flags, struct lwp *l)
|
|||
if (error) {
|
||||
if ((mp->mnt_flag & (MNT_RDONLY | MNT_ASYNC)) == 0)
|
||||
(void) vfs_allocate_syncvnode(mp);
|
||||
mutex_enter(&mountlist_lock);
|
||||
mp->mnt_iflag &= ~IMNT_UNMOUNT;
|
||||
mp->mnt_unmounter = NULL;
|
||||
mp->mnt_flag |= async;
|
||||
lockmgr(&mp->mnt_lock, LK_RELEASE | LK_INTERLOCK | LK_REENABLE,
|
||||
&mountlist_lock);
|
||||
if (used_syncer)
|
||||
mutex_exit(&syncer_mutex);
|
||||
mutex_enter(&mp->mnt_mutex);
|
||||
while (mp->mnt_wcnt > 0) {
|
||||
wakeup(mp);
|
||||
mtsleep(&mp->mnt_wcnt, PVFS, "mntwcnt1",
|
||||
0, &mp->mnt_mutex);
|
||||
}
|
||||
mutex_exit(&mp->mnt_mutex);
|
||||
vfs_unbusy(mp, false);
|
||||
return (error);
|
||||
}
|
||||
vfs_scrubvnlist(mp);
|
||||
|
@ -710,23 +734,17 @@ dounmount(struct mount *mp, int flags, struct lwp *l)
|
|||
CIRCLEQ_REMOVE(&mountlist, mp, mnt_list);
|
||||
if ((coveredvp = mp->mnt_vnodecovered) != NULLVP)
|
||||
coveredvp->v_mountedhere = NULL;
|
||||
mutex_exit(&mountlist_lock);
|
||||
if (TAILQ_FIRST(&mp->mnt_vnodelist) != NULL)
|
||||
panic("unmount: dangling vnode");
|
||||
mp->mnt_iflag |= IMNT_GONE;
|
||||
lockmgr(&mp->mnt_lock, LK_RELEASE | LK_INTERLOCK, &mountlist_lock);
|
||||
if (coveredvp != NULLVP)
|
||||
vrele(coveredvp);
|
||||
if (used_syncer)
|
||||
mutex_exit(&syncer_mutex);
|
||||
mutex_enter(&mp->mnt_mutex);
|
||||
while (mp->mnt_wcnt > 0) {
|
||||
wakeup(mp);
|
||||
mtsleep(&mp->mnt_wcnt, PVFS, "mntwcnt2", 0, &mp->mnt_mutex);
|
||||
}
|
||||
mutex_exit(&mp->mnt_mutex);
|
||||
vfs_hooks_unmount(mp);
|
||||
vfs_delref(mp->mnt_op);
|
||||
vfs_unbusy(mp, false);
|
||||
vfs_destroy(mp);
|
||||
if (coveredvp != NULLVP)
|
||||
vrele(coveredvp);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -750,7 +768,7 @@ sys_sync(struct lwp *l, const void *v, register_t *retval)
|
|||
|
||||
mutex_enter(&mountlist_lock);
|
||||
for (mp = mountlist.cqh_last; mp != (void *)&mountlist; mp = nmp) {
|
||||
if (vfs_busy(mp, LK_NOWAIT, &mountlist_lock)) {
|
||||
if (vfs_trybusy(mp, RW_READER, &mountlist_lock)) {
|
||||
nmp = mp->mnt_list.cqe_prev;
|
||||
continue;
|
||||
}
|
||||
|
@ -763,7 +781,7 @@ sys_sync(struct lwp *l, const void *v, register_t *retval)
|
|||
}
|
||||
mutex_enter(&mountlist_lock);
|
||||
nmp = mp->mnt_list.cqe_prev;
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
|
||||
}
|
||||
mutex_exit(&mountlist_lock);
|
||||
|
@ -971,7 +989,7 @@ do_sys_getvfsstat(struct lwp *l, void *sfsp, size_t bufsize, int flags,
|
|||
count = 0;
|
||||
for (mp = CIRCLEQ_FIRST(&mountlist); mp != (void *)&mountlist;
|
||||
mp = nmp) {
|
||||
if (vfs_busy(mp, LK_NOWAIT, &mountlist_lock)) {
|
||||
if (vfs_trybusy(mp, RW_READER, &mountlist_lock)) {
|
||||
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
||||
continue;
|
||||
}
|
||||
|
@ -980,12 +998,12 @@ do_sys_getvfsstat(struct lwp *l, void *sfsp, size_t bufsize, int flags,
|
|||
if (error) {
|
||||
mutex_enter(&mountlist_lock);
|
||||
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
continue;
|
||||
}
|
||||
error = copyfn(sb, sfsp, entry_sz);
|
||||
if (error) {
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
goto out;
|
||||
}
|
||||
sfsp = (char *)sfsp + entry_sz;
|
||||
|
@ -994,7 +1012,7 @@ do_sys_getvfsstat(struct lwp *l, void *sfsp, size_t bufsize, int flags,
|
|||
count++;
|
||||
mutex_enter(&mountlist_lock);
|
||||
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
}
|
||||
|
||||
mutex_exit(&mountlist_lock);
|
||||
|
@ -1066,12 +1084,11 @@ sys_fchdir(struct lwp *l, const struct sys_fchdir_args *uap, register_t *retval)
|
|||
goto out;
|
||||
}
|
||||
while ((mp = vp->v_mountedhere) != NULL) {
|
||||
if (vfs_busy(mp, 0, 0))
|
||||
if (vfs_busy(mp, RW_READER, NULL))
|
||||
continue;
|
||||
|
||||
vput(vp);
|
||||
error = VFS_ROOT(mp, &tdp);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
if (error)
|
||||
goto out;
|
||||
vp = tdp;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: procfs_linux.c,v 1.47 2007/12/22 01:06:54 yamt Exp $ */
|
||||
/* $NetBSD: procfs_linux.c,v 1.48 2008/01/30 11:47:02 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2001 Wasabi Systems, Inc.
|
||||
|
@ -36,7 +36,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: procfs_linux.c,v 1.47 2007/12/22 01:06:54 yamt Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: procfs_linux.c,v 1.48 2008/01/30 11:47:02 ad Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -561,7 +561,7 @@ procfs_domounts(struct lwp *curl, struct proc *p,
|
|||
mutex_enter(&mountlist_lock);
|
||||
for (mp = CIRCLEQ_FIRST(&mountlist); mp != (void *)&mountlist;
|
||||
mp = nmp) {
|
||||
if (vfs_busy(mp, LK_NOWAIT, &mountlist_lock)) {
|
||||
if (vfs_trybusy(mp, RW_READER, &mountlist_lock)) {
|
||||
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
||||
continue;
|
||||
}
|
||||
|
@ -593,7 +593,7 @@ procfs_domounts(struct lwp *curl, struct proc *p,
|
|||
|
||||
mutex_enter(&mountlist_lock);
|
||||
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
}
|
||||
mutex_exit(&mountlist_lock);
|
||||
free(bf, M_TEMP);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: sync_vnops.c,v 1.21 2008/01/30 09:50:23 ad Exp $ */
|
||||
/* $NetBSD: sync_vnops.c,v 1.22 2008/01/30 11:47:02 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 1997 Marshall Kirk McKusick. All Rights Reserved.
|
||||
|
@ -32,7 +32,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: sync_vnops.c,v 1.21 2008/01/30 09:50:23 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: sync_vnops.c,v 1.22 2008/01/30 11:47:02 ad Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/proc.h>
|
||||
|
@ -158,13 +158,13 @@ sync_fsync(v)
|
|||
* not already on the sync list.
|
||||
*/
|
||||
mutex_enter(&mountlist_lock);
|
||||
if (vfs_busy(mp, LK_NOWAIT, &mountlist_lock) == 0) {
|
||||
if (vfs_trybusy(mp, RW_WRITER, &mountlist_lock) == 0) {
|
||||
asyncflag = mp->mnt_flag & MNT_ASYNC;
|
||||
mp->mnt_flag &= ~MNT_ASYNC;
|
||||
VFS_SYNC(mp, MNT_LAZY, ap->a_cred);
|
||||
if (asyncflag)
|
||||
mp->mnt_flag |= MNT_ASYNC;
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
} else
|
||||
mutex_exit(&mountlist_lock);
|
||||
return (0);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: nfs_export.c,v 1.31 2007/12/08 19:29:51 pooka Exp $ */
|
||||
/* $NetBSD: nfs_export.c,v 1.32 2008/01/30 11:47:03 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1997, 1998, 2004, 2005 The NetBSD Foundation, Inc.
|
||||
|
@ -82,7 +82,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: nfs_export.c,v 1.31 2007/12/08 19:29:51 pooka Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: nfs_export.c,v 1.32 2008/01/30 11:47:03 ad Exp $");
|
||||
|
||||
#include "opt_compat_netbsd.h"
|
||||
#include "opt_inet.h"
|
||||
|
@ -249,7 +249,7 @@ mountd_set_exports_list(const struct mountd_exports_list *mel, struct lwp *l)
|
|||
}
|
||||
|
||||
/* Mark the file system busy. */
|
||||
error = vfs_busy(mp, LK_NOWAIT, NULL);
|
||||
error = vfs_busy(mp, RW_READER, NULL);
|
||||
vput(vp);
|
||||
if (error != 0)
|
||||
return error;
|
||||
|
@ -294,7 +294,7 @@ mountd_set_exports_list(const struct mountd_exports_list *mel, struct lwp *l)
|
|||
|
||||
out:
|
||||
netexport_wrunlock();
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: nfs_vfsops.c,v 1.193 2008/01/28 14:31:20 dholland Exp $ */
|
||||
/* $NetBSD: nfs_vfsops.c,v 1.194 2008/01/30 11:47:03 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1993, 1995
|
||||
|
@ -35,7 +35,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.193 2008/01/28 14:31:20 dholland Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: nfs_vfsops.c,v 1.194 2008/01/30 11:47:03 ad Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_compat_netbsd.h"
|
||||
|
@ -363,7 +363,7 @@ nfs_mountroot()
|
|||
mutex_exit(&mountlist_lock);
|
||||
rootvp = vp;
|
||||
mp->mnt_vnodecovered = NULLVP;
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
|
||||
/* Get root attributes (for the time). */
|
||||
error = VOP_GETATTR(vp, &attr, l->l_cred);
|
||||
|
@ -420,11 +420,10 @@ nfs_mount_diskless(ndmntp, mntname, mpp, vpp, l)
|
|||
error = mountnfs(&ndmntp->ndm_args, mp, m, mntname,
|
||||
ndmntp->ndm_args.hostname, vpp, l);
|
||||
if (error) {
|
||||
mp->mnt_op->vfs_refcount--;
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
vfs_destroy(mp);
|
||||
printf("nfs_mountroot: mount %s failed: %d\n",
|
||||
mntname, error);
|
||||
free(mp, M_MOUNT);
|
||||
} else
|
||||
*mpp = mp;
|
||||
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: mount.h,v 1.172 2008/01/28 14:31:20 dholland Exp $ */
|
||||
/* $NetBSD: mount.h,v 1.173 2008/01/30 11:47:03 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1991, 1993
|
||||
|
@ -45,7 +45,7 @@
|
|||
#include <sys/ucred.h>
|
||||
#include <sys/fstypes.h>
|
||||
#include <sys/queue.h>
|
||||
#include <sys/lock.h>
|
||||
#include <sys/rwlock.h>
|
||||
#include <sys/statvfs.h>
|
||||
#include <sys/specificdata.h>
|
||||
#endif /* !_STANDALONE */
|
||||
|
@ -102,22 +102,22 @@ struct vnode;
|
|||
*/
|
||||
struct mount {
|
||||
CIRCLEQ_ENTRY(mount) mnt_list; /* mount list */
|
||||
TAILQ_HEAD(, vnode) mnt_vnodelist; /* list of vnodes this mount */
|
||||
struct vfsops *mnt_op; /* operations on fs */
|
||||
struct vnode *mnt_vnodecovered; /* vnode we mounted on */
|
||||
struct vnode *mnt_syncer; /* syncer vnode */
|
||||
TAILQ_HEAD(, vnode) mnt_vnodelist; /* list of vnodes this mount */
|
||||
struct lock mnt_lock; /* mount structure lock */
|
||||
void *mnt_transinfo; /* for FS-internal use */
|
||||
void *mnt_data; /* private data */
|
||||
struct lwp *mnt_writer; /* who is [un]mounting */
|
||||
krwlock_t mnt_lock; /* mount structure lock */
|
||||
kmutex_t mnt_renamelock; /* per-fs rename lock */
|
||||
int mnt_refcnt; /* ref count on this structure */
|
||||
int mnt_recursecnt; /* count of write locks */
|
||||
int mnt_flag; /* flags */
|
||||
int mnt_iflag; /* internal flags */
|
||||
int mnt_fs_bshift; /* offset shift for lblkno */
|
||||
int mnt_dev_bshift; /* shift for device sectors */
|
||||
struct statvfs mnt_stat; /* cache of filesystem stats */
|
||||
void *mnt_data; /* private data */
|
||||
int mnt_wcnt; /* count of vfs_busy waiters */
|
||||
struct lwp *mnt_unmounter; /* who is unmounting */
|
||||
kmutex_t mnt_mutex; /* mutex for wcnt */
|
||||
kmutex_t mnt_renamelock; /* per-fs rename lock */
|
||||
void *mnt_transinfo; /* for FS-internal use */
|
||||
specificdata_reference
|
||||
mnt_specdataref; /* subsystem specific data */
|
||||
};
|
||||
|
@ -330,9 +330,10 @@ int vfs_mountedon(struct vnode *);/* is a vfs mounted on vp */
|
|||
int vfs_mountroot(void);
|
||||
void vfs_shutdown(void); /* unmount and sync file systems */
|
||||
void vfs_unmountall(struct lwp *); /* unmount file systems */
|
||||
int vfs_busy(struct mount *, int, kmutex_t *);
|
||||
int vfs_busy(struct mount *, const krw_t, kmutex_t *);
|
||||
int vfs_trybusy(struct mount *, const krw_t, kmutex_t *);
|
||||
int vfs_rootmountalloc(const char *, const char *, struct mount **);
|
||||
void vfs_unbusy(struct mount *);
|
||||
void vfs_unbusy(struct mount *, bool);
|
||||
int vfs_attach(struct vfsops *);
|
||||
int vfs_detach(struct vfsops *);
|
||||
void vfs_reinit(void);
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ext2fs_vfsops.c,v 1.129 2008/01/28 14:31:20 dholland Exp $ */
|
||||
/* $NetBSD: ext2fs_vfsops.c,v 1.130 2008/01/30 11:47:03 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1991, 1993, 1994
|
||||
|
@ -65,7 +65,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.129 2008/01/28 14:31:20 dholland Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ext2fs_vfsops.c,v 1.130 2008/01/30 11:47:03 ad Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_compat_netbsd.h"
|
||||
|
@ -222,8 +222,7 @@ ext2fs_mountroot(void)
|
|||
}
|
||||
|
||||
if ((error = ext2fs_mountfs(rootvp, mp)) != 0) {
|
||||
mp->mnt_op->vfs_refcount--;
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
vfs_destroy(mp);
|
||||
return (error);
|
||||
}
|
||||
|
@ -241,7 +240,7 @@ ext2fs_mountroot(void)
|
|||
sizeof(fs->e2fs.e2fs_fsmnt) - 1, 0);
|
||||
}
|
||||
(void)ext2fs_statvfs(mp, &mp->mnt_stat);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
setrootfstime((time_t)fs->e2fs.e2fs_wtime);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ffs_snapshot.c,v 1.62 2008/01/30 09:50:25 ad Exp $ */
|
||||
/* $NetBSD: ffs_snapshot.c,v 1.63 2008/01/30 11:47:03 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright 2000 Marshall Kirk McKusick. All Rights Reserved.
|
||||
|
@ -38,7 +38,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ffs_snapshot.c,v 1.62 2008/01/30 09:50:25 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ffs_snapshot.c,v 1.63 2008/01/30 11:47:03 ad Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_ffs.h"
|
||||
|
@ -166,7 +166,7 @@ si_mount_dtor(void *arg)
|
|||
mutex_destroy(&si->si_lock);
|
||||
rw_destroy(&si->si_vnlock.vl_lock);
|
||||
KASSERT(si->si_snapblklist == NULL);
|
||||
free(si, M_MOUNT);
|
||||
kmem_free(si, sizeof(*si));
|
||||
}
|
||||
|
||||
static struct snap_info *
|
||||
|
@ -175,18 +175,18 @@ si_mount_init(struct mount *mp)
|
|||
struct snap_info *new;
|
||||
|
||||
mutex_enter(&si_mount_init_lock);
|
||||
|
||||
if ((new = mount_getspecific(mp, si_mount_data_key)) != NULL) {
|
||||
mutex_exit(&si_mount_init_lock);
|
||||
return new;
|
||||
}
|
||||
|
||||
new = malloc(sizeof(*new), M_MOUNT, M_WAITOK);
|
||||
TAILQ_INIT(&new->si_snapshots);
|
||||
mutex_init(&new->si_lock, MUTEX_DEFAULT, IPL_NONE);
|
||||
new->si_gen = 0;
|
||||
new->si_snapblklist = NULL;
|
||||
mount_setspecific(mp, si_mount_data_key, new);
|
||||
new = kmem_alloc(sizeof(*new), KM_SLEEP);
|
||||
if (new != NULL) {
|
||||
TAILQ_INIT(&new->si_snapshots);
|
||||
mutex_init(&new->si_lock, MUTEX_DEFAULT, IPL_NONE);
|
||||
new->si_gen = 0;
|
||||
new->si_snapblklist = NULL;
|
||||
mount_setspecific(mp, si_mount_data_key, new);
|
||||
}
|
||||
mutex_exit(&si_mount_init_lock);
|
||||
return new;
|
||||
}
|
||||
|
@ -225,8 +225,12 @@ ffs_snapshot(struct mount *mp, struct vnode *vp,
|
|||
struct snap_info *si;
|
||||
|
||||
ns = UFS_FSNEEDSWAP(fs);
|
||||
if ((si = mount_getspecific(mp, si_mount_data_key)) == NULL)
|
||||
if ((si = mount_getspecific(mp, si_mount_data_key)) == NULL) {
|
||||
si = si_mount_init(mp);
|
||||
if (si == NULL)
|
||||
return ENOMEM;
|
||||
}
|
||||
|
||||
/*
|
||||
* Need to serialize access to snapshot code per filesystem.
|
||||
*/
|
||||
|
@ -1730,8 +1734,11 @@ ffs_snapshot_mount(struct mount *mp)
|
|||
if (UFS_MPISAPPLEUFS(VFSTOUFS(mp)))
|
||||
return;
|
||||
|
||||
if ((si = mount_getspecific(mp, si_mount_data_key)) == NULL)
|
||||
if ((si = mount_getspecific(mp, si_mount_data_key)) == NULL) {
|
||||
si = si_mount_init(mp);
|
||||
if (si == NULL)
|
||||
return;
|
||||
}
|
||||
ns = UFS_FSNEEDSWAP(fs);
|
||||
/*
|
||||
* XXX The following needs to be set before ffs_truncate or
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ffs_vfsops.c,v 1.221 2008/01/28 14:31:20 dholland Exp $ */
|
||||
/* $NetBSD: ffs_vfsops.c,v 1.222 2008/01/30 11:47:04 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1991, 1993, 1994
|
||||
|
@ -32,7 +32,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.221 2008/01/28 14:31:20 dholland Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ffs_vfsops.c,v 1.222 2008/01/30 11:47:04 ad Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_ffs.h"
|
||||
|
@ -164,8 +164,7 @@ ffs_mountroot(void)
|
|||
return (error);
|
||||
}
|
||||
if ((error = ffs_mountfs(rootvp, mp, l)) != 0) {
|
||||
mp->mnt_op->vfs_refcount--;
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
vfs_destroy(mp);
|
||||
return (error);
|
||||
}
|
||||
|
@ -177,7 +176,7 @@ ffs_mountroot(void)
|
|||
memset(fs->fs_fsmnt, 0, sizeof(fs->fs_fsmnt));
|
||||
(void)copystr(mp->mnt_stat.f_mntonname, fs->fs_fsmnt, MNAMELEN - 1, 0);
|
||||
(void)ffs_statvfs(mp, &mp->mnt_stat);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
setrootfstime((time_t)fs->fs_time);
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
/* $NetBSD: lfs_bio.c,v 1.107 2008/01/02 11:49:10 ad Exp $ */
|
||||
/* $NetBSD: lfs_bio.c,v 1.108 2008/01/30 11:47:04 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999, 2000, 2001, 2002, 2003 The NetBSD Foundation, Inc.
|
||||
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2008 The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
|
@ -67,7 +67,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.107 2008/01/02 11:49:10 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: lfs_bio.c,v 1.108 2008/01/30 11:47:04 ad Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
|
@ -583,19 +583,19 @@ lfs_flush(struct lfs *fs, int flags, int only_onefs)
|
|||
|
||||
if (only_onefs) {
|
||||
KASSERT(fs != NULL);
|
||||
if (vfs_busy(fs->lfs_ivnode->v_mount, LK_NOWAIT,
|
||||
&mountlist_lock))
|
||||
if (vfs_trybusy(fs->lfs_ivnode->v_mount, RW_READER,
|
||||
&mountlist_lock))
|
||||
goto errout;
|
||||
mutex_enter(&lfs_lock);
|
||||
lfs_flush_fs(fs, flags);
|
||||
mutex_exit(&lfs_lock);
|
||||
vfs_unbusy(fs->lfs_ivnode->v_mount);
|
||||
vfs_unbusy(fs->lfs_ivnode->v_mount, false);
|
||||
} else {
|
||||
locked_fakequeue_count = 0;
|
||||
mutex_enter(&mountlist_lock);
|
||||
for (mp = CIRCLEQ_FIRST(&mountlist); mp != (void *)&mountlist;
|
||||
mp = nmp) {
|
||||
if (vfs_busy(mp, LK_NOWAIT, &mountlist_lock)) {
|
||||
if (vfs_trybusy(mp, RW_READER, &mountlist_lock)) {
|
||||
DLOG((DLOG_FLUSH, "lfs_flush: fs vfs_busy\n"));
|
||||
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
||||
continue;
|
||||
|
@ -609,7 +609,7 @@ lfs_flush(struct lfs *fs, int flags, int only_onefs)
|
|||
}
|
||||
mutex_enter(&mountlist_lock);
|
||||
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
}
|
||||
mutex_exit(&mountlist_lock);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
/* $NetBSD: lfs_syscalls.c,v 1.127 2008/01/30 09:50:27 ad Exp $ */
|
||||
/* $NetBSD: lfs_syscalls.c,v 1.128 2008/01/30 11:47:04 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007 The NetBSD Foundation, Inc.
|
||||
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
|
||||
* The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
|
@ -67,7 +68,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: lfs_syscalls.c,v 1.127 2008/01/30 09:50:27 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: lfs_syscalls.c,v 1.128 2008/01/30 11:47:04 ad Exp $");
|
||||
|
||||
#ifndef LFS
|
||||
# define LFS /* for prototypes in syscallargs.h */
|
||||
|
@ -254,7 +255,7 @@ lfs_markv(struct proc *p, fsid_t *fsidp, BLOCK_INFO *blkiov,
|
|||
|
||||
cnt = blkcnt;
|
||||
|
||||
if ((error = vfs_busy(mntp, LK_NOWAIT, NULL)) != 0)
|
||||
if ((error = vfs_trybusy(mntp, RW_READER, NULL)) != 0)
|
||||
return (error);
|
||||
|
||||
/*
|
||||
|
@ -505,7 +506,7 @@ lfs_markv(struct proc *p, fsid_t *fsidp, BLOCK_INFO *blkiov,
|
|||
|
||||
lfs_segunlock(fs);
|
||||
|
||||
vfs_unbusy(mntp);
|
||||
vfs_unbusy(mntp, false);
|
||||
if (error)
|
||||
return (error);
|
||||
else if (do_again)
|
||||
|
@ -533,7 +534,7 @@ err3:
|
|||
}
|
||||
|
||||
lfs_segunlock(fs);
|
||||
vfs_unbusy(mntp);
|
||||
vfs_unbusy(mntp, false);
|
||||
#ifdef DIAGNOSTIC
|
||||
if (numrefed != 0)
|
||||
panic("lfs_markv: numrefed=%d", numrefed);
|
||||
|
@ -679,7 +680,7 @@ lfs_bmapv(struct proc *p, fsid_t *fsidp, BLOCK_INFO *blkiov, int blkcnt)
|
|||
return (ENOENT);
|
||||
|
||||
ump = VFSTOUFS(mntp);
|
||||
if ((error = vfs_busy(mntp, LK_NOWAIT, NULL)) != 0)
|
||||
if ((error = vfs_trybusy(mntp, RW_READER, NULL)) != 0)
|
||||
return (error);
|
||||
|
||||
cnt = blkcnt;
|
||||
|
@ -819,7 +820,7 @@ lfs_bmapv(struct proc *p, fsid_t *fsidp, BLOCK_INFO *blkiov, int blkcnt)
|
|||
panic("lfs_bmapv: numrefed=%d", numrefed);
|
||||
#endif
|
||||
|
||||
vfs_unbusy(mntp);
|
||||
vfs_unbusy(mntp, false);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -857,13 +858,13 @@ sys_lfs_segclean(struct lwp *l, const struct sys_lfs_segclean_args *uap, registe
|
|||
fs = VFSTOUFS(mntp)->um_lfs;
|
||||
segnum = SCARG(uap, segment);
|
||||
|
||||
if ((error = vfs_busy(mntp, LK_NOWAIT, NULL)) != 0)
|
||||
if ((error = vfs_trybusy(mntp, RW_READER, NULL)) != 0)
|
||||
return (error);
|
||||
|
||||
lfs_seglock(fs, SEGM_PROT);
|
||||
error = lfs_do_segclean(fs, segnum);
|
||||
lfs_segunlock(fs);
|
||||
vfs_unbusy(mntp);
|
||||
vfs_unbusy(mntp, false);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
/* $NetBSD: lfs_vfsops.c,v 1.254 2008/01/28 14:31:20 dholland Exp $ */
|
||||
/* $NetBSD: lfs_vfsops.c,v 1.255 2008/01/30 11:47:04 ad Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007 The NetBSD Foundation, Inc.
|
||||
* Copyright (c) 1999, 2000, 2001, 2002, 2003, 2007, 2007
|
||||
* The NetBSD Foundation, Inc.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to The NetBSD Foundation
|
||||
|
@ -67,7 +68,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.254 2008/01/28 14:31:20 dholland Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: lfs_vfsops.c,v 1.255 2008/01/30 11:47:04 ad Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_lfs.h"
|
||||
|
@ -218,7 +219,7 @@ lfs_writerd(void *arg)
|
|||
mutex_enter(&mountlist_lock);
|
||||
for (mp = CIRCLEQ_FIRST(&mountlist); mp != (void *)&mountlist;
|
||||
mp = nmp) {
|
||||
if (vfs_busy(mp, LK_NOWAIT, &mountlist_lock)) {
|
||||
if (vfs_trybusy(mp, RW_WRITER, &mountlist_lock)) {
|
||||
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
||||
continue;
|
||||
}
|
||||
|
@ -248,7 +249,7 @@ lfs_writerd(void *arg)
|
|||
|
||||
mutex_enter(&mountlist_lock);
|
||||
nmp = CIRCLEQ_NEXT(mp, mnt_list);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
}
|
||||
mutex_exit(&mountlist_lock);
|
||||
|
||||
|
@ -351,8 +352,7 @@ lfs_mountroot()
|
|||
return (error);
|
||||
}
|
||||
if ((error = lfs_mountfs(rootvp, mp, l))) {
|
||||
mp->mnt_op->vfs_refcount--;
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
vfs_destroy(mp);
|
||||
return (error);
|
||||
}
|
||||
|
@ -360,7 +360,7 @@ lfs_mountroot()
|
|||
CIRCLEQ_INSERT_TAIL(&mountlist, mp, mnt_list);
|
||||
mutex_exit(&mountlist_lock);
|
||||
(void)lfs_statvfs(mp, &mp->mnt_stat);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
setrootfstime((time_t)(VFSTOUFS(mp)->um_lfs->lfs_tstamp));
|
||||
return (0);
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: mfs_vfsops.c,v 1.88 2008/01/28 14:31:21 dholland Exp $ */
|
||||
/* $NetBSD: mfs_vfsops.c,v 1.89 2008/01/30 11:47:05 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1989, 1990, 1993, 1994
|
||||
|
@ -32,7 +32,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: mfs_vfsops.c,v 1.88 2008/01/28 14:31:21 dholland Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: mfs_vfsops.c,v 1.89 2008/01/30 11:47:05 ad Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_compat_netbsd.h"
|
||||
|
@ -198,8 +198,7 @@ mfs_mountroot(void)
|
|||
mfsp->mfs_shutdown = 0;
|
||||
bufq_alloc(&mfsp->mfs_buflist, "fcfs", 0);
|
||||
if ((error = ffs_mountfs(rootvp, mp, l)) != 0) {
|
||||
mp->mnt_op->vfs_refcount--;
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
bufq_free(mfsp->mfs_buflist);
|
||||
vfs_destroy(mp);
|
||||
free(mfsp, M_MFSNODE);
|
||||
|
@ -213,7 +212,7 @@ mfs_mountroot(void)
|
|||
fs = ump->um_fs;
|
||||
(void) copystr(mp->mnt_stat.f_mntonname, fs->fs_fsmnt, MNAMELEN - 1, 0);
|
||||
(void)ffs_statvfs(mp, &mp->mnt_stat);
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
return (0);
|
||||
}
|
||||
|
||||
|
@ -387,7 +386,7 @@ mfs_start(struct mount *mp, int flags)
|
|||
* the mount point. See dounmount() for details.
|
||||
*/
|
||||
mutex_enter(&syncer_mutex);
|
||||
if (vfs_busy(mp, LK_NOWAIT, 0) != 0)
|
||||
if (vfs_trybusy(mp, RW_WRITER, NULL) != 0)
|
||||
mutex_exit(&syncer_mutex);
|
||||
else if (dounmount(mp, 0, l) != 0) {
|
||||
p = l->l_proc;
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: ufs_vfsops.c,v 1.36 2008/01/03 19:28:51 ad Exp $ */
|
||||
/* $NetBSD: ufs_vfsops.c,v 1.37 2008/01/30 11:47:05 ad Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 1991, 1993, 1994
|
||||
|
@ -37,7 +37,7 @@
|
|||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: ufs_vfsops.c,v 1.36 2008/01/03 19:28:51 ad Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: ufs_vfsops.c,v 1.37 2008/01/30 11:47:05 ad Exp $");
|
||||
|
||||
#if defined(_KERNEL_OPT)
|
||||
#include "opt_ffs.h"
|
||||
|
@ -133,8 +133,9 @@ ufs_quotactl(struct mount *mp, int cmds, uid_t uid, void *arg)
|
|||
type = cmds & SUBCMDMASK;
|
||||
if ((u_int)type >= MAXQUOTAS)
|
||||
return (EINVAL);
|
||||
if (vfs_busy(mp, LK_NOWAIT, 0))
|
||||
return (0);
|
||||
error = vfs_trybusy(mp, RW_READER, NULL);
|
||||
if (error != 0)
|
||||
return (error);
|
||||
|
||||
switch (cmd) {
|
||||
|
||||
|
@ -165,7 +166,7 @@ ufs_quotactl(struct mount *mp, int cmds, uid_t uid, void *arg)
|
|||
default:
|
||||
error = EINVAL;
|
||||
}
|
||||
vfs_unbusy(mp);
|
||||
vfs_unbusy(mp, false);
|
||||
return (error);
|
||||
#endif
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue