mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Eric Paris <eparis@redhat.com>
To: linux-kernel@vger.kernel.org, malware-list@lists.printk.net
Cc: viro@ZenIV.linux.org.uk, alan@lxorguk.ukuu.org.uk,
	arjan@infradead.org, greg@kroah.com, tytso@mit.edu
Subject: [PATCH -v2 09/16] fanotify: add group priorities
Date: Tue, 14 Oct 2008 16:52:17 -0400	[thread overview]
Message-ID: <20081014205217.1057.69686.stgit@paris.rdu.redhat.com> (raw)
In-Reply-To: <20081014205009.1057.12041.stgit@paris.rdu.redhat.com>

In preperation for blocking fanotify calls group priorities must be added.
async events will be sent as quickly as possible without waiting for a
response.

Signed-off-by: Eric Paris <eparis@redhat.com>
---

 fs/notify/group.c          |   30 ++++++++++++++++++++++++------
 include/linux/fanotify.h   |    5 ++++-
 net/fanotify/af_fanotify.c |    2 +-
 3 files changed, 29 insertions(+), 8 deletions(-)

diff --git a/fs/notify/group.c b/fs/notify/group.c
index 21037cc..37b8630 100644
--- a/fs/notify/group.c
+++ b/fs/notify/group.c
@@ -42,15 +42,16 @@ void fanotify_get_group(struct fanotify_group *group)
 	atomic_inc(&group->refcnt);
 }
 
-struct fanotify_group *fanotify_find_group(unsigned int group_num, unsigned int mask)
+struct fanotify_group *fanotify_find_group(unsigned int priority, unsigned int group_num, unsigned int mask)
 {
 	struct fanotify_group *group_iter;
 	struct fanotify_group *group = NULL;
 
 	mutex_lock(&fanotify_grp_mutex);
 	list_for_each_entry_rcu(group_iter, &fanotify_groups, group_list) {
-		if (group_iter->group_num == group_num) {
-			if (group_iter->mask == mask) {
+		if (group_iter->priority == priority) {
+			if ((group_iter->mask == mask) &&
+			    (group_iter->group_num == group_num)) {
 				fanotify_get_group(group_iter);
 				group = group_iter;
 			} else
@@ -69,6 +70,7 @@ struct fanotify_group *fanotify_find_group(unsigned int group_num, unsigned int
 
 	group->group_num = group_num;
 	group->mask = mask;
+	group->priority = priority;
 
 	mutex_init(&group->notification_mutex);
 	INIT_LIST_HEAD(&group->notification_list);
@@ -77,9 +79,26 @@ struct fanotify_group *fanotify_find_group(unsigned int group_num, unsigned int
 	mutex_init(&group->fastpath_mutex);
 	INIT_LIST_HEAD(&group->fastpath_entries);
 
-	/* add it */
-	list_add_rcu(&group->group_list, &fanotify_groups);
+	/* Do we need to be the first entry? */
+	if (list_empty(&fanotify_groups)) {
+		list_add_rcu(&group->group_list, &fanotify_groups);
+		goto out;
+	}
+
+	list_for_each_entry(group_iter, &fanotify_groups, group_list) {
+		/* insert in front of this one? */
+		if (priority < group_iter->priority) {
+			/* I used list_add_tail() to insert in front of group_iter...  */
+			list_add_tail_rcu(&group->group_list, &group_iter->group_list);
+			break;
+		}
 
+		/* are we at the end?  if so insert at end */
+		if (list_is_last(&group_iter->group_list, &fanotify_groups)) {
+			list_add_tail_rcu(&group->group_list, &fanotify_groups);
+			break;
+		}
+	}
 out:
 	mutex_unlock(&fanotify_grp_mutex);
 	return group;
@@ -100,7 +119,6 @@ void fanotify_put_group(struct fanotify_group *group)
 {
 	mutex_lock(&fanotify_grp_mutex);
 	if (atomic_dec_and_test(&group->refcnt)) {
-
 		list_del_rcu(&group->group_list);
 		mutex_unlock(&fanotify_grp_mutex);
 
diff --git a/include/linux/fanotify.h b/include/linux/fanotify.h
index a1ea7e0..22496b2 100644
--- a/include/linux/fanotify.h
+++ b/include/linux/fanotify.h
@@ -42,6 +42,7 @@
 #endif
 
 struct fanotify_addr {
+	uint32_t priority;
         uint32_t group_num;
         uint32_t mask;
         uint32_t timeout;
@@ -89,6 +90,8 @@ struct fanotify_group {
 	/* stores all fastapth entries assoc with this group so they can be cleaned on unregister */
 	struct mutex fastpath_mutex;	/* protect fastpath_entries list */
 	struct list_head fastpath_entries; /* all fastpath entries for this group */
+
+	unsigned int priority;		/* order this group should receive msgs.  low first */
 };
 
 #ifdef CONFIG_FANOTIFY
@@ -97,7 +100,7 @@ extern void fanotify(struct file *file, unsigned int mask);
 extern void fanotify_inode_delete(struct inode *inode);
 
 extern void fanotify_get_group(struct fanotify_group *group);
-extern struct fanotify_group *fanotify_find_group(unsigned int group_num, unsigned int mask);
+extern struct fanotify_group *fanotify_find_group(unsigned int priority, unsigned int group_num, unsigned int mask);
 extern void fanotify_put_group(struct fanotify_group *group);
 
 /* things called from the socket */
diff --git a/net/fanotify/af_fanotify.c b/net/fanotify/af_fanotify.c
index f63ee7a..a7d3b96 100644
--- a/net/fanotify/af_fanotify.c
+++ b/net/fanotify/af_fanotify.c
@@ -143,7 +143,7 @@ static int fan_bind(struct socket *sock, struct sockaddr *addr, int addr_len)
 		return -EINVAL;
 
 	fan_sock = fan_sk(sock->sk);
-	fan_sock->group = fanotify_find_group(fan_addr->group_num, fan_addr->mask);
+	fan_sock->group = fanotify_find_group(fan_addr->priority, fan_addr->group_num, fan_addr->mask);
 
 	if (IS_ERR(fan_sock->group))
 		return PTR_ERR(fan_sock->group);


  parent reply	other threads:[~2008-10-14 20:56 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-10-14 20:51 [PATCH -v2 00/16] fanotify: novel all file access notification and permissions system Eric Paris
2008-10-14 20:51 ` [PATCH -v2 01/16] filesystem notification: create fs/notify to contain all fs notification Eric Paris
2008-10-14 20:51 ` [PATCH -v2 02/16] fsnotify: pass a file instead of an inode to open, read, and write Eric Paris
2008-10-14 20:51 ` [PATCH -v2 03/16] fanotify: fscking all notify, system wide file access notification Eric Paris
2008-10-14 20:51 ` [PATCH -v2 04/16] fsnotify: sys_execve and sys_uselib do not call into fsnotify Eric Paris
2008-10-14 20:51 ` [PATCH -v2 05/16] fanotify: make use of the new fsnotify_open_exec calls Eric Paris
2008-10-14 20:52 ` [PATCH -v2 06/16] fanotify: add a userspace interface for fanotify notifications Eric Paris
2008-10-14 20:52 ` [PATCH -v2 07/16] fanotify: fastpath to ignore certain in core inodes Eric Paris
2008-10-14 20:52 ` [PATCH -v2 08/16] fanotify: add a userspace interface for fastpaths Eric Paris
2008-10-14 20:52 ` Eric Paris [this message]
2008-10-14 20:52 ` [PATCH -v2 10/16] fanotify: blocking and access granting Eric Paris
2008-10-14 20:52 ` [PATCH -v2 11/16] fanotify: give a special access permission check Eric Paris
2008-10-14 20:52 ` [PATCH -v2 12/16] fanotify: user interface for access decisions Eric Paris
2008-10-14 20:52 ` [PATCH -v2 13/16] fanotify: ability for userspace to delay responses Eric Paris
2008-10-14 20:52 ` [PATCH -v2 14/16] fanotify: send pid with fanotify notification events Eric Paris
2008-10-14 20:52 ` [PATCH -v2 15/16] fanotify: send tgid with notification messages Eric Paris
2008-10-14 20:52 ` [PATCH -v2 16/16] fanotify: send file f_flags along with notifications Eric Paris

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=20081014205217.1057.69686.stgit@paris.rdu.redhat.com \
    --to=eparis@redhat.com \
    --cc=alan@lxorguk.ukuu.org.uk \
    --cc=arjan@infradead.org \
    --cc=greg@kroah.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=malware-list@lists.printk.net \
    --cc=tytso@mit.edu \
    --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

all inboxes | Powered by JetHome®