From nobody Thu Oct 27 00:24:33 2022 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4MyRJK2Rvzz4gW2H; Thu, 27 Oct 2022 00:24:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4MyRJK1v6lz4PVw; Thu, 27 Oct 2022 00:24:33 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666830273; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+XWuuBMAsyCSeBDi0l/Fu5XJRkSjUm63UHqf9bLktkI=; b=VCe2yckAFNMYxSZqeB9S+p2kUjOkRUdR8DsIeTAy5jJjLCp02SS8mcqZ1R2FPf/BU4kIs8 gXNubq5uTTBqnz5WUTVDjKNeGxzQOxFiOYGayUr7JUJ8rHXP0FFVgBY0c+WSGkrNiX1hQU Y/oBL2ksfh/s0Ex30ng4Lwg3s9SoIeIdOKtmQGZV7r07YiK5dk/KNANKHFeCEt4LiupIY9 WUytVZe+C7lzDrLGpYLCm+T324oinyIfOM0bozvTpzmtfNfuXTKkmI6jg4LRwXudLD/pEN F02gRc50Yq8JzAU+MqCWMDM/9ZI45yqwoMHPZEa4c8DGYr4OEIkbxd0BowamaA== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4MyRJK0jn4zcl7; Thu, 27 Oct 2022 00:24:33 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 29R0OXVx033594; Thu, 27 Oct 2022 00:24:33 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 29R0OXox033593; Thu, 27 Oct 2022 00:24:33 GMT (envelope-from git) Date: Thu, 27 Oct 2022 00:24:33 GMT Message-Id: <202210270024.29R0OXox033593@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Jason A. Harmening" Subject: git: f7833196bd6b - main - vfs_lookup(): Minor performance optimizations List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jah X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: f7833196bd6ba9bfc060a41b353422b15d6aa95b Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1666830273; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=+XWuuBMAsyCSeBDi0l/Fu5XJRkSjUm63UHqf9bLktkI=; b=v2ws/rfgvEUfewZpuSePU+nmh4s9zX7HN+9Ch+SdlU3fYZTpPlZw5Ind6L5xJzmtU7RFT1 UaIYajkhsT2K+D136hfB5dcOl7WS2i9RoC4wV5CaFdj6vJMt1s+Sbtdd5RqJL1aj+DgAa0 9E2MuBo46QmKtVIiuMInsPe/K7ejfSewJiyuF6EvG0jvCPvRDK/P+zUVTVL1U/Kg+6e0QB 6TjaCwMhpAnGOf+8mhqvCzG5S9nln1MzBn37CXc2MaHuXydSO4jxGB3BpyhpuP0VcX0b2l nkOj+3YXo+7RbDAw3E+eAe8uvFSePrVXjbG9+tIiuaENSon+UoigueSrLInk7Q== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1666830273; a=rsa-sha256; cv=none; b=q0g6RBOSr60Hfgn0kDiBITehMzyMpKbdB7aUbbA7UJO/HPUmjWY+Cn2YhvypECBka48l7h +pUr7uVLeq7jiatJRZurTwjg5PKqzk6Dt4H+M/mYZZkd0m1GsIfI3Y/lIb2niJVmdSeA+k xZFHTfSswcxsTo8PkeMDLcMkApMppqnK3mRYjl2mAOwDxuOV2RrjCs7rwRrfwaKE1tjvee V5hv88Qnw+jgTmuz3SQyJU1qzLd5hOCF9K4I+seSDt1E5VAbuRfOEQmHryJ+/xsV3UhtrG vrfniGz7wnqqWoysHwUEsbaupcCDg1394kOR/23HVuq8rN+g7jyS8RKHqFLZPg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jah: URL: https://cgit.FreeBSD.org/src/commit/?id=f7833196bd6ba9bfc060a41b353422b15d6aa95b commit f7833196bd6ba9bfc060a41b353422b15d6aa95b Author: Jason A. Harmening AuthorDate: 2022-10-20 03:33:19 +0000 Commit: Jason A. Harmening CommitDate: 2022-10-27 00:33:33 +0000 vfs_lookup(): Minor performance optimizations Refactor the symlink and mountpoint traversal logic to avoid repeatedly checking the vnode type; a symlink cannot be a mountpoint and vice versa. Avoid repeatedly checking cn_flags for NOCROSSMOUNT and simplify the check which determines whether the vnode is a mountpoint. Suggested by: mjg Reviewed by: kib Tested by: pho Differential Revision: https://reviews.freebsd.org/D35054 --- sys/kern/vfs_lookup.c | 74 ++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 34 deletions(-) diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c index 318dcf6fb72b..cc41849de532 100644 --- a/sys/kern/vfs_lookup.c +++ b/sys/kern/vfs_lookup.c @@ -1221,12 +1221,47 @@ good: #endif dp = ndp->ni_vp; + /* + * Check for symbolic link + */ + if ((dp->v_type == VLNK) && + ((cnp->cn_flags & FOLLOW) || (cnp->cn_flags & TRAILINGSLASH) || + *ndp->ni_next == '/')) { + cnp->cn_flags |= ISSYMLINK; + if (VN_IS_DOOMED(dp)) { + /* + * We can't know whether the directory was mounted with + * NOSYMFOLLOW, so we can't follow safely. + */ + error = ENOENT; + goto bad2; + } + if (dp->v_mount->mnt_flag & MNT_NOSYMFOLLOW) { + error = EACCES; + goto bad2; + } + /* + * Symlink code always expects an unlocked dvp. + */ + if (ndp->ni_dvp != ndp->ni_vp) { + VOP_UNLOCK(ndp->ni_dvp); + ni_dvp_unlocked = 1; + } + goto success; + } else if ((vn_irflag_read(dp) & VIRF_MOUNTPOINT) != 0) { + if ((cnp->cn_flags & NOCROSSMOUNT) != 0) + goto nextname; + } else + goto nextname; + /* * Check to see if the vnode has been mounted on; * if so find the root of the mounted filesystem. */ - while (dp->v_type == VDIR && (mp = dp->v_mountedhere) && - (cnp->cn_flags & NOCROSSMOUNT) == 0) { + do { + mp = dp->v_mountedhere; + KASSERT(mp != NULL, + ("%s: NULL mountpoint for VIRF_MOUNTPOINT vnode", __func__)); crosslock = (dp->v_vflag & VV_CROSSLOCK) != 0; crosslkflags = compute_cn_lkflags(mp, cnp->cn_lkflags, cnp->cn_flags); @@ -1239,7 +1274,7 @@ good: goto bad2; } } - if (vfs_busy(mp, 0)) + if (vfs_busy(mp, 0) != 0) continue; if (__predict_true(!crosslock)) vput(dp); @@ -1255,41 +1290,12 @@ good: vput(dp); if (vn_lock(vp_crossmp, LK_SHARED | LK_NOWAIT)) panic("vp_crossmp exclusively locked or reclaimed"); - if (error) { + if (error != 0) { dpunlocked = 1; goto bad2; } ndp->ni_vp = dp = tdp; - } - - /* - * Check for symbolic link - */ - if ((dp->v_type == VLNK) && - ((cnp->cn_flags & FOLLOW) || (cnp->cn_flags & TRAILINGSLASH) || - *ndp->ni_next == '/')) { - cnp->cn_flags |= ISSYMLINK; - if (VN_IS_DOOMED(dp)) { - /* - * We can't know whether the directory was mounted with - * NOSYMFOLLOW, so we can't follow safely. - */ - error = ENOENT; - goto bad2; - } - if (dp->v_mount->mnt_flag & MNT_NOSYMFOLLOW) { - error = EACCES; - goto bad2; - } - /* - * Symlink code always expects an unlocked dvp. - */ - if (ndp->ni_dvp != ndp->ni_vp) { - VOP_UNLOCK(ndp->ni_dvp); - ni_dvp_unlocked = 1; - } - goto success; - } + } while ((vn_irflag_read(dp) & VIRF_MOUNTPOINT) != 0); nextname: /*