From 16521d63538139aa6ae31d10b4321084960fe274 Mon Sep 17 00:00:00 2001 From: Dominik Csapak Date: Tue, 14 Jun 2016 10:50:39 +0200 Subject: [PATCH] add qemu_usb_hotplug this adds a function for hotplugging usb devices Signed-off-by: Dominik Csapak --- PVE/QemuServer.pm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index c97e6f11..2dd00fdb 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -3598,6 +3598,31 @@ sub qemu_netdevdel { vm_mon_cmd($vmid, "netdev_del", id => $deviceid); } +sub qemu_usb_hotplug { + my ($storecfg, $conf, $vmid, $deviceid, $device) = @_; + + return if !$device; + + # remove the old one first + vm_deviceunplug($vmid, $conf, $deviceid); + + # check if xhci controller is necessary and available + if ($device->{usb3}) { + + my $devicelist = vm_devices_list($vmid); + + if (!$devicelist->{xhci}) { + my $pciaddr = print_pci_addr("xhci"); + qemu_deviceadd($vmid, "nec-usb-xhci,id=xhci$pciaddr"); + } + } + my $d = parse_usb_device($device->{host}); + $d->{usb3} = $device->{usb3}; + + # add the new one + vm_deviceplug($storecfg, $conf, $vmid, $deviceid, $d); +} + sub qemu_cpu_hotplug { my ($vmid, $conf, $vcpus) = @_; -- 2.39.5