Skip to content

Commit 689f934

Browse files
ukernelchrismason-xx
authored andcommitted
Fix inline extent handling in btrfs_get_extent
1. Reorder kmap and the test for 'page != NULL' 2. Zero-fill rest area of a block when inline extent isn't big enough. 3. Do not insert extent_map into the map tree when page == NULL. (If insert the extent_map into the map tree, subsequent read requests will find it in the map tree directly and the corresponding inline extent data aren't copied into page by the the get_extent function. extent_read_full_page can't handle that case) Signed-off-by: Chris Mason <[email protected]>
1 parent c67cda1 commit 689f934

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

fs/btrfs/inode.c

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1596,8 +1596,7 @@ struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
15961596

15971597
size = btrfs_file_extent_inline_len(leaf, btrfs_item_nr(leaf,
15981598
path->slots[0]));
1599-
1600-
extent_end = (extent_start + size) |
1599+
extent_end = (extent_start + size - 1) |
16011600
((u64)root->sectorsize - 1);
16021601
if (start < extent_start || start >= extent_end) {
16031602
em->start = start;
@@ -1610,29 +1609,32 @@ struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page,
16101609
}
16111610
goto not_found_em;
16121611
}
1612+
em->block_start = EXTENT_MAP_INLINE;
1613+
em->block_end = EXTENT_MAP_INLINE;
1614+
1615+
if (!page) {
1616+
em->start = extent_start;
1617+
em->end = extent_start + size - 1;
1618+
goto out;
1619+
}
16131620

16141621
extent_offset = (page->index << PAGE_CACHE_SHIFT) -
1615-
extent_start;
1616-
ptr = btrfs_file_extent_inline_start(item) + extent_offset;
1617-
map = kmap(page);
1622+
extent_start + page_offset;
16181623
copy_size = min_t(u64, PAGE_CACHE_SIZE - page_offset,
16191624
size - extent_offset);
1620-
1621-
em->block_start = EXTENT_MAP_INLINE;
1622-
em->block_end = EXTENT_MAP_INLINE;
16231625
em->start = extent_start + extent_offset;
16241626
em->end = (em->start + copy_size -1) |
16251627
((u64)root->sectorsize -1);
1626-
1627-
if (!page) {
1628-
goto insert;
1628+
map = kmap(page);
1629+
ptr = btrfs_file_extent_inline_start(item) + extent_offset;
1630+
read_extent_buffer(leaf, map + page_offset, ptr, copy_size);
1631+
1632+
if (em->start + copy_size <= em->end) {
1633+
size = min_t(u64, em->end + 1 - em->start,
1634+
PAGE_CACHE_SIZE - page_offset) - copy_size;
1635+
memset(map + page_offset + copy_size, 0, size);
16291636
}
16301637

1631-
read_extent_buffer(leaf, map + page_offset, ptr, copy_size);
1632-
/*
1633-
memset(map + page_offset + copy_size, 0,
1634-
PAGE_CACHE_SIZE - copy_size - page_offset);
1635-
*/
16361638
flush_dcache_page(page);
16371639
kunmap(page);
16381640
set_extent_uptodate(em_tree, em->start, em->end, GFP_NOFS);

0 commit comments

Comments
 (0)