Detaching a mount point with a removed underlying storage causes it to
be labeled as an unused disk. With this change, removing an unused disk
with a removed underlying storage causes it to be removed from the
configuration instead of failing. Deleting the mount point is skipped in
this case to avoid failing and to allow removing the unused volume from
the CT configuration and to achieve behavior consistent with destroying
a CT.

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

diff --git a/src/PVE/LXC/Config.pm b/src/PVE/LXC/Config.pm
index a7c1023..8c96691 100644
--- a/src/PVE/LXC/Config.pm
+++ b/src/PVE/LXC/Config.pm
@@ -1470,11 +1470,17 @@ sub vmconfig_hotplug_pending {
     foreach my $opt (sort keys %$pending_delete_hash) {
        next if $selection && !$selection->{$opt};
        eval {
+           my $mp = $class->parse_volume($opt, $conf->{$opt});
+           my ($storeid, undef) = PVE::Storage::parse_volume_id($mp->{volume});
+
            if ($LXC_FASTPLUG_OPTIONS->{$opt}) {
                # pass
-           } elsif ($opt =~ m/^unused(\d+)$/) {
+           } elsif (
+               $opt =~ m/^unused(\d+)$/
+               && PVE::Storage::storage_config($storecfg, $storeid, 1)
+           ) {
                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 eq 'swap') {
                $hotplug_memory->(undef, 0);
            } elsif ($opt eq 'cpulimit') {
@@ -1558,13 +1564,17 @@ sub vmconfig_apply_pending {
        next if $selection && !$selection->{$opt};
        eval {
            my $mp = $class->parse_volume($opt, $conf->{$opt});
+           my ($storeid, undef) = PVE::Storage::parse_volume_id($mp->{volume});
 
            if ($opt =~ m/^mp(\d+)$/) {
                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+)$/) {
+           } elsif (
+               $opt =~ m/^unused(\d+)$/
+               && PVE::Storage::storage_config($storecfg, $storeid, 1)
+           ) {
                # $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
-- 
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