From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: <pve-devel-bounces@lists.proxmox.com> Received: from firstgate.proxmox.com (firstgate.proxmox.com [IPv6:2a01:7e0:0:424::9]) by lore.proxmox.com (Postfix) with ESMTPS id 02A091FF170 for <inbox@lore.proxmox.com>; Thu, 12 Jun 2025 16:03:27 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 4E0B11F28A; Thu, 12 Jun 2025 16:03:06 +0200 (CEST) From: Fiona Ebner <f.ebner@proxmox.com> To: pve-devel@lists.proxmox.com Date: Thu, 12 Jun 2025 16:02:43 +0200 Message-Id: <20250612140253.106555-13-f.ebner@proxmox.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20250612140253.106555-1-f.ebner@proxmox.com> References: <20250612140253.106555-1-f.ebner@proxmox.com> MIME-Version: 1.0 X-SPAM-LEVEL: Spam detection results: 0 AWL -0.032 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Subject: [pve-devel] [PATCH qemu-server 12/22] vm start: move state file handling to dedicated module X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion <pve-devel.lists.proxmox.com> List-Unsubscribe: <https://lists.proxmox.com/cgi-bin/mailman/options/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=unsubscribe> List-Archive: <http://lists.proxmox.com/pipermail/pve-devel/> List-Post: <mailto:pve-devel@lists.proxmox.com> List-Help: <mailto:pve-devel-request@lists.proxmox.com?subject=help> List-Subscribe: <https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel>, <mailto:pve-devel-request@lists.proxmox.com?subject=subscribe> Reply-To: Proxmox VE development discussion <pve-devel@lists.proxmox.com> Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: pve-devel-bounces@lists.proxmox.com Sender: "pve-devel" <pve-devel-bounces@lists.proxmox.com> Signed-off-by: Fiona Ebner <f.ebner@proxmox.com> --- PVE/QemuServer.pm | 56 +++++++------------------------------ PVE/QemuServer/StateFile.pm | 56 +++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+), 46 deletions(-) diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm index 91b55cf9..25ba709d 100644 --- a/PVE/QemuServer.pm +++ b/PVE/QemuServer.pm @@ -5577,8 +5577,6 @@ sub vm_start_nolock { my $migration_type = $migrate_opts->{type}; my $nbd_protocol_version = $migrate_opts->{nbd_proto_version} // 0; - my $res = {}; - # clean up leftover reboot request files eval { clear_reboot_request($vmid); }; warn $@ if $@; @@ -5649,54 +5647,20 @@ sub vm_start_nolock { $nodename, $migrate_opts->{network}); } + my $res = {}; + my $statefile_is_a_volume; + my $state_cmdline = []; if ($statefile) { - if ($statefile eq 'tcp') { - my $migrate = $res->{migrate} = { proto => 'tcp' }; - $migrate->{addr} = "localhost"; - my $datacenterconf = PVE::Cluster::cfs_read_file('datacenter.cfg'); - my $nodename = nodename(); - - if (!defined($migration_type)) { - if (defined($datacenterconf->{migration}->{type})) { - $migration_type = $datacenterconf->{migration}->{type}; - } else { - $migration_type = 'secure'; - } - } - - if ($migration_type eq 'insecure') { - $migrate->{addr} = $migration_ip // die "internal error - no migration IP"; - $migrate->{addr} = "[$migrate->{addr}]" if Net::IP::ip_is_ipv6($migrate->{addr}); - } - - # see #4501: port reservation should be done close to usage - tell QEMU where to listen - # via QMP later - push @$cmd, '-incoming', 'defer'; - push @$cmd, '-S'; - - } elsif ($statefile eq 'unix') { - # should be default for secure migrations as a ssh TCP forward - # tunnel is not deterministic reliable ready and fails regurarly - # to set up in time, so use UNIX socket forwards - my $migrate = $res->{migrate} = { proto => 'unix' }; - $migrate->{addr} = "/run/qemu-server/$vmid.migrate"; - unlink $migrate->{addr}; - - $migrate->{uri} = "unix:$migrate->{addr}"; - push @$cmd, '-incoming', $migrate->{uri}; - push @$cmd, '-S'; - - } elsif (-e $statefile) { - push @$cmd, '-loadstate', $statefile; - } else { - my $statepath = PVE::Storage::path($storecfg, $statefile); - push @$vollist, $statefile; - push @$cmd, '-loadstate', $statepath; - } + ($state_cmdline, $res->{migrate}, $statefile_is_a_volume) = + PVE::QemuServer::StateFile::statefile_cmdline_option( + $storecfg, $vmid, $statefile, $migrate_opts, $migration_ip); + push @$vollist, $statefile if $statefile_is_a_volume; } elsif ($params->{paused}) { - push @$cmd, '-S'; + $state_cmdline = ['-S']; } + push $cmd->@*, $state_cmdline->@*; + my $memory = get_current_memory($conf->{memory}); my $start_timeout = $params->{timeout} // config_aware_timeout($conf, $memory, $resume); diff --git a/PVE/QemuServer/StateFile.pm b/PVE/QemuServer/StateFile.pm index e297839b..630ccca3 100644 --- a/PVE/QemuServer/StateFile.pm +++ b/PVE/QemuServer/StateFile.pm @@ -29,4 +29,60 @@ sub get_migration_ip { return PVE::Cluster::remote_node_ip($nodename, 1); } +# $migration_ip must be defined if using insecure TCP migration +sub statefile_cmdline_option { + my ($storecfg, $vmid, $statefile, $migrate_opts, $migration_ip) = @_; + + my $migration_type = $migrate_opts->{type}; + + my $statefile_is_a_volume = 0; + my $res = {}; + my $cmd = []; + + if ($statefile eq 'tcp') { + my $migrate = $res->{migrate} = { proto => 'tcp' }; + $migrate->{addr} = "localhost"; + my $datacenterconf = PVE::Cluster::cfs_read_file('datacenter.cfg'); + + if (!defined($migration_type)) { + if (defined($datacenterconf->{migration}->{type})) { + $migration_type = $datacenterconf->{migration}->{type}; + } else { + $migration_type = 'secure'; + } + } + + if ($migration_type eq 'insecure') { + $migrate->{addr} = $migration_ip // die "internal error - no migration IP"; + $migrate->{addr} = "[$migrate->{addr}]" if Net::IP::ip_is_ipv6($migrate->{addr}); + } + + # see #4501: port reservation should be done close to usage - tell QEMU where to listen + # via QMP later + push @$cmd, '-incoming', 'defer'; + push @$cmd, '-S'; + + } elsif ($statefile eq 'unix') { + # should be default for secure migrations as a ssh TCP forward + # tunnel is not deterministic reliable ready and fails regurarly + # to set up in time, so use UNIX socket forwards + my $migrate = $res->{migrate} = { proto => 'unix' }; + $migrate->{addr} = "/run/qemu-server/$vmid.migrate"; + unlink $migrate->{addr}; + + $migrate->{uri} = "unix:$migrate->{addr}"; + push @$cmd, '-incoming', $migrate->{uri}; + push @$cmd, '-S'; + + } elsif (-e $statefile) { + push @$cmd, '-loadstate', $statefile; + } else { + my $statepath = PVE::Storage::path($storecfg, $statefile); + $statefile_is_a_volume = 1; + push @$cmd, '-loadstate', $statepath; + } + + return ($cmd, $res->{migrate}, $statefile_is_a_volume); +} + 1; -- 2.39.5 _______________________________________________ pve-devel mailing list pve-devel@lists.proxmox.com https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel