From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 950151FF0B4 for ; Fri, 27 Nov 2026 11:40:46 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 410B4218E1; Fri, 27 Nov 2026 11:39:09 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.10.3 smtp.infra.comaite.com 0291462C0A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=comaite.com; s=377A38C6-3A8D-11E5-A0EC-E97757B27CB3; t=1795775318; bh=svVC+EgIOzvaEUkl2qt/7OpqAguChFFr4KkNukbFjxM=; h=From:To:Date:Message-ID:MIME-Version; b=nx66PyacK2w9jcYVeDCimi4EIJWOS0+Wj8IH0mixPxRdsa+Ms3VXmDwxfCuQeyJa1 JcSNHuLrgwyCl38RrxigsLFG4hf8k/B+O7MFiLuOVhbFnBLt8M/5OMF9ZTONQIt2z5 tBEs6hIaOhM4WsyJMdkUa4d96mqVX80PATGQLxRh9pjr3NLbUtFN6lxJNvJbPVQGoZ 6+VZN422GCCWg1Bc9LFrMW+ddXr+tI/FOtQa8O7dgnQK+mqT9UJe7ETypciAX7IpKO WKMvDaUPEyhkIXiI3OQvie78h3trJHPIMfoOTYbvGb69Hgp/L9GpTq17gcXF+lTBFP QjLgYNFGLz01w== From: =?UTF-8?q?R=C3=A9mi=20PAETA?= To: pve-devel@lists.proxmox.com Subject: [RFC PATCH v2 network 09/15] sdn: ovn: bind guest ports to the chassis of their node Date: Fri, 27 Nov 2026 11:28:30 +0100 Message-ID: <20261127102836.313797-10-remi.paeta@comaite.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261127102836.313797-1-remi.paeta@comaite.com> References: <20261127102836.313797-1-remi.paeta@comaite.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.631 Adjusted score from AWL reputation of From: address DKIM_SIGNED 0.1 Message has a DKIM or DK signature, not necessarily valid DKIM_VALID -0.1 Message has at least one valid DKIM or DK signature DKIM_VALID_AU -0.1 Message has a valid DKIM or DK signature from author's domain DKIM_VALID_EF -0.1 Message has a valid DKIM or DK signature from envelope-from domain DMARC_PASS -0.1 DMARC pass policy SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: DHVNJY3PGMFLOA27XMIPM4WLS6ABHJOE X-Message-ID-Hash: DHVNJY3PGMFLOA27XMIPM4WLS6ABHJOE X-MailFrom: remi.paeta@comaite.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: During a live migration, QEMU already runs on the destination node while the memory gets copied, so both ovn-controller instances see an interface for the logical switch port and keep claiming it from each other, every 500 ms, until the source releases it. Traffic goes to the wrong node in the meantime: 2 to 3 s of loss were measured, while QEMU reported a downtime of about 20 ms. Set the requested-chassis option of guest ports to the local node when plugging them. On the destination of a live migration, set it to both nodes with activation-strategy=rarp instead, as recommended by OVN for this case: the source stays the main chassis while the memory gets copied. qemu-server calls add_bridge_fdb on the destination right before resuming the guest, which binds the port to the destination only. QEMU keeps PVE_MIGRATED_FROM in its environment for its whole lifetime and passes it on to the script plugging hotplugged NICs, so it is only taken into account while the guest configuration is still on the source node, which qemu-server only moves once the memory is copied. requested-chassis refers to the chassis hostname, which Open vSwitch sets to the FQDN, so set it to the node name when configuring the chassis. With this, the loss went down to 0.4 to 0.8 s, close to the resolution of the probe used. Signed-off-by: Rémi PAETA --- Changes since v1: - only take PVE_MIGRATED_FROM into account while the guest configuration is still on the source node: QEMU keeps it in its environment, so NICs hotplugged after a migration were bound to two chassis and never activated - commit message: describe the source as the main chassis during the migration src/PVE/Network/SDN/Ovn.pm | 87 +++++++++++++++++++++++--- src/PVE/Network/SDN/Zones/OvnPlugin.pm | 15 ++++- src/test/run_test_ovn.pl | 82 +++++++++++++++++++++++- 3 files changed, 171 insertions(+), 13 deletions(-) diff --git a/src/PVE/Network/SDN/Ovn.pm b/src/PVE/Network/SDN/Ovn.pm index a2327c2..12e03ce 100644 --- a/src/PVE/Network/SDN/Ovn.pm +++ b/src/PVE/Network/SDN/Ovn.pm @@ -36,6 +36,9 @@ our $CONTROLLER_UNIT_FILE = '/usr/lib/systemd/system/ovn-controller.service'; our $CONTROLLER_DROPIN = '/run/systemd/system/ovn-controller.service.d/pve-sdn-ssl.conf'; our $SYSTEMCTL = '/usr/bin/systemctl'; +# guest configurations, per node +our $NODES_DIR = '/etc/pve/nodes'; + # external_ids keys tagging the objects managed by PVE. Northbound objects # without them are never touched, so the OVN deployment can be shared with # other consumers. @@ -46,7 +49,7 @@ my $EXT_VMID = 'pve-sdn-vmid'; my $EXT_MAC = 'pve-sdn-mac'; # chassis settings written to the local Open_vSwitch table -my @CHASSIS_KEYS = ('ovn-remote', 'ovn-encap-type', 'ovn-encap-ip', $EXT_CONTROLLER); +my @CHASSIS_KEYS = ('ovn-remote', 'ovn-encap-type', 'ovn-encap-ip', 'hostname', $EXT_CONTROLLER); =head3 ovn_controllers(\%running_cfg) @@ -694,16 +697,75 @@ sub port_vnet { return $output eq '' ? undef : $output; } -=head3 update_port($controller, $iface, $level, \%running_cfg, $vnetid, $mac) +=head3 chassis_commands($iface, $nodename, $migrated_from) + +Returns the C commands binding the logical switch port C<$iface> to +the chassis of the node C<$nodename>, so that no other chassis claims it. + +During a live migration from the node C<$migrated_from>, the port is bound to +both chassis, the source one staying the main one. The destination chassis only +gets the traffic of the port once the guest announces itself there (QEMU sends a +RARP after the switchover). Otherwise, both chassis keep claiming the port while +the memory gets copied, and traffic goes to the wrong node for seconds. + +=cut + +sub chassis_commands { + my ($iface, $nodename, $migrated_from) = @_; + + if (defined($migrated_from)) { + return [[ + 'set', + 'Logical_Switch_Port', + $iface, + "options:requested-chassis=$migrated_from,$nodename", + 'options:activation-strategy=rarp', + ]]; + } + + return [ + ['set', 'Logical_Switch_Port', $iface, "options:requested-chassis=$nodename"], + ['remove', 'Logical_Switch_Port', $iface, 'options', 'activation-strategy'], + ]; +} + +=head3 migration_source($iface) + +Returns the node that the guest of C<$iface> is being live migrated from, if +this node is the destination of an ongoing migration. + +qemu-server sets C before starting QEMU on the destination +node, and QEMU passes its environment on to the script plugging the interfaces +it hotplugs later on. The variable thus stays set after the migration, so it +only counts while the guest configuration is still on the source node, as +qemu-server only moves it once the memory is copied. The configuration file is +checked directly, as the plugging script does not load the cluster VM list. + +=cut + +sub migration_source { + my ($iface) = @_; + + my $source = $ENV{PVE_MIGRATED_FROM} or return undef; + my ($vmid) = $iface =~ m/^tap(\d+)i\d+$/ or return undef; + + return -f "$NODES_DIR/$source/qemu-server/$vmid.conf" ? $source : undef; +} + +=head3 update_port($controller, $iface, $level, \%running_cfg, $vnetid, $mac, $nodename) Sets the guest MAC C<$mac> and its IPAM IPs on the logical switch port C<$iface> according to the port security C<$level>, and records the MAC so that later syncs can update the port. +Also binds the port to the chassis of C<$nodename> only. qemu-server calls this +on the destination node when resuming a guest after a live migration, which +ends the binding to both chassis set up by C. + =cut sub update_port { - my ($controller, $iface, $level, $running_cfg, $vnetid, $mac) = @_; + my ($controller, $iface, $level, $running_cfg, $vnetid, $mac, $nodename) = @_; # Without an answer from the IPAM, only the MAC can be enforced: the guest # keeps its connectivity, and the next sync applies the IPs. @@ -716,19 +778,21 @@ sub update_port { port_addresses_commands($iface, $addresses, $port_security)->@*, # as written in the guest config, which is what the IPAM is keyed by ['set', 'Logical_Switch_Port', $iface, "external_ids:$EXT_MAC=$mac"], + chassis_commands($iface, $nodename)->@*, ], ); } -=head3 ensure_port($controllerid, $controller, $zoneid, $vnetid, $iface) +=head3 ensure_port($controllerid, $controller, $zoneid, $vnetid, $iface, $nodename, $migrated_from) Creates or updates the logical switch port of the guest interface C<$iface> on -the logical switch of C<$vnetid>, moving it over from another switch if needed. +the logical switch of C<$vnetid>, moving it over from another switch if needed, +and binds it to the chassis of C<$nodename>, see C. =cut sub ensure_port { - my ($controllerid, $controller, $zoneid, $vnetid, $iface) = @_; + my ($controllerid, $controller, $zoneid, $vnetid, $iface, $nodename, $migrated_from) = @_; eval { my $current_switch; @@ -748,6 +812,7 @@ sub ensure_port { my $external_ids = port_external_ids($controllerid, $zoneid, $vnetid, $iface); my $commands = port_commands($vnetid, $iface, $external_ids, $current_switch); + push @$commands, chassis_commands($iface, $nodename, $migrated_from)->@*; nbctl_transaction($controller, $commands); }; die "unable to create OVN logical switch port '$iface' on '$vnetid' - $@" if $@; @@ -841,20 +906,24 @@ sub parse_remote_ip { die "unable to parse OVN database connection '$first'\n"; } -=head3 chassis_settings($controllerid, $controller, $encap_ip) +=head3 chassis_settings($controllerid, $controller, $encap_ip, $nodename) Returns the external_ids to set in the local Open_vSwitch table so that ovn-controller joins the OVN deployment of C<$controller>. +The chassis hostname is set to the node name, which logical switch ports refer +to in their requested-chassis option. Open vSwitch would use the FQDN instead. + =cut sub chassis_settings { - my ($controllerid, $controller, $encap_ip) = @_; + my ($controllerid, $controller, $encap_ip, $nodename) = @_; return { 'ovn-remote' => $controller->{'sb-connection'}, 'ovn-encap-type' => $controller->{'encap-type'} // 'geneve', 'ovn-encap-ip' => $encap_ip, + hostname => $nodename, $EXT_CONTROLLER => $controllerid, }; } @@ -923,7 +992,7 @@ sub configure_chassis { uses_ssl($controller->{'sb-connection'}) ? $id : undef, $nodename, ); - my $settings = chassis_settings($id, $controller, $encap_ip); + my $settings = chassis_settings($id, $controller, $encap_ip, $nodename); run_command([ $VSCTL, @VSCTL_OPTS, diff --git a/src/PVE/Network/SDN/Zones/OvnPlugin.pm b/src/PVE/Network/SDN/Zones/OvnPlugin.pm index 6c78fc0..fded449 100644 --- a/src/PVE/Network/SDN/Zones/OvnPlugin.pm +++ b/src/PVE/Network/SDN/Zones/OvnPlugin.pm @@ -3,6 +3,7 @@ package PVE::Network::SDN::Zones::OvnPlugin; use v5.36; use PVE::Exception qw(raise_param_exc); +use PVE::INotify; use PVE::Network; use PVE::Network::SDN::Ovn; @@ -102,7 +103,13 @@ sub tap_plug { if !$controller; PVE::Network::SDN::Ovn::ensure_port( - $controllerid, $controller, $vnet->{zone}, $vnetid, $iface, + $controllerid, + $controller, + $vnet->{zone}, + $vnetid, + $iface, + PVE::INotify::nodename(), + PVE::Network::SDN::Ovn::migration_source($iface), ); # detach from any previous bridge @@ -114,8 +121,9 @@ sub tap_plug { die "VLAN tags and trunks are not supported on OVN vnet '$vnetid'\n" if $tag || $trunks; } -# Called by qemu-server on guest start and by pve-container on plug, with the -# guest MAC, which tap_plug does not get. +# Called by qemu-server on guest start and resume, including after a live +# migration, and by pve-container on plug, with the guest MAC, which tap_plug +# does not get. sub add_bridge_fdb { my ($class, $plugin_config, $iface, $macaddr) = @_; @@ -145,6 +153,7 @@ sub add_bridge_fdb { $running_config, $vnetid, $macaddr, + PVE::INotify::nodename(), ); }; warn "unable to set the addresses of OVN logical switch port '$iface' - $@" if $@; diff --git a/src/test/run_test_ovn.pl b/src/test/run_test_ovn.pl index ddf0f0a..7632bd9 100755 --- a/src/test/run_test_ovn.pl +++ b/src/test/run_test_ovn.pl @@ -5,6 +5,7 @@ use warnings; use lib qw(..); +use File::Path qw(make_path); use File::Temp qw(tempdir); use JSON; use Test::More; @@ -278,6 +279,82 @@ is_deeply( 'port_commands: port moved to another vnet', ); +is_deeply( + PVE::Network::SDN::Ovn::chassis_commands('tap100i0', 'node1'), + [ + ['set', 'Logical_Switch_Port', 'tap100i0', 'options:requested-chassis=node1'], + ['remove', 'Logical_Switch_Port', 'tap100i0', 'options', 'activation-strategy'], + ], + 'chassis_commands: bound to the local chassis', +); +is_deeply( + PVE::Network::SDN::Ovn::chassis_commands('tap100i0', 'node2', 'node1'), + [[ + 'set', + 'Logical_Switch_Port', + 'tap100i0', + 'options:requested-chassis=node1,node2', + 'options:activation-strategy=rarp', + ]], + 'chassis_commands: live migration, bound to both chassis until the guest announces itself', +); + +{ + local $ENV{PVE_MIGRATED_FROM}; + local $PVE::Network::SDN::Ovn::NODES_DIR = "$tmpdir/nodes"; + make_path("$tmpdir/nodes/node1/qemu-server", "$tmpdir/nodes/node2/qemu-server"); + is( + PVE::Network::SDN::Ovn::migration_source('tap100i0'), + undef, + 'migration_source: no migration', + ); + + $ENV{PVE_MIGRATED_FROM} = 'node1'; + PVE::Tools::file_set_contents("$tmpdir/nodes/node1/qemu-server/100.conf", ''); + is( + PVE::Network::SDN::Ovn::migration_source('tap100i0'), + 'node1', + 'migration_source: incoming migration, the configuration is still on the source', + ); + is(PVE::Network::SDN::Ovn::migration_source('veth100i0'), undef, 'migration_source: container'); + + rename( + "$tmpdir/nodes/node1/qemu-server/100.conf", "$tmpdir/nodes/node2/qemu-server/100.conf", + ); + is( + PVE::Network::SDN::Ovn::migration_source('tap100i0'), + undef, + 'migration_source: hotplug after a migration, QEMU kept the variable', + ); +} + +{ + my $transactions = []; + no warnings 'redefine'; + local *PVE::Network::SDN::Ovn::nbctl = sub { return '' }; + local *PVE::Network::SDN::Ovn::nbctl_transaction = sub { push @$transactions, $_[1] }; + + PVE::Network::SDN::Ovn::ensure_port( + 'ovnctl', $controller, 'zone1', 'vnet1', 'tap100i0', 'node2', 'node1', + ); + is_deeply( + $transactions->[0]->[-1], + PVE::Network::SDN::Ovn::chassis_commands('tap100i0', 'node2', 'node1')->[0], + 'ensure_port: binds the port to both chassis on an incoming migration', + ); + + $transactions = []; + local *PVE::Network::SDN::Ovn::guest_ips = sub { return [] }; + PVE::Network::SDN::Ovn::update_port( + $controller, 'tap100i0', 'off', {}, 'vnet1', 'BC:24:11:00:00:01', 'node2', + ); + is_deeply( + [$transactions->[0]->@[-2, -1]], + PVE::Network::SDN::Ovn::chassis_commands('tap100i0', 'node2'), + 'update_port: binds the port to the local chassis only', + ); +} + { no warnings 'redefine'; local *PVE::Network::SDN::Ovn::run_command = sub { @@ -644,11 +721,12 @@ is_deeply( ); is_deeply( - PVE::Network::SDN::Ovn::chassis_settings('ovnctl', $controller, '192.168.0.10'), + PVE::Network::SDN::Ovn::chassis_settings('ovnctl', $controller, '192.168.0.10', 'node1'), { 'ovn-remote' => $controller->{'sb-connection'}, 'ovn-encap-type' => 'geneve', 'ovn-encap-ip' => '192.168.0.10', + hostname => 'node1', 'pve-sdn-controller' => 'ovnctl', }, 'chassis_settings', @@ -682,6 +760,7 @@ is_deeply( 'set', 'Open_vSwitch', '.', + 'external_ids:hostname=node1', 'external_ids:ovn-encap-ip=192.168.0.10', 'external_ids:ovn-encap-type=geneve', "external_ids:ovn-remote=$controller->{'sb-connection'}", @@ -708,6 +787,7 @@ is_deeply( 'ovn-remote', 'ovn-encap-type', 'ovn-encap-ip', + 'hostname', 'pve-sdn-controller', ]], 'configure_chassis: detach chassis', -- 2.47.3