Skip to content

Commit 2155d0c

Browse files
fdmananakdave
authored andcommitted
btrfs: use the correct type to initialize block reserve for delayed refs
When initializing the delayed refs block reserve for a transaction handle we are passing a type of BTRFS_BLOCK_RSV_DELOPS, which is meant for delayed items and not for delayed refs. The correct type for delayed refs is BTRFS_BLOCK_RSV_DELREFS. On release of any excess space reserved in a local delayed refs reserve, we also should transfer that excess space to the global block reserve (it it's full, we return to the space info for general availability). By initializing a transaction's local delayed refs block reserve with a type of BTRFS_BLOCK_RSV_DELOPS, we were also causing any excess space released from the delayed block reserve (fs_info->delayed_block_rsv, used for delayed inodes and items) to be transferred to the global block reserve instead of the global delayed refs block reserve. This was an unintentional change in commit 28270e2 ("btrfs: always reserve space for delayed refs when starting transaction"), but it's not particularly serious as things tend to cancel out each other most of the time and it's relatively rare to be anywhere near exhaustion of the global reserve. Fix this by initializing a transaction's local delayed refs reserve with a type of BTRFS_BLOCK_RSV_DELREFS and making btrfs_block_rsv_release() attempt to transfer unused space from such a reserve into the global block reserve, just as we did before that commit for when the block reserve is a delayed refs rsv. Reported-by: Alex Lyakas <alex.lyakas@zadara.com> Link: https://lore.kernel.org/linux-btrfs/CAOcd+r0FHG5LWzTSu=LknwSoqxfw+C00gFAW7fuX71+Z5AfEew@mail.gmail.com/ Fixes: 28270e2 ("btrfs: always reserve space for delayed refs when starting transaction") Reviewed-by: Alex Lyakas <alex.lyakas@zadara.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 8ceaad6 commit 2155d0c

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

fs/btrfs/block-rsv.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,10 +276,11 @@ u64 btrfs_block_rsv_release(struct btrfs_fs_info *fs_info,
276276
struct btrfs_block_rsv *target = NULL;
277277

278278
/*
279-
* If we are a delayed block reserve then push to the global rsv,
280-
* otherwise dump into the global delayed reserve if it is not full.
279+
* If we are a delayed refs block reserve then push to the global
280+
* reserve, otherwise dump into the global delayed refs reserve if it is
281+
* not full.
281282
*/
282-
if (block_rsv->type == BTRFS_BLOCK_RSV_DELOPS)
283+
if (block_rsv->type == BTRFS_BLOCK_RSV_DELREFS)
283284
target = global_rsv;
284285
else if (block_rsv != global_rsv && !btrfs_block_rsv_full(delayed_rsv))
285286
target = delayed_rsv;

fs/btrfs/transaction.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -726,7 +726,7 @@ start_transaction(struct btrfs_root *root, unsigned int num_items,
726726

727727
h->type = type;
728728
INIT_LIST_HEAD(&h->new_bgs);
729-
btrfs_init_metadata_block_rsv(fs_info, &h->delayed_rsv, BTRFS_BLOCK_RSV_DELOPS);
729+
btrfs_init_metadata_block_rsv(fs_info, &h->delayed_rsv, BTRFS_BLOCK_RSV_DELREFS);
730730

731731
smp_mb();
732732
if (cur_trans->state >= TRANS_STATE_COMMIT_START &&

0 commit comments

Comments
 (0)