Commit 856bf3e5 authored by Chris Mason's avatar Chris Mason

Btrfs: Avoid extent_buffer lru corruption

Signed-off-by: default avatarChris Mason <chris.mason@oracle.com>
parent 257d0ce3
...@@ -2047,7 +2047,7 @@ static int add_lru(struct extent_map_tree *tree, struct extent_buffer *eb) ...@@ -2047,7 +2047,7 @@ static int add_lru(struct extent_map_tree *tree, struct extent_buffer *eb)
rm = list_entry(tree->buffer_lru.prev, rm = list_entry(tree->buffer_lru.prev,
struct extent_buffer, lru); struct extent_buffer, lru);
tree->lru_size--; tree->lru_size--;
list_del(&rm->lru); list_del_init(&rm->lru);
free_extent_buffer(rm); free_extent_buffer(rm);
} }
} else } else
...@@ -2187,6 +2187,9 @@ struct extent_buffer *alloc_extent_buffer(struct extent_map_tree *tree, ...@@ -2187,6 +2187,9 @@ struct extent_buffer *alloc_extent_buffer(struct extent_map_tree *tree,
return eb; return eb;
fail: fail:
spin_lock(&tree->lru_lock);
list_del_init(&eb->lru);
spin_unlock(&tree->lru_lock);
if (!atomic_dec_and_test(&eb->refs)) if (!atomic_dec_and_test(&eb->refs))
return NULL; return NULL;
for (index = 0; index < i; index++) { for (index = 0; index < i; index++) {
...@@ -2246,6 +2249,9 @@ struct extent_buffer *find_extent_buffer(struct extent_map_tree *tree, ...@@ -2246,6 +2249,9 @@ struct extent_buffer *find_extent_buffer(struct extent_map_tree *tree,
spin_unlock(&tree->lru_lock); spin_unlock(&tree->lru_lock);
return eb; return eb;
fail: fail:
spin_lock(&tree->lru_lock);
list_del_init(&eb->lru);
spin_unlock(&tree->lru_lock);
if (!atomic_dec_and_test(&eb->refs)) if (!atomic_dec_and_test(&eb->refs))
return NULL; return NULL;
for (index = 0; index < i; index++) { for (index = 0; index < i; index++) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment