diff --git a/src/PVE/QemuMigrate.pm b/src/PVE/QemuMigrate.pm index e18cc2aa..4381b542 100644 --- a/src/PVE/QemuMigrate.pm +++ b/src/PVE/QemuMigrate.pm @@ -998,6 +998,10 @@ sub phase2_start_local_cluster { push @$cmd, '--force-cpu', $start->{forcecpu}; } + if ($start->{'nets-host-mtu'}) { + push @$cmd, '--nets-host-mtu', $start->{'nets-host-mtu'}; + } + if ($self->{storage_migration}) { push @$cmd, '--targetstorage', ($self->{opts}->{targetstorage} // '1'); } @@ -1187,6 +1191,10 @@ sub phase2 { }, }; + if (my $nets_host_mtu = PVE::QemuServer::Network::get_nets_host_mtu($vmid, $conf)) { + $params->{start_params}->{'nets-host-mtu'} = $nets_host_mtu; + } + my ($tunnel_info, $spice_port); my @online_local_volumes = $self->filter_local_volumes('online'); diff --git a/src/PVE/QemuServer/Network.pm b/src/PVE/QemuServer/Network.pm index 56df83fb..eb8222e8 100644 --- a/src/PVE/QemuServer/Network.pm +++ b/src/PVE/QemuServer/Network.pm @@ -11,6 +11,8 @@ use PVE::Network::SDN::Zones; use PVE::RESTEnvironment qw(log_warn); use PVE::Tools qw($IPV6RE file_read_firstline); +use PVE::QemuServer::Monitor qw(mon_cmd); + my $nic_model_list = [ 'e1000', 'e1000-82540em', @@ -330,4 +332,31 @@ sub tap_plug { PVE::Network::SDN::Zones::tap_plug($iface, $bridge, $tag, $firewall, $trunks, $rate); } +sub get_nets_host_mtu { + my ($vmid, $conf) = @_; + + my $nets_host_mtu = []; + for my $opt (sort keys $conf->%*) { + next if $opt !~ m/^net(\d+)$/; + my $net = parse_net($conf->{$opt}); + next if $net->{model} ne 'virtio'; + + my $host_mtu = eval { + mon_cmd( + $vmid, 'qom-get', + path => "/machine/peripheral/$opt", + property => 'host_mtu', + ); + }; + if (my $err = $@) { + log_warn("$opt: could not query host_mtu - $err"); + } elsif (defined($host_mtu)) { + push $nets_host_mtu->@*, "${opt}=${host_mtu}"; + } else { + log_warn("$opt: got undefined value when querying host_mtu"); + } + } + return join(',', $nets_host_mtu->@*); +} + 1; diff --git a/src/test/MigrationTest/QemuMigrateMock.pm b/src/test/MigrationTest/QemuMigrateMock.pm index b04cf78b..421f0bb7 100644 --- a/src/test/MigrationTest/QemuMigrateMock.pm +++ b/src/test/MigrationTest/QemuMigrateMock.pm @@ -225,6 +225,21 @@ $qemu_server_machine_module->mock( my $qemu_server_network_module = Test::MockModule->new("PVE::QemuServer::Network"); $qemu_server_network_module->mock( del_nets_bridge_fdb => sub { return; }, + mon_cmd => sub { + my ($vmid, $command, %params) = @_; + + if ($command eq 'qom-get') { + if ( + $params{path} =~ m|^/machine/peripheral/net\d+$| + && $params{property} eq 'host_mtu' + ) { + return 1500; + } + die "mon_cmd (mocked) - implement me: $command for path '$params{path}' property" + . " '$params{property}'"; + } + die "mon_cmd (mocked) - implement me: $command"; + }, ); my $qemu_server_qmphelpers_module = Test::MockModule->new("PVE::QemuServer::QMPHelpers");