From patchwork Tue Jul 19 12:45:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miklos Szeredi X-Patchwork-Id: 9236981 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 2C32E602F0 for ; Tue, 19 Jul 2016 12:45:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D3A8205A8 for ; Tue, 19 Jul 2016 12:45:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 119A226929; Tue, 19 Jul 2016 12:45:41 +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.9 required=2.0 tests=BAYES_00,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 E8235205A8 for ; Tue, 19 Jul 2016 12:45:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753597AbcGSMpU (ORCPT ); Tue, 19 Jul 2016 08:45:20 -0400 Received: from mail-wm0-f44.google.com ([74.125.82.44]:35785 "EHLO mail-wm0-f44.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753486AbcGSMpS (ORCPT ); Tue, 19 Jul 2016 08:45:18 -0400 Received: by mail-wm0-f44.google.com with SMTP id f65so137640873wmi.0 for ; Tue, 19 Jul 2016 05:45:18 -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; bh=4CfWNoCtkuHuQt5bVmaoGBmZjJFUg8fJVeop68wlFFY=; b=iFvgK+GYoxuYhm8k/lynABtJBbmSUR44hcjhtl9iu2wQb0V4OIZ+hTRHH7mjgeSZP1 2Bm7G3Ws3Ad7OCdQSvmcsITZjyqAxXAegzfSp/IxokwFUGZbwvbmsEX3MMQY87AjZyKv 7btX6WD/Duy2EH121PBI2ufvZIgYEseYStmpP4MXA/vB3hO2dypxIi2aI3YhS/KJg7VM z8OPp8G3WiKQxq+efLt92ok6uQZxA/QSaZlv2luSL+NtNlbNrEk8igryiCZqVH8fspJF 0AELmfN/xqrD/+o/6F9KjS5fwophjNUhV4Ff79iMb/aAixP6QOB3LH5IYQb3pClBOXxw JjQQ== X-Gm-Message-State: ALyK8tKee42QsfwT7WyaZHpSsS1kYdQPEsWlia1keFLzRqnVWeb39wC0w3UQFck9+p8iATlX X-Received: by 10.28.158.87 with SMTP id h84mr4014037wme.43.1468932317395; Tue, 19 Jul 2016 05:45:17 -0700 (PDT) Received: from veci.piliscsaba.szeredi.hu (563B8D07.dsl.pool.telekom.hu. [86.59.141.7]) by smtp.gmail.com with ESMTPSA id i66sm22682029wmg.9.2016.07.19.05.45.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 19 Jul 2016 05:45:16 -0700 (PDT) From: Miklos Szeredi To: Eric Paris , Al Viro Cc: linux-unionfs@vger.kernel.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Aihua Zhang Subject: [RFC PATCH] fsnotify: support overlayfs Date: Tue, 19 Jul 2016 14:45:15 +0200 Message-Id: <1468932315-27384-1-git-send-email-mszeredi@redhat.com> X-Mailer: git-send-email 2.5.5 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 --- 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 0141f257d67b..bca822bb3ce3 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; @@ -185,7 +189,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)) @@ -203,7 +207,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)) @@ -221,7 +225,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)) @@ -237,7 +241,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;