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 E71621FF0C0 for ; Wed, 21 Oct 2026 10:45:31 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 0549521653; Wed, 21 Oct 2026 10:45:11 +0200 (CEST) From: Hannes Laimer To: pve-devel@lists.proxmox.com Subject: [PATCH pve-network v4 05/20] sdn: ipam: write the lookup's cache entry under the cluster lock Date: Wed, 21 Oct 2026 10:44:30 +0200 Message-ID: <20261021084445.462195-6-h.laimer@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261021084445.462195-1-h.laimer@proxmox.com> References: <20261021084445.462195-1-h.laimer@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1792572306525 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.378 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust 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: DSJR5NIB4ZTI5VOWJHXKZSW2BFQT3UNP X-Message-ID-Hash: DSJR5NIB4ZTI5VOWJHXKZSW2BFQT3UNP X-MailFrom: h.laimer@proxmox.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: The lookup that stores the IPAM's answer wrote the whole cache back without the cluster lock the other writers take. A change made between its read and its write was lost. The lookup now takes the lock and reads the cache again before it stores its answer. Signed-off-by: Hannes Laimer --- Notes: v4: * new, split out of the MAC cache patch src/PVE/Network/SDN/Ipams.pm | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/PVE/Network/SDN/Ipams.pm b/src/PVE/Network/SDN/Ipams.pm index 79591ea0..3d849d79 100644 --- a/src/PVE/Network/SDN/Ipams.pm +++ b/src/PVE/Network/SDN/Ipams.pm @@ -142,8 +142,8 @@ sub complete_sdn_vnet { sub get_ips_from_mac { my ($mac, $zoneid, $zone) = @_; - my $macdb = read_macdb(); - return ($macdb->{macs}->{$mac}->{ip4}, $macdb->{macs}->{$mac}->{ip6}) if $macdb->{macs}->{$mac}; + my $cached = read_macdb()->{macs}->{$mac}; + return ($cached->{ip4}, $cached->{ip6}) if $cached; my $plugin_config = get_plugin_config($zone); my $plugin = PVE::Network::SDN::Ipams::Plugin->lookup($plugin_config->{type}); @@ -152,9 +152,17 @@ sub get_ips_from_mac { # an empty answer is not cached, since the record may simply not exist yet return if !defined($ip4) && !defined($ip6); - $macdb->{macs}->{$mac}->{ip4} = $ip4 if defined($ip4); - $macdb->{macs}->{$mac}->{ip6} = $ip6 if defined($ip6); - write_macdb($macdb); + cfs_lock_file( + $macdb_filename, + undef, + sub { + my $db = read_macdb(); + $db->{macs}->{$mac}->{ip4} = $ip4 if defined($ip4); + $db->{macs}->{$mac}->{ip6} = $ip6 if defined($ip6); + write_macdb($db); + }, + ); + warn "$@" if $@; return ($ip4, $ip6); } -- 2.47.3