diff mbox

[10/12] Btrfs-progs: deal with mismatch index between dir index and inode ref

Message ID 1412974637-31334-11-git-send-email-jbacik@fb.com (mailing list archive)
State Accepted
Headers show

Commit Message

Josef Bacik Oct. 10, 2014, 8:57 p.m. UTC
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>
---
 cmds-check.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
diff mbox

Patch

diff --git a/cmds-check.c b/cmds-check.c
index ca890cc..80fa244 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -608,9 +608,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);
@@ -1654,8 +1655,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;