From owner-freebsd-fs@freebsd.org Thu Jul 9 15:40:27 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 94099997D19 for ; Thu, 9 Jul 2015 15:40:27 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: from mail-wi0-x230.google.com (mail-wi0-x230.google.com [IPv6:2a00:1450:400c:c05::230]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G2" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 3692A1AA9; Thu, 9 Jul 2015 15:40:27 +0000 (UTC) (envelope-from mjguzik@gmail.com) Received: by wiga1 with SMTP id a1so316554312wig.0; Thu, 09 Jul 2015 08:40:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=date:from:to:cc:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=7i9jVucnMTv1nOzhtOFZE8szPhOAg+ow1nDpYr4HAqk=; b=BGqG368jjgzmnaoCBLzaMGGHfg8lc3zaHBBrlpkgqPdsD7rSkLRJwLtGS6dKnrkSUO Kx9rf8LriHnbVmCwrIUuKdqD4GCSoZllG3lqh0kxGzBwo3WTsWvIY47Z0syiZaW38ypE JxzuwY5yWMMC4I32m8cxUuY96UU/INho93ZjNLPAt1zVkc9toRFFqQyc/B68/jEyp6EV vCVrAus45o9VzcEnDhE+94/E+0gZrzIowDzeuUMZDNlJD78l0b+ZZhOFYE5JZyzlvGLU n4bHbVkQT146CRcu0LOpUXjeSQUsbzyi5o1POJdmpm6CaMgQPzUSpkWs52BkTdYRW200 xGxA== X-Received: by 10.194.60.226 with SMTP id k2mr30120485wjr.10.1436456425632; Thu, 09 Jul 2015 08:40:25 -0700 (PDT) Received: from dft-labs.eu (n1x0n-1-pt.tunnel.tserv5.lon1.ipv6.he.net. [2001:470:1f08:1f7::2]) by smtp.gmail.com with ESMTPSA id ej5sm9409291wjd.22.2015.07.09.08.40.23 (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Thu, 09 Jul 2015 08:40:24 -0700 (PDT) Date: Thu, 9 Jul 2015 17:40:21 +0200 From: Mateusz Guzik To: Konstantin Belousov Cc: rwatson@FreeBSD.org, freebsd-fs@freebsd.org Subject: Re: [PATCH 3/4] vfs: simplify error handling in namei Message-ID: <20150709154021.GC1718@dft-labs.eu> References: <20150707085857.GZ2080@kib.kiev.ua> <1436393231-5831-1-git-send-email-mjguzik@gmail.com> <1436393231-5831-4-git-send-email-mjguzik@gmail.com> <20150709102533.GO2080@kib.kiev.ua> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20150709102533.GO2080@kib.kiev.ua> User-Agent: Mutt/1.5.21 (2010-09-15) 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 15:40:27 -0000 On Thu, Jul 09, 2015 at 01:25:33PM +0300, Konstantin Belousov wrote: > On Thu, Jul 09, 2015 at 12:07:10AM +0200, Mateusz Guzik wrote: > > From: Mateusz Guzik > > > > The logic is reorganised so that there is one exit point prior to the > > lookup loop. This is an intermediate step to making audit logging > > functions use found vnode instead of translating ni_dirfd on their own. > > > > ni_startdir validation is removed. The only in-tree consumer is nfs > > which already makes sure it is a directory. > > --- > > sys/kern/vfs_lookup.c | 50 +++++++++++++++++++++----------------------------- > > 1 file changed, 21 insertions(+), 29 deletions(-) > > > > diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c > > index e434464..d48fcff 100644 > > --- a/sys/kern/vfs_lookup.c > > +++ b/sys/kern/vfs_lookup.c > > @@ -158,7 +158,7 @@ namei(struct nameidata *ndp) > > struct vnode *dp; /* the directory we are searching */ > > struct iovec aiov; /* uio for reading symbolic links */ > > struct uio auio; > > - int error, linklen; > > + int error, linklen, startdir_used; > > struct componentname *cnp = &ndp->ni_cnd; > > struct thread *td = cnp->cn_thread; > > struct proc *p = td->td_proc; > > @@ -169,6 +169,9 @@ namei(struct nameidata *ndp) > > ("namei: nameiop contaminated with flags")); > > KASSERT((cnp->cn_flags & OPMASK) == 0, > > ("namei: flags contaminated with nameiops")); > > + if (ndp->ni_startdir != NULL) > > + MPASS(ndp->ni_startdir->v_type == VDIR || > > + ndp->ni_startdir->v_type == VBAD); > Write this as > MPASS(ndp->ni_startdir == NULL || ... == VDIR || ... == VBAD); > ? > Done. > I think that the two previous patches are self-contained ? > Please commit them, after that I think review of this patch can > be finished. > Committed. diff --git a/sys/kern/vfs_lookup.c b/sys/kern/vfs_lookup.c index e434464..a93314e 100644 --- a/sys/kern/vfs_lookup.c +++ b/sys/kern/vfs_lookup.c @@ -158,7 +158,7 @@ namei(struct nameidata *ndp) struct vnode *dp; /* the directory we are searching */ struct iovec aiov; /* uio for reading symbolic links */ struct uio auio; - int error, linklen; + int error, linklen, startdir_used; struct componentname *cnp = &ndp->ni_cnd; struct thread *td = cnp->cn_thread; struct proc *p = td->td_proc; @@ -169,6 +169,8 @@ namei(struct nameidata *ndp) ("namei: nameiop contaminated with flags")); KASSERT((cnp->cn_flags & OPMASK) == 0, ("namei: flags contaminated with nameiops")); + MPASS(ndp->ni_startdir == NULL || ndp->ni_startdir->v_type == VDIR || + ndp->ni_startdir->v_type == VBAD); if (!lookup_shared) cnp->cn_flags &= ~LOCKSHARED; fdp = p->p_fd; @@ -242,23 +244,19 @@ namei(struct nameidata *ndp) if (cnp->cn_flags & AUDITVNODE2) AUDIT_ARG_UPATH2(td, ndp->ni_dirfd, cnp->cn_pnbuf); + startdir_used = 0; dp = NULL; 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; - } else if (ndp->ni_dirfd != AT_FDCWD) { + startdir_used = 1; + } else if (ndp->ni_dirfd == AT_FDCWD) { + dp = fdp->fd_cdir; + VREF(dp); + } else { cap_rights_t rights; rights = ndp->ni_rightsneeded; @@ -285,25 +283,18 @@ namei(struct nameidata *ndp) } #endif } - if (error != 0 || dp != NULL) { - FILEDESC_SUNLOCK(fdp); - if (error == 0 && dp->v_type != VDIR) { - vrele(dp); - error = ENOTDIR; - } - } - if (error) { - vrele(ndp->ni_rootdir); - namei_cleanup_cnp(cnp); - return (error); - } + if (error == 0 && dp->v_type != VDIR) + error = ENOTDIR; } - if (dp == NULL) { - dp = fdp->fd_cdir; - VREF(dp); - FILEDESC_SUNLOCK(fdp); - if (ndp->ni_startdir != NULL) - vrele(ndp->ni_startdir); + FILEDESC_SUNLOCK(fdp); + if (ndp->ni_startdir != NULL && !startdir_used) + vrele(ndp->ni_startdir); + if (error != 0) { + if (dp != NULL) + vrele(dp); + vrele(ndp->ni_rootdir); + namei_cleanup_cnp(cnp); + return (error); } SDT_PROBE(vfs, namei, lookup, entry, dp, cnp->cn_pnbuf, cnp->cn_flags, 0, 0); -- Mateusz Guzik