From patchwork Thu Jan 10 17:04:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amir Goldstein X-Patchwork-Id: 10756287 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CEF2813BF for ; Thu, 10 Jan 2019 17:05:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B9CE429AC2 for ; Thu, 10 Jan 2019 17:05:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ADEFF29D01; Thu, 10 Jan 2019 17:05:13 +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=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI 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 3F8DA29AC2 for ; Thu, 10 Jan 2019 17:05:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729256AbfAJRFM (ORCPT ); Thu, 10 Jan 2019 12:05:12 -0500 Received: from mail-wr1-f65.google.com ([209.85.221.65]:41928 "EHLO mail-wr1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729240AbfAJRFM (ORCPT ); Thu, 10 Jan 2019 12:05:12 -0500 Received: by mail-wr1-f65.google.com with SMTP id x10so12199963wrs.8 for ; Thu, 10 Jan 2019 09:05:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qddB0e7rz0R06Lt2FEgpJdHOIx510I9h425BmQU+sPc=; b=dmWXMr2PKayVuof2qMWQ72MMd+XOhTR75/TlUbYqKwC1NWm+dGClpHzkaqrdo3jTil 5hq+2A//xsu1tf4aFiRs70hKCtVFTCLmVJurvd3kH2j6ZYOQvxjM92yStQC6QdfvYoPS /JAOeSqWYlaGKAhfxZbwoEzG3k7NoDPxQwmvXQCf02DGViK/5PzhTcl/FEjhRqS2nhoa J9GuuDVjd0jndzyJ77dWMdWugPlJdqb+ODFwUl5lm72zSeJbw+B2x9YoZW45hmIOStkd qTuWBy/31fXEmhV+OOlLusptQwM/3nzyBcUTEJb9a9DnPPWgV6uqyvI6+akrFfmj/eaK 9s+w== 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=qddB0e7rz0R06Lt2FEgpJdHOIx510I9h425BmQU+sPc=; b=elhzXbiAy6dh3fJNqNfXaaoIEMXiJOgGNAKvRMCyrJTnJHumU0GhJQa/tmceOis4zg /GTCmLxObIThHgRwbz0fVy4CmWFj4abeK8FoikULDSDsETKOzqXiAbZZZdO6BqZ1uJBx gDS1IUfynT37xP2X0cJTgqn+9p59BXtspkwxDno6d73ecY2i0Anie7a+FAILghw2WtTX NfHGE8htM4nkmHNz6RBSqng4E3gIiXYf022D5QTF6zZJXQRTjVJzFVAH1rPlwXD5xuKg 3NVTPZlif5Z4mwvPXTbddYcZeij3+c4BJntwNDwlPsWQSr/98PKdYES9raqaFSaQShbS 4Z/Q== X-Gm-Message-State: AJcUukdwsrFQwZOyunsY5MLtNakEePqpHBd5uDYskIbeTYKeSrO/fnN8 EwDEZbNCRMgXXOTfWAf0z+T1DTR3 X-Google-Smtp-Source: ALg8bN4XV0o/PMn7ZosWVAuJ8o0rJq07mQYh6MJtk/OW6IkOJULCjVe+zo4E6WU7/tjLNGK3Oxr9+A== X-Received: by 2002:adf:f703:: with SMTP id r3mr9797558wrp.93.1547139909673; Thu, 10 Jan 2019 09:05:09 -0800 (PST) Received: from amir-VirtualBox.ctera.local ([188.120.129.201]) by smtp.gmail.com with ESMTPSA id m4sm5725868wmi.3.2019.01.10.09.05.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 10 Jan 2019 09:05:09 -0800 (PST) From: Amir Goldstein To: Jan Kara Cc: Matthew Bobrowski , linux-fsdevel@vger.kernel.org Subject: [PATCH v5 13/17] fsnotify: report FS_ISDIR flag with MOVE_SELF and DELETE_SELF events Date: Thu, 10 Jan 2019 19:04:40 +0200 Message-Id: <20190110170444.30616-14-amir73il@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190110170444.30616-1-amir73il@gmail.com> References: <20190110170444.30616-1-amir73il@gmail.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 We need to report FS_ISDIR flag with MOVE_SELF and DELETE_SELF events for fanotify, because fanotify API requires the user to explicitly request events on directories by FAN_ONDIR flag. inotify never reported IN_ISDIR with those events. It looks like an oversight, but to avoid the risk of breaking existing inotify programs, mask the FS_ISDIR flag out when reprting those events to inotify backend. We also add the FS_ISDIR flag with FS_ATTRIB event in the case of rename over an empty target directory. inotify did not report IN_ISDIR in this case, but it normally does report IN_ISDIR along with IN_ATTRIB event, so in this case, we do not mask out the FS_ISDIR flag. Signed-off-by: Amir Goldstein --- fs/notify/inotify/inotify_fsnotify.c | 9 +++++++++ include/linux/fsnotify.h | 23 +++++++++++++++++++---- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c index fe97299975f2..ff30abd6a49b 100644 --- a/fs/notify/inotify/inotify_fsnotify.c +++ b/fs/notify/inotify/inotify_fsnotify.c @@ -113,6 +113,15 @@ int inotify_handle_event(struct fsnotify_group *group, return -ENOMEM; } + /* + * We now report FS_ISDIR flag with MOVE_SELF and DELETE_SELF events + * for fanotify. inotify never reported IN_ISDIR with those events. + * It looks like an oversight, but to avoid the risk of breaking + * existing inotify programs, mask the flag out from those events. + */ + if (mask & (IN_MOVE_SELF | IN_DELETE_SELF)) + mask &= ~IN_ISDIR; + fsn_event = &event->fse; fsnotify_init_event(fsn_event, inode); event->mask = mask; diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 116907928c7f..bec2e8f66012 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -87,7 +87,12 @@ static inline int fsnotify_perm(struct file *file, int mask) */ static inline void fsnotify_link_count(struct inode *inode) { - fsnotify(inode, FS_ATTRIB, inode, FSNOTIFY_EVENT_INODE, NULL, 0); + __u32 mask = FS_ATTRIB; + + if (S_ISDIR(inode->i_mode)) + mask |= FS_ISDIR; + + fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); } /* @@ -95,12 +100,14 @@ static inline void fsnotify_link_count(struct inode *inode) */ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, const unsigned char *old_name, - int isdir, struct inode *target, struct dentry *moved) + int isdir, struct inode *target, + struct dentry *moved) { struct inode *source = moved->d_inode; u32 fs_cookie = fsnotify_get_cookie(); __u32 old_dir_mask = FS_MOVED_FROM; __u32 new_dir_mask = FS_MOVED_TO; + __u32 mask = FS_MOVE_SELF; const unsigned char *new_name = moved->d_name.name; if (old_dir == new_dir) @@ -111,6 +118,9 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, new_dir_mask |= FS_ISDIR; } + if (d_is_dir(moved)) + mask |= FS_ISDIR; + fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name, fs_cookie); fsnotify(new_dir, new_dir_mask, source, FSNOTIFY_EVENT_INODE, new_name, @@ -120,7 +130,7 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, fsnotify_link_count(target); if (source) - fsnotify(source, FS_MOVE_SELF, moved->d_inode, FSNOTIFY_EVENT_INODE, NULL, 0); + fsnotify(source, mask, source, FSNOTIFY_EVENT_INODE, NULL, 0); audit_inode_child(new_dir, moved, AUDIT_TYPE_CHILD_CREATE); } @@ -197,7 +207,12 @@ static inline void fsnotify_nameremove(struct dentry *dentry, int isdir) */ static inline void fsnotify_inoderemove(struct inode *inode) { - fsnotify(inode, FS_DELETE_SELF, inode, FSNOTIFY_EVENT_INODE, NULL, 0); + __u32 mask = FS_DELETE_SELF; + + if (S_ISDIR(inode->i_mode)) + mask |= FS_ISDIR; + + fsnotify(inode, mask, inode, FSNOTIFY_EVENT_INODE, NULL, 0); __fsnotify_inode_delete(inode); }