]> git.proxmox.com Git - pve-container.git/commitdiff
add mountpoint deletion support and unused volumes
authorWolfgang Bumiller <w.bumiller@proxmox.com>
Thu, 1 Oct 2015 08:58:30 +0000 (10:58 +0200)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 1 Oct 2015 09:33:27 +0000 (11:33 +0200)
Like with qemu, deleting a mountpoint now adds an unused
disk, which when deleted will now also delete the underlying
volume.

src/PVE/LXC.pm

index 8463cc335f97438a8b464c469107250bcf5d889c..1b27f34a04ba39e1260c9798c09649a5968293c3 100644 (file)
@@ -344,6 +344,12 @@ my $mp_desc = {
 };
 PVE::JSONSchema::register_format('pve-ct-mountpoint', $mp_desc);
 
+my $unuseddesc = {
+    optional => 1,
+    type => 'string', format => 'pve-volume-id',
+    description => "Reference to unused volumes.",
+};
+
 my $MAX_MOUNT_POINTS = 10;
 for (my $i = 0; $i < $MAX_MOUNT_POINTS; $i++) {
     $confdesc->{"mp$i"} = {
@@ -354,6 +360,11 @@ for (my $i = 0; $i < $MAX_MOUNT_POINTS; $i++) {
     };
 }
 
+my $MAX_UNUSED_DISKS = $MAX_MOUNT_POINTS;
+for (my $i = 0; $i < $MAX_MOUNT_POINTS; $i++) {
+    $confdesc->{"unused$i"} = $unuseddesc;
+}
+
 sub write_pct_config {
     my ($filename, $conf) = @_;
 
@@ -1150,12 +1161,33 @@ sub verify_searchdomain_list {
     return join(' ', @list);
 }
 
+sub add_unused_volume {
+    my ($config, $volid) = @_;
+
+    my $key;
+    for (my $ind = $MAX_UNUSED_DISKS - 1; $ind >= 0; $ind--) {
+       my $test = "unused$ind";
+       if (my $vid = $config->{$test}) {
+           return if $vid eq $volid; # do not add duplicates
+       } else {
+           $key = $test;
+       }
+    }
+
+    die "To many unused volume - please delete them first.\n" if !$key;
+
+    $config->{$key} = $volid;
+
+    return $key;
+}
+
 sub update_pct_config {
     my ($vmid, $conf, $running, $param, $delete) = @_;
 
     my @nohotplug;
 
     my $new_disks = 0;
+    my @deleted_volumes;
 
     my $rootdir;
     if ($running) {
@@ -1184,8 +1216,16 @@ sub update_pct_config {
                PVE::Network::veth_delete("veth${vmid}i$netid");
            } elsif ($opt eq 'protection') {
                delete $conf->{$opt};
+           } elsif ($opt =~ m/^unused(\d+)$/) {
+               check_protection($conf, "can't remove CT $vmid drive '$opt'");
+               push @deleted_volumes, $conf->{$opt};
+               delete $conf->{$opt};
+               push @nohotplug, $opt;
+               next if $running;
            } elsif ($opt =~ m/^mp(\d+)$/) {
                check_protection($conf, "can't remove CT $vmid drive '$opt'");
+               my $mountpoint = parse_ct_mountpoint($conf->{$opt});
+               add_unused_volume($conf, $mountpoint->{volume});
                delete $conf->{$opt};
                push @nohotplug, $opt;
                next if $running;
@@ -1276,6 +1316,13 @@ sub update_pct_config {
        die "unable to modify " . join(',', @nohotplug) . " while container is running\n";
     }
 
+    if (@deleted_volumes) {
+       my $storage_cfg = PVE::Storage::config();
+       foreach my $volume (@deleted_volumes) {
+           delete_mountpoint_volume($storage_cfg, $vmid, $volume);
+       }
+    }
+
     if ($new_disks) {
        my $storage_cfg = PVE::Storage::config();
        create_disks($storage_cfg, $vmid, $conf, $conf);