summaryrefslogtreecommitdiff
path: root/extent-tree.c
Commit message (Collapse)AuthorAge
* btrfs-progs: treewide: Fix missing declarationsRosen Penev2018-11-13
| | | | | | | | | | | | Found using -Wmissing-prototypes in GCC. This should improve LTO behavior. Note that set_free_space_tree_thresholds is an unused function. Adding inline seems to remove the unused function warning. Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: Rosen Penev <rosenp@gmail.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Hook FST code in extent (de)allocNikolay Borisov2018-10-25
| | | | | | | | | | For now this doesn't change the functionality since FST code is not yet enabled via the compat bits. But this will be needed when it's enabled so that the FST is correctly modified during repair operations that allocate/deallocate extents. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Merge alloc_reserved_tree_block2 and alloc_reserved_tree_blockNikolay Borisov2018-10-23
| | | | | | | | | Now that delayed refs have been wired let's merge the two function. In the process also remove one BUG_ON since alloc_reserved_tree_block's callers can handle errors. No functional changes. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove __free_extent2, now unusedNikolay Borisov2018-10-23
| | | | | | | | Now that delayed refs have been all wired up clean up the __free_extent2 adapter function since it's no longer needed. No functional changes. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove old delayed refs infrastructureNikolay Borisov2018-10-23
| | | | | | | | Given that the new delayed refs infrastructure is implemented and wired up, there is no point in keeping the old code. So just remove it. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Wire up delayed refsNikolay Borisov2018-10-23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This commit enables the delayed refs infrastructures. This entails doing the following: 1. Replacing existing calls of btrfs_extent_post_op (which is the equivalent of delayed refs) with the proper btrfs_run_delayed_refs. As well as eliminating open-coded calls to finish_current_insert and del_pending_extents which execute the delayed ops. 2. Wiring up the addition of delayed refs when freeing extents (btrfs_free_extent) and when adding new extents (alloc_tree_block). 3. Adding calls to btrfs_run_delayed refs in the transaction commit path alongside comments why every call is needed, since it's not always obvious (those call sites were derived empirically by running and debugging existing tests) 4. Correctly flagging the transaction in which we are reinitialising the extent tree. 5. Moving btrfs_write_dirty_block_groups to btrfs_write_dirty_block_groups since blockgroups should be written to disk after the last delayed refs have been run. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Make btrfs_write_dirty_block_groups take only trans argumentNikolay Borisov2018-10-23
| | | | | | | | | | The root argument is used only to get a reference to the fs_info, this can be achieved with the transaction handle being passed so use that. This is in preparation for moving this function in the main transaction commit routine. No functional changes. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Add delayed refs infrastructureNikolay Borisov2018-10-23
| | | | | | | | | | | | | | | | | This commit pulls those portions of the kernel implementation of delayed refs which are necessary to have them working in user-space. I've done the following modifications: 1. Replaced all kmem_cache_alloc calls to kmalloc. 2. Removed all locking-related code, since we are single threaded in userspace. 3. Removed code which deals with data refs - delayed refs in user space are going to be used only for cowonly trees. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add alloc_reserved_tree_block2 functionNikolay Borisov2018-10-23
| | | | | | | | This is a simple adapter function to convert the delayed-refs structures to the current arguments of alloc_reserved_tree_block. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add __free_extent2 functionNikolay Borisov2018-10-23
| | | | | | | | This is a simple adapter to convert the arguments delayed ref arguments to the existing arguments of __free_extent. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: exit gracefully if we hit ENOSPC when allocating tree blockQu Wenruo2018-10-23
| | | | | | | | | | | | | | | | | | | | When running test fuzz/003, we could hit the following BUG_ON: ====== RUN MAYFAIL btrfs check --init-csum-tree tests//fuzz-tests/images/bko-155621-bad-block-group-offset.raw.restored Unable to find block group for 0 Unable to find block group for 0 Unable to find block group for 0 extent-tree.c:2657: alloc_tree_block: BUG_ON `ret` triggered, value -28 failed (ignored, ret=134): btrfs check --init-csum-tree tests/fuzz-tests/images/bko-155621-bad-block-group-offset.raw.restored mayfail: returned code 134 (SIGABRT), not ignored test failed for case 003-multi-check-unmounted Just remove that BUG_ON() and allow us to exit gracefully, the caller handles the errors. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Always pass 0 for offset when calling btrfs_free_extent for ↵Nikolay Borisov2018-08-06
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | btree blocks. Currently some instances of btrfs_free_extent are called with the last parameter ("offset") being set to 1. This makes no sense, since offset is used for data extents. I suspect this is a left-over from 95d3f20b51e9 ("Mixed back reference (FORWARD ROLLING FORMAT CHANGE)") since this commit changed the signature of the function from : -int btrfs_free_extent(struct btrfs_trans_handle *trans, struct btrfs_root - *root, u64 bytenr, u64 num_bytes, u64 parent, - u64 root_objectid, u64 ref_generation, - u64 owner_objectid, int pin); to +int btrfs_free_extent(struct btrfs_trans_handle *trans, + struct btrfs_root *root, + u64 bytenr, u64 num_bytes, u64 parent, + u64 root_objectid, u64 owner, u64 offset); I.e the last parameter was "pin" and not offset. So these are just leftovers with no semantic meaning. Fix this by passing 0. 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: Remove root argument from alloc_reserved_tree_blockNikolay Borisov2018-08-06
| | | | | | | | This is not really needed, since we can reference the fs_info from the passed transaction. This is in preparation for delayed-refs support. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove root argument from __free_extentNikolay Borisov2018-08-06
| | | | | | | This argument is no longer used in this function so remove it. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: check: Drop trans/root arguments from free_extent_hookNikolay Borisov2018-08-06
| | | | | | | | | | They are not really needed, what free_extent_hook wants is really a pointer to fs_info so give it to it directly. This is in preparation of delayed refs code. 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: Make update_block_group take fs_info instead of rootNikolay Borisov2018-08-06
| | | | | | | | This is in preparation of delayed refs code. 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: Refactor the root used bytes are updatedNikolay Borisov2018-08-06
| | | | | | | | | Instead of updating this during update_block_group, move the updating code at the places where we free/allocate a block. This resembles the current state of the kernel code. This is in prep for delayed refs. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove root argument from btrfs_del_csumsNikolay Borisov2018-08-06
| | | | | | | | It's not needed, since we can obtain a reference to fs_info from the passed transaction handle. This is needed by delayed refs code. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove root argument from pin_down_bytesNikolay Borisov2018-08-06
| | | | | | | | | | This argument is used to obtain a reference to fs_info, which can already be done from the passed trans handle, so use that instead. This is in preparation for delayed refs support. 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: Use symbolic names for read ahead behaviorNikolay Borisov2018-06-07
| | | | | | | | | | Presently btrfs-progs haven't pulled the enum defining the symbolic names of read ahead constants. This commit adds the enum and simultaneously converts all usages to respective symbolic name. No functional change, just making the code human readable. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove root argument from write_one_cache_groupNikolay Borisov2018-06-07
| | | | | | | | | It's not needed since we can acquire a reference to the fs_info from the transaction handle already passed. 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 root argument from btrfs_set_block_flagsNikolay Borisov2018-06-07
| | | | | | | | | It's used only to get a reference to fs_info, which can be obtained from the transaction handle. 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: Change btrfs_root to btrfs_fs_info argument in ↵Nikolay Borisov2018-06-07
| | | | | | | | | | | btrfs_lookup_extent_info That function really wants an fs_info and not a root. Accidentally, this also makes the kernel/user space signatures to be coherent. 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: check: Remove unused root argument from btrfs_extent_post_opNikolay Borisov2018-06-07
| | | | | | | | This is no longer used by the callees of that function so remove 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: check: Make update_pinned_extents take btrfs_fs_infoNikolay Borisov2018-06-07
| | | | | | | | | This function needs btrfs_fs_info and not a root. So make it directly take btrfs_fs_info, 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: check: Remove root argument from finish_current_insertNikolay Borisov2018-06-07
| | | | | | | | Just reference it directly from trans->fs_info. 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: check: Remove root parameter from del_pending_extentsNikolay Borisov2018-06-07
| | | | | | | | | | This function always operates on the extent root which can be referenced from trans->fs_info. Do that to simplify function's signature. 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: check: Remove root parameter from btrfs_fix_block_accountingNikolay Borisov2018-06-07
| | | | | | | | | | It's always set to extent_root and the function already takes a transaction handle where fs_info could be referenced and in turn the extent_tree. 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: Use exclude_super_stripes instead of account_super_bytesNikolay Borisov2018-06-07
| | | | | | | | | | | | | | | | | | Originally commit 2681e00f00fe ("btrfs-progs: check for matchingi free space in cache") added the account_super_bytes function to prevent false negative when running btrfs check. Turns out this function is really copied exclude_super_stripes, excluding the calls to exclude_super_stripes. Later commit e4797df6a9fa ("btrfs-progs: check the free space tree in btrfsck") introduced proper version of exclude_super_stripes. Instead of duplicating the function, just remove account_super_bytes and use exclude_super_stripes instead of the former. This also has the benefit of bringing the userspace code a bit closer to the kernel counterpart. Signed-off-by: Nikolay Borisov <nborisov@suse.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove devid parameter from btrfs_rmap_blockNikolay Borisov2018-06-07
| | | | | | | | | This parameter was introduced with the original implementation of the function but has never really been used, so just remove it. 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: print-tree: Remove btrfs_root parameterQu Wenruo2018-04-24
| | | | | | | | | | | | Just like kernel cleanup made by David, btrfs_print_leaf() and btrfs_print_tree() doesn't need btrfs_root parameter at all. With previous patches as preparation, now we can remove the btrfs_root parameter. 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: do clean up for redundancy value assignmentGu Jinxiang2018-02-02
| | | | | | | | | | Although skinny_metadata's type is int, its value just can be 0/1. And if condition be true only when skinny_metadata equals 1, so in if's executive part, set skinny_metadata to 1 is redundancy. Remove it. Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove unnecessary parameter for btrfs_add_block_groupQu Wenruo2018-01-31
| | | | | | | | | | @chunk_objectid of btrfs_make_block_group() function is always fixed to BTRFS_FIRST_FREE_OBJECTID, so there is no need to pass it as parameter explicitly. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Use bool parameter to determine if we're allocating data extentQu Wenruo2018-01-31
| | | | | | | | | | | | | | | btrfs_reserve_extent() uses int @data to determine if we're allocating data extent, while reuse the parameter later to pass it as profile (data/meta/sys). It's a little confusing, this patch will follow kernel parameter to use bool @is_data to replace it. And in btrfs_reserve_extent(), use dedicated u64 @profile. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Su Yue <suy.fnst@cn.fujitsu.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Remove unused parameter transGu Jinxiang2018-01-08
| | | | | | | | Some parameter of trans is not used indeed. Let's remove them. Signed-off-by: Gu Jinxiang <gujx@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: mkfs: avoid BUG_ON for chunk allocation when ENOSPC happensQu Wenruo2017-11-14
| | | | | | | | | | | | | | | | | | | | | | | When passing directory larger than block device using --rootdir parameter, we get the following backtrace: ------ extent-tree.c:2693: btrfs_reserve_extent: BUG_ON `ret` triggered, value -28 ./mkfs.btrfs(+0x1a05d)[0x557939e6b05d] ./mkfs.btrfs(btrfs_reserve_extent+0xb5a)[0x557939e710c8] ./mkfs.btrfs(+0xb0b6)[0x557939e5c0b6] ./mkfs.btrfs(main+0x15d5)[0x557939e5de04] /usr/lib/libc.so.6(__libc_start_main+0xea)[0x7f83b101af6a] ./mkfs.btrfs(_start+0x2a)[0x557939e5af5a] ------ Nothing special, just BUG_ON() abusing from ancient code. Fix them by using correct return. Signed-off-by: Qu Wenruo <wqu@suse.com> Reviewed-by: Nikolay Borisov <nborisov@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Fix one-byte overlap bug in free_block_group_cacheQu Wenruo2017-09-25
| | | | | | | | | | | | | | | | free_block_group_cache() calls clear_extent_bits() with wrong end, which is one byte larger than the correct range. This will cause the next adjacent cache state to be split. And due to the split, private pointer (which points to block group cache) will be reset to NULL. This is very hard to detect as this function only gets called in cleanup_temp_chunks() which is just before mkfs finishes. This bug only gets exposed when reworking --rootdir option. Signed-off-by: Qu Wenruo <quwenruo.btrfs@gmx.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: handle failed search in find_search_start betterDavid Sterba2017-09-08
| | | | | | | The warning can pop up frequently on a fuzzed image, the message seems to be enough. Add a more fitting error code too. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: add more error handling to btrfs_free_block_groupDavid Sterba2017-09-08
| | | | | | | | As btrfs_update_block_group fails when the block group is not found in cache, we can exit btrfs_free_block_group, not much to rollback. The caller will also exit in turn. Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: switch fs_info::system_allocs to bitDavid Sterba2017-09-08
| | | | | | | The value really is 0 or 1, the test in btrfs_reserve_extent can be simplified. 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: fix infinite loop in find_free_extentLiu Bo2017-07-20
| | | | | | | | | | | If the found %ins is crossing a stripe len, ie. BTRFS_STRIPE_LEN, we'd search again with a stripe-aligned %search_start. The current code calculates %search_start by adding a wrong offset, in order to fix it, the start position of the block group should be taken, otherwise, it'll end up with looking at the same block group forever. Signed-off-by: Liu Bo <bo.li.liu@oracle.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Refactor chunk creation functions to use btrfs_fs_infoQu Wenruo2017-07-12
| | | | | | | | 4 functions are involved in this refactor: btrfs_make_block_group() btrfs_make_block_groups(), btrfs_alloc_chunk, btrfs_alloc_data_chunk(). Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: Refactor btrfs_chunk_readonly 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 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 block sizes users in extent-tree.cQu Wenruo2017-07-03
| | | | | | And in the refactoring, also refactors a open-coded round_up(). Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com>
* btrfs-progs: Fix memory leak when 0 sized block group item is foundQu Wenruo2017-05-02
| | | | | | | | | | | | | | | | When a 0 sized block group item is found, set_extent_bits() will not really set any bits. While set_state_private() still inserts allocated block group cache into block group extent_io_tree. So at close_ctree() time, we won't free the private block group cache stored since we can't find any bit set for the 0 sized block group. To fix it, at btrfs_read_block_groups() we skip any 0 sized block group, so such leak won't happen. Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: David Sterba <dsterba@suse.com>
* btrfs-progs: remove unused argument from clear_extent_dirtyDavid Sterba2017-03-08
| | | | Signed-off-by: David Sterba <dsterba@suse.com>