Bug 72151

Summary: Btrfs is corrupted and "brtfs check" craches during recovery
Product: File System Reporter: ar.fahrutdinov
Component: btrfsAssignee: Josef Bacik (josef)
Status: RESOLVED CODE_FIX    
Severity: normal CC: dpisklov, dsterba, leho, mail
Priority: P1    
Hardware: All   
OS: Linux   
Kernel Version: 3.13 Subsystem:
Regression: No Bisected commit-id:
Attachments: dmesg and strace btrfs check logs
btrfs rescue chunk-recover -v /dev/sda1

Description ar.fahrutdinov 2014-03-15 12:40:21 UTC
Created attachment 129491 [details]
dmesg and strace btrfs check logs

Hello!

My file system was corrupted after the power cycle."Btrfs check" utility crashes during recovery.

> uname -a                             
Linux sysresccd 3.13.5-alt410-amd64 #2 SMP Mon Mar 10 21:31:36 UTC 2014 x86_64 AMD A8-3850 APU with Radeon(tm) HD Graphics AuthenticAMD GNU/Linux

> btrfs version
Btrfs v3.12

> mount -t btrfs /dev/sda1 /mnt/custom
[ 9426.596084] btrfs: device fsid 77de157d-afb1-4774-b944-6cd086b42a7c devid 1 transid 41709 /dev/sda1
[ 9426.597675] btrfs: disk space caching is enabled
[ 9426.624554] Btrfs detected SSD devices, enabling SSD mode
[ 9426.624733] btrfs bad tree block start 18446744073709551615 54231040
[ 9426.624921] btrfs bad tree block start 18446744073709551615 54231040
[ 9426.624951] btrfs: failed to read log tree
[ 9426.638889] btrfs: open_ctree failed


> btrfs check /dev/sda1
Check tree block failed, want=54231040, have=18446744073709551615
Check tree block failed, want=54231040, have=18446744073709551615
Check tree block failed, want=54231040, have=18446744073709551615
Check tree block failed, want=54231040, have=18446744073709551615
Check tree block failed, want=54231040, have=18446744073709551615
read block failed check_tree_block
Couldn't setup log root tree
Checking filesystem on /dev/sda1
UUID: 77de157d-afb1-4774-b944-6cd086b42a7c
checking extents
zsh: segmentation fault  btrfs check /dev/sda1


> btrfs-zero-log /dev/sda1 
Check tree block failed, want=54231040, have=18446744073709551615
Check tree block failed, want=54231040, have=18446744073709551615
Check tree block failed, want=54231040, have=18446744073709551615
Check tree block failed, want=54231040, have=18446744073709551615
Check tree block failed, want=54231040, have=18446744073709551615
read block failed check_tree_block
Couldn't setup log root tree
Comment 1 ar.fahrutdinov 2014-03-15 13:01:58 UTC
Created attachment 129501 [details]
btrfs rescue chunk-recover -v /dev/sda1
Comment 2 ar.fahrutdinov 2014-03-15 14:00:01 UTC
btrfsck --repair --init-extent-tree --init-csum-tree /dev/sda1 
enabling repair mode
Creating a new CRC tree
Check tree block failed, want=54231040, have=18446744073709551615
Check tree block failed, want=54231040, have=18446744073709551615
Check tree block failed, want=54231040, have=18446744073709551615
Check tree block failed, want=54231040, have=18446744073709551615
Check tree block failed, want=54231040, have=18446744073709551615
read block failed check_tree_block
Couldn't setup log root tree
Checking filesystem on /dev/sda1
UUID: 77de157d-afb1-4774-b944-6cd086b42a7c
Creating a new extent tree
btrfsck: ctree.c:297: __btrfs_cow_block: Assertion `!(!(buf->flags & (1 << 10)) && btrfs_header_generation(buf) > trans->transid)' failed.
zsh: abort      btrfsck --repair --init-extent-tree --init-csum-tree /dev/sda1
Comment 3 Max Liebkies 2014-08-28 07:53:55 UTC
I had that exact same behaviour yesterday after a powerloss. Nearly every rescue method in described in the btrfs wiki failed (either errord out, segfaulted or failed an assertion) with either btrfs-progs 3.14, 3.16 or git. 

The only thing that helped was following this post: http://www.spinics.net/lists/linux-btrfs/msg36714.html

Shouldn't that "patch" be made into some sort of option to btrfs-zero-log?
Comment 4 Max Liebkies 2014-08-28 07:59:55 UTC
Oh and, I wasn't able to btrfs image the filesystem because that also segfaulted. Sorry...
Comment 5 dpisklov 2014-11-15 15:13:52 UTC
(In reply to Max Liebkies from comment #4)
> Oh and, I wasn't able to btrfs image the filesystem because that also
> segfaulted. Sorry...

@Max I've got exacly same thing but didn't try patching yet, will try now. I created https://bugzilla.kernel.org/show_bug.cgi?id=88181 bug but seems it can be closed as duplicate of this one.

Also found another one that seems exactly same issue:
https://bugzilla.kernel.org/show_bug.cgi?id=87021
Comment 6 dpisklov 2014-11-15 15:14:38 UTC
*** Bug 88181 has been marked as a duplicate of this bug. ***
Comment 7 dpisklov 2014-11-17 13:04:34 UTC
(In reply to Max Liebkies from comment #3)
> I had that exact same behaviour yesterday after a powerloss. Nearly every
> rescue method in described in the btrfs wiki failed (either errord out,
> segfaulted or failed an assertion) with either btrfs-progs 3.14, 3.16 or
> git. 
> 
> The only thing that helped was following this post:
> http://www.spinics.net/lists/linux-btrfs/msg36714.html
> 
> Shouldn't that "patch" be made into some sort of option to btrfs-zero-log?

I absolutely agree, it also solved my problem. That needs to be runtime option or better just delete relevant code path...
Comment 8 David Sterba 2014-11-18 16:32:12 UTC
That's effectively what these patches do (enhance zero-log to fix broken log tree pointer):

https://patchwork.kernel.org/patch/5206241/
https://patchwork.kernel.org/patch/5206221/

I'm going to add them to btrfs-progs 3.17.2 release.

The bug 87021 is a bit different and the patches will not help (it's not the log tree), though the underlying bug seems to be the same.
Comment 9 David Sterba 2014-11-19 17:06:14 UTC
Fixed in progs 3.17.2