Btrfs-progs: deal with mismatch index between dir index and inode ref
authorJosef Bacik <jbacik@fb.com>
Fri, 10 Oct 2014 20:57:15 +0000 (16:57 -0400)
committerDavid Sterba <dsterba@suse.cz>
Tue, 14 Oct 2014 08:47:59 +0000 (10:47 +0200)
Sometimes we have a dir index and an inode ref that don't agree on the index.
In this case just assume that the inode ref is the ultimate authority on the
subject and delete the dir index.  This means we have to not reset index if we
find a mismatched inode ref to make sure we delete the right dir index.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
cmds-check.c

index 8150203..6fada45 100644 (file)
@@ -620,9 +620,10 @@ static int add_inode_backref(struct cache_tree *inode_cache,
                        backref->errors |= REF_ERR_DUP_INODE_REF;
                if (backref->found_dir_index && backref->index != index)
                        backref->errors |= REF_ERR_INDEX_UNMATCH;
+               else
+                       backref->index = index;
 
                backref->ref_type = itemtype;
-               backref->index = index;
                backref->found_inode_ref = 1;
        } else {
                BUG_ON(1);
@@ -1719,8 +1720,10 @@ static int repair_inode_backrefs(struct btrfs_root *root,
                if (rec->ino == root_dirid && backref->index == 0)
                        continue;
 
-               if (delete && backref->found_dir_index &&
-                   !backref->found_inode_ref) {
+               if (delete &&
+                   ((backref->found_dir_index && !backref->found_inode_ref) ||
+                    (backref->found_dir_index && backref->found_inode_ref &&
+                     (backref->errors & REF_ERR_INDEX_UNMATCH)))) {
                        ret = delete_dir_index(root, inode_cache, rec, backref);
                        if (ret)
                                break;