Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp2366000imm; Tue, 10 Jul 2018 19:25:35 -0700 (PDT) X-Google-Smtp-Source: AAOMgpf8N7iAZfkZtZt5fxUkBfRzJrkFsfuhNURKXtX42tRl3AJX80Jb7mnnuEzOF+f1r9UEcdq0 X-Received: by 2002:a17:902:a518:: with SMTP id s24-v6mr27258939plq.144.1531275935141; Tue, 10 Jul 2018 19:25:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531275935; cv=none; d=google.com; s=arc-20160816; b=e1JTFeqEX0O+5Tc7HuQJvY0JXXYThy4IhkR/nLUR2DPZ2WS69pEnS04Wh5swZC/kjb UYxm9+SImag2y5yiHUgLTrAkDteyvfPc5QsfA7kbarJoZubIpF8jd8sUKdzyJJk8dDRY TjEnMIUKSelRk5qGDIvjRHD1zOxgGZzLzzE408BMfV4gjwzJ9U5/5s2EJdh+sg9ly8u/ ff8Ntlo6HdN5sDNDCHc8qyuCAH09Jmh01hsTYRBlv28ztQsqFmTzUcumpydYfBMtotp5 tgnpP6Gm4UZhR9NtAvFIUHrwh4uHDco3aQZn2ECAebdirhWyUx5FECQGKodtb2fYahAP XDsg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:arc-authentication-results; bh=JfWIM2nOzuKKQ4S8kRZbcwkDLy4EQ02YX++iBDrNFl0=; b=J5wZLT1511s+BPV+b0G7tZ0wgsQcx9QJkEheld/sAkD3pgi9mu1yyp03vMBhciQQ/o TL8vo1bwWbueSI80A+hK+auCK8rf2FKNMdVTmgQ3fkNiTvtS/vvWyPXAGw0+Vtu2qa6Q UX89pv/WTF2Ol3EalBie7ffDJHmE01+sm9gwgFzIJ74uMo3bK4Vg6Nm+k/9H1UUy5PzP emhhnXOfnx+lDlM5/w98Y+8nYD0Nh2ORNfcLR9WRXRbH1Q7qUo9moSdNL4q/dSUC85KH snhiUa6b0Bel6nDPw4vW8Lc6W7PJs/cCiWJ6P0tyw04G3e+0jOpQdBm2H5KTuirYUtMr mQkw== 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 9-v6si18454996pla.59.2018.07.10.19.25.20; Tue, 10 Jul 2018 19:25:35 -0700 (PDT) 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 S1732691AbeGKC0A (ORCPT + 99 others); Tue, 10 Jul 2018 22:26:00 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:45638 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732355AbeGKCYG (ORCPT ); Tue, 10 Jul 2018 22:24:06 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1fd4lc-0003KB-VX; Wed, 11 Jul 2018 02:22:08 +0000 From: Al Viro To: Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Miklos Szeredi Subject: [RFC][PATCH 26/42] switch atomic_open() and lookup_open() to returning 0 in all success cases Date: Wed, 11 Jul 2018 03:21:50 +0100 Message-Id: <20180711022206.12571-26-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180711022206.12571-1-viro@ZenIV.linux.org.uk> References: <20180711021136.GN30522@ZenIV.linux.org.uk> <20180711022206.12571-1-viro@ZenIV.linux.org.uk> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Al Viro caller can tell "opened" from "open it yourself" by looking at ->f_mode. Signed-off-by: Al Viro --- fs/namei.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index 8b1e5cb85f58..ca3f4dec8cda 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3027,9 +3027,9 @@ static int may_o_create(const struct path *dir, struct dentry *dentry, umode_t m * Returns 0 if successful. The file will have been created and attached to * @file by the filesystem calling finish_open(). * - * Returns 1 if the file was looked up only or didn't need creating. The - * caller will need to perform the open themselves. @path will have been - * updated to point to the new dentry. This may be negative. + * If the file was looked up only or didn't need creating, FMODE_OPENED won't + * be set. The caller will need to perform the open themselves. @path will + * have been updated to point to the new dentry. This may be negative. * * Returns an error code otherwise. */ @@ -3082,7 +3082,7 @@ static int atomic_open(struct nameidata *nd, struct dentry *dentry, } else { path->dentry = dentry; path->mnt = nd->path.mnt; - return 1; + return 0; } } } @@ -3093,17 +3093,17 @@ static int atomic_open(struct nameidata *nd, struct dentry *dentry, /* * Look up and maybe create and open the last component. * - * Must be called with i_mutex held on parent. - * - * Returns 0 if the file was successfully atomically created (if necessary) and - * opened. In this case the file will be returned attached to @file. + * Must be called with parent locked (exclusive in O_CREAT case). * - * Returns 1 if the file was not completely opened at this time, though lookups - * and creations will have been performed and the dentry returned in @path will - * be positive upon return if O_CREAT was specified. If O_CREAT wasn't - * specified then a negative dentry may be returned. + * Returns 0 on success, that is, if + * the file was successfully atomically created (if necessary) and opened, or + * the file was not completely opened at this time, though lookups and + * creations were performed. + * These case are distinguished by presence of FMODE_OPENED on file->f_mode. + * In the latter case dentry returned in @path might be negative if O_CREAT + * hadn't been specified. * - * An error code is returned otherwise. + * An error code is returned on failure. */ static int lookup_open(struct nameidata *nd, struct path *path, struct file *file, @@ -3225,7 +3225,7 @@ static int lookup_open(struct nameidata *nd, struct path *path, out_no_open: path->dentry = dentry; path->mnt = nd->path.mnt; - return 1; + return 0; out_dput: dput(dentry); @@ -3308,10 +3308,10 @@ static int do_last(struct nameidata *nd, else inode_unlock_shared(dir->d_inode); - if (error <= 0) { - if (error) - goto out; + if (error) + goto out; + if (file->f_mode & FMODE_OPENED) { if ((file->f_mode & FMODE_CREATED) || !S_ISREG(file_inode(file)->i_mode)) will_truncate = false; -- 2.11.0