Skip to contentSkip to conversation

fanotify: fastpath to ignore certain in core inodes

RFC In review Eric Paris 1 participant 1 message Sep 26, 2008

Subsystems (3)
lore
Share & tools
lore

Eric Paris

author
#0 lore raw

RFC 5/11 fanotify: fastpath to ignore certain in core inodes

fanotify: fastpath to ignore certain in core inodes

From: Eric Paris <[email protected]>

Allows a process to ignore certain events for the given in core inodes. This does not preclude the need to keep a userspace or xattr based cache if a fanotifier listener wants something with a different lifetime than in core inode.

---

 fs/inode.c                |    6 +
 fs/notify/Makefile        |    2 
 fs/notify/fanotify.c      |   22 +++++
 fs/notify/fanotify.h      |   43 +++++++++
 fs/notify/fastpath.c      |  204 +++++++++++++++++++++++++++++++++++++++++++++
 fs/notify/fastpath_user.c |  159 +++++++++++++++++++++++++++++++++++
 fs/notify/group.c         |    9 ++
 include/linux/fanotify.h  |    5 +
 include/linux/fs.h        |    5 +
 include/linux/fsnotify.h  |    8 ++
 10 files changed, 462 insertions(+), 1 deletions(-)
 create mode 100644 fs/notify/fastpath.c
 create mode 100644 fs/notify/fastpath_user.c
fs/inode.c +6 -0
index 0487ddb..cc802ae 100644
@@ -21,6 +21,7 @@
 #include <linux/cdev.h>
 #include <linux/bootmem.h>
 #include <linux/inotify.h>
+#include <linux/fsnotify.h>
 #include <linux/mount.h>
 
 /*
@@ -183,6 +184,10 @@ static struct inode *alloc_inode(struct super_block *sb)
 		}
 		inode->i_private = NULL;
 		inode->i_mapping = mapping;
+#ifdef CONFIG_FANOTIFY
+		INIT_LIST_HEAD(&inode->fastpath_entries);
+		rwlock_init(&inode->fastpath_rwlock);
+#endif
 	}
 	return inode;
 }
@@ -191,6 +196,7 @@ void destroy_inode(struct inode *inode)
 {
 	BUG_ON(inode_has_buffers(inode));
 	security_inode_free(inode);
+	fsnotify_inode_delete(inode);
 	if (inode->i_sb->s_op->destroy_inode)
 		inode->i_sb->s_op->destroy_inode(inode);
 	else
fs/notify/Makefile +1 -1
index 01915f7..8fac822 100644
@@ -3,4 +3,4 @@ obj-$(CONFIG_INOTIFY_USER)	+= inotify_user.o
 
 obj-$(CONFIG_DNOTIFY)		+= dnotify.o
 
-obj-$(CONFIG_FANOTIFY)		+= fanotify.o notification.o notification_user.o group.o group_user.o info_user.o
+obj-$(CONFIG_FANOTIFY)		+= fanotify.o notification.o notification_user.o group.o group_user.o info_user.o fastpath.o fastpath_user.o
fs/notify/fanotify.c +22 -0
index d3ee8d1..c7aa1ad 100644
@@ -35,6 +35,15 @@
 
 struct dentry *fanotify_fs_root;
 
+void fanotify_inode_delete(struct inode *inode)
+{
+	if (likely(list_empty(&groups)))
+		return;
+
+	fanotify_fastpath_clear(inode);
+}
+EXPORT_SYMBOL_GPL(fanotify_inode_delete);
+
 void fanotify(struct file *file, unsigned int mask)
 {
 	struct fanotify_group *group;
@@ -52,6 +61,8 @@ void fanotify(struct file *file, unsigned int mask)
 	if (!S_ISREG(inode->i_mode))
 		return;
 
+	if (mask & FAN_MODIFY)
+		fanotify_fastpath_clear(inode);
 	/*
 	 * SRCU!!  the groups list is very very much read only and the path is
 	 * very hot (assuming something is using fanotify)  Not blocking while
@@ -67,6 +78,8 @@ void fanotify(struct file *file, unsigned int mask)
 	idx = srcu_read_lock(&groups_srcu_struct);
 	list_for_each_entry_rcu(group, &groups, group_list) {
 		if (mask & group->mask) {
+			if (is_fastpath(file, mask, group))
+				continue;
 			if (!event) {
 				event = create_event(file, mask);
 				/* shit, we OOM'd and now we can't tell, lets hope something else blows up */
@@ -112,6 +125,15 @@ static __init int fanotify_init(void)
 		return rc;
 	}
 
+	rc = fastpath_init();
+	if (rc) {
+		fanotify_notification_uninit();
+		fanotify_register_uninit();
+		securityfs_remove(fanotify_fs_root);
+		fanotify_fs_root = NULL;
+		return rc;
+	}
+
 	return 0;
 }
 __initcall(fanotify_init);
fs/notify/fanotify.h +43 -0

65 lines not on this page · raw message

fs/notify/fastpath.c new file +204 -0

204 lines not on this page · raw message

fs/notify/fastpath_user.c new file +159 -0

159 lines not on this page · raw message

fs/notify/group.c +9 -0
index 926d0a4..dc23127 100644
@@ -47,6 +47,8 @@ void fanotify_kill_group(struct fanotify_group *group)
 	fanotify_notification_user_destroy(group);
 	fanotify_info_user_destroy(group);
 
+	fanotify_fastpath_user_destroy(group);
+
 	securityfs_remove(group->subdir);
 	group->subdir = NULL;
 
@@ -112,12 +114,18 @@ int fanotify_register_group(char *name, unsigned int mask)
 	if (rc)
 		goto out_clean_notification;
 
+	rc = fanotify_fastpath_user_create(group);
+	if (rc)
+		goto out_clean_info;
+
 	/* add it */
 	list_add_rcu(&group->group_list, &groups);
 	mutex_unlock(&groups_mutex);
 
 	return 0;
 
+out_clean_info:
+	fanotify_info_user_destroy(group);
 out_clean_notification:
 	fanotify_notification_user_destroy(group);
 out_clean_subdir:
@@ -126,6 +134,7 @@ out_free_name:
 	kfree(group->name);
 out:
 	kfree(group);
+	mutex_unlock(&groups_mutex);
 	return rc;
 }
 
include/linux/fanotify.h +5 -0
index 16ff769..a23ab97 100644
@@ -36,16 +36,21 @@
 #ifdef __KERNEL__
 
 #include <linux/fs.h>
+#include <linux/list.h>
 
 #ifdef CONFIG_FANOTIFY
 
 extern void fanotify(struct file *file, unsigned int mask);
+extern void fanotify_inode_delete(struct inode *inode);
 
 #else
 
 static inline void fanotify(struct file *file, unsigned int mask)
 {}
 
+static inline void fanotify_inode_delete(struct inode *inode)
+{}
+
 #endif	/* CONFIG_FANOTIFY */
 
 #endif	/* __KERNEL __ */
include/linux/fs.h +5 -0
index 580b513..2d630fc 100644
@@ -671,6 +671,11 @@ struct inode {
 	struct mutex		inotify_mutex;	/* protects the watches list */
 #endif
 
+#ifdef CONFIG_FANOTIFY
+	struct list_head	fastpath_entries; /* fanotify fastpath entries protected by group */
+	rwlock_t		fastpath_rwlock; /* protect the fastpath entries list */
+#endif
+
 	unsigned long		i_state;
 	unsigned long		dirtied_when;	/* jiffies of first dirtying */
 
include/linux/fsnotify.h +8 -0
index 50d8d8b..0b03d8a 100644
@@ -82,6 +82,14 @@ static inline void fsnotify_nameremove(struct dentry *dentry, int isdir)
 }
 
 /*
+ * fsnotify_inode_delete - and inode is being evicted from cache, clean up is needed
+ */
+static inline void fsnotify_inode_delete(struct inode *inode)
+{
+	fanotify_inode_delete(inode);
+}
+
+/*
  * fsnotify_inoderemove - an inode is going away
  */
 static inline void fsnotify_inoderemove(struct inode *inode)