Received: by 10.192.165.156 with SMTP id m28csp2077025imm; Thu, 12 Apr 2018 08:14:17 -0700 (PDT) X-Google-Smtp-Source: AIpwx4/5Ae248Iz1udWbVzf3RuOPSHW4qNEWwvmjhqKpJ4hRbOj2hj32LEvotj8ki/WVu5cXx2Qs X-Received: by 10.98.223.149 with SMTP id d21mr8003996pfl.160.1523546057625; Thu, 12 Apr 2018 08:14:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1523546057; cv=none; d=google.com; s=arc-20160816; b=txN9PsIZJ24bDItT5iX2Hxv6unrzi6CCybt0ei5YFgfkSMA8zy7HjFii9EZGTgzpqu 3AdVpbnrddrEz37nyaQOmtCuWSFLwiFr+K0ESV+vEK+Ho5cPeySpoIXvR/5GLlRaxvx3 93HTOrrYCp3edoqh7rG+vvCiEJkV7J5JQ9kNjK+GGBvMp15F9O961J9XQmFZ1zRzK/aK uZvIE3ptkVhTta6wBBfKlvM3FG8pxpwsw0cTjNgiEFj2AUGciwRW+sRpnMUo5cIkMw2t 1DAbp/GEZrL4T9zILIS/9kLmUev7bOqe84v3hvL1c8P9h4K5npAFWDyl6DattkuyrKRm KEXA== 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=CvhR/oadaCpZCNvQReZrrMqHNnaft5G6TkMG4851fyc=; b=srQL4tousGZJrV2W7QGanAg/NDllsuzoX3qs5wC1N0BG7h3EcDGcY3hHpu6eQ4f3eN W0DP96M2mAZLpMik2bd84LbDr9sWaaW9lQ9sthrA/1g05WL2/uKq1+hmHkkYDRX1mmnF k4EGI74t2AjFhJFfFIB+2ByMd5Hyc4FrRapPKUfK88nSQU9F2548ApUONUc67SGXcL/j /D4xia/zFtNw7xd3BNY/ggOv9A/ujzbu0Y5msB0Fj9kpP7yW2elrmzZzxwzELIzwBA6F WW5ELQwzPyxZlIikBJAHnaM+II8sOk7eya7aSJwYMQhfqscrmAt8fP5a4Dg0CQBIIvX2 xdYQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 13si2737006pfm.246.2018.04.12.08.13.40; Thu, 12 Apr 2018 08:14:17 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753924AbeDLPKJ (ORCPT + 99 others); Thu, 12 Apr 2018 11:10:09 -0400 Received: from mail-wr0-f193.google.com ([209.85.128.193]:33591 "EHLO mail-wr0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753765AbeDLPJM (ORCPT ); Thu, 12 Apr 2018 11:09:12 -0400 Received: by mail-wr0-f193.google.com with SMTP id z73so5472966wrb.0 for ; Thu, 12 Apr 2018 08:09:11 -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=CvhR/oadaCpZCNvQReZrrMqHNnaft5G6TkMG4851fyc=; b=GnCfBt6Us8uEyzYHR4yOWatzLO3uOQGVF2v2nQdZcxPbsVXyO1jx2uX5rQKqzPA8UK nkGMZ7VbOD8QJpaarz3d2ZqhSTaH/Xhf81BUijx6/UzV66UxrcFWMp0wu6H6d9HDVY6J 2ZXdpA5GsdAAFM8MFM6WTqNIgyxPtJ3S48dGrcwsz3ymQfNTdU6YUSRUrf0znIJu75KQ Dn8T1K/vpBjD8GHGrFjDhQ2id/WS3/28lcTLZJAxo06TNu6zvctIqbn4N5H7YyTAVy5L SWtr+m4PmivvuSRsHSKuO73SFT99SBM6Cag46g/zu3HOJ7BEe7IHkAQdSPpD/efZUa/s qidw== X-Gm-Message-State: ALQs6tCyLo1AIOJKD7K60Y//q5dGc/0MPQkePJS0Mgo2+KJBYaja9w5V 0mCEg1s3XY90Ue54vByfmasRnQ== X-Received: by 10.223.132.229 with SMTP id 92mr1194783wrg.46.1523545751168; Thu, 12 Apr 2018 08:09:11 -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.09.10 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 12 Apr 2018 08:09:10 -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 34/35] vfs: simplify d_op->d_real() Date: Thu, 12 Apr 2018 17:08:25 +0200 Message-Id: <20180412150826.20988-35-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-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The only remaining user of d_real() is file_dentry(). Simplify code related to ->d_real() by: - remove dead code from overlayfs implementation - remove the open_flags argument - expand d_real() helper into file_dentry() - remove d_real() helper, since there are no callers and makes no sense to add new ones Signed-off-by: Miklos Szeredi --- Documentation/filesystems/Locking | 3 +-- Documentation/filesystems/vfs.txt | 22 +++------------- fs/overlayfs/super.c | 55 +++++++-------------------------------- include/linux/dcache.h | 24 +---------------- include/linux/fs.h | 7 ++++- 5 files changed, 21 insertions(+), 90 deletions(-) diff --git a/Documentation/filesystems/Locking b/Documentation/filesystems/Locking index a4afe96f0112..e1d7e43d302c 100644 --- a/Documentation/filesystems/Locking +++ b/Documentation/filesystems/Locking @@ -21,8 +21,7 @@ prototypes: char *(*d_dname)((struct dentry *dentry, char *buffer, int buflen); struct vfsmount *(*d_automount)(struct path *path); int (*d_manage)(const struct path *, bool); - struct dentry *(*d_real)(struct dentry *, const struct inode *, - unsigned int); + struct dentry *(*d_real)(struct dentry *, const struct inode *); locking rules: rename_lock ->d_lock may block rcu-walk diff --git a/Documentation/filesystems/vfs.txt b/Documentation/filesystems/vfs.txt index af54d3651ff8..632d5c58fde9 100644 --- a/Documentation/filesystems/vfs.txt +++ b/Documentation/filesystems/vfs.txt @@ -990,8 +990,7 @@ struct dentry_operations { char *(*d_dname)(struct dentry *, char *, int); struct vfsmount *(*d_automount)(struct path *); int (*d_manage)(const struct path *, bool); - struct dentry *(*d_real)(struct dentry *, const struct inode *, - unsigned int); + struct dentry *(*d_real)(struct dentry *, const struct inode *); }; d_revalidate: called when the VFS needs to revalidate a dentry. This @@ -1124,23 +1123,8 @@ struct dentry_operations { This function is only used if DCACHE_MANAGE_TRANSIT is set on the dentry being transited from. - d_real: overlay/union type filesystems implement this method to return one of - the underlying dentries hidden by the overlay. It is used in three - different modes: - - Called from open it may need to copy-up the file depending on the - supplied open flags. This mode is selected with a non-zero flags - argument. In this mode the d_real method can return an error. - - Called from file_dentry() it returns the real dentry matching the inode - argument. The real dentry may be from a lower layer already copied up, - but still referenced from the file. This mode is selected with a - non-NULL inode argument. This will always succeed. - - With NULL inode and zero flags the topmost real underlying dentry is - returned. This will always succeed. - - This method is never called with both non-NULL inode and non-zero flags. + d_real: This is called from file_dentry(). It returns the real dentry + matching the inode argument. Each dentry has a pointer to its parent dentry, as well as a hash list of child dentries. Child dentries are basically like files in a diff --git a/fs/overlayfs/super.c b/fs/overlayfs/super.c index f2a83fabe2eb..ab1642fcece3 100644 --- a/fs/overlayfs/super.c +++ b/fs/overlayfs/super.c @@ -80,64 +80,29 @@ static void ovl_dentry_release(struct dentry *dentry) } } -static int ovl_check_append_only(struct inode *inode, int flag) -{ - /* - * This test was moot in vfs may_open() because overlay inode does - * not have the S_APPEND flag, so re-check on real upper inode - */ - if (IS_APPEND(inode)) { - if ((flag & O_ACCMODE) != O_RDONLY && !(flag & O_APPEND)) - return -EPERM; - if (flag & O_TRUNC) - return -EPERM; - } - - return 0; -} - static struct dentry *ovl_d_real(struct dentry *dentry, - const struct inode *inode, - unsigned int open_flags) + const struct inode *inode) { struct dentry *real; - int err; + + if (WARN_ON(!inode)) + return dentry; /* It's an overlay file */ - if (inode && d_inode(dentry) == inode) + if (d_inode(dentry) == inode) return dentry; - if (!d_is_reg(dentry)) { - if (!inode || inode == d_inode(dentry)) - return dentry; + if (!d_is_reg(dentry)) goto bug; - } - if (open_flags) { - err = ovl_open_maybe_copy_up(dentry, open_flags); - if (err) - return ERR_PTR(err); - } - - real = ovl_dentry_upper(dentry); - if (real && (!inode || inode == d_inode(real))) { - if (!inode) { - err = ovl_check_append_only(d_inode(real), open_flags); - if (err) - return ERR_PTR(err); - } + real = ovl_dentry_real(dentry); + if (inode == d_inode(real)) return real; - } - - real = ovl_dentry_lower(dentry); - if (!real) - goto bug; /* Handle recursion */ - real = d_real(real, inode, open_flags); + if (unlikely(real->d_flags & DCACHE_OP_REAL)) + return real->d_op->d_real(real, inode); - if (!inode || inode == d_inode(real)) - return real; bug: WARN(1, "ovl_d_real(%pd4, %s:%lu): real dentry not found\n", dentry, inode ? inode->i_sb->s_id : "NULL", inode ? inode->i_ino : 0); diff --git a/include/linux/dcache.h b/include/linux/dcache.h index 129ef05759a9..712cc21c2e6d 100644 --- a/include/linux/dcache.h +++ b/include/linux/dcache.h @@ -147,8 +147,7 @@ struct dentry_operations { char *(*d_dname)(struct dentry *, char *, int); struct vfsmount *(*d_automount)(struct path *); int (*d_manage)(const struct path *, bool); - struct dentry *(*d_real)(struct dentry *, const struct inode *, - unsigned int); + struct dentry *(*d_real)(struct dentry *, const struct inode *); } ____cacheline_aligned; /* @@ -565,27 +564,6 @@ static inline struct dentry *d_backing_dentry(struct dentry *upper) return upper; } -/** - * d_real - Return the real dentry - * @dentry: the dentry to query - * @inode: inode to select the dentry from multiple layers (can be NULL) - * @flags: open flags to control copy-up behavior - * - * If dentry is on a union/overlay, then return the underlying, real dentry. - * Otherwise return the dentry itself. - * - * See also: Documentation/filesystems/vfs.txt - */ -static inline struct dentry *d_real(struct dentry *dentry, - const struct inode *inode, - unsigned int flags) -{ - if (unlikely(dentry->d_flags & DCACHE_OP_REAL)) - return dentry->d_op->d_real(dentry, inode, flags); - else - return dentry; -} - struct name_snapshot { const unsigned char *name; unsigned char inline_name[DNAME_INLINE_LEN]; diff --git a/include/linux/fs.h b/include/linux/fs.h index 6db6e83004d6..77403c19dc69 100644 --- a/include/linux/fs.h +++ b/include/linux/fs.h @@ -1234,7 +1234,12 @@ static inline struct inode *file_inode(const struct file *f) static inline struct dentry *file_dentry(const struct file *file) { - return d_real(file->f_path.dentry, file_inode(file), 0); + struct dentry *dentry = file->f_path.dentry; + + if (unlikely(dentry->d_flags & DCACHE_OP_REAL)) + return dentry->d_op->d_real(dentry, file_inode(file)); + else + return dentry; } static inline int locks_lock_file_wait(struct file *filp, struct file_lock *fl) -- 2.14.3