# test if container exists
my $conf = PVE::LXC::load_config($param->{vmid});
- my $realcmd = sub {
- my $cmd = ['lxc-destroy', '-n', $vmid ];
+ my $storage_cfg = cfs_read_file("storage.cfg");
- run_command($cmd);
+ my $code = sub {
+ if (my $volid = $conf->{'pve.volid'}) {
+
+ my ($vtype, $name, $owner) = PVE::Storage::parse_volname($storage_cfg, $volid);
+ die "got strange volid (containe is not owner!)\n" if $vmid != $owner;
+
+ PVE::Storage::vdisk_free($storage_cfg, $volid);
+
+ PVE::LXC::destroy_config($vmid);
+ } else {
+ my $cmd = ['lxc-destroy', '-n', $vmid ];
+
+ run_command($cmd);
+ }
+
PVE::AccessControl::remove_vm_from_pool($vmid);
};
+ my $realcmd = sub { PVE::LXC::lock_container($vmid, 1, $code); };
+
return $rpcenv->fork_worker('vzdestroy', $vmid, $authuser, $realcmd);
}});
},
'pve.comment' => 1,
'pve.disksize' => '\d+(\.\d+)?',
+ 'pve.volid' => sub {
+ my ($name, $value) = @_;
+ PVE::Storage::parse_volume_id($value);
+ return $value;
+ },
};
my $valid_lxc_network_keys = {
PVE::Tools::run_command(['mount', '-t', 'ext4', $loopdev, $tmp]);
$mountpoint = $tmp;
+ $conf->{'pve.volid'} = $volid;
restore_and_configure($vmid, $archive, $mountpoint, $conf, $password);
};
if (my $err = $@) {
PVE::Tools::run_command(['mount', '-t', 'ext4', $nbd_dev, $tmp]);
$mountpoint = $tmp;
+ $conf->{'pve.volid'} = $volid;
restore_and_configure($vmid, $archive, $mountpoint, $conf, $password);
};
if (my $err = $@) {