render / rpms / libvirt

Forked from rpms/libvirt 10 months ago
Clone
c480ed
From a86cb3601add390b718377be021128fc18e4c9b2 Mon Sep 17 00:00:00 2001
c480ed
Message-Id: <a86cb3601add390b718377be021128fc18e4c9b2@dist-git>
c480ed
From: Michal Privoznik <mprivozn@redhat.com>
c480ed
Date: Thu, 27 Jun 2019 14:44:47 +0200
c480ed
Subject: [PATCH] qemu_hotplug: Detach guestfwd using netdev_del
c480ed
c480ed
The guestfwd channels are -netdevs really. Hotunplug them as
c480ed
such. Also, DEVICE_DELETED event is not triggered (surprisingly,
c480ed
since we're not issuing device_del rather than netdev_del) and
c480ed
associated chardev is removed automagically too. This means that
c480ed
we need to do qemuDomainRemoveChrDevice() minus monitor call to
c480ed
remove the chardev.
c480ed
c480ed
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
c480ed
Reviewed-by: John Ferlan <jferlan@redhat.com>
c480ed
(cherry picked from commit 112f3a8d0f324c0705326957cca4508602b25eba)
c480ed
c480ed
https://bugzilla.redhat.com/show_bug.cgi?id=1624204
c480ed
c480ed
Signed-off-by: Michal Privoznik <mprivozn@redhat.com>
c480ed
Message-Id: <de45d53975997bcdbb4260055664a7b0a0079bbe.1561639408.git.mprivozn@redhat.com>
c480ed
Reviewed-by: Jiri Denemark <jdenemar@redhat.com>
c480ed
---
c480ed
 src/qemu/qemu_hotplug.c | 48 ++++++++++++++++++++++++++++-------------
c480ed
 1 file changed, 33 insertions(+), 15 deletions(-)
c480ed
c480ed
diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
c480ed
index 468389fa7a..05489cf116 100644
c480ed
--- a/src/qemu/qemu_hotplug.c
c480ed
+++ b/src/qemu/qemu_hotplug.c
c480ed
@@ -4355,25 +4355,28 @@ qemuDomainRemoveNetDevice(virQEMUDriverPtr driver,
c480ed
 static int
c480ed
 qemuDomainRemoveChrDevice(virQEMUDriverPtr driver,
c480ed
                           virDomainObjPtr vm,
c480ed
-                          virDomainChrDefPtr chr)
c480ed
+                          virDomainChrDefPtr chr,
c480ed
+                          bool monitor)
c480ed
 {
c480ed
     virObjectEventPtr event;
c480ed
     char *charAlias = NULL;
c480ed
     qemuDomainObjPrivatePtr priv = vm->privateData;
c480ed
     int ret = -1;
c480ed
-    int rc;
c480ed
+    int rc = 0;
c480ed
 
c480ed
     VIR_DEBUG("Removing character device %s from domain %p %s",
c480ed
               chr->info.alias, vm, vm->def->name);
c480ed
 
c480ed
-    if (!(charAlias = qemuAliasChardevFromDevAlias(chr->info.alias)))
c480ed
-        goto cleanup;
c480ed
+    if (monitor) {
c480ed
+        if (!(charAlias = qemuAliasChardevFromDevAlias(chr->info.alias)))
c480ed
+            goto cleanup;
c480ed
 
c480ed
-    qemuDomainObjEnterMonitor(driver, vm);
c480ed
-    rc = qemuMonitorDetachCharDev(priv->mon, charAlias);
c480ed
+        qemuDomainObjEnterMonitor(driver, vm);
c480ed
+        rc = qemuMonitorDetachCharDev(priv->mon, charAlias);
c480ed
 
c480ed
-    if (qemuDomainObjExitMonitor(driver, vm) < 0)
c480ed
-        goto cleanup;
c480ed
+        if (qemuDomainObjExitMonitor(driver, vm) < 0)
c480ed
+            goto cleanup;
c480ed
+    }
c480ed
 
c480ed
     if (rc == 0 &&
c480ed
         qemuDomainDelChardevTLSObjects(driver, vm, chr->source, charAlias) < 0)
c480ed
@@ -4674,7 +4677,7 @@ qemuDomainRemoveDevice(virQEMUDriverPtr driver,
c480ed
         break;
c480ed
 
c480ed
     case VIR_DOMAIN_DEVICE_CHR:
c480ed
-        ret = qemuDomainRemoveChrDevice(driver, vm, dev->data.chr);
c480ed
+        ret = qemuDomainRemoveChrDevice(driver, vm, dev->data.chr, true);
c480ed
         break;
c480ed
     case VIR_DOMAIN_DEVICE_RNG:
c480ed
         ret = qemuDomainRemoveRNGDevice(driver, vm, dev->data.rng);
c480ed
@@ -5749,6 +5752,7 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver,
c480ed
     virDomainDefPtr vmdef = vm->def;
c480ed
     virDomainChrDefPtr tmpChr;
c480ed
     char *devstr = NULL;
c480ed
+    bool guestfwd = false;
c480ed
 
c480ed
     if (!(tmpChr = virDomainChrFind(vmdef, chr))) {
c480ed
         virReportError(VIR_ERR_DEVICE_MISSING,
c480ed
@@ -5758,6 +5762,11 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver,
c480ed
         goto cleanup;
c480ed
     }
c480ed
 
c480ed
+    /* guestfwd channels are not really -device rather than
c480ed
+     * -netdev. We need to treat them slightly differently. */
c480ed
+    guestfwd = tmpChr->deviceType == VIR_DOMAIN_CHR_DEVICE_TYPE_CHANNEL &&
c480ed
+               tmpChr->targetType == VIR_DOMAIN_CHR_CHANNEL_TARGET_TYPE_GUESTFWD;
c480ed
+
c480ed
     if (!tmpChr->info.alias && qemuAssignDeviceChrAlias(vmdef, tmpChr, -1) < 0)
c480ed
         goto cleanup;
c480ed
 
c480ed
@@ -5766,22 +5775,31 @@ int qemuDomainDetachChrDevice(virQEMUDriverPtr driver,
c480ed
     if (qemuBuildChrDeviceStr(&devstr, vmdef, tmpChr, priv->qemuCaps) < 0)
c480ed
         goto cleanup;
c480ed
 
c480ed
-    if (!async)
c480ed
+    if (!async && !guestfwd)
c480ed
         qemuDomainMarkDeviceForRemoval(vm, &tmpChr->info);
c480ed
 
c480ed
     qemuDomainObjEnterMonitor(driver, vm);
c480ed
-    if (devstr && qemuMonitorDelDevice(priv->mon, tmpChr->info.alias) < 0) {
c480ed
-        ignore_value(qemuDomainObjExitMonitor(driver, vm));
c480ed
-        goto cleanup;
c480ed
+    if (guestfwd) {
c480ed
+        if (qemuMonitorRemoveNetdev(priv->mon, tmpChr->info.alias) < 0) {
c480ed
+            ignore_value(qemuDomainObjExitMonitor(driver, vm));
c480ed
+            goto cleanup;
c480ed
+        }
c480ed
+    } else {
c480ed
+        if (devstr && qemuMonitorDelDevice(priv->mon, tmpChr->info.alias) < 0) {
c480ed
+            ignore_value(qemuDomainObjExitMonitor(driver, vm));
c480ed
+            goto cleanup;
c480ed
+        }
c480ed
     }
c480ed
     if (qemuDomainObjExitMonitor(driver, vm) < 0)
c480ed
         goto cleanup;
c480ed
 
c480ed
-    if (async) {
c480ed
+    if (guestfwd) {
c480ed
+        ret = qemuDomainRemoveChrDevice(driver, vm, tmpChr, false);
c480ed
+    } else if (async) {
c480ed
         ret = 0;
c480ed
     } else {
c480ed
         if ((ret = qemuDomainWaitForDeviceRemoval(vm)) == 1)
c480ed
-            ret = qemuDomainRemoveChrDevice(driver, vm, tmpChr);
c480ed
+            ret = qemuDomainRemoveChrDevice(driver, vm, tmpChr, true);
c480ed
     }
c480ed
 
c480ed
  cleanup:
c480ed
-- 
c480ed
2.22.0
c480ed