mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/kdave/btrfs-progs.git
synced 2025-01-23 20:23:20 +08:00
btrfs-progs: Fix a bug in reset_nlink() which may deletes the recovered file
In reset_nlink(), we believe rec->found_link as accurate number of the valid links. However it only records the number of found DIR_ITEM, so we can't use it as reliable value. Before this patch, in some case, leaf corruption recovery will believe there is a valid backref but don't add_link() since it can't find any valid one and don't put it into the lost+found dir. So the recovered inode will be considered as an orphan item without orphan item and repair_inode_orphan_item() will add orphan item for it, causing all the filename/filetype we recovered being a waste of time. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz>
This commit is contained in:
parent
44d3ee3e1f
commit
0f38766b8f
@ -1959,6 +1959,9 @@ static int reset_nlink(struct btrfs_trans_handle *trans,
|
||||
struct btrfs_inode_item *inode_item;
|
||||
int ret = 0;
|
||||
|
||||
/* We don't believe this either, reset it and iterate backref */
|
||||
rec->found_link = 0;
|
||||
|
||||
/* Remove all backref including the valid ones */
|
||||
list_for_each_entry_safe(backref, tmp, &rec->backrefs, list) {
|
||||
ret = btrfs_unlink(trans, root, rec->ino, backref->dir,
|
||||
@ -1973,6 +1976,8 @@ static int reset_nlink(struct btrfs_trans_handle *trans,
|
||||
backref->found_inode_ref)) {
|
||||
list_del(&backref->list);
|
||||
free(backref);
|
||||
} else {
|
||||
rec->found_link++;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user