From 4eb686043552f755c9d66e529b49614fa20f315e Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Tue, 14 Jun 2016 10:50:40 +0200 Subject: [PATCH] implement usb hotplug 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 --- PVE/QemuServer.pm | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 2dd00fdb..b6ad27a6 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -3271,6 +3271,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); @@ -3366,6 +3370,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); @@ -3900,6 +3909,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); @@ -3950,6 +3962,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.39.5