Source-Changes-HG archive

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

[src/trunk]: src/sys/sys Add a helper to set or clear lower mount and use it.



details:   https://anonhg.NetBSD.org/src/rev/32c924a91348
branches:  trunk
changeset: 372261:32c924a91348
user:      hannken <hannken%NetBSD.org@localhost>
date:      Fri Nov 04 11:20:39 2022 +0000

description:
Add a helper to set or clear lower mount and use it.
Always add a reference to the lower mount.

Ride 9.99.105

diffstat:

 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c |   4 +-
 sys/fs/union/union_vfsops.c                             |   8 ++-
 sys/kern/vfs_mount.c                                    |  37 ++++++++++++++++-
 sys/kern/vfs_trans.c                                    |  10 ++-
 sys/miscfs/nullfs/null_vfsops.c                         |  11 +++-
 sys/miscfs/overlay/overlay_vfsops.c                     |  11 +++-
 sys/miscfs/umapfs/umap_vfsops.c                         |  11 +++-
 sys/sys/mount.h                                         |   3 +-
 8 files changed, 75 insertions(+), 20 deletions(-)

diffs (266 lines):

diff -r c80e3c206e19 -r 32c924a91348 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c
--- a/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c   Fri Nov 04 10:51:16 2022 +0000
+++ b/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c   Fri Nov 04 11:20:39 2022 +0000
@@ -1343,7 +1343,9 @@
        set_statvfs_info(path, UIO_SYSSPACE, vfsp->mnt_stat.f_mntfromname,
            UIO_SYSSPACE, vfsp->mnt_op->vfs_name, vfsp, curlwp);
 
-       vfsp->mnt_lower = vp->v_vfsp;
+       error = vfs_set_lowermount(vfsp, vp->v_vfsp);
+       if (error)
+               goto out;
 
        mountlist_append(vfsp);
        vref(vp);
diff -r c80e3c206e19 -r 32c924a91348 sys/fs/union/union_vfsops.c
--- a/sys/fs/union/union_vfsops.c       Fri Nov 04 10:51:16 2022 +0000
+++ b/sys/fs/union/union_vfsops.c       Fri Nov 04 11:20:39 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: union_vfsops.c,v 1.83 2022/09/12 13:11:41 christos Exp $       */
+/*     $NetBSD: union_vfsops.c,v 1.84 2022/11/04 11:20:39 hannken Exp $        */
 
 /*
  * Copyright (c) 1994 The Regents of the University of California.
@@ -77,7 +77,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: union_vfsops.c,v 1.83 2022/09/12 13:11:41 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: union_vfsops.c,v 1.84 2022/11/04 11:20:39 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -244,7 +244,9 @@
 
        mp->mnt_data = um;
        vfs_getnewfsid(mp);
-       mp->mnt_lower = um->um_uppervp->v_mount;
+       error = vfs_set_lowermount(mp, um->um_uppervp->v_mount);
+       if (error)
+               goto bad;
 
        error = set_statvfs_info(path, UIO_USERSPACE, NULL, UIO_USERSPACE,
            mp->mnt_op->vfs_name, mp, l);
diff -r c80e3c206e19 -r 32c924a91348 sys/kern/vfs_mount.c
--- a/sys/kern/vfs_mount.c      Fri Nov 04 10:51:16 2022 +0000
+++ b/sys/kern/vfs_mount.c      Fri Nov 04 11:20:39 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_mount.c,v 1.98 2022/10/26 23:39:10 riastradh Exp $ */
+/*     $NetBSD: vfs_mount.c,v 1.99 2022/11/04 11:20:39 hannken Exp $   */
 
 /*-
  * Copyright (c) 1997-2020 The NetBSD Foundation, Inc.
@@ -67,7 +67,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.98 2022/10/26 23:39:10 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_mount.c,v 1.99 2022/11/04 11:20:39 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/kernel.h>
@@ -391,6 +391,37 @@
        vfs_rele(mp);
 }
 
+/*
+ * Change a file systems lower mount.
+ * Both the current and the new lower mount may be NULL.  The caller
+ * guarantees exclusive access to the mount and holds a pre-existing
+ * reference to the new lower mount.
+ */
+int
+vfs_set_lowermount(struct mount *mp, struct mount *lowermp)
+{
+       struct mount *oldlowermp;
+       int error;
+
+       if (lowermp) {
+               error = vfs_busy(lowermp);
+               if (error)
+                       return error;
+               vfs_ref(lowermp);
+       }
+
+       oldlowermp = mp->mnt_lower;
+       mp->mnt_lower = lowermp;
+
+       if (lowermp)
+               vfs_unbusy(lowermp);
+
+       if (oldlowermp)
+               vfs_rele(oldlowermp);
+
+       return 0;
+}
+
 struct vnode_iterator {
        vnode_impl_t vi_vnode;
 };
@@ -874,6 +905,7 @@
        mutex_exit(mp->mnt_updating);
        if (error2 == 0)
                vfs_resume(mp);
+       vfs_set_lowermount(mp, NULL);
        vfs_rele(mp);
 
        return error;
@@ -959,6 +991,7 @@
                panic("unmount: dangling vnode");
        vfs_hooks_unmount(mp);
 
+       vfs_set_lowermount(mp, NULL);
        vfs_rele(mp);   /* reference from mount() */
        if (coveredvp != NULLVP) {
                vrele(coveredvp);
diff -r c80e3c206e19 -r 32c924a91348 sys/kern/vfs_trans.c
--- a/sys/kern/vfs_trans.c      Fri Nov 04 10:51:16 2022 +0000
+++ b/sys/kern/vfs_trans.c      Fri Nov 04 11:20:39 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: vfs_trans.c,v 1.69 2022/10/26 23:39:43 riastradh Exp $ */
+/*     $NetBSD: vfs_trans.c,v 1.70 2022/11/04 11:20:39 hannken Exp $   */
 
 /*-
  * Copyright (c) 2007, 2020 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.69 2022/10/26 23:39:43 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: vfs_trans.c,v 1.70 2022/11/04 11:20:39 hannken Exp $");
 
 /*
  * File system transaction operations.
@@ -284,6 +284,8 @@
        KASSERT(fstrans_gone_count > 0);
        fstrans_gone_count -= 1;
 
+       KASSERT(fmi->fmi_mount->mnt_lower == NULL);
+
        kmem_free(fmi->fmi_mount, sizeof(*fmi->fmi_mount));
        kmem_free(fmi, sizeof(*fmi));
 }
@@ -473,8 +475,8 @@
         */
        for (fli = curlwp->l_fstrans; fli; fli = fli->fli_succ) {
                if (fli->fli_mount == mp) {
-                       KASSERT((mp->mnt_lower == NULL) ==
-                           (fli->fli_alias == NULL));
+                       KASSERT(mp->mnt_lower == NULL ||
+                           fli->fli_alias != NULL);
                        if (fli->fli_alias != NULL)
                                fli = fli->fli_alias;
                        break;
diff -r c80e3c206e19 -r 32c924a91348 sys/miscfs/nullfs/null_vfsops.c
--- a/sys/miscfs/nullfs/null_vfsops.c   Fri Nov 04 10:51:16 2022 +0000
+++ b/sys/miscfs/nullfs/null_vfsops.c   Fri Nov 04 11:20:39 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: null_vfsops.c,v 1.99 2020/04/13 19:23:19 ad Exp $      */
+/*     $NetBSD: null_vfsops.c,v 1.100 2022/11/04 11:20:39 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.99 2020/04/13 19:23:19 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: null_vfsops.c,v 1.100 2022/11/04 11:20:39 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -146,7 +146,12 @@
         * that the node create call will work.
         */
        vfs_getnewfsid(mp);
-       mp->mnt_lower = lowerrootvp->v_mount;
+       error = vfs_set_lowermount(mp, lowerrootvp->v_mount);
+       if (error) {
+               vput(lowerrootvp);
+               kmem_free(nmp, sizeof(struct null_mount));
+               return error;
+       }
 
        nmp->nullm_size = sizeof(struct null_node);
        nmp->nullm_tag = VT_NULL;
diff -r c80e3c206e19 -r 32c924a91348 sys/miscfs/overlay/overlay_vfsops.c
--- a/sys/miscfs/overlay/overlay_vfsops.c       Fri Nov 04 10:51:16 2022 +0000
+++ b/sys/miscfs/overlay/overlay_vfsops.c       Fri Nov 04 11:20:39 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: overlay_vfsops.c,v 1.72 2022/07/08 07:43:48 hannken Exp $      */
+/*     $NetBSD: overlay_vfsops.c,v 1.73 2022/11/04 11:20:39 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.72 2022/07/08 07:43:48 hannken Exp $");
+__KERNEL_RCSID(0, "$NetBSD: overlay_vfsops.c,v 1.73 2022/11/04 11:20:39 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -153,7 +153,12 @@
         * that the node create call will work.
         */
        vfs_getnewfsid(mp);
-       mp->mnt_lower = lowerrootvp->v_mount;
+       error = vfs_set_lowermount(mp, lowerrootvp->v_mount);
+       if (error) {
+               vput(lowerrootvp);
+               kmem_free(nmp, sizeof(struct overlay_mount));
+               return error;
+       }
 
        nmp->ovm_size = sizeof (struct overlay_node);
        nmp->ovm_tag = VT_OVERLAY;
diff -r c80e3c206e19 -r 32c924a91348 sys/miscfs/umapfs/umap_vfsops.c
--- a/sys/miscfs/umapfs/umap_vfsops.c   Fri Nov 04 10:51:16 2022 +0000
+++ b/sys/miscfs/umapfs/umap_vfsops.c   Fri Nov 04 11:20:39 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: umap_vfsops.c,v 1.103 2020/04/13 19:23:19 ad Exp $     */
+/*     $NetBSD: umap_vfsops.c,v 1.104 2022/11/04 11:20:40 hannken Exp $        */
 
 /*
  * Copyright (c) 1992, 1993
@@ -41,7 +41,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: umap_vfsops.c,v 1.103 2020/04/13 19:23:19 ad Exp $");
+__KERNEL_RCSID(0, "$NetBSD: umap_vfsops.c,v 1.104 2022/11/04 11:20:40 hannken Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -212,7 +212,12 @@
        log(LOG_DEBUG, "umapfs: using fsid %x/%x\n",
                mp->mnt_stat.f_fsidx.__fsid_val[0],
                mp->mnt_stat.f_fsidx.__fsid_val[1]);
-       mp->mnt_lower = lowerrootvp->v_mount;
+       error = vfs_set_lowermount(mp, lowerrootvp->v_mount);
+       if (error) {
+               vput(lowerrootvp);
+               kmem_free(amp, sizeof(struct umap_mount));
+               return error;
+       }
 
        amp->umapm_size = sizeof(struct umap_node);
        amp->umapm_tag = VT_UMAP;
diff -r c80e3c206e19 -r 32c924a91348 sys/sys/mount.h
--- a/sys/sys/mount.h   Fri Nov 04 10:51:16 2022 +0000
+++ b/sys/sys/mount.h   Fri Nov 04 11:20:39 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mount.h,v 1.239 2022/10/26 23:39:22 riastradh Exp $    */
+/*     $NetBSD: mount.h,v 1.240 2022/11/04 11:20:40 hannken Exp $      */
 
 /*
  * Copyright (c) 1989, 1991, 1993
@@ -393,6 +393,7 @@
 int    vfs_trybusy(struct mount *);
 int    vfs_rootmountalloc(const char *, const char *, struct mount **);
 void   vfs_unbusy(struct mount *);
+int    vfs_set_lowermount(struct mount *, struct mount *);
 int    vfs_attach(struct vfsops *);
 int    vfs_detach(struct vfsops *);
 void   vfs_reinit(void);



Home | Main Index | Thread Index | Old Index