Module Name: src Committed By: hannken Date: Fri Nov 4 11:20:40 UTC 2022
Modified Files: src/external/cddl/osnet/dist/uts/common/fs/zfs: zfs_ctldir.c src/sys/fs/union: union_vfsops.c 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 src/sys/sys: mount.h Log Message: Add a helper to set or clear lower mount and use it. Always add a reference to the lower mount. Ride 9.99.105 To generate a diff of this commit: cvs rdiff -u -r1.13 -r1.14 \ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c cvs rdiff -u -r1.83 -r1.84 src/sys/fs/union/union_vfsops.c cvs rdiff -u -r1.98 -r1.99 src/sys/kern/vfs_mount.c cvs rdiff -u -r1.69 -r1.70 src/sys/kern/vfs_trans.c cvs rdiff -u -r1.99 -r1.100 src/sys/miscfs/nullfs/null_vfsops.c cvs rdiff -u -r1.72 -r1.73 src/sys/miscfs/overlay/overlay_vfsops.c cvs rdiff -u -r1.103 -r1.104 src/sys/miscfs/umapfs/umap_vfsops.c cvs rdiff -u -r1.239 -r1.240 src/sys/sys/mount.h Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c diff -u src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.13 src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.14 --- src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c:1.13 Sun Jul 4 11:25:07 2021 +++ src/external/cddl/osnet/dist/uts/common/fs/zfs/zfs_ctldir.c Fri Nov 4 11:20:39 2022 @@ -1343,7 +1343,9 @@ sfs_snapshot_mount(vnode_t *vp, const ch 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); Index: src/sys/fs/union/union_vfsops.c diff -u src/sys/fs/union/union_vfsops.c:1.83 src/sys/fs/union/union_vfsops.c:1.84 --- src/sys/fs/union/union_vfsops.c:1.83 Mon Sep 12 13:11:41 2022 +++ src/sys/fs/union/union_vfsops.c Fri Nov 4 11:20:39 2022 @@ -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 @@ union_mount(struct mount *mp, const char 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); Index: src/sys/kern/vfs_mount.c diff -u src/sys/kern/vfs_mount.c:1.98 src/sys/kern/vfs_mount.c:1.99 --- src/sys/kern/vfs_mount.c:1.98 Wed Oct 26 23:39:10 2022 +++ src/sys/kern/vfs_mount.c Fri Nov 4 11:20:39 2022 @@ -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_unbusy(struct mount *mp) 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 @@ err_mounted: 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 @@ dounmount(struct mount *mp, int flags, s panic("unmount: dangling vnode"); vfs_hooks_unmount(mp); + vfs_set_lowermount(mp, NULL); vfs_rele(mp); /* reference from mount() */ if (coveredvp != NULLVP) { vrele(coveredvp); Index: src/sys/kern/vfs_trans.c diff -u src/sys/kern/vfs_trans.c:1.69 src/sys/kern/vfs_trans.c:1.70 --- src/sys/kern/vfs_trans.c:1.69 Wed Oct 26 23:39:43 2022 +++ src/sys/kern/vfs_trans.c Fri Nov 4 11:20:39 2022 @@ -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 @@ fstrans_mount_dtor(struct fstrans_mount_ 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 @@ fstrans_get_lwp_info(struct mount *mp, b */ 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; Index: src/sys/miscfs/nullfs/null_vfsops.c diff -u src/sys/miscfs/nullfs/null_vfsops.c:1.99 src/sys/miscfs/nullfs/null_vfsops.c:1.100 --- src/sys/miscfs/nullfs/null_vfsops.c:1.99 Mon Apr 13 19:23:19 2020 +++ src/sys/miscfs/nullfs/null_vfsops.c Fri Nov 4 11:20:39 2022 @@ -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 @@ nullfs_mount(struct mount *mp, const cha * 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; Index: src/sys/miscfs/overlay/overlay_vfsops.c diff -u src/sys/miscfs/overlay/overlay_vfsops.c:1.72 src/sys/miscfs/overlay/overlay_vfsops.c:1.73 --- src/sys/miscfs/overlay/overlay_vfsops.c:1.72 Fri Jul 8 07:43:48 2022 +++ src/sys/miscfs/overlay/overlay_vfsops.c Fri Nov 4 11:20:39 2022 @@ -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 @@ ov_mount(struct mount *mp, const char *p * 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; Index: src/sys/miscfs/umapfs/umap_vfsops.c diff -u src/sys/miscfs/umapfs/umap_vfsops.c:1.103 src/sys/miscfs/umapfs/umap_vfsops.c:1.104 --- src/sys/miscfs/umapfs/umap_vfsops.c:1.103 Mon Apr 13 19:23:19 2020 +++ src/sys/miscfs/umapfs/umap_vfsops.c Fri Nov 4 11:20:40 2022 @@ -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 @@ umapfs_mount(struct mount *mp, const cha 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; Index: src/sys/sys/mount.h diff -u src/sys/sys/mount.h:1.239 src/sys/sys/mount.h:1.240 --- src/sys/sys/mount.h:1.239 Wed Oct 26 23:39:22 2022 +++ src/sys/sys/mount.h Fri Nov 4 11:20:40 2022 @@ -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_busy(struct mount *); 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);