Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys Change _fstrans_start() to allocate per lwp info for lay...



details:   https://anonhg.NetBSD.org/src/rev/a3842f4df240
branches:  trunk
changeset: 822648:a3842f4df240
user:      hannken <hannken%NetBSD.org@localhost>
date:      Thu Mar 30 09:13:01 2017 +0000

description:
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.

diffstat:

 sys/kern/vfs_mount.c                |  16 ++++++++--------
 sys/kern/vfs_trans.c                |  26 ++++++++++++++++++--------
 sys/miscfs/nullfs/null_vfsops.c     |  10 ++++++----
 sys/miscfs/overlay/overlay_vfsops.c |  10 ++++++----
 sys/miscfs/umapfs/umap_vfsops.c     |  10 ++++++----
 5 files changed, 44 insertions(+), 28 deletions(-)

diffs (226 lines):

diff -r cd6f0f64f78a -r a3842f4df240 sys/kern/vfs_mount.c
--- a/sys/kern/vfs_mount.c      Thu Mar 30 09:12:21 2017 +0000
+++ b/sys/kern/vfs_mount.c      Thu Mar 30 09:13:01 2017 +0000
@@ -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 @@
                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 @@
        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.
         */
diff -r cd6f0f64f78a -r a3842f4df240 sys/kern/vfs_trans.c
--- a/sys/kern/vfs_trans.c      Thu Mar 30 09:12:21 2017 +0000
+++ b/sys/kern/vfs_trans.c      Thu Mar 30 09:13:01 2017 +0000
@@ -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 @@
 _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 @@
        }
 
        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 @@
 
        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) {
diff -r cd6f0f64f78a -r a3842f4df240 sys/miscfs/nullfs/null_vfsops.c
--- a/sys/miscfs/nullfs/null_vfsops.c   Thu Mar 30 09:12:21 2017 +0000
+++ b/sys/miscfs/nullfs/null_vfsops.c   Thu Mar 30 09:13:01 2017 +0000
@@ -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 @@
        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
diff -r cd6f0f64f78a -r a3842f4df240 sys/miscfs/overlay/overlay_vfsops.c
--- a/sys/miscfs/overlay/overlay_vfsops.c       Thu Mar 30 09:12:21 2017 +0000
+++ b/sys/miscfs/overlay/overlay_vfsops.c       Thu Mar 30 09:13:01 2017 +0000
@@ -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 @@
        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;
 }
 
 /*
diff -r cd6f0f64f78a -r a3842f4df240 sys/miscfs/umapfs/umap_vfsops.c
--- a/sys/miscfs/umapfs/umap_vfsops.c   Thu Mar 30 09:12:21 2017 +0000
+++ b/sys/miscfs/umapfs/umap_vfsops.c   Thu Mar 30 09:13:01 2017 +0000
@@ -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 @@
        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;
 }
 
 /*



Home | Main Index | Thread Index | Old Index