From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wj0-f195.google.com ([209.85.210.195]:35662 "EHLO mail-wj0-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1755570AbcLQOVJ (ORCPT ); Sat, 17 Dec 2016 09:21:09 -0500 Received: by mail-wj0-f195.google.com with SMTP id he10so17974258wjc.2 for ; Sat, 17 Dec 2016 06:21:02 -0800 (PST) From: Amir Goldstein To: Al Viro Cc: Jan Kara , Eric Paris , linux-fsdevel@vger.kernel.org Subject: [PATCH 2/4] fsnotify: annotate filename events Date: Sat, 17 Dec 2016 16:20:32 +0200 Message-Id: <1481984434-13293-3-git-send-email-amir73il@gmail.com> In-Reply-To: <1481984434-13293-1-git-send-email-amir73il@gmail.com> References: <1481984434-13293-1-git-send-email-amir73il@gmail.com> Sender: linux-fsdevel-owner@vger.kernel.org List-ID: Filename events are referring to events that modify directory entries, such as create,delete,rename. Those events should always be reported on a watched directory, regardless if FS_EVENT_ON_CHILD is set on the watch mask. fsnotify_nameremove() and fsnotify_move() were modified to no longer set the FS_EVENT_ON_CHILD event bit. This is a semantic change to align with the filename event definition. It has no effect on any existing backend, because dnotify and inotify always requets the child events and fanotify does not get the delete,rename events. The fsnotify_filename() helper is used to report all the filename events. It gets a reference on parent dentry and passes it as the data for the event along with the filename. fsnotify_filename() is different from fsnotify_parent(). fsnotify_parent() is intended to report any events that happened on child inodes when FS_EVENT_ON_CHILD is requested. fsnotify_filename() is intended to report only filename events, such as create,mkdir,link. Those events must always be reported on a watched directory, regardless if FS_EVENT_ON_CHILD was requested. fsnotify_d_name() is a helper for the common case where the filename to pass is dentry->d_name.name. It is safe to use these helpers with negative or not instantiated dentries, such as the case with fsnotify_link() and fsnotify_nameremove(). Signed-off-by: Amir Goldstein --- include/linux/fsnotify.h | 37 +++++++++++++++++++++++++++++-------- 1 file changed, 29 insertions(+), 8 deletions(-) diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 86244c5..ef54e8f 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -25,6 +25,28 @@ static inline int fsnotify_parent(const struct path *path, struct dentry *dentry return __fsnotify_parent(path, dentry, mask); } +/* + * Notify this parent about a filename event (create,delete,rename). + * Unlike fsnotify_parent(), the event will be reported regardless of the + * FS_EVENT_ON_CHILD mask on the parent inode + */ +static inline int fsnotify_filename(struct dentry *parent, __u32 mask, + const unsigned char *file_name, u32 cookie) +{ + return fsnotify(d_inode(parent), mask, parent, FSNOTIFY_EVENT_DENTRY, + file_name, cookie); +} + +/* + * Call fsnotify_filename() with parent and d_name of this dentry. + * Safe to call with negative dentry, e.g. from fsnotify_nameremove() + */ +static inline int fsnotify_d_name(struct dentry *dentry, __u32 mask) +{ + return fsnotify_filename(dentry->d_parent, mask, + dentry->d_name.name, 0); +} + /* simple call site for access decisions */ static inline int fsnotify_perm(struct file *file, int mask) { @@ -72,8 +94,8 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, { struct inode *source = moved->d_inode; u32 fs_cookie = fsnotify_get_cookie(); - __u32 old_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_FROM); - __u32 new_dir_mask = (FS_EVENT_ON_CHILD | FS_MOVED_TO); + __u32 old_dir_mask = FS_MOVED_FROM; + __u32 new_dir_mask = FS_MOVED_TO; const unsigned char *new_name = moved->d_name.name; if (old_dir == new_dir) @@ -86,8 +108,7 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name, fs_cookie); - fsnotify(new_dir, new_dir_mask, moved, FSNOTIFY_EVENT_DENTRY, new_name, - fs_cookie); + fsnotify_filename(moved->d_parent, new_dir_mask, new_name, fs_cookie); if (target) fsnotify_link_count(target); @@ -123,7 +144,7 @@ static inline void fsnotify_nameremove(struct dentry *dentry, int isdir) if (isdir) mask |= FS_ISDIR; - fsnotify_parent(NULL, dentry, mask); + fsnotify_d_name(dentry, mask); } /* @@ -142,7 +163,7 @@ static inline void fsnotify_create(struct inode *inode, struct dentry *dentry) { audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE); - fsnotify(inode, FS_CREATE, dentry, FSNOTIFY_EVENT_DENTRY, dentry->d_name.name, 0); + fsnotify_d_name(dentry, FS_CREATE); } /* @@ -155,7 +176,7 @@ static inline void fsnotify_link(struct inode *dir, struct inode *inode, struct fsnotify_link_count(inode); audit_inode_child(dir, new_dentry, AUDIT_TYPE_CHILD_CREATE); - fsnotify(dir, FS_CREATE, new_dentry, FSNOTIFY_EVENT_DENTRY, new_dentry->d_name.name, 0); + fsnotify_d_name(new_dentry, FS_CREATE); } /* @@ -167,7 +188,7 @@ static inline void fsnotify_mkdir(struct inode *inode, struct dentry *dentry) audit_inode_child(inode, dentry, AUDIT_TYPE_CHILD_CREATE); - fsnotify(inode, mask, dentry, FSNOTIFY_EVENT_DENTRY, dentry->d_name.name, 0); + fsnotify_d_name(dentry, mask); } /* -- 2.7.4