From nobody Thu Mar 24 14:36:35 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 CC21F1A2FB59; Thu, 24 Mar 2022 14:36:35 +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 4KPSTb5P1lz3tp4; Thu, 24 Mar 2022 14:36:35 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648132595; 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=zYKHxdyivSeNuj/lgsgC13vMHaVLtjuI8pNs1PaZOak=; b=lDgFk4807Qh/9cwfIvmGsjwhQ+1GY+BFCXf1vuhqwRIoZANDUgN6ls3CoNuB/2yueejJq5 ZOgpc4W/JkO67hvczXu9Zad8k0VL19ZTGIibJ903mSJpHp+c3oxY6pdseGr43v6WOamlMz rRvWsXdP/O5oQGQRiW7CfNwn2j7EjwdedFMcQd6XN+6SSfBDEdtMlPJvbRbPimGP+YwgN5 GJ2bI/35ExesNmsxz605XCVMs6sMoKMpVS+P33pFJ3wqC+cgCsejPicz0PDqGvY2pu65FZ pL2pFowm58JsAtJJoGZXGeaWLS97OO8m6h1zhfw+0E50TG0HQ+eaLMgVA4qjGw== 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 9993E19861; Thu, 24 Mar 2022 14:36:35 +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 22OEaZZg040930; Thu, 24 Mar 2022 14:36:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 22OEaZev040929; Thu, 24 Mar 2022 14:36:35 GMT (envelope-from git) Date: Thu, 24 Mar 2022 14:36:35 GMT Message-Id: <202203241436.22OEaZev040929@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mateusz Guzik Subject: git: 4ef6e56ae807 - main - vfs: hoist trailing slash handling out of the loop 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: mjg X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 4ef6e56ae80782e4242cc1a32abfd5b0cd541955 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1648132595; 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=zYKHxdyivSeNuj/lgsgC13vMHaVLtjuI8pNs1PaZOak=; b=vb4TKxrNU0ODw0Aplb5niVgvgpMMuER3SNi1+lJO5y6AkZXQ6A5qxeOnKtYj1VTTG6gh2y uGU31OOrOCLB7/TtqrdQt6NfDbni4btwv1IK0VC9zIPuncmjmrwggrnXLHCZEOR2qLPThR Jez8yLoBGDNySby4vDRsvNA3WJMVJRcNdXVy9UpINMZApko7t7PLtmJFsd1DEOiROc2Q+4 +ifCLPTAhM4Lk44Hg3n4Ukz7rn5YCt/aBK0lXt1VGS1ZGUtq7pnWY32g67iYWNKeUbxQ/s HJmK+8q7EMS7RsPUKGEcRBuBaCv7uI2QQM/+PcZI6NZ3x2gMiTlwsxHF22ISTQ== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1648132595; a=rsa-sha256; cv=none; b=MYM2c5ZKN3hHU0uAQC9d3TBzm9UHdb/VWd45N/UDayqIyj6zOxXso7Bk7W7MLismDfhTqk vQgJk6/Tmm+AUdPT2O6hdP6hEngfQ0iWjLCAbbCx5EE7Cm/O/Zdv4EJTfP2cjHQCBt+NU8 RwYxln3IPMar8bX1pxE2Z63l97exzwqBzbALzbRfu9lk16shH00b/e4UAeneRyp807FIND Pxnp4LSPQnA+4jOzHlglR+TUpBZk94s/pSbMkwaaA6ENdl8fYgONQ5HTjl8hWendqaB3j6 sgoqnmlUjqOWfh4REdfjmC5G+XwUk45EAsRY6n3BoIDnDBw2L5wUQOUkmAtOUg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by mjg: URL: https://cgit.FreeBSD.org/src/commit/?id=4ef6e56ae80782e4242cc1a32abfd5b0cd541955 commit 4ef6e56ae80782e4242cc1a32abfd5b0cd541955 Author: Mateusz Guzik AuthorDate: 2022-03-24 13:17:31 +0000 Commit: Mateusz Guzik CommitDate: 2022-03-24 14:36:31 +0000 vfs: hoist trailing slash handling out of the loop --- sys/kern/vfs_lookup.c | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c index 8b4ceecce462..71173d189ef2 100644 --- a/sys/kern/vfs_lookup.c +++ b/sys/kern/vfs_lookup.c @@ -940,6 +940,7 @@ vfs_lookup(struct nameidata *ndp) char *cp; /* pointer into pathname argument */ char *prev_ni_next; /* saved ndp->ni_next */ char *nulchar; /* location of '\0' in cn_pnbuf */ + char *lastchar; /* location of the last character */ struct vnode *dp = NULL; /* the directory we are searching */ struct vnode *tdp; /* saved dp */ struct mount *mp; /* mount table entry */ @@ -1001,6 +1002,28 @@ vfs_lookup(struct nameidata *ndp) goto bad_unlocked; } + /* + * Nul-out trailing slashes (e.g., "foo///" -> "foo"). + * + * This must be done before VOP_LOOKUP() because some fs's don't know + * about trailing slashes. Remember if there were trailing slashes to + * handle symlinks, existing non-directories and non-existing files + * that won't be directories specially later. + */ + MPASS(ndp->ni_pathlen >= 2); + lastchar = &cnp->cn_nameptr[ndp->ni_pathlen - 2]; + if (*lastchar == '/') { + while (lastchar >= cnp->cn_pnbuf) { + *lastchar = '\0'; + lastchar--; + ndp->ni_pathlen--; + if (*lastchar != '/') { + break; + } + } + cnp->cn_flags |= TRAILINGSLASH; + } + /* * We use shared locks until we hit the parent of the last cn then * we adjust based on the requesting flags. @@ -1052,23 +1075,6 @@ dirloop: prev_ni_next = ndp->ni_next; ndp->ni_next = cp; - /* - * Replace multiple slashes by a single slash and trailing slashes - * by a null. This must be done before VOP_LOOKUP() because some - * fs's don't know about trailing slashes. Remember if there were - * trailing slashes to handle symlinks, existing non-directories - * and non-existing files that won't be directories specially later. - */ - while (*cp == '/' && (cp[1] == '/' || cp[1] == '\0')) { - cp++; - ndp->ni_pathlen--; - if (*cp == '\0') { - *ndp->ni_next = '\0'; - cnp->cn_flags |= TRAILINGSLASH; - } - } - ndp->ni_next = cp; - cnp->cn_flags |= MAKEENTRY; if (*cp == '\0' && docache == 0) cnp->cn_flags &= ~MAKEENTRY;