From patchwork Thu Apr 12 15:07:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 10338885 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 B121D602D8 for ; Thu, 12 Apr 2018 15:25:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A700E1FFB2 for ; Thu, 12 Apr 2018 15:25:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9BDBB201A4; Thu, 12 Apr 2018 15:25:51 +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=unavailable 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 4CB1C1FFB2 for ; Thu, 12 Apr 2018 15:25:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753241AbeDLPIh (ORCPT ); Thu, 12 Apr 2018 11:08:37 -0400 Received: from mail-wm0-f65.google.com ([74.125.82.65]:52953 "EHLO mail-wm0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753015AbeDLPIf (ORCPT ); Thu, 12 Apr 2018 11:08:35 -0400 Received: by mail-wm0-f65.google.com with SMTP id g8so12314736wmd.2 for ; Thu, 12 Apr 2018 08:08:34 -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=4WXD0vv9+eWoGR0E60ATHExkoMjrgmozLU5+vZLe2Sk=; b=BMdT6qZyJ2mxf64IdqvFvw+MDAnYxYGj6DSXiCtFBidN8LfWuAQFhdiw+EipEZ53jx 3F84ZSNhWPRwj6IDseCVDTHA8x+nvkAK+t7+5KWClHC1y4srPhyTDJ+7fADQHS3MKPPa qLJqef5sZFr2V67LkcZ4la8BJdwZXdlpmxDsZBaj6YfJdGgfdCdOC5I0B2dcZTRxV68f ccFrG6/ZRYoGe1+UGC7vXqLtKWSHXvijdc3yvCp4PWFqM2lQNP1qRpigk2dRB0QJ/+Pe oyv5A6kwsT2wZ0KQzuSVpid+TqFoVg1/gcGvwRpOtAe/Cvii57K5YGRkUg3A0fGpnypk WaLw== X-Gm-Message-State: ALQs6tBNA/4q8TeX37cVNLTTPd1mfIIXumZ8X0c6kR89YsZhiE69uMz6 h2lQJ8q3oXCGei6WYfSO0G4Jtw== X-Google-Smtp-Source: AIpwx4+N24LLC9t0YeGUDBU1x3nqargzbkCQnfWZXzaX/JiKys6sgJtvRJ4ajNPASpVAtltYaBRuYQ== X-Received: by 10.28.191.27 with SMTP id p27mr1091546wmf.97.1523545714084; Thu, 12 Apr 2018 08:08:34 -0700 (PDT) Received: from veci.piliscsaba.redhat.com (catv-176-63-54-97.catv.broadband.hu. [176.63.54.97]) by smtp.gmail.com with ESMTPSA id p197sm2621783wme.43.2018.04.12.08.08.33 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Apr 2018 08:08:33 -0700 (PDT) From: Miklos Szeredi To: linux-unionfs@vger.kernel.org Cc: linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [RFC PATCH 02/35] vfs: add path_open() Date: Thu, 12 Apr 2018 17:07:53 +0200 Message-Id: <20180412150826.20988-3-mszeredi@redhat.com> X-Mailer: git-send-email 2.14.3 In-Reply-To: <20180412150826.20988-1-mszeredi@redhat.com> References: <20180412150826.20988-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 | 27 +++++++++++++++++++++++++++ include/linux/fs.h | 2 ++ 2 files changed, 29 insertions(+) diff --git a/fs/open.c b/fs/open.c index 7ea118471dce..8c315f9ec2f6 100644 --- a/fs/open.c +++ b/fs/open.c @@ -866,6 +866,33 @@ int vfs_open(const struct path *path, struct file *file, return do_dentry_open(file, d_backing_inode(dentry), NULL, cred); } +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)) { + file->f_flags = flags; + file->f_path = *path; + retval = do_dentry_open(file, inode, NULL, cred); + if (retval) { + put_filp(file); + file = ERR_PTR(retval); + } else { + retval = open_check_o_direct(file); + if (retval) { + fput(file); + file = 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 f0f87f2beb79..c6d7e3b00163 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 *);