Commit d5ad3308 authored by Qu Wenruo's avatar Qu Wenruo Committed by Greg Kroah-Hartman

btrfs: Remove false alert when fiemap range is smaller than on-disk extent

commit 848c23b7 upstream.

Commit 4751832d ("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: default avatarDavid Sterba <dsterba@suse.cz>
Reported-by: default avatarAdam Borowski <kilobyte@angband.pl>
Fixes: 4751832d ("btrfs: fiemap: Cache and merge fiemap extent ...")
Signed-off-by: default avatarQu Wenruo <quwenruo@cn.fujitsu.com>
Signed-off-by: default avatarDavid Sterba <dsterba@suse.com>
Cc: Holger Hoffstätte <holger@applied-asynchrony.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent c4b3691a
...@@ -4463,29 +4463,25 @@ static int emit_fiemap_extent(struct fiemap_extent_info *fieinfo, ...@@ -4463,29 +4463,25 @@ static int emit_fiemap_extent(struct fiemap_extent_info *fieinfo,
} }
/* /*
* Sanity check for fiemap cache * Emit last fiemap cache
* *
* All fiemap cache should be submitted by emit_fiemap_extent() * The last fiemap cache may still be cached in the following case:
* Iteration should be terminated either by last fiemap extent or * 0 4k 8k
* fieinfo->fi_extents_max. * |<- Fiemap range ->|
* So no cached fiemap should exist. * |<------------ First extent ----------->|
*
* In this case, the first extent range will be cached but not emitted.
* So we must emit it before ending extent_fiemap().
*/ */
static int check_fiemap_cache(struct btrfs_fs_info *fs_info, static int emit_last_fiemap_cache(struct btrfs_fs_info *fs_info,
struct fiemap_extent_info *fieinfo, struct fiemap_extent_info *fieinfo,
struct fiemap_cache *cache) struct fiemap_cache *cache)
{ {
int ret; int ret;
if (!cache->cached) if (!cache->cached)
return 0; return 0;
/* Small and recoverbale problem, only to info developer */
#ifdef CONFIG_BTRFS_DEBUG
WARN_ON(1);
#endif
btrfs_warn(fs_info,
"unhandled fiemap cache detected: offset=%llu phys=%llu len=%llu flags=0x%x",
cache->offset, cache->phys, cache->len, cache->flags);
ret = fiemap_fill_next_extent(fieinfo, cache->offset, cache->phys, ret = fiemap_fill_next_extent(fieinfo, cache->offset, cache->phys,
cache->len, cache->flags); cache->len, cache->flags);
cache->cached = false; cache->cached = false;
...@@ -4701,7 +4697,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, ...@@ -4701,7 +4697,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo,
} }
out_free: out_free:
if (!ret) if (!ret)
ret = check_fiemap_cache(root->fs_info, fieinfo, &cache); ret = emit_last_fiemap_cache(root->fs_info, fieinfo, &cache);
free_extent_map(em); free_extent_map(em);
out: out:
btrfs_free_path(path); btrfs_free_path(path);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment