We need to start adding some sanity tests to btrfs-progs to make sure we aren't
breaking things with our patches. The most important of these tools is btrfsck.
This patch gets things started by adding a basic btrfsck test that makes sure we
can fix a corruption problem we know we can fix. 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>
Until now if one of device's first superblock is corrupt,btrfs will
fail to mount. Luckily, btrfs have at least two superblocks for
every disk.
In theory, if silent corrupting happens when we are writting superblocks
into disk, we must hold at least one good superblock.
One side effect is that user must gurantee that the disk must be
a btrfs disk. Otherwise, this tool may destroy other fs.(This is also
reason why btrfs only use first superblock in every disk to mount)
This little program will try to correct bad superblocks from
good superblocks with max generation.
There will be five kinds of return values:
0: all supers are valid, no need to recover
1: usage or syntax error
2: recover all bad superblocks successfully
3: fail to recover bad superblocks
4: abort to recover bad superblocks
Signed-off-by: Wang Shilong <wangsl.fnst@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
The devices in 'btrfs filesystem show' are now sorted by the device id,
currently the order was undefined.
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
The command has been moved and we should rename the files accordingly,
so the entry point is now in cmds-rescue.c and the core functionality
in it's own file.
Return codes of btrfs_recover_chunk_tree have been simplified not to
require a define and another file for defintion.
CC: Miao Xie <miaox@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Add an empty 1st level command namespace that will collect specialized
recovery tools like chunk-recover, zero-log, select-super and similar.
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Preparatory patch to move cmd & test files into their
own subdirs.
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>
There were a few problems that were breaking sparse checking:
- We were defining CHECK_ENDIAN late in the environment, after
linux/fs.h has been included which defines __force and __bitwise in
confusing ways that conflict with ours. Define it up with __CHECKER__
so that linux/fs.h and our copy are acting on the same input.
- We had manually set a few of gcc's internal defines to give to sparse.
It's easier to just ask gcc for all the defines it sets and hand those
to sparse.
- We weren't passing the same *FLAGS to sparse as we were to CC.
- glibc has so many errors with FORTIFY turned on that sparse gives up
and doesn't show us any errors from our code. It's a questionable
hack to always turn on FORTIFY ourselves, so we'll just not do that
when building with sparse.
And add a nice '[SP]' quiet output line for sparse checks.
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>
Some files don't compile because of insufficient prerequisite.
$ make btrfs
...
[CC] btrfs.o
btrfs.c:24:21: fatal error: version.h: No such file or directory
#include "version.h"
^
compilation terminated.
make: *** [btrfs.o] Error 1
Signed-off-by: Kusanagi Kouichi <slash@ac.auone-net.jp>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
This commit adds UUID tree lookup methods that make use of the search
ioctl. The code is based on the kernel code.
Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Signed-off-by: Richard W.M. Jones <rjones@redhat.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
btrfsck gets hardlinked to btrfs during the build, but the
install phase simply copies them both to the destination without
preserving the link.
Just force-link btrfsck in the destination again during install
so that the installed btrfsck is a link as well.
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>
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>
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>
Add a default rule for any btrfs-$FOO or btrfs-$FOO.static
target, allowing it to be built from btrfs-$FOO.c along with
all the normal userspace objects.
This gets rid of a lot of the cut and pasted rules for
each individual command, and as an added bonus makes it
easy to build any btrfs-$FOO statically as well, i.e.
# make btrfs-convert.static
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
For any btrfs-$FOO executable, rename the main source file from
$FOO.c to to btrfs-$FOO.c
This makes it slightly more obvious what's building what,
and allows us to write a default rule in the Makefile for
these tools.
(also add btrfs-calc-size to the list of objects to remove
on make clean)
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
In trying to track down a weird tree log problem I wanted to make sure that the
free space cache was actually valid, which we currently have no way of doing.
So this patch adds a bunch of support for the free space cache code and then a
checker to fsck. Basically we go through and if we can actually load the free
space cache then we will walk the extent tree and verify that the free space
cache exactly matches what is in the extent tree. Hopefully this will always be
correct, the only time it wouldn't is if the extent tree is corrupt or we have
some sort of awful bug in the free space cache. Thanks,
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
send-test.c links against libbtrfs and uses the send functionality provided
to decode and print a send stream to the console.
66819df "btrfs-progs: add send-test" contained this file when
submitted, but somehow got lost on commit.
[sandeen@redhat.com: Resurrect lost send-test.c from original commit]
Signed-off-by: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
This tool can be used to compute btrfs' style crc32c checksums for filenames
as done by the kernel. Additionally, there is -c mode to do a brute force
search for file names with a given checksum.
Signed-off-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
This tool draws per-chunk pngs representing the allocation map. A black
or colored dot means the block is allocated.
The output is written to a subdirectory, together with an index.html to be
viewed in a browser.
There are options to control whether color should be used and which block
group types should be printed.
To build, you need to have libpng and libgd installed. It is not part of
the 'all' target, so please build it explicitely with make btrfs-fragments.
A (rather untypical) example can be seen at
http://sensille.com/fragments
Please regard this as a first scratch version and feel free to improve it :)
Signed-off-by: Arne Jansen <sensille@gmx.net>
* create .static.o version from the library objects as well and use them
for building static targets
* remove build dependencies on libbtrfs.*
* other minor cleanups
Signed-off-by: David Sterba <dsterba@suse.cz>
With the commit 002d021c (committed October 2011)
btrfsctl, btrfs-vol, btrfs-show were declared deprecated.
The last patches related to these commands are dated December 2010.
These tools are replaced by the "btrfs" tool in all the
functionality.
This commit removes all the related code.
Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Signed-off-by: David Sterba <dsterba@suse.cz>
Detected by gentoo's QA checker:
* QA Notice: Files built without respecting LDFLAGS have been detected
* Please include the following list of files in your report:
* /usr/lib/libbtrfs.so.0.1
Signed-off-by: Sergei Trofimovich <slyfox@gentoo.org>
btrfs-find-root isn't yet integrated into the main btrfs tool, and is
an important recovery tool, so it deserves to be built as a static
binary.
Signed-off-by: Hugo Mills <hugo@carfax.org.uk>
Static mkfs.btrfs can be used to "bootstrap" a system from a live CD
which does not provide mkfs.btrfs.
The executable produced is named mkfs.btrfs.static and built by invoking
the "static" make rule.
Signed-off-by: Antoine Sirinelli <antoine@monte-stello.com>
Linking 'btrfs' and other binaries against the dynamic library makes it
tedious to use directly from the git repo. This is useful for testing
various fixes, but now it'd need to also set LD_LIBRARY_PATH or install
the library to a known path.
Add a target for static library and use it for linking, the dynamic
library is to be used by external users.
Signed-off-by: David Sterba <dsterba@suse.cz>
External software wanting to use the functionality provided by the btrfs
send ioctl has a hard time doing so without replicating tons of work. Of
particular interest are functions like btrfs_read_and_process_send_stream()
and subvol_uuid_search(). As that functionality requires a bit more than
just send-stream.c and send-utils.c we have to pull in some other parts of
the progs package.
This patch adds code to the Makefile and headers to create a library,
libbtrfs which the btrfs command now links to.
Signed-off-by: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
Clean btrfslabel.[c|h] out of the source tree and move those related
functions to utils.[c|h].
CC: Gene Czarcinski <gene@czarc.net>
Signed-off-by: Jie Liu <jeff.liu@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
The core of this is shamelessly stolen from xfsprogs.
Use blkid to detect an existing filesystem or partition
table on any of the target devices. If something is found,
require the '-f' option to overwrite it, hopefully avoiding
disaster due to mistyped devicenames, etc.
# mkfs.btrfs /dev/sda1
WARNING! - Btrfs v0.20-rc1-59-gd00279c-dirty IS EXPERIMENTAL
WARNING! - see http://btrfs.wiki.kernel.org before using
/dev/sda1 appears to contain an existing filesystem (xfs).
Use the -f option to force overwrite.
#
This does introduce a requirement on libblkid.
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
send-test.c links against libbtrfs and uses the send functionality provided
to decode and print a send stream to the console.
Signed-off-by: Mark Fasheh <mfasheh@suse.de>
Signed-off-by: David Sterba <dsterba@suse.cz>
Add 'btrfs restore' command which previously existed as a separate
utility btrfs-restore.
Signed-off-by: Ian Kumlien <pomac@demius.net>
Signed-off-by: David Sterba <dsterba@suse.cz>
This patch includes the functionality of btrfs, it's
found as "btrfs check".
Signed-off-by: Ian Kumlien <pomac@demius.net>
Signed-off-by: David Sterba <dsterba@suse.cz>
My builds are cluttered with:
<command-line>:0:0: warning: "_FORTIFY_SOURCE" redefined [enabled by
default]
Which makes it hard to tell if something breaks or not.
Signed-off-by: Ian Kumlien <pomac@demius.net>
Sometimes, when you least expect it, a static binary is what you need to
rescue your data... Or just get a good enough handle on things to make
it work again ;)
"make static" is a gift to you, dear user with filesystem problems!
Anyway, on a more serious note, changed the cflags and ldflags so that
we create a smaller binary, 1.1MB stripped on my 64 bit system
(2.7MB with debug data)
Signed-off-by: Ian Kumlien <pomac@demius.net>
David Woodhouse originally contributed this code, and Chris Mason
changed it around to reflect the current design goals for raid56.
The original code expected all metadata and data writes to be full
stripes. This meant metadata block size == stripe size, and had a few
other restrictions.
This version allows metadata blocks smaller than the stripe size. It
implements both raid5 and raid6, although it does not have code to
rebuild from parity if one of the drives is missing or incorrect.
Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
Signed-off-by: Chris Mason <chris.mason@fusionio.com>
Parallel build may fail due to late creation of version.h, fix the rule name
that does not match the filename.
Signed-off-by: David Sterba <dsterba@suse.cz>
Reviewed-by: Eri Sandeen <sandeen@redhat.com>
This is the user mode part of the device replace patch series.
The command group "btrfs replace" is added with three commands:
- btrfs replace start srcdev|srcdevid targetdev [-Bfr] mount_point
- btrfs replace status mount_point [-1]
- btrfs replace cancel mount_point
Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
The definition of the function open_file_or_dir() is moved from common.c
to utils.c in order to be able to share some common code between scrub
and the device stats in the following step. That common code uses
open_file_or_dir(). Since open_file_or_dir() makes use of the function
dirfd(3), the required XOPEN version was raised from 6 to 7.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
Original-Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
A quieter build makes warnings more obvious.
This could probably be improved, but just to see
if people like this or if they hate it. :)
make V=1 overrides it and gets you the full
glory again.
[CC] ctree.o
[CC] disk-io.o
[CC] radix-tree.o
[CC] extent-tree.o
...
Signed-off-by: Eric Sandeen <sandeen@redhat.com>
Just a small program to print the fields of a super block.
Signed-off-by: Stefan Behrens <sbehrens@giantdisaster.de>
Signed-off-by: Goffredo Baroncelli <kreijack@inwind.it>
Patch rebased because of changes in mkfs.c but otherwise the same
as created by Josef Bacik
SSD's do not gain anything by having metadata DUP turned on. The underlying
file system that is a part of all SSD's could easily map duplicate metadat
blocks into the same erase block which effectively eliminates the benefit of
duplicating the metadata on disk. So detect if we are formatting a single
SSD drive and if we are do not use DUP. Thanks,
Signed-off-by: Josef Bacik <jbacik@fusionio.com>
Signed-off-by: Gene Czarcinski <gene@czarc.net>
Add user space commands for btrfs send/receive.
Signed-off-by: Alexander Block <ablock84@googlemail.com>
Reviewed-by: David Sterba <dave@jikos.cz>
Reviewed-by: Arne Jansen <sensille@gmx.net>
Reviewed-by: Jan Schmidt <list.btrfs@jan-o-sch.net>
Reviewed-by: Alex Lyakas <alex.bolshoy.btrfs@gmail.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>