Received: from eggs.gnu.org ([2001:4830:134:3::10]:36105) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XX1YZ-0006HH-K1 for qemu-devel@nongnu.org; Thu, 25 Sep 2014 01:25:36 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1XX1YV-0006Zl-03 for qemu-devel@nongnu.org; Thu, 25 Sep 2014 01:25:31 -0400 Received: from ozlabs.org ([103.22.144.67]:44651) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1XX1YU-0006Xe-LU for qemu-devel@nongnu.org; Thu, 25 Sep 2014 01:25:26 -0400 From: Tony Breeds Date: Thu, 25 Sep 2014 15:23:47 +1000 Message-Id: <1411622627-22110-1-git-send-email-tony@bakeyournoodle.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [PATCH] block/raw-posix: use seek_hole ahead of fiemap List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: =?UTF-8?q?P=C3=A1draig=20Brady?= , Tony Breeds , Michael Steffens The command qemu-img convert -O raw inputimage.qcow2 outputimage.raw intermittently creates corrupted output images, when the input image is n= ot yet fully synchronized to disk. This patch preferese the use of seek_= hole checks to determine if the sector is present in the disk image. While we're there modify try_fiemap() to set FIEMAP_FLAG_SYNC. Reported-By: Michael Steffens CC: P=C3=A1draig Brady Signed-off-by: Tony Breeds --- block/raw-posix.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/block/raw-posix.c b/block/raw-posix.c index a253697..b438c54 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, =20 f.fm.fm_start =3D start; f.fm.fm_length =3D (int64_t)nb_sectors * BDRV_SECTOR_SIZE; - f.fm.fm_flags =3D 0; + f.fm.fm_flags =3D FIEMAP_FLAG_SYNC; f.fm.fm_extent_count =3D 1; f.fm.fm_reserved =3D 0; if (ioctl(s->fd, FS_IOC_FIEMAP, &f) =3D=3D -1) { @@ -1561,9 +1561,9 @@ static int64_t coroutine_fn raw_co_get_block_status= (BlockDriverState *bs, =20 start =3D sector_num * BDRV_SECTOR_SIZE; =20 - ret =3D try_fiemap(bs, start, &data, &hole, nb_sectors, pnum); + ret =3D try_seek_hole(bs, start, &data, &hole, pnum); if (ret < 0) { - ret =3D try_seek_hole(bs, start, &data, &hole, pnum); + ret =3D try_fiemap(bs, start, &data, &hole, nb_sectors, pnum); if (ret < 0) { /* Assume everything is allocated. */ data =3D 0; --=20 1.9.3