Module Name: src
Committed By: hannken
Date: Thu Mar 30 09:13:01 UTC 2017
Modified Files:
src/sys/kern: vfs_mount.c vfs_trans.c
src/sys/miscfs/nullfs: null_vfsops.c
src/sys/miscfs/overlay: overlay_vfsops.c
src/sys/miscfs/umapfs: umap_vfsops.c
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.50 -r1.51 src/sys/kern/vfs_mount.c
cvs rdiff -u -r1.39 -r1.40 src/sys/kern/vfs_trans.c
cvs rdiff -u -r1.92 -r1.93 src/sys/miscfs/nullfs/null_vfsops.c
cvs rdiff -u -r1.65 -r1.66 src/sys/miscfs/overlay/overlay_vfsops.c
cvs rdiff -u -r1.97 -r1.98 src/sys/miscfs/umapfs/umap_vfsops.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/kern/vfs_mount.c
diff -u src/sys/kern/vfs_mount.c:1.50 src/sys/kern/vfs_mount.c:1.51
--- src/sys/kern/vfs_mount.c:1.50 Mon Mar 6 10:11:21 2017
+++ src/sys/kern/vfs_mount.c Thu Mar 30 09:13:01 2017
@@ -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 **v
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 **v
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.
*/
Index: src/sys/kern/vfs_trans.c
diff -u src/sys/kern/vfs_trans.c:1.39 src/sys/kern/vfs_trans.c:1.40
--- src/sys/kern/vfs_trans.c:1.39 Mon Mar 6 10:11:21 2017
+++ src/sys/kern/vfs_trans.c Thu Mar 30 09:13:01 2017
@@ -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 fs
}
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) {
Index: src/sys/miscfs/nullfs/null_vfsops.c
diff -u src/sys/miscfs/nullfs/null_vfsops.c:1.92 src/sys/miscfs/nullfs/null_vfsops.c:1.93
--- src/sys/miscfs/nullfs/null_vfsops.c:1.92 Mon Mar 6 10:10:07 2017
+++ src/sys/miscfs/nullfs/null_vfsops.c Thu Mar 30 09:13:01 2017
@@ -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 cha
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
Index: src/sys/miscfs/overlay/overlay_vfsops.c
diff -u src/sys/miscfs/overlay/overlay_vfsops.c:1.65 src/sys/miscfs/overlay/overlay_vfsops.c:1.66
--- src/sys/miscfs/overlay/overlay_vfsops.c:1.65 Mon Mar 6 10:10:07 2017
+++ src/sys/miscfs/overlay/overlay_vfsops.c Thu Mar 30 09:13:01 2017
@@ -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 *p
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;
}
/*
Index: src/sys/miscfs/umapfs/umap_vfsops.c
diff -u src/sys/miscfs/umapfs/umap_vfsops.c:1.97 src/sys/miscfs/umapfs/umap_vfsops.c:1.98
--- src/sys/miscfs/umapfs/umap_vfsops.c:1.97 Mon Mar 6 10:10:07 2017
+++ src/sys/miscfs/umapfs/umap_vfsops.c Thu Mar 30 09:13:01 2017
@@ -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 cha
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;
}
/*