* [PATCH container] fix #7173: config: do not write out an empty tag list
@ 2026-11-09 13:56 Lucas Barros
0 siblings, 0 replies; only message in thread
From: Lucas Barros @ 2026-11-09 13:56 UTC (permalink / raw)
To: pve-devel
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
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-11-09 13:56 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-09 13:56 [PATCH container] fix #7173: config: do not write out an empty tag list Lucas Barros
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox