summaryrefslogtreecommitdiff
path: root/image
Commit message (Collapse)AuthorAge
* btrfs-progs: convert: Fix offset-by-one error in read_data_extent()Qu Wenruo2018-03-30
| | | | | | | | | | | | | | | | | | | | | | For read_data_extent() in convert/main.c it's using mirror number in a incorrect way, which will not get correct copy for RAID1: for (cur_mirror = 0; cur_mirror < num_copies; cur_mirror++) { In such case, for RAID1 @cur_mirror will only be 0 and 1. However for 0 and 1 case, btrfs_map_block() will only return the first copy. To reach the 2nd copy, it correct @cur_mirror range should be 1 and 2. So with this off-by-one error, btrfs-image will never be able to read out data extent if the first stripe of the chunk is the missing one. Fix it by starting @cur_mirror from 1 and to @num_copies (including). Fixes: 2d46558b30f5 ("btrfs-progs: Use existing facility to replace read_data_extent function") Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove BTRFS_CRC32_SIZE definitionMisono, Tomohiro2018-03-30
| | | | | | | | | | The kernel code no longer has BTRFS_CRC32_SIZE and only uses btrfs_csum_sizes[]. So, update the progs code as well. Suggested-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Tomohiro Misono <misono.tomohiro@jp.fujitsu.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: treewide: Replace strerror(errno) with %m.Rosen Penev2018-01-31
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | As btrfs is specific to Linux, %m can be used instead of strerror(errno) in format strings. This has some size reduction benefits for embedded systems. glibc, musl, and uclibc-ng all support %m as a modifier to printf. A quick glance at the BIONIC libc source indicates that it has support for %m as well. BSDs and Windows do not but I do believe them to be beyond the scope of btrfs-progs. Compiled sizes on Ubuntu 16.04: Before: 3916512 btrfs 233688 libbtrfs.so.0.1 4899 bcp 2367672 btrfs-convert 2208488 btrfs-corrupt-block 13302 btrfs-debugfs 2152160 btrfs-debug-tree 2136024 btrfs-find-root 2287592 btrfs-image 2144600 btrfs-map-logical 2130760 btrfs-select-super 2152608 btrfstune 2131760 btrfs-zero-log 2277752 mkfs.btrfs 9166 show-blocks After: 3908744 btrfs 233256 libbtrfs.so.0.1 4899 bcp 2366560 btrfs-convert 2207432 btrfs-corrupt-block 13302 btrfs-debugfs 2151104 btrfs-debug-tree 2134968 btrfs-find-root 2281864 btrfs-image 2143536 btrfs-map-logical 2129704 btrfs-select-super 2151552 btrfstune 2130696 btrfs-zero-log 2276272 mkfs.btrfs 9166 show-blocks Total savings: 23928 (24 kilo)bytes Signed-off-by: Rosen Penev <rosenp@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: move sanitization to new fileDavid Sterba2017-11-14
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: pass sanitize mode and name tree separately to sanitize_nameDavid Sterba2017-11-14
| | | | | | Now sanitize_name and all callees do not depend on metadump_struct. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: pass sanitize mode and name tree separately to ↵David Sterba2017-11-14
| | | | | | | | sanitize_dir_item We don't need the full mdrestore structure. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: pass sanitize mode and name tree separately to ↵David Sterba2017-11-14
| | | | | | | | sanitize_inode_ref We don't need the full mdrestore structure. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: drop unused parameter from sanitize_xattrDavid Sterba2017-11-14
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: pass rb_root to find_collisionsDavid Sterba2017-11-14
| | | | | | We don't need the full metadump structure, pass only the name tree. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: introduce symbolic names for the sanitization modesDavid Sterba2017-11-14
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: start a new header for sanitization functionsDavid Sterba2017-11-14
| | | | | | | Will be used by following cleanups, so far only the name structure could be moved here. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: move metadump definitions to own headerDavid Sterba2017-11-14
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: use CRC32C reversing instead of brute force to find ↵Piotr Pawlow2017-09-25
| | | | | | | collisions Author: Piotr Pawlow <pp@siedziba.pl> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: add a function to check if generated filename suffix is ↵Piotr Pawlow2017-09-25
| | | | | | | valid Author: Piotr Pawlow <pp@siedziba.pl> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: add a function to calculate CRC32C collisionsPiotr Pawlow2017-09-25
| | | | | | | | | | The function uses the reverse CRC32C table to quickly calculate a 4-byte suffix, that when added to the original data will make it match desired checksum. Author: Piotr Pawlow <pp@siedziba.pl> [ minor adjustments ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: add reverse CRC32C tablePiotr Pawlow2017-09-25
| | | | | | | The table will be used to speed up calculations of CRC32C collisions. Author: Piotr Pawlow <pp@siedziba.pl> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: move core find_collision code to a separate functionPiotr Pawlow2017-09-25
| | | | | Author: Piotr Pawlow <pp@siedziba.pl> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: fix non-printable characters in generated file namesPiotr Pawlow2017-09-25
| | | | | | | | | Function find_collision sometimes generated file names with non-printable DEL characters (code 127), for example file name "|5gp!" would be changed to "U'2<DEL>y" when using "crc-collisions" sanitize mode. Author: Piotr Pawlow <pp@siedziba.pl> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: drop blocksize argument from readahead_tree_blockDavid Sterba2017-09-08
| | | | | | | Tree blocks are always nodesize. As readahead is only an optimization, exact size is not required and is only advisory. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: drop blocksize from read_tree_blockDavid Sterba2017-09-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: drop local blocksize variables if they're nodesizeDavid Sterba2017-09-08
| | | | | | Prep work so we can drop the blocksize argument from several functions. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: fix typos in messagesAdam Buchbinder2017-07-20
| | | | | | Signed-off-by: Adam Buchbinder <abuchbinder@google.com> [ separated from the previous patch ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: Fix data races when reporting progressAdam Buchbinder2017-07-20
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | Making the code data-race safe requires that reads *and* writes happen under a mutex lock, if any of the access are writes. See Dmitri Vyukov, "Benign data races: what could possibly go wrong?" for more details. The fix here was to put most of the main loop of restore_worker under a mutex lock. This race was detected using fsck-tests/012-leaf-corruption. ================== WARNING: ThreadSanitizer: data race Write of size 4 by main thread: #0 add_cluster btrfs-progs/image/main.c:1931 #1 restore_metadump btrfs-progs/image/main.c:2566 #2 main btrfs-progs/image/main.c:2859 Previous read of size 4 by thread T6: #0 restore_worker btrfs-progs/image/main.c:1720 Location is stack of main thread. Thread T6 (running) created by main thread at: #0 pthread_create <null> #1 mdrestore_init btrfs-progs/image/main.c:1868 #2 restore_metadump btrfs-progs/image/main.c:2534 #3 main btrfs-progs/image/main.c:2859 SUMMARY: ThreadSanitizer: data race btrfs-progs/image/main.c:1931 in add_cluster Signed-off-by: Adam Buchbinder <abuchbinder@google.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Refactor btrfs_readahead_tree_block to use btrfs_fs_infoQu Wenruo2017-07-12
| | | | | Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Refactor read_extent_data to use btrfs_fs_infoQu Wenruo2017-07-12
| | | | | Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Refactor btrfs_num_copies to use btrfs_fs_infoQu Wenruo2017-07-12
| | | | | Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Refactor read_tree_block to get rid of btrfs_rootQu Wenruo2017-07-03
| | | | | | | | | | | | | The only reasom read_tree_block() needs a btrfs_root parameter is to get its node/sector size. And long ago, I have already introduced a compactible interface, read_tree_block_fs_info() to pass btrfs_fs_info instead of btrfs_root. Since we have cleaned up all root->sector/node/stripesize users, we should be OK to refactor read_tree_block() function. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: Refactor nodesize users in image/main.cQu Wenruo2017-07-03
| | | | Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: Fix restoring image from multi devices fs into single deviceFilipe Manana2017-06-26
| | | | | | | | | | | | | | | | | | | | | | | | | We correctly build an image from a multiple devices filesystem but when restoring the image into a single device we were missing updating the number of devices in the superblock to the value 1 (we already took care of setting the number of stripes to 1 for each chunk item and setting the device id for each chunk item to match the device id from the super block). This missing update of the number of devices makes it impossible to mount the restored filesystem on recent kernels, more specifically since the linux kernel commit 99e3ecfcb9f4ca35192d20a5bea158b81f600062 ("Btrfs: add more validation checks for superblock"), that produce the following message in the dmesg/syslog: [21097.542047] BTRFS error (device sdi): super_num_devices 2 mismatch with num_devices 1 found here [21097.543972] BTRFS error (device sdi): failed to read chunk tree: -22 [21097.720360] BTRFS error (device sdi): open_ctree failed So fix this by updating the number of devices to 1 in the superblock. Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: Liu Bo <bo.li.liu@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: image: remove unused argument from copy_log_treesDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move help defines to own headerDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: sanitize - Use correct source for memcpyGoldwyn Rodrigues2017-01-25
| | | | | | | | | While performing a memcpy, we are copying from uninitialized dst as opposed to src->data. Though using eb->len is correct, I used src->len to make it more readable. Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Fix spelling/typos in user-facing stringsNicholas D Steeves2017-01-25
| | | | | Signed-off-by: Nicholas D Steeves <nsteeves@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove extra newline from messagesDavid Sterba2016-12-14
| | | | | | The common message helpers add the newline. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move btrfs-image sources to own directoryDavid Sterba2016-11-24
There are no pending patches to btrfs-image, this looks like a good time to move it. Signed-off-by: David Sterba <dsterba@suse.com>