99cbc7
From 9a33b0d475699d322f3e881c397143eed2dc9b3f Mon Sep 17 00:00:00 2001
99cbc7
Message-Id: <9a33b0d475699d322f3e881c397143eed2dc9b3f@dist-git>
99cbc7
From: Michal Privoznik <mprivozn@redhat.com>
99cbc7
Date: Thu, 11 Apr 2019 15:14:19 -0400
99cbc7
Subject: [PATCH] qemu_hotplug: Detach guestfwd using netdev_del
99cbc7
99cbc7
https://bugzilla.redhat.com/show_bug.cgi?id=1624204
99cbc7
99cbc7
The guestfwd channels are -netdevs really. Hotunplug them as
99cbc7
such. Also, DEVICE_DELETED event is not triggered (surprisingly,
99cbc7
since we're not issuing device_del rather than netdev_del) and
99cbc7
associated chardev is removed automagically too. This means that
99cbc7
we need to do qemuDomainRemoveChrDevice() minus monitor call to
99cbc7
remove the chardev.
99cbc7
99cbc7
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
99cbc7
Reviewed-by: John Ferlan <jferlan@redhat.com>
99cbc7
(cherry picked from commit 112f3a8d0f324c0705326957cca4508602b25eba)
99cbc7
99cbc7
Partially-Resolves: https://bugzilla.redhat.com/1658198
99cbc7
Signed-off-by: Laine Stump <laine@redhat.com>
99cbc7
Signed-off-by: Laine Stump <laine@laine.org>
99cbc7
Message-Id: <20190411191453.24055-8-laine@redhat.com>
99cbc7
Acked-by: Michal Privoznik <mprivozn@redhat.com>
99cbc7
---
99cbc7
 src/qemu/qemu_hotplug.c | 48 ++++++++++++++++++++++++++++-------------
99cbc7
 1 file changed, 33 insertions(+), 15 deletions(-)
99cbc7
99cbc7
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
99cbc7
index 680c06c1ed..43dec329b6 100644
99cbc7
--- a/src/qemu/qemu_hotplug.c
99cbc7
+++ b/src/qemu/qemu_hotplug.c
99cbc7
@@ -4214,25 +4214,28 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
99cbc7
 static int
99cbc7
 qemuDomainRemoveChrDevice(virQEMUDriverPtr driver,
99cbc7
                           virDomainObjPtr vm,
99cbc7
-                          virDomainChrDefPtr chr)
99cbc7
+                          virDomainChrDefPtr chr,
99cbc7
+                          bool monitor)
99cbc7
 {
99cbc7
     virObjectEventPtr event;
99cbc7
     char *charAlias = NULL;
99cbc7
     qemuDomainObjPrivatePtr priv = vm->privateData;
99cbc7
     int ret = -1;
99cbc7
-    int rc;
99cbc7
+    int rc = 0;
99cbc7
 
99cbc7
     VIR_DEBUG("Removing character device %s from domain %p %s",
99cbc7
               chr->info.alias, vm, vm->def->name);
99cbc7
 
99cbc7
-    if (!(charAlias = qemuAliasChardevFromDevAlias(chr->info.alias)))
99cbc7
-        goto cleanup;
99cbc7
+    if (monitor) {
99cbc7
+        if (!(charAlias = qemuAliasChardevFromDevAlias(chr->info.alias)))
99cbc7
+            goto cleanup;
99cbc7
 
99cbc7
-    qemuDomainObjEnterMonitor(driver, vm);
99cbc7
-    rc = qemuMonitorDetachCharDev(priv->mon, charAlias);
99cbc7
+        qemuDomainObjEnterMonitor(driver, vm);
99cbc7
+        rc = qemuMonitorDetachCharDev(priv->mon, charAlias);
99cbc7
 
99cbc7
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
99cbc7
-        goto cleanup;
99cbc7
+        if (qemuDomainObjExitMonitor(driver, vm) < 0)
99cbc7
+            goto cleanup;
99cbc7
+    }
99cbc7
 
99cbc7
     if (rc == 0 &&
99cbc7
         qemuDomainDelChardevTLSObjects(driver, vm, chr->source, charAlias) < 0)
99cbc7
@@ -4526,7 +4529,7 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver,
99cbc7
         break;
99cbc7
 
99cbc7
     case VIR_DOMAIN_DEVICE_CHR:
99cbc7
-        ret = qemuDomainRemoveChrDevice(driver, vm, dev->data.chr);
99cbc7
+        ret = qemuDomainRemoveChrDevice(driver, vm, dev->data.chr, true);
99cbc7
         break;
99cbc7
     case VIR_DOMAIN_DEVICE_RNG:
99cbc7
         ret = qemuDomainRemoveRNGDevice(driver, vm, dev->data.rng);
99cbc7
@@ -5590,6 +5593,7 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver,
99cbc7
     virDomainDefPtr vmdef = vm->def;
99cbc7
     virDomainChrDefPtr tmpChr;
99cbc7
     char *devstr = NULL;
99cbc7
+    bool guestfwd = false;
99cbc7
 
99cbc7
     if (!(tmpChr = virDomainChrFind(vmdef, chr))) {
99cbc7
         virReportError(VIR_ERR_DEVICE_MISSING,
99cbc7
@@ -5599,6 +5603,11 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver,
99cbc7
         goto cleanup;
99cbc7
     }
99cbc7
 
99cbc7
+    /* guestfwd channels are not really -device rather than
99cbc7
+     * -netdev. We need to treat them slightly differently. */
99cbc7
+    guestfwd = tmpChr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
99cbc7
+               tmpChr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD;
99cbc7
+
99cbc7
     if (!tmpChr->info.alias && qemuAssignDeviceChrAlias(vmdef, tmpChr, -1) < 0)
99cbc7
         goto cleanup;
99cbc7
 
99cbc7
@@ -5607,22 +5616,31 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver,
99cbc7
     if (qemuBuildChrDeviceStr(&devstr, vmdef, tmpChr, priv->qemuCaps) < 0)
99cbc7
         goto cleanup;
99cbc7
 
99cbc7
-    if (!async)
99cbc7
+    if (!async && !guestfwd)
99cbc7
         qemuDomainMarkDeviceForRemoval(vm, &tmpChr->info);
99cbc7
 
99cbc7
     qemuDomainObjEnterMonitor(driver, vm);
99cbc7
-    if (devstr && qemuMonitorDelDevice(priv->mon, tmpChr->info.alias) < 0) {
99cbc7
-        ignore_value(qemuDomainObjExitMonitor(driver, vm));
99cbc7
-        goto cleanup;
99cbc7
+    if (guestfwd) {
99cbc7
+        if (qemuMonitorRemoveNetdev(priv->mon, tmpChr->info.alias) < 0) {
99cbc7
+            ignore_value(qemuDomainObjExitMonitor(driver, vm));
99cbc7
+            goto cleanup;
99cbc7
+        }
99cbc7
+    } else {
99cbc7
+        if (devstr && qemuMonitorDelDevice(priv->mon, tmpChr->info.alias) < 0) {
99cbc7
+            ignore_value(qemuDomainObjExitMonitor(driver, vm));
99cbc7
+            goto cleanup;
99cbc7
+        }
99cbc7
     }
99cbc7
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
99cbc7
         goto cleanup;
99cbc7
 
99cbc7
-    if (async) {
99cbc7
+    if (guestfwd) {
99cbc7
+        ret = qemuDomainRemoveChrDevice(driver, vm, tmpChr, false);
99cbc7
+    } else if (async) {
99cbc7
         ret = 0;
99cbc7
     } else {
99cbc7
         if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1)
99cbc7
-            ret = qemuDomainRemoveChrDevice(driver, vm, tmpChr);
99cbc7
+            ret = qemuDomainRemoveChrDevice(driver, vm, tmpChr, true);
99cbc7
     }
99cbc7
 
99cbc7
  cleanup:
99cbc7
-- 
99cbc7
2.21.0
99cbc7