qemu: Fix (managed)save and snapshots with host mode CPU

When host-model and host-passthrouh CPU modes were introduced, qemu
driver was properly modify to update guest CPU definition during
migration so that we use the right CPU at the destination. However,
similar treatment is needed for (managed)save and snapshots since they
need to save the exact CPU so that a domain can be properly restored.
To avoid repetition of such situation, all places that need live XML
share the code which generates it.

As a side effect, this patch fixes error reporting from
qemuDomainSnapshotWriteMetadata().
This commit is contained in:
Jiri Denemark 2012-03-09 16:42:46 +01:00
parent 98deac7dcc
commit 041109afef
5 changed files with 30 additions and 17 deletions

View File

@ -13561,7 +13561,8 @@ char *virDomainSnapshotDefFormat(const char *domain_uuid,
virBuffer buf = VIR_BUFFER_INITIALIZER;
int i;
virCheckFlags(VIR_DOMAIN_XML_SECURE, NULL);
virCheckFlags(VIR_DOMAIN_XML_SECURE |
VIR_DOMAIN_XML_UPDATE_CPU, NULL);
flags |= VIR_DOMAIN_XML_INACTIVE;

View File

@ -47,6 +47,10 @@
#define QEMU_NAMESPACE_HREF "http://libvirt.org/schemas/domain/qemu/1.0"
#define QEMU_DOMAIN_FORMAT_LIVE_FLAGS \
(VIR_DOMAIN_XML_SECURE | \
VIR_DOMAIN_XML_UPDATE_CPU)
VIR_ENUM_DECL(qemuDomainJob)
VIR_ENUM_IMPL(qemuDomainJob, QEMU_JOB_LAST,
"none",
@ -1192,6 +1196,19 @@ char *qemuDomainFormatXML(struct qemud_driver *driver,
return qemuDomainDefFormatXML(driver, def, flags);
}
char *
qemuDomainDefFormatLive(struct qemud_driver *driver,
virDomainDefPtr def,
bool inactive)
{
unsigned int flags = QEMU_DOMAIN_FORMAT_LIVE_FLAGS;
if (inactive)
flags |= VIR_DOMAIN_XML_INACTIVE;
return qemuDomainDefFormatXML(driver, def, flags);
}
void qemuDomainObjTaint(struct qemud_driver *driver,
virDomainObjPtr obj,
@ -1436,11 +1453,9 @@ qemuDomainSnapshotWriteMetadata(virDomainObjPtr vm,
virUUIDFormat(vm->def->uuid, uuidstr);
newxml = virDomainSnapshotDefFormat(uuidstr, snapshot->def,
VIR_DOMAIN_XML_SECURE, 1);
if (newxml == NULL) {
virReportOOMError();
QEMU_DOMAIN_FORMAT_LIVE_FLAGS, 1);
if (newxml == NULL)
return -1;
}
if (virAsprintf(&snapDir, "%s/%s", snapshotDir, vm->def->name) < 0) {
virReportOOMError();

View File

@ -232,6 +232,10 @@ char *qemuDomainFormatXML(struct qemud_driver *driver,
virDomainObjPtr vm,
unsigned int flags);
char *qemuDomainDefFormatLive(struct qemud_driver *driver,
virDomainDefPtr def,
bool inactive);
void qemuDomainObjTaint(struct qemud_driver *driver,
virDomainObjPtr obj,
enum virDomainTaintFlags taint,

View File

@ -2587,11 +2587,9 @@ qemuDomainSaveInternal(struct qemud_driver *driver, virDomainPtr dom,
virDomainDefFree(def);
goto endjob;
}
xml = virDomainDefFormat(def, (VIR_DOMAIN_XML_INACTIVE |
VIR_DOMAIN_XML_SECURE));
xml = qemuDomainDefFormatLive(driver, def, true);
} else {
xml = virDomainDefFormat(vm->def, (VIR_DOMAIN_XML_INACTIVE |
VIR_DOMAIN_XML_SECURE));
xml = qemuDomainDefFormatLive(driver, vm->def, true);
}
if (!xml) {
qemuReportError(VIR_ERR_OPERATION_FAILED,
@ -10173,8 +10171,7 @@ qemuDomainSnapshotCreateXML(virDomainPtr domain,
} else {
/* Easiest way to clone inactive portion of vm->def is via
* conversion in and back out of xml. */
if (!(xml = virDomainDefFormat(vm->def, (VIR_DOMAIN_XML_INACTIVE |
VIR_DOMAIN_XML_SECURE))) ||
if (!(xml = qemuDomainDefFormatLive(driver, vm->def, true)) ||
!(def->dom = virDomainDefParseString(driver->caps, xml,
QEMU_EXPECTED_VIRT_TYPES,
VIR_DOMAIN_XML_INACTIVE)))

View File

@ -1092,13 +1092,9 @@ char *qemuMigrationBegin(struct qemud_driver *driver,
if (!virDomainDefCheckABIStability(vm->def, def))
goto cleanup;
rv = qemuDomainDefFormatXML(driver, def,
VIR_DOMAIN_XML_SECURE |
VIR_DOMAIN_XML_UPDATE_CPU);
rv = qemuDomainDefFormatLive(driver, def, false);
} else {
rv = qemuDomainFormatXML(driver, vm,
VIR_DOMAIN_XML_SECURE |
VIR_DOMAIN_XML_UPDATE_CPU);
rv = qemuDomainDefFormatLive(driver, vm->def, false);
}
cleanup: