From patchwork Mon May 7 08:37:33 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 10383683 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2879F60548 for ; Mon, 7 May 2018 08:51:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1BBBF28BB4 for ; Mon, 7 May 2018 08:51:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1082528B87; Mon, 7 May 2018 08:51:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 82CA228BB4 for ; Mon, 7 May 2018 08:51:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752050AbeEGIiQ (ORCPT ); Mon, 7 May 2018 04:38:16 -0400 Received: from mail-wm0-f66.google.com ([74.125.82.66]:38533 "EHLO mail-wm0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752017AbeEGIiO (ORCPT ); Mon, 7 May 2018 04:38:14 -0400 Received: by mail-wm0-f66.google.com with SMTP id m198-v6so13049672wmg.3 for ; Mon, 07 May 2018 01:38:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=+RDJddIFjdNcSUOK41IyhB9NRT1ehVcS+vZRXo3j+5k=; b=d5DBIj18R5WkMkcP/GIVxYHYWmzEzL/x/ezN7NaXDhpzsJMXoAMdePPIgM8LkZYCtf QsWbomtFcMLzfBwvtN/bc45aQAkKq+rlHUFH8sCX58xKCuByF3Ydidmn7B2eaaltrQNv ozt/dn/JIj5pSPBUaRUy3XwgCpttI6dBygWn95Wbx8vfrqEQd4gxZ4z0dY7N9Vs9FpzV Pg7BwGYZrkXR1PGCxQw332Az8WFEacgrJLgSpqh9BKJw07hfmVDbxjnTKbcXbL8YinBJ YXuDKXevA1ivgcEs4dvh0RQ03p79o0acrBO8AH7dc9T9uAtC1C7FoHtZ5P/fQgEWPy7a poyg== X-Gm-Message-State: ALQs6tDK9XQDx5q/p2h64hgo0PmFIkyNX321EnWQokBD9rKLeJg7bpkt Z1vgYxQ98W0RS96eMY7KN966vQB80kY= X-Google-Smtp-Source: AB8JxZrOy4G7KLYlg3pbIpWNsgoc1rEVwdxOKz9S5NL+x5K+ESrnTPvK5zNQ28ZTEGAfv/IrBrcJQg== X-Received: by 10.28.146.73 with SMTP id u70mr167704wmd.128.1525682293579; Mon, 07 May 2018 01:38:13 -0700 (PDT) Received: from veci.piliscsaba.redhat.com (C2B0E321.catv.pool.telekom.hu. [194.176.227.33]) by smtp.gmail.com with ESMTPSA id h8-v6sm5908050wmc.16.2018.05.07.01.38.12 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 07 May 2018 01:38:13 -0700 (PDT) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org, Al Viro Subject: [PATCH v2 01/35] vfs: add path_open() Date: Mon, 7 May 2018 10:37:33 +0200 Message-Id: <20180507083807.28792-2-mszeredi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180507083807.28792-1-mszeredi@redhat.com> References: <20180507083807.28792-1-mszeredi@redhat.com> Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Currently opening an overlay file results in: - the real file on the underlying layer being opened - f_path being set to the overlay {mount, dentry} pair This patch adds a new helper that allows the above to be explicitly performed. I.e. it's the same as dentry_open(), except the underlying inode to open is given as a separate argument. This is in preparation for stacking I/O operations on overlay files. Later, when implicit opening is removed, dentry_open() can be implemented by just calling path_open(). Signed-off-by: Miklos Szeredi --- fs/open.c | 31 +++++++++++++++++++++++++++++++ include/linux/fs.h | 2 ++ 2 files changed, 33 insertions(+) diff --git a/fs/open.c b/fs/open.c index c5ee7cd60424..d0bf7f061a1a 100644 --- a/fs/open.c +++ b/fs/open.c @@ -906,6 +906,37 @@ int vfs_open(const struct path *path, struct file *file, return do_dentry_open(file, d_backing_inode(dentry), NULL, cred); } +/** + * path_open() - Open an inode by a particular name. + * @path: The name of the file. + * @flags: The O_ flags used to open this file. + * @inode: The inode to open. + * @cred: The task's credentials used when opening this file. + * + * Context: Process context. + * Return: A pointer to a struct file or an IS_ERR pointer. Cannot return NULL. + */ +struct file *path_open(const struct path *path, int flags, struct inode *inode, + const struct cred *cred) +{ + struct file *file; + int retval; + + file = get_empty_filp(); + if (IS_ERR(file)) + return file; + + file->f_flags = flags; + file->f_path = *path; + retval = do_dentry_open(file, inode, NULL, cred); + if (retval) { + put_filp(file); + return ERR_PTR(retval); + } + return file; +} +EXPORT_SYMBOL(path_open); + struct file *dentry_open(const struct path *path, int flags, const struct cred *cred) { diff --git a/include/linux/fs.h b/include/linux/fs.h index 8007a31c4d3c..d97a661342c8 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -2401,6 +2401,8 @@ extern struct file *filp_open(const char *, int, umode_t); extern struct file *file_open_root(struct dentry *, struct vfsmount *, const char *, int, umode_t); extern struct file * dentry_open(const struct path *, int, const struct cred *); +extern struct file *path_open(const struct path *, int, struct inode *, + const struct cred *); extern int filp_close(struct file *, fl_owner_t id); extern struct filename *getname_flags(const char __user *, int, int *);