public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Lucas Barros <lucasbarros.kam@gmail.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH container] fix #7173: config: do not write out an empty tag list
Date: Mon,  9 Nov 2026 10:56:40 -0300	[thread overview]
Message-ID: <20261109135640.94964-1-lucasbarros.kam@gmail.com> (raw)

Removing the last tag of a container, for example in the web UI, sets
'tags' to an empty string, which then ends up as an empty 'tags:' line
in the container config and in the output of 'pct config'. This
carries no information, is inconsistent with how unset options are
handled and confuses tools that consume the config, as they need to
special case an empty tag list.

Drop the key when writing the config if the tag list is empty, which
also cleans up configs that already contain such a line on the next
write. The pending section is left alone, as an empty value there is
still needed to apply the change.

Signed-off-by: Lucas Barros <lucasbarros.kam@gmail.com>
---
A matching patch for qemu-server is sent separately.

Only the main section is touched, the pending section keeps an empty
value so that applying the change still removes the tags.

Tested on a PVE 9 node (qemu-server 9.2.15, pve-container 6.1.18),
adding and then removing the only tag of a VM and of a container:

without the patches:
  $ qm set 9901 --tags foo; pvesh set /nodes/<node>/qemu/9901/config --tags ''
  $ grep -n tags /etc/pve/qemu-server/9901.conf | cat -A
  6:tags:  $
  $ pct set 9902 --tags foo; pct set 9902 --tags ''
  $ grep -n tags /etc/pve/lxc/9902.conf | cat -A
  7:tags: $
  $ pvesh get /nodes/<node>/qemu/9901/config --output-format json | jq -c '{tags}'
  {"tags":" "}

with the patches:
  $ grep -c tags /etc/pve/qemu-server/9901.conf /etc/pve/lxc/9902.conf
  /etc/pve/qemu-server/9901.conf:0
  /etc/pve/lxc/9902.conf:0
  $ pvesh get /nodes/<node>/qemu/9901/config --output-format json | jq -c '{tags}'
  {"tags":null}

An existing empty 'tags:' line goes away on the next write of the
config, removing the tag of a running VM leaves no line and no
[PENDING] entry, and 'tags: a;b' is still written as before.

The pve-container test suite passes before and after; it has no tests
for writing the config. proxmox-perltidy reports no changes.

This patch was prepared with the help of an LLM based coding assistant;
I reviewed the change and ran the tests mentioned above myself.

 src/PVE/LXC/Config.pm | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index 13ff1bd..00da15b 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -1222,6 +1222,9 @@ sub write_pct_config {
 
     delete $conf->{snapstate}; # just to be sure
 
+    # an empty tag list carries no information, so do not write out the key
+    delete $conf->{tags} if defined($conf->{tags}) && $conf->{tags} =~ m/^[\s,;]*$/;
+
     my $volidlist = PVE::LXC::Config->get_vm_volumes($conf);
     my $used_volids = {};
     foreach my $vid (@$volidlist) {
-- 
2.47.3




                 reply	other threads:[~2026-11-09 13:56 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261109135640.94964-1-lucasbarros.kam@gmail.com \
    --to=lucasbarros.kam@gmail.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