From owner-svn-src-head@freebsd.org Sat Feb 1 20:37:12 2020 Return-Path: Delivered-To: svn-src-head@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 8916422C214; Sat, 1 Feb 2020 20:37:12 +0000 (UTC) (envelope-from mjg@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4895Vc37HVz43Sw; Sat, 1 Feb 2020 20:37:12 +0000 (UTC) (envelope-from mjg@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 mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 66B324A95; Sat, 1 Feb 2020 20:37:12 +0000 (UTC) (envelope-from mjg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 011KbC3L051950; Sat, 1 Feb 2020 20:37:12 GMT (envelope-from mjg@FreeBSD.org) Received: (from mjg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 011KbCDT051949; Sat, 1 Feb 2020 20:37:12 GMT (envelope-from mjg@FreeBSD.org) Message-Id: <202002012037.011KbCDT051949@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mjg set sender to mjg@FreeBSD.org using -f From: Mateusz Guzik Date: Sat, 1 Feb 2020 20:37:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r357385 - head/sys/kern X-SVN-Group: head X-SVN-Commit-Author: mjg X-SVN-Commit-Paths: head/sys/kern X-SVN-Commit-Revision: 357385 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 01 Feb 2020 20:37:12 -0000 Author: mjg Date: Sat Feb 1 20:37:11 2020 New Revision: 357385 URL: https://svnweb.freebsd.org/changeset/base/357385 Log: cache: return the total length from vn_fullpath1 This removes strlen from getcwd. Modified: head/sys/kern/vfs_cache.c Modified: head/sys/kern/vfs_cache.c ============================================================================== --- head/sys/kern/vfs_cache.c Sat Feb 1 20:36:35 2020 (r357384) +++ head/sys/kern/vfs_cache.c Sat Feb 1 20:37:11 2020 (r357385) @@ -388,7 +388,7 @@ STATNODE_COUNTER(shrinking_skipped, static void cache_zap_locked(struct namecache *ncp, bool neg_locked); static int vn_fullpath1(struct thread *td, struct vnode *vp, struct vnode *rdir, - char *buf, char **retbuf, size_t buflen); + char *buf, char **retbuf, size_t *buflen); static MALLOC_DEFINE(M_VFSCACHE, "vfscache", "VFS name cache entries"); @@ -2198,15 +2198,15 @@ kern___getcwd(struct thread *td, char *buf, enum uio_s rdir = fdp->fd_rdir; vrefact(rdir); FILEDESC_SUNLOCK(fdp); - error = vn_fullpath1(td, cdir, rdir, tmpbuf, &bp, buflen); + error = vn_fullpath1(td, cdir, rdir, tmpbuf, &bp, &buflen); vrele(rdir); vrele(cdir); if (!error) { if (bufseg == UIO_SYSSPACE) - bcopy(bp, buf, strlen(bp) + 1); + bcopy(bp, buf, buflen); else - error = copyout(bp, buf, strlen(bp) + 1); + error = copyout(bp, buf, buflen); #ifdef KTRACE if (KTRPOINT(curthread, KTR_NAMEI)) ktrnamei(bp); @@ -2226,18 +2226,20 @@ vn_fullpath(struct thread *td, struct vnode *vn, char char *buf; struct filedesc *fdp; struct vnode *rdir; + size_t buflen; int error; if (__predict_false(vn == NULL)) return (EINVAL); - buf = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); + buflen = MAXPATHLEN; + buf = malloc(buflen, M_TEMP, M_WAITOK); fdp = td->td_proc->p_fd; FILEDESC_SLOCK(fdp); rdir = fdp->fd_rdir; vrefact(rdir); FILEDESC_SUNLOCK(fdp); - error = vn_fullpath1(td, vn, rdir, buf, retbuf, MAXPATHLEN); + error = vn_fullpath1(td, vn, rdir, buf, retbuf, &buflen); vrele(rdir); if (!error) @@ -2258,12 +2260,14 @@ vn_fullpath_global(struct thread *td, struct vnode *vn char **retbuf, char **freebuf) { char *buf; + size_t buflen; int error; if (__predict_false(vn == NULL)) return (EINVAL); - buf = malloc(MAXPATHLEN, M_TEMP, M_WAITOK); - error = vn_fullpath1(td, vn, rootvnode, buf, retbuf, MAXPATHLEN); + buflen = MAXPATHLEN; + buf = malloc(buflen, M_TEMP, M_WAITOK); + error = vn_fullpath1(td, vn, rootvnode, buf, retbuf, &buflen); if (!error) *freebuf = buf; else @@ -2338,14 +2342,17 @@ vn_vptocnp(struct vnode **vp, struct ucred *cred, char */ static int vn_fullpath1(struct thread *td, struct vnode *vp, struct vnode *rdir, - char *buf, char **retbuf, size_t buflen) + char *buf, char **retbuf, size_t *len) { int error, slash_prefixed; #ifdef KDTRACE_HOOKS struct vnode *startvp = vp; #endif struct vnode *vp1; + size_t buflen; + buflen = *len; + buflen--; buf[buflen] = '\0'; error = 0; @@ -2436,6 +2443,7 @@ vn_fullpath1(struct thread *td, struct vnode *vp, stru SDT_PROBE3(vfs, namecache, fullpath, return, 0, startvp, buf + buflen); *retbuf = buf + buflen; + *len -= buflen; return (0); }