linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] fanotify: to differ file access event from different threads
@ 2011-12-06  1:23 boyd yang
  2011-12-10 16:25 ` Lino Sanfilippo
  2013-02-11 19:49 ` Mihai Donțu
  0 siblings, 2 replies; 11+ messages in thread
From: boyd yang @ 2011-12-06  1:23 UTC (permalink / raw)
  To: eparis, xiyou.wangcong, Josef Bacik, linux-fsdevel, linux-kernel

fanotify: to differ file access event from different threads
When fanotify is monitoring the whole mount point "/", and multiple
threads iterate the same direcotry, some thread will hang.
This patch let fanotify to differ access events from different
threads, prevent fanotify from merging access events from different
threads.
It also hide overflow events to reach user space.
Signed-off-by: Boyd Yang <boyd.yang@gmail.com>

diff -r -u linux-3.1-rc4_orig/fs/notify/fanotify/fanotify.c
linux-3.1-rc4/fs/notify/fanotify/fanotify.c
--- linux-3.1-rc4_orig/fs/notify/fanotify/fanotify.c	2011-08-29
12:16:01.000000000 +0800
+++ linux-3.1-rc4/fs/notify/fanotify/fanotify.c	2011-10-14
14:17:53.055958000 +0800
@@ -15,7 +15,8 @@

 	if (old->to_tell == new->to_tell &&
 	    old->data_type == new->data_type &&
-	    old->tgid == new->tgid) {
+	    old->tgid == new->tgid &&
+	    old->pid == new->pid) {
 		switch (old->data_type) {
 		case (FSNOTIFY_EVENT_PATH):
 			if ((old->path.mnt == new->path.mnt) &&
@@ -144,11 +145,16 @@
 		return PTR_ERR(notify_event);

 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
-	if (event->mask & FAN_ALL_PERM_EVENTS) {
-		/* if we merged we need to wait on the new event */
-		if (notify_event)
-			event = notify_event;
-		ret = fanotify_get_response_from_access(group, event);
+	/*if overflow, do not wait for response*/
+	if (event->mask&FS_Q_OVERFLOW) {
+		pr_debug("fanotify overflow!\n");
+	}	else {
+		if (event->mask & FAN_ALL_PERM_EVENTS) {
+			/* if we merged we need to wait on the new event */
+			if (notify_event)
+				event = notify_event;
+			ret = fanotify_get_response_from_access(group, event);
+		}
 	}
 #endif

diff -r -u linux-3.1-rc4_orig/fs/notify/notification.c
linux-3.1-rc4/fs/notify/notification.c
--- linux-3.1-rc4_orig/fs/notify/notification.c	2011-08-29
12:16:01.000000000 +0800
+++ linux-3.1-rc4/fs/notify/notification.c	2011-10-14 13:52:36.946608000 +0800
@@ -95,6 +95,7 @@
 		BUG_ON(!list_empty(&event->private_data_list));

 		kfree(event->file_name);
+		put_pid(event->pid);
 		put_pid(event->tgid);
 		kmem_cache_free(fsnotify_event_cachep, event);
 	}
@@ -374,6 +375,7 @@
 			return NULL;
 		}
 	}
+	event->pid = get_pid(old_event->pid);
 	event->tgid = get_pid(old_event->tgid);
 	if (event->data_type == FSNOTIFY_EVENT_PATH)
 		path_get(&event->path);
@@ -417,6 +419,7 @@
 		event->name_len = strlen(event->file_name);
 	}

+	event->pid = get_pid(task_pid(current));
 	event->tgid = get_pid(task_tgid(current));
 	event->sync_cookie = cookie;
 	event->to_tell = to_tell;
diff -r -u linux-3.1-rc4_orig/include/linux/fsnotify_backend.h
linux-3.1-rc4/include/linux/fsnotify_backend.h
--- linux-3.1-rc4_orig/include/linux/fsnotify_backend.h	2011-08-29
12:16:01.000000000 +0800
+++ linux-3.1-rc4/include/linux/fsnotify_backend.h	2011-10-14
13:51:50.380168000 +0800
@@ -238,6 +238,7 @@
 	u32 sync_cookie;	/* used to corrolate events, namely inotify mv events */
 	const unsigned char *file_name;
 	size_t name_len;
+	struct pid *pid;
 	struct pid *tgid;

 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS

^ permalink raw reply	[flat|nested] 11+ messages in thread
* [PATCH] fanotify: to differ file access event from different threads
@ 2011-10-13  8:56 boyd yang
  2011-10-13 13:27 ` boyd yang
  2011-10-13 13:38 ` Josef Bacik
  0 siblings, 2 replies; 11+ messages in thread
From: boyd yang @ 2011-10-13  8:56 UTC (permalink / raw)
  To: linux-fsdevel; +Cc: eparis

This patch fixes a hang problem of Eric Paris's fs Notification/fanotify.

Fanotify brings a way to intercept file access events.
When multiple threadsiterate the same direcotry, some thread will hang.
This patch let fanotify to differ access events from different
threads, prevent fanotify from merging access events from different
threads.

=============================================================

diff -r -u linux-3.1-rc4_orig/fs/notify/fanotify/fanotify.c
linux-3.1-rc4/fs/notify/fanotify/fanotify.c
--- linux-3.1-rc4_orig/fs/notify/fanotify/fanotify.c	2011-08-29
12:16:01.000000000 +0800
+++ linux-3.1-rc4/fs/notify/fanotify/fanotify.c	2011-10-10
12:28:23.276847000 +0800
@@ -15,7 +15,8 @@

 	if (old->to_tell == new->to_tell &&
 	    old->data_type == new->data_type &&
-	    old->tgid == new->tgid) {
+	    old->tgid == new->tgid &&
+	    old->pid == new->pid) {
 		switch (old->data_type) {
 		case (FSNOTIFY_EVENT_PATH):
 			if ((old->path.mnt == new->path.mnt) &&
@@ -144,11 +145,19 @@
 		return PTR_ERR(notify_event);

 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
-	if (event->mask & FAN_ALL_PERM_EVENTS) {
-		/* if we merged we need to wait on the new event */
-		if (notify_event)
-			event = notify_event;
-		ret = fanotify_get_response_from_access(group, event);
+	//if overflow, do not wait for response
+	if(fsnotify_isoverflow(event))
+	{
+		pr_debug("fanotify overflow!\n");
+	}
+	else
+	{
+		if (event->mask & FAN_ALL_PERM_EVENTS) {
+			/* if we merged we need to wait on the new event */
+			if (notify_event)
+				event = notify_event;
+			ret = fanotify_get_response_from_access(group, event);
+		}
 	}
 #endif

diff -r -u linux-3.1-rc4_orig/fs/notify/notification.c
linux-3.1-rc4/fs/notify/notification.c
--- linux-3.1-rc4_orig/fs/notify/notification.c	2011-08-29
12:16:01.000000000 +0800
+++ linux-3.1-rc4/fs/notify/notification.c	2011-10-10 12:27:09.331787000 +0800
@@ -95,6 +95,7 @@
 		BUG_ON(!list_empty(&event->private_data_list));

 		kfree(event->file_name);
+		put_pid(event->pid);
 		put_pid(event->tgid);
 		kmem_cache_free(fsnotify_event_cachep, event);
 	}
@@ -132,6 +133,14 @@
 	return priv;
 }

+bool fsnotify_isoverflow(struct fsnotify_event *event)
+{
+	if(event==q_overflow_event)
+	{
+		return true;
+	}
+	return false;
+}
 /*
  * Add an event to the group notification queue.  The group can later pull this
  * event off the queue to deal with.  If the event is successfully added to the
@@ -374,6 +383,7 @@
 			return NULL;
 		}
 	}
+	event->pid = get_pid(old_event->pid);
 	event->tgid = get_pid(old_event->tgid);
 	if (event->data_type == FSNOTIFY_EVENT_PATH)
 		path_get(&event->path);
@@ -417,6 +427,7 @@
 		event->name_len = strlen(event->file_name);
 	}

+	event->pid = get_pid(task_pid(current));
 	event->tgid = get_pid(task_tgid(current));
 	event->sync_cookie = cookie;
 	event->to_tell = to_tell;
diff -r -u linux-3.1-rc4_orig/include/linux/fsnotify_backend.h
linux-3.1-rc4/include/linux/fsnotify_backend.h
--- linux-3.1-rc4_orig/include/linux/fsnotify_backend.h	2011-08-29
12:16:01.000000000 +0800
+++ linux-3.1-rc4/include/linux/fsnotify_backend.h	2011-10-10
12:27:48.587369000 +0800
@@ -238,6 +238,7 @@
 	u32 sync_cookie;	/* used to corrolate events, namely inotify mv events */
 	const unsigned char *file_name;
 	size_t name_len;
+	struct pid *pid;
 	struct pid *tgid;

 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
@@ -378,6 +379,8 @@
 							struct fsnotify_event_private_data *priv,
 							struct fsnotify_event *(*merge)(struct list_head *,
 											struct fsnotify_event *));
+/*true if the event is an overflow event*/
+extern bool fsnotify_isoverflow(struct fsnotify_event *event);
 /* true if the group notification queue is empty */
 extern bool fsnotify_notify_queue_is_empty(struct fsnotify_group *group);
 /* return, but do not dequeue the first event on the notification queue */

^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2013-02-11 19:49 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-12-06  1:23 [PATCH] fanotify: to differ file access event from different threads boyd yang
2011-12-10 16:25 ` Lino Sanfilippo
2013-02-11 19:49 ` Mihai Donțu
  -- strict thread matches above, loose matches on Subject: below --
2011-10-13  8:56 boyd yang
2011-10-13 13:27 ` boyd yang
2011-10-13 14:35   ` Américo Wang
2011-10-13 13:38 ` Josef Bacik
2011-10-14  6:56   ` boyd yang
2011-11-17 10:21     ` boyd yang
2011-11-24 14:58       ` Jan Kara
2011-12-06  1:24         ` boyd yang

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).