PCI: Add pci_ioremap_wc_bar()
[deliverable/linux.git] / kernel / audit_tree.c
index 80f29e0155705159fc83a80c1138e45b590661e2..b0f9877273fc39746fa063849f1bac51487d8606 100644 (file)
@@ -37,6 +37,7 @@ struct audit_chunk {
 
 static LIST_HEAD(tree_list);
 static LIST_HEAD(prune_list);
+static struct task_struct *prune_thread;
 
 /*
  * One struct chunk is attached to each inode of interest.
@@ -174,9 +175,9 @@ static void insert_hash(struct audit_chunk *chunk)
        struct fsnotify_mark *entry = &chunk->mark;
        struct list_head *list;
 
-       if (!entry->i.inode)
+       if (!entry->inode)
                return;
-       list = chunk_hash(entry->i.inode);
+       list = chunk_hash(entry->inode);
        list_add_rcu(&chunk->hash, list);
 }
 
@@ -188,7 +189,7 @@ struct audit_chunk *audit_tree_lookup(const struct inode *inode)
 
        list_for_each_entry_rcu(p, list, hash) {
                /* mark.inode may have gone NULL, but who cares? */
-               if (p->mark.i.inode == inode) {
+               if (p->mark.inode == inode) {
                        atomic_long_inc(&p->refs);
                        return p;
                }
@@ -231,7 +232,7 @@ static void untag_chunk(struct node *p)
                new = alloc_chunk(size);
 
        spin_lock(&entry->lock);
-       if (chunk->dead || !entry->i.inode) {
+       if (chunk->dead || !entry->inode) {
                spin_unlock(&entry->lock);
                if (new)
                        free_chunk(new);
@@ -258,7 +259,7 @@ static void untag_chunk(struct node *p)
                goto Fallback;
 
        fsnotify_duplicate_mark(&new->mark, entry);
-       if (fsnotify_add_mark(&new->mark, new->mark.group, new->mark.i.inode, NULL, 1)) {
+       if (fsnotify_add_mark(&new->mark, new->mark.group, new->mark.inode, NULL, 1)) {
                fsnotify_put_mark(&new->mark);
                goto Fallback;
        }
@@ -386,7 +387,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
        chunk_entry = &chunk->mark;
 
        spin_lock(&old_entry->lock);
-       if (!old_entry->i.inode) {
+       if (!old_entry->inode) {
                /* old_entry is being shot, lets just lie */
                spin_unlock(&old_entry->lock);
                fsnotify_put_mark(old_entry);
@@ -395,7 +396,7 @@ static int tag_chunk(struct inode *inode, struct audit_tree *tree)
        }
 
        fsnotify_duplicate_mark(chunk_entry, old_entry);
-       if (fsnotify_add_mark(chunk_entry, chunk_entry->group, chunk_entry->i.inode, NULL, 1)) {
+       if (fsnotify_add_mark(chunk_entry, chunk_entry->group, chunk_entry->inode, NULL, 1)) {
                spin_unlock(&old_entry->lock);
                fsnotify_put_mark(chunk_entry);
                fsnotify_put_mark(old_entry);
@@ -576,7 +577,7 @@ int audit_remove_tree_rule(struct audit_krule *rule)
 
 static int compare_root(struct vfsmount *mnt, void *arg)
 {
-       return mnt->mnt_root->d_inode == arg;
+       return d_backing_inode(mnt->mnt_root) == arg;
 }
 
 void audit_trim_trees(void)
@@ -611,7 +612,7 @@ void audit_trim_trees(void)
                list_for_each_entry(node, &tree->chunks, list) {
                        struct audit_chunk *chunk = find_chunk(node);
                        /* this could be NULL if the watch is dying else where... */
-                       struct inode *inode = chunk->mark.i.inode;
+                       struct inode *inode = chunk->mark.inode;
                        node->index |= 1U<<31;
                        if (iterate_mounts(compare_root, inode, root_mnt))
                                node->index &= ~(1U<<31);
@@ -648,7 +649,58 @@ void audit_put_tree(struct audit_tree *tree)
 
 static int tag_mount(struct vfsmount *mnt, void *arg)
 {
-       return tag_chunk(mnt->mnt_root->d_inode, arg);
+       return tag_chunk(d_backing_inode(mnt->mnt_root), arg);
+}
+
+/*
+ * That gets run when evict_chunk() ends up needing to kill audit_tree.
+ * Runs from a separate thread.
+ */
+static int prune_tree_thread(void *unused)
+{
+       for (;;) {
+               set_current_state(TASK_INTERRUPTIBLE);
+               if (list_empty(&prune_list))
+                       schedule();
+               __set_current_state(TASK_RUNNING);
+
+               mutex_lock(&audit_cmd_mutex);
+               mutex_lock(&audit_filter_mutex);
+
+               while (!list_empty(&prune_list)) {
+                       struct audit_tree *victim;
+
+                       victim = list_entry(prune_list.next,
+                                       struct audit_tree, list);
+                       list_del_init(&victim->list);
+
+                       mutex_unlock(&audit_filter_mutex);
+
+                       prune_one(victim);
+
+                       mutex_lock(&audit_filter_mutex);
+               }
+
+               mutex_unlock(&audit_filter_mutex);
+               mutex_unlock(&audit_cmd_mutex);
+       }
+       return 0;
+}
+
+static int audit_launch_prune(void)
+{
+       if (prune_thread)
+               return 0;
+       prune_thread = kthread_create(prune_tree_thread, NULL,
+                               "audit_prune_tree");
+       if (IS_ERR(prune_thread)) {
+               pr_err("cannot start thread audit_prune_tree");
+               prune_thread = NULL;
+               return -ENOMEM;
+       } else {
+               wake_up_process(prune_thread);
+               return 0;
+       }
 }
 
 /* called with audit_filter_mutex */
@@ -674,6 +726,12 @@ int audit_add_tree_rule(struct audit_krule *rule)
        /* do not set rule->tree yet */
        mutex_unlock(&audit_filter_mutex);
 
+       if (unlikely(!prune_thread)) {
+               err = audit_launch_prune();
+               if (err)
+                       goto Err;
+       }
+
        err = kern_path(tree->pathname, 0, &path);
        if (err)
                goto Err;
@@ -811,36 +869,10 @@ int audit_tag_tree(char *old, char *new)
        return failed;
 }
 
-/*
- * That gets run when evict_chunk() ends up needing to kill audit_tree.
- * Runs from a separate thread.
- */
-static int prune_tree_thread(void *unused)
-{
-       mutex_lock(&audit_cmd_mutex);
-       mutex_lock(&audit_filter_mutex);
-
-       while (!list_empty(&prune_list)) {
-               struct audit_tree *victim;
-
-               victim = list_entry(prune_list.next, struct audit_tree, list);
-               list_del_init(&victim->list);
-
-               mutex_unlock(&audit_filter_mutex);
-
-               prune_one(victim);
-
-               mutex_lock(&audit_filter_mutex);
-       }
-
-       mutex_unlock(&audit_filter_mutex);
-       mutex_unlock(&audit_cmd_mutex);
-       return 0;
-}
 
 static void audit_schedule_prune(void)
 {
-       kthread_run(prune_tree_thread, NULL, "audit_prune_tree");
+       wake_up_process(prune_thread);
 }
 
 /*
@@ -907,9 +939,9 @@ static void evict_chunk(struct audit_chunk *chunk)
        for (n = 0; n < chunk->count; n++)
                list_del_init(&chunk->owners[n].list);
        spin_unlock(&hash_lock);
+       mutex_unlock(&audit_filter_mutex);
        if (need_prune)
                audit_schedule_prune();
-       mutex_unlock(&audit_filter_mutex);
 }
 
 static int audit_tree_handle_event(struct fsnotify_group *group,
This page took 0.080216 seconds and 5 git commands to generate.