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 086EA1FF183
	for <inbox@lore.proxmox.com>; Wed, 18 Jun 2025 15:09:12 +0200 (CEST)
Received: from firstgate.proxmox.com (localhost [127.0.0.1])
	by firstgate.proxmox.com (Proxmox) with ESMTP id 7EADE13603;
	Wed, 18 Jun 2025 15:09:34 +0200 (CEST)
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Date: Wed, 18 Jun 2025 15:01:52 +0200
Message-Id: <20250618130209.90649-16-f.ebner@proxmox.com>
X-Mailer: git-send-email 2.39.5
In-Reply-To: <20250618130209.90649-1-f.ebner@proxmox.com>
References: <20250618130209.90649-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
 RCVD_IN_VALIDITY_CERTIFIED_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_RPBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 RCVD_IN_VALIDITY_SAFE_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to
 Validity was blocked. See
 https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more
 information.
 SPF_HELO_NONE           0.001 SPF: HELO does not publish an SPF Record
 SPF_PASS               -0.001 SPF: sender matches SPF record
 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See
 http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more
 information. [qemuserver.pm, statefile.pm]
Subject: [pve-devel] [PATCH qemu-server v2 15/32] 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>
---

Changes in v2:
* Re-do on top of change from patch 13/32.

 src/PVE/QemuServer.pm           | 49 ++++++++-------------------------
 src/PVE/QemuServer/StateFile.pm | 47 +++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+), 38 deletions(-)

diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index c1133eb8..442adde6 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -5946,8 +5946,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 $@;
@@ -6019,46 +6017,21 @@ sub vm_start_nolock {
             PVE::QemuServer::StateFile::get_migration_ip($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";
-
-            die "no migration type set\n" if !defined($migration_type);
-
-            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, $migration_type, $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/src/PVE/QemuServer/StateFile.pm b/src/PVE/QemuServer/StateFile.pm
index d2cdde46..3c26a9c6 100644
--- a/src/PVE/QemuServer/StateFile.pm
+++ b/src/PVE/QemuServer/StateFile.pm
@@ -29,4 +29,51 @@ 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, $migration_type, $migration_ip) = @_;
+
+    my $statefile_is_a_volume = 0;
+    my $res = {};
+    my $cmd = [];
+
+    if ($statefile eq 'tcp') {
+        my $migrate = $res->{migrate} = { proto => 'tcp' };
+        $migrate->{addr} = "localhost";
+
+        die "no migration type set\n" if !defined($migration_type);
+
+        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