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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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>
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
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>
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>
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>
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.