summaryrefslogtreecommitdiff
path: root/cmds-check.c
Commit message (Collapse)AuthorAge
* btrfs-progs: btrfsck operations should be exclusiveAnand Jain2014-01-31
| | | | | | | | | this patch will make btrfsck operations to open disk in exclusive mode, so that mount will fail when btrfsck is running Signed-off-by: Anand Jain <Anand.Jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* Btrfs-progs: check return value of read_tree_block() in ↵Eryu Guan2014-01-31
| | | | | | | | | | | | | | | | | | | check_chunks_and_extents() The following steps could trigger btrfs segfault: mkfs -t btrfs -m raid5 -d raid5 /dev/loop{0..3} losetup -d /dev/loop2 btrfs check /dev/loop0 The reason is that read_tree_block() returns NULL and add_root_to_pending() dereferences it without checking it first. Also replace a BUG_ON with proper error checking. Signed-off-by: Eryu Guan <guaneryu@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* Btrfs-progs: add support for the no holes incompat flagJosef Bacik2014-01-31
| | | | | | | | | | This adds the flag to ctree.h, adds the feature option to mkfs to turn it on and fixes fsck so it doesn't complain about missing hole extents in files when this flag is set. Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* Btrfs-progs: deal with invalid key orderings and bad orphan items V2Josef Bacik2014-01-31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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-progs: reset balance before reiniting extent rootJosef Bacik2014-01-31
| | | | | | | | | | | | When we re-init the extent root we make it completely empty, so when we reset a pending balance we will fail to find refs for any blocks we may cow, which will result in errors and we will exit out. We need to reset the balance first so the normal cow stuff doesn't freak out and then we can re-init the extent tree. 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-progs: fix backref after init-csum-treeAnand Jain2014-01-31
| | | | | | | | | | | | | | | | | | | btrfsck reports backref error after running init-csum-tree btrfsck --init-csum-tree /dev/sdc btrfsck /dev/sdc :: ref mismatch on [29474816 16384] extent item 1, found 0 Backref 29474816 root 7 not referenced back 0x1101d30 Incorrect global backref count on 29474816 found 1 wanted 0 backpointer mismatch on [29474816 16384] owner ref check failed [29474816 16384] Errors found in extent allocation tree or chunk allocation :: Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: Make btrfs_header_chunk_tree_uuid() return unsigned longRoss Kirk2014-01-31
| | | | | | | | | | | | Internally, btrfs_header_chunk_tree_uuid() calculates an unsigned long, but casts it to a pointer, while all callers cast it to unsigned long again. From btrfs commit b308bc2f05a86e728bd035e21a4974acd05f4d1e Signed-off-by: Ross Kirk <ross.kirk@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: define BTRFS_UUID_UNPARSE_SIZE for uuid unparse buf sizeAnand Jain2014-01-31
| | | | | | | | | we use 37 as the allocation size to hold the uuid_unparse, here it defines BTRFS_UUID_UNPARSE_SIZE for the same. Signed-off-by: Anand Jain <anand.jain@oracle.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* Btrfs-progs: don't output baffling message when checking a fresh fsMiao Xie2014-01-31
| | | | | | | | | | | | | | | As we know, a new fs doesn't have space cache, so we set the cache generation of the super block to be -1ULL, it is not equal to the fs generation. But the check program didn't consider this case, and output the following message cache and super generation don't match, space cache will be invalidated directly, it would be baffling the users. So we should avoid outputing such message. This patch fixes this problem. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* Btrfs-progs: allow --init-extent-tree to work when extent tree is borkedJosef Bacik2014-01-31
| | | | | | | | | | | Unfortunately you can't run --init-extent-tree if you can't actually read the extent root. Fix this by allowing partial starts with no extent root and then have fsck only check to see if the extent root is uptodate _after_ the check to see if we are init'ing the extent tree. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* Btrfs-progs: fix btrfsck improper prompt on dropping snapshotsGui Hecheng2014-01-31
| | | | | | | | | | | | Exec btrfsck on btrfs with snapshots that are under a dropping progress will cause prompt on "ref mismatch". However we do not want this kind of prompt, since an remount operation will continue the dropping progress. Here the prompt is nonsense. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <clm@fb.com>
* btrfs-progs: remove more dead code from check_extent_refsEric Sandeen2013-11-07
| | | | | | | | | | e0a04278 removed a bunch of dead code but left one little bit; reinit is always 0, so btrfs_read_block_groups is never called from here. Resolves-Coverity-CID: 1125926 Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: rework open_ctree to take flags, add a new one V2Josef Bacik2013-11-07
| | | | | | | | | | | So I needed to add a flag to not try to read block groups when doing --init-extent-tree since we could hang there, but that meant adding a whole other 0/1 type flag to open_ctree_fs_info. So instead I've converted it all over to using a flags setting and added the flag that I needed. This has been tested with xfstests and make test. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: add -b to btrfsck to look at backup rootsJosef Bacik2013-11-07
| | | | | | | | | | In some cases the tree root is so hosed we can't get anything useful out of it. So add the -b option to btrfsck to make us look for the most recent backup tree root to use for repair. Then we can hopefully get ourselves into a working state. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: don't leak path in verify_space_cacheZach Brown2013-10-16
| | | | | | | | | This was found by static analysis. Signed-off-by: Zach Brown <zab@redhat.com> Reviewed-by: chandan <chandan@linux.vnet.ibm.com Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: remove dead block group checkingZach Brown2013-10-16
| | | | | | | | | Don't carry around dead code. If its needed again, it's only a few git commands away. This was found by static analysis. Signed-off-by: Zach Brown <zab@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: print out human readable errors for inodes and backrefsJosef Bacik2013-10-16
| | | | | | | | | | | | | We usually print out a hex value of any errors on inodes or their backrefs, which is a huge pain for me because I have to put it into a calculator and count the bits to figure out which errors these map to, and usually I get it wrong the first time. To fix this lets just print out a human readable string for each error that way it will be easier to spot the "OH GOD THAT'S AWFUL" errors from "oh yeah thats no big deal, repair will fix that." Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: keep track of transid failures and fix them if possibleJosef Bacik2013-10-16
| | | | | | | | | | | | | A user was reporting an issue with bad transid errors on his blocks. The thing is that btrfs-progs will ignore transid failures for things like restore and fsck so we can do a best effort to fix a users file system. So fsck can put together a coherent view of the file system with stale blocks. So if everything else is ok in the mind of fsck then we can recow these blocks to fix the generation and the user can get their file system back. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: make the repair option a global static varJosef Bacik2013-10-16
| | | | | | | | It's just annoying to have to pass it around everywhere. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: Make btrfs_header_fsid() return unsigned longRoss Kirk2013-10-16
| | | | | | | | | | | | | Internally, btrfs_header_fsid() calculates an unsigned long, but casts it to a pointer, while all callers cast it to unsigned long again. Committed to btrfs as fba6aa75654394fccf2530041e9451414c28084f Fix line length issues and match changes to kernelspace Signed-off-by: Ross Kirk <ross.kirk@gmail.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: remove unused parameter from btrfs_header_fsidRoss Kirk2013-10-16
| | | | | | | | | | Remove unused parameter, 'eb'. Unused since introduction in 7777e63b425f1444d2472ea05a6b2b9cf865f35b Signed-off-by: Ross Kirk <ross.kirk@gmail.com> Reviewed-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: make btrfsck fix backrefs that are brokenJosef Bacik2013-10-16
| | | | | | | | | | | | | | | | If you set an file extent item's disk_bytenr to something completely wrong we won't be able to fix this if it is the only one who has a ref on the original disk bytenr. Our extent records know exactly who is supposed to point at them, so if we have an extent record that has no backrefs we can go and try to lookup the backrefs ourselves. If these backrefs do not point to an extent record that was actually found then we can be pretty sure this extent record is valid and the backref is bogus. Then the verify_backref code can do its thing and reset the backref to point to the right extent record and we can all carry on. This fixes a user reported corruption. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: allow fsck to fix directory isize errorsJosef Bacik2013-10-16
| | | | | | | | | | A user reported a problem where he was unable to rmdir an empty directory. This is because his isize was wrong. This patch will fix this sort of corruption and allow him to rmdir his directory. Thanks Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: missing tree-freeing statements addedGui Hecheng2013-10-16
| | | | | | | | | The seen cache_tree in run_next_block freed. Originally, this "missing" causes memory leaks, reported by valgrind. Signed-off-by: Gui Hecheng <guihc.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: use NULL instead of 0Zach Brown2013-09-03
| | | | | | | | | These were mostly in option structs but there were a few gross string pointer arguments given as 0. Signed-off-by: Zach Brown <zab@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: fix extent key endian bug in repairZach Brown2013-09-03
| | | | | | | | | Extents rebuilt from backrefs can have their objectid mangled. The code tried to build a disk_key by hand and got the swabbing backwards. Signed-off-by: Zach Brown <zab@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: fix shadow symbolsZach Brown2013-09-03
| | | | | | | | | | | | | | | This fixes all the instances of warnings that symbols declared in blocks shadow symbols with the same name in surrounding scopes: cmds-device.c:341:22: warning: symbol 'path' shadows an earlier one cmds-device.c:285:14: originally declared here I just renamed or removed the risky shadow symbols instead of pulling their blocks out into functions. Signed-off-by: Zach Brown <zab@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: drop unused parameter from btrfs_release_pathEric Sandeen2013-09-03
| | | | | | | | | | | | | | | Port of commit b3b4aa7 to userspace. parameter tree root it's not used since commit 5f39d397dfbe140a14edecd4e73c34ce23c4f9ee ("Btrfs: Create extent_buffer interface for large blocksizes") This gets userspace a tad closer to kernelspace by removing this unused parameter that was all over the codebase... Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: add missing path alloc return value checkFilipe David Borba Manana2013-08-09
| | | | | | | | | Also remove unused path in extent-tree.c:finish_current_insert(). Signed-off-by: Filipe David Borba Manana <fdmanana@gmail.com> Reviewed-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: commit the csum_root if we do --init-csum-treeJosef Bacik2013-08-09
| | | | | | | | | | | | | This is just an oddity with the commit stuff in btrfs-progs. It will just update the generation of the root you call with, which in btrfsck case would have been the fs_root. But because we didn't actually update the fs_root we wouldn't have cow'ed the fs root and therefore the generation will not match the node which will make the file system unmountable. Fix this by calling with the csum_root which is the one we're messing with. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfs-progs: pass up return value of walk_down_treeLin Ming2013-08-09
| | | | | | | | | Pass up return value of walk_down_tree, so the caller can handle it. This also fixes a segfault when read_tree_block fails with NULL returned. Signed-off-by: Lin Ming <mlin@kernel.org> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: move btrfs_fsck_reinit_root to cmds-check.cEric Sandeen2013-08-09
| | | | | | | | | | | cmds-check.c contains the only caller of btrfs_fsck_reinit_root; moving it to the caller's source file gets ctree.c a little closer to kernelspace, although it does require exporting add_root_to_dirty_list(), which is not done in kernelspace. Signed-off-by: Eric Sandeen <sandeen@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* btrfsck: fix incorrect casting on items in the corrupt_blocks treeChris Mason2013-07-05
| | | | | | | check_extent_refs is pinning down all the corrupt tree blocks it finds, but it is incorrectly casting these to an extent_record first. Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: Add chunk rebuild function for RAID1/SINGLE/DUPMiao Xie2013-07-03
| | | | | | | | | | | | | Add chunk rebuild for RAID1/SINGLE/DUP to chunk-recover command. Before this patch chunk-recover can only scan and reuse the old chunk data to recover. With this patch, chunk-recover can use the reference between chunk/block group/dev extent to rebuild the whole chunk tree even when old chunks are not available. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: Add chunk recover function - using old chunk itemsMiao Xie2013-07-03
| | | | | | | | | | | | | | | | | | Add chunk-recover program to check or rebuild chunk tree when the system chunk array or chunk tree is broken. Due to the importance of the system chunk array and chunk tree, if one of them is broken, the whole btrfs will be broken even other data are OK. But we have some hint(fsid, checksum...) to salvage the old metadata. So this function will first scan the whole file system and collect the needed data(chunk/block group/dev extent), and check for the references between them. If the references are OK, the chunk tree can be rebuilt and luckily the file system will be mountable. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: Add block group check funtionMiao Xie2013-07-03
| | | | | | | | | This patch adds the function to check correspondence between block group, chunk and device extent. Original-signed-off-by: Cheng Yang <chenyang.fnst@cn.fujitsu.com> Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: extend the extent cache for the device extentMiao Xie2013-07-03
| | | | | | | | | | | | As we know, btrfs can manage several devices in the same fs, so [offset, size] is not sufficient for unique identification of an device extent, we need the device id to identify the device extents which have the same offset and size, but are not in the same device. So, we added a member variant named objectid into the extent cache, and introduced some functions to make the extent cache be suitable to manage the device extent. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: introduce common insert/search/delete functions for rb-treeMiao Xie2013-07-03
| | | | | | | | | In fact, the code of many rb-tree insert/search/delete functions is similar, so we can abstract them, and implement common functions for rb-tree, and then simplify them. Signed-off-by: Miao Xie <miaox@cn.fujitsu.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: fix reference check for roots in btrfsckJosef Bacik2013-06-19
| | | | | | | | | | | | | I noticed that I was getting these errors on a bigger file system with more snapshots that had been removed. This check is bogus since we won't inc rec->found_ref if we don't find a REF_KEY _and_ a DIR_ITEM, so we only have to worry about there being no references to a root if it actually has a root item. If it doesn't then it's just referenced by things that will go no where anyway. With this patch fsck no longer incorrectly complains about this file system image I have. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: fix incorrect root backref errors in fsckJosef Bacik2013-06-19
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: fix fsck dealing with finding backrefs firstJosef Bacik2013-06-19
| | | | | | | | | | | | | | | There is a problem where if we find a backref extent record first that doesn't match a extent item we will delete some of the duplicates but not others. In order to deal with this we need to make sure we only pay attention to duplicates that actually have duplicate extent items. If a extent_rec has a duplicate but the record itself doesn't have an associated extent item we promote the duplicate to the extent record and just discard the original extent_rec since it was just added by the backref. We copy the backref onto the promoted extent record and then continue processing. This allowed me to fix a file system that previously was not able to be fixed by fsck. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: fix free space cache checksJosef Bacik2013-06-19
| | | | | | | | | | | | This fixes two bugs with the free space cache checker. First is we apparently always use root->sectorsize for our unit in the kernel so we have to do that in progs otherwise bitmaps turn out to not look right if we have leafsize != sectorsize. The second is a small issue if we had skinny metadata extents set, we wouldn't advance last properly because we unconditionally use key.offset instead of root->leafsize. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: add --init-extent-tree to btrfsckJosef Bacik2013-06-19
| | | | | | | | | | | | | In some cases the extent tree can just be so gone there is no point in trying to figure out how to put it back together. So add a --init-extent-tree mode which will zero out the extent tree and then re-add extents for all of the blocks we find. This will also undo any balance that was going on at the time of the crash, this is needed because the reloc tree seems to confuse fsck at the moment. With this patch I can put back together a users file system that was completely gone. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: make fsck fix certain file extent inconsistenciesJosef Bacik2013-06-19
| | | | | | | | | | | | | | | | | | | | | | The tree log bug I introduced could create inconsistent file extent entries in the file system tree and in some worst cases even create multiple extent entries for the same entry. To fix this we need to do a few things 1) Keep track of extent items that overlap and then pick the one that covers the largest area and delete the rest of the items. 2) Keep track of file extent items that land in extent items but don't match disk_bytenr/disk_num_bytes exactly. Once we find these we need to figure out who is the right ref and then fix all of the other refs to agree. Each of these cases require a complete rescan of all of the extents, so unfortunately if you hit this particular problem the fsck is going to take quite a while since it will likely rescan all the trees 2 or 3 times. With this patch the broken file system a user sent me is fixed and a broken file system that was created by my reproducer is also fixed. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: add the ability to find mismmatching backrefsJosef Bacik2013-05-10
| | | | | | | | | | | | | An unfortunate side effect to my fsync bug means that anybody who didn't hit the BUG_ON() during tree log replay would have ended up with a corrupted file system. Currently our fsck does not catch this because it just looks for bytenrs for backrefs, it doesn't look at the num_bytes at all. So this patch makes us keep track of how big the backrefs are, since their disk_num_bytes _have_ to match the number of bytes for the actual extent item. With this patch fsck now finds problems with a file system it previously thought was ok. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com>
* Btrfs-progs: init free space ctl with proper unitJosef Bacik2013-05-06
| | | | | | | | | | | btrfsck was blowing up when checking the free space cache when we ran xfstests with -l 64k. That is because I was init'ing the free space ctl to whatever the leafsize was, which isn't right for data block groups. With this patch btrfsck no longer complains. This also fixes a tiny little typo in free-space-cache.c I noticed while figuring this problem out. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com> Signed-off-by: Chris Mason <chris.mason@fusionio.com>
* Btrfs-progs: make restore deal with really broken file systemsJosef Bacik2013-04-23
| | | | | | | | | | | | | | | | | All we need for restore to work is the chunk root, the tree root and the fs root we want to restore from. So to do this we need to make a few adjustments 1) Make open_ctree_fs_info fail completely if it can't read the chunk tree. There is no sense in continuing if we can't read the chunk tree since we won't be able to translate logical to physical blocks. 2) Use open_ctree_fs_info in restore, and if we didn't load a tree root or fs root go ahead and try to set those up manually ourselves. This is related to work I did last year on restore, but it uses the open_ctree_fs_info instead of my open coded open_ctree. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com>
* Btrfs-progs: fix csum check when extent lands on block groupJosef Bacik2013-04-23
| | | | | | | | | | | | | | | | I was running fsync() tests and noticed that occasionally I was getting a bunch of errors from fsck complaining about csums not having corresponding extents. Thankfully after a few days of debugging this it turned out to be a bug with fsck. The csums were for an extent that started at the same offset as a block group, and were offset within the extent. So the search put us out at the block group item and we just walked forward from there, never finding the actual extent. This is because the block group item key is higher than the extent item key, so it comes first. In order to fix this we need to check and see if we landed on a block group item and take another step backwards to make sure we end up at the extent item. With this patch my reproducer no longer finds csums that don't have matching extent records. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com>
* Btrfs-progs: add csum tree checks to btrfsckJosef Bacik2013-04-23
| | | | | | | | | | Looking at a recent user problem I noticed there are weird cases we could possibly be leaving csums in place for an extent we've free'd. I don't think this can happen unless the extent tree is also corrupt, but just in case I'm adding sanity checks to btrfsck. This way we will catch this if it happens normally since xfstests runs btrfsck between each run. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com>
* Btrfs-progs: fix segfault in fsck if the chunk tree is bogusJosef Bacik2013-04-23
| | | | | | | | | I made open_ctree fail if the chunk tree couldn't be open, which means that fsck now segfaults if it can't open the chunk tree. So fix fsck to check the fs_info we get back from open_ctree_fsinfo to make sure it's valid and exit if it's not instead of segfaulting. Thanks, Signed-off-by: Josef Bacik <jbacik@fusionio.com>