qemu: Store updated CPU in save cookie

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@redhat.com>
Reviewed-by: Pavel Hrdina <phrdina@redhat.com>
This commit is contained in:
Jiri Denemark 2017-06-02 22:52:03 +02:00
parent 48bc3053b8
commit 8c19fbf452
2 changed files with 21 additions and 3 deletions

View File

@ -9167,12 +9167,15 @@ qemuDomainSaveCookieDispose(void *obj)
qemuDomainSaveCookiePtr cookie = obj; qemuDomainSaveCookiePtr cookie = obj;
VIR_DEBUG("cookie=%p", cookie); VIR_DEBUG("cookie=%p", cookie);
virCPUDefFree(cookie->cpu);
} }
qemuDomainSaveCookiePtr qemuDomainSaveCookiePtr
qemuDomainSaveCookieNew(virDomainObjPtr vm ATTRIBUTE_UNUSED) qemuDomainSaveCookieNew(virDomainObjPtr vm ATTRIBUTE_UNUSED)
{ {
qemuDomainObjPrivatePtr priv = vm->privateData;
qemuDomainSaveCookiePtr cookie = NULL; qemuDomainSaveCookiePtr cookie = NULL;
if (qemuDomainInitialize() < 0) if (qemuDomainInitialize() < 0)
@ -9181,7 +9184,10 @@ qemuDomainSaveCookieNew(virDomainObjPtr vm ATTRIBUTE_UNUSED)
if (!(cookie = virObjectNew(qemuDomainSaveCookieClass))) if (!(cookie = virObjectNew(qemuDomainSaveCookieClass)))
goto error; 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; return cookie;
@ -9203,6 +9209,10 @@ qemuDomainSaveCookieParse(xmlXPathContextPtr ctxt ATTRIBUTE_UNUSED,
if (!(cookie = virObjectNew(qemuDomainSaveCookieClass))) if (!(cookie = virObjectNew(qemuDomainSaveCookieClass)))
goto error; goto error;
if (virCPUDefParseXML(ctxt, "./cpu[1]", VIR_CPU_TYPE_GUEST,
&cookie->cpu) < 0)
goto error;
*obj = (virObjectPtr) cookie; *obj = (virObjectPtr) cookie;
return 0; return 0;
@ -9213,9 +9223,15 @@ qemuDomainSaveCookieParse(xmlXPathContextPtr ctxt ATTRIBUTE_UNUSED,
static int static int
qemuDomainSaveCookieFormat(virBufferPtr buf ATTRIBUTE_UNUSED, qemuDomainSaveCookieFormat(virBufferPtr buf,
virObjectPtr obj ATTRIBUTE_UNUSED) virObjectPtr obj)
{ {
qemuDomainSaveCookiePtr cookie = (qemuDomainSaveCookiePtr) obj;
if (cookie->cpu &&
virCPUDefFormatBufFull(buf, cookie->cpu, NULL, false) < 0)
return -1;
return 0; return 0;
} }

View File

@ -424,6 +424,8 @@ typedef struct _qemuDomainSaveCookie qemuDomainSaveCookie;
typedef qemuDomainSaveCookie *qemuDomainSaveCookiePtr; typedef qemuDomainSaveCookie *qemuDomainSaveCookiePtr;
struct _qemuDomainSaveCookie { struct _qemuDomainSaveCookie {
virObject parent; virObject parent;
virCPUDefPtr cpu;
}; };
qemuDomainSaveCookiePtr qemuDomainSaveCookieNew(virDomainObjPtr vm); qemuDomainSaveCookiePtr qemuDomainSaveCookieNew(virDomainObjPtr vm);