From owner-freebsd-fs@freebsd.org Thu Jul 9 10:17:48 2015 Return-Path: Delivered-To: freebsd-fs@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 79AE2996F24 for ; Thu, 9 Jul 2015 10:17:48 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from kib.kiev.ua (kib.kiev.ua [IPv6:2001:470:d5e7:1::1]) (using TLSv1 with cipher DHE-RSA-CAMELLIA256-SHA (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 0465F102B; Thu, 9 Jul 2015 10:17:47 +0000 (UTC) (envelope-from kostikbel@gmail.com) Received: from tom.home (kostik@localhost [127.0.0.1]) by kib.kiev.ua (8.14.9/8.14.9) with ESMTP id t69AHhDh011726 (version=TLSv1/SSLv3 cipher=DHE-RSA-CAMELLIA256-SHA bits=256 verify=NO); Thu, 9 Jul 2015 13:17:43 +0300 (EEST) (envelope-from kostikbel@gmail.com) DKIM-Filter: OpenDKIM Filter v2.9.2 kib.kiev.ua t69AHhDh011726 Received: (from kostik@localhost) by tom.home (8.14.9/8.14.9/Submit) id t69AHgOv011725; Thu, 9 Jul 2015 13:17:43 +0300 (EEST) (envelope-from kostikbel@gmail.com) X-Authentication-Warning: tom.home: kostik set sender to kostikbel@gmail.com using -f Date: Thu, 9 Jul 2015 13:17:42 +0300 From: Konstantin Belousov To: Mateusz Guzik Cc: rwatson@FreeBSD.org, freebsd-fs@freebsd.org, Mateusz Guzik Subject: Re: [PATCH 2/4] vfs: avoid spurious vref/vrele for absolute lookups Message-ID: <20150709101742.GN2080@kib.kiev.ua> References: <20150707085857.GZ2080@kib.kiev.ua> <1436393231-5831-1-git-send-email-mjguzik@gmail.com> <1436393231-5831-3-git-send-email-mjguzik@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1436393231-5831-3-git-send-email-mjguzik@gmail.com> User-Agent: Mutt/1.5.23 (2014-03-12) X-Spam-Status: No, score=-2.0 required=5.0 tests=ALL_TRUSTED,BAYES_00, DKIM_ADSP_CUSTOM_MED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED autolearn=no autolearn_force=no version=3.4.1 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) on tom.home X-BeenThere: freebsd-fs@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Filesystems List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 09 Jul 2015 10:17:48 -0000 On Thu, Jul 09, 2015 at 12:07:09AM +0200, Mateusz Guzik wrote: > From: Mateusz Guzik > > namei used to vref fd_cdir, which was immediatley vrele'd on entry to > the loop. > > Check for absolute lookup and vref the right vnode the first time. > --- > sys/kern/vfs_lookup.c | 70 +++++++++++++++++++++++++++++++++------------------ > 1 file changed, 46 insertions(+), 24 deletions(-) > > diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c > index 20f8e96..e434464 100644 > --- a/sys/kern/vfs_lookup.c > +++ b/sys/kern/vfs_lookup.c > @@ -109,6 +109,27 @@ namei_cleanup_cnp(struct componentname *cnp) > #endif > } > > +static int > +namei_handle_root(struct nameidata *ndp, struct vnode **dpp) > +{ > + struct componentname *cnp = &ndp->ni_cnd; Do not put initialization into declaration. Otherwise, the patch looks fine. > + > + if (ndp->ni_strictrelative != 0) { > +#ifdef KTRACE > + if (KTRPOINT(curthread, KTR_CAPFAIL)) > + ktrcapfail(CAPFAIL_LOOKUP, NULL, NULL); > +#endif > + return (ENOTCAPABLE); > + } > + while (*(cnp->cn_nameptr) == '/') { > + cnp->cn_nameptr++; > + ndp->ni_pathlen--; > + } > + *dpp = ndp->ni_rootdir; > + VREF(*dpp); > + return (0); > +} > + > /* > * Convert a pathname into a pointer to a locked vnode. > * > @@ -222,7 +243,18 @@ namei(struct nameidata *ndp) > AUDIT_ARG_UPATH2(td, ndp->ni_dirfd, cnp->cn_pnbuf); > > dp = NULL; > - if (cnp->cn_pnbuf[0] != '/') { > + cnp->cn_nameptr = cnp->cn_pnbuf; > + if (cnp->cn_pnbuf[0] == '/') { > + error = namei_handle_root(ndp, &dp); > + FILEDESC_SUNLOCK(fdp); > + if (error != 0) { > + vrele(ndp->ni_rootdir); > + if (ndp->ni_startdir != NULL) > + vrele(ndp->ni_startdir); > + namei_cleanup_cnp(cnp); > + return (error); > + } > + } else { > if (ndp->ni_startdir != NULL) { > dp = ndp->ni_startdir; > error = 0; > @@ -276,29 +308,6 @@ namei(struct nameidata *ndp) > SDT_PROBE(vfs, namei, lookup, entry, dp, cnp->cn_pnbuf, > cnp->cn_flags, 0, 0); > for (;;) { > - /* > - * Check if root directory should replace current directory. > - * Done at start of translation and after symbolic link. > - */ > - cnp->cn_nameptr = cnp->cn_pnbuf; > - if (*(cnp->cn_nameptr) == '/') { > - vrele(dp); > - if (ndp->ni_strictrelative != 0) { > -#ifdef KTRACE > - if (KTRPOINT(curthread, KTR_CAPFAIL)) > - ktrcapfail(CAPFAIL_LOOKUP, NULL, NULL); > -#endif > - vrele(ndp->ni_rootdir); > - namei_cleanup_cnp(cnp); > - return (ENOTCAPABLE); > - } > - while (*(cnp->cn_nameptr) == '/') { > - cnp->cn_nameptr++; > - ndp->ni_pathlen--; > - } > - dp = ndp->ni_rootdir; > - VREF(dp); > - } > ndp->ni_startdir = dp; > error = lookup(ndp); > if (error) { > @@ -375,6 +384,19 @@ namei(struct nameidata *ndp) > ndp->ni_pathlen += linklen; > vput(ndp->ni_vp); > dp = ndp->ni_dvp; > + /* > + * Check if root directory should replace current directory. > + */ > + cnp->cn_nameptr = cnp->cn_pnbuf; > + if (*(cnp->cn_nameptr) == '/') { > + vrele(dp); > + error = namei_handle_root(ndp, &dp); > + if (error != 0) { > + vrele(ndp->ni_rootdir); > + namei_cleanup_cnp(cnp); > + return (error); > + } > + } > } > vrele(ndp->ni_rootdir); > namei_cleanup_cnp(cnp); > -- > 2.4.5