Received: by 2002:ac0:a5b6:0:0:0:0:0 with SMTP id m51-v6csp1209580imm; Fri, 8 Jun 2018 11:53:47 -0700 (PDT) X-Google-Smtp-Source: ADUXVKIjh/wMO3RduFd39TkzUGSa5Jen6y9tAc5N+QuCuTMt72Ifm3mUgX+xROR0X+99VDPbcunJ X-Received: by 2002:a63:902:: with SMTP id 2-v6mr6131869pgj.3.1528484027745; Fri, 08 Jun 2018 11:53:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1528484027; cv=none; d=google.com; s=arc-20160816; b=HZBsrvx8ETjKSeLnDAFNGQPtIQSeITz+eEjj4Cf5Y4KKnwDN17JOw6eF2foJC6JCFN 1LVoFg665IIi/t7k8GOKQ4TAD9xBhJENqLdtXaulrAvbqO1S2bn9PFfwZjOSJBoiorzs Xl3E5X2bN1IymzxjJB80oa3C2JWaeSaOm+caGev385E/5ec/VUskd5YXicG5mUTbbm62 GmTzEUnlTIu/CNv6eHhOao2MJMaTDufL9xQH11RQra/Xjl2aI+kelK07LLRhy3DCeqbJ 8XfhnTCfXiHu1BxY+HwxKEb2JErr8PAaUQ47BpWYMz4cdjirw0s5JNSA+UXPacDt5kBh sXWA== 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=86NEnQWK07u1Lk6p5Tgqf1R4kqZHACN2BIXbv4WByts=; b=uFCtYQiUWTQH5y1iAMXTW1u3nd7XVXSNoCgJ3OA8v6I1+FTEWSc2CdIvtct192VAO6 x7jXV4F0Ym6A8P5Lk+VshDcUJyMT128c087HWCj03vkjnO4NexcNmVpQ+cVbcyvXscwv Z6ac+2eeGsliSpYQgmHZSJ7jkExRsv11/ETvMcXmePNzCo/6GUcxtk7aitTmGS9twR2S panLIHxKOA3jRzFF8Hzi1W8EF8+DaeeHP32Hy3yeCB8xfmF7OiO9jV+EbDHAo49QYwhH OJQXwEby+DilLBTdy2ukBXQlUGip8ge7jZeujxSPax6hYJGJ2nr1sAqcn0LI50sVFS6Q JW3w== 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 z12-v6si18899206plk.48.2018.06.08.11.53.33; Fri, 08 Jun 2018 11:53:47 -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 S1753013AbeFHSvs (ORCPT + 99 others); Fri, 8 Jun 2018 14:51:48 -0400 Received: from zeniv.linux.org.uk ([195.92.253.2]:53806 "EHLO ZenIV.linux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752746AbeFHSuV (ORCPT ); Fri, 8 Jun 2018 14:50:21 -0400 Received: from viro by ZenIV.linux.org.uk with local (Exim 4.87 #1 (Red Hat Linux)) id 1fRMSq-0006Nt-1h; Fri, 08 Jun 2018 18:50:20 +0000 From: Al Viro To: Linus Torvalds Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 07/13] now we can fold open_check_o_direct() into do_dentry_open() Date: Fri, 8 Jun 2018 19:50:13 +0100 Message-Id: <20180608185019.24472-7-viro@ZenIV.linux.org.uk> X-Mailer: git-send-email 2.9.5 In-Reply-To: <20180608185019.24472-1-viro@ZenIV.linux.org.uk> References: <20180608184842.GD30522@ZenIV.linux.org.uk> <20180608185019.24472-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 Signed-off-by: Al Viro --- fs/internal.h | 1 - fs/namei.c | 7 +------ fs/open.c | 27 +++++++++------------------ 3 files changed, 10 insertions(+), 25 deletions(-) diff --git a/fs/internal.h b/fs/internal.h index 5645b4ebf494..08ac9cdee1b4 100644 --- a/fs/internal.h +++ b/fs/internal.h @@ -125,7 +125,6 @@ int do_fchmodat(int dfd, const char __user *filename, umode_t mode); int do_fchownat(int dfd, const char __user *filename, uid_t user, gid_t group, int flag); -extern int open_check_o_direct(struct file *f); extern int vfs_open(const struct path *, struct file *, const struct cred *); /* diff --git a/fs/namei.c b/fs/namei.c index 3034c97df757..ef21c904f147 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -3366,9 +3366,7 @@ static int do_last(struct nameidata *nd, if (error) goto out; opened: - error = open_check_o_direct(file); - if (!error) - error = ima_file_check(file, op->acc_mode, *opened); + error = ima_file_check(file, op->acc_mode, *opened); if (!error && will_truncate) error = handle_truncate(file); out: @@ -3444,9 +3442,6 @@ static int do_tmpfile(struct nameidata *nd, unsigned flags, goto out2; file->f_path.mnt = path.mnt; error = finish_open(file, child, NULL); - if (error) - goto out2; - error = open_check_o_direct(file); out2: mnt_drop_write(path.mnt); out: diff --git a/fs/open.c b/fs/open.c index 83e489d43526..2724aa2e9635 100644 --- a/fs/open.c +++ b/fs/open.c @@ -724,16 +724,6 @@ SYSCALL_DEFINE3(fchown, unsigned int, fd, uid_t, user, gid_t, group) return ksys_fchown(fd, user, group); } -int open_check_o_direct(struct file *f) -{ - /* NB: we're sure to have correct a_ops only after f_op->open */ - if (f->f_flags & O_DIRECT) { - if (!f->f_mapping->a_ops || !f->f_mapping->a_ops->direct_IO) - return -EINVAL; - } - return 0; -} - static int do_dentry_open(struct file *f, struct inode *inode, int (*open)(struct inode *, struct file *), @@ -810,6 +800,11 @@ static int do_dentry_open(struct file *f, file_ra_state_init(&f->f_ra, f->f_mapping->host->i_mapping); + /* NB: we're sure to have correct a_ops only after f_op->open */ + if (f->f_flags & O_DIRECT) { + if (!f->f_mapping->a_ops || !f->f_mapping->a_ops->direct_IO) + return -EINVAL; + } return 0; cleanup_all: @@ -918,15 +913,11 @@ struct file *dentry_open(const struct path *path, int flags, if (!IS_ERR(f)) { f->f_flags = flags; error = vfs_open(path, f, cred); - if (!error) { - /* from now on we need fput() to dispose of f */ - error = open_check_o_direct(f); - if (error) { + if (error) { + if (f->f_mode & FMODE_OPENED) fput(f); - f = ERR_PTR(error); - } - } else { - put_filp(f); + else + put_filp(f); f = ERR_PTR(error); } } -- 2.11.0