Change _fstrans_start() to allocate per lwp info for layered file

systems to get a reference on the mount.

Set mnt_lower on successfull mount only.
This commit is contained in:
hannken 2017-03-30 09:13:01 +00:00
parent 3332a1029e
commit dd67c605a3
5 changed files with 44 additions and 28 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_mount.c,v 1.50 2017/03/06 10:11:21 hannken Exp $ */
/* $NetBSD: vfs_mount.c,v 1.51 2017/03/30 09:13:01 hannken Exp $ */
/*-
* Copyright (c) 1997-2011 The NetBSD Foundation, Inc.
@ -67,7 +67,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.50 2017/03/06 10:11:21 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.51 2017/03/30 09:13:01 hannken Exp $");
#include <sys/param.h>
#include <sys/kernel.h>
@ -711,6 +711,12 @@ mount_domount(struct lwp *l, vnode_t **vpp, struct vfsops *vfsops,
return ENOMEM;
}
if ((error = fstrans_mount(mp)) != 0) {
vfs_unbusy(mp, false, NULL);
vfs_destroy(mp);
return error;
}
mp->mnt_stat.f_owner = kauth_cred_geteuid(l->l_cred);
/*
@ -728,12 +734,6 @@ mount_domount(struct lwp *l, vnode_t **vpp, struct vfsops *vfsops,
if (error != 0)
goto err_unmounted;
if (mp->mnt_lower == NULL) {
error = fstrans_mount(mp);
if (error)
goto err_mounted;
}
/*
* Validate and prepare the mount point.
*/

View File

@ -1,4 +1,4 @@
/* $NetBSD: vfs_trans.c,v 1.39 2017/03/06 10:11:21 hannken Exp $ */
/* $NetBSD: vfs_trans.c,v 1.40 2017/03/30 09:13:01 hannken Exp $ */
/*-
* Copyright (c) 2007 The NetBSD Foundation, Inc.
@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.39 2017/03/06 10:11:21 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.40 2017/03/30 09:13:01 hannken Exp $");
/*
* File system transaction operations.
@ -329,15 +329,26 @@ int
_fstrans_start(struct mount *mp, enum fstrans_lock_type lock_type, int wait)
{
int s;
struct mount *lmp;
struct fstrans_lwp_info *fli;
struct fstrans_mount_info *fmi;
if ((mp = fstrans_normalize_mount(mp)) == NULL)
if ((lmp = fstrans_normalize_mount(mp)) == NULL)
return 0;
ASSERT_SLEEPABLE();
if ((fli = fstrans_get_lwp_info(mp, true)) == NULL)
/*
* Allocate per lwp info for layered file systems to
* get a reference to the mount. No need to increment
* the reference counter here.
*/
for (lmp = mp; lmp->mnt_lower; lmp = lmp->mnt_lower) {
fli = fstrans_get_lwp_info(lmp, true);
KASSERT(fli != NULL);
}
if ((fli = fstrans_get_lwp_info(lmp, true)) == NULL)
return 0;
if (fli->fli_trans_cnt > 0) {
@ -348,7 +359,7 @@ _fstrans_start(struct mount *mp, enum fstrans_lock_type lock_type, int wait)
}
s = pserialize_read_enter();
fmi = mp->mnt_transinfo;
fmi = lmp->mnt_transinfo;
if (__predict_true(grant_lock(fmi->fmi_state, lock_type))) {
fli->fli_trans_cnt = 1;
fli->fli_lock_type = lock_type;
@ -383,9 +394,8 @@ fstrans_done(struct mount *mp)
if ((mp = fstrans_normalize_mount(mp)) == NULL)
return;
if ((fli = fstrans_get_lwp_info(mp, true)) == NULL)
return;
fli = fstrans_get_lwp_info(mp, false);
KASSERT(fli != NULL);
KASSERT(fli->fli_trans_cnt > 0);
if (fli->fli_trans_cnt > 1) {

View File

@ -1,4 +1,4 @@
/* $NetBSD: null_vfsops.c,v 1.92 2017/03/06 10:10:07 hannken Exp $ */
/* $NetBSD: null_vfsops.c,v 1.93 2017/03/30 09:13:01 hannken Exp $ */
/*
* Copyright (c) 1999 National Aeronautics & Space Administration
@ -76,7 +76,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: null_vfsops.c,v 1.92 2017/03/06 10:10:07 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: null_vfsops.c,v 1.93 2017/03/30 09:13:01 hannken Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -170,13 +170,15 @@ nullfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
vp->v_vflag |= VV_ROOT;
nmp->nullm_rootvp = vp;
mp->mnt_lower = nmp->nullm_vfs;
mp->mnt_iflag |= IMNT_MPSAFE;
VOP_UNLOCK(vp);
error = set_statvfs_info(path, UIO_USERSPACE, args->la.target,
UIO_USERSPACE, mp->mnt_op->vfs_name, mp, curlwp);
return error;
if (error)
return error;
mp->mnt_lower = nmp->nullm_vfs;
return 0;
}
int

View File

@ -1,4 +1,4 @@
/* $NetBSD: overlay_vfsops.c,v 1.65 2017/03/06 10:10:07 hannken Exp $ */
/* $NetBSD: overlay_vfsops.c,v 1.66 2017/03/30 09:13:01 hannken Exp $ */
/*
* Copyright (c) 1999, 2000 National Aeronautics & Space Administration
@ -74,7 +74,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: overlay_vfsops.c,v 1.65 2017/03/06 10:10:07 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: overlay_vfsops.c,v 1.66 2017/03/30 09:13:01 hannken Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -185,16 +185,18 @@ ov_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
vp->v_vflag |= VV_ROOT;
nmp->ovm_rootvp = vp;
mp->mnt_lower = nmp->ovm_vfs;
VOP_UNLOCK(vp);
error = set_statvfs_info(path, UIO_USERSPACE, args->la.target,
UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l);
if (error)
return error;
mp->mnt_lower = nmp->ovm_vfs;
#ifdef OVERLAYFS_DIAGNOSTIC
printf("ov_mount: lower %s, alias at %s\n",
mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
#endif
return error;
return 0;
}
/*

View File

@ -1,4 +1,4 @@
/* $NetBSD: umap_vfsops.c,v 1.97 2017/03/06 10:10:07 hannken Exp $ */
/* $NetBSD: umap_vfsops.c,v 1.98 2017/03/30 09:13:01 hannken Exp $ */
/*
* Copyright (c) 1992, 1993
@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: umap_vfsops.c,v 1.97 2017/03/06 10:10:07 hannken Exp $");
__KERNEL_RCSID(0, "$NetBSD: umap_vfsops.c,v 1.98 2017/03/30 09:13:01 hannken Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -220,16 +220,18 @@ umapfs_mount(struct mount *mp, const char *path, void *data, size_t *data_len)
vn_lock(vp, LK_EXCLUSIVE | LK_RETRY);
vp->v_vflag |= VV_ROOT;
amp->umapm_rootvp = vp;
mp->mnt_lower = amp->umapm_vfs;
VOP_UNLOCK(vp);
error = set_statvfs_info(path, UIO_USERSPACE, args->umap_target,
UIO_USERSPACE, mp->mnt_op->vfs_name, mp, l);
if (error)
return error;
mp->mnt_lower = amp->umapm_vfs;
#ifdef UMAPFS_DIAGNOSTIC
printf("umapfs_mount: lower %s, alias at %s\n",
mp->mnt_stat.f_mntfromname, mp->mnt_stat.f_mntonname);
#endif
return error;
return 0;
}
/*