public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Stefan Hanreich <s.hanreich@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server 5/6] restore: add missing MAC addresses of the backup config
Date: Tue, 24 Nov 2026 15:56:49 +0100	[thread overview]
Message-ID: <20261124145651.335234-6-s.hanreich@proxmox.com> (raw)
In-Reply-To: <20261124145651.335234-1-s.hanreich@proxmox.com>

A restore without 'unique' takes over the network devices of the backup
config as they are, so a device without a MAC address stays without one
until the VM is started.

Add the missing MAC addresses when restoring the config, so that the
restored config is complete right away. Existing ones are kept, as
without 'unique' the restored VM should have the same addresses as the
backed up one.

Signed-off-by: Stefan Hanreich <s.hanreich@proxmox.com>
---
 src/PVE/QemuServer.pm                     |  3 +++
 src/test/run_qemu_restore_config_tests.pl | 18 ++++++++++++++++++
 2 files changed, 21 insertions(+)

diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 1e4fe203..7e940e33 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -6692,6 +6692,9 @@ sub restore_update_config_line {
         $net->{macaddr} = PVE::Tools::random_ether_addr($dc->{mac_prefix}) if $net->{macaddr};
         $netstr = PVE::QemuServer::Network::print_net($net);
         $res .= "$id: $netstr\n";
+    } elsif ($line =~ m/^(net\d+):\s*(\S+)\s*$/) {
+        # a backup can have network devices without a MAC address
+        $res .= "$1: " . PVE::QemuServer::Network::add_missing_mac($2) . "\n";
     } elsif ($line =~ m/^((ide|scsi|virtio|sata|efidisk|tpmstate)\d+):\s*(\S+)\s*$/) {
         my $virtdev = $1;
         my $value = $3;
diff --git a/src/test/run_qemu_restore_config_tests.pl b/src/test/run_qemu_restore_config_tests.pl
index 851f0a0d..3ab81fab 100755
--- a/src/test/run_qemu_restore_config_tests.pl
+++ b/src/test/run_qemu_restore_config_tests.pl
@@ -77,6 +77,24 @@ dir_glob_foreach(
     },
 );
 
+subtest 'missing MAC addresses of the backup are added' => sub {
+    my $restore_line = sub {
+        my ($line, $unique) = @_;
+        return PVE::QemuServer::restore_update_config_line({ netcount => 0 }, {}, $line,
+            $unique);
+    };
+
+    my $with_mac = "net0: virtio=BC:24:11:00:00:01,bridge=vmbr0,firewall=1\n";
+    is($restore_line->($with_mac, 0), $with_mac, 'line with a MAC address is kept');
+
+    my $restored = $restore_line->("net1: virtio,bridge=vmbr0,firewall=1\n", 0);
+    my ($net1) = $restored =~ m/^net1: (.*)\n\z/;
+    my $net = PVE::QemuServer::Network::parse_net($net1, 1);
+    like($net->{macaddr}, qr/^[0-9A-F]{2}(?::[0-9A-F]{2}){5}$/i,
+        'missing MAC address is added');
+    is($net->{firewall}, 1, 'other properties are kept');
+};
+
 # Restores through the create API and the restore paths for PBS, backup providers, VMA and legacy
 # tar archives, against the fake cluster filesystem. Storage, archive tools and other external
 # effects are mocked. The backups have no disks, so that no volumes get allocated.
-- 
2.47.3





  parent reply	other threads:[~2026-11-24 14:57 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-24 14:56 [PATCH container/manager/qemu-server 0/6] persist auto-generated MAC addresses of guest network devices Stefan Hanreich
2026-11-24 14:56 ` [PATCH pve-container 1/6] setup: do not read datacenter.cfg inside the container's root Stefan Hanreich
2026-11-24 14:56 ` [PATCH pve-container 2/6] start: persist a MAC address for network devices without one Stefan Hanreich
2026-11-24 18:06   ` Dominik Csapak
2026-11-24 14:56 ` [PATCH pve-container 3/6] restore: add missing MAC addresses of the backup config Stefan Hanreich
2026-11-24 14:56 ` [PATCH qemu-server 4/6] start: persist a MAC address for network devices without one Stefan Hanreich
2026-11-24 18:06   ` Dominik Csapak
2026-11-24 14:56 ` Stefan Hanreich [this message]
2026-11-24 14:56 ` [PATCH pve-manager 6/6] ui: lxc: network: handle network devices without a MAC address Stefan Hanreich
2026-11-24 18:06 ` [PATCH container/manager/qemu-server 0/6] persist auto-generated MAC addresses of guest network devices Dominik Csapak
2026-11-24 18:38   ` Dominik Csapak
2026-11-24 19:09   ` Stefan Hanreich
2026-11-24 23:45 ` applied: " Thomas Lamprecht

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=20261124145651.335234-6-s.hanreich@proxmox.com \
    --to=s.hanreich@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