* [Qemu-devel] [PATCH] qcow2: Restore total_sectors value in save_vmstate
@ 2013-10-20 18:28 Max Reitz
2013-10-21 20:36 ` Eric Blake
0 siblings, 1 reply; 4+ messages in thread
From: Max Reitz @ 2013-10-20 18:28 UTC (permalink / raw)
To: qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi, Max Reitz
Since df2a6f29a5, bdrv_co_do_writev increases the total_sectors value of
a growable block devices on writes after the current end. This leads to
the virtual disk apparently growing in qcow2_save_vmstate, which in turn
affects the disk size captured by the internal snapshot taken directly
afterwards through e.g. the HMP savevm command. Such a "grown" snapshot
cannot be loaded after reopening the qcow2 image, since its disk size
differs from the actual virtual disk size (writing a VM state does not
actually increase the virtual disk size).
Fix this by restoring total_sectors at the end of qcow2_save_vmstate.
Signed-off-by: Max Reitz <mreitz@redhat.com>
---
block/qcow2.c | 5 +++++
1 file changed, 5 insertions(+)
diff --git a/block/qcow2.c b/block/qcow2.c
index c1abaff..5c05bb5 100644
--- a/block/qcow2.c
+++ b/block/qcow2.c
@@ -1939,6 +1939,7 @@ static int qcow2_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov,
int64_t pos)
{
BDRVQcowState *s = bs->opaque;
+ int64_t total_sectors = bs->total_sectors;
int growable = bs->growable;
int ret;
@@ -1946,6 +1947,10 @@ static int qcow2_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov,
bs->growable = 1;
ret = bdrv_pwritev(bs, qcow2_vm_state_offset(s) + pos, qiov);
bs->growable = growable;
+ // bdrv_co_do_writev will have increased the total_sectors value to include
+ // the VM state - the VM state is however not an actual part of the block
+ // device, therefore, we need to restore the old value.
+ bs->total_sectors = total_sectors;
return ret;
}
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] qcow2: Restore total_sectors value in save_vmstate
2013-10-20 18:28 [Qemu-devel] [PATCH] qcow2: Restore total_sectors value in save_vmstate Max Reitz
@ 2013-10-21 20:36 ` Eric Blake
2013-10-23 17:03 ` Max Reitz
0 siblings, 1 reply; 4+ messages in thread
From: Eric Blake @ 2013-10-21 20:36 UTC (permalink / raw)
To: Max Reitz, qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi
[-- Attachment #1: Type: text/plain, Size: 1593 bytes --]
On 10/20/2013 07:28 PM, Max Reitz wrote:
> Since df2a6f29a5, bdrv_co_do_writev increases the total_sectors value of
> a growable block devices on writes after the current end. This leads to
> the virtual disk apparently growing in qcow2_save_vmstate, which in turn
> affects the disk size captured by the internal snapshot taken directly
> afterwards through e.g. the HMP savevm command. Such a "grown" snapshot
> cannot be loaded after reopening the qcow2 image, since its disk size
> differs from the actual virtual disk size (writing a VM state does not
> actually increase the virtual disk size).
>
> Fix this by restoring total_sectors at the end of qcow2_save_vmstate.
>
> Signed-off-by: Max Reitz <mreitz@redhat.com>
> ---
> block/qcow2.c | 5 +++++
> 1 file changed, 5 insertions(+)
>
> @@ -1946,6 +1947,10 @@ static int qcow2_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov,
> bs->growable = 1;
> ret = bdrv_pwritev(bs, qcow2_vm_state_offset(s) + pos, qiov);
> bs->growable = growable;
> + // bdrv_co_do_writev will have increased the total_sectors value to include
> + // the VM state - the VM state is however not an actual part of the block
> + // device, therefore, we need to restore the old value.
> + bs->total_sectors = total_sectors;
It looks like // comments aren't forbidden, but also uncommon; I don't
know if /**/ would be better. At any rate:
Reviewed-by: Eric Blake <eblake@redhat.com>
--
Eric Blake eblake redhat com +1-919-301-3266
Libvirt virtualization library http://libvirt.org
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 621 bytes --]
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] qcow2: Restore total_sectors value in save_vmstate
2013-10-21 20:36 ` Eric Blake
@ 2013-10-23 17:03 ` Max Reitz
2013-10-24 9:52 ` Kevin Wolf
0 siblings, 1 reply; 4+ messages in thread
From: Max Reitz @ 2013-10-23 17:03 UTC (permalink / raw)
To: Eric Blake, qemu-devel; +Cc: Kevin Wolf, Stefan Hajnoczi
On 2013-10-21 22:36, Eric Blake wrote:
> On 10/20/2013 07:28 PM, Max Reitz wrote:
>> Since df2a6f29a5, bdrv_co_do_writev increases the total_sectors value of
>> a growable block devices on writes after the current end. This leads to
>> the virtual disk apparently growing in qcow2_save_vmstate, which in turn
>> affects the disk size captured by the internal snapshot taken directly
>> afterwards through e.g. the HMP savevm command. Such a "grown" snapshot
>> cannot be loaded after reopening the qcow2 image, since its disk size
>> differs from the actual virtual disk size (writing a VM state does not
>> actually increase the virtual disk size).
>>
>> Fix this by restoring total_sectors at the end of qcow2_save_vmstate.
>>
>> Signed-off-by: Max Reitz <mreitz@redhat.com>
>> ---
>> block/qcow2.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> @@ -1946,6 +1947,10 @@ static int qcow2_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov,
>> bs->growable = 1;
>> ret = bdrv_pwritev(bs, qcow2_vm_state_offset(s) + pos, qiov);
>> bs->growable = growable;
>> + // bdrv_co_do_writev will have increased the total_sectors value to include
>> + // the VM state - the VM state is however not an actual part of the block
>> + // device, therefore, we need to restore the old value.
>> + bs->total_sectors = total_sectors;
> It looks like // comments aren't forbidden, but also uncommon; I don't
> know if /**/ would be better. At any rate:
Ah, right, sorry, I forgot.
Max
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [Qemu-devel] [PATCH] qcow2: Restore total_sectors value in save_vmstate
2013-10-23 17:03 ` Max Reitz
@ 2013-10-24 9:52 ` Kevin Wolf
0 siblings, 0 replies; 4+ messages in thread
From: Kevin Wolf @ 2013-10-24 9:52 UTC (permalink / raw)
To: Max Reitz; +Cc: qemu-devel, Stefan Hajnoczi
Am 23.10.2013 um 19:03 hat Max Reitz geschrieben:
> On 2013-10-21 22:36, Eric Blake wrote:
> >On 10/20/2013 07:28 PM, Max Reitz wrote:
> >>Since df2a6f29a5, bdrv_co_do_writev increases the total_sectors value of
> >>a growable block devices on writes after the current end. This leads to
> >>the virtual disk apparently growing in qcow2_save_vmstate, which in turn
> >>affects the disk size captured by the internal snapshot taken directly
> >>afterwards through e.g. the HMP savevm command. Such a "grown" snapshot
> >>cannot be loaded after reopening the qcow2 image, since its disk size
> >>differs from the actual virtual disk size (writing a VM state does not
> >>actually increase the virtual disk size).
> >>
> >>Fix this by restoring total_sectors at the end of qcow2_save_vmstate.
> >>
> >>Signed-off-by: Max Reitz <mreitz@redhat.com>
> >>---
> >> block/qcow2.c | 5 +++++
> >> 1 file changed, 5 insertions(+)
> >>
> >>@@ -1946,6 +1947,10 @@ static int qcow2_save_vmstate(BlockDriverState *bs, QEMUIOVector *qiov,
> >> bs->growable = 1;
> >> ret = bdrv_pwritev(bs, qcow2_vm_state_offset(s) + pos, qiov);
> >> bs->growable = growable;
> >>+ // bdrv_co_do_writev will have increased the total_sectors value to include
> >>+ // the VM state - the VM state is however not an actual part of the block
> >>+ // device, therefore, we need to restore the old value.
> >>+ bs->total_sectors = total_sectors;
> >It looks like // comments aren't forbidden, but also uncommon; I don't
> >know if /**/ would be better. At any rate:
>
> Ah, right, sorry, I forgot.
Thanks, fixed up the command and applied to the block branch.
Kevin
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2013-10-24 9:52 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-20 18:28 [Qemu-devel] [PATCH] qcow2: Restore total_sectors value in save_vmstate Max Reitz
2013-10-21 20:36 ` Eric Blake
2013-10-23 17:03 ` Max Reitz
2013-10-24 9:52 ` Kevin Wolf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).