Commit 3ef5969c authored by Alexander Block's avatar Alexander Block Committed by Josef Bacik

Btrfs: merge inode_list in __merge_refs

When __merge_refs merges two refs, it is also needed to merge the
inode_list of both refs. Otherwise we have missed backrefs and memory
leaks. This happens for example if two inodes share an extent and
both lie in the same leaf and thus also have the same parent.
Signed-off-by: default avatarAlexander Block <ablock84@googlemail.com>
Reviewed-by: default avatarJan Schmidt <list.btrfs@jan-o-sch.net>
Signed-off-by: default avatarChris Mason <chris.mason@fusionio.com>
parent e1f5790e
...@@ -461,6 +461,7 @@ static int __merge_refs(struct list_head *head, int mode) ...@@ -461,6 +461,7 @@ static int __merge_refs(struct list_head *head, int mode)
pos2 = n2, n2 = pos2->next) { pos2 = n2, n2 = pos2->next) {
struct __prelim_ref *ref2; struct __prelim_ref *ref2;
struct __prelim_ref *xchg; struct __prelim_ref *xchg;
struct extent_inode_elem *eie;
ref2 = list_entry(pos2, struct __prelim_ref, list); ref2 = list_entry(pos2, struct __prelim_ref, list);
...@@ -472,12 +473,20 @@ static int __merge_refs(struct list_head *head, int mode) ...@@ -472,12 +473,20 @@ static int __merge_refs(struct list_head *head, int mode)
ref1 = ref2; ref1 = ref2;
ref2 = xchg; ref2 = xchg;
} }
ref1->count += ref2->count;
} else { } else {
if (ref1->parent != ref2->parent) if (ref1->parent != ref2->parent)
continue; continue;
ref1->count += ref2->count;
} }
eie = ref1->inode_list;
while (eie && eie->next)
eie = eie->next;
if (eie)
eie->next = ref2->inode_list;
else
ref1->inode_list = ref2->inode_list;
ref1->count += ref2->count;
list_del(&ref2->list); list_del(&ref2->list);
kfree(ref2); kfree(ref2);
} }
......
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