Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp57998ybh; Fri, 13 Mar 2020 17:00:38 -0700 (PDT) X-Google-Smtp-Source: ADFU+vvkOpqk/BzkZ9ITQMTBWT5JRR6Qxmz9jCDfPePy+nskm4xfNUiDPBweIyl0rUp37nVegQFw X-Received: by 2002:aca:1201:: with SMTP id 1mr9435520ois.172.1584144037986; Fri, 13 Mar 2020 17:00:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584144037; cv=none; d=google.com; s=arc-20160816; b=h5fnBYFaYeOG7rzuM1dDvxsCy+EVY1DePQyLDG6IXgczqeddD7S3TJ6JV5HmHtlKeQ t8VfnzVqr7OvOBgCs6ID8rXF44j4ThKASlTkVgvdtyiGEADMaMIP7JX/YcRUBv8W/itc Cd5TgJmUduZPeuB9L+QUeRPz89r7LVxGjGGw3CdkhrhwwfUw5Op6qBq4pTt390P+/2Yo YOS+038d78dK9R7Pa5wFcH4M1j0Lh26BSRHKrGfsHYxZRjk1aWofaixEIUNKzYD5CNDe xSvr/Ikdy7hL/RF/qvxr+sp2tnHQKzS8eM0sqs44UNqp/crns8xAVmbicw3z0PPZkubK QWpA== 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=aW4KYZoaYVEZLxDRyjpe15emYfn9J96sdQ1RdVeN0BM=; b=a+GLlPjNkQloOh/3gDFfIee7YWjmO6Wjxn8e/s0pjDKV27ZOCG8JxX9QUtTgiK24AV v05qBXohfam4bA7udTISBLLhvzyI4LBk36b2fWj5ZhwadscyEh14j8Y8vIuSDYDqyk3m /v4i5/cXIC2rIHI9fdF17ot8oq0GZJUVSXGIdTsB+NeSlruh8WtoIJ6ap5f2mv9kNtjf 38LFBtZAcEou2tzIfBnSIXYlX8CbyiI7YXQ9tUzjUFkavcdwlMiHt9SI8BSt3W2MBhK/ ciuNKsWczbHJANFYH3lMd+JJb6vjJsZAl+j/tJC8LhVWildMNeEJoEJZlJ2sShWTLBuK /SWw== 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 m81si5285512oig.190.2020.03.13.17.00.24; Fri, 13 Mar 2020 17:00:37 -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 S1728036AbgCMX6l (ORCPT + 99 others); Fri, 13 Mar 2020 19:58:41 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:49970 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727678AbgCMXx7 (ORCPT ); Fri, 13 Mar 2020 19:53:59 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.92.3 #3 (Red Hat Linux)) id 1jCu7p-00B6Yo-Ue; Fri, 13 Mar 2020 23:53:57 +0000 From: Al Viro To: linux-fsdevel@vger.kernel.org Cc: linux-kernel@vger.kernel.org, Linus Torvalds Subject: [RFC][PATCH v4 07/69] atomic_open(): saner calling conventions (return dentry on success) Date: Fri, 13 Mar 2020 23:52:55 +0000 Message-Id: <20200313235357.2646756-7-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.24.1 In-Reply-To: <20200313235357.2646756-1-viro@ZenIV.linux.org.uk> References: <20200313235303.GP23230@ZenIV.linux.org.uk> <20200313235357.2646756-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 Currently it either returns -E... or puts (nd->path.mnt,dentry) into *path and returns 0. Make it return ERR_PTR(-E...) or dentry; adjust the caller. Fewer arguments and it's easier to keep track of *path contents that way. Signed-off-by: Al Viro --- fs/namei.c | 41 ++++++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 17 deletions(-) diff --git a/fs/namei.c b/fs/namei.c index c104ec75faef..5f8b791a6d6e 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3087,10 +3087,10 @@ static int may_o_create(const struct path *dir, struct dentry *dentry, umode_t m * * Returns an error code otherwise. */ -static int atomic_open(struct nameidata *nd, struct dentry *dentry, - struct path *path, struct file *file, - const struct open_flags *op, - int open_flag, umode_t mode) +static struct dentry *atomic_open(struct nameidata *nd, struct dentry *dentry, + struct file *file, + const struct open_flags *op, + int open_flag, umode_t mode) { struct dentry *const DENTRY_NOT_SET = (void *) -1UL; struct inode *dir = nd->path.dentry->d_inode; @@ -3131,17 +3131,15 @@ static int atomic_open(struct nameidata *nd, struct dentry *dentry, } if (file->f_mode & FMODE_CREATED) fsnotify_create(dir, dentry); - if (unlikely(d_is_negative(dentry))) { + if (unlikely(d_is_negative(dentry))) error = -ENOENT; - } else { - path->dentry = dentry; - path->mnt = nd->path.mnt; - return 0; - } } } - dput(dentry); - return error; + if (error) { + dput(dentry); + dentry = ERR_PTR(error); + } + return dentry; } /* @@ -3236,11 +3234,20 @@ static int lookup_open(struct nameidata *nd, struct path *path, } if (dir_inode->i_op->atomic_open) { - error = atomic_open(nd, dentry, path, file, op, open_flag, - mode); - if (unlikely(error == -ENOENT) && create_error) - error = create_error; - return error; + dentry = atomic_open(nd, dentry, file, op, open_flag, mode); + if (IS_ERR(dentry)) { + error = PTR_ERR(dentry); + if (unlikely(error == -ENOENT) && create_error) + error = create_error; + return error; + } + if (file->f_mode & FMODE_OPENED) { + dput(dentry); + return 0; + } + path->mnt = nd->path.mnt; + path->dentry = dentry; + return 0; } no_open: -- 2.11.0