mirror of
https://github.com/kdave/btrfs-progs
synced 2024-12-25 23:52:17 +00:00
btrfs-progs: check, properly reset nlink of multi-linked file
If a file is linked from more than one directory and only one of the links is corrupted, btrfs check dose not reset the nlink properly. Actually it can go into infinite loop to link the broken file into lost+found. This patch fix two part of the code. The first one delay the freeing valid (no error, found inode ref, directory index, and directory item) backrefs. Freeing valid backrefs earier prevent reset_nlink() to add back all valid links. The second fix is obvious: passing `ref_type' to btrfs_add_link() is just wrong. It should be `filetype' instead. The current code can break all valid file links. Signed-off-by: Naohiro Aota <naota@elisp.net> Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
This commit is contained in:
parent
05d4159946
commit
9709d754db
@ -810,7 +810,8 @@ static void maybe_free_inode_rec(struct cache_tree *inode_cache,
|
||||
if (backref->found_dir_item && backref->found_dir_index) {
|
||||
if (backref->filetype != filetype)
|
||||
backref->errors |= REF_ERR_FILETYPE_UNMATCH;
|
||||
if (!backref->errors && backref->found_inode_ref) {
|
||||
if (!backref->errors && backref->found_inode_ref &&
|
||||
rec->nlink == rec->found_link) {
|
||||
list_del(&backref->list);
|
||||
free(backref);
|
||||
}
|
||||
@ -2392,7 +2393,7 @@ static int reset_nlink(struct btrfs_trans_handle *trans,
|
||||
list_for_each_entry(backref, &rec->backrefs, list) {
|
||||
ret = btrfs_add_link(trans, root, rec->ino, backref->dir,
|
||||
backref->name, backref->namelen,
|
||||
backref->ref_type, &backref->index, 1);
|
||||
backref->filetype, &backref->index, 1);
|
||||
if (ret < 0)
|
||||
goto out;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user