Skip to content

Commit 3880a1b

Browse files
author
Josef Bacik
committed
Btrfs: reserve some space for an orphan item when unlinking
In __unlink_start_trans() if we don't have enough room for a reservation we will check to see if the unlink will free up space. If it does that's great, but we will still could add an orphan item, so we need to reserve enough space to add the orphan item. Do this and migrate the space the global reserve so it all works out right. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com>
1 parent b24e03d commit 3880a1b

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

‎fs/btrfs/inode.c‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2790,7 +2790,8 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir,
27902790
return ERR_PTR(-ENOMEM);
27912791
}
27922792

2793-
trans = btrfs_start_transaction(root, 0);
2793+
/* 1 for the orphan item */
2794+
trans = btrfs_start_transaction(root, 1);
27942795
if (IS_ERR(trans)) {
27952796
btrfs_free_path(path);
27962797
root->fs_info->enospc_unlink = 0;
@@ -2895,6 +2896,12 @@ static struct btrfs_trans_handle *__unlink_start_trans(struct inode *dir,
28952896
err = 0;
28962897
out:
28972898
btrfs_free_path(path);
2899+
/* Migrate the orphan reservation over */
2900+
if (!err)
2901+
err = btrfs_block_rsv_migrate(trans->block_rsv,
2902+
&root->fs_info->global_block_rsv,
2903+
btrfs_calc_trans_metadata_size(root, 1));
2904+
28982905
if (err) {
28992906
btrfs_end_transaction(trans, root);
29002907
root->fs_info->enospc_unlink = 0;

0 commit comments

Comments
 (0)