git: 82397d791966 - main - vfs: denote vnode being a mount point with VIRF_MOUNTPOINT

Mateusz Guzik mjg at FreeBSD.org
Sun Jan 3 06:53:12 UTC 2021


The branch main has been updated by mjg:

URL: https://cgit.FreeBSD.org/src/commit/?id=82397d791966b09d344251bc709cd9db2b3a1902

commit 82397d791966b09d344251bc709cd9db2b3a1902
Author:     Mateusz Guzik <mjg at FreeBSD.org>
AuthorDate: 2021-01-01 03:10:12 +0000
Commit:     Mateusz Guzik <mjg at FreeBSD.org>
CommitDate: 2021-01-03 06:50:06 +0000

    vfs: denote vnode being a mount point with VIRF_MOUNTPOINT
    
    Reviewed by:    kib (previous version)
    Differential Revision:  https://reviews.freebsd.org/D27794
---
 sys/contrib/openzfs/module/os/freebsd/spl/spl_vfs.c |  4 ++--
 sys/kern/vfs_cache.c                                | 13 +------------
 sys/kern/vfs_mount.c                                |  8 ++++++--
 sys/kern/vfs_mountroot.c                            |  9 ++++++++-
 sys/kern/vfs_subr.c                                 |  4 +++-
 sys/sys/vnode.h                                     |  1 +
 6 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/sys/contrib/openzfs/module/os/freebsd/spl/spl_vfs.c b/sys/contrib/openzfs/module/os/freebsd/spl/spl_vfs.c
index 991a11fe2baf..9e16c0029087 100644
--- a/sys/contrib/openzfs/module/os/freebsd/spl/spl_vfs.c
+++ b/sys/contrib/openzfs/module/os/freebsd/spl/spl_vfs.c
@@ -240,9 +240,9 @@ mount_snapshot(kthread_t *td, vnode_t **vpp, const char *fstype, char *fspath,
 #endif
 	VI_LOCK(vp);
 	vp->v_iflag &= ~VI_MOUNT;
-	VI_UNLOCK(vp);
-
+	vn_irflag_set_locked(vp, VIRF_MOUNTPOINT);
 	vp->v_mountedhere = mp;
+	VI_UNLOCK(vp);
 	/* Put the new filesystem on the mount list. */
 	mtx_lock(&mountlist_mtx);
 	TAILQ_INSERT_TAIL(&mountlist, mp, mnt_list);
diff --git a/sys/kern/vfs_cache.c b/sys/kern/vfs_cache.c
index 2773ed76036c..767b7136c580 100644
--- a/sys/kern/vfs_cache.c
+++ b/sys/kern/vfs_cache.c
@@ -4755,21 +4755,10 @@ cache_fplookup_cross_mount(struct cache_fpl *fpl)
 static bool
 cache_fplookup_is_mp(struct cache_fpl *fpl)
 {
-	struct mount *mp;
 	struct vnode *vp;
 
 	vp = fpl->tvp;
-
-	/*
-	 * Hack: while this is a union, the pointer tends to be NULL so save on
-	 * a branch.
-	 */
-	mp = atomic_load_ptr(&vp->v_mountedhere);
-	if (mp == NULL)
-		return (false);
-	if (vp->v_type == VDIR)
-		return (true);
-	return (false);
+	return ((vn_irflag_read(vp) & VIRF_MOUNTPOINT) != 0);
 }
 
 /*
diff --git a/sys/kern/vfs_mount.c b/sys/kern/vfs_mount.c
index b3555f0a43e5..b3870e46c5e9 100644
--- a/sys/kern/vfs_mount.c
+++ b/sys/kern/vfs_mount.c
@@ -1034,8 +1034,9 @@ vfs_domount_first(
 	cache_purge(vp);
 	VI_LOCK(vp);
 	vp->v_iflag &= ~VI_MOUNT;
-	VI_UNLOCK(vp);
+	vn_irflag_set_locked(vp, VIRF_MOUNTPOINT);
 	vp->v_mountedhere = mp;
+	VI_UNLOCK(vp);
 	/* Place the new filesystem at the end of the mount list. */
 	mtx_lock(&mountlist_mtx);
 	TAILQ_INSERT_TAIL(&mountlist, mp, mnt_list);
@@ -1881,8 +1882,11 @@ dounmount(struct mount *mp, int flags, struct thread *td)
 	mtx_unlock(&mountlist_mtx);
 	EVENTHANDLER_DIRECT_INVOKE(vfs_unmounted, mp, td);
 	if (coveredvp != NULL) {
+		VI_LOCK(coveredvp);
+		vn_irflag_unset_locked(coveredvp, VIRF_MOUNTPOINT);
 		coveredvp->v_mountedhere = NULL;
-		vn_seqc_write_end(coveredvp);
+		vn_seqc_write_end_locked(coveredvp);
+		VI_UNLOCK(coveredvp);
 		VOP_UNLOCK(coveredvp);
 		vdrop(coveredvp);
 	}
diff --git a/sys/kern/vfs_mountroot.c b/sys/kern/vfs_mountroot.c
index b07457693968..3b968fd19bbd 100644
--- a/sys/kern/vfs_mountroot.c
+++ b/sys/kern/vfs_mountroot.c
@@ -335,8 +335,9 @@ vfs_mountroot_shuffle(struct thread *td, struct mount *mpdevfs)
 
 	VI_LOCK(vporoot);
 	vporoot->v_iflag &= ~VI_MOUNT;
-	VI_UNLOCK(vporoot);
+	vn_irflag_unset_locked(vporoot, VIRF_MOUNTPOINT);
 	vporoot->v_mountedhere = NULL;
+	VI_UNLOCK(vporoot);
 	mporoot->mnt_flag &= ~MNT_ROOTFS;
 	mporoot->mnt_vnodecovered = NULL;
 	vput(vporoot);
@@ -393,11 +394,17 @@ vfs_mountroot_shuffle(struct thread *td, struct mount *mpdevfs)
 			vpdevfs = mpdevfs->mnt_vnodecovered;
 			if (vpdevfs != NULL) {
 				cache_purge(vpdevfs);
+				VI_LOCK(vpdevfs);
+				vn_irflag_unset_locked(vpdevfs, VIRF_MOUNTPOINT);
 				vpdevfs->v_mountedhere = NULL;
+				VI_UNLOCK(vpdevfs);
 				vrele(vpdevfs);
 			}
+			VI_LOCK(vp);
 			mpdevfs->mnt_vnodecovered = vp;
+			vn_irflag_set_locked(vp, VIRF_MOUNTPOINT);
 			vp->v_mountedhere = mpdevfs;
+			VI_UNLOCK(vp);
 			VOP_UNLOCK(vp);
 		} else
 			vput(vp);
diff --git a/sys/kern/vfs_subr.c b/sys/kern/vfs_subr.c
index 8896b542a499..680475c00d52 100644
--- a/sys/kern/vfs_subr.c
+++ b/sys/kern/vfs_subr.c
@@ -4042,7 +4042,9 @@ vn_printf(struct vnode *vp, const char *fmt, ...)
 		strlcat(buf, "|VIRF_DOOMED", sizeof(buf));
 	if (irflag & VIRF_PGREAD)
 		strlcat(buf, "|VIRF_PGREAD", sizeof(buf));
-	flags = irflag & ~(VIRF_DOOMED | VIRF_PGREAD);
+	if (irflag & VIRF_MOUNTPOINT)
+		strlcat(buf, "|VIRF_MOUNTPOINT", sizeof(buf));
+	flags = irflag & ~(VIRF_DOOMED | VIRF_PGREAD | VIRF_MOUNTPOINT);
 	if (flags != 0) {
 		snprintf(buf2, sizeof(buf2), "|VIRF(0x%lx)", flags);
 		strlcat(buf, buf2, sizeof(buf));
diff --git a/sys/sys/vnode.h b/sys/sys/vnode.h
index 107cf45f9602..9be22f02e8d4 100644
--- a/sys/sys/vnode.h
+++ b/sys/sys/vnode.h
@@ -246,6 +246,7 @@ struct xvnode {
 #define	VIRF_DOOMED	0x0001	/* This vnode is being recycled */
 #define	VIRF_PGREAD	0x0002	/* Direct reads from the page cache are permitted,
 				   never cleared once set */
+#define	VIRF_MOUNTPOINT	0x0004	/* This vnode is mounted on */
 
 #define	VI_TEXT_REF	0x0001	/* Text ref grabbed use ref */
 #define	VI_MOUNT	0x0002	/* Mount in progress */


More information about the dev-commits-src-all mailing list