]> git.ipfire.org Git - thirdparty/libvirt.git/commitdiff
qemu: Build activeUsbHostdevs list on process reconnect
authorMichal Privoznik <mprivozn@redhat.com>
Mon, 26 Mar 2012 14:44:19 +0000 (16:44 +0200)
committerMichal Privoznik <mprivozn@redhat.com>
Wed, 4 Apr 2012 13:09:41 +0000 (15:09 +0200)
If the daemon is restarted it will lose list of active
USB devices assigned to active domains. Therefore we need
to rebuild this list on qemuProcessReconnect().

src/qemu/qemu_hostdev.c
src/qemu/qemu_hostdev.h
src/qemu/qemu_process.c

index a8890ebfa7cd7b54c0f7f4d018d97ab94e223e2a..8594fb276638c707c0d6eafe97f1a1f146913aa4 100644 (file)
@@ -157,6 +157,46 @@ int qemuUpdateActivePciHostdevs(struct qemud_driver *driver,
     return 0;
 }
 
+int
+qemuUpdateActiveUsbHostdevs(struct qemud_driver *driver,
+                            virDomainDefPtr def)
+{
+    virDomainHostdevDefPtr hostdev = NULL;
+    int i;
+
+    if (!def->nhostdevs)
+        return 0;
+
+    for (i = 0; i < def->nhostdevs; i++) {
+        usbDevice *usb = NULL;
+        hostdev = def->hostdevs[i];
+
+        if (hostdev->mode != VIR_DOMAIN_HOSTDEV_MODE_SUBSYS)
+            continue;
+        if (hostdev->source.subsys.type != VIR_DOMAIN_HOSTDEV_SUBSYS_TYPE_USB)
+            continue;
+
+        usb = usbGetDevice(hostdev->source.subsys.u.usb.bus,
+                           hostdev->source.subsys.u.usb.device);
+        if (!usb) {
+            VIR_WARN("Unable to reattach USB device %03d.%03d on domain %s",
+                     hostdev->source.subsys.u.usb.bus,
+                     hostdev->source.subsys.u.usb.device,
+                     def->name);
+            continue;
+        }
+
+        usbDeviceSetUsedBy(usb, def->name);
+
+        if (usbDeviceListAdd(driver->activeUsbHostdevs, usb) < 0) {
+            usbFreeDevice(usb);
+            return -1;
+        }
+    }
+
+    return 0;
+}
+
 static int
 qemuDomainHostdevPciSysfsPath(virDomainHostdevDefPtr hostdev, char **sysfs_path)
 {
index 173e4f43cd7de8a763b318960dd2d07ac8565258..371630ab365d1f841c1c06e03f1d1260dc94d81b 100644 (file)
@@ -29,6 +29,8 @@
 
 int qemuUpdateActivePciHostdevs(struct qemud_driver *driver,
                                 virDomainDefPtr def);
+int qemuUpdateActiveUsbHostdevs(struct qemud_driver *driver,
+                                virDomainDefPtr def);
 int qemuPrepareHostdevPCIDevices(struct qemud_driver *driver,
                                  const char *name,
                                  const unsigned char *uuid,
index 9eed160559fc68ec481a92963f8e14ae4016da46..481b4f3db07755e48d12a2fce80a66eeec79da3e 100644 (file)
@@ -3057,6 +3057,9 @@ qemuProcessReconnect(void *opaque)
         goto error;
     }
 
+    if (qemuUpdateActiveUsbHostdevs(driver, obj->def) < 0)
+        goto error;
+
     if (qemuProcessUpdateState(driver, obj) < 0)
         goto error;