linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Amir Goldstein <amir73il@gmail.com>
To: Al Viro <viro@zeniv.linux.org.uk>
Cc: Jan Kara <jack@suse.cz>, Eric Paris <eparis@redhat.com>,
	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	[thread overview]
Message-ID: <1481984434-13293-5-git-send-email-amir73il@gmail.com> (raw)
In-Reply-To: <1481984434-13293-1-git-send-email-amir73il@gmail.com>

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 <amir73il@gmail.com>
---
 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


      parent reply	other threads:[~2016-12-17 14:21 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-17 14:20 [PATCH 0/4] fsnotify: misc cleanups Amir Goldstein
2016-12-17 14:20 ` [PATCH 1/4] fsnotify: pass dentry instead of inode when available Amir Goldstein
2016-12-17 14:20 ` [PATCH 2/4] fsnotify: annotate filename events Amir Goldstein
2016-12-17 14:20 ` [PATCH 3/4] fsnotify: simplify API for " Amir Goldstein
2016-12-17 14:20 ` Amir Goldstein [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1481984434-13293-5-git-send-email-amir73il@gmail.com \
    --to=amir73il@gmail.com \
    --cc=eparis@redhat.com \
    --cc=jack@suse.cz \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).