Using fiemap without FIEMAP_FLAG_SYNC is a known corrupter. Add the FIEMAP_FLAG_SYNC flag to the FS_IOC_FIEMAP ioctl. This has the downside of significantly reducing performance.
Reported-By: Michael Steffens <michael_steff...@posteo.de> Signed-off-by: Tony Breeds <t...@bakeyournoodle.com> Cc: Kevin Wolf <kw...@redhat.com> Cc: Markus Armbruster <arm...@redhat.com> Cc: Stefan Hajnoczi <stefa...@redhat.com> Cc: Max Reitz <mre...@redhat.com> Cc: Pádraig Brady <pbr...@redhat.com> Cc: Eric Blake <ebl...@redhat.com> --- Changes since v1: - split in to 2 patches - tried to make the commit messages better block/raw-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index a253697..b8203e9 100644 --- a/block/raw-posix.c +++ b/block/raw-posix.c @@ -1472,7 +1472,7 @@ static int64_t try_fiemap(BlockDriverState *bs, off_t start, off_t *data, f.fm.fm_start = start; f.fm.fm_length = (int64_t)nb_sectors * BDRV_SECTOR_SIZE; - f.fm.fm_flags = 0; + f.fm.fm_flags = FIEMAP_FLAG_SYNC; f.fm.fm_extent_count = 1; f.fm.fm_reserved = 0; if (ioctl(s->fd, FS_IOC_FIEMAP, &f) == -1) { -- 1.9.3