From cd6ecb89eb5591e2912b5d04db43e2752a515477 Mon Sep 17 00:00:00 2001 From: Alexandre Derumier Date: Mon, 18 Feb 2013 13:44:34 +0100 Subject: [PATCH] hotplug/unplug tablet on config update Signed-off-by: Alexandre Derumier --- PVE/API2/Qemu.pm | 8 ++++++++ PVE/QemuServer.pm | 19 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm index cabe2cf4..71d39a90 100644 --- a/PVE/API2/Qemu.pm +++ b/PVE/API2/Qemu.pm @@ -649,6 +649,8 @@ my $vmconfig_delete_option = sub { die "error hot-unplug $opt" if !PVE::QemuServer::vm_deviceunplug($vmid, $conf, $opt); + PVE::QemuServer::vm_deviceplug(undef, $conf, $vmid, $opt) if $opt eq 'tablet'; + if ($isDisk) { my $drive = PVE::QemuServer::parse_drive($opt, $conf->{$opt}); &$delete_drive($conf, $storecfg, $vmid, $opt, $drive, $force); @@ -910,6 +912,12 @@ __PACKAGE__->register_method({ } else { + if($opt eq 'tablet' && $param->{$opt} == 1){ + PVE::QemuServer::vm_deviceplug(undef, $conf, $vmid, $opt); + }elsif($opt eq 'tablet' && $param->{$opt} == 0){ + PVE::QemuServer::vm_deviceunplug($vmid, $conf, $opt); + } + $conf->{$opt} = $param->{$opt}; PVE::QemuServer::update_config_nolock($vmid, $conf, 1); } diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 3546d1d8..21368cdf 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -2511,7 +2511,15 @@ sub vm_devices_list { sub vm_deviceplug { my ($storecfg, $conf, $vmid, $deviceid, $device) = @_; - return 1 if !check_running($vmid) || !$conf->{hotplug}; + return 1 if !check_running($vmid); + + if ($deviceid eq 'tablet') { + my $devicefull = "usb-tablet,id=tablet,bus=ehci.0,port=6"; + qemu_deviceadd($vmid, $devicefull); + return 1; + } + + return 1 if !$conf->{hotplug}; my $devices_list = vm_devices_list($vmid); return 1 if defined($devices_list->{$deviceid}); @@ -2571,7 +2579,14 @@ sub vm_deviceplug { sub vm_deviceunplug { my ($vmid, $conf, $deviceid) = @_; - return 1 if !check_running ($vmid) || !$conf->{hotplug}; + return 1 if !check_running ($vmid); + + if ($deviceid eq 'tablet') { + qemu_devicedel($vmid, $deviceid); + return 1; + } + + return 1 if!$conf->{hotplug}; my $devices_list = vm_devices_list($vmid); return 1 if !defined($devices_list->{$deviceid});