Skip to content

Commit 5fc070a

Browse files
adam900710kdave
authored andcommitted
btrfs: tree-checker: add extra ram_bytes and disk_num_bytes check
This is to ensure non-compressed file extents (both regular and prealloc) should have matching ram_bytes and disk_num_bytes. This is only for CONFIG_BTRFS_DEBUG and CONFIG_BTRFS_ASSERT case, furthermore this will not return error, but just a kernel warning to inform developers. Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 896c8b9 commit 5fc070a

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

fs/btrfs/tree-checker.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,24 @@ static int check_extent_data_item(struct extent_buffer *leaf,
340340
}
341341
}
342342

343+
/*
344+
* For non-compressed data extents, ram_bytes should match its
345+
* disk_num_bytes.
346+
* However we do not really utilize ram_bytes in this case, so this check
347+
* is only optional for DEBUG builds for developers to catch the
348+
* unexpected behaviors.
349+
*/
350+
if (IS_ENABLED(CONFIG_BTRFS_DEBUG) &&
351+
btrfs_file_extent_compression(leaf, fi) == BTRFS_COMPRESS_NONE &&
352+
btrfs_file_extent_disk_bytenr(leaf, fi)) {
353+
if (WARN_ON(btrfs_file_extent_ram_bytes(leaf, fi) !=
354+
btrfs_file_extent_disk_num_bytes(leaf, fi)))
355+
file_extent_err(leaf, slot,
356+
"mismatch ram_bytes (%llu) and disk_num_bytes (%llu) for non-compressed extent",
357+
btrfs_file_extent_ram_bytes(leaf, fi),
358+
btrfs_file_extent_disk_num_bytes(leaf, fi));
359+
}
360+
343361
return 0;
344362
}
345363

0 commit comments

Comments
 (0)