The volume ID returned by parse_volume() is used here as opposed to
$conf->{$opt} used for regular mount points because $conf->{$opt} is not
necessarily a valid volume ID in this case. This distinction is
important because is_volume_in_use does internally not consider
'unused*' a valid volume key and does not check it. parse_volume knows
about 'unused*' and returns a valid volume ID.

No functional changes intended.

Originally-by: Stefan Hrdlicka <s.hrdli...@proxmox.com>
Signed-off-by: Michael Köppl <m.koe...@proxmox.com>
---
 src/PVE/LXC/Config.pm | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index 0740e8c..a7c1023 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -1557,15 +1557,20 @@ sub vmconfig_apply_pending {
     foreach my $opt (sort keys %$pending_delete_hash) {
        next if $selection && !$selection->{$opt};
        eval {
+           my $mp = $class->parse_volume($opt, $conf->{$opt});
+
            if ($opt =~ m/^mp(\d+)$/) {
-               my $mp = $class->parse_volume($opt, $conf->{$opt});
                if ($mp->{type} eq 'volume') {
                    $class->add_unused_volume($conf, $mp->{volume})
                        if !$class->is_volume_in_use($conf, $conf->{$opt}, 1, 
1);
                }
            } elsif ($opt =~ m/^unused(\d+)$/) {
+               # $mp->{volume} is used for is_volume_in_use() because 
parse_volume()
+               # knows about 'unused*' and will return a valid volume ID 
whereas
+               # $conf->{$opt} is not guaranteed to contain a valid volume ID 
in this
+               # case.
                PVE::LXC::delete_mountpoint_volume($storecfg, $vmid, 
$conf->{$opt})
-                   if !$class->is_volume_in_use($conf, $conf->{$opt}, 1, 1);
+                   if !$class->is_volume_in_use($conf, $mp->{volume}, 1, 1);
            } elsif ($opt =~ m/^net(\d+)$/) {
                if ($have_sdn) {
                    my $net = $class->parse_lxc_network($conf->{$opt});
-- 
2.39.5



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

Reply via email to