mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-08-07 08:58:16 +00:00
return spice_port from config_to_command()
That way we do not need to run qmp command to get the port. Set spice ticket expire time to 30 (5 seconds seems a bit too short). Coding style cleanups.
This commit is contained in:
parent
95a4b4a98b
commit
1d794448fc
@ -2455,12 +2455,13 @@ sub config_to_command {
|
|||||||
push @$devices, '-device', 'virtserialport,chardev=qga0,name=org.qemu.guest_agent.0';
|
push @$devices, '-device', 'virtserialport,chardev=qga0,name=org.qemu.guest_agent.0';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
my $spice_port;
|
||||||
if ($vga eq 'qxl') {
|
if ($vga eq 'qxl') {
|
||||||
my $pciaddr = print_pci_addr("spice", $bridges);
|
my $pciaddr = print_pci_addr("spice", $bridges);
|
||||||
|
|
||||||
my $port = PVE::Tools::next_unused_port(61000, 61099);
|
$spice_port = PVE::Tools::next_unused_port(61000, 61099);
|
||||||
|
|
||||||
push @$cmd, '-spice', "tls-port=$port,addr=127.0.0.1,tls-ciphers=DES-CBC3-SHA,seamless-migration=on";
|
push @$cmd, '-spice', "tls-port=${spice_port},addr=127.0.0.1,tls-ciphers=DES-CBC3-SHA,seamless-migration=on";
|
||||||
|
|
||||||
push @$cmd, '-device', "virtio-serial,id=spice$pciaddr";
|
push @$cmd, '-device', "virtio-serial,id=spice$pciaddr";
|
||||||
push @$cmd, '-chardev', "spicevmc,id=vdagent,name=vdagent";
|
push @$cmd, '-chardev', "spicevmc,id=vdagent,name=vdagent";
|
||||||
@ -2582,7 +2583,7 @@ sub config_to_command {
|
|||||||
push @$cmd, '-global', join(',', @$globalFlags)
|
push @$cmd, '-global', join(',', @$globalFlags)
|
||||||
if scalar(@$globalFlags);
|
if scalar(@$globalFlags);
|
||||||
|
|
||||||
return wantarray ? ($cmd, $vollist) : $cmd;
|
return wantarray ? ($cmd, $vollist, $spice_port) : $cmd;
|
||||||
}
|
}
|
||||||
|
|
||||||
sub vnc_socket {
|
sub vnc_socket {
|
||||||
@ -2593,7 +2594,7 @@ sub vnc_socket {
|
|||||||
sub spice_port {
|
sub spice_port {
|
||||||
my ($vmid) = @_;
|
my ($vmid) = @_;
|
||||||
|
|
||||||
my $res = vm_mon_cmd_nocheck($vmid, 'query-spice');
|
my $res = vm_mon_cmd($vmid, 'query-spice');
|
||||||
|
|
||||||
return $res->{'tls-port'} || $res->{'port'} || die "no spice port\n";
|
return $res->{'tls-port'} || $res->{'port'} || die "no spice port\n";
|
||||||
}
|
}
|
||||||
@ -3027,7 +3028,7 @@ sub qga_unfreezefs {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub vm_start {
|
sub vm_start {
|
||||||
my ($storecfg, $vmid, $statefile, $skiplock, $migratedfrom, $paused, $forcemachine) = @_;
|
my ($storecfg, $vmid, $statefile, $skiplock, $migratedfrom, $paused, $forcemachine, $spice_ticket) = @_;
|
||||||
|
|
||||||
lock_config($vmid, sub {
|
lock_config($vmid, sub {
|
||||||
my $conf = load_config($vmid, $migratedfrom);
|
my $conf = load_config($vmid, $migratedfrom);
|
||||||
@ -3043,7 +3044,7 @@ sub vm_start {
|
|||||||
# set environment variable useful inside network script
|
# set environment variable useful inside network script
|
||||||
$ENV{PVE_MIGRATED_FROM} = $migratedfrom if $migratedfrom;
|
$ENV{PVE_MIGRATED_FROM} = $migratedfrom if $migratedfrom;
|
||||||
|
|
||||||
my ($cmd, $vollist) = config_to_command($storecfg, $vmid, $conf, $defaults, $forcemachine);
|
my ($cmd, $vollist, $spice_port) = config_to_command($storecfg, $vmid, $conf, $defaults, $forcemachine);
|
||||||
|
|
||||||
my $migrate_port = 0;
|
my $migrate_port = 0;
|
||||||
|
|
||||||
@ -3085,22 +3086,22 @@ sub vm_start {
|
|||||||
warn $@ if $@;
|
warn $@ if $@;
|
||||||
}
|
}
|
||||||
|
|
||||||
if($migratedfrom) {
|
if ($migratedfrom) {
|
||||||
my $capabilities = {};
|
my $capabilities = {};
|
||||||
$capabilities->{capability} = "xbzrle";
|
$capabilities->{capability} = "xbzrle";
|
||||||
$capabilities->{state} = JSON::true;
|
$capabilities->{state} = JSON::true;
|
||||||
eval { vm_mon_cmd_nocheck($vmid, "migrate-set-capabilities", capabilities => [$capabilities]); };
|
eval { vm_mon_cmd_nocheck($vmid, "migrate-set-capabilities", capabilities => [$capabilities]); };
|
||||||
if($conf->{vga} eq 'qxl'){
|
warn $@ if $@;
|
||||||
my $spice_port = PVE::QemuServer::spice_port($vmid);
|
|
||||||
print "spice listens on port $spice_port\n" if $spice_port;
|
if ($spice_port) {
|
||||||
if($spiceticket){
|
print "spice listens on port $spice_port\n";
|
||||||
PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "set_password", protocol => 'spice', password => $spiceticket);
|
if ($spice_ticket) {
|
||||||
PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "expire_password", protocol => 'spice', time => "+5");
|
PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "set_password", protocol => 'spice', password => $spice_ticket);
|
||||||
|
PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "expire_password", protocol => 'spice', time => "+30");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
} else {
|
||||||
else{
|
|
||||||
|
|
||||||
if (!$statefile && (!defined($conf->{balloon}) || $conf->{balloon})) {
|
if (!$statefile && (!defined($conf->{balloon}) || $conf->{balloon})) {
|
||||||
vm_mon_cmd_nocheck($vmid, "balloon", value => $conf->{balloon}*1024*1024)
|
vm_mon_cmd_nocheck($vmid, "balloon", value => $conf->{balloon}*1024*1024)
|
||||||
|
Loading…
Reference in New Issue
Block a user