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.
This commit is contained in:
Jiri Denemark 2010-03-23 09:34:19 +01:00
parent 284805e666
commit e455b221be
4 changed files with 55 additions and 11 deletions

View File

@ -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,

View File

@ -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;

View File

@ -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"));

View File

@ -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;