The aim of this function will be to fix return value of
qemuMonitorDelDevice() in one specific case. But that is yet to
come. Right now this is nothing but a plain substitution.
Signed-off-by: Michal Privoznik <mprivozn(a)redhat.com>
---
src/qemu/qemu_hotplug.c | 278 +++++++++++++++-------------------------
1 file changed, 103 insertions(+), 175 deletions(-)
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index f43f80668c..baa4713cf4 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -67,6 +67,44 @@ VIR_LOG_INIT("qemu.qemu_hotplug");
unsigned long long qemuDomainRemoveDeviceWaitTime = 1000ull * 5;
+/**
+ * qemuDomainDeleteDevice:
+ * @vm: domain object
+ * @alias: device to remove
+ * @enterMonitor: whether do EnterMonitor/ExitMonitor too
+ *
+ * This is a wrapper over qemuMonitorDelDevice() plus
+ * (optionally) enter/exit monitor calls. This function MUST be
+ * used instead of plain qemuMonitorDelDevice().
+ *
+ * If @enterMonitor is true then the function expects @vm to be
+ * locked upon entry.
+ *
+ * Returns: 0 on success,
+ * -1 otherwise.
+ */
+static int
+qemuDomainDeleteDevice(virDomainObjPtr vm,
+ const char *alias,
+ bool enterMonitor)
+{
+ qemuDomainObjPrivatePtr priv = vm->privateData;
+ virQEMUDriverPtr driver = priv->driver;
+ int rc;
+
+ if (enterMonitor)
+ qemuDomainObjEnterMonitor(driver, vm);
+
+ rc = qemuMonitorDelDevice(priv->mon, alias);
+
+ if (enterMonitor &&
+ qemuDomainObjExitMonitor(driver, vm) < 0)
+ rc = -1;
+
+ return rc;
+}
+
+
/**
* qemuHotplugPrepareDiskSourceAccess:
* @driver: qemu driver struct
@@ -158,7 +196,7 @@ qemuDomainAttachZPCIDevice(qemuMonitorPtr mon,
static int
-qemuDomainDetachZPCIDevice(qemuMonitorPtr mon,
+qemuDomainDetachZPCIDevice(virDomainObjPtr vm,
virDomainDeviceInfoPtr info)
{
char *zpciAlias = NULL;
@@ -167,7 +205,7 @@ qemuDomainDetachZPCIDevice(qemuMonitorPtr mon,
if (virAsprintf(&zpciAlias, "zpci%d", info->addr.pci.zpci.uid) <
0)
goto cleanup;
- if (qemuMonitorDelDevice(mon, zpciAlias) < 0)
+ if (qemuDomainDeleteDevice(vm, zpciAlias, false) < 0)
goto cleanup;
ret = 0;
@@ -195,7 +233,7 @@ qemuDomainAttachExtensionDevice(qemuMonitorPtr mon,
static int
-qemuDomainDetachExtensionDevice(qemuMonitorPtr mon,
+qemuDomainDetachExtensionDevice(virDomainObjPtr vm,
virDomainDeviceInfoPtr info)
{
if (info->type != VIR_DOMAIN_DEVICE_ADDRESS_TYPE_PCI ||
@@ -204,7 +242,7 @@ qemuDomainDetachExtensionDevice(qemuMonitorPtr mon,
}
if (info->addr.pci.extFlags & VIR_PCI_ADDRESS_EXTENSION_ZPCI)
- return qemuDomainDetachZPCIDevice(mon, info);
+ return qemuDomainDetachZPCIDevice(vm, info);
return 0;
}
@@ -904,7 +942,7 @@ qemuDomainAttachDiskGeneric(virQEMUDriverPtr driver,
goto exit_monitor;
if (qemuMonitorAddDevice(priv->mon, devstr) < 0) {
- ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &disk->info));
+ ignore_value(qemuDomainDetachExtensionDevice(vm, &disk->info));
goto exit_monitor;
}
@@ -1021,7 +1059,7 @@ int qemuDomainAttachControllerDevice(virQEMUDriverPtr driver,
}
if ((ret = qemuMonitorAddDevice(priv->mon, devstr)) < 0)
- ignore_value(qemuDomainDetachExtensionDevice(priv->mon,
&controller->info));
+ ignore_value(qemuDomainDetachExtensionDevice(vm, &controller->info));
exit_monitor:
if (qemuDomainObjExitMonitor(driver, vm) < 0) {
@@ -1564,7 +1602,7 @@ qemuDomainAttachNetDevice(virQEMUDriverPtr driver,
}
if (qemuMonitorAddDevice(priv->mon, nicstr) < 0) {
- ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &net->info));
+ ignore_value(qemuDomainDetachExtensionDevice(vm, &net->info));
ignore_value(qemuDomainObjExitMonitor(driver, vm));
virDomainAuditNet(vm, NULL, net, "attach", false);
goto try_remove;
@@ -1787,7 +1825,7 @@ qemuDomainAttachHostPCIDevice(virQEMUDriverPtr driver,
if ((ret = qemuMonitorAddDeviceWithFd(priv->mon, devstr,
configfd, configfd_name)) < 0) {
- ignore_value(qemuDomainDetachExtensionDevice(priv->mon, hostdev->info));
+ ignore_value(qemuDomainDetachExtensionDevice(vm, hostdev->info));
}
exit_monitor:
@@ -2460,7 +2498,7 @@ qemuDomainAttachRNGDevice(virQEMUDriverPtr driver,
goto exit_monitor;
if (qemuMonitorAddDevice(priv->mon, devstr) < 0) {
- ignore_value(qemuDomainDetachExtensionDevice(priv->mon, &rng->info));
+ ignore_value(qemuDomainDetachExtensionDevice(vm, &rng->info));
goto exit_monitor;
}
@@ -2948,7 +2986,7 @@ qemuDomainAttachSCSIVHostDevice(virQEMUDriverPtr driver,
if ((ret = qemuMonitorAddDeviceWithFd(priv->mon, devstr, vhostfd,
vhostfdName)) < 0) {
- ignore_value(qemuDomainDetachExtensionDevice(priv->mon, hostdev->info));
+ ignore_value(qemuDomainDetachExtensionDevice(vm, hostdev->info));
goto exit_monitor;
}
@@ -3201,7 +3239,7 @@ qemuDomainAttachShmemDevice(virQEMUDriverPtr driver,
goto exit_monitor;
if (qemuMonitorAddDevice(priv->mon, shmstr) < 0) {
- ignore_value(qemuDomainDetachExtensionDevice(priv->mon,
&shmem->info));
+ ignore_value(qemuDomainDetachExtensionDevice(vm, &shmem->info));
goto exit_monitor;
}
@@ -3381,7 +3419,7 @@ qemuDomainAttachInputDevice(virQEMUDriverPtr driver,
goto exit_monitor;
if (qemuMonitorAddDevice(priv->mon, devstr) < 0) {
- ignore_value(qemuDomainDetachExtensionDevice(priv->mon,
&input->info));
+ ignore_value(qemuDomainDetachExtensionDevice(vm, &input->info));
goto exit_monitor;
}
@@ -3466,7 +3504,7 @@ qemuDomainAttachVsockDevice(virQEMUDriverPtr driver,
goto exit_monitor;
if (qemuMonitorAddDeviceWithFd(priv->mon, devstr, vsockPriv->vhostfd, fdname)
< 0) {
- ignore_value(qemuDomainDetachExtensionDevice(priv->mon,
&vsock->info));
+ ignore_value(qemuDomainDetachExtensionDevice(vm, &vsock->info));
goto exit_monitor;
}
@@ -4819,7 +4857,7 @@ qemuDomainRemoveRNGDevice(virQEMUDriverPtr driver,
qemuDomainObjEnterMonitor(driver, vm);
- if (qemuDomainDetachExtensionDevice(priv->mon, &rng->info) < 0)
+ if (qemuDomainDetachExtensionDevice(vm, &rng->info) < 0)
rc = -1;
if (rc == 0 &&
@@ -5216,7 +5254,6 @@ qemuDomainDetachVirtioDiskDevice(virQEMUDriverPtr driver,
bool async)
{
int ret = -1;
- qemuDomainObjPrivatePtr priv = vm->privateData;
if (qemuIsMultiFunctionDevice(vm->def, &detach->info)) {
virReportError(VIR_ERR_OPERATION_FAILED,
@@ -5228,15 +5265,11 @@ qemuDomainDetachVirtioDiskDevice(virQEMUDriverPtr driver,
if (!async)
qemuDomainMarkDeviceForRemoval(vm, &detach->info);
- qemuDomainObjEnterMonitor(driver, vm);
- if (qemuMonitorDelDevice(priv->mon, detach->info.alias) < 0) {
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
- goto cleanup;
- virDomainAuditDisk(vm, detach->src, NULL, "detach", false);
+ if (qemuDomainDeleteDevice(vm, detach->info.alias, true) < 0) {
+ if (virDomainObjIsActive(vm))
+ virDomainAuditDisk(vm, detach->src, NULL, "detach", false);
goto cleanup;
}
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
- goto cleanup;
if (async) {
ret = 0;
@@ -5258,7 +5291,6 @@ qemuDomainDetachDiskDevice(virQEMUDriverPtr driver,
bool async)
{
int ret = -1;
- qemuDomainObjPrivatePtr priv = vm->privateData;
if (qemuDomainDiskBlockJobIsActive(detach))
goto cleanup;
@@ -5266,15 +5298,11 @@ qemuDomainDetachDiskDevice(virQEMUDriverPtr driver,
if (!async)
qemuDomainMarkDeviceForRemoval(vm, &detach->info);
- qemuDomainObjEnterMonitor(driver, vm);
- if (qemuMonitorDelDevice(priv->mon, detach->info.alias) < 0) {
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
- goto cleanup;
- virDomainAuditDisk(vm, detach->src, NULL, "detach", false);
+ if (qemuDomainDeleteDevice(vm, detach->info.alias, true) < 0) {
+ if (virDomainObjIsActive(vm))
+ virDomainAuditDisk(vm, detach->src, NULL, "detach", false);
goto cleanup;
}
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
- goto cleanup;
if (async) {
ret = 0;
@@ -5409,7 +5437,6 @@ int qemuDomainDetachControllerDevice(virQEMUDriverPtr driver,
{
int idx, ret = -1;
virDomainControllerDefPtr detach = NULL;
- qemuDomainObjPrivatePtr priv = vm->privateData;
if ((idx = virDomainControllerFind(vm->def,
dev->data.controller->type,
@@ -5455,19 +5482,18 @@ int qemuDomainDetachControllerDevice(virQEMUDriverPtr driver,
if (!async)
qemuDomainMarkDeviceForRemoval(vm, &detach->info);
- qemuDomainObjEnterMonitor(driver, vm);
- if (detach->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI &&
- qemuDomainDetachExtensionDevice(priv->mon, &detach->info) < 0) {
- goto exit_monitor;
- }
+ if (detach->type == VIR_DOMAIN_CONTROLLER_TYPE_PCI) {
+ int rc;
+ qemuDomainObjEnterMonitor(driver, vm);
+ rc = qemuDomainDetachExtensionDevice(vm, &detach->info);
+ if (qemuDomainObjExitMonitor(driver, vm) < 0)
+ rc = -1;
- if (qemuMonitorDelDevice(priv->mon, detach->info.alias) < 0) {
- ignore_value(qemuDomainObjExitMonitor(driver, vm));
- goto cleanup;
+ if (rc < 0)
+ goto cleanup;
}
- exit_monitor:
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
+ if (qemuDomainDeleteDevice(vm, detach->info.alias, true) < 0)
goto cleanup;
if (async) {
@@ -5484,14 +5510,11 @@ int qemuDomainDetachControllerDevice(virQEMUDriverPtr driver,
}
static int
-qemuDomainDetachHostPCIDevice(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
+qemuDomainDetachHostPCIDevice(virDomainObjPtr vm,
virDomainHostdevDefPtr detach,
bool async)
{
- qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainHostdevSubsysPCIPtr pcisrc = &detach->source.subsys.u.pci;
- int ret;
if (qemuIsMultiFunctionDevice(vm->def, detach->info)) {
virReportError(VIR_ERR_OPERATION_FAILED,
@@ -5504,23 +5527,14 @@ qemuDomainDetachHostPCIDevice(virQEMUDriverPtr driver,
if (!async)
qemuDomainMarkDeviceForRemoval(vm, detach->info);
- qemuDomainObjEnterMonitor(driver, vm);
- ret = qemuMonitorDelDevice(priv->mon, detach->info->alias);
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
- ret = -1;
-
- return ret;
+ return qemuDomainDeleteDevice(vm, detach->info->alias, true);
}
static int
-qemuDomainDetachHostUSBDevice(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
+qemuDomainDetachHostUSBDevice(virDomainObjPtr vm,
virDomainHostdevDefPtr detach,
bool async)
{
- qemuDomainObjPrivatePtr priv = vm->privateData;
- int ret;
-
if (!detach->info->alias) {
virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("device cannot be detached without a device
alias"));
@@ -5530,23 +5544,14 @@ qemuDomainDetachHostUSBDevice(virQEMUDriverPtr driver,
if (!async)
qemuDomainMarkDeviceForRemoval(vm, detach->info);
- qemuDomainObjEnterMonitor(driver, vm);
- ret = qemuMonitorDelDevice(priv->mon, detach->info->alias);
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
- ret = -1;
-
- return ret;
+ return qemuDomainDeleteDevice(vm, detach->info->alias, true);
}
static int
-qemuDomainDetachHostSCSIDevice(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
+qemuDomainDetachHostSCSIDevice(virDomainObjPtr vm,
virDomainHostdevDefPtr detach,
bool async)
{
- qemuDomainObjPrivatePtr priv = vm->privateData;
- int ret = -1;
-
if (!detach->info->alias) {
virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("device cannot be detached without a device
alias"));
@@ -5556,24 +5561,14 @@ qemuDomainDetachHostSCSIDevice(virQEMUDriverPtr driver,
if (!async)
qemuDomainMarkDeviceForRemoval(vm, detach->info);
- qemuDomainObjEnterMonitor(driver, vm);
- ret = qemuMonitorDelDevice(priv->mon, detach->info->alias);
-
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
- return -1;
-
- return ret;
+ return qemuDomainDeleteDevice(vm, detach->info->alias, true);
}
static int
-qemuDomainDetachSCSIVHostDevice(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
+qemuDomainDetachSCSIVHostDevice(virDomainObjPtr vm,
virDomainHostdevDefPtr detach,
bool async)
{
- qemuDomainObjPrivatePtr priv = vm->privateData;
- int ret = -1;
-
if (!detach->info->alias) {
virReportError(VIR_ERR_OPERATION_FAILED,
"%s", _("device cannot be detached without a device
alias"));
@@ -5583,25 +5578,15 @@ qemuDomainDetachSCSIVHostDevice(virQEMUDriverPtr driver,
if (!async)
qemuDomainMarkDeviceForRemoval(vm, detach->info);
- qemuDomainObjEnterMonitor(driver, vm);
- ret = qemuMonitorDelDevice(priv->mon, detach->info->alias);
-
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
- return -1;
-
- return ret;
+ return qemuDomainDeleteDevice(vm, detach->info->alias, true);
}
static int
-qemuDomainDetachMediatedDevice(virQEMUDriverPtr driver,
- virDomainObjPtr vm,
+qemuDomainDetachMediatedDevice(virDomainObjPtr vm,
virDomainHostdevDefPtr detach,
bool async)
{
- int ret = -1;
- qemuDomainObjPrivatePtr priv = vm->privateData;
-
if (!detach->info->alias) {
virReportError(VIR_ERR_OPERATION_FAILED, "%s",
_("device cannot be detached without a device alias"));
@@ -5611,12 +5596,7 @@ qemuDomainDetachMediatedDevice(virQEMUDriverPtr driver,
if (!async)
qemuDomainMarkDeviceForRemoval(vm, detach->info);
- qemuDomainObjEnterMonitor(driver, vm);
- ret = qemuMonitorDelDevice(priv->mon, detach->info->alias);
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
- ret = -1;
-
- return ret;
+ return qemuDomainDeleteDevice(vm, detach->info->alias, true);
}
@@ -5633,19 +5613,19 @@ qemuDomainDetachThisHostDevice(virQEMUDriverPtr driver,
switch (detach->source.subsys.type) {
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
- ret = qemuDomainDetachHostPCIDevice(driver, vm, detach, async);
+ ret = qemuDomainDetachHostPCIDevice(vm, detach, async);
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
- ret = qemuDomainDetachHostUSBDevice(driver, vm, detach, async);
+ ret = qemuDomainDetachHostUSBDevice(vm, detach, async);
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
- ret = qemuDomainDetachHostSCSIDevice(driver, vm, detach, async);
+ ret = qemuDomainDetachHostSCSIDevice(vm, detach, async);
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
- ret = qemuDomainDetachSCSIVHostDevice(driver, vm, detach, async);
+ ret = qemuDomainDetachSCSIVHostDevice(vm, detach, async);
break;
case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
- ret = qemuDomainDetachMediatedDevice(driver, vm, detach, async);
+ ret = qemuDomainDetachMediatedDevice(vm, detach, async);
break;
default:
virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
@@ -5762,7 +5742,6 @@ qemuDomainDetachShmemDevice(virQEMUDriverPtr driver,
int ret = -1;
ssize_t idx = -1;
virDomainShmemDefPtr shmem = NULL;
- qemuDomainObjPrivatePtr priv = vm->privateData;
if ((idx = virDomainShmemDefFind(vm->def, dev)) < 0) {
virReportError(VIR_ERR_DEVICE_MISSING,
@@ -5791,12 +5770,7 @@ qemuDomainDetachShmemDevice(virQEMUDriverPtr driver,
if (!async)
qemuDomainMarkDeviceForRemoval(vm, &shmem->info);
- qemuDomainObjEnterMonitor(driver, vm);
- if (qemuMonitorDelDevice(priv->mon, shmem->info.alias) < 0) {
- ignore_value(qemuDomainObjExitMonitor(driver, vm));
- goto cleanup;
- }
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
+ if (qemuDomainDeleteDevice(vm, shmem->info.alias, true) < 0)
goto cleanup;
if (async) {
@@ -5821,7 +5795,6 @@ qemuDomainDetachWatchdog(virQEMUDriverPtr driver,
{
int ret = -1;
virDomainWatchdogDefPtr watchdog = vm->def->watchdog;
- qemuDomainObjPrivatePtr priv = vm->privateData;
if (!watchdog) {
virReportError(VIR_ERR_DEVICE_MISSING, "%s",
@@ -5852,12 +5825,7 @@ qemuDomainDetachWatchdog(virQEMUDriverPtr driver,
if (!async)
qemuDomainMarkDeviceForRemoval(vm, &watchdog->info);
- qemuDomainObjEnterMonitor(driver, vm);
- if (qemuMonitorDelDevice(priv->mon, watchdog->info.alias) < 0) {
- ignore_value(qemuDomainObjExitMonitor(driver, vm));
- goto cleanup;
- }
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
+ if (qemuDomainDeleteDevice(vm, watchdog->info.alias, true) < 0)
goto cleanup;
if (async) {
@@ -5881,7 +5849,6 @@ qemuDomainDetachRedirdevDevice(virQEMUDriverPtr driver,
bool async)
{
int ret = -1;
- qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainRedirdevDefPtr tmpRedirdevDef;
ssize_t idx;
@@ -5902,12 +5869,7 @@ qemuDomainDetachRedirdevDevice(virQEMUDriverPtr driver,
if (!async)
qemuDomainMarkDeviceForRemoval(vm, &tmpRedirdevDef->info);
- qemuDomainObjEnterMonitor(driver, vm);
- if (qemuMonitorDelDevice(priv->mon, tmpRedirdevDef->info.alias) < 0) {
- ignore_value(qemuDomainObjExitMonitor(driver, vm));
- goto cleanup;
- }
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
+ if (qemuDomainDeleteDevice(vm, tmpRedirdevDef->info.alias, true) < 0)
goto cleanup;
if (async) {
@@ -5932,7 +5894,6 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver,
{
int detachidx, ret = -1;
virDomainNetDefPtr detach = NULL;
- qemuDomainObjPrivatePtr priv = vm->privateData;
if ((detachidx = virDomainNetFindIdx(vm->def, dev->data.net)) < 0)
goto cleanup;
@@ -5973,15 +5934,11 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver,
if (!async)
qemuDomainMarkDeviceForRemoval(vm, &detach->info);
- qemuDomainObjEnterMonitor(driver, vm);
- if (qemuMonitorDelDevice(priv->mon, detach->info.alias) < 0) {
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
- goto cleanup;
- virDomainAuditNet(vm, detach, NULL, "detach", false);
+ if (qemuDomainDeleteDevice(vm, detach->info.alias, true) < 0) {
+ if (virDomainObjIsActive(vm))
+ virDomainAuditNet(vm, detach, NULL, "detach", false);
goto cleanup;
}
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
- goto cleanup;
if (async) {
ret = 0;
@@ -6144,20 +6101,19 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver,
if (!async && !guestfwd)
qemuDomainMarkDeviceForRemoval(vm, &tmpChr->info);
- qemuDomainObjEnterMonitor(driver, vm);
if (guestfwd) {
- if (qemuMonitorRemoveNetdev(priv->mon, tmpChr->info.alias) < 0) {
- ignore_value(qemuDomainObjExitMonitor(driver, vm));
+ int rc;
+ qemuDomainObjEnterMonitor(driver, vm);
+ rc = qemuMonitorRemoveNetdev(priv->mon, tmpChr->info.alias);
+ if (qemuDomainObjExitMonitor(driver, vm) < 0)
+ rc = -1;
+
+ if (rc < 0)
goto cleanup;
- }
} else {
- if (qemuMonitorDelDevice(priv->mon, tmpChr->info.alias) < 0) {
- ignore_value(qemuDomainObjExitMonitor(driver, vm));
+ if (qemuDomainDeleteDevice(vm, tmpChr->info.alias, true) < 0)
goto cleanup;
- }
}
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
- goto cleanup;
if (guestfwd) {
ret = qemuDomainRemoveChrDevice(driver, vm, tmpChr, false);
@@ -6181,10 +6137,8 @@ qemuDomainDetachRNGDevice(virQEMUDriverPtr driver,
virDomainRNGDefPtr rng,
bool async)
{
- qemuDomainObjPrivatePtr priv = vm->privateData;
ssize_t idx;
virDomainRNGDefPtr tmpRNG;
- int rc;
int ret = -1;
if ((idx = virDomainRNGFind(vm->def, rng)) < 0) {
@@ -6206,9 +6160,7 @@ qemuDomainDetachRNGDevice(virQEMUDriverPtr driver,
if (!async)
qemuDomainMarkDeviceForRemoval(vm, &tmpRNG->info);
- qemuDomainObjEnterMonitor(driver, vm);
- rc = qemuMonitorDelDevice(priv->mon, tmpRNG->info.alias);
- if (qemuDomainObjExitMonitor(driver, vm) || rc < 0)
+ if (qemuDomainDeleteDevice(vm, tmpRNG->info.alias, true) < 0)
goto cleanup;
if (async) {
@@ -6231,10 +6183,8 @@ qemuDomainDetachMemoryDevice(virQEMUDriverPtr driver,
virDomainMemoryDefPtr memdef,
bool async)
{
- qemuDomainObjPrivatePtr priv = vm->privateData;
virDomainMemoryDefPtr mem;
int idx;
- int rc;
int ret = -1;
qemuDomainMemoryDeviceAlignSize(vm->def, memdef);
@@ -6258,9 +6208,7 @@ qemuDomainDetachMemoryDevice(virQEMUDriverPtr driver,
if (!async)
qemuDomainMarkDeviceForRemoval(vm, &mem->info);
- qemuDomainObjEnterMonitor(driver, vm);
- rc = qemuMonitorDelDevice(priv->mon, mem->info.alias);
- if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
+ if (qemuDomainDeleteDevice(vm, mem->info.alias, true) < 0)
goto cleanup;
if (async) {
@@ -6365,15 +6313,9 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver,
qemuDomainMarkDeviceAliasForRemoval(vm, vcpupriv->alias);
- qemuDomainObjEnterMonitor(driver, vm);
-
- rc = qemuMonitorDelDevice(qemuDomainGetMonitor(vm), vcpupriv->alias);
-
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
- goto cleanup;
-
- if (rc < 0) {
- virDomainAuditVcpu(vm, oldvcpus, oldvcpus - nvcpus, "update", false);
+ if (qemuDomainDeleteDevice(vm, vcpupriv->alias, true) < 0) {
+ if (virDomainObjIsActive(vm))
+ virDomainAuditVcpu(vm, oldvcpus, oldvcpus - nvcpus, "update",
false);
goto cleanup;
}
@@ -6943,8 +6885,6 @@ qemuDomainDetachInputDevice(virDomainObjPtr vm,
virDomainInputDefPtr def,
bool async)
{
- qemuDomainObjPrivatePtr priv = vm->privateData;
- virQEMUDriverPtr driver = priv->driver;
virDomainInputDefPtr input;
int ret = -1;
int idx;
@@ -6974,12 +6914,7 @@ qemuDomainDetachInputDevice(virDomainObjPtr vm,
if (!async)
qemuDomainMarkDeviceForRemoval(vm, &input->info);
- qemuDomainObjEnterMonitor(driver, vm);
- if (qemuMonitorDelDevice(priv->mon, input->info.alias) < 0) {
- ignore_value(qemuDomainObjExitMonitor(driver, vm));
- goto cleanup;
- }
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
+ if (qemuDomainDeleteDevice(vm, input->info.alias, true) < 0)
goto cleanup;
if (async) {
@@ -7001,8 +6936,6 @@ qemuDomainDetachVsockDevice(virDomainObjPtr vm,
virDomainVsockDefPtr dev,
bool async)
{
- qemuDomainObjPrivatePtr priv = vm->privateData;
- virQEMUDriverPtr driver = priv->driver;
virDomainVsockDefPtr vsock = vm->def->vsock;
int ret = -1;
@@ -7017,12 +6950,7 @@ qemuDomainDetachVsockDevice(virDomainObjPtr vm,
if (!async)
qemuDomainMarkDeviceForRemoval(vm, &vsock->info);
- qemuDomainObjEnterMonitor(driver, vm);
- if (qemuMonitorDelDevice(priv->mon, vsock->info.alias) < 0) {
- ignore_value(qemuDomainObjExitMonitor(driver, vm));
- goto cleanup;
- }
- if (qemuDomainObjExitMonitor(driver, vm) < 0)
+ if (qemuDomainDeleteDevice(vm, vsock->info.alias, true) < 0)
goto cleanup;
if (async) {
--
2.19.2