Lines Matching full:chunk
42 struct audit_chunk *chunk; member
50 * One struct chunk is attached to each inode of interest through
51 * audit_tree_mark (fsnotify mark). We replace struct chunk on tagging /
52 * untagging, the mark is stable as long as there is chunk attached. The
53 * association between mark and chunk is protected by hash_lock and
57 * the current chunk.
62 * References to struct chunk are collected at audit_inode{,_child}()
68 * tree.chunks anchors chunk.owners[].list hash_lock
70 * chunk.trees anchors tree.same_root hash_lock
71 * chunk.hash is a hash with middle bits of watch.inode as
75 * it", one for each chunk with pointer to it.
77 * chunk is refcounted by embedded .refs. Mark associated with the chunk holds
78 * one chunk reference. This reference is dropped either when a mark is going
79 * to be freed (corresponding inode goes away) or when chunk attached to the
84 * node.index allows to get from node.list to containing chunk.
128 static void free_chunk(struct audit_chunk *chunk) in free_chunk() argument
132 for (i = 0; i < chunk->count; i++) { in free_chunk()
133 if (chunk->owners[i].owner) in free_chunk()
134 put_tree(chunk->owners[i].owner); in free_chunk()
136 kfree(chunk); in free_chunk()
139 void audit_put_chunk(struct audit_chunk *chunk) in audit_put_chunk() argument
141 if (atomic_long_dec_and_test(&chunk->refs)) in audit_put_chunk()
142 free_chunk(chunk); in audit_put_chunk()
147 struct audit_chunk *chunk = container_of(rcu, struct audit_chunk, head); in __put_chunk() local
148 audit_put_chunk(chunk); in __put_chunk()
152 * Drop reference to the chunk that was held by the mark. This is the reference
153 * that gets dropped after we've removed the chunk from the hash table and we
154 * use it to make sure chunk cannot be freed before RCU grace period expires.
156 static void audit_mark_put_chunk(struct audit_chunk *chunk) in audit_mark_put_chunk() argument
158 call_rcu(&chunk->head, __put_chunk); in audit_mark_put_chunk()
168 return audit_mark(mark)->chunk; in mark_chunk()
190 struct audit_chunk *chunk; in alloc_chunk() local
193 chunk = kzalloc(struct_size(chunk, owners, count), GFP_KERNEL); in alloc_chunk()
194 if (!chunk) in alloc_chunk()
197 INIT_LIST_HEAD(&chunk->hash); in alloc_chunk()
198 INIT_LIST_HEAD(&chunk->trees); in alloc_chunk()
199 chunk->count = count; in alloc_chunk()
200 atomic_long_set(&chunk->refs, 1); in alloc_chunk()
202 INIT_LIST_HEAD(&chunk->owners[i].list); in alloc_chunk()
203 chunk->owners[i].index = i; in alloc_chunk()
205 return chunk; in alloc_chunk()
226 static void insert_hash(struct audit_chunk *chunk) in insert_hash() argument
231 * Make sure chunk is fully initialized before making it visible in the in insert_hash()
236 WARN_ON_ONCE(!chunk->key); in insert_hash()
237 list = chunk_hash(chunk->key); in insert_hash()
238 list_add_rcu(&chunk->hash, list); in insert_hash()
251 * the chunk we see is fully initialized. in audit_tree_lookup()
261 bool audit_tree_match(struct audit_chunk *chunk, struct audit_tree *tree) in audit_tree_match() argument
264 for (n = 0; n < chunk->count; n++) in audit_tree_match()
265 if (chunk->owners[n].owner == tree) in audit_tree_match()
280 struct audit_chunk *chunk) in replace_mark_chunk() argument
286 audit_mark(mark)->chunk = chunk; in replace_mark_chunk()
287 if (chunk) in replace_mark_chunk()
288 chunk->mark = mark; in replace_mark_chunk()
317 * Make sure chunk is fully initialized before making it visible in the in replace_chunk()
325 static void remove_chunk_node(struct audit_chunk *chunk, struct audit_node *p) in remove_chunk_node() argument
329 if (owner->root == chunk) { in remove_chunk_node()
338 static int chunk_count_trees(struct audit_chunk *chunk) in chunk_count_trees() argument
343 for (i = 0; i < chunk->count; i++) in chunk_count_trees()
344 if (chunk->owners[i].owner) in chunk_count_trees()
349 static void untag_chunk(struct audit_chunk *chunk, struct fsnotify_mark *mark) in untag_chunk() argument
356 * mark_mutex stabilizes chunk attached to the mark so we can check in untag_chunk()
360 mark_chunk(mark) != chunk) in untag_chunk()
363 size = chunk_count_trees(chunk); in untag_chunk()
366 list_del_init(&chunk->trees); in untag_chunk()
367 list_del_rcu(&chunk->hash); in untag_chunk()
372 audit_mark_put_chunk(chunk); in untag_chunk()
383 * This has to go last when updating chunk as once replace_chunk() is in untag_chunk()
384 * called, new RCU readers can see the new chunk. in untag_chunk()
386 replace_chunk(new, chunk); in untag_chunk()
389 audit_mark_put_chunk(chunk); in untag_chunk()
400 struct audit_chunk *chunk = alloc_chunk(1); in create_chunk() local
402 if (!chunk) { in create_chunk()
410 kfree(chunk); in create_chunk()
417 kfree(chunk); in create_chunk()
428 kfree(chunk); in create_chunk()
431 replace_mark_chunk(mark, chunk); in create_chunk()
432 chunk->owners[0].index = (1U << 31); in create_chunk()
433 chunk->owners[0].owner = tree; in create_chunk()
435 list_add(&chunk->owners[0].list, &tree->chunks); in create_chunk()
437 tree->root = chunk; in create_chunk()
438 list_add(&tree->same_root, &chunk->trees); in create_chunk()
440 chunk->key = inode_to_key(inode); in create_chunk()
443 * readers can see the chunk. in create_chunk()
445 insert_hash(chunk); in create_chunk()
451 * chunk pointing to this mark. in create_chunk()
461 struct audit_chunk *chunk, *old; in tag_chunk() local
472 * from getting detached and thus it makes sure there is chunk attached in tag_chunk()
488 chunk = alloc_chunk(old->count + 1); in tag_chunk()
489 if (!chunk) { in tag_chunk()
500 kfree(chunk); in tag_chunk()
503 p = &chunk->owners[chunk->count - 1]; in tag_chunk()
504 p->index = (chunk->count - 1) | (1U<<31); in tag_chunk()
509 tree->root = chunk; in tag_chunk()
510 list_add(&tree->same_root, &chunk->trees); in tag_chunk()
513 * This has to go last when updating chunk as once replace_chunk() is in tag_chunk()
514 * called, new RCU readers can see the new chunk. in tag_chunk()
516 replace_chunk(chunk, old); in tag_chunk()
574 struct audit_chunk *chunk; in prune_tree_chunks() local
581 chunk = find_chunk(p); in prune_tree_chunks()
582 mark = chunk->mark; in prune_tree_chunks()
583 remove_chunk_node(chunk, p); in prune_tree_chunks()
590 untag_chunk(chunk, mark); in prune_tree_chunks()
706 struct audit_chunk *chunk = find_chunk(node); in audit_trim_trees() local
710 (void *)(chunk->key), in audit_trim_trees()
1001 static void evict_chunk(struct audit_chunk *chunk) in evict_chunk() argument
1010 while (!list_empty(&chunk->trees)) { in evict_chunk()
1011 owner = list_entry(chunk->trees.next, in evict_chunk()
1026 list_del_rcu(&chunk->hash); in evict_chunk()
1027 for (n = 0; n < chunk->count; n++) in evict_chunk()
1028 list_del_init(&chunk->owners[n].list); in evict_chunk()
1045 struct audit_chunk *chunk; in audit_tree_freeing_mark() local
1049 chunk = mark_chunk(mark); in audit_tree_freeing_mark()
1053 if (chunk) { in audit_tree_freeing_mark()
1054 evict_chunk(chunk); in audit_tree_freeing_mark()
1055 audit_mark_put_chunk(chunk); in audit_tree_freeing_mark()