In general, we should only remove a backend after seeing DEVICE_DELETED
event for a corresponding frontend.
Signed-off-by: Jiri Denemark <jdenemar(a)redhat.com>
---
Notes:
Version 2:
- return int and propagate errors
src/qemu/qemu_hotplug.c | 33 ++++++++++++++++++++-------------
1 file changed, 20 insertions(+), 13 deletions(-)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 35099e4..fde46ad 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -2742,22 +2742,38 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
}
-static void
+static int
qemuDomainRemoveChrDevice(virQEMUDriverPtr driver,
virDomainObjPtr vm,
virDomainChrDefPtr chr)
{
virObjectEventPtr event;
+ char *charAlias = NULL;
+ qemuDomainObjPrivatePtr priv = vm->privateData;
VIR_DEBUG("Removing character device %s from domain %p %s",
chr->info.alias, vm, vm->def->name);
+ if (virAsprintf(&charAlias, "char%s", chr->info.alias) < 0)
+ return -1;
+
+ qemuDomainObjEnterMonitor(driver, vm);
+ if (qemuMonitorDetachCharDev(priv->mon, charAlias) < 0) {
+ qemuDomainObjExitMonitor(driver, vm);
+ goto cleanup;
+ }
+ qemuDomainObjExitMonitor(driver, vm);
+
event = virDomainEventDeviceRemovedNewFromObj(vm, chr->info.alias);
if (event)
qemuDomainEventQueue(driver, event);
qemuDomainChrRemove(vm->def, chr);
virDomainChrDefFree(chr);
+
+ cleanup:
+ VIR_FREE(charAlias);
+ return 0;
}
@@ -3595,7 +3611,6 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver,
qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainDefPtr vmdef = vm->def;
virDomainChrDefPtr tmpChr;
- char *charAlias = NULL;
char *devstr = NULL;
int rc;
@@ -3608,9 +3623,6 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver,
if (qemuBuildChrDeviceStr(&devstr, vm->def, chr, priv->qemuCaps) < 0)
return ret;
- if (virAsprintf(&charAlias, "char%s", tmpChr->info.alias) < 0)
- goto cleanup;
-
qemuDomainMarkDeviceForRemoval(vm, &tmpChr->info);
qemuDomainObjEnterMonitor(driver, vm);
@@ -3618,21 +3630,16 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver,
qemuDomainObjExitMonitor(driver, vm);
goto cleanup;
}
-
- if (qemuMonitorDetachCharDev(priv->mon, charAlias) < 0) {
- qemuDomainObjExitMonitor(driver, vm);
- goto cleanup;
- }
qemuDomainObjExitMonitor(driver, vm);
rc = qemuDomainWaitForDeviceRemoval(vm);
if (rc == 0 || rc == 1)
- qemuDomainRemoveChrDevice(driver, vm, tmpChr);
- ret = 0;
+ ret = qemuDomainRemoveChrDevice(driver, vm, tmpChr);
+ else
+ ret = 0;
cleanup:
qemuDomainResetDeviceRemoval(vm);
VIR_FREE(devstr);
- VIR_FREE(charAlias);
return ret;
}
--
2.0.0