diff mbox

[RFC,2/4] fsnotify: helper to update marks ignored_mask

Message ID 1482867148-31497-3-git-send-email-amir73il@gmail.com (mailing list archive)
State New, archived
Headers show

Commit Message

Amir Goldstein Dec. 27, 2016, 7:32 p.m. UTC
Factor out a helper update_ignored_mask() to update ignored_mask
of inode and vfsmount marks and calculate their combined mask.

With this change, in should_send_to_group() the inode mark mask
is masked with the combined ignored mask, instead of just its own
ignored mask, just like the vfsmount mark mask.

This behavior is similar to the test in fanotify_should_send_event(),
so it does not have any visible effect.

Signed-off-by: Amir Goldstein <amir73il@gmail.com>
---
 fs/notify/fsnotify.c | 38 ++++++++++++++++++++++++++------------
 1 file changed, 26 insertions(+), 12 deletions(-)
diff mbox

Patch

diff --git a/fs/notify/fsnotify.c b/fs/notify/fsnotify.c
index 138e066..b631df5 100644
--- a/fs/notify/fsnotify.c
+++ b/fs/notify/fsnotify.c
@@ -122,6 +122,30 @@  int __fsnotify_parent(const struct path *path, struct dentry *dentry, __u32 mask
 }
 EXPORT_SYMBOL_GPL(__fsnotify_parent);
 
+static __u32 update_ignored_mask(struct fsnotify_mark *inode_mark,
+				 struct fsnotify_mark *vfsmount_mark,
+				 __u32 mask)
+{
+	__u32 ignored_mask = 0;
+
+	/* clear ignored on inode modification */
+	if (mask & FS_MODIFY) {
+		if (inode_mark &&
+		    !(inode_mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY))
+			inode_mark->ignored_mask = 0;
+		if (vfsmount_mark &&
+		    !(vfsmount_mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY))
+			vfsmount_mark->ignored_mask = 0;
+	}
+
+	if (inode_mark)
+		ignored_mask |= inode_mark->ignored_mask;
+	if (vfsmount_mark)
+		ignored_mask |= vfsmount_mark->ignored_mask;
+
+	return ignored_mask;
+}
+
 static int send_to_group(struct inode *to_tell,
 			 struct fsnotify_mark *inode_mark,
 			 struct fsnotify_mark *vfsmount_mark,
@@ -132,29 +156,20 @@  static int send_to_group(struct inode *to_tell,
 	struct fsnotify_group *group = NULL;
 	__u32 inode_test_mask = 0;
 	__u32 vfsmount_test_mask = 0;
-	__u32 ignored_mask = 0;
+	__u32 ignored_mask;
 
 	if (unlikely(!inode_mark && !vfsmount_mark)) {
 		BUG();
 		return 0;
 	}
 
-	/* clear ignored on inode modification */
-	if (mask & FS_MODIFY) {
-		if (inode_mark &&
-		    !(inode_mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY))
-			inode_mark->ignored_mask = 0;
-		if (vfsmount_mark &&
-		    !(vfsmount_mark->flags & FSNOTIFY_MARK_FLAG_IGNORED_SURV_MODIFY))
-			vfsmount_mark->ignored_mask = 0;
-	}
+	ignored_mask = update_ignored_mask(inode_mark, vfsmount_mark, mask);
 
 	/* does the inode mark tell us to do something? */
 	if (inode_mark) {
 		group = inode_mark->group;
 		inode_test_mask = (mask & ~FS_EVENT_ON_CHILD);
 		inode_test_mask &= inode_mark->mask;
-		ignored_mask |= inode_mark->ignored_mask;
 		inode_test_mask &= ~ignored_mask;
 	}
 
@@ -163,7 +178,6 @@  static int send_to_group(struct inode *to_tell,
 		vfsmount_test_mask = (mask & ~FS_EVENT_ON_CHILD);
 		group = vfsmount_mark->group;
 		vfsmount_test_mask &= vfsmount_mark->mask;
-		ignored_mask |= vfsmount_mark->ignored_mask;
 		vfsmount_test_mask &= ~ignored_mask;
 	}