Commit Graph

1918 Commits (0522713f3c0a2251e7e52e747f2008ed78dba7f9)
 

Author SHA1 Message Date
Qu Wenruo 0522713f3c btrfs-progs: btrfstune: add ability to restore unfinished fsid change
Now change_uuid() can auto detected unfinished fsid change and restore
it.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-26 17:21:46 +02:00
Qu Wenruo e737a9d56b btrfs-progs: btrfstune: rework change_uuid
Change the change_uuid():
1) Remove new_chunk_tree_uuid parameter
   As chunk_tree_uuid is only internal used, no need to manual specify it.
   Use random generated UUID instead.

2) Don't use heap allocated memory for fs_info->new_fsid/chunk_tree_id.
   It's easy to forgot free or double free heap memory.
   Use stack memory instead.
   (In fact, I forgot to free them in previous patchset)

3) Print destination fsid.
   As now it's possible to change fsid to random uuid, it's better to print
   it out.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-26 16:48:16 +02:00
Josef Bacik af3b243358 Btrfs-progs: corrupt-block: add the ability to remove csums
Sometimes we need to test what happens when we're missing a csum for a range, so
add an option to btrfs-corrupt-block to be able to remove a csum range.  Thanks,

Signed-off-by: Josef Bacik <jbacik@fb.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-26 16:38:32 +02:00
Emil Karlson 5d4f3ea9b4 btrfs-progs: use openat for process_clone in receive
This will fix breakage, when doing chrooted receive with cloned paths
outside main subvolume.

Steps to reproduce:
 $ create subvolume
 $ create file
 $ snapshot to snap1
 $ delete file
 $ snapshot to snap2
 $ reflink file from snap1
 $ snapsthot to snap3

 $ send full snap1 | receive --chroot
 $ send incremental snap2 | receive --chroot
 $ send incremental snap3 | receive --chroot

The last step would fail with:

 Chroot to /mnt/recvdir
 At snapshot snap3
 ERROR: failed to open /recvdir/snap1/file. No such file or directory

Signed-off-by: Emil Karlson <jekarlson@gmail.com>
[added reproducer]
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-26 16:31:32 +02:00
David Sterba b51cc1d325 btrfs-progs: tests: add script to clean intermediate images
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-25 16:10:58 +02:00
David Sterba 1497c92e67 btrfs-progs: test: 015-check-bad-memory-access
Crafted images may trigger out-of-bounds access during check, fixed by
"btrfs-progs: Enhance read_tree_block to avoid memory corruption"

Now adding image for the first one, the other need enhancements in the
testing framework.

Reference: https://bugzilla.kernel.org/show_bug.cgi?id=97171
Reference: https://bugzilla.kernel.org/show_bug.cgi?id=97191
Reference: https://bugzilla.kernel.org/show_bug.cgi?id=97271
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-25 16:10:48 +02:00
David Sterba e413938ea9 btrfs-progs: tests: sort image files
If a test has several images let filenames enforce a particular order of
checks if desired.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-25 15:35:58 +02:00
Qu Wenruo 6c9e4dacb2 btrfs-progs: Enhance read_tree_block to avoid memory corruption
Add the following tree block check to avoid memory corruption on hostile
image:
1) Check level.
Level >= BTRFS_MAX_LEVEL won't be read out.

2) Nritems.
For nr_items > max_nritems, the tree_block won't be read out.
Max nritems is calculated in a easy method.
For node, it's straightforward, just (nodesize - header size) /
(btrfs_key_ptr)
For leaf, (nodesize - header size) / (btrfs_item), as btrfs support zero
item size

This fixes 3 kernel bugs: BZ#97171, BZ#97191, BZ#97271.

Reported-by: Lukas Lueg <lukas.lueg@gmail.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-25 14:58:58 +02:00
David Sterba 9e3e423d68 btrfs-progs: tests: use readlink -f to resolve path
The utility 'realpath' from coreutils is new enough to be missing on my
"old" reference build host.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-21 18:48:55 +02:00
Dimitri John Ledkov 7f1ccecfaa btrfs-progs: fsck.btrfs: Fix bashism and bad getopts processing
First fix == bashism, as that is not accepted by e.g. Debian/Ubuntu
dash.

Secondly shift OPTIND, such that last parameter is checked to exist.

Signed-off-by: Dimitri John Ledkov <dimitri.j.ledkov@intel.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-21 16:53:44 +02:00
David Sterba d6cedbcdd3 btrfs-progs: tests: support more formats of test images
We're using he meta-dump images, now we support compressed meta-dump,
raw and compressed raw images.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-21 16:37:52 +02:00
David Sterba 7c6801606e btrfs-progs: tests: log the test name in results file
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-21 16:37:52 +02:00
David Sterba c061b303c0
Btrfs progs v4.0.1
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-20 15:12:44 +02:00
Qu Wenruo 4643934109 btrfs-progs: Fix a bug in chunk item extra check and allow degraded chunk.
For DUP profile, the num_stripes should be 2 not 1.
This causes btrfs offline tool fails on valid image.

Also, num_stripes check is too restrict for btrfsck self test,
as there is some image in degraded mode, so modify it to allow degraded
chunk.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-20 14:24:26 +02:00
Qu Wenruo f146c40c65 btrfs-progs: Add extra chunk item check to avoid btrfs-progs crash.
Adds extra check when reading a chunk item:
1) Check chunk type.
Don't allow any unsupported type/profile bit.

2) Check num_stripes
Any chunk item should contain at least one stripe.
For system chunk, the chunk item size(calculated by btrfs_stripe size *
(num_stripes - 1) + btrfs_chunk size) should not exceed
BTRFS_SYSTEM_CHUNK_SIZE(2048).
For normal chunk, the chunk item size(calculated) should match the chunk
item size.

3) Check num_stripes/sub_stripes against chunk profile.
Num_stripes/sub_stripes must meet its lower limit for its chunk profile.

Reported-by: Lukas Lueg <lukas.lueg@gmail.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:08 +02:00
Qu Wenruo 20ce7d3ee6 btrfs-progs: Remove non-exist csum size.
Current btrfs only support CRC32 as checksum algorithm.
But in btrfs_csum_sizes array, we have an extra 0 at tail, causing
csum_type 1 can still be considered as supported csum type.

Fix it by removing the tailing 0.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:08 +02:00
Qu Wenruo 235072c2ee btrfs-progs: Introduce change_uuid function
This function does all the needed things for changing filesystem uuid.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:08 +02:00
Qu Wenruo d275dbd183 btrfs-progs: Introduce change_fsid_prepare and change_fsid_done functions
These two functions will write flags to all supers before and after
fsid/chunk tree id change, informing kernel not to mount a inconsistent
fs.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[removed chunk tree super flag]
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:08 +02:00
Qu Wenruo 01cdf01ecf btrfs-progs: Introduce change_devices_uuid function.
This function will change all device items' fsid.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:07 +02:00
Qu Wenruo cff8aa2313 btrfs-progs: Introduce change_device_uuid function
This function changes a device items uuid.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:07 +02:00
Qu Wenruo 605621993d btrfs-progs: Introduce change_extents_uuid function
This is the function which iterates all metadata extents and changes
their fsid.

This function also does it without transaction.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:07 +02:00
Qu Wenruo 0c8b978881 btrfs-progs: Introduce change_header_uuid function
This function is used to change fsid and chunk_tree_uuid of a node/leaf.
The function does it without transaction protection.

This is the basis of offline uuid change.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:07 +02:00
Qu Wenruo 92b020ee04 btrfs-progs: Export write_tree_block
Export write_tree_block() function and allow it write extent without
transaction.

This provides the basis for later uuid change function.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:07 +02:00
Qu Wenruo 2259f03439 btrfs-progs: Add open_ctree check for uuid changing
Now open_ctree will exit if it found the superblock is marked
CHANGING_FSID, except given IGNORE_FSID open ctree flags.

Kernel will do the same thing later.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[removed the chunk tree flag, reworded the error message]
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:07 +02:00
Qu Wenruo 9ae2b8b52f btrfs-progs: show-super: print human readable text for super flags
Use the new __print_readable_flag() to implement
print_readable_super_flag().

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[removed the chunk tree flag]
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:07 +02:00
Qu Wenruo b8436121c2 btrfs-progs: Use unified function to implement print_readable_*_flag function
Now add a new unified __print_readable_flag() function to implement
print_readable_incompat_flag().

This makes later extension for human readable flags easier.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:07 +02:00
Qu Wenruo 7cc792872a btrfs-progs: Add CHANGING_FSID super flag
Add the super flag to inform kernel not to mount a filesystem wich fsid
change is in progress.

Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
[removed the chunk tree flag]
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:07 +02:00
Anand Jain fda6638093 btrfs-progs: use the correct variable
It's res instead of ret, wrong error message could be prointed in case
of error.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:07 +02:00
Anand Jain e9b5ff23ea btrfs-progs: btrfs_scan_block_devices is unused function delete it
After Patch:
 remove BTRFS_SCAN_PROC scan method
There isn't any consumer for btrfs_scan_block_devices() so delete it.

Signed-off-by: Anand Jain <anand.jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:06 +02:00
Qu Wenruo f4fac5d46e btrfs-progs: fsck: Fix a shallow copy which will leads to segfault.
In copy_inode_rec(), a shallow copy happens on rec->holes rb_root.
So for shared inode case, new rec->holes still points to old rb_root,
and when the old inode record is freed, the new inode_rec->holes will
points to garbage and cause segfault when we try to free new
inode_rec->holes.

Fix it by calling copy_file_extent_holes() to do deep copy.

Reported-by: Eric Sandeen <sandeen@redhat.com>
Reported-by: Filipe David Manana <fdmanana@gmail.com>
Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:06 +02:00
David Sterba ab5984ff6c btrfs-progs: convert: drop dependency on sys/acl.h
The file sys/acl.h is part of libacl and if the development package is
not installed, build of btrfs-convert fails.

We do not link against libacl nor use the functions provided by libacl.  The
ACL_* values are directly read from the extN data, so it's more part of the
on-disk format rather than an interface to libacl.

The dependency on libacl is completely dropped.

Reported-by: Hugo Mills <hugo@carfax.org.uk>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:06 +02:00
David Sterba bea9ba0acb btrfs-progs: restore: add more long option variants
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:06 +02:00
David Sterba 18b48340de btrfs-progs: restore: shift option texts
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:06 +02:00
David Sterba ffd53c0fe8 btrfs-progs: restore: use bigger buffer for output path name
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:06 +02:00
Dan Merillat bd91f80725 btrfs-progs: optionally restore symlinks.
Restore symlinks, optionally with owner/times.

Signed-off-by: Dan Merillat <dan.merillat@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-05-14 15:41:02 +02:00
Dan Merillat 829950844e btrfs-progs: restore: separate the overwrite check
Symlink restore needs this, but the cut&paste became too complicated.
Simplify everything.

Signed-off-by: Dan Merillat <dan.merillat@gmail.com>
[message wording adjustments]
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-29 17:55:18 +02:00
David Sterba 19a806f575
Btrfs progs v4.0
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-29 16:56:22 +02:00
David Sterba 630a917aa1 btrfs-progs: restore: don't misreport errors from search_dir
The logic around return value has changed in the metadata restore
patches. The return value from btrfs_search_slot may remain non-zero and
is returned. This is incorrectly interpreted as an error.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-29 16:48:04 +02:00
David Sterba 1b7dd327f4 btrfs-progs: receive: unconditionally print if doing chroot
The chroot action seems important enough to be printed unconditionally
and without the verbose option that prints way too much information.

Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-24 18:01:32 +02:00
David Sterba 582e156baf btrfs-progs: fix typos in restore help/doc
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-24 17:28:37 +02:00
Dan Merillat ce72ae32d2 btrfs-progs: restore: document metadata restore.
This was lost in the cleanup of 71a559

Signed-off-by: Dan Merillat <dan.merillat@gmail.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-24 17:07:34 +02:00
David Sterba faf8b94323 btrfs-progs: restore: cleanup, use PATH_MAX
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-24 15:42:05 +02:00
David Sterba 6e0a620ba6 btrfs-progs: check: fix compile warnings in del_file_extent_hole
make[1]: Nothing to be done for `all'.
cmds-check.c: In function ‘del_file_extent_hole’:
cmds-check.c:289:26: warning: ‘prev.start’ may be used uninitialized in this function
cmds-check.c:289:26: warning: ‘prev.len’ may be used uninitialized in this function
cmds-check.c:290:26: warning: ‘next.start’ may be used uninitialized in this function
cmds-check.c:290:26: warning: ‘next.len’ may be used uninitialized in this function

Reported-by: Anand Jain <Anand.Jain@oracle.com>
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-24 15:42:05 +02:00
David Sterba 9ea0eff31f btrfs-progs: restore: convert copy_file exit paths to a single return
Resolves-coverity-id: 1295365
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-24 15:42:05 +02:00
David Sterba 97f8e20930 btrfs-progs: restore: convert search_dir exit paths to a single return
Resolves-coverity-id: 1295366
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-24 15:42:05 +02:00
David Sterba a8762e43fd btrfs-progs: restore: fix path leak in copy_metadata
The path lifecycle spans only this function and we have to free it.

Resolves-coverity-id: 1295367
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-24 15:42:05 +02:00
Lauri Võsandi 9a86668071 btrfs-progs: optionally enforce chroot for btrfs receive
This patch forces btrfs receive to issue chroot before
parsing the btrfs stream using command-line flag -C
to confine the process and minimize damage that could
be done via malicious btrfs stream.

Signed-off-by: Lauri Võsandi <lauri.vosandi@gmail.com>
[added long option variant, added docs]
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-24 15:42:05 +02:00
Dan Merillat 7732e6ef62 btrfs-progs: restore: optionally restore metadata
As long as the inode is intact, the file metadata can be restored.
Directory data is restored at the end of search_dir.  Errors are
checked and returned, unless ignore_errors is requested.

Signed-off-by: Dan Merillat <dan.merillat@gmail.com>
[minor style fixes, error message updates]
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-24 15:42:04 +02:00
Zygo Blaxell 7ab0bdd712 btrfs-progs: report failure when resize ioctl fails
The BTRFS_IOC_RESIZE ioctl returns 0 on success, negative for POSIX
errors, and positive for btrfs-specific errors.

If resize fails with a btrfs-specific error, decode the error and
report it.  If we can't decode the error, report its numeric value so
that the userspace tool is not instantly useless when a new error code
is defined in the kernel.

Exit with non-zero status on any resize error.  This is very important
for scripts that will shrink the underlying storage when btrfs reports
success!

Signed-off-by: Zygo Blaxell <ce3g8jdj@umail.furryterror.org
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-24 15:42:04 +02:00
Anand Jain 2890c41504 btrfs-progs: fix typo in btrfs-device.txt
Signed-off-by: David Sterba <dsterba@suse.cz>
2015-04-24 15:42:04 +02:00