From patchwork Fri Sep 16 12:19:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 9335669 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 140C86077F for ; Fri, 16 Sep 2016 12:21:51 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 05C5A29F28 for ; Fri, 16 Sep 2016 12:21:51 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EEF6F29F6D; Fri, 16 Sep 2016 12:21:50 +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=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM 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 5E8ED29F28 for ; Fri, 16 Sep 2016 12:21:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S934930AbcIPMVr (ORCPT ); Fri, 16 Sep 2016 08:21:47 -0400 Received: from mail-wm0-f47.google.com ([74.125.82.47]:35819 "EHLO mail-wm0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S934854AbcIPMTm (ORCPT ); Fri, 16 Sep 2016 08:19:42 -0400 Received: by mail-wm0-f47.google.com with SMTP id l132so34535000wmf.0 for ; Fri, 16 Sep 2016 05:19:41 -0700 (PDT) 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:in-reply-to :references; bh=xMg/MYTjWauk7DRtOL0yX5T0aC4r6ReE1Zc+qaBwzzs=; b=QaS5RvfiJ2zEKJhxITBbPGGe9nQa0SKxIzW8vWKwOxJt6ffI1P8EkauykotgDNijIF VsSM2GlX+7kni3aTYBm6Aa4nGX53k4SyQIlcvA2NrMrdgvZRMLV6M4pYAKIQmbRLiqWO ncBRp3cDJcNfVk8ALJfYFb/55yybGh0XhM5900ei5lEOvclKdxS76CIQLabo4FGIDogl /rJtMG5u+lXkPns53KOw0dEE5RoOHIHqmLva5RyIkZ0AcigkxiLMov36haErN2iryclc yw2T69HrwkQdQ8igqVGFGRYHOKbDnIPki6096fiJwBBOJxpjXlgPShMkcHXzOSm6oKIq Jueg== X-Gm-Message-State: AE9vXwPpahbguDUOUUpPmOiKs4PH+RWXp9OfJZSF0trxuiS/evN4hXlxiyXy42ljckAbTnHp X-Received: by 10.28.153.69 with SMTP id b66mr2171738wme.7.1474028380354; Fri, 16 Sep 2016 05:19:40 -0700 (PDT) Received: from veci.piliscsaba.szeredi.hu (4E5CE698.dsl.pool.telekom.hu. [78.92.230.152]) by smtp.gmail.com with ESMTPSA id n7sm8169812wjs.34.2016.09.16.05.19.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Sep 2016 05:19:39 -0700 (PDT) From: Miklos Szeredi To: linux-fsdevel@vger.kernel.org Cc: Aihua Zhang , linux-kernel@vger.kernel.org, Al Viro , Jan Kara , Eric Paris Subject: [PATCH 04/12] fsnotify: support overlayfs Date: Fri, 16 Sep 2016 14:19:23 +0200 Message-Id: <1474028371-21288-5-git-send-email-mszeredi@redhat.com> X-Mailer: git-send-email 2.5.5 In-Reply-To: <1474028371-21288-1-git-send-email-mszeredi@redhat.com> References: <1474028371-21288-1-git-send-email-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 From: Aihua Zhang When an event occurs direct it to the overlay inode instead of the real underlying inode. This will work even if the file was first on the lower layer and then copied up, while the watch is there. This is because the watch is on the overlay inode, which stays the same through the copy-up. For filesystems other than overlayfs this is a no-op, except for the performance impact of an extra pointer dereferece. Verified to work correctly with the inotify/fanotify tests in LTP. Signed-off-by: Aihua Zhang Signed-off-by: Miklos Szeredi Cc: Jan Kara Cc: Eric Paris --- include/linux/fsnotify.h | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index eed9e853a06f..b8bcc058e031 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -29,7 +29,11 @@ static inline int fsnotify_parent(struct path *path, struct dentry *dentry, __u3 static inline int fsnotify_perm(struct file *file, int mask) { struct path *path = &file->f_path; - struct inode *inode = file_inode(file); + /* + * Do not use file_inode() here or anywhere in this file to get the + * inode. That would break *notity on overlayfs. + */ + struct inode *inode = path->dentry->d_inode; __u32 fsnotify_mask = 0; int ret; @@ -173,7 +177,7 @@ static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry) static inline void fsnotify_access(struct file *file) { struct path *path = &file->f_path; - struct inode *inode = file_inode(file); + struct inode *inode = path->dentry->d_inode; __u32 mask = FS_ACCESS; if (S_ISDIR(inode->i_mode)) @@ -191,7 +195,7 @@ static inline void fsnotify_access(struct file *file) static inline void fsnotify_modify(struct file *file) { struct path *path = &file->f_path; - struct inode *inode = file_inode(file); + struct inode *inode = path->dentry->d_inode; __u32 mask = FS_MODIFY; if (S_ISDIR(inode->i_mode)) @@ -209,7 +213,7 @@ static inline void fsnotify_modify(struct file *file) static inline void fsnotify_open(struct file *file) { struct path *path = &file->f_path; - struct inode *inode = file_inode(file); + struct inode *inode = path->dentry->d_inode; __u32 mask = FS_OPEN; if (S_ISDIR(inode->i_mode)) @@ -225,7 +229,7 @@ static inline void fsnotify_open(struct file *file) static inline void fsnotify_close(struct file *file) { struct path *path = &file->f_path; - struct inode *inode = file_inode(file); + struct inode *inode = path->dentry->d_inode; fmode_t mode = file->f_mode; __u32 mask = (mode & FMODE_WRITE) ? FS_CLOSE_WRITE : FS_CLOSE_NOWRITE;