render / rpms / libvirt

Forked from rpms/libvirt 9 months ago
Clone
0a7476
From 2c396c9f38179ca8a2428d30bc26be1bb05789c1 Mon Sep 17 00:00:00 2001
0a7476
Message-Id: <2c396c9f38179ca8a2428d30bc26be1bb05789c1@dist-git>
0a7476
From: Michal Privoznik <mprivozn@redhat.com>
0a7476
Date: Thu, 11 Apr 2019 15:14:25 -0400
0a7476
Subject: [PATCH] qemu_hotplug: Introduce and use qemuDomainDeleteDevice
0a7476
0a7476
The aim of this function will be to fix return value of
0a7476
qemuMonitorDelDevice() in one specific case. But that is yet to
0a7476
come. Right now this is nothing but a plain substitution.
0a7476
0a7476
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
0a7476
ACKed-by: Peter Krempa <pkrempa@redhat.com>
0a7476
(cherry picked from commit 4cd13478ac331f5e42c926d4f2111dd89d2970a6)
0a7476
0a7476
Partially-Resolves: https://bugzilla.redhat.com/1658198
0a7476
Signed-off-by: Laine Stump <laine@redhat.com>
0a7476
0a7476
Conflicts: src/qemu/qemu_hotplug.c:
0a7476
   - qemuDomainDetachExtensionDevice() (erroneously) added to
0a7476
     qemuDomainDetachControllerDevice upstream, doesn't exist
0a7476
     downstream.
0a7476
Signed-off-by: Laine Stump <laine@laine.org>
0a7476
Message-Id: <20190411191453.24055-14-laine@redhat.com>
0a7476
Acked-by: Michal Privoznik <mprivozn@redhat.com>
0a7476
---
0a7476
 src/qemu/qemu_hotplug.c | 239 ++++++++++++++--------------------------
0a7476
 1 file changed, 82 insertions(+), 157 deletions(-)
0a7476
0a7476
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
0a7476
index 963b87f798..1f41efa180 100644
0a7476
--- a/src/qemu/qemu_hotplug.c
0a7476
+++ b/src/qemu/qemu_hotplug.c
0a7476
@@ -68,6 +68,45 @@ VIR_LOG_INIT("qemu.qemu_hotplug");
0a7476
 unsigned long long qemuDomainRemoveDeviceWaitTime = 1000ull * 5;
0a7476
 
0a7476
 
0a7476
+/**
0a7476
+ * qemuDomainDeleteDevice:
0a7476
+ * @vm: domain object
0a7476
+ * @alias: device to remove
0a7476
+ *
0a7476
+ * This is a wrapper over qemuMonitorDelDevice() plus enter/exit
0a7476
+ * monitor calls.  This function MUST be used instead of plain
0a7476
+ * qemuMonitorDelDevice() in all places where @alias represents a
0a7476
+ * device from domain XML, i.e. caller marks the device for
0a7476
+ * removal and then calls qemuDomainWaitForDeviceRemoval()
0a7476
+ * followed by qemuDomainRemove*Device().
0a7476
+ *
0a7476
+ * For collateral devices (e.g. extension devices like zPCI) it
0a7476
+ * is safe to use plain qemuMonitorDelDevice().
0a7476
+ *
0a7476
+ * Upon entry, @vm must be locked.
0a7476
+ *
0a7476
+ * Returns: 0 on success,
0a7476
+ *         -1 otherwise.
0a7476
+ */
0a7476
+static int
0a7476
+qemuDomainDeleteDevice(virDomainObjPtr vm,
0a7476
+                       const char *alias)
0a7476
+{
0a7476
+    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
+    virQEMUDriverPtr driver = priv->driver;
0a7476
+    int rc;
0a7476
+
0a7476
+    qemuDomainObjEnterMonitor(driver, vm);
0a7476
+
0a7476
+    rc = qemuMonitorDelDevice(priv->mon, alias);
0a7476
+
0a7476
+    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
+        rc = -1;
0a7476
+
0a7476
+    return rc;
0a7476
+}
0a7476
+
0a7476
+
0a7476
 /**
0a7476
  * qemuHotplugPrepareDiskAccess:
0a7476
  * @driver: qemu driver struct
0a7476
@@ -4689,7 +4728,6 @@ qemuDomainDetachVirtioDiskDevice(virQEMUDriverPtr driver,
0a7476
                                  bool async)
0a7476
 {
0a7476
     int ret = -1;
0a7476
-    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
 
0a7476
     if (qemuIsMultiFunctionDevice(vm->def, &detach->info)) {
0a7476
         virReportError(VIR_ERR_OPERATION_FAILED,
0a7476
@@ -4701,15 +4739,11 @@ qemuDomainDetachVirtioDiskDevice(virQEMUDriverPtr driver,
0a7476
     if (!async)
0a7476
         qemuDomainMarkDeviceForRemoval(vm, &detach->info);
0a7476
 
0a7476
-    qemuDomainObjEnterMonitor(driver, vm);
0a7476
-    if (qemuMonitorDelDevice(priv->mon, detach->info.alias) < 0) {
0a7476
-        if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
-            goto cleanup;
0a7476
-        virDomainAuditDisk(vm, detach->src, NULL, "detach", false);
0a7476
+    if (qemuDomainDeleteDevice(vm, detach->info.alias) < 0) {
0a7476
+        if (virDomainObjIsActive(vm))
0a7476
+            virDomainAuditDisk(vm, detach->src, NULL, "detach", false);
0a7476
         goto cleanup;
0a7476
     }
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
-        goto cleanup;
0a7476
 
0a7476
     if (async) {
0a7476
         ret = 0;
0a7476
@@ -4731,7 +4765,6 @@ qemuDomainDetachDiskDevice(virQEMUDriverPtr driver,
0a7476
                            bool async)
0a7476
 {
0a7476
     int ret = -1;
0a7476
-    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
 
0a7476
     if (qemuDomainDiskBlockJobIsActive(detach))
0a7476
         goto cleanup;
0a7476
@@ -4739,15 +4772,11 @@ qemuDomainDetachDiskDevice(virQEMUDriverPtr driver,
0a7476
     if (!async)
0a7476
         qemuDomainMarkDeviceForRemoval(vm, &detach->info);
0a7476
 
0a7476
-    qemuDomainObjEnterMonitor(driver, vm);
0a7476
-    if (qemuMonitorDelDevice(priv->mon, detach->info.alias) < 0) {
0a7476
-        if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
-            goto cleanup;
0a7476
-        virDomainAuditDisk(vm, detach->src, NULL, "detach", false);
0a7476
+    if (qemuDomainDeleteDevice(vm, detach->info.alias) < 0) {
0a7476
+        if (virDomainObjIsActive(vm))
0a7476
+            virDomainAuditDisk(vm, detach->src, NULL, "detach", false);
0a7476
         goto cleanup;
0a7476
     }
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
-        goto cleanup;
0a7476
 
0a7476
     if (async) {
0a7476
         ret = 0;
0a7476
@@ -4882,7 +4911,6 @@ int qemuDomainDetachControllerDevice(virQEMUDriverPtr driver,
0a7476
 {
0a7476
     int idx, ret = -1;
0a7476
     virDomainControllerDefPtr detach = NULL;
0a7476
-    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
 
0a7476
     if ((idx = virDomainControllerFind(vm->def,
0a7476
                                        dev->data.controller->type,
0a7476
@@ -4928,12 +4956,7 @@ int qemuDomainDetachControllerDevice(virQEMUDriverPtr driver,
0a7476
     if (!async)
0a7476
         qemuDomainMarkDeviceForRemoval(vm, &detach->info);
0a7476
 
0a7476
-    qemuDomainObjEnterMonitor(driver, vm);
0a7476
-    if (qemuMonitorDelDevice(priv->mon, detach->info.alias) < 0) {
0a7476
-        ignore_value(qemuDomainObjExitMonitor(driver, vm));
0a7476
-        goto cleanup;
0a7476
-    }
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
+    if (qemuDomainDeleteDevice(vm, detach->info.alias) < 0)
0a7476
         goto cleanup;
0a7476
 
0a7476
     if (async) {
0a7476
@@ -4950,14 +4973,11 @@ int qemuDomainDetachControllerDevice(virQEMUDriverPtr driver,
0a7476
 }
0a7476
 
0a7476
 static int
0a7476
-qemuDomainDetachHostPCIDevice(virQEMUDriverPtr driver,
0a7476
-                              virDomainObjPtr vm,
0a7476
+qemuDomainDetachHostPCIDevice(virDomainObjPtr vm,
0a7476
                               virDomainHostdevDefPtr detach,
0a7476
                               bool async)
0a7476
 {
0a7476
-    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
     virDomainHostdevSubsysPCIPtr pcisrc = &detach->source.subsys.u.pci;
0a7476
-    int ret;
0a7476
 
0a7476
     if (qemuIsMultiFunctionDevice(vm->def, detach->info)) {
0a7476
         virReportError(VIR_ERR_OPERATION_FAILED,
0a7476
@@ -4970,23 +4990,14 @@ qemuDomainDetachHostPCIDevice(virQEMUDriverPtr driver,
0a7476
     if (!async)
0a7476
         qemuDomainMarkDeviceForRemoval(vm, detach->info);
0a7476
 
0a7476
-    qemuDomainObjEnterMonitor(driver, vm);
0a7476
-    ret = qemuMonitorDelDevice(priv->mon, detach->info->alias);
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
-        ret = -1;
0a7476
-
0a7476
-    return ret;
0a7476
+    return qemuDomainDeleteDevice(vm, detach->info->alias);
0a7476
 }
0a7476
 
0a7476
 static int
0a7476
-qemuDomainDetachHostUSBDevice(virQEMUDriverPtr driver,
0a7476
-                              virDomainObjPtr vm,
0a7476
+qemuDomainDetachHostUSBDevice(virDomainObjPtr vm,
0a7476
                               virDomainHostdevDefPtr detach,
0a7476
                               bool async)
0a7476
 {
0a7476
-    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
-    int ret;
0a7476
-
0a7476
     if (!detach->info->alias) {
0a7476
         virReportError(VIR_ERR_OPERATION_FAILED,
0a7476
                        "%s", _("device cannot be detached without a device alias"));
0a7476
@@ -4996,23 +5007,14 @@ qemuDomainDetachHostUSBDevice(virQEMUDriverPtr driver,
0a7476
     if (!async)
0a7476
         qemuDomainMarkDeviceForRemoval(vm, detach->info);
0a7476
 
0a7476
-    qemuDomainObjEnterMonitor(driver, vm);
0a7476
-    ret = qemuMonitorDelDevice(priv->mon, detach->info->alias);
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
-        ret = -1;
0a7476
-
0a7476
-    return ret;
0a7476
+    return qemuDomainDeleteDevice(vm, detach->info->alias);
0a7476
 }
0a7476
 
0a7476
 static int
0a7476
-qemuDomainDetachHostSCSIDevice(virQEMUDriverPtr driver,
0a7476
-                               virDomainObjPtr vm,
0a7476
+qemuDomainDetachHostSCSIDevice(virDomainObjPtr vm,
0a7476
                                virDomainHostdevDefPtr detach,
0a7476
                                bool async)
0a7476
 {
0a7476
-    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
-    int ret = -1;
0a7476
-
0a7476
     if (!detach->info->alias) {
0a7476
         virReportError(VIR_ERR_OPERATION_FAILED,
0a7476
                        "%s", _("device cannot be detached without a device alias"));
0a7476
@@ -5022,24 +5024,14 @@ qemuDomainDetachHostSCSIDevice(virQEMUDriverPtr driver,
0a7476
     if (!async)
0a7476
         qemuDomainMarkDeviceForRemoval(vm, detach->info);
0a7476
 
0a7476
-    qemuDomainObjEnterMonitor(driver, vm);
0a7476
-    ret = qemuMonitorDelDevice(priv->mon, detach->info->alias);
0a7476
-
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
-        return -1;
0a7476
-
0a7476
-    return ret;
0a7476
+    return qemuDomainDeleteDevice(vm, detach->info->alias);
0a7476
 }
0a7476
 
0a7476
 static int
0a7476
-qemuDomainDetachSCSIVHostDevice(virQEMUDriverPtr driver,
0a7476
-                                virDomainObjPtr vm,
0a7476
+qemuDomainDetachSCSIVHostDevice(virDomainObjPtr vm,
0a7476
                                 virDomainHostdevDefPtr detach,
0a7476
                                 bool async)
0a7476
 {
0a7476
-    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
-    int ret = -1;
0a7476
-
0a7476
     if (!detach->info->alias) {
0a7476
         virReportError(VIR_ERR_OPERATION_FAILED,
0a7476
                        "%s", _("device cannot be detached without a device alias"));
0a7476
@@ -5049,25 +5041,15 @@ qemuDomainDetachSCSIVHostDevice(virQEMUDriverPtr driver,
0a7476
     if (!async)
0a7476
         qemuDomainMarkDeviceForRemoval(vm, detach->info);
0a7476
 
0a7476
-    qemuDomainObjEnterMonitor(driver, vm);
0a7476
-    ret = qemuMonitorDelDevice(priv->mon, detach->info->alias);
0a7476
-
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
-        return -1;
0a7476
-
0a7476
-    return ret;
0a7476
+    return qemuDomainDeleteDevice(vm, detach->info->alias);
0a7476
 }
0a7476
 
0a7476
 
0a7476
 static int
0a7476
-qemuDomainDetachMediatedDevice(virQEMUDriverPtr driver,
0a7476
-                               virDomainObjPtr vm,
0a7476
+qemuDomainDetachMediatedDevice(virDomainObjPtr vm,
0a7476
                                virDomainHostdevDefPtr detach,
0a7476
                                bool async)
0a7476
 {
0a7476
-    int ret = -1;
0a7476
-    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
-
0a7476
     if (!detach->info->alias) {
0a7476
         virReportError(VIR_ERR_OPERATION_FAILED, "%s",
0a7476
                        _("device cannot be detached without a device alias"));
0a7476
@@ -5077,12 +5059,7 @@ qemuDomainDetachMediatedDevice(virQEMUDriverPtr driver,
0a7476
     if (!async)
0a7476
         qemuDomainMarkDeviceForRemoval(vm, detach->info);
0a7476
 
0a7476
-    qemuDomainObjEnterMonitor(driver, vm);
0a7476
-    ret = qemuMonitorDelDevice(priv->mon, detach->info->alias);
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
-        ret = -1;
0a7476
-
0a7476
-    return ret;
0a7476
+    return qemuDomainDeleteDevice(vm, detach->info->alias);
0a7476
 }
0a7476
 
0a7476
 
0a7476
@@ -5099,19 +5076,19 @@ qemuDomainDetachThisHostDevice(virQEMUDriverPtr driver,
0a7476
 
0a7476
     switch (detach->source.subsys.type) {
0a7476
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_PCI:
0a7476
-        ret = qemuDomainDetachHostPCIDevice(driver, vm, detach, async);
0a7476
+        ret = qemuDomainDetachHostPCIDevice(vm, detach, async);
0a7476
         break;
0a7476
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB:
0a7476
-        ret = qemuDomainDetachHostUSBDevice(driver, vm, detach, async);
0a7476
+        ret = qemuDomainDetachHostUSBDevice(vm, detach, async);
0a7476
         break;
0a7476
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI:
0a7476
-        ret = qemuDomainDetachHostSCSIDevice(driver, vm, detach, async);
0a7476
+        ret = qemuDomainDetachHostSCSIDevice(vm, detach, async);
0a7476
         break;
0a7476
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_SCSI_HOST:
0a7476
-        ret = qemuDomainDetachSCSIVHostDevice(driver, vm, detach, async);
0a7476
+        ret = qemuDomainDetachSCSIVHostDevice(vm, detach, async);
0a7476
         break;
0a7476
     case VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_MDEV:
0a7476
-        ret = qemuDomainDetachMediatedDevice(driver, vm, detach, async);
0a7476
+        ret = qemuDomainDetachMediatedDevice(vm, detach, async);
0a7476
         break;
0a7476
     default:
0a7476
         virReportError(VIR_ERR_CONFIG_UNSUPPORTED,
0a7476
@@ -5228,7 +5205,6 @@ qemuDomainDetachShmemDevice(virQEMUDriverPtr driver,
0a7476
     int ret = -1;
0a7476
     ssize_t idx = -1;
0a7476
     virDomainShmemDefPtr shmem = NULL;
0a7476
-    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
 
0a7476
     if ((idx = virDomainShmemDefFind(vm->def, dev)) < 0) {
0a7476
         virReportError(VIR_ERR_DEVICE_MISSING,
0a7476
@@ -5257,12 +5233,7 @@ qemuDomainDetachShmemDevice(virQEMUDriverPtr driver,
0a7476
     if (!async)
0a7476
         qemuDomainMarkDeviceForRemoval(vm, &shmem->info);
0a7476
 
0a7476
-    qemuDomainObjEnterMonitor(driver, vm);
0a7476
-    if (qemuMonitorDelDevice(priv->mon, shmem->info.alias) < 0) {
0a7476
-        ignore_value(qemuDomainObjExitMonitor(driver, vm));
0a7476
-        goto cleanup;
0a7476
-    }
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
+    if (qemuDomainDeleteDevice(vm, shmem->info.alias) < 0)
0a7476
         goto cleanup;
0a7476
 
0a7476
     if (async) {
0a7476
@@ -5287,7 +5258,6 @@ qemuDomainDetachWatchdog(virQEMUDriverPtr driver,
0a7476
 {
0a7476
     int ret = -1;
0a7476
     virDomainWatchdogDefPtr watchdog = vm->def->watchdog;
0a7476
-    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
 
0a7476
     if (!watchdog) {
0a7476
         virReportError(VIR_ERR_DEVICE_MISSING, "%s",
0a7476
@@ -5318,12 +5288,7 @@ qemuDomainDetachWatchdog(virQEMUDriverPtr driver,
0a7476
     if (!async)
0a7476
         qemuDomainMarkDeviceForRemoval(vm, &watchdog->info);
0a7476
 
0a7476
-    qemuDomainObjEnterMonitor(driver, vm);
0a7476
-    if (qemuMonitorDelDevice(priv->mon, watchdog->info.alias) < 0) {
0a7476
-        ignore_value(qemuDomainObjExitMonitor(driver, vm));
0a7476
-        goto cleanup;
0a7476
-    }
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
+    if (qemuDomainDeleteDevice(vm, watchdog->info.alias) < 0)
0a7476
         goto cleanup;
0a7476
 
0a7476
     if (async) {
0a7476
@@ -5347,7 +5312,6 @@ qemuDomainDetachRedirdevDevice(virQEMUDriverPtr driver,
0a7476
                                bool async)
0a7476
 {
0a7476
     int ret = -1;
0a7476
-    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
     virDomainRedirdevDefPtr tmpRedirdevDef;
0a7476
     ssize_t idx;
0a7476
 
0a7476
@@ -5368,12 +5332,7 @@ qemuDomainDetachRedirdevDevice(virQEMUDriverPtr driver,
0a7476
     if (!async)
0a7476
         qemuDomainMarkDeviceForRemoval(vm, &tmpRedirdevDef->info);
0a7476
 
0a7476
-    qemuDomainObjEnterMonitor(driver, vm);
0a7476
-    if (qemuMonitorDelDevice(priv->mon, tmpRedirdevDef->info.alias) < 0) {
0a7476
-        ignore_value(qemuDomainObjExitMonitor(driver, vm));
0a7476
-        goto cleanup;
0a7476
-    }
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
+    if (qemuDomainDeleteDevice(vm, tmpRedirdevDef->info.alias) < 0)
0a7476
         goto cleanup;
0a7476
 
0a7476
     if (async) {
0a7476
@@ -5398,7 +5357,6 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver,
0a7476
 {
0a7476
     int detachidx, ret = -1;
0a7476
     virDomainNetDefPtr detach = NULL;
0a7476
-    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
 
0a7476
     if ((detachidx = virDomainNetFindIdx(vm->def, dev->data.net)) < 0)
0a7476
         goto cleanup;
0a7476
@@ -5439,15 +5397,11 @@ qemuDomainDetachNetDevice(virQEMUDriverPtr driver,
0a7476
     if (!async)
0a7476
         qemuDomainMarkDeviceForRemoval(vm, &detach->info);
0a7476
 
0a7476
-    qemuDomainObjEnterMonitor(driver, vm);
0a7476
-    if (qemuMonitorDelDevice(priv->mon, detach->info.alias) < 0) {
0a7476
-        if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
-            goto cleanup;
0a7476
-        virDomainAuditNet(vm, detach, NULL, "detach", false);
0a7476
+    if (qemuDomainDeleteDevice(vm, detach->info.alias) < 0) {
0a7476
+        if (virDomainObjIsActive(vm))
0a7476
+            virDomainAuditNet(vm, detach, NULL, "detach", false);
0a7476
         goto cleanup;
0a7476
     }
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
-        goto cleanup;
0a7476
 
0a7476
     if (async) {
0a7476
         ret = 0;
0a7476
@@ -5610,20 +5564,19 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver,
0a7476
     if (!async && !guestfwd)
0a7476
         qemuDomainMarkDeviceForRemoval(vm, &tmpChr->info);
0a7476
 
0a7476
-    qemuDomainObjEnterMonitor(driver, vm);
0a7476
     if (guestfwd) {
0a7476
-        if (qemuMonitorRemoveNetdev(priv->mon, tmpChr->info.alias) < 0) {
0a7476
-            ignore_value(qemuDomainObjExitMonitor(driver, vm));
0a7476
+        int rc;
0a7476
+        qemuDomainObjEnterMonitor(driver, vm);
0a7476
+        rc = qemuMonitorRemoveNetdev(priv->mon, tmpChr->info.alias);
0a7476
+        if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
+            rc = -1;
0a7476
+
0a7476
+        if (rc < 0)
0a7476
             goto cleanup;
0a7476
-        }
0a7476
     } else {
0a7476
-        if (qemuMonitorDelDevice(priv->mon, tmpChr->info.alias) < 0) {
0a7476
-            ignore_value(qemuDomainObjExitMonitor(driver, vm));
0a7476
+        if (qemuDomainDeleteDevice(vm, tmpChr->info.alias) < 0)
0a7476
             goto cleanup;
0a7476
-        }
0a7476
     }
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
-        goto cleanup;
0a7476
 
0a7476
     if (guestfwd) {
0a7476
         ret = qemuDomainRemoveChrDevice(driver, vm, tmpChr, false);
0a7476
@@ -5647,10 +5600,8 @@ qemuDomainDetachRNGDevice(virQEMUDriverPtr driver,
0a7476
                           virDomainRNGDefPtr rng,
0a7476
                           bool async)
0a7476
 {
0a7476
-    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
     ssize_t idx;
0a7476
     virDomainRNGDefPtr tmpRNG;
0a7476
-    int rc;
0a7476
     int ret = -1;
0a7476
 
0a7476
     if ((idx = virDomainRNGFind(vm->def, rng)) < 0) {
0a7476
@@ -5672,9 +5623,7 @@ qemuDomainDetachRNGDevice(virQEMUDriverPtr driver,
0a7476
     if (!async)
0a7476
         qemuDomainMarkDeviceForRemoval(vm, &tmpRNG->info);
0a7476
 
0a7476
-    qemuDomainObjEnterMonitor(driver, vm);
0a7476
-    rc = qemuMonitorDelDevice(priv->mon, tmpRNG->info.alias);
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) || rc < 0)
0a7476
+    if (qemuDomainDeleteDevice(vm, tmpRNG->info.alias) < 0)
0a7476
         goto cleanup;
0a7476
 
0a7476
     if (async) {
0a7476
@@ -5697,10 +5646,8 @@ qemuDomainDetachMemoryDevice(virQEMUDriverPtr driver,
0a7476
                              virDomainMemoryDefPtr memdef,
0a7476
                              bool async)
0a7476
 {
0a7476
-    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
     virDomainMemoryDefPtr mem;
0a7476
     int idx;
0a7476
-    int rc;
0a7476
     int ret = -1;
0a7476
 
0a7476
     qemuDomainMemoryDeviceAlignSize(vm->def, memdef);
0a7476
@@ -5724,9 +5671,7 @@ qemuDomainDetachMemoryDevice(virQEMUDriverPtr driver,
0a7476
     if (!async)
0a7476
         qemuDomainMarkDeviceForRemoval(vm, &mem->info);
0a7476
 
0a7476
-    qemuDomainObjEnterMonitor(driver, vm);
0a7476
-    rc = qemuMonitorDelDevice(priv->mon, mem->info.alias);
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) < 0 || rc < 0)
0a7476
+    if (qemuDomainDeleteDevice(vm, mem->info.alias) < 0)
0a7476
         goto cleanup;
0a7476
 
0a7476
     if (async) {
0a7476
@@ -5831,15 +5776,9 @@ qemuDomainHotplugDelVcpu(virQEMUDriverPtr driver,
0a7476
 
0a7476
     qemuDomainMarkDeviceAliasForRemoval(vm, vcpupriv->alias);
0a7476
 
0a7476
-    qemuDomainObjEnterMonitor(driver, vm);
0a7476
-
0a7476
-    rc = qemuMonitorDelDevice(qemuDomainGetMonitor(vm), vcpupriv->alias);
0a7476
-
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
-        goto cleanup;
0a7476
-
0a7476
-    if (rc < 0) {
0a7476
-        virDomainAuditVcpu(vm, oldvcpus, oldvcpus - nvcpus, "update", false);
0a7476
+    if (qemuDomainDeleteDevice(vm, vcpupriv->alias) < 0) {
0a7476
+        if (virDomainObjIsActive(vm))
0a7476
+            virDomainAuditVcpu(vm, oldvcpus, oldvcpus - nvcpus, "update", false);
0a7476
         goto cleanup;
0a7476
     }
0a7476
 
0a7476
@@ -6409,8 +6348,6 @@ qemuDomainDetachInputDevice(virDomainObjPtr vm,
0a7476
                             virDomainInputDefPtr def,
0a7476
                             bool async)
0a7476
 {
0a7476
-    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
-    virQEMUDriverPtr driver = priv->driver;
0a7476
     virDomainInputDefPtr input;
0a7476
     int ret = -1;
0a7476
     int idx;
0a7476
@@ -6440,12 +6377,7 @@ qemuDomainDetachInputDevice(virDomainObjPtr vm,
0a7476
     if (!async)
0a7476
         qemuDomainMarkDeviceForRemoval(vm, &input->info);
0a7476
 
0a7476
-    qemuDomainObjEnterMonitor(driver, vm);
0a7476
-    if (qemuMonitorDelDevice(priv->mon, input->info.alias) < 0) {
0a7476
-        ignore_value(qemuDomainObjExitMonitor(driver, vm));
0a7476
-        goto cleanup;
0a7476
-    }
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
+    if (qemuDomainDeleteDevice(vm, input->info.alias) < 0)
0a7476
         goto cleanup;
0a7476
 
0a7476
     if (async) {
0a7476
@@ -6467,8 +6399,6 @@ qemuDomainDetachVsockDevice(virDomainObjPtr vm,
0a7476
                             virDomainVsockDefPtr dev,
0a7476
                             bool async)
0a7476
 {
0a7476
-    qemuDomainObjPrivatePtr priv = vm->privateData;
0a7476
-    virQEMUDriverPtr driver = priv->driver;
0a7476
     virDomainVsockDefPtr vsock = vm->def->vsock;
0a7476
     int ret = -1;
0a7476
 
0a7476
@@ -6483,12 +6413,7 @@ qemuDomainDetachVsockDevice(virDomainObjPtr vm,
0a7476
     if (!async)
0a7476
         qemuDomainMarkDeviceForRemoval(vm, &vsock->info);
0a7476
 
0a7476
-    qemuDomainObjEnterMonitor(driver, vm);
0a7476
-    if (qemuMonitorDelDevice(priv->mon, vsock->info.alias) < 0) {
0a7476
-        ignore_value(qemuDomainObjExitMonitor(driver, vm));
0a7476
-        goto cleanup;
0a7476
-    }
0a7476
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
0a7476
+    if (qemuDomainDeleteDevice(vm, vsock->info.alias) < 0)
0a7476
         goto cleanup;
0a7476
 
0a7476
     if (async) {
0a7476
-- 
0a7476
2.21.0
0a7476