Assign an address when hotplugging a virtio-serial device

This commit is contained in:
Ján Tomko 2015-03-02 10:59:52 +01:00
parent ee0d97a770
commit 89e991a2aa
2 changed files with 20 additions and 3 deletions

View File

@ -1541,6 +1541,8 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
virDomainDefPtr vmdef = vm->def;
char *devstr = NULL;
char *charAlias = NULL;
bool need_release = false;
bool allowZero = false;
if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
@ -1551,6 +1553,16 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
if (qemuAssignDeviceChrAlias(vmdef, chr, -1) < 0)
goto cleanup;
if (chr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CONSOLE &&
chr->targetType == VIR_DOMAIN_CHR_CONSOLE_TARGET_TYPE_VIRTIO)
allowZero = true;
if (virDomainVirtioSerialAddrAutoAssign(priv->vioserialaddrs,
&chr->info,
allowZero) < 0)
goto cleanup;
need_release = true;
if (qemuBuildChrDeviceStr(&devstr, vm->def, chr, priv->qemuCaps) < 0)
goto cleanup;
@ -1582,6 +1594,8 @@ int qemuDomainAttachChrDevice(virQEMUDriverPtr driver,
cleanup:
if (ret < 0 && virDomainObjIsActive(vm))
qemuDomainChrInsertPreAllocCleanup(vm->def, chr);
if (ret < 0 && need_release)
virDomainVirtioSerialAddrRelease(priv->vioserialaddrs, &chr->info);
VIR_FREE(charAlias);
VIR_FREE(devstr);
return ret;
@ -4120,10 +4134,13 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver,
goto cleanup;
rc = qemuDomainWaitForDeviceRemoval(vm);
if (rc == 0 || rc == 1)
if (rc == 0 || rc == 1) {
virDomainVirtioSerialAddrRelease(priv->vioserialaddrs, &tmpChr->info);
ret = qemuDomainRemoveChrDevice(driver, vm, tmpChr);
else
} else {
ret = 0;
}
cleanup:
qemuDomainResetDeviceRemoval(vm);

View File

@ -86,7 +86,7 @@ qemuHotplugCreateObjects(virDomainXMLOptionPtr xmlopt,
if (event)
virQEMUCapsSet(priv->qemuCaps, QEMU_CAPS_DEVICE_DEL_EVENT);
if (qemuDomainAssignPCIAddresses((*vm)->def, priv->qemuCaps, *vm) < 0)
if (qemuDomainAssignAddresses((*vm)->def, priv->qemuCaps, *vm) < 0)
goto cleanup;
if (qemuAssignDeviceAliases((*vm)->def, priv->qemuCaps) < 0)