[pve-devel] [PATCH qemu-server 12/22] vm start: move state file handling to dedicated module
Fabian Grünbichler
f.gruenbichler at proxmox.com
Mon Jun 16 12:54:42 CEST 2025
> Fiona Ebner <f.ebner at proxmox.com> hat am 16.06.2025 12:34 CEST geschrieben:
>
>
> Am 13.06.25 um 12:00 schrieb Fabian Grünbichler:
> > On June 12, 2025 4:02 pm, Fiona Ebner wrote:
> >> @@ -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';
> >> - }
> >> - }
> >
> > I think this fallback here was already not needed..
> >
> > the migration type is always set in migration context, either via `qm
> > start` (intra-cluster) or via the start call over mtunnel (remote
> > migration).
>
> Okay, I can add a preparatory patch.
>
> > a few lines up we already have the assumptions the $statefile being set
> > implies $migration_type being set as well.
>
> What assumption do you mean? $statefile might also be set after
> hibernation for example and then there is no $migration_type.
5728 ($statefile && $statefile eq 'tcp' && $migration_type eq 'insecure')
$statefile set to *tcp*, sorry.
>
> >> 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';
> >> + }
> >> + }
> >
> > and here we can just assert that a type is set, instead of parsing
> > datacenter.cfg again and falling back..
>
> Why "again"? It is the very same fallback, just moved here.
again, because we already parsed it in get_migration_ip (the only other
sub in PVE::QemuServer::StateFile, which gets called in vm_start_nolock
right before this one here is).
More information about the pve-devel
mailing list