From patchwork Thu Mar 17 09:02:00 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 8608331 Return-Path: X-Original-To: patchwork-linux-fsdevel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id 8193DC0553 for ; Thu, 17 Mar 2016 09:01:23 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 88895202E6 for ; Thu, 17 Mar 2016 09:01:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 78A552022A for ; Thu, 17 Mar 2016 09:01:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933099AbcCQJBA (ORCPT ); Thu, 17 Mar 2016 05:01:00 -0400 Received: from mail-wm0-f67.google.com ([74.125.82.67]:35882 "EHLO mail-wm0-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755905AbcCQJA4 (ORCPT ); Thu, 17 Mar 2016 05:00:56 -0400 Received: by mail-wm0-f67.google.com with SMTP id l68so13052119wml.3 for ; Thu, 17 Mar 2016 02:00:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=from:to:cc:subject:date:message-id; bh=9ghJxtOPwS9jRlMJEEBgXQikwY1QnuXBUhOraHW859g=; b=qwYi1lpa2i3svUaVqOGcRk7Ir2isff86JKaD/QIE5Rk66f52VcyF9rnHi1ZHgd5Swr 4RBhn0RMou0Jl/Z6st6HsHvN1MLxCinqq5rU0/nqDdcjhfYfXKF7+KgsBNfSJ/TypmgW ZCTZhAnnj8/AE+7qr9BVci4fSW+loGJIArSHM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=9ghJxtOPwS9jRlMJEEBgXQikwY1QnuXBUhOraHW859g=; b=GcAtGyIZekaS71oyeZp+a7JKfFUaGb6VjSW1MJ/dymdwlQwsA+/V0jaXpbGrX7/zdP c2q4TXjhYh0VbNhIWdc8C64V17eBbtLSLk7bSLe8QjCOlnQechvyclnuWWndHEY/agSN qUB6FHzufrkXnb7F4fiKH0u8ULK6xxGOXkpaAomWKMlcEqlDP1WqRlIuf4S38I8mEV0K gpbU2bYo+rSmpOWkX6d87lLzut/loLbZeyOA26FP4zNR3CF2sAwhko5LPeYZHxu8QSPh yqsSqjRiwOsT9CYcsaSR1K24mPZsvELfl+F7DbuwAD8GCtYM7x7tmMOIqWlMF/pCHqOs VjnQ== X-Gm-Message-State: AD7BkJIq9uOfcEtEGxHy9rW8Xb/MwdScGf+jSG5B29bbuiOg8o9EB7wOteX5Vm4zfwE8+A== X-Received: by 10.194.87.161 with SMTP id az1mr8489435wjb.163.1458205254872; Thu, 17 Mar 2016 02:00:54 -0700 (PDT) Received: from tucsk.pomaz.szeredi.hu (pool-dsl-2c-0018.externet.hu. [217.173.44.24]) by smtp.gmail.com with ESMTPSA id n66sm7110841wmg.20.2016.03.17.02.00.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 17 Mar 2016 02:00:54 -0700 (PDT) From: Miklos Szeredi To: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org Cc: dhowells@redhat.com, viro@zeniv.linux.org.uk, Goldwyn Rodrigues , Trond Myklebust , , Theodore Ts'o , Daniel Axtens Subject: [PATCH 1/4] vfs: add file_dentry() Date: Thu, 17 Mar 2016 10:02:00 +0100 Message-Id: <1458205323-25685-1-git-send-email-miklos@szeredi.hu> X-Mailer: git-send-email 2.1.4 Sender: linux-fsdevel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fsdevel@vger.kernel.org X-Spam-Status: No, score=-6.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_HI,RP_MATCHES_RCVD,T_DKIM_INVALID,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Miklos Szeredi This series fixes bugs in nfs and ext4 due to 4bacc9c9234c ("overlayfs: Make f_path always point to the overlay and f_inode to the underlay"). Regular files opened on overlayfs will result in the file being opened on the underlying filesystem, while f_path points to the overlayfs mount/dentry. This confuses filesystems which get the dentry from struct file and assume it's theirs. Add a new helper, file_dentry() [*], to get the filesystem's own dentry from the file. This simply compares file_inode(file->f_path.dentry) to file_inode(file) and if they are equal returns file->f_path.dentry (this is the common, non-overlayfs case). In the uncommon case (regular file on overlayfs) it will call into overlayfs's ->d_native_dentry() to get the underlying dentry matching file_inode(file). [*] If possible, it's better simply to use file_inode() instead. Signed-off-by: Miklos Szeredi Tested-by: Goldwyn Rodrigues Reviewed-by: Trond Myklebust Cc: # v4.2 Cc: David Howells Cc: Al Viro Cc: Theodore Ts'o Cc: Daniel Axtens Tested-by: Daniel Axtens --- fs/open.c | 11 +++++++++++ fs/overlayfs/super.c | 16 ++++++++++++++++ include/linux/dcache.h | 1 + include/linux/fs.h | 2 ++ 4 files changed, 30 insertions(+) diff --git a/fs/open.c b/fs/open.c index 55bdc75e2172..6326c11eda78 100644 --- a/fs/open.c +++ b/fs/open.c @@ -831,6 +831,17 @@ char *file_path(struct file *filp, char *buf, int buflen) } EXPORT_SYMBOL(file_path); +struct dentry *file_dentry(const struct file *file) +{ + struct dentry *dentry = file->f_path.dentry; + + if (likely(d_inode(dentry) == file_inode(file))) + return dentry; + else + return dentry->d_op->d_native_dentry(dentry, file_inode(file)); +} +EXPORT_SYMBOL(file_dentry); + /** * vfs_open - open the file at the given path * @path: path to open diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index 619ad4b016d2..5142aa2034c4 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -336,14 +336,30 @@ static int ovl_dentry_weak_revalidate(struct dentry *dentry, unsigned int flags) return ret; } +static struct dentry *ovl_d_native_dentry(struct dentry *dentry, + struct inode *inode) +{ + struct ovl_entry *oe = dentry->d_fsdata; + struct dentry *realentry = ovl_upperdentry_dereference(oe); + + if (realentry && inode == d_inode(realentry)) + return realentry; + realentry = __ovl_dentry_lower(oe); + if (realentry && inode == d_inode(realentry)) + return realentry; + BUG(); +} + static const struct dentry_operations ovl_dentry_operations = { .d_release = ovl_dentry_release, .d_select_inode = ovl_d_select_inode, + .d_native_dentry = ovl_d_native_dentry, }; static const struct dentry_operations ovl_reval_dentry_operations = { .d_release = ovl_dentry_release, .d_select_inode = ovl_d_select_inode, + .d_native_dentry = ovl_d_native_dentry, .d_revalidate = ovl_dentry_revalidate, .d_weak_revalidate = ovl_dentry_weak_revalidate, }; diff --git a/include/linux/dcache.h b/include/linux/dcache.h index c4b5f4b3f8f8..99ecb6de636c 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -161,6 +161,7 @@ struct dentry_operations { struct vfsmount *(*d_automount)(struct path *); int (*d_manage)(struct dentry *, bool); struct inode *(*d_select_inode)(struct dentry *, unsigned); + struct dentry *(*d_native_dentry)(struct dentry *, struct inode *); } ____cacheline_aligned; /* diff --git a/include/linux/fs.h b/include/linux/fs.h index ae681002100a..1091d9f43271 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1234,6 +1234,8 @@ static inline struct inode *file_inode(const struct file *f) return f->f_inode; } +extern struct dentry *file_dentry(const struct file *file); + static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl) { return locks_lock_inode_wait(file_inode(filp), fl);