]> git.proxmox.com Git - pve-container.git/commitdiff
save volid inside config, so that we can cleanly destroy the container
authorDietmar Maurer <dietmar@proxmox.com>
Mon, 27 Apr 2015 07:24:37 +0000 (09:24 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 27 Apr 2015 07:24:37 +0000 (09:24 +0200)
src/PVE/API2/LXC.pm
src/PVE/LXC.pm
src/PVE/LXCCreate.pm

index 25510c9d4d2fee698c2efac76b80288ed4f177d4..b1aaf2213d9d276202ee4c99166bed492968f8b0 100644 (file)
@@ -563,14 +563,29 @@ __PACKAGE__->register_method({
        # 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);
     }});
 
index b9e7b1c69792927318ae992d742b96295b3fd04d..72f8c8027dd78658b3bae91b24351fab7b610849 100644 (file)
@@ -117,6 +117,11 @@ my $valid_lxc_keys = {
     },
     '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 = {
index 33074f15273c074cf10155d9244fc31a69dca8d3..a36b153eb6a534c2d9081d3bd098bdd880d33c53 100644 (file)
@@ -116,6 +116,7 @@ sub create_rootfs_dir_loop {
        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 = $@) {
@@ -164,6 +165,7 @@ sub create_rootfs_dir_qemu {
        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 = $@) {