From patchwork Tue Mar 8 15:47:16 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 8535291 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 9147EC0553 for ; Tue, 8 Mar 2016 15:46:17 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 9EFF8201C8 for ; Tue, 8 Mar 2016 15:46:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id AD1262017D for ; Tue, 8 Mar 2016 15:46:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932543AbcCHPqK (ORCPT ); Tue, 8 Mar 2016 10:46:10 -0500 Received: from mail-wm0-f42.google.com ([74.125.82.42]:35904 "EHLO mail-wm0-f42.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754310AbcCHPqI (ORCPT ); Tue, 8 Mar 2016 10:46:08 -0500 Received: by mail-wm0-f42.google.com with SMTP id n186so137805690wmn.1 for ; Tue, 08 Mar 2016 07:46:07 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=date:from:to:cc:subject:message-id:mime-version:content-disposition :user-agent; bh=sHAfa/ih+GRsomx0Wi5UkfuSq16x891p0Manil0IJUw=; b=T2pGtCcQHJ4YGUe5HGFQm1IxTuR7RzjuEPPN+NsCy2TAaMJl0bi1iYmcbJG3QWOjUX 5VBal5+MT6Tba+qxpp6oleXFC07NpyntKZ7f3vrcCa6WNbNsPGAMj9eNgYqfZpxeOO06 ul9xYIwzkVNz6/z/sBTkrNdZNeePWCaL1jgKc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:date:from:to:cc:subject:message-id:mime-version :content-disposition:user-agent; bh=sHAfa/ih+GRsomx0Wi5UkfuSq16x891p0Manil0IJUw=; b=hC69NDuoY49X4XmzVfjU0p/bclsNlg6dh7BtWYgvEgvDfY2bejAMk1oomr5EoA2aJ0 fRXYFO1FL4Qp+bw7xP5xdruTGWgnbw9aHx6ztMGw/MasxXuP+G2XkKNXYWF9RfdPMlyZ 5U7MA0f0lTILOwSNOQgR8t4bW6GcyQDpF4z0COxcCO91O9J+sDQu9ou1aV/fOvTi2B5g Oa1wcCc+CaIp5zxxea+Q33SigUGz5VyVLX9RhKCyWkYBLkUz5sPh+jpdIGN5gdphshs5 kOd4604bsaHtyqvgF2TAHR6aDE2v7qhEjM/nGtlCRxYm0TbPSFQqOp7ppvn/f6b4vp8H b7zw== X-Gm-Message-State: AD7BkJKW+xXXzaLFOrOE9Qi9EspgOeOvGGwgY083RQ/YPIWblyYUPbno3qlPokzJ5w96/w== X-Received: by 10.194.103.198 with SMTP id fy6mr34240650wjb.48.1457451966768; Tue, 08 Mar 2016 07:46:06 -0800 (PST) Received: from tucsk (pool-dsl-2c-0018.externet.hu. [217.173.44.24]) by smtp.gmail.com with ESMTPSA id e25sm11506686wmi.21.2016.03.08.07.46.05 (version=TLS1 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 08 Mar 2016 07:46:06 -0800 (PST) Date: Tue, 8 Mar 2016 16:47:16 +0100 From: Miklos Szeredi To: linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-nfs@vger.kernel.org Cc: Goldwyn Rodrigues , Trond Myklebust Subject: [PATCH 1/2] vfs: add file_dentry() Message-ID: <20160308154716.GC8655@tucsk> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.21 (2010-09-15) 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 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. Fixes: 4bacc9c9234c ("overlayfs: Make f_path always point to the overlay and f_inode to the underlay") Signed-off-by: Miklos Szeredi Tested-by: Goldwyn Rodrigues Reviewed-by: Trond Myklebust --- fs/open.c | 11 +++++++++++ fs/overlayfs/super.c | 16 ++++++++++++++++ include/linux/dcache.h | 1 + include/linux/fs.h | 2 ++ 4 files changed, 30 insertions(+) -- To unsubscribe from this list: send the line "unsubscribe linux-fsdevel" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1234,6 +1234,8 @@ static inline struct inode *file_inode(c 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); --- a/fs/open.c +++ b/fs/open.c @@ -831,6 +831,17 @@ char *file_path(struct file *filp, char } 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 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -336,14 +336,30 @@ static int ovl_dentry_weak_revalidate(st 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, }; --- 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; /*