summaryrefslogtreecommitdiff
path: root/disk-io.c
Commit message (Collapse)AuthorAge
* btrfs-progs: print bytenr of tree block in print_tree_block_errorSu Yue2018-08-06
| | | | | | | | For easier debugging, let print_tree_block_error() print bytenr of tree block. Signed-off-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add new flag to read superblock with mismatched fsidsDavid Sterba2018-08-06
| | | | | | | | | | | | | | New flag that mimics OPEN_CTREE_IGNORE_FSID_MISMATCH but only for reading the superblock. It should be passed around to various helpers like scan or mount checks as they'd fail before we'd get to the final caller that can do something useful with the filesystem. This will be used for an interrupted 'btrfstune -u'. Note to __open_ctree_fd: the RECOVERY mode is not compatible with that flag Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove fs_info argument from write_ctree_superNikolay Borisov2018-06-07
| | | | | | | | | This function already takes a transaction handle which has a reference to the fs_info, so use that to obtain it. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove unused argument from clean_tree_blockNikolay Borisov2018-06-07
| | | | | | | | | | This function actually uses only the extent_buffer arg but takes 3 arguments. Furthermore, it's current interface doesn't even mirror the kernel counterpart. Just remove the extra arguments. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Rename OPEN_CTREE_FS_PARTIAL to OPEN_CTREE_TEMPORARY_SUPERQu Wenruo2018-04-24
| | | | | | | | | | | | | | | | | | | | | | | | The old flag OPEN_CTREE_FS_PARTIAL is in fact quite easy to be confused with OPEN_CTREE_PARTIAL, which allow btrfs-progs to open damaged filesystem (like corrupted extent/csum tree). However OPEN_CTREE_FS_PARTIAL, unlike its name, is just allowing btrfs-progs to open fs with temporary superblocks (which only has 6 basic trees on SINGLE meta/sys chunks). The usage of FS_PARTIAL is really confusing here. So rename OPEN_CTREE_FS_PARTIAL to OPEN_CTREE_TEMPORARY_SUPER, and add extra comment for its behavior. Also rename BTRFS_MAGIC_PARTIAL to BTRFS_MAGIC_TEMPORARY to keep the naming consistent. And with above comment, the usage of FS_PARTIAL in dump-tree is obviously incorrect, fix it. Fixes: 8698a2b9ba89 ("btrfs-progs: Allow inspect dump-tree to show specified tree block even some tree roots are corrupted") Signed-off-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: extent_io: Refactor alloc_extent_buffer() to follow kernel ↵Qu Wenruo2018-04-24
| | | | | | | | | | | | | parameters Instead of using the internal struct extent_io_tree, use struct fs_info. This does not only unify the interface between kernel and btrfs-progs, but also makes later btrfs_print_tree() use fewer parameters. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: disk-io: Fix read_extent_data() error handler for missing deviceQu Wenruo2018-03-30
| | | | | | | | | | | | | | | | | | | | | | | | | When device is missing, read_extent_data() (function exported from old btrfs check code) has the following problems: 1) Modifies @len parameter if device is missing If device returned in @multi is missing, @len can be larger than @max_len (originl length). This could confuse caller and underflow in the read loop. 2) Still returns 0 for missing device It only handles read error, missing device is not handled and 0 is returned. 3) Wrong check for device->fd In fact, 0 is also a valid fd. Although not possible under most cases, but still needs fix. Fix them all. Fixes: 1bad2f2f2dfe ("Btrfs-progs: fsck: add an option to check data csums") Signed-off-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: Document logic of btrfs_read_dev_superNikolay Borisov2018-01-31
| | | | | | Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Replace usage of list_for_each with list_for_each_entryNikolay Borisov2018-01-31
| | | | | | | | | | | | | There are a couple of places where instead of the more succinct list_for_each_entry the code uses list_for_each. This results in slightly more code with no additional benefit as well as no coherent pattern. This patch makes the code uniform. No functional changes. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Qu Wenruo <wqu@suse.com> [ remove unused variable in uuid_search ] Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: handle transaction start failure in close_ctreeDavid Sterba2017-09-08
| | | | | | | | | Closing the fs will try to commit a pending transaction, but may fail to do so if the filesystem state is not well defined. This will eg. fail for some fuzz tests. The data structures are freed but no furhter attempt to commit is made. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: move transaction code out of disk-ioDavid Sterba2017-09-08
| | | | | | Temporarily export the low-level helpers. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add crude error handling when transaction start failsDavid Sterba2017-09-08
| | | | | | | | | | Currently transaction bugs out insided btrfs_start_transaction in case of error, we want to lift the error handling to the callers. This patch adds the BUG_ON anywhere it's been missing so far. This is not the best way of course. Transforming BUG_ON to a proper error handling highly depends on the caller and should be dealt with case by case. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: handle blockgroup errors when opening filesystemDavid Sterba2017-09-08
| | | | | | | | | | | | | The call to btrfs_read_block_groups could loop if the metadata are damaged (reported eg. for an unaligned block), due to lack of error handling. We have to check for restored images or currently created filesystems, that do not contain the blockgroups. Can be reproduced by fuzzed image bko-155551. Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=155551 Reported-by: Lukas Lueg <lukas.lueg@gmail.com> 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 argument from btrfs_find_create_tree_blockDavid Sterba2017-09-08
| | | | | | | | Metadata blocks are always nodesize. When reading the superblock::sys_array, the actual size of data is fixed to 4k and smaller than nodesize, but otherwise everything works as before. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: drop redundant check of blocksize in read_tree_blockDavid Sterba2017-09-08
| | | | | | | | The tree blocks are supposed to be always of nodesize. Before the parameter has been dropped, it was unlikely but possible to pass a misaligned value. 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: Refactor btrfs_read_sys_array/chunk_tree 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 write_all_supers and its callers 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_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 btrfs_find_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 write_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 write_and_map_eb 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 csum_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 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 btrfs_map_block and its variants to use btrfs_fs_infoQu Wenruo2017-07-12
| | | | | | | | | Just to keep the 1st paramter the same as kernel. We can also save a few lines since the parameter is shorter now. 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: Remove block size members in btrfs_rootQu Wenruo2017-07-03
| | | | | | Finally, we can get rid of per tree block size members now. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: Refactor block sizes users in disk-io.cQu Wenruo2017-07-03
| | | | | | | | | Since we have cached block sizes in fs_info, there is no need to specify these sizes in btrfs_setup_root() function. And refactor all root->sector/node/stripesize users in disk-io.c. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: Introduce sectorsize nodesize and stripesize members forQu Wenruo2017-07-03
| | | | | | | | | | | | | btrfs_fs_info Just like what we do in kernel, since we will not support different leaf/node/stripe size per tree, there is no need to store these block sizes in btrfs_root. This patch will introduce these block size members into btrfs_fs_info structure, allowing us to convert such usage in later patches. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: Remove deprecated leafsize usageQu Wenruo2017-07-03
| | | | | | | | | | | | | | | | | | | | | | | | | | | Leafsize is deprecated for a long time, and kernel has already updated ctree.h to rename sb->leafsize to sb->__unused_leafsize. This patch will remove normal users of leafsize: 1) Remove leafsize member from btrfs_root structure Now only root->nodesize and root->sectorisze. No longer root->leafsize. 2) Remove @leafsize parameter from btrfs_setup_root() function Since no root->leafsize, no need for @leafsize parameter. The remaining user of leafsize will be: 1) btrfs inspect-internal dump-super Reformat the "leafsize" output to "leafsize (deprecated)" and use le32_to_cpu() to do the cast manually. 2) mkfs We still need to set sb->__unused_leafsize to nodesize. Do the manual cast too. 3) convert Same as mkfs, these two superblock setup should be merged later Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: tests: Fix fuzz-test for bko-161821.raw.txtLu Fengqi2017-05-02
| | | | | | | | | | | | | | | | | | | | | | | Fuzzed image bko-161821.raw causes btrfs check to get segmentation fault. The function check_owner_ref attempts to access a non-exist quota tree when dealing with extent_item [4198400 4096] in the corrupted filesystem. The function btrfs_new_fs_info always allocates memory for fs_info->quota_root regardless of whether quota_tree exists or not. Additionally, the function btrfs_read_fs_root will directly return fs_info->quota_root if location->objectid == BTRFS_QUOTA_TREE_OBJECTID. This patch does the following things: 1. Do extra check and return ENOENT if quota tree does not exist in the function btrfs_read_fs_root. 2. Free useless fs_info->quota_root in the function btrfs_setup_all_roots to reduce confusion. 3. free_extent_buffer even if check_child_node failed in the function walk_down_tree. Signed-off-by: Lu Fengqi <lufq.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: report I/O errors when closing the filesystemOmar Sandoval2017-03-08
| | | | | | | | | | If the final fsync() on the Btrfs device fails, we just swallow the error and don't alert the user in any way. This was uncovered by xfstest generic/405, which checks that mkfs fails when it encounters EIO. Signed-off-by: Omar Sandoval <osandov@fb.com> Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove unused function wait_on_tree_block_writebackDavid Sterba2017-03-08
| | | | | | | This used to be a kernel stub but has been removed from kernel long time ago. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove unused argument from write_and_map_ebDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove unused argument from btrfs_csum_dataDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: opencode trivial helper btrfs_free_transactionDavid Sterba2017-03-08
| | | | | | It also does not exist in kernel code. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Introduce kernel sizes to cleanup large intermediate numberQu Wenruo2017-03-08
| | | | | | | | | | | Large numbers like (1024 * 1024 * 1024) may cost reader/reviewer to waste one second to convert to 1G. Introduce kernel include/linux/sizes.h to replace any intermediate number larger than 4096 (not including 4096) to SZ_*. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: get the highest inode for lost+foundGoldwyn Rodrigues2017-01-25
| | | | | | | | | | | | | root->highest_inode is not accurate at the time of creating a lost+found and it fails because the highest_inode+1 is already present. This could be because of fixes after highest_inode is set. Instead, search for the highest inode in the tree and use it for lost+found. This makes root->highest_inode unnecessary and hence deleted. Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com> Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: make incompat bit wrappers more compactDavid Sterba2016-12-14
| | | | | | Use the same macro tricks as in kernel code. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add OPEN_CTREE_INVALIDATE_FST flagOmar Sandoval2016-11-23
| | | | | | | | | | If this flag is passed to open_ctree(), we'll clear the FREE_SPACE_TREE_VALID compat_ro bit. The kernel will then reconstruct the free space tree the next time the filesystem is mounted. Reviewed-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: Omar Sandoval <osandov@fb.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: rename btrfs_scan_lblkid() to btrfs_scan_devices()Karel Zak2016-10-25
| | | | | | | | | It seems like bad idea to use a library name (lblkid) within generic function name. The currently used scanning library is implementation detail and this detail should be hidden for rest of the code. Signed-off-by: Karel Zak <kzak@redhat.com> Signed-off-by: David Sterba <dsterba@suse.cz>
* btrfs-progs: fix printf format of sizeof on 32bit buildDavid Sterba2016-10-10
| | | | Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: rename __setup_root and change to return voidDavid Sterba2016-10-05
| | | | | | Exported function should use a prefix. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: more sanity checks in read_tree_block_fs_infoDavid Sterba2016-10-03
| | | | | | | | | If blocksize is 0, it passes the IS_ALIGNED check but fails later as the length of ebs will be zero. Reported-by: Lukas Lueg <lukas.lueg@gmail.com> Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=169311 Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove unnecessary parameter to clear_extent_uptodateQu Wenruo2016-10-03
| | | | | Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Return more meaningful value for btrfs_read_deve_superQu Wenruo2016-10-03
| | | | | | | | | | | | | | btrfs_read_dev_super() only returns 0 or -1, which doesn't really help, caller won't know if it's caused by bad superblock or superblock out of range. Return -errno if pread64() return -1, and return -EOF if none or part of the super is read out, and return what check_super() returned. So caller can get -EIO to catch real corrupted super blocks. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>