]> git.proxmox.com Git - pve-storage.git/commitdiff
free_image: correctly check if base volume is not used
authorDietmar Maurer <dietmar@proxmox.com>
Thu, 31 Jan 2013 10:36:49 +0000 (11:36 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Thu, 31 Jan 2013 10:36:49 +0000 (11:36 +0100)
moved parse_volume_id to PVE::Storage::Plugin::parse_volume_id

PVE/Storage.pm
PVE/Storage/Plugin.pm

index 710c7ae25a35879e42f5da7244cb2bcbd0935727..2260f063a77d74b330502707827cde4ab6a72ef9 100755 (executable)
@@ -257,15 +257,10 @@ sub parse_vmid {
     return int($vmid);
 }
 
-PVE::JSONSchema::register_format('pve-volume-id', \&parse_volume_id);
 sub parse_volume_id {
     my ($volid, $noerr) = @_;
 
-    if ($volid =~ m/^([a-z][a-z0-9\-\_\.]*[a-z0-9]):(.+)$/i) {
-       return wantarray ? ($1, $2) : $1;
-    }
-    return undef if $noerr;
-    die "unable to parse volume ID '$volid'\n";
+    return PVE::Storage::Plugin::parse_volume_id($volid, $noerr);
 }
 
 sub volume_is_base {
index effd02afeae46d77208447edbed74260e03b8b34..0cbf488e5ec3f9e4c7d1d3c0a358d8c8fdaad804 100644 (file)
@@ -178,6 +178,17 @@ sub verify_options {
     return $value;
 }
 
+PVE::JSONSchema::register_format('pve-volume-id', \&parse_volume_id);
+sub parse_volume_id {
+    my ($volid, $noerr) = @_;
+
+    if ($volid =~ m/^([a-z][a-z0-9\-\_\.]*[a-z0-9]):(.+)$/i) {
+       return wantarray ? ($1, $2) : $1;
+    }
+    return undef if $noerr;
+    die "unable to parse volume ID '$volid'\n";
+}
+
 
 sub private {
     return $defaultData;
@@ -545,10 +556,29 @@ sub free_image {
 
     if (! -f $path) {
        warn "disk image '$path' does not exists\n";
-    } else {
-       unlink $path;
+       return undef;
+    }
+
+    my ($vtype, $name, $vmid, undef, undef, $isBase) = 
+       $class->parse_volname($volname);
+
+    if ($isBase) {
+       my $vollist = $class->list_images($storeid, $scfg);
+       foreach my $info (@$vollist) {
+           my (undef, $tmpvolname) = parse_volume_id($info->{volid});
+
+           my (undef, undef, undef, $basename, $basevmid) = 
+               $class->parse_volname($tmpvolname);
+
+           if ($basename && $basevmid == $vmid && $basename eq $name) {
+               die "base volume '$volname' is still in use " .
+                   "(use by '$tmpvolname')\n";
+           }
+       }
     }
 
+    unlink $path;
+
     return undef;
 }