Skip to content

Commit 970ea37

Browse files
committed
btrfs: pass a valid extent map cache pointer to __get_extent_map()
We can pass a valid em cache pointer down to __get_extent_map() and drop the validity check. This avoids the special case, the call stacks are simple: btrfs_read_folio btrfs_do_readpage __get_extent_map extent_readahead contiguous_readpages btrfs_do_readpage __get_extent_map Reviewed-by: Josef Bacik <josef@toxicpanda.com> Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 5a8a57f commit 970ea37

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

fs/btrfs/extent_io.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,9 @@ static struct extent_map *__get_extent_map(struct inode *inode, struct page *pag
970970
{
971971
struct extent_map *em;
972972

973-
if (em_cached && *em_cached) {
973+
ASSERT(em_cached);
974+
975+
if (*em_cached) {
974976
em = *em_cached;
975977
if (extent_map_in_tree(em) && start >= em->start &&
976978
start < extent_map_end(em)) {
@@ -983,7 +985,7 @@ static struct extent_map *__get_extent_map(struct inode *inode, struct page *pag
983985
}
984986

985987
em = btrfs_get_extent(BTRFS_I(inode), page, start, len);
986-
if (em_cached && !IS_ERR(em)) {
988+
if (!IS_ERR(em)) {
987989
BUG_ON(*em_cached);
988990
refcount_inc(&em->refs);
989991
*em_cached = em;
@@ -1154,11 +1156,14 @@ int btrfs_read_folio(struct file *file, struct folio *folio)
11541156
u64 start = page_offset(page);
11551157
u64 end = start + PAGE_SIZE - 1;
11561158
struct btrfs_bio_ctrl bio_ctrl = { .opf = REQ_OP_READ };
1159+
struct extent_map *em_cached = NULL;
11571160
int ret;
11581161

11591162
btrfs_lock_and_flush_ordered_range(inode, start, end, NULL);
11601163

1161-
ret = btrfs_do_readpage(page, NULL, &bio_ctrl, NULL);
1164+
ret = btrfs_do_readpage(page, &em_cached, &bio_ctrl, NULL);
1165+
free_extent_map(em_cached);
1166+
11621167
/*
11631168
* If btrfs_do_readpage() failed we will want to submit the assembled
11641169
* bio to do the cleanup.
@@ -1176,6 +1181,8 @@ static inline void contiguous_readpages(struct page *pages[], int nr_pages,
11761181
struct btrfs_inode *inode = page_to_inode(pages[0]);
11771182
int index;
11781183

1184+
ASSERT(em_cached);
1185+
11791186
btrfs_lock_and_flush_ordered_range(inode, start, end, NULL);
11801187

11811188
for (index = 0; index < nr_pages; index++) {

0 commit comments

Comments
 (0)