linux-btrfs.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Josef Bacik <jbacik@fusionio.com>
To: <linux-btrfs@vger.kernel.org>
Subject: [PATCH] Btrfs-progs: fix incorrect root backref errors in fsck
Date: Tue, 4 Jun 2013 16:58:39 -0400	[thread overview]
Message-ID: <1370379519-9334-1-git-send-email-jbacik@fusionio.com> (raw)

A user reported that fsck was complaining about unresolved refs for some
snapshots.  You can reproduce this by doing

mkfs.btrfs /dev/sdb
mount /dev/sdb /mnt
btrfs subvol snap /mnt/ /mnt/a
btrfs subvol snap /mnt/ /mnt/b
btrfs subvol del /mnt/a
umount /mnt
btrfsck /dev/sdb

and you'd get this

unresolved ref root 258 dir 256 index 2 namelen 1 name a error 600

because snapshot b has a dir item that points to a.  Except we encode in our
root ref the dirid of the ref holder, and if it doesn't match we just give it
back a empty directory since we can't hardlink directories.  This makes the
check in btrfsck bogus, when we delete a we remove the ref key for it so any
lookups into /mnt/b/a will just give a blank directory as it's supposed to.  Fix
this by only saying the backref is reachable if there is both a DIR_ITEM and a
REF_KEY for the given root.  With this patch I no longer see errors when running
this reproducer.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
---
 cmds-check.c |    8 ++++++--
 1 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/cmds-check.c b/cmds-check.c
index bbef89a..4083298 100644
--- a/cmds-check.c
+++ b/cmds-check.c
@@ -1507,14 +1507,16 @@ static int add_root_backref(struct cache_tree *root_cache,
 	}
 
 	if (item_type == BTRFS_DIR_ITEM_KEY) {
+		if (backref->found_forward_ref)
+			rec->found_ref++;
 		backref->found_dir_item = 1;
-		backref->reachable = 1;
-		rec->found_ref++;
 	} else if (item_type == BTRFS_DIR_INDEX_KEY) {
 		backref->found_dir_index = 1;
 	} else if (item_type == BTRFS_ROOT_REF_KEY) {
 		if (backref->found_forward_ref)
 			backref->errors |= REF_ERR_DUP_ROOT_REF;
+		else if (backref->found_dir_item)
+			rec->found_ref++;
 		backref->found_forward_ref = 1;
 	} else if (item_type == BTRFS_ROOT_BACKREF_KEY) {
 		if (backref->found_back_ref)
@@ -1524,6 +1526,8 @@ static int add_root_backref(struct cache_tree *root_cache,
 		BUG_ON(1);
 	}
 
+	if (backref->found_forward_ref && backref->found_dir_item)
+		backref->reachable = 1;
 	return 0;
 }
 
-- 
1.7.7.6


                 reply	other threads:[~2013-06-04 20:58 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1370379519-9334-1-git-send-email-jbacik@fusionio.com \
    --to=jbacik@fusionio.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).