From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wj0-f196.google.com ([209.85.210.196]:36140 "EHLO mail-wj0-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1754121AbcLQOVH (ORCPT ); Sat, 17 Dec 2016 09:21:07 -0500 Received: by mail-wj0-f196.google.com with SMTP id j10so17946321wjb.3 for ; Sat, 17 Dec 2016 06:21:06 -0800 (PST) From: Amir Goldstein To: Al Viro Cc: Jan Kara , Eric Paris , linux-fsdevel@vger.kernel.org Subject: [PATCH 4/4] fsnotify: make MOVED_FROM a dentry event Date: Sat, 17 Dec 2016 16:20:34 +0200 Message-Id: <1481984434-13293-5-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: Propagate old/new parent dentries to fsnotify_move() and pass old parent dentry as FSNOTIFY_DENTRY info of MOVED_FROM event. This change has no effect on current backends. Soon, this will allow fanotify backend to get MOVED_FROM events. Signed-off-by: Amir Goldstein --- fs/debugfs/inode.c | 2 +- fs/namei.c | 7 +++++-- include/linux/fsnotify.h | 18 ++++++++++-------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c index c83336f..a6fb6ae 100644 --- a/fs/debugfs/inode.c +++ b/fs/debugfs/inode.c @@ -754,7 +754,7 @@ struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry, goto exit; } d_move(old_dentry, dentry); - fsnotify_move(d_inode(old_dir), d_inode(new_dir), old_name, + fsnotify_move(old_dir, new_dir, old_name, d_is_dir(old_dentry), NULL, old_dentry); fsnotify_oldname_free(old_name); diff --git a/fs/namei.c b/fs/namei.c index 706b685..f951680 100644 --- a/fs/namei.c +++ b/fs/namei.c @@ -4300,6 +4300,8 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry, int error; bool is_dir = d_is_dir(old_dentry); const unsigned char *old_name; + struct dentry *old_parent = old_dentry->d_parent; + struct dentry *new_parent = new_dentry->d_parent; struct inode *source = old_dentry->d_inode; struct inode *target = new_dentry->d_inode; bool new_is_dir = false; @@ -4405,10 +4407,11 @@ int vfs_rename(struct inode *old_dir, struct dentry *old_dentry, inode_unlock(target); dput(new_dentry); if (!error) { - fsnotify_move(old_dir, new_dir, old_name, is_dir, + fsnotify_move(old_parent, new_parent, old_name, is_dir, !(flags & RENAME_EXCHANGE) ? target : NULL, old_dentry); if (flags & RENAME_EXCHANGE) { - fsnotify_move(new_dir, old_dir, old_dentry->d_name.name, + fsnotify_move(new_parent, old_parent, + old_dentry->d_name.name, new_is_dir, NULL, new_dentry); } } diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h index 93efa8c..7a98370 100644 --- a/include/linux/fsnotify.h +++ b/include/linux/fsnotify.h @@ -94,17 +94,19 @@ static inline void fsnotify_link_count(struct inode *inode) /* * fsnotify_move - file old_name at old_dir was moved to new_name at new_dir */ -static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, +static inline void fsnotify_move(struct dentry *old_dir, + struct dentry *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; + struct inode *source = d_inode(moved); u32 fs_cookie = fsnotify_get_cookie(); __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) + if (d_inode(old_dir) == d_inode(new_dir)) old_dir_mask |= FS_DN_RENAME; if (isdir) { @@ -112,15 +114,15 @@ static inline void fsnotify_move(struct inode *old_dir, struct inode *new_dir, new_dir_mask |= FS_ISDIR; } - fsnotify(old_dir, old_dir_mask, source, FSNOTIFY_EVENT_INODE, old_name, - fs_cookie); - fsnotify_filename(moved->d_parent, new_dir_mask, new_name, fs_cookie); + fsnotify_filename(old_dir, old_dir_mask, old_name, fs_cookie); + fsnotify_filename(new_dir, new_dir_mask, new_name, fs_cookie); if (target) fsnotify_link_count(target); if (source) - fsnotify(source, FS_MOVE_SELF, moved, FSNOTIFY_EVENT_DENTRY, NULL, 0); + fsnotify(source, FS_MOVE_SELF, moved, FSNOTIFY_EVENT_DENTRY, + NULL, 0); audit_dentry_child(moved, AUDIT_TYPE_CHILD_CREATE); } -- 2.7.4