---
src/qemu/qemu_hotplug.c | 21 +++++++++++++++++++--
tests/qemuhotplugtest.c | 2 +-
2 files changed, 20 insertions(+), 3 deletions(-)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index ef2f9b0..560a164 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -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);
diff --git a/tests/qemuhotplugtest.c b/tests/qemuhotplugtest.c
index 12a7f71..ea2cf77 100644
--- a/tests/qemuhotplugtest.c
+++ b/tests/qemuhotplugtest.c
@@ -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)
--
2.0.5