[PATCH v3 11/12] qemu: handle detaching of unplugged hostdev

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



If hostdev is unplugged we don't need to delete it's correspondent device
from qemu etc. Just remove it from config immediately.

Signed-off-by: Nikolay Shirokovskiy <nshirokovskiy@xxxxxxxxxxxxx>
---
 src/qemu/qemu_hotplug.c | 16 +++++++++++++++-
 src/util/virhostdev.c   |  2 ++
 2 files changed, 17 insertions(+), 1 deletion(-)

diff --git a/src/qemu/qemu_hotplug.c b/src/qemu/qemu_hotplug.c
index 780bfde002..32ab581755 100644
--- a/src/qemu/qemu_hotplug.c
+++ b/src/qemu/qemu_hotplug.c
@@ -4528,6 +4528,7 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
     char *objAlias = NULL;
     bool is_vfio = false;
     bool unplug = hostdev->deleteAction == VIR_DOMAIN_HOSTDEV_DELETE_ACTION_UNPLUG;
+    bool unplugged = false;
 
     VIR_DEBUG("Removing host device %s from domain %p %s",
               hostdev->info->alias, vm, vm->def->name);
@@ -4586,13 +4587,17 @@ qemuDomainRemoveHostDevice(virQEMUDriverPtr driver,
 
     virDomainAuditHostdev(vm, hostdev, "detach", true);
 
+    if (hostdev->source.subsys.type == VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB) {
+        virDomainHostdevSubsysUSBPtr usbsrc = &hostdev->source.subsys.u.usb;
+        unplugged = !usbsrc->bus && !usbsrc->device;
+    }
     /*
      * In case of unplug the attempt to restore label will fail. But we don't
      * need to restore the label! In case of separate mount namespace for the
      * domain we remove device file later in this function. In case of global
      * mount namespace the device file is deleted or being deleted by systemd.
      */
-    if (!is_vfio && !unplug &&
+    if (!is_vfio && !unplug && !unplugged &&
         qemuSecurityRestoreHostdevLabel(driver, vm, hostdev) < 0)
         VIR_WARN("Failed to restore host device labelling");
 
@@ -5932,6 +5937,15 @@ qemuDomainDetachDeviceLive(virDomainObjPtr vm,
                                         unplug) < 0) {
             return -1;
         }
+        if (!unplug) {
+            virDomainHostdevDefPtr hostdev = detach.data.hostdev;
+            virDomainHostdevSubsysUSBPtr usbsrc = &hostdev->source.subsys.u.usb;
+
+            if (hostdev->startupPolicy != VIR_DOMAIN_STARTUP_POLICY_OPTIONAL &&
+                hostdev->startupPolicy != VIR_DOMAIN_STARTUP_POLICY_REQUISITE &&
+                usbsrc->device == 0 && usbsrc->bus == 0)
+                return qemuDomainRemoveDevice(driver, vm, &detach);
+        }
         break;
     case VIR_DOMAIN_DEVICE_RNG:
         if (qemuDomainDetachPrepRNG(vm, match->data.rng,
diff --git a/src/util/virhostdev.c b/src/util/virhostdev.c
index 41fcab7222..ed9bc09e14 100644
--- a/src/util/virhostdev.c
+++ b/src/util/virhostdev.c
@@ -1793,6 +1793,8 @@ virHostdevReAttachUSBDevices(virHostdevManagerPtr mgr,
             continue;
         if (hostdev->missing)
             continue;
+        if (!usbsrc->bus && !usbsrc->device)
+            continue;
 
         if (!(usb = virUSBDeviceNew(usbsrc->bus, usbsrc->device, NULL))) {
             VIR_WARN("Unable to reattach USB device %03d.%03d on domain %s",
-- 
2.23.0

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]

  Powered by Linux