Skip to content

Commit 94ed938

Browse files
Qu Wenruomasoncl
authored andcommitted
btrfs: qgroup: Add handler for NOCOW and inline
For NOCOW and inline case, there will be no delayed_ref created for them, so we should free their reserved data space at proper time(finish_ordered_io for NOCOW and cow_file_inline for inline). Signed-off-by: Qu Wenruo <quwenruo@cn.fujitsu.com> Signed-off-by: Chris Mason <clm@fb.com>
1 parent 7cf5b97 commit 94ed938

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

fs/btrfs/extent-tree.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4052,7 +4052,12 @@ int btrfs_check_data_free_space(struct inode *inode, u64 start, u64 len)
40524052
if (ret < 0)
40534053
return ret;
40544054

4055-
/* Use new btrfs_qgroup_reserve_data to reserve precious data space */
4055+
/*
4056+
* Use new btrfs_qgroup_reserve_data to reserve precious data space
4057+
*
4058+
* TODO: Find a good method to avoid reserve data space for NOCOW
4059+
* range, but don't impact performance on quota disable case.
4060+
*/
40564061
ret = btrfs_qgroup_reserve_data(inode, start, len);
40574062
return ret;
40584063
}

fs/btrfs/inode.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,13 @@ static noinline int cow_file_range_inline(struct btrfs_root *root,
310310
btrfs_delalloc_release_metadata(inode, end + 1 - start);
311311
btrfs_drop_extent_cache(inode, start, aligned_end - 1, 0);
312312
out:
313+
/*
314+
* Don't forget to free the reserved space, as for inlined extent
315+
* it won't count as data extent, free them directly here.
316+
* And at reserve time, it's always aligned to page size, so
317+
* just free one page here.
318+
*/
319+
btrfs_qgroup_free_data(inode, 0, PAGE_CACHE_SIZE);
313320
btrfs_free_path(path);
314321
btrfs_end_transaction(trans, root);
315322
return ret;
@@ -2838,6 +2845,14 @@ static int btrfs_finish_ordered_io(struct btrfs_ordered_extent *ordered_extent)
28382845

28392846
if (test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags)) {
28402847
BUG_ON(!list_empty(&ordered_extent->list)); /* Logic error */
2848+
2849+
/*
2850+
* For mwrite(mmap + memset to write) case, we still reserve
2851+
* space for NOCOW range.
2852+
* As NOCOW won't cause a new delayed ref, just free the space
2853+
*/
2854+
btrfs_qgroup_free_data(inode, ordered_extent->file_offset,
2855+
ordered_extent->len);
28412856
btrfs_ordered_update_i_size(inode, 0, ordered_extent);
28422857
if (nolock)
28432858
trans = btrfs_join_transaction_nolock(root);

0 commit comments

Comments
 (0)