[pve-devel] [PATCH 2/2] hotplug/unplug tablet on config update

Alexandre Derumier aderumier at odiso.com
Mon Feb 18 13:44:34 CET 2013


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 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 cabe2cf..71d39a9 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 3546d1d..21368cd 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});
-- 
1.7.10.4




More information about the pve-devel mailing list