[libvirt] [PATCH v2 19/20] qemu: Store updated CPU in save cookie

Jiri Denemark jdenemar at redhat.com
Wed Jun 7 08:37:44 UTC 2017


Since the domain XML saved in a snapshot or saved image uses the
original guest CPU definition but we still want to enforce ABI when
restoring the domain if libvirt and QEMU are new enough, we save the
live updated CPU definition in a save cookie.

Signed-off-by: Jiri Denemark <jdenemar at redhat.com>
Reviewed-by: Pavel Hrdina <phrdina at redhat.com>
---

Notes:
    Version 2:
    - no change

 src/qemu/qemu_domain.c | 22 +++++++++++++++++++---
 src/qemu/qemu_domain.h |  2 ++
 2 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/src/qemu/qemu_domain.c b/src/qemu/qemu_domain.c
index 0da44f066..ec43d06d7 100644
--- a/src/qemu/qemu_domain.c
+++ b/src/qemu/qemu_domain.c
@@ -9167,12 +9167,15 @@ qemuDomainSaveCookieDispose(void *obj)
     qemuDomainSaveCookiePtr cookie = obj;
 
     VIR_DEBUG("cookie=%p", cookie);
+
+    virCPUDefFree(cookie->cpu);
 }
 
 
 qemuDomainSaveCookiePtr
 qemuDomainSaveCookieNew(virDomainObjPtr vm ATTRIBUTE_UNUSED)
 {
+    qemuDomainObjPrivatePtr priv = vm->privateData;
     qemuDomainSaveCookiePtr cookie = NULL;
 
     if (qemuDomainInitialize() < 0)
@@ -9181,7 +9184,10 @@ qemuDomainSaveCookieNew(virDomainObjPtr vm ATTRIBUTE_UNUSED)
     if (!(cookie = virObjectNew(qemuDomainSaveCookieClass)))
         goto error;
 
-    VIR_DEBUG("Save cookie %p", cookie);
+    if (priv->origCPU && !(cookie->cpu = virCPUDefCopy(vm->def->cpu)))
+        goto error;
+
+    VIR_DEBUG("Save cookie %p, cpu=%p", cookie, cookie->cpu);
 
     return cookie;
 
@@ -9203,6 +9209,10 @@ qemuDomainSaveCookieParse(xmlXPathContextPtr ctxt ATTRIBUTE_UNUSED,
     if (!(cookie = virObjectNew(qemuDomainSaveCookieClass)))
         goto error;
 
+    if (virCPUDefParseXML(ctxt, "./cpu[1]", VIR_CPU_TYPE_GUEST,
+                          &cookie->cpu) < 0)
+        goto error;
+
     *obj = (virObjectPtr) cookie;
     return 0;
 
@@ -9213,9 +9223,15 @@ qemuDomainSaveCookieParse(xmlXPathContextPtr ctxt ATTRIBUTE_UNUSED,
 
 
 static int
-qemuDomainSaveCookieFormat(virBufferPtr buf ATTRIBUTE_UNUSED,
-                           virObjectPtr obj ATTRIBUTE_UNUSED)
+qemuDomainSaveCookieFormat(virBufferPtr buf,
+                           virObjectPtr obj)
 {
+    qemuDomainSaveCookiePtr cookie = (qemuDomainSaveCookiePtr) obj;
+
+    if (cookie->cpu &&
+        virCPUDefFormatBufFull(buf, cookie->cpu, NULL, false) < 0)
+        return -1;
+
     return 0;
 }
 
diff --git a/src/qemu/qemu_domain.h b/src/qemu/qemu_domain.h
index 08c0b32f1..44c466cb7 100644
--- a/src/qemu/qemu_domain.h
+++ b/src/qemu/qemu_domain.h
@@ -424,6 +424,8 @@ typedef struct _qemuDomainSaveCookie qemuDomainSaveCookie;
 typedef qemuDomainSaveCookie *qemuDomainSaveCookiePtr;
 struct _qemuDomainSaveCookie {
     virObject parent;
+
+    virCPUDefPtr cpu;
 };
 
 qemuDomainSaveCookiePtr qemuDomainSaveCookieNew(virDomainObjPtr vm);
-- 
2.13.0




More information about the libvir-list mailing list