public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
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	[thread overview]
Message-ID: <20261021084445.462195-6-h.laimer@proxmox.com> (raw)
In-Reply-To: <20261021084445.462195-1-h.laimer@proxmox.com>

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 <h.laimer@proxmox.com>
---

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





  parent reply	other threads:[~2026-10-21  8:45 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-21  8:44 [PATCH container/docs/manager/network/proxmox{-ebpf,-perl-rs,-ve-rs}/qemu-server v4 00/20] sdn: implement DHCP for all zones using eBPF Hannes Laimer
2026-10-21  8:44 ` [PATCH proxmox-ebpf v4 01/20] dhcp: add the per-tap DHCPv4 responder program Hannes Laimer
2026-10-21  8:44 ` [PATCH proxmox-ebpf v4 02/20] dhcp: add the subsystem that loads the responder and keeps its records Hannes Laimer
2026-10-21  8:44 ` [PATCH proxmox-perl-rs v4 03/20] pve-rs: sdn: add bindings for the eBPF DHCP responder Hannes Laimer
2026-10-21  8:44 ` [PATCH pve-network v4 04/20] sdn: ipam: stop caching IPAM misses Hannes Laimer
2026-10-21  8:44 ` Hannes Laimer [this message]
2026-10-21  8:44 ` [PATCH pve-network v4 06/20] sdn: ipam: key the MAC cache by lower-case MAC Hannes Laimer
2026-10-21  8:44 ` [PATCH pve-network v4 07/20] sdn: dhcp: replace a stale dnsmasq reservation instead of dropping it Hannes Laimer
2026-10-21  8:44 ` [PATCH pve-network v4 08/20] sdn: dhcp: update reservations when ip mappings change Hannes Laimer
2026-10-21  8:44 ` [PATCH pve-network v4 09/20] sdn: dhcp: make the lease time configurable per subnet Hannes Laimer
2026-10-21  8:44 ` [PATCH pve-network v4 10/20] sdn: dhcp: require a backend only if a zone on this node uses it Hannes Laimer
2026-10-21  8:44 ` [PATCH pve-network v4 11/20] sdn: dhcp: add an eBPF backend answering on each guest interface Hannes Laimer
2026-10-21  8:44 ` [PATCH pve-network v4 12/20] sdn: zones: report interface plugs and unplugs to the DHCP backends Hannes Laimer
2026-10-21  8:44 ` [PATCH pve-network v4 13/20] sdn: dhcp: run IP mapping edits on the guest's node Hannes Laimer
2026-10-21  8:44 ` [PATCH pve-network v4 14/20] sdn: zones: allow the ebpf DHCP backend on every zone type Hannes Laimer
2026-10-21  8:44 ` [PATCH qemu-server v4 15/20] network: sdn: keep the DHCP backends current on guest NICs Hannes Laimer
2026-10-21  8:44 ` [PATCH pve-container v4 16/20] net: report NIC plugs and removals to the SDN DHCP backends Hannes Laimer
2026-10-21  8:44 ` [PATCH pve-manager v4 17/20] ui: sdn: add zone DHCP backend selector and subnet DHCP options Hannes Laimer
2026-10-21  8:44 ` [PATCH pve-manager v4 18/20] sdn: bring up the DHCP backends at boot before the guests start Hannes Laimer
2026-10-21  8:44 ` [PATCH proxmox-ve-rs v4 19/20] ve-config: sdn: add the ebpf dhcp backend Hannes Laimer
2026-10-21  8:44 ` [PATCH pve-docs v4 20/20] sdn: dhcp: add eBPF backend section Hannes Laimer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261021084445.462195-6-h.laimer@proxmox.com \
    --to=h.laimer@proxmox.com \
    --cc=pve-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal