From owner-svn-src-stable@freebsd.org Wed Oct 4 07:37:37 2017 Return-Path: Delivered-To: svn-src-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5DBDBE311A8; Wed, 4 Oct 2017 07:37:37 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 37BEE7563D; Wed, 4 Oct 2017 07:37:37 +0000 (UTC) (envelope-from avg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v947baxK099322; Wed, 4 Oct 2017 07:37:36 GMT (envelope-from avg@FreeBSD.org) Received: (from avg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v947baBf099321; Wed, 4 Oct 2017 07:37:36 GMT (envelope-from avg@FreeBSD.org) Message-Id: <201710040737.v947baBf099321@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: avg set sender to avg@FreeBSD.org using -f From: Andriy Gapon Date: Wed, 4 Oct 2017 07:37:36 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-11@freebsd.org Subject: svn commit: r324253 - stable/11/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-SVN-Group: stable-11 X-SVN-Commit-Author: avg X-SVN-Commit-Paths: stable/11/sys/cddl/contrib/opensolaris/uts/common/fs/zfs X-SVN-Commit-Revision: 324253 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-stable@freebsd.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: SVN commit messages for all the -stable branches of the src tree List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Oct 2017 07:37:37 -0000 Author: avg Date: Wed Oct 4 07:37:36 2017 New Revision: 324253 URL: https://svnweb.freebsd.org/changeset/base/324253 Log: MFC r323483: zfsctl_snapdir_lookup should be able to handle an uncovered vnode Modified: stable/11/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ctldir.c Directory Properties: stable/11/ (props changed) Modified: stable/11/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ctldir.c ============================================================================== --- stable/11/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ctldir.c Wed Oct 4 07:36:06 2017 (r324252) +++ stable/11/sys/cddl/contrib/opensolaris/uts/common/fs/zfs/zfs_ctldir.c Wed Oct 4 07:37:36 2017 (r324253) @@ -816,6 +816,12 @@ zfsctl_snapshot_vnode_setup(vnode_t *vp, void *arg) * Lookup entry point for the 'snapshot' directory. Try to open the * snapshot if it exist, creating the pseudo filesystem vnode as necessary. * Perform a mount of the associated dataset on top of the vnode. + * There are four possibilities: + * - the snapshot node and vnode do not exist + * - the snapshot vnode is covered by the mounted snapshot + * - the snapshot vnode is not covered yet, the mount operation is in progress + * - the snapshot vnode is not covered, because the snapshot has been unmounted + * The last two states are transient and should be relatively short-lived. */ int zfsctl_snapdir_lookup(ap) @@ -881,7 +887,7 @@ zfsctl_snapdir_lookup(ap) /* * The vnode must be referenced at least by this thread and - * the mounted snapshot or the thread doing the mounting. + * the mount point or the thread doing the mounting. * There can be more references from concurrent lookups. */ KASSERT(vrefcnt(*vpp) > 1, ("found unreferenced mountpoint")); @@ -893,22 +899,31 @@ zfsctl_snapdir_lookup(ap) if (err != EJUSTRETURN) return (err); -#ifdef INVARIANTS /* - * If the vnode not covered yet, then the mount operation - * must be in progress. + * If the vnode is not covered, then either the mount operation + * is in progress or the snapshot has already been unmounted + * but the vnode hasn't been inactivated and reclaimed yet. + * We can try to re-use the vnode in the latter case. */ VI_LOCK(*vpp); - KASSERT(((*vpp)->v_iflag & VI_MOUNT) != 0, - ("snapshot vnode not covered")); - VI_UNLOCK(*vpp); -#endif - vput(*vpp); + if (((*vpp)->v_iflag & VI_MOUNT) == 0) { + /* Upgrade to exclusive lock in order to: + * - avoid race conditions + * - satisfy the contract of mount_snapshot() + */ + err = VOP_LOCK(*vpp, LK_TRYUPGRADE | LK_INTERLOCK); + if (err == 0) + break; + } else { + VI_UNLOCK(*vpp); + } /* - * In this situation we can loop on uncontested locks and starve + * In this state we can loop on uncontested locks and starve * the thread doing the lengthy, non-trivial mount operation. + * So, yield to prevent that from happening. */ + vput(*vpp); kern_yield(PRI_USER); }