Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 6 Oct 2019 22:16:00 +0000 (UTC)
From:      Mateusz Guzik <mjg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r353151 - in head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs: . sys
Message-ID:  <201910062216.x96MG070085756@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: mjg
Date: Sun Oct  6 22:16:00 2019
New Revision: 353151
URL: https://svnweb.freebsd.org/changeset/base/353151

Log:
  zfs: add root vnode caching
  
  This replaces the approach added in r338927.
  
  See r353150.
  
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_vfsops.h
  head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vfsops.c

Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_vfsops.h
==============================================================================
--- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_vfsops.h	Sun Oct  6 22:14:32 2019	(r353150)
+++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/sys/zfs_vfsops.h	Sun Oct  6 22:16:00 2019	(r353151)
@@ -46,8 +46,6 @@ struct zfsvfs {
 	zfsvfs_t	*z_parent;	/* parent fs */
 	objset_t	*z_os;		/* objset reference */
 	uint64_t	z_root;		/* id of root znode */
-	struct vnode	*z_rootvnode;	/* root vnode */
-	struct rmlock	z_rootvnodelock;/* protection for root vnode */
 	uint64_t	z_unlinkedobj;	/* id of unlinked zapobj */
 	uint64_t	z_max_blksz;	/* maximum block size for files */
 	uint64_t	z_fuid_obj;	/* fuid table object number */

Modified: head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vfsops.c
==============================================================================
--- head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vfsops.c	Sun Oct  6 22:14:32 2019	(r353150)
+++ head/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_vfsops.c	Sun Oct  6 22:16:00 2019	(r353151)
@@ -65,7 +65,6 @@
 #include <sys/spa_boot.h>
 #include <sys/jail.h>
 #include <ufs/ufs/quota.h>
-#include <sys/rmlock.h>
 
 #include "zfs_comutil.h"
 
@@ -93,9 +92,6 @@ static int zfs_version_zpl = ZPL_VERSION;
 SYSCTL_INT(_vfs_zfs_version, OID_AUTO, zpl, CTLFLAG_RD, &zfs_version_zpl, 0,
     "ZPL_VERSION");
 
-static int zfs_root_setvnode(zfsvfs_t *zfsvfs);
-static void zfs_root_dropvnode(zfsvfs_t *zfsvfs);
-
 static int zfs_quotactl(vfs_t *vfsp, int cmds, uid_t id, void *arg);
 static int zfs_mount(vfs_t *vfsp);
 static int zfs_umount(vfs_t *vfsp, int fflag);
@@ -112,7 +108,8 @@ static void zfs_freevfs(vfs_t *vfsp);
 struct vfsops zfs_vfsops = {
 	.vfs_mount =		zfs_mount,
 	.vfs_unmount =		zfs_umount,
-	.vfs_root =		zfs_root,
+	.vfs_root =		vfs_cache_root,
+	.vfs_cachedroot =	zfs_root,
 	.vfs_statfs =		zfs_statfs,
 	.vfs_vget =		zfs_vget,
 	.vfs_sync =		zfs_sync,
@@ -1213,8 +1210,6 @@ zfsvfs_create_impl(zfsvfs_t **zfvp, zfsvfs_t *zfsvfs, 
 	for (int i = 0; i != ZFS_OBJ_MTX_SZ; i++)
 		mutex_init(&zfsvfs->z_hold_mtx[i], NULL, MUTEX_DEFAULT, NULL);
 
-	rm_init(&zfsvfs->z_rootvnodelock, "zfs root vnode lock");
-
 	error = zfsvfs_init(zfsvfs, os);
 	if (error != 0) {
 		*zfvp = NULL;
@@ -1321,8 +1316,6 @@ zfsvfs_free(zfsvfs_t *zfsvfs)
 	rw_enter(&zfsvfs_lock, RW_READER);
 	rw_exit(&zfsvfs_lock);
 
-	rm_destroy(&zfsvfs->z_rootvnodelock);
-
 	zfs_fuid_destroy(zfsvfs);
 
 	mutex_destroy(&zfsvfs->z_znodes_lock);
@@ -1929,9 +1922,6 @@ zfs_mount(vfs_t *vfsp)
 	error = zfs_domount(vfsp, osname);
 	PICKUP_GIANT();
 
-	if (error == 0)
-		zfs_root_setvnode((zfsvfs_t *)vfsp->vfs_data);
-
 #ifdef illumos
 	/*
 	 * Add an extra VFS_HOLD on our parent vfs so that it can't
@@ -2004,65 +1994,14 @@ zfs_statfs(vfs_t *vfsp, struct statfs *statp)
 }
 
 static int
-zfs_root_setvnode(zfsvfs_t *zfsvfs)
-{
-	znode_t *rootzp;
-	int error;
-
-	ZFS_ENTER(zfsvfs);
-	error = zfs_zget(zfsvfs, zfsvfs->z_root, &rootzp);
-	if (error != 0)
-		panic("could not zfs_zget for root vnode");
-	ZFS_EXIT(zfsvfs);
-
-	rm_wlock(&zfsvfs->z_rootvnodelock);
-	if (zfsvfs->z_rootvnode != NULL)
-		panic("zfs mount point already has a root vnode: %p\n",
-		    zfsvfs->z_rootvnode);
-	zfsvfs->z_rootvnode = ZTOV(rootzp);
-	rm_wunlock(&zfsvfs->z_rootvnodelock);
-	return (0);
-}
-
-static void
-zfs_root_putvnode(zfsvfs_t *zfsvfs)
-{
-	struct vnode *vp;
-
-	rm_wlock(&zfsvfs->z_rootvnodelock);
-	vp = zfsvfs->z_rootvnode;
-	zfsvfs->z_rootvnode = NULL;
-	rm_wunlock(&zfsvfs->z_rootvnodelock);
-	if (vp != NULL)
-		vrele(vp);
-}
-
-static int
 zfs_root(vfs_t *vfsp, int flags, vnode_t **vpp)
 {
-	struct rm_priotracker tracker;
 	zfsvfs_t *zfsvfs = vfsp->vfs_data;
 	znode_t *rootzp;
 	int error;
 
-	rm_rlock(&zfsvfs->z_rootvnodelock, &tracker);
-	*vpp = zfsvfs->z_rootvnode;
-	if (*vpp != NULL && (((*vpp)->v_iflag & VI_DOOMED) == 0)) {
-		vrefact(*vpp);
-		rm_runlock(&zfsvfs->z_rootvnodelock, &tracker);
-		goto lock;
-	}
-	rm_runlock(&zfsvfs->z_rootvnodelock, &tracker);
-
-	/*
-	 * We found the vnode but did not like it.
-	 */
-	if (*vpp != NULL) {
-		*vpp = NULL;
-		zfs_root_putvnode(zfsvfs);
-	}
-
 	ZFS_ENTER(zfsvfs);
+
 	error = zfs_zget(zfsvfs, zfsvfs->z_root, &rootzp);
 	if (error == 0)
 		*vpp = ZTOV(rootzp);
@@ -2070,7 +2009,6 @@ zfs_root(vfs_t *vfsp, int flags, vnode_t **vpp)
 	ZFS_EXIT(zfsvfs);
 
 	if (error == 0) {
-lock:
 		error = vn_lock(*vpp, flags);
 		if (error != 0) {
 			VN_RELE(*vpp);
@@ -2188,8 +2126,6 @@ zfs_umount(vfs_t *vfsp, int fflag)
 	objset_t *os;
 	cred_t *cr = td->td_ucred;
 	int ret;
-
-	zfs_root_putvnode(zfsvfs);
 
 	ret = secpolicy_fs_unmount(cr, vfsp);
 	if (ret) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201910062216.x96MG070085756>