all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [pve-devel] [PATCH qemu-server v5 11/16] parse config: warn about duplicate sections
Date: Mon, 27 Jan 2025 12:29:18 +0100	[thread overview]
Message-ID: <20250127112923.31703-12-f.ebner@proxmox.com> (raw)
In-Reply-To: <20250127112923.31703-1-f.ebner@proxmox.com>

Currently, a duplicate section will quietly override the previous
instance of the section with the same identifier. Keep the current
behavior of preferring later entries, but issue a warning or die when
parsing strictly.

The entry for 'pending' in the result needs to start out as undefined
for the check to also work in presence of empty sections. Avoid
changing the returned value itself, by making sure to initialize the
entry before returning.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 PVE/QemuServer.pm                                      | 10 +++++++++-
 .../duplicate-sections.conf.strict.error               |  1 +
 2 files changed, 10 insertions(+), 1 deletion(-)
 create mode 100644 test/parse-config-expected/duplicate-sections.conf.strict.error

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 5a55e70e..8c26fbc3 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2202,7 +2202,7 @@ sub parse_vm_config {
     my $res = {
 	digest => Digest::SHA::sha1_hex($raw),
 	snapshots => {},
-	pending => {},
+	pending => undef,
 	'special-sections' => {},
     };
 
@@ -2242,17 +2242,23 @@ sub parse_vm_config {
 	if ($line =~ m/^\[PENDING\]\s*$/i) {
 	    $section = { name => 'pending', type => 'pending' };
 	    $finish_description->();
+	    $handle_error->("vm $vmid - duplicate section: $section->{name}\n")
+		if defined($res->{$section->{name}});
 	    $conf = $res->{$section->{name}} = {};
 	    next;
 	} elsif ($line =~ m/^\[special:$special_sections_re_1\]\s*$/i) {
 	    $section = { name => $1, type => 'special' };
 	    $finish_description->();
+	    $handle_error->("vm $vmid - duplicate special section: $section->{name}\n")
+		if defined($res->{'special-sections'}->{$section->{name}});
 	    $conf = $res->{'special-sections'}->{$section->{name}} = {};
 	    next;
 
 	} elsif ($line =~ m/^\[([a-z][a-z0-9_\-]+)\]\s*$/i) {
 	    $section = { name => $1, type => 'snapshot' };
 	    $finish_description->();
+	    $handle_error->("vm $vmid - duplicate snapshot section: $section->{name}\n")
+		if defined($res->{snapshots}->{$section->{name}});
 	    $conf = $res->{snapshots}->{$section->{name}} = {};
 	    next;
 	} elsif ($line =~ m/^\[([^\]]*)\]\s*$/i) {
@@ -2322,6 +2328,8 @@ sub parse_vm_config {
     $finish_description->();
     delete $res->{snapstate}; # just to be sure
 
+    $res->{pending} = {} if !defined($res->{pending});
+
     return $res;
 }
 
diff --git a/test/parse-config-expected/duplicate-sections.conf.strict.error b/test/parse-config-expected/duplicate-sections.conf.strict.error
new file mode 100644
index 00000000..f7aabfd7
--- /dev/null
+++ b/test/parse-config-expected/duplicate-sections.conf.strict.error
@@ -0,0 +1 @@
+vm 8006 - duplicate section: pending
-- 
2.39.5



_______________________________________________
pve-devel mailing list
pve-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pve-devel


  parent reply	other threads:[~2025-01-27 11:30 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-01-27 11:29 [pve-devel] [PATCH-SERIES qemu-server v5 00/16] more robust handling of fleecing images Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 01/16] migration: remove unused variable Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 02/16] test: avoid duplicate mock module in restore config test Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 03/16] test: add parse config tests Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 04/16] parse config: be precise about section type checks Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 05/16] test: add test case exposing issue with unknown sections Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 06/16] parse config: skip unknown sections and warn about their presence Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 07/16] vzdump: anchor matches for pending and special sections Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 08/16] vzdump: skip all " Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 09/16] config: make special section handling generic Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 10/16] test: parse config: test config with duplicate sections Fiona Ebner
2025-01-27 11:29 ` Fiona Ebner [this message]
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 12/16] check type: require schema as an argument Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 13/16] config: add fleecing section Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 14/16] fix #5440: vzdump: better cleanup fleecing images after hard errors Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 15/16] migration: attempt to clean up potential left-over fleecing images Fiona Ebner
2025-01-27 11:29 ` [pve-devel] [PATCH qemu-server v5 16/16] destroy vm: " Fiona Ebner
2025-03-07 10:45 ` [pve-devel] [PATCH-SERIES qemu-server v5 00/16] more robust handling of " Fiona Ebner
2025-04-07 13:11 ` [pve-devel] 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=20250127112923.31703-12-f.ebner@proxmox.com \
    --to=f.ebner@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal