Skip to content

Commit 88e2e6d

Browse files
adam900710kdave
authored andcommitted
btrfs: ignore incorrect btrfs_file_extent_item::ram_bytes
[HICCUP] Kernels can create file extent items with incorrect ram_bytes like this: item 6 key (257 EXTENT_DATA 0) itemoff 15816 itemsize 53 generation 7 type 1 (regular) extent data disk byte 13631488 nr 32768 extent data offset 0 nr 4096 ram 4096 extent compression 0 (none) Thankfully kernel can handle them properly, as in that case ram_bytes is not utilized at all. [ENHANCEMENT] Since the hiccup is not going to cause any data-loss and is only a minor violation of on-disk format, here we only need to ignore the incorrect ram_bytes value, and use the correct one from btrfs_file_extent_item::disk_num_bytes. Reviewed-by: Filipe Manana <[email protected]> Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent 0edeb6e commit 88e2e6d

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

fs/btrfs/file-item.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1306,6 +1306,13 @@ void btrfs_extent_item_to_extent_map(struct btrfs_inode *inode,
13061306
if (compress_type != BTRFS_COMPRESS_NONE) {
13071307
extent_map_set_compression(em, compress_type);
13081308
} else {
1309+
/*
1310+
* Older kernels can create regular non-hole data
1311+
* extents with ram_bytes smaller than disk_num_bytes.
1312+
* Not a big deal, just always use disk_num_bytes
1313+
* for ram_bytes.
1314+
*/
1315+
em->ram_bytes = em->disk_num_bytes;
13091316
if (type == BTRFS_FILE_EXTENT_PREALLOC)
13101317
em->flags |= EXTENT_FLAG_PREALLOC;
13111318
}

0 commit comments

Comments
 (0)