Skip to content

Commit 6787a82

Browse files
chaseyuJaegeuk Kim
authored andcommitted
f2fs: fix to requery extent which cross boundary of inquiry
dd if=/dev/zero of=file bs=4k count=5 xfs_io file -c "fiemap -v 2 16384" file: EXT: FILE-OFFSET BLOCK-RANGE TOTAL FLAGS 0: [0..31]: 139272..139303 32 0x1000 1: [32..39]: 139304..139311 8 0x1001 xfs_io file -c "fiemap -v 0 16384" file: EXT: FILE-OFFSET BLOCK-RANGE TOTAL FLAGS 0: [0..31]: 139272..139303 32 0x1000 xfs_io file -c "fiemap -v 0 16385" file: EXT: FILE-OFFSET BLOCK-RANGE TOTAL FLAGS 0: [0..39]: 139272..139311 40 0x1001 There are two problems: - continuous extent is split to two - FIEMAP_EXTENT_LAST is missing in last extent The root cause is: if upper boundary of inquiry crosses extent, f2fs_map_blocks() will truncate length of returned extent to F2FS_BYTES_TO_BLK(len), and also, it will stop to query latter extent or hole to make sure current extent is last or not. In order to fix this issue, once we found an extent locates in the end of inquiry range by f2fs_map_blocks(), we need to expand inquiry range to requiry. Cc: stable@vger.kernel.org Fixes: 7f63eb7 ("f2fs: report unwritten area in f2fs_fiemap") Reported-by: Zhiguo Niu <zhiguo.niu@unisoc.com> Signed-off-by: Chao Yu <chao@kernel.org> Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
1 parent 77569f7 commit 6787a82

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

fs/f2fs/data.c

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1896,7 +1896,7 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
18961896
u64 start, u64 len)
18971897
{
18981898
struct f2fs_map_blocks map;
1899-
sector_t start_blk, last_blk;
1899+
sector_t start_blk, last_blk, blk_len, max_len;
19001900
pgoff_t next_pgofs;
19011901
u64 logical = 0, phys = 0, size = 0;
19021902
u32 flags = 0;
@@ -1940,14 +1940,13 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
19401940

19411941
start_blk = F2FS_BYTES_TO_BLK(start);
19421942
last_blk = F2FS_BYTES_TO_BLK(start + len - 1);
1943-
1944-
if (len & F2FS_BLKSIZE_MASK)
1945-
len = round_up(len, F2FS_BLKSIZE);
1943+
blk_len = last_blk - start_blk + 1;
1944+
max_len = F2FS_BYTES_TO_BLK(maxbytes) - start_blk;
19461945

19471946
next:
19481947
memset(&map, 0, sizeof(map));
19491948
map.m_lblk = start_blk;
1950-
map.m_len = F2FS_BYTES_TO_BLK(len);
1949+
map.m_len = blk_len;
19511950
map.m_next_pgofs = &next_pgofs;
19521951
map.m_seg_type = NO_CHECK_TYPE;
19531952

@@ -1970,6 +1969,17 @@ int f2fs_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
19701969
flags |= FIEMAP_EXTENT_LAST;
19711970
}
19721971

1972+
/*
1973+
* current extent may cross boundary of inquiry, increase len to
1974+
* requery.
1975+
*/
1976+
if (!compr_cluster && (map.m_flags & F2FS_MAP_MAPPED) &&
1977+
map.m_lblk + map.m_len - 1 == last_blk &&
1978+
blk_len != max_len) {
1979+
blk_len = max_len;
1980+
goto next;
1981+
}
1982+
19731983
compr_appended = false;
19741984
/* In a case of compressed cluster, append this to the last extent */
19751985
if (compr_cluster && ((map.m_flags & F2FS_MAP_DELALLOC) ||

0 commit comments

Comments
 (0)