Skip to content

Commit 726c35f

Browse files
author
Josef Bacik
committed
Btrfs: use the global reserve as a backup for deleting inodes
Xfstests 83 really stresses our ENOSPC since it uses a 100mb fs which ends up with the mixed block group stuff. Because of this we can run into a situation where we don't have enough space to delete inodes, or even worse we can't free the inodes when we next mount the fs which causes the orphan code to lose its mind. So if we fail to make our reservation, steal from the global reserve. The global reserve will end up taking up the entire rest of the free space on the fs in this worst case so there really is no other option. With this patch test 83 doesn't freak out. Thanks, Signed-off-by: Josef Bacik <josef@redhat.com>
1 parent 1728366 commit 726c35f

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

‎fs/btrfs/inode.c‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3526,7 +3526,7 @@ void btrfs_evict_inode(struct inode *inode)
35263526
{
35273527
struct btrfs_trans_handle *trans;
35283528
struct btrfs_root *root = BTRFS_I(inode)->root;
3529-
struct btrfs_block_rsv *rsv;
3529+
struct btrfs_block_rsv *rsv, *global_rsv;
35303530
u64 min_size = btrfs_calc_trunc_metadata_size(root, 1);
35313531
unsigned long nr;
35323532
int ret;
@@ -3561,6 +3561,7 @@ void btrfs_evict_inode(struct inode *inode)
35613561
goto no_delete;
35623562
}
35633563
rsv->size = min_size;
3564+
global_rsv = &root->fs_info->global_block_rsv;
35643565

35653566
btrfs_i_size_write(inode, 0);
35663567

@@ -3577,6 +3578,15 @@ void btrfs_evict_inode(struct inode *inode)
35773578
*/
35783579
while (1) {
35793580
ret = btrfs_block_rsv_check(root, rsv, min_size, 0, 1);
3581+
3582+
/*
3583+
* Try and steal from the global reserve since we will
3584+
* likely not use this space anyway, we want to try as
3585+
* hard as possible to get this to work.
3586+
*/
3587+
if (ret)
3588+
ret = btrfs_block_rsv_migrate(global_rsv, rsv, min_size);
3589+
35803590
if (ret) {
35813591
printk(KERN_WARNING "Could not get space for a "
35823592
"delete, will truncate on mount %d\n", ret);

0 commit comments

Comments
 (0)