hotplug/unplug tablet on config update

Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
This commit is contained in:
Alexandre Derumier 2013-02-18 13:44:34 +01:00 committed by Dietmar Maurer
parent 42869ac07d
commit cd6ecb89eb
2 changed files with 25 additions and 2 deletions

View File

@ -649,6 +649,8 @@ my $vmconfig_delete_option = sub {
die "error hot-unplug $opt" if !PVE::QemuServer::vm_deviceunplug($vmid, $conf, $opt); 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) { if ($isDisk) {
my $drive = PVE::QemuServer::parse_drive($opt, $conf->{$opt}); my $drive = PVE::QemuServer::parse_drive($opt, $conf->{$opt});
&$delete_drive($conf, $storecfg, $vmid, $opt, $drive, $force); &$delete_drive($conf, $storecfg, $vmid, $opt, $drive, $force);
@ -910,6 +912,12 @@ __PACKAGE__->register_method({
} else { } 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}; $conf->{$opt} = $param->{$opt};
PVE::QemuServer::update_config_nolock($vmid, $conf, 1); PVE::QemuServer::update_config_nolock($vmid, $conf, 1);
} }

View File

@ -2511,7 +2511,15 @@ sub vm_devices_list {
sub vm_deviceplug { sub vm_deviceplug {
my ($storecfg, $conf, $vmid, $deviceid, $device) = @_; 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); my $devices_list = vm_devices_list($vmid);
return 1 if defined($devices_list->{$deviceid}); return 1 if defined($devices_list->{$deviceid});
@ -2571,7 +2579,14 @@ sub vm_deviceplug {
sub vm_deviceunplug { sub vm_deviceunplug {
my ($vmid, $conf, $deviceid) = @_; 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); my $devices_list = vm_devices_list($vmid);
return 1 if !defined($devices_list->{$deviceid}); return 1 if !defined($devices_list->{$deviceid});