default => 0,
optional => 1,
},
+ 'destroy-unreferenced-disks' => {
+ type => 'boolean',
+ description => "If set, destroy additionally all disks with the VMID from all"
+ ." enabled storages which are not referenced in the config.",
+ optional => 1,
+ },
},
},
returns => {
}
my $storage_cfg = cfs_read_file("storage.cfg");
- PVE::LXC::destroy_lxc_container($storage_cfg, $vmid, $conf, { lock => 'destroyed' });
+ PVE::LXC::destroy_lxc_container(
+ $storage_cfg,
+ $vmid,
+ $conf,
+ { lock => 'destroyed' },
+ $param->{'destroy-unreferenced-disks'},
+ );
PVE::AccessControl::remove_vm_access($vmid);
PVE::Firewall::remove_vmfw_conf($vmid);
}
sub destroy_lxc_container {
- my ($storage_cfg, $vmid, $conf, $replacement_conf) = @_;
+ my ($storage_cfg, $vmid, $conf, $replacement_conf, $purge_unreferenced) = @_;
PVE::LXC::Config->foreach_volume_full($conf, {include_unused => 1}, sub {
my ($ms, $mountpoint) = @_;
delete_mountpoint_volume($storage_cfg, $vmid, $mountpoint->{volume});
});
+ if ($purge_unreferenced) { # also remove unreferenced disk
+ my $vmdisks = PVE::Storage::vdisk_list($storage_cfg, undef, $vmid);
+ PVE::Storage::foreach_volid($vmdisks, sub {
+ my ($volid, $sid, $volname, $d) = @_;
+ eval { PVE::Storage::vdisk_free($storage_cfg, $volid) };
+ warn $@ if $@;
+ });
+ }
+
rmdir "/var/lib/lxc/$vmid/rootfs";
unlink "/var/lib/lxc/$vmid/config";
rmdir "/var/lib/lxc/$vmid";