Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp876144ybv; Sat, 22 Feb 2020 17:25:50 -0800 (PST) X-Google-Smtp-Source: APXvYqz9Nm7W1ZCh/FDQ8UT+9sjjfuBQaAFQakHMOqG9DJXzit5YwY8+xBHwzAv+95qNmUHmcVsC X-Received: by 2002:aca:190b:: with SMTP id l11mr8110303oii.65.1582421150456; Sat, 22 Feb 2020 17:25:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582421150; cv=none; d=google.com; s=arc-20160816; b=X9mcUkhMAuw9sag3yQuFBsAUMlu5Joa2WBUgrsAIbQSbtSv4prGlGLv5eeP62Q9Yj0 R75/jLC+fIZBhm+kq2Z9G4LN8Dgs5SWmPxp+d+LbT78WwKGzui6BMfrAJOaZD4IipH9r hZLx03oTRZd4VjomsJJuB9+dYv/iPBzb3Hxge/5tzgCETtUIIPuZvjMZ+JFHiF3bbhz+ BGMN74qS5qB+rxyh3ns/YkrGXsdzsWguw67LA+/mP7mM0+n6rBB1/tyO5b/hDpZLZ9y1 IXMdqCDJ2y345Wnm4gEXS5SwZ9B7YGycpMGOwu62W5IQyHRrfQD/z+EHXhzg/s/4pVSZ Uwzw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=DiuO9cuBy91xeQfG/EXi/YTyX3dkAZAXfFVlA8AO3O8=; b=oAQWkIzBDJYB9PtgJhfZKXEjqQH72O4bQu1SWVD+OJbjUo58HCY5HhEptEzaLVRCQa S0DzQrtjnfFIB+VMrmTnh/KIVN0FfIdsMymjeNjSppE+xXKOs2aQzNSh+IUyftbiGogJ XmPNtQU8pSd0/dGxj+173IsN5W6JSkPZGNwuCPIQuUsickHdcC/Cbvgw3CczbjlrCSt/ hKTwdp8mGIJtjaqx7GL8Jn1VBV3quHOA4S8tgfAgeEXPucNCTcdnz0ewoE1yaHzLwSi5 cjoYCz/35gK30Bxj3zxXXCTI08D5y5oR8AXcEQE+3C19n7nB7OjycD/OZiqrzntYYKXE uDGA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s11si3028494oic.57.2020.02.22.17.25.38; Sat, 22 Feb 2020 17:25:50 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727249AbgBWBZ3 (ORCPT + 99 others); Sat, 22 Feb 2020 20:25:29 -0500 Received: from zeniv.linux.org.uk ([195.92.253.2]:50276 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727091AbgBWBZ3 (ORCPT ); Sat, 22 Feb 2020 20:25:29 -0500 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1j5g15-00HDp3-SI; Sun, 23 Feb 2020 01:25:16 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Linus Torvalds Subject: [RFC][PATCH v2 31/34] do_last(): rejoing the common path earlier in FMODE_{OPENED,CREATED} case Date: Sun, 23 Feb 2020 01:16:23 +0000 Message-Id: <20200223011626.4103706-31-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200223011626.4103706-1-viro@ZenIV.linux.org.uk> References: <20200223011154.GY23230@ZenIV.linux.org.uk> <20200223011626.4103706-1-viro@ZenIV.linux.org.uk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro Signed-off-by: Al Viro --- fs/namei.c | 21 ++++++++------------- 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 56285466aa55..51283caaf7c4 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3208,13 +3208,6 @@ static const char *do_last(struct nameidata *nd, return ERR_CAST(dentry); if (file->f_mode & FMODE_OPENED) { - if (file->f_mode & FMODE_CREATED) { - open_flag &= ~O_TRUNC; - will_truncate = false; - acc_mode = 0; - } else if (!S_ISREG(file_inode(file)->i_mode)) - will_truncate = false; - audit_inode(nd->name, file->f_path.dentry, 0); dput(nd->path.dentry); nd->path.dentry = dentry; @@ -3222,10 +3215,6 @@ static const char *do_last(struct nameidata *nd, } if (file->f_mode & FMODE_CREATED) { - /* Don't check for write permission, don't truncate */ - open_flag &= ~O_TRUNC; - will_truncate = false; - acc_mode = 0; dput(nd->path.dentry); nd->path.dentry = dentry; goto finish_open_created; @@ -3260,10 +3249,16 @@ static const char *do_last(struct nameidata *nd, } if ((nd->flags & LOOKUP_DIRECTORY) && !d_can_lookup(nd->path.dentry)) return ERR_PTR(-ENOTDIR); - if (!d_is_reg(nd->path.dentry)) - will_truncate = false; finish_open_created: + if (file->f_mode & FMODE_CREATED) { + /* Don't check for write permission, don't truncate */ + open_flag &= ~O_TRUNC; + will_truncate = false; + acc_mode = 0; + } else if (!d_is_reg(nd->path.dentry)) { + will_truncate = false; + } if (will_truncate) { error = mnt_want_write(nd->path.mnt); if (error) -- 2.11.0