Skip to content

Commit 848c23b

Browse files
Qu Wenruokdave
authored andcommitted
btrfs: Remove false alert when fiemap range is smaller than on-disk extent
Commit 4751832 ("btrfs: fiemap: Cache and merge fiemap extent before submit it to user") introduced a warning to catch unemitted cached fiemap extent. However such warning doesn't take the following case into consideration: 0 4K 8K |<---- fiemap range --->| |<----------- On-disk extent ------------------>| In this case, the whole 0~8K is cached, and since it's larger than fiemap range, it break the fiemap extent emit loop. This leaves the fiemap extent cached but not emitted, and caught by the final fiemap extent sanity check, causing kernel warning. This patch removes the kernel warning and renames the sanity check to emit_last_fiemap_cache() since it's possible and valid to have cached fiemap extent. Reported-by: David Sterba <[email protected]> Reported-by: Adam Borowski <[email protected]> Fixes: 4751832 ("btrfs: fiemap: Cache and merge fiemap extent ...") Signed-off-by: Qu Wenruo <[email protected]> Signed-off-by: David Sterba <[email protected]>
1 parent b7f8a09 commit 848c23b

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

fs/btrfs/extent_io.c

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4438,29 +4438,25 @@ static int emit_fiemap_extent(struct fiemap_extent_info *fieinfo,
44384438
}
44394439

44404440
/*
4441-
* Sanity check for fiemap cache
4441+
* Emit last fiemap cache
44424442
*
4443-
* All fiemap cache should be submitted by emit_fiemap_extent()
4444-
* Iteration should be terminated either by last fiemap extent or
4445-
* fieinfo->fi_extents_max.
4446-
* So no cached fiemap should exist.
4443+
* The last fiemap cache may still be cached in the following case:
4444+
* 0 4k 8k
4445+
* |<- Fiemap range ->|
4446+
* |<------------ First extent ----------->|
4447+
*
4448+
* In this case, the first extent range will be cached but not emitted.
4449+
* So we must emit it before ending extent_fiemap().
44474450
*/
4448-
static int check_fiemap_cache(struct btrfs_fs_info *fs_info,
4449-
struct fiemap_extent_info *fieinfo,
4450-
struct fiemap_cache *cache)
4451+
static int emit_last_fiemap_cache(struct btrfs_fs_info *fs_info,
4452+
struct fiemap_extent_info *fieinfo,
4453+
struct fiemap_cache *cache)
44514454
{
44524455
int ret;
44534456

44544457
if (!cache->cached)
44554458
return 0;
44564459

4457-
/* Small and recoverbale problem, only to info developer */
4458-
#ifdef CONFIG_BTRFS_DEBUG
4459-
WARN_ON(1);
4460-
#endif
4461-
btrfs_warn(fs_info,
4462-
"unhandled fiemap cache detected: offset=%llu phys=%llu len=%llu flags=0x%x",
4463-
cache->offset, cache->phys, cache->len, cache->flags);
44644460
ret = fiemap_fill_next_extent(fieinfo, cache->offset, cache->phys,
44654461
cache->len, cache->flags);
44664462
cache->cached = false;
@@ -4676,7 +4672,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
46764672
}
46774673
out_free:
46784674
if (!ret)
4679-
ret = check_fiemap_cache(root->fs_info, fieinfo, &cache);
4675+
ret = emit_last_fiemap_cache(root->fs_info, fieinfo, &cache);
46804676
free_extent_map(em);
46814677
out:
46824678
btrfs_free_path(path);

0 commit comments

Comments
 (0)