Skip to content

Commit 0c476a5

Browse files
jeffmahoneykdave
authored andcommitted
btrfs: Ensure proper sector alignment for btrfs_free_reserved_data_space
This fixes the WARN_ON on BTRFS_I(inode)->reserved_extents in btrfs_destroy_inode and the WARN_ON on nonzero delalloc bytes on umount with qgroups enabled. I was able to reproduce this by setting up a small (~500kb) quota limit and writing a file one byte at a time until I hit the limit. The warnings would all hit on umount. The root cause is that we would reserve a block-sized range in both the reservation and the quota in btrfs_check_data_free_space, but if we encountered a problem (like e.g. EDQUOT), we would only release the single byte in the qgroup reservation. That caused an iotree state split, which increased the number of outstanding extents, in turn disallowing releasing the metadata reservation. Signed-off-by: Jeff Mahoney <[email protected]> Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent f94480b commit 0c476a5

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

fs/btrfs/extent-tree.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4322,6 +4322,13 @@ void btrfs_free_reserved_data_space_noquota(struct inode *inode, u64 start,
43224322
*/
43234323
void btrfs_free_reserved_data_space(struct inode *inode, u64 start, u64 len)
43244324
{
4325+
struct btrfs_root *root = BTRFS_I(inode)->root;
4326+
4327+
/* Make sure the range is aligned to sectorsize */
4328+
len = round_up(start + len, root->sectorsize) -
4329+
round_down(start, root->sectorsize);
4330+
start = round_down(start, root->sectorsize);
4331+
43254332
btrfs_free_reserved_data_space_noquota(inode, start, len);
43264333
btrfs_qgroup_free_data(inode, start, len);
43274334
}

0 commit comments

Comments
 (0)