@@ -4504,7 +4504,7 @@ int btrfs_cont_expand(struct inode *inode, loff_t oldsize, loff_t size)
45044504 cur_offset = hole_start ;
45054505 while (1 ) {
45064506 em = btrfs_get_extent (BTRFS_I (inode ), NULL , 0 , cur_offset ,
4507- block_end - cur_offset , 0 );
4507+ block_end - cur_offset );
45084508 if (IS_ERR (em )) {
45094509 err = PTR_ERR (em );
45104510 em = NULL ;
@@ -6283,18 +6283,27 @@ static noinline int uncompress_inline(struct btrfs_path *path,
62836283 return ret ;
62846284}
62856285
6286- /*
6287- * a bit scary, this does extent mapping from logical file offset to the disk.
6288- * the ugly parts come from merging extents from the disk with the in-ram
6289- * representation. This gets more complex because of the data=ordered code,
6290- * where the in-ram extents might be locked pending data=ordered completion.
6286+ /**
6287+ * btrfs_get_extent - Lookup the first extent overlapping a range in a file.
6288+ * @inode: file to search in
6289+ * @page: page to read extent data into if the extent is inline
6290+ * @pg_offset: offset into @page to copy to
6291+ * @start: file offset
6292+ * @len: length of range starting at @start
6293+ *
6294+ * This returns the first &struct extent_map which overlaps with the given
6295+ * range, reading it from the B-tree and caching it if necessary. Note that
6296+ * there may be more extents which overlap the given range after the returned
6297+ * extent_map.
62916298 *
6292- * This also copies inline extents directly into the page.
6299+ * If @page is not NULL and the extent is inline, this also reads the extent
6300+ * data directly into the page and marks the extent up to date in the io_tree.
6301+ *
6302+ * Return: ERR_PTR on error, non-NULL extent_map on success.
62936303 */
62946304struct extent_map * btrfs_get_extent (struct btrfs_inode * inode ,
6295- struct page * page ,
6296- size_t pg_offset , u64 start , u64 len ,
6297- int create )
6305+ struct page * page , size_t pg_offset ,
6306+ u64 start , u64 len )
62986307{
62996308 struct btrfs_fs_info * fs_info = inode -> root -> fs_info ;
63006309 int ret ;
@@ -6311,7 +6320,6 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
63116320 struct extent_map * em = NULL ;
63126321 struct extent_map_tree * em_tree = & inode -> extent_tree ;
63136322 struct extent_io_tree * io_tree = & inode -> io_tree ;
6314- const bool new_inline = !page || create ;
63156323
63166324 read_lock (& em_tree -> lock );
63176325 em = lookup_extent_mapping (em_tree , start , len );
@@ -6434,8 +6442,7 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
64346442 goto insert ;
64356443 }
64366444
6437- btrfs_extent_item_to_extent_map (inode , path , item ,
6438- new_inline , em );
6445+ btrfs_extent_item_to_extent_map (inode , path , item , !page , em );
64396446
64406447 if (extent_type == BTRFS_FILE_EXTENT_REG ||
64416448 extent_type == BTRFS_FILE_EXTENT_PREALLOC ) {
@@ -6447,7 +6454,7 @@ struct extent_map *btrfs_get_extent(struct btrfs_inode *inode,
64476454 size_t extent_offset ;
64486455 size_t copy_size ;
64496456
6450- if (new_inline )
6457+ if (! page )
64516458 goto out ;
64526459
64536460 size = btrfs_file_extent_ram_bytes (leaf , item );
@@ -6530,7 +6537,7 @@ struct extent_map *btrfs_get_extent_fiemap(struct btrfs_inode *inode,
65306537 u64 delalloc_end ;
65316538 int err = 0 ;
65326539
6533- em = btrfs_get_extent (inode , NULL , 0 , start , len , 0 );
6540+ em = btrfs_get_extent (inode , NULL , 0 , start , len );
65346541 if (IS_ERR (em ))
65356542 return em ;
65366543 /*
@@ -7155,7 +7162,7 @@ static int btrfs_get_blocks_direct(struct inode *inode, sector_t iblock,
71557162 goto err ;
71567163 }
71577164
7158- em = btrfs_get_extent (BTRFS_I (inode ), NULL , 0 , start , len , 0 );
7165+ em = btrfs_get_extent (BTRFS_I (inode ), NULL , 0 , start , len );
71597166 if (IS_ERR (em )) {
71607167 ret = PTR_ERR (em );
71617168 goto unlock_err ;
@@ -10166,7 +10173,7 @@ static int btrfs_swap_activate(struct swap_info_struct *sis, struct file *file,
1016610173 struct btrfs_block_group * bg ;
1016710174 u64 len = isize - start ;
1016810175
10169- em = btrfs_get_extent (BTRFS_I (inode ), NULL , 0 , start , len , 0 );
10176+ em = btrfs_get_extent (BTRFS_I (inode ), NULL , 0 , start , len );
1017010177 if (IS_ERR (em )) {
1017110178 ret = PTR_ERR (em );
1017210179 goto out ;
0 commit comments