Skip to content

Commit bb721a9

Browse files
fdmananakdave
authored andcommitted
btrfs: assert we can NOCOW the range in btrfs_truncate_block()
We call btrfs_check_nocow_lock() to see if we can NOCOW a block sized range but we don't check later if we can NOCOW the whole range. It's unexpected to be able to NOCOW a range smaller than blocksize, so add an assertion to check the NOCOW range matches the blocksize. Reviewed-by: Boris Burkov <[email protected]> Signed-off-by: Filipe Manana <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 1044d59 commit bb721a9

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

fs/btrfs/inode.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4847,7 +4847,6 @@ int btrfs_truncate_block(struct btrfs_inode *inode, u64 offset, u64 start, u64 e
48474847
pgoff_t index = (offset >> PAGE_SHIFT);
48484848
struct folio *folio;
48494849
gfp_t mask = btrfs_alloc_write_mask(mapping);
4850-
size_t write_bytes = blocksize;
48514850
int ret = 0;
48524851
const bool in_head_block = is_inside_block(offset, round_down(start, blocksize),
48534852
blocksize);
@@ -4899,8 +4898,12 @@ int btrfs_truncate_block(struct btrfs_inode *inode, u64 offset, u64 start, u64 e
48994898
ret = btrfs_check_data_free_space(inode, &data_reserved, block_start,
49004899
blocksize, false);
49014900
if (ret < 0) {
4901+
size_t write_bytes = blocksize;
4902+
49024903
if (btrfs_check_nocow_lock(inode, block_start, &write_bytes, false) > 0) {
4903-
/* For nocow case, no need to reserve data space */
4904+
/* For nocow case, no need to reserve data space. */
4905+
ASSERT(write_bytes == blocksize, "write_bytes=%zu blocksize=%u",
4906+
write_bytes, blocksize);
49044907
only_release_metadata = true;
49054908
} else {
49064909
goto out;

0 commit comments

Comments
 (0)