[libvirt PATCH] qemu: re-add padding to the saved state images

Daniel P. Berrangé posted 1 patch 3 years, 11 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/libvirt tags/patchew/20200427134147.1369948-1-berrange@redhat.com
Test syntax-check failed
src/qemu/qemu_driver.c | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
[libvirt PATCH] qemu: re-add padding to the saved state images
Posted by Daniel P. Berrangé 3 years, 11 months ago
In the past we added 1024 bytes of padding to saved state images so that
users can run "virsh managedsave-edit $GUEST" and make XML changes which
increase the size of the XML document. This padding was accidentally
lost a while back

  commit 6b9b21db7079888a05d192b079e68290bdf14a76
  Author: Peter Krempa <pkrempa@redhat.com>
  Date:   Wed Feb 17 13:10:11 2016 +0100

    qemu: Remove unnecessary calculations in qemuDomainSaveMemory

The original 1024 bytes was unreasonably stingy when we consider that
the QEMU state is typically going to be many 100's of MB in size. Thus
this adds 64 KB of padding after the XML which should cope with any
plausible modifications a user will want to make.

Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
---
 src/qemu/qemu_driver.c | 17 ++++++++++-------
 1 file changed, 10 insertions(+), 7 deletions(-)

diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c
index 01330e55e7..d5aeeac66d 100644
--- a/src/qemu/qemu_driver.c
+++ b/src/qemu/qemu_driver.c
@@ -2922,20 +2922,23 @@ virQEMUSaveDataWrite(virQEMUSaveDataPtr data,
 
     len = xml_len + cookie_len;
 
-    if (header->data_len > 0) {
+    if (header->data_len == 0) {
+        /* This 64kb padding allows the user to edit the XML in
+         * a saved state image and have the new XML be larger
+         * that what was originally saved
+         */
+        header->data_len = len + (64 * 1024);
+    } else {
         if (len > header->data_len) {
             virReportError(VIR_ERR_OPERATION_FAILED, "%s",
                            _("new xml too large to fit in file"));
             return -1;
         }
-
-        zerosLen = header->data_len - len;
-        if (VIR_ALLOC_N(zeros, zerosLen) < 0)
-            return -1;
-    } else {
-        header->data_len = len;
     }
 
+    zerosLen = header->data_len - len;
+    zeros = g_new0(char, zerosLen);
+
     if (data->cookie)
         header->cookieOffset = xml_len;
 
-- 
2.25.3

Re: [libvirt PATCH] qemu: re-add padding to the saved state images
Posted by Eric Blake 3 years, 11 months ago
On 4/27/20 8:41 AM, Daniel P. Berrangé wrote:
> In the past we added 1024 bytes of padding to saved state images so that
> users can run "virsh managedsave-edit $GUEST" and make XML changes which
> increase the size of the XML document. This padding was accidentally
> lost a while back
> 
>    commit 6b9b21db7079888a05d192b079e68290bdf14a76
>    Author: Peter Krempa <pkrempa@redhat.com>
>    Date:   Wed Feb 17 13:10:11 2016 +0100
> 
>      qemu: Remove unnecessary calculations in qemuDomainSaveMemory
> 
> The original 1024 bytes was unreasonably stingy when we consider that
> the QEMU state is typically going to be many 100's of MB in size. Thus
> this adds 64 KB of padding after the XML which should cope with any
> plausible modifications a user will want to make.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>   src/qemu/qemu_driver.c | 17 ++++++++++-------
>   1 file changed, 10 insertions(+), 7 deletions(-)

Reviewed-by: Eric Blake <eblake@redhat.com>

-- 
Eric Blake, Principal Software Engineer
Red Hat, Inc.           +1-919-301-3226
Virtualization:  qemu.org | libvirt.org

Re: [libvirt PATCH] qemu: re-add padding to the saved state images
Posted by Andrea Bolognani 3 years, 11 months ago
On Mon, 2020-04-27 at 14:41 +0100, Daniel P. Berrangé wrote:
> In the past we added 1024 bytes of padding to saved state images so that
> users can run "virsh managedsave-edit $GUEST" and make XML changes which
> increase the size of the XML document. This padding was accidentally
> lost a while back
> 
>   commit 6b9b21db7079888a05d192b079e68290bdf14a76
>   Author: Peter Krempa <pkrempa@redhat.com>
>   Date:   Wed Feb 17 13:10:11 2016 +0100
> 
>     qemu: Remove unnecessary calculations in qemuDomainSaveMemory
> 
> The original 1024 bytes was unreasonably stingy when we consider that
> the QEMU state is typically going to be many 100's of MB in size. Thus
> this adds 64 KB of padding after the XML which should cope with any
> plausible modifications a user will want to make.
> 
> Signed-off-by: Daniel P. Berrangé <berrange@redhat.com>
> ---
>  src/qemu/qemu_driver.c | 17 ++++++++++-------
>  1 file changed, 10 insertions(+), 7 deletions(-)

Please consider including a link to

  https://bugzilla.redhat.com/show_bug.cgi?id=1229255

in the commit message.

-- 
Andrea Bolognani / Red Hat / Virtualization