From: Jiri Denemark Date: Tue, 23 Mar 2010 08:34:19 +0000 (+0100) Subject: Introduce UPDATE_CPU flag for virDomainGetXMLDesc X-Git-Tag: v0.8.0~176 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e455b221be6a4518a793d9e7083544253f38261c;p=thirdparty%2Flibvirt.git Introduce UPDATE_CPU flag for virDomainGetXMLDesc This flag is used in migration prepare step to send updated XML definition of a guest. Also ``virsh dumpxml --update-cpu [--inactive] guest'' command can be used to see the updated CPU requirements. --- diff --git a/include/libvirt/libvirt.h.in b/include/libvirt/libvirt.h.in index fd32529299..6d8552f6ea 100644 --- a/include/libvirt/libvirt.h.in +++ b/include/libvirt/libvirt.h.in @@ -686,8 +686,9 @@ int virDomainGetSecurityLabel (virDomainPtr domain, */ typedef enum { - VIR_DOMAIN_XML_SECURE = 1, /* dump security sensitive information too */ - VIR_DOMAIN_XML_INACTIVE = 2/* dump inactive domain information */ + VIR_DOMAIN_XML_SECURE = (1 << 0), /* dump security sensitive information too */ + VIR_DOMAIN_XML_INACTIVE = (1 << 1), /* dump inactive domain information */ + VIR_DOMAIN_XML_UPDATE_CPU = (1 << 2), /* update guest CPU requirements according to host CPU */ } virDomainXMLFlags; char * virDomainGetXMLDesc (virDomainPtr domain, diff --git a/src/libvirt.c b/src/libvirt.c index 1ee299ab74..cc5b4c5e93 100644 --- a/src/libvirt.c +++ b/src/libvirt.c @@ -3256,7 +3256,8 @@ virDomainMigrateVersion2 (virDomainPtr domain, return NULL; } dom_xml = domain->conn->driver->domainDumpXML (domain, - VIR_DOMAIN_XML_SECURE); + VIR_DOMAIN_XML_SECURE | + VIR_DOMAIN_XML_UPDATE_CPU); if (!dom_xml) return NULL; diff --git a/src/qemu/qemu_driver.c b/src/qemu/qemu_driver.c index 6d76de697a..3df0398801 100644 --- a/src/qemu/qemu_driver.c +++ b/src/qemu/qemu_driver.c @@ -5596,6 +5596,44 @@ cleanup: } +static char *qemudVMDumpXML(struct qemud_driver *driver, + virDomainObjPtr vm, + int flags) +{ + char *ret = NULL; + virCPUDefPtr cpu = NULL; + virDomainDefPtr def; + virCPUDefPtr def_cpu; + + if ((flags & VIR_DOMAIN_XML_INACTIVE) && vm->newDef) + def = vm->newDef; + else + def = vm->def; + def_cpu = def->cpu; + + /* Update guest CPU requirements according to host CPU */ + if ((flags & VIR_DOMAIN_XML_UPDATE_CPU) && def_cpu && def_cpu->model) { + if (!driver->caps || !driver->caps->host.cpu) { + qemuReportError(VIR_ERR_OPERATION_FAILED, + "%s", _("cannot get host CPU capabilities")); + goto cleanup; + } + + if (!(cpu = virCPUDefCopy(def_cpu)) + || cpuUpdate(cpu, driver->caps->host.cpu)) + goto cleanup; + def->cpu = cpu; + } + + ret = virDomainDefFormat(def, flags); + +cleanup: + def->cpu = def_cpu; + virCPUDefFree(cpu); + return ret; +} + + static char *qemudDomainDumpXML(virDomainPtr dom, int flags) { struct qemud_driver *driver = dom->conn->privateData; @@ -5606,7 +5644,6 @@ static char *qemudDomainDumpXML(virDomainPtr dom, qemuDriverLock(driver); vm = virDomainFindByUUID(&driver->domains, dom->uuid); - qemuDriverUnlock(driver); if (!vm) { char uuidstr[VIR_UUID_STRING_BUFLEN]; @@ -5622,12 +5659,12 @@ static char *qemudDomainDumpXML(virDomainPtr dom, /* Don't delay if someone's using the monitor, just use * existing most recent data instead */ if (!priv->jobActive) { - if (qemuDomainObjBeginJob(vm) < 0) + if (qemuDomainObjBeginJobWithDriver(driver, vm) < 0) goto cleanup; - qemuDomainObjEnterMonitor(vm); + qemuDomainObjEnterMonitorWithDriver(driver, vm); err = qemuMonitorGetBalloonInfo(priv->mon, &balloon); - qemuDomainObjExitMonitor(vm); + qemuDomainObjExitMonitorWithDriver(driver, vm); if (qemuDomainObjEndJob(vm) == 0) { vm = NULL; goto cleanup; @@ -5640,13 +5677,12 @@ static char *qemudDomainDumpXML(virDomainPtr dom, } } - ret = virDomainDefFormat((flags & VIR_DOMAIN_XML_INACTIVE) && vm->newDef ? - vm->newDef : vm->def, - flags); + ret = qemudVMDumpXML(driver, vm, flags); cleanup: if (vm) virDomainObjUnlock(vm); + qemuDriverUnlock(driver); return ret; } @@ -9540,7 +9576,9 @@ static int doPeer2PeerMigrate(virDomainPtr dom, goto cleanup; } - dom_xml = virDomainDefFormat(vm->def, VIR_DOMAIN_XML_SECURE); + dom_xml = qemudVMDumpXML(driver, vm, + VIR_DOMAIN_XML_SECURE | + VIR_DOMAIN_XML_UPDATE_CPU); if (!dom_xml) { qemuReportError(VIR_ERR_OPERATION_FAILED, "%s", _("failed to get domain xml")); diff --git a/tools/virsh.c b/tools/virsh.c index c8ee1917ef..cfc4803c1a 100644 --- a/tools/virsh.c +++ b/tools/virsh.c @@ -2512,6 +2512,7 @@ static const vshCmdOptDef opts_dumpxml[] = { {"domain", VSH_OT_DATA, VSH_OFLAG_REQ, N_("domain name, id or uuid")}, {"inactive", VSH_OT_BOOL, 0, N_("show inactive defined XML")}, {"security-info", VSH_OT_BOOL, 0, N_("include security sensitive information in XML dump")}, + {"update-cpu", VSH_OT_BOOL, 0, N_("update guest CPU according to host CPU")}, {NULL, 0, 0, NULL} }; @@ -2524,11 +2525,14 @@ cmdDumpXML(vshControl *ctl, const vshCmd *cmd) int flags = 0; int inactive = vshCommandOptBool(cmd, "inactive"); int secure = vshCommandOptBool(cmd, "security-info"); + int update = vshCommandOptBool(cmd, "update-cpu"); if (inactive) flags |= VIR_DOMAIN_XML_INACTIVE; if (secure) flags |= VIR_DOMAIN_XML_SECURE; + if (update) + flags |= VIR_DOMAIN_XML_UPDATE_CPU; if (!vshConnectionUsability(ctl, ctl->conn, TRUE)) return FALSE;