[pve-devel] [PATCH v4 10/14] vmconfig_hotplug_pending: implement tablet hotplug

Dietmar Maurer dietmar at proxmox.com
Fri Nov 21 11:46:22 CET 2014


Remove special case: now, we only hotplug if 'hotplug' is enabled.

Signed-off-by: Dietmar Maurer <dietmar at proxmox.com>
---
 PVE/QemuServer.pm |   71 ++++++++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 59 insertions(+), 12 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index e43a228..2ac72e6 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2974,7 +2974,6 @@ sub vm_devices_list {
     my ($vmid) = @_;
 
     my $res = vm_mon_cmd($vmid, 'query-pci');
-
     my $devices = {};
     foreach my $pcibus (@$res) {
 	foreach my $device (@{$pcibus->{devices}}) {
@@ -2990,6 +2989,14 @@ sub vm_devices_list {
 	}
     }
 
+    my $resmice = vm_mon_cmd($vmid, 'query-mice');
+    foreach my $mice (@$resmice) {
+	if ($mice->{name} eq 'QEMU HID Tablet') {
+	    $devices->{tablet} = 1;
+	    last;
+	}
+    }
+
     return $devices;
 }
 
@@ -3000,16 +3007,16 @@ sub vm_deviceplug {
 
     my $q35 = machine_type_is_q35($conf);
 
-    if ($deviceid eq 'tablet') {
-	qemu_deviceadd($vmid, print_tabletdevice_full($conf));
-	return 1;
-    }
-
     return 1 if !$conf->{hotplug};
 
     my $devices_list = vm_devices_list($vmid);
     return 1 if defined($devices_list->{$deviceid});
 
+    if ($deviceid eq 'tablet') {
+	qemu_deviceadd($vmid, print_tabletdevice_full($conf));
+	return 1;
+    }
+
     qemu_bridgeadd($storecfg, $conf, $vmid, $deviceid); #add bridge if we need it for the device
 
     if ($deviceid =~ m/^(virtio)(\d+)$/) {
@@ -3067,16 +3074,16 @@ sub vm_deviceunplug {
 
     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});
 
+    if ($deviceid eq 'tablet') {
+	qemu_devicedel($vmid, $deviceid);
+	return 1;
+    }
+
     die "can't unplug bootdisk" if $conf->{bootdisk} && $conf->{bootdisk} eq $deviceid;
 
     if ($deviceid =~ m/^(virtio)(\d+)$/) {
@@ -3478,8 +3485,48 @@ sub vmconfig_hotplug_pending {
 
     return if !$conf->{hotplug};
 
-    # fixme: implement disk/network hotplug here
+    my @delete = PVE::Tools::split_list($conf->{pending}->{delete});
+    foreach my $opt (@delete) { 
+	if ($opt eq 'tablet') {
+	    if ($defaults->{tablet}) {
+		PVE::QemuServer::vm_deviceplug($storecfg, $conf, $vmid, $opt);
+	    } else {
+		PVE::QemuServer::vm_deviceunplug($vmid, $conf, $opt);
+	    }
+	} else {
+	    # skip non-hot-pluggable options
+	    next;
+	}
+
+	# save new config if hotplug was successful
+	delete $conf->{$opt};
+	vmconfig_undelete_pending_option($conf, $opt);
+	update_config_nolock($vmid, $conf, 1);
+
+	$conf = load_config($vmid); # update/reload
+    }
 
+    foreach my $opt (keys %{$conf->{pending}}) {
+	my $value = $conf->{pending}->{$opt};
+
+	if ($opt eq 'tablet') {
+	    if ($value == 1) {
+		PVE::QemuServer::vm_deviceplug($storecfg, $conf, $vmid, $opt);
+	    } elsif ($value == 0) {
+		PVE::QemuServer::vm_deviceunplug($vmid, $conf, $opt);
+	    }
+	} else {
+	    # skip non-hot-pluggable options
+	    next;
+	}
+
+	# save new config if hotplug was successful
+	$conf->{$opt} = $value;
+	delete $conf->{pending}->{$opt};
+	update_config_nolock($vmid, $conf, 1);
+
+	$conf = load_config($vmid); # update/reload
+    }
 }
 
 sub vmconfig_apply_pending {
-- 
1.7.10.4




More information about the pve-devel mailing list