}
/* Returns:
- * 0 when DEVICE_DELETED event is unsupported, or we failed to reliably wait
- * for the event
- * 1 when DEVICE_DELETED arrived before the timeout and the caller is
- * responsible for finishing the removal
- * 2 device removal did not finish in qemuDomainRemoveDeviceWaitTime
+ * 0 DEVICE_DELETED event is supported and removal of the device did not
+ * finish in qemuDomainRemoveDeviceWaitTime
+ *
+ * 1 when the caller is responsible for finishing the device removal:
+ * - DEVICE_DELETED event is unsupported
+ * - DEVICE_DELETED event arrived before the timeout time
+ * - we failed to reliably wait for the event and thus use fallback behavior
*/
static int
qemuDomainWaitForDeviceRemoval(virDomainObjPtr vm)
unsigned long long until;
if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE_DEL_EVENT))
- return 0;
+ return 1;
if (virTimeMillisNow(&until) < 0)
- return 0;
+ return 1;
until += qemuDomainRemoveDeviceWaitTime;
while (priv->unpluggingDevice) {
if (virCondWaitUntil(&priv->unplugFinished,
&vm->parent.lock, until) < 0) {
if (errno == ETIMEDOUT) {
- return 2;
+ return 0;
} else {
VIR_WARN("Failed to wait on unplug condition for domain '%s' "
"device '%s'", vm->def->name, priv->unpluggingDevice);
- return 0;
+ return 1;
}
}
}
{
int ret = -1;
qemuDomainObjPrivatePtr priv = vm->privateData;
- int rc;
if (qemuIsMultiFunctionDevice(vm->def, &detach->info)) {
virReportError(VIR_ERR_OPERATION_FAILED,
if (qemuDomainObjExitMonitor(driver, vm) < 0)
goto cleanup;
- rc = qemuDomainWaitForDeviceRemoval(vm);
- if (rc == 0 || rc == 1)
+ if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1)
ret = qemuDomainRemoveDiskDevice(driver, vm, detach);
- else
- ret = 0;
cleanup:
qemuDomainResetDeviceRemoval(vm);
{
int ret = -1;
qemuDomainObjPrivatePtr priv = vm->privateData;
- int rc;
if (!virQEMUCapsGet(priv->qemuCaps, QEMU_CAPS_DEVICE)) {
virReportError(VIR_ERR_OPERATION_FAILED,
if (qemuDomainObjExitMonitor(driver, vm) < 0)
goto cleanup;
- rc = qemuDomainWaitForDeviceRemoval(vm);
- if (rc == 0 || rc == 1)
+ if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1)
ret = qemuDomainRemoveDiskDevice(driver, vm, detach);
- else
- ret = 0;
cleanup:
qemuDomainResetDeviceRemoval(vm);
int idx, ret = -1;
virDomainControllerDefPtr detach = NULL;
qemuDomainObjPrivatePtr priv = vm->privateData;
- int rc;
if ((idx = virDomainControllerFind(vm->def,
dev->data.controller->type,
if (qemuDomainObjExitMonitor(driver, vm) < 0)
goto cleanup;
- rc = qemuDomainWaitForDeviceRemoval(vm);
- if (rc == 0 || rc == 1)
+ if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1)
ret = qemuDomainRemoveControllerDevice(driver, vm, detach);
- else
- ret = 0;
cleanup:
qemuDomainResetDeviceRemoval(vm);
if (ret < 0) {
if (virDomainObjIsActive(vm))
virDomainAuditHostdev(vm, detach, "detach", false);
- } else {
- int rc = qemuDomainWaitForDeviceRemoval(vm);
- if (rc == 0 || rc == 1)
- ret = qemuDomainRemoveHostDevice(driver, vm, detach);
+ } else if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1) {
+ ret = qemuDomainRemoveHostDevice(driver, vm, detach);
}
qemuDomainResetDeviceRemoval(vm);
int detachidx, ret = -1;
virDomainNetDefPtr detach = NULL;
qemuDomainObjPrivatePtr priv = vm->privateData;
- int rc;
if ((detachidx = virDomainNetFindIdx(vm->def, dev->data.net)) < 0)
goto cleanup;
if (qemuDomainObjExitMonitor(driver, vm) < 0)
goto cleanup;
- rc = qemuDomainWaitForDeviceRemoval(vm);
- if (rc == 0 || rc == 1)
+ if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1)
ret = qemuDomainRemoveNetDevice(driver, vm, detach);
- else
- ret = 0;
cleanup:
qemuDomainResetDeviceRemoval(vm);
virDomainDefPtr vmdef = vm->def;
virDomainChrDefPtr tmpChr;
char *devstr = NULL;
- int rc;
if (!(tmpChr = virDomainChrFind(vmdef, chr))) {
virReportError(VIR_ERR_OPERATION_INVALID, "%s",
if (qemuDomainObjExitMonitor(driver, vm) < 0)
goto cleanup;
- rc = qemuDomainWaitForDeviceRemoval(vm);
- if (rc == 0 || rc == 1) {
+ if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1) {
qemuDomainReleaseDeviceAddress(vm, &tmpChr->info, NULL);
ret = qemuDomainRemoveChrDevice(driver, vm, tmpChr);
- } else {
- ret = 0;
}
-
cleanup:
qemuDomainResetDeviceRemoval(vm);
VIR_FREE(devstr);
if (qemuDomainObjExitMonitor(driver, vm) || rc < 0)
goto cleanup;
- rc = qemuDomainWaitForDeviceRemoval(vm);
- if (rc == 0 || rc == 1)
+ if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1)
ret = qemuDomainRemoveRNGDevice(driver, vm, tmpRNG);
- else
- ret = 0;
cleanup:
qemuDomainResetDeviceRemoval(vm);
if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
goto cleanup;
- rc = qemuDomainWaitForDeviceRemoval(vm);
- if (rc == 0 || rc == 1)
+ if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1)
ret = qemuDomainRemoveMemoryDevice(driver, vm, mem);
- else
- ret = 0;
cleanup:
qemuDomainResetDeviceRemoval(vm);