Skip to content

Commit 03a5ed2

Browse files
Christoph Hellwigtytso
authored andcommitted
ext4: split _ext4_fiemap
The fiemap and EXT4_IOC_GET_ES_CACHE cases share almost no code, so split them into entirely separate functions. Signed-off-by: Christoph Hellwig <[email protected]> Reviewed-by: Ritesh Harjani <[email protected]> Reviewed-by: Jan Kara <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Theodore Ts'o <[email protected]>
1 parent 328e24a commit 03a5ed2

File tree

1 file changed

+35
-37
lines changed

1 file changed

+35
-37
lines changed

fs/ext4/extents.c

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4884,11 +4884,9 @@ static int ext4_fiemap_check_ranges(struct inode *inode, u64 start, u64 *len)
48844884
return 0;
48854885
}
48864886

4887-
static int _ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
4888-
__u64 start, __u64 len, bool from_es_cache)
4887+
int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
4888+
u64 start, u64 len)
48894889
{
4890-
ext4_lblk_t start_blk;
4891-
u32 ext4_fiemap_flags = FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR;
48924890
int error = 0;
48934891

48944892
if (fieinfo->fi_flags & FIEMAP_FLAG_CACHE) {
@@ -4898,10 +4896,7 @@ static int _ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
48984896
fieinfo->fi_flags &= ~FIEMAP_FLAG_CACHE;
48994897
}
49004898

4901-
if (from_es_cache)
4902-
ext4_fiemap_flags &= FIEMAP_FLAG_XATTR;
4903-
4904-
if (fiemap_check_flags(fieinfo, ext4_fiemap_flags))
4899+
if (fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC | FIEMAP_FLAG_XATTR))
49054900
return -EBADR;
49064901

49074902
/*
@@ -4915,40 +4910,20 @@ static int _ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
49154910

49164911
if (fieinfo->fi_flags & FIEMAP_FLAG_XATTR) {
49174912
fieinfo->fi_flags &= ~FIEMAP_FLAG_XATTR;
4918-
error = iomap_fiemap(inode, fieinfo, start, len,
4919-
&ext4_iomap_xattr_ops);
4920-
} else if (!from_es_cache) {
4921-
error = iomap_fiemap(inode, fieinfo, start, len,
4922-
&ext4_iomap_report_ops);
4923-
} else {
4924-
ext4_lblk_t len_blks;
4925-
__u64 last_blk;
4926-
4927-
start_blk = start >> inode->i_sb->s_blocksize_bits;
4928-
last_blk = (start + len - 1) >> inode->i_sb->s_blocksize_bits;
4929-
if (last_blk >= EXT_MAX_BLOCKS)
4930-
last_blk = EXT_MAX_BLOCKS-1;
4931-
len_blks = ((ext4_lblk_t) last_blk) - start_blk + 1;
4932-
4933-
/*
4934-
* Walk the extent tree gathering extent information
4935-
* and pushing extents back to the user.
4936-
*/
4937-
error = ext4_fill_es_cache_info(inode, start_blk, len_blks,
4938-
fieinfo);
4913+
return iomap_fiemap(inode, fieinfo, start, len,
4914+
&ext4_iomap_xattr_ops);
49394915
}
4940-
return error;
4941-
}
49424916

4943-
int ext4_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
4944-
__u64 start, __u64 len)
4945-
{
4946-
return _ext4_fiemap(inode, fieinfo, start, len, false);
4917+
return iomap_fiemap(inode, fieinfo, start, len, &ext4_iomap_report_ops);
49474918
}
49484919

49494920
int ext4_get_es_cache(struct inode *inode, struct fiemap_extent_info *fieinfo,
49504921
__u64 start, __u64 len)
49514922
{
4923+
ext4_lblk_t start_blk, len_blks;
4924+
__u64 last_blk;
4925+
int error = 0;
4926+
49524927
if (ext4_has_inline_data(inode)) {
49534928
int has_inline;
49544929

@@ -4959,9 +4934,32 @@ int ext4_get_es_cache(struct inode *inode, struct fiemap_extent_info *fieinfo,
49594934
return 0;
49604935
}
49614936

4962-
return _ext4_fiemap(inode, fieinfo, start, len, true);
4963-
}
4937+
if (fieinfo->fi_flags & FIEMAP_FLAG_CACHE) {
4938+
error = ext4_ext_precache(inode);
4939+
if (error)
4940+
return error;
4941+
fieinfo->fi_flags &= ~FIEMAP_FLAG_CACHE;
4942+
}
4943+
4944+
if (fiemap_check_flags(fieinfo, FIEMAP_FLAG_SYNC))
4945+
return -EBADR;
49644946

4947+
error = ext4_fiemap_check_ranges(inode, start, &len);
4948+
if (error)
4949+
return error;
4950+
4951+
start_blk = start >> inode->i_sb->s_blocksize_bits;
4952+
last_blk = (start + len - 1) >> inode->i_sb->s_blocksize_bits;
4953+
if (last_blk >= EXT_MAX_BLOCKS)
4954+
last_blk = EXT_MAX_BLOCKS-1;
4955+
len_blks = ((ext4_lblk_t) last_blk) - start_blk + 1;
4956+
4957+
/*
4958+
* Walk the extent tree gathering extent information
4959+
* and pushing extents back to the user.
4960+
*/
4961+
return ext4_fill_es_cache_info(inode, start_blk, len_blks, fieinfo);
4962+
}
49654963

49664964
/*
49674965
* ext4_access_path:

0 commit comments

Comments
 (0)