Commit Graph

77 Commits

Author SHA1 Message Date
Josef Bacik 8795e785ce Btrfs-progs: fix double free of extent buffer
Noticed this while looking for an segfault related to our eb cache in
btrfsck.  We free the eb in out: so we don't need this extra free.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
2013-02-07 01:19:50 +01:00
Josef Bacik 6cba7b1b46 Btrfs-progs: handle errors reading fs roots
A user had a problem where btrfsck would bail out because it was finding
extents for a snapshot that had been deleted but not entirely cleaned up.
We can handle this case fine, we just need to report an error properly.
This patch allowed btrfsck to continue and eventually fix his file system.
Thanks,

Signed-off-by: Josef Bacik <jbacik@fusionio.com>
2013-02-07 01:19:49 +01:00
Zach Brown 6ea327567f btrfs-progs: free bits in check_extents()
As far as I can tell, nothing took the address of this.

Signed-off-by: Zach Brown <zab@redhat.com>
2013-02-05 16:09:40 -08:00
Zach Brown e37d9aa8e1 btrfs-progs: remove unused arguments
add_root_to_pending() took a bunch of arguments that it never used.

Signed-off-by: Zach Brown <zab@redhat.com>
2013-02-05 16:09:40 -08:00
Zach Brown 968efc6f98 btrfs-progs: more carefully check eb backrefs
check_owner_ref() could deref a null path node if btrfs_search_slot()
fails or simply doesn't find a tree tall enough to get to the parent of
the desired block.

This was flagged by static analysis warning that btrfs_search_slot()'s
return value wasn't being checked.

Signed-off-by: Zach Brown <zab@redhat.com>

Again: caught by static analysis.
2013-02-05 16:09:38 -08:00
Dieter Ries 629dfb8fa8 btrfs-progs: btrfsck: Print which filesystem to be checked to stdout
This patch makes btrfsck print the filesystem, which is to be checked,
to stdout, as well as the UUID of the corresponding partition.
This should be helpful when analyzing (copied and pasted) output of
btrfsck.

Signed-off-by: Dieter Ries <mail@dieterries.net>
2013-02-01 17:38:35 +01:00
Mark Fasheh 86279e7ef2 btrfs-progs: add extended inode ref support to btrfsck
Add a function, process_inode_extref() to be called from process_one_leaf()
when an item type of BTRFS_INODE_EXTREF_KEY is encountered.

Similarly to process_inode_ref(), process_inode_extref() walks an extref and
adds an inode_backref structure for each reference found within.

I modified fsck's inode_backref to get a type field (ref_type) which helps
us internally track the exact type of backrefs found.  Of course this field
could be overwritten in case of disk corruption (duplicate refs) but
duplicate refs themselves are tracked by btrfsck so that should not be an
issue as btrfsck is written today.

Signed-off-by: Mark Fasheh <mfasheh@suse.de>
2013-01-31 22:33:23 +01:00
Eric Sandeen 5cdc0913dd btrfs-progs: Use sysconf instead of getpagesize
Rawhide is getting cranky with posix compliance, and a few
things have stopped building.

getpagesize() is now only available -with- __USE_XOPEN_EXTENDED
or __USE_BSD, and NOT __USE_XOPEN2K.

_GNU_SOURCE must define __USE_XOPEN2K because getpagesize()
has gone away for mkfs.  I gave up and used sysconf.

Also, something used to pull in stat that no longer does, so
things like S_ISREG weren't getting defined.

The following fixes things for me.

Signed-off-by: Eric Sandeen <sandeen@redhat.com>
2013-01-23 19:27:13 +01:00
David Sterba 6cd836d7d9 btrfs-progs: ignore -a option in mkfs
Let mkfs accept '-a' option and not complain.  When a partition has non-zero
value in the fs_passno filed in /etc/fstab, the fsck is run but fails and boot
stops. As fsck does not break things currently, it's safe to ignore the option
and let the boot proceed.

Reference: https://bugzilla.novell.com/show_bug.cgi?id=655906

Signed-off-by: David Sterba <dsterba@suse.cz>
2013-01-17 18:34:40 +01:00
Miao Xie 50dcf9a5b4 Btrfs-progs: fix wrong return value of check_owner_ref()
If we find the block by seach corresponding fs tree, we should return 0,
and tell the caller we pass the check.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
2012-10-04 16:26:31 -04:00
Miao Xie f3f72863d5 Btrfs-progs: fix unresolved ref root message
btrfsck misinformed "unresolved ref root" message when there were several
snapshots in the file system. The patch(commit cfdd42686c70) tried to fix
this bug, but didn't fix it completely. If the metadata was stored in a
shared leaf of the tree, the problem would happen again. This patch fixes
it by another way, we don't check the relationship of the trees when we
traverse the fs/file tree, we just do the check when we merge the snapshot
records to the root cache.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
2012-10-04 16:26:31 -04:00
Miao Xie 78bffa2387 Btrfs-progs: fix wrong leaf when checking the trees relationship
The variant named 'leaf' in is_child_root() still hold old result after
we get the next leaf, it make btrfsck returns the wrong result, such as
"unresolved ref root ..", fix it.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
2012-10-04 16:26:31 -04:00
David Sterba 45e9ec733d btrfs-progs: fsck: understand the -s option
Short options have to be repeated at the getopt_long call.

Signed-off-by: David Sterba <dsterba@suse.cz>
2012-10-02 13:02:41 +02:00
Miao Xie cfdd42686c Btrfs-progs: fix btrfsck's snapshot wrong "unresolved refs"
If the fs/file tree is not the parent of the snapshot, it is reasonable
that we can not find the relative reference and back reference. But btrfsck
doesn't consider this case, and reports "unresolved refs" message, it's wrong,
fix it.

Signed-off-by: Miao Xie <miaox@cn.fujitsu.com>
2012-07-03 16:27:46 -04:00
Josef Bacik eda76e4629 Btrfs-progs: make btrfsck aware of free space inodes
The new xfstests will run fsck against the volume to make sure we didn't
introduce any inconsistencies, which is nice except we will error out
immediately if we mount with inode_cache.  We need to make btrfsck skip the
special free space cache items and then just assume that we have a link for
the free space cache inode item.  This makes btrfsck pass with success on a
fs with inode cache items.  Thanks,

Signed-off-by: Josef Bacik <josef@redhat.com>
2012-06-05 19:56:19 +01:00
Chris Mason e22827e9bb btrfsck: add early code to handle corrupted block groups
This is mostly disabled, but it is step one in handling
corrupted block groups in the extent allocation tree.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
2012-02-22 10:59:55 -05:00
Chris Mason af00db292e Btrfsck: add the ability to prune corrupt extent allocation tree blocks
When we discover bad blocks in the extent allocation tree, repair can
now discard them and recreate the references from the rest of the trees.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
2012-02-21 14:37:21 -05:00
Chris Mason 62b7993154 btrfsck: remove extents from the fsck reference tracker as they are freed
During btrfsck --repair, we make an index of extents that have incorrect
reference counts.  Once we've collect the whole index, we go through
and modify the extent allocation tree to reflect the correct results.

Changing the extent allocation tree may free blocks, and so it may
end up removing a block that had a missing reference structure.  The
fsck code may then circle back around and add the reference back.

The result is an extent that isn't actually used, but is recorded in the
extent allocation tree.

This commit adds a hook called as extents are freed.  The hook searches
the index of incorrect references and updates it to reflect the freeing
of the extent.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
2012-02-10 13:28:50 -05:00
Chris Mason ae1822f73f btrfsck: make sure we fix the block group accounting during repair
The block group accounting is fixed after we check the extent back
references.  This makes sure the accounting is fixed unless we
were not able to repair the backrefs.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
2012-02-09 11:53:33 -05:00
Chris Mason 47b104b7f1 btrfsck: add --init-csum-tree to replace the csum root with an empty one
This will effectively delete all of your crcs, but at least you'll
be able to mount the FS with nodatasum.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
2012-02-09 10:38:05 -05:00
Chris Mason 5fd54bc94b btrfsck: fix block group accounting during repair
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2012-02-08 21:29:13 -05:00
Chris Mason f5c4c4f3b7 btrfsck: add code to rebuild extent records
This also includes a new --repair btrfsck option.  For now it can
only fix errors in the extent allocation tree.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
2012-02-07 10:58:32 -05:00
Chris Mason 712c23e38e btrfsck: don't BUG on corrupted extent records 2012-02-06 08:53:43 -05:00
Chris Mason 6a4903c8ad btrfsck: print some progress
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2012-02-06 05:05:59 -05:00
Chris Mason e7580bb296 Add open_ctree_fs_info for partial FS opens
fsck needs to be able to open a damaged FS, which means open_ctree needs
to be able to return a damaged FS.

This adds a new open_ctree_fs_info which can be used to open any and all
roots that are valid.  btrfs-debug-tree is changed to use it.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
2012-02-05 16:11:48 -05:00
Sergei Trofimovich 3d7c94cfec btrfsck: decode error properly
check_mounted() returns kernel-style negative errors.
Patch drops sign for strerror().

Before the patch:
check_mounted(): Could not open /dev/sdb2
Could not check mount status: Unknown error 18446744073709551603

After the patch:
check_mounted(): Could not open /dev/sdb2
Could not check mount status: Permission denied

Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
2011-10-25 09:18:59 -04:00
Hugo Mills db9831e4f4 gcc 4.6: fix potentially unused variable
Fix a complaint by gcc 4.6 that "ret" may be unused in
process_one_leaf of btrfsck.

Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
2011-10-25 09:18:59 -04:00
Chris Ball fcdc0929c6 Fix unused-but-set errors in gcc-4.6
gcc-4.6 (as shipped in Fedora) turns on -Wunused-but-set-variable by
default, which breaks the build when combined with -Wall, e.g.:

debug-tree.c: In function ‘print_extent_leaf’:
debug-tree.c:45:13: error: variable ‘last_len’ set but not used [-Werror=unused-but-set-variable]
debug-tree.c:44:13: error: variable ‘last’ set but not used [-Werror=unused-but-set-variable]
debug-tree.c:41:21: error: variable ‘item’ set but not used [-Werror=unused-but-set-variable]
cc1: all warnings being treated as errors

This patch fixes the errors by removing the unused variables.

Signed-off-by: Chris Ball <cjb@laptop.org>
Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
2011-10-25 09:18:32 -04:00
Chris Mason 8c43a9adf7 Add btrfsck option to select the super block copy
btrfsck -s 0 uses the defult 0, -s 1 uses copy #1 etc.

Signed-off-by: Chris Mason <chris.mason@oracle.com>
2010-10-04 15:41:10 -04:00
Yan Zheng d44860cee5 Fix inode link count checks in btrfsck
Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
2010-09-23 20:26:50 -04:00
Yan Zheng 076de67f5b Remove superfluous WARN_ON in btrfsck
Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
2010-09-23 20:26:49 -04:00
Christian Hesse 34915ad27b add missing include for btrfsck.c
compiling btrfs-progs from current git I get an error in btrfsck.c about
undefined references. The attached patch adds an include for sys/stat.h
which fixes the problem for me.

Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
2010-09-23 20:26:49 -04:00
Andi Drebes 659d37c68d prevent btrfsck to run on mounted filesystems
As recently discussed on the list, btrfsck should only be run on
unmounted filesystems. This patch adds a short check for the mount
status at the beginning of btrfsck. If the FS is mounted, the
program aborts showing an error message.

Signed-off-by: Andi Drebes <lists-receive@programmierforen.de>
2010-09-23 20:26:49 -04:00
Yan, Zheng 6f3cf25a4e btrfsck: check root back/forward references
This patch adds semantic checks for links to snapshot/subvolume and
root back/forward references.

Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-09-21 16:03:57 -04:00
Chris Mason 95d3f20b51 Mixed back reference (FORWARD ROLLING FORMAT CHANGE)
This commit introduces a new kind of back reference for btrfs metadata.
Once a filesystem has been mounted with this commit, IT WILL NO LONGER
BE MOUNTABLE BY OLDER KERNELS.

The new back ref provides information about pointer's key, level and in which
tree the pointer lives. This information allow us to find the pointer by
searching the tree. The shortcoming of the new back ref is that it only works
for pointers in tree blocks referenced by their owner trees.

This is mostly a problem for snapshots, where resolving one of these fuzzy back
references would be O(number_of_snapshots) and quite slow.  The solution used
here is to use the fuzzy back references in the common case where a given tree
block is only referenced by one root, and use the full back references when
multiple roots have a reference
2009-06-08 13:30:36 -04:00
Luca Bruno 6fa19b04d9 Fix printf format casting errors
There are still some warnings of the form:

format '%llu' expects type 'long long unsigned int' but argument has type 'u64'

In conjunction with -Werror, this is causing some build failures.
Now they're properly casted, avoiding compiler warnings.

Signed-off-by: Luca Bruno <lucab@debian.org>
Signed-off-by: Chris Mason <chris.mason@oracle.com>
2009-06-03 12:15:40 -04:00
Chris Mason cc04d99e90 Add scan of the btrfs log tree to btrfs-debug-tree 2009-04-15 14:30:14 -04:00
Wang Cong 47e1a8f56a btrfsck.c: bit-fields should be unsigned
Signed-off-by: WANG Cong <wangcong@zeuux.org>
2009-01-21 13:22:49 -05:00
Thadeu Lima de Souza Cascardo af250420ca btrfsck: Exit and print error message when not able to open a device
If btrfsck is not able to open a device, it segfaults. This fixes it and
prints an error message too.
2009-01-21 13:59:36 -05:00
Wang Cong 86179a0507 btrfs-progs: make several functions static
Make several functions static, and make one argument const.

Signed-off-by: WANG Cong <wangcong@zeuux.org>
2009-01-21 13:22:49 -05:00
Yan Zheng 4f0347004e Fix an accessing freed memory bug in btrfsck 2009-01-09 14:39:33 -05:00
Yan Zheng 9a6930e9be Add semantic checks to btrfsck for files and directories
This patch makes btrfsck check more things, including
directory items, file extents, checksumming, inode link
counts etc.

The code for these checks is similar to the code verifies
extent back references. The main difference is that
shared tree blocks are treated specially. The partial
checking results(unresolved references and/or errors)
of shared sub-trees are cached. This avoids scanning
the shared blocks several times. Thank you,

Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
2009-01-07 14:57:12 -05:00
Yan Zheng 95470dfaf1 Add fallocate support v2
This patch updates btrfs-progs for fallocate support.
 
Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
2008-10-31 12:48:02 -04:00
Yan Zheng 5986faaf47 Remove offset field from struct btrfs_extent_ref
The offset field in struct btrfs_extent_ref records the position
inside file that file extent is referenced by. In the new back
reference system, tree leaves holding reference to file extent
are recorded explicitly. We can quickly scan these tree leaves, so the
offset field is not required.

This patch also makes the back reference system check the objectid
when extents are being deleted

Signed-off-by: Yan Zheng <zheng.yan@oracle.com>
2008-10-09 11:55:30 -04:00
Zheng Yan 428b7fa630 Full back reference support
This patch makes the back reference system to explicit record the
location of parent node for all types of extents. The location of
parent node is placed into the offset field of backref key. Every
time a tree block is balanced, the back references for the affected
lower level extents are updated.
2008-09-23 12:29:10 -04:00
Chris Mason 9864c90760 Print the version string in a few programs 2008-07-24 12:13:30 -04:00
Chris Mason 9a9bdd6047 Pass down the expected generation number when reading tree blocks 2008-05-12 13:51:24 -04:00
Chris Mason a62332eeb2 Add a readonly flag open_ctree to force RO opens 2008-05-05 09:45:26 -04:00
Chris Mason 9a73efb7d1 Fix compiler warning in volumes.c 2008-05-02 15:05:11 -04:00
Chris Mason 9462e711a7 Fix a few casts for 32 bit compile 2008-04-11 12:18:46 -04:00