Skip to content

Commit f8da41d

Browse files
fdmananakdave
authored andcommitted
btrfs: do not free data reservation in fallback from inline due to -ENOSPC
If we fail to create an inline extent due to -ENOSPC, we will attempt to go through the normal COW path, reserve an extent, create an ordered extent, etc. However we were always freeing the reserved qgroup data, which is wrong since we will use data. Fix this by freeing the reserved qgroup data in __cow_file_range_inline() only if we are not doing the fallback (ret is <= 0). Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Filipe Manana <fdmanana@suse.com> Reviewed-by: David Sterba <dsterba@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 83f5907 commit f8da41d

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

fs/btrfs/inode.c

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -673,8 +673,12 @@ static noinline int __cow_file_range_inline(struct btrfs_inode *inode,
673673
* it won't count as data extent, free them directly here.
674674
* And at reserve time, it's always aligned to page size, so
675675
* just free one page here.
676+
*
677+
* If we fallback to non-inline (ret == 1) due to -ENOSPC, then we need
678+
* to keep the data reservation.
676679
*/
677-
btrfs_qgroup_free_data(inode, NULL, 0, fs_info->sectorsize, NULL);
680+
if (ret <= 0)
681+
btrfs_qgroup_free_data(inode, NULL, 0, fs_info->sectorsize, NULL);
678682
btrfs_free_path(path);
679683
btrfs_end_transaction(trans);
680684
return ret;

0 commit comments

Comments
 (0)