block/raw-posix: use seek_hole ahead of fiemap
PATCH 1/1 block/raw-posix: use seek_hole ahead of fiemap
The command
qemu-img convert -O raw inputimage.qcow2 outputimage.raw
intermittently creates corrupted output images, when the input image is not 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.
--- block/raw-posix.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
block/raw-posix.c +3 -3
@@ -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 ) {
@@ -1561,9 +1561,9 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, start = sector_num *BDRV_SECTOR_SIZE ; - ret =try_fiemap (bs, start, &data, &hole, nb_sectors, pnum); + ret =try_seek_hole (bs, start, &data, &hole, pnum);if (ret <0 ) { - ret =try_seek_hole (bs, start, &data, &hole, pnum); + ret =try_fiemap (bs, start, &data, &hole, nb_sectors, pnum);if (ret <0 ) {/* Assume everything is allocated. */ data =0 ;
Signature · 1 line
1.9.3
Please copy Kevin & Stefan for block patches. Doing that for you. I also copy Max, who left his fingerprints on commit 4f11aa8.
Quoted 39 lines · Tony Breeds
The command
qemu-img convert -O raw inputimage.qcow2 outputimage.rawintermittently creates corrupted output images, when the input image is not yet fully synchronized to disk. This patch preferese the use of
seek_holechecks to determine if the sector is present in the disk image.While we're there modify
try_fiemap()to setFIEMAP_FLAG_SYNC.Reported-By Michael Steffens <[email protected]>CC Pádraig Brady <[email protected]>Signed-off-by Tony Breeds <[email protected]>--- block/raw-posix.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)block/raw-posix.c +3
-3@@ -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 ) {@@ -1561,9 +1561,9 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, start = sector_num *BDRV_SECTOR_SIZE ; - ret =try_fiemap (bs, start, &data, &hole, nb_sectors, pnum); + ret =try_seek_hole (bs, start, &data, &hole, pnum);if (ret <0 ) { - ret =try_seek_hole (bs, start, &data, &hole, pnum); + ret =try_fiemap (bs, start, &data, &hole, nb_sectors, pnum);if (ret <0 ) {/* Assume everything is allocated. */ data =0 ;
Quoted 2 lines · Markus Armbruster
Please copy Kevin & Stefan for block patches. Doing that for you. I also copy Max, who left his fingerprints on commit 4f11aa8.
Sorry.
Is there a qemu version of get_maintainers.pl?
Tony.
Quoted 9 lines · On Thu, 25 Sep 2014 16:29:31 +1000 Tony Breeds <[email protected]> wrote:
Quoted 2 lines · Markus Armbruster
Please copy Kevin & Stefan for block patches. Doing that for you. I also copy Max, who left his fingerprints on commit 4f11aa8.
Sorry.
Is there a qemu version of get_maintainers.pl?
Tony.
Hi Tony,
Same path : ./scripts/get_maintainer.pl
Cheers.
--
Greg
Quoted 1 line · Greg Kurz
Same path :
./scripts/get_maintainer.pl
Thanks Greg. Now I know :)
Tony.
Quoted 7 lines · Tony Breeds
Quoted 2 lines · Markus Armbruster
Please copy Kevin & Stefan for block patches. Doing that for you. I also copy Max, who left his fingerprints on commit 4f11aa8.
Sorry.
Is there a qemu version of get_maintainers.pl?
Yes :)
$ scripts/get_maintainer.pl $your_msg Kevin Wolf <[email protected]> (supporter:Block) Stefan Hajnoczi <[email protected]> (supporter:Block)
Am 25.09.2014 um 08:21 hat Markus Armbruster geschrieben:
Quoted 9 lines
Please copy Kevin & Stefan for block patches. Doing that for you. I also copy Max, who left his fingerprints on commit 4f11aa8.
Quoted 4 lines · Tony Breeds
The command
qemu-img convert -O raw inputimage.qcow2 outputimage.rawintermittently creates corrupted output images, when the input image is not yet fully synchronized to disk. This patch preferese the use of
seek_holechecks to determine if the sector is present in the disk image.
Does this fix the problem or does it just make it less likely that it becomes apparent?
If there is a data corruptor, we need to fix it, not just ensure that only the less common environments are affected.
Quoted 1 line
Quoted 1 line
While we're there modify
try_fiemap()to setFIEMAP_FLAG_SYNC.
That looks like a logically separate change, so it should probably be a separate patch.
Is this fix for the corruptor? The commit message doesn't make it clear. If so and fiemap is safe now, why would we still prefer seek_hole?
Quoted 3 lines
Quoted 3 lines
Reported-By Michael Steffens <[email protected]>CC Pádraig Brady <[email protected]>Signed-off-by Tony Breeds <[email protected]>
Kevin
Quoted 2 lines · Kevin Wolf
Does this fix the problem or does it just make it less likely that it becomes apparent?
Sorry for not making this clearer in my commit message.
I haven't been able to reproduce the corruption with the fiemap flag change.
Quoted 2 lines
If there is a data corruptor, we need to fix it, not just ensure that only the less common environments are affected.
I agree. I believe that the FIEMAP_FLAG_SYNC flag change fixes the corrupter and then, as you say, makes that code less commonly executed.
Quoted 2 lines
That looks like a logically separate change, so it should probably be a separate patch.
Sure I can do that, and be more explicit about the reason in the commit message.
Quoted 3 lines
Is this fix for the corruptor? The commit message doesn't make it clear. If so and fiemap is safe now, why would we still prefer
seek_hole?
The preference for seek_hole was a suggestion from Pádraig Brady , so I'll let him defend that :) but as I said above I think it was about reducing the situations where fiemap was/is called.
Tony.
Am 25.09.2014 um 11:00 hat Tony Breeds geschrieben:
Quoted 22 lines · Kevin Wolf
Quoted 3 lines
Does this fix the problem or does it just make it less likely that it becomes apparent?
Sorry for not making this clearer in my commit message.
I haven't been able to reproduce the corruption with the fiemap flag change.
Quoted 2 lines
If there is a data corruptor, we need to fix it, not just ensure that only the less common environments are affected.
I agree. I believe that the
FIEMAP_FLAG_SYNCflag change fixes the corrupter and then, as you say, makes that code less commonly executed.Quoted 2 lines
That looks like a logically separate change, so it should probably be a separate patch.
Sure I can do that, and be more explicit about the reason in the commit message.
Quoted 7 lines
Quoted 3 lines
Is this fix for the corruptor? The commit message doesn't make it clear. If so and fiemap is safe now, why would we still prefer
seek_hole?The preference for
seek_holewas a suggestion from Pádraig Brady , so I'll let him defend that :) but as I said above I think it was about reducing the situations where fiemap was/is called.
Okay. I'm not opposed to the change, we just need to split and document it properly.
So first we should fix the bug by adding FIEMAP_FLAG_SYNC. Or actually, it might just be a workaround for a kernel bug. Is the expected behaviour documented, and if yes, what is it? We should describe as precisely as possible what the situation is and why we have to add this flag in qemu. You can probably reuse a good part of your current commit message for that and extend it a bit.
And then we may or may not make the second change with the preference for seek_hole. If FIEMAP_FLAG_SYNC actually does additional writes or an fsync(), switching is a performance optimisation and might be justified as such. Maybe Pádraig has some more input on this.
Kevin
Quoted 13 lines · Tony Breeds
Quoted 2 lines · Kevin Wolf
Does this fix the problem or does it just make it less likely that it becomes apparent?
Sorry for not making this clearer in my commit message.
I haven't been able to reproduce the corruption with the fiemap flag change.
Quoted 2 lines
If there is a data corruptor, we need to fix it, not just ensure that only the less common environments are affected.
Quoted 12 lines
I agree. I believe that the
FIEMAP_FLAG_SYNCflag change fixes the corrupter and then, as you say, makes that code less commonly executed.Quoted 2 lines
That looks like a logically separate change, so it should probably be a separate patch.
Sure I can do that, and be more explicit about the reason in the commit message.
Quoted 3 lines
Is this fix for the corruptor? The commit message doesn't make it clear. If so and fiemap is safe now, why would we still prefer
seek_hole?
syncing a file has performance side effects, so best go try the (more portable) seek hole interface.
Quoted 3 lines
The preference for
seek_holewas a suggestion from Pádraig Brady , so I'll let him defend that :) but as I said above I think it was about reducing the situations where fiemap was/is called.
IMHO it's a kernel bug that fiemap() needs a sync to be useful. This was being fixed up in various file systems but Dave Chiner pushed back on XFS adjustments, and thus changes were stalled. The current situation is it's best to avoid fiemap().
thanks,
Pádraig.
Quoted 17 lines · Kevin Wolf
Am 25.09.2014 um 08:21 hat Markus Armbruster geschrieben:
Quoted 9 lines
Please copy Kevin & Stefan for block patches. Doing that for you. I also copy Max, who left his fingerprints on commit 4f11aa8.
Quoted 4 lines · Tony Breeds
The command
qemu-img convert -O raw inputimage.qcow2 outputimage.rawintermittently creates corrupted output images, when the input image is not yet fully synchronized to disk. This patch preferese the use of
seek_holechecks to determine if the sector is present in the disk image.Does this fix the problem or does it just make it less likely that it becomes apparent?
If there is a data corruptor, we need to fix it, not just ensure that only the less common environments are affected.
Quoted 8 lines
Quoted 1 line
Quoted 1 line
While we're there modify
try_fiemap()to setFIEMAP_FLAG_SYNC.That looks like a logically separate change, so it should probably be a separate patch.
Is this fix for the corruptor? The commit message doesn't make it clear. If so and fiemap is safe now, why would we still prefer
seek_hole?
My understanding, based on what coreutils learned:
fiemap without FIEMAP_FLAG_SYNC is a data corrupter. fiemap _with_ FIEMAP_FLAG_SYNC is a performance killer (noticeably slower, because it forces a sync). SEEK_HOLE is a much simpler interface, and therefore the kernel can optimize it to return correct results faster than it can for fiemap, and it does not suffer from the fiemap on unsynced file data corruption. So coreutils _prefers_ seek_hole first, and when it has to use fiemap, prefers using fiemap with FIEMAP_FLAG_SYNC.
I agree with splitting this into two patches; one to add the flag as a data corruption fix but acknowledging that it slows fiemap down, the other to relegate fiemap to the fallback case since seek_hole can be faster when it doesn't have to force a sync.
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Quoted 4 lines · Tony Breeds
The command
qemu-img convert -O raw inputimage.qcow2 outputimage.rawintermittently creates corrupted output images, when the input image
is not 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.
s/preferese/prefers/
Please wrap your commit messages to fit in 70 or so columns (so that git log, which indents messages, is still legible in an 80-column window).
Quoted 10 lines
While we're there modify
try_fiemap()to setFIEMAP_FLAG_SYNC.Reported-By Michael Steffens <[email protected]>CC Pádraig Brady <[email protected]>Signed-off-by Tony Breeds <[email protected]>--- block/raw-posix.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
Adding Kevin and Stefan in cc (per scripts/get_maintainer.pl).
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
PATCH v2 1/2 block/raw-posix: Fix disk corruption in try_fiemap
In reply to Tony BreedsUsing 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.
---
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(-)
block/raw-posix.c +1 -1
@@ -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 ) {
Signature · 1 line
1.9.3
PATCH v2 2/2 block/raw-posix: use seek_hole ahead of fiemap
try_fiemap() uses FIEMAP_FLAG_SYNC which has a significant performance impact.
Prefer seek_hole() over fiemap() to avoid this impact where possible. seek_hole is more widely used and, arguably, has potential to be optimised in the kernel.
---
Changes since v1:
- split in to 2 patches
- tried to make the commit messages better
block/raw-posix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
block/raw-posix.c +2 -2
@@ -1561,9 +1561,9 @@ static int64_t coroutine_fn raw_co_get_block_status(BlockDriverState *bs, start = sector_num *BDRV_SECTOR_SIZE ; - ret =try_fiemap (bs, start, &data, &hole, nb_sectors, pnum); + ret =try_seek_hole (bs, start, &data, &hole, pnum);if (ret <0 ) { - ret =try_seek_hole (bs, start, &data, &hole, pnum); + ret =try_fiemap (bs, start, &data, &hole, nb_sectors, pnum);if (ret <0 ) {/* Assume everything is allocated. */ data =0 ;
Signature · 1 line
1.9.3
Quoted 15 lines · Tony Breeds
try_fiemap()usesFIEMAP_FLAG_SYNCwhich has a significant performance impact.Prefer
seek_hole()overfiemap()to avoid this impact where possible.seek_holeis more widely used and, arguably, has potential to be optimised in the kernel.Reported-By Michael Steffens <[email protected]>Signed-off-by Tony Breeds <[email protected]>Cc Kevin Wolf <[email protected]>Cc Markus Armbruster <[email protected]>Cc Stefan Hajnoczi <[email protected]>Cc Max Reitz <[email protected]>Cc Pádraig Brady <[email protected]>Cc Eric Blake <[email protected]>
Quoted 4 lines
---
Changes since v1:
- split in to 2 patches
- tried to make the commit messages better
I used this order in at least one of the non-final versions of 4f11aa8a, so I'm fine with it. The reason it got rejected was (as far as I remember) that the FIEMAP ioctl() returns ENOTSUP if not supported, whereas lseek() with SEEK_HOLE/SEEK_DATA returns some failsafe value, probably reporting no holes at all. By reversing the order of try_fiemap() and try_seek_hole(), try_fiemap() therefore may very well become dead code. I don't object, however.
Quoted 6 lines · Tony Breeds
try_fiemap()usesFIEMAP_FLAG_SYNCwhich has a significant performance impact.Prefer
seek_hole()overfiemap()to avoid this impact where possible.seek_holeis more widely used and, arguably, has potential to be optimised in the kernel.
It also has the potential to be less precise than fiemap on older kernels (any filesystem that supports fiemap but has not yet wired up seek_hole will get the kernel's default fallback of claiming no holes at all), but that problem will fade as more people use modern kernels. This matches what coreutils does, so I like it on that grounds.
Quoted 9 lines
Reported-By Michael Steffens <[email protected]>Signed-off-by Tony Breeds <[email protected]>Cc Kevin Wolf <[email protected]>Cc Markus Armbruster <[email protected]>Cc Stefan Hajnoczi <[email protected]>Cc Max Reitz <[email protected]>Cc Pádraig Brady <[email protected]>Cc Eric Blake <[email protected]>
Quoted 4 lines
---
Changes since v1:
- split in to 2 patches
- tried to make the commit messages better
Thanks; it is indeed better.
Quoted 3 lines
block/raw-posix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v2 1/2] block/raw-posix: Fix disk corruption in try_fiemap
In reply to Tony BreedsQuoted 13 lines · Tony Breeds
Using fiemap without
FIEMAP_FLAG_SYNCis a known corrupter.Add the
FIEMAP_FLAG_SYNCflag to theFS_IOC_FIEMAPioctl. This has the downside of significantly reducing performance.Reported-By Michael Steffens <[email protected]>Signed-off-by Tony Breeds <[email protected]>Cc Kevin Wolf <[email protected]>Cc Markus Armbruster <[email protected]>Cc Stefan Hajnoczi <[email protected]>Cc Max Reitz <[email protected]>Cc Pádraig Brady <[email protected]>Cc Eric Blake <[email protected]>
Quoted 7 lines
---
Changes since v1:
- split in to 2 patches
- tried to make the commit messages betterblock/raw-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Re: [Qemu-devel] [PATCH v2 1/2] block/raw-posix: Fix disk corruption in try_fiemap
In reply to Tony BreedsQuoted 13 lines · Tony Breeds
Using fiemap without
FIEMAP_FLAG_SYNCis a known corrupter.Add the
FIEMAP_FLAG_SYNCflag to theFS_IOC_FIEMAPioctl. This has the downside of significantly reducing performance.Reported-By Michael Steffens <[email protected]>Signed-off-by Tony Breeds <[email protected]>Cc Kevin Wolf <[email protected]>Cc Markus Armbruster <[email protected]>Cc Stefan Hajnoczi <[email protected]>Cc Max Reitz <[email protected]>Cc Pádraig Brady <[email protected]>Cc Eric Blake <[email protected]>
Quoted 7 lines
---
Changes since v1:
- split in to 2 patches
- tried to make the commit messages betterblock/raw-posix.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
[you buried your patches in deep reply to a longer thread, making them harder to find; in the future, you can just send a v2 as a new top-level thread]
Signature · 2 lines
Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
Re: [Qemu-devel] [PATCH v2 1/2] block/raw-posix: Fix disk corruption in try_fiemap
Quoted 3 lines · Eric Blake
[you buried your patches in deep reply to a longer thread, making them harder to find; in the future, you can just send a v2 as a new top-level thread]
Thanks. I'll remember that next time.
Tony.
Kevin Wolf
AppliedRe: [Qemu-devel] [PATCH v2 1/2] block/raw-posix: Fix disk corruption in try_fiemap
In reply to Tony BreedsAm 26.09.2014 um 01:14 hat Tony Breeds geschrieben:
Quoted 13 lines
Using fiemap without
FIEMAP_FLAG_SYNCis a known corrupter.Add the
FIEMAP_FLAG_SYNCflag to theFS_IOC_FIEMAPioctl. This has the downside of significantly reducing performance.Reported-By Michael Steffens <[email protected]>Signed-off-by Tony Breeds <[email protected]>Cc Kevin Wolf <[email protected]>Cc Markus Armbruster <[email protected]>Cc Stefan Hajnoczi <[email protected]>Cc Max Reitz <[email protected]>Cc Pádraig Brady <[email protected]>Cc Eric Blake <[email protected]>
Quoted 4 lines
---
Changes since v1:
- split in to 2 patches
- tried to make the commit messages better
Thanks, applied to the block branch.
Kevin