[pve-devel] [PATCH qemu-server 6/7] implement usb hotplug

Dominik Csapak d.csapak at proxmox.com
Tue Jun 14 10:50:40 CEST 2016


this patch introduces working usb hotplugging

you can now add a usb device while a vm is running

this does not work with spice at the moment, only
with usb passthrough

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
 PVE/QemuServer.pm | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 6834b33..abbec21 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -3265,6 +3265,10 @@ sub vm_deviceplug {
 
 	qemu_deviceadd($vmid, print_tabletdevice_full($conf));
 
+    } elsif ($deviceid =~ m/^usb(\d+)$/) {
+
+	qemu_deviceadd($vmid, PVE::QemuServer::USB::print_usbdevice_full($conf, $deviceid, $device));
+
     } elsif ($deviceid =~ m/^(virtio)(\d+)$/) {
 
 	qemu_iothread_add($vmid, $deviceid, $device);
@@ -3360,6 +3364,11 @@ sub vm_deviceunplug {
 
 	qemu_devicedel($vmid, $deviceid);
 
+    } elsif ($deviceid =~ m/^usb\d+$/) {
+
+	qemu_devicedel($vmid, $deviceid);
+	qemu_devicedelverify($vmid, $deviceid);
+
     } elsif ($deviceid =~ m/^(virtio)(\d+)$/) {
 
         qemu_devicedel($vmid, $deviceid);
@@ -3894,6 +3903,9 @@ sub vmconfig_hotplug_pending {
 		} else {
 		    vm_deviceunplug($vmid, $conf, $opt);
 		}
+	    } elsif ($opt =~ m/^usb\d+/) {
+		die "skip\n" if !$hotplug_features->{usb} || $conf->{$opt} =~ m/spice/i;
+		vm_deviceunplug($vmid, $conf, $opt);
 	    } elsif ($opt eq 'vcpus') {
 		die "skip\n" if !$hotplug_features->{cpu};
 		qemu_cpu_hotplug($vmid, $conf, undef);
@@ -3944,6 +3956,11 @@ sub vmconfig_hotplug_pending {
 		} elsif ($value == 0) {
 		    vm_deviceunplug($vmid, $conf, $opt);
 		}
+	    } elsif ($opt =~ m/^usb\d+$/) {
+		die "skip\n" if !$hotplug_features->{usb} || $value =~ m/spice/i;
+		my $d = eval { PVE::JSONSchema::parse_property_string($usbdesc->{format}, $value) };
+		die "skip\n" if !$d;
+		qemu_usb_hotplug($storecfg, $conf, $vmid, $opt, $d);
 	    } elsif ($opt eq 'vcpus') {
 		die "skip\n" if !$hotplug_features->{cpu};
 		qemu_cpu_hotplug($vmid, $conf, $value);
-- 
2.1.4




More information about the pve-devel mailing list