Btrfs-progs: deal with invalid key orderings and bad orphan items V2
authorJosef Bacik <jbacik@fb.com>
Tue, 7 Jan 2014 20:19:35 +0000 (15:19 -0500)
committerChris Mason <clm@fb.com>
Fri, 31 Jan 2014 16:22:15 +0000 (08:22 -0800)
commit70749a77fe2b1c69d2ebe732de0d0ae53b967171
tree9d750cf2568195033aeba0dd803fb52a7a2b8e2e
parentd04707f78735d6bb119a2d088f99547949a65f3c
Btrfs-progs: deal with invalid key orderings and bad orphan items V2

A user had a fs where the objectid of an orphan item was not the actual orphan
item objectid.  This screwed up fsck because the block has keys in the wrong
order, also the fs scanning stuff will freak out because we have an inode with
nlink 0 and no orphan item.  So this patch is pretty big but is all related.

1) Deal with bad key ordering.  We can easily fix this up, so fix the checking
stuff to tell us exactly what it found when it said there was a problem.  Then
if it's bad key ordering we can reorder the keys and restart the scan.

2) Deal with bad keys.  If we find an orphan item with the wrong objectid it's
likely to screw with stuff, so keep track of these sort of things with a
bad_item list and just run through and delete any objects that don't make sense.
So far we just do this for orphan items but we could extend this as new stuff
pops up.

3) Deal with missing orphan items.  This is easy, if we have a file with i_nlink
set to 0 and no orphan item we can just add an orphan item.

4) Add the infrastructure to corrupt actual key values.  Needed this to create a
test image to verify I was fixing things properly.

This patch fixes the corrupt image I'm adding and passes the other make test
tests.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <clm@fb.com>
btrfs-corrupt-block.c
cmds-check.c
ctree.c
ctree.h
file-item.c