free_image: correctly check if base volume is not used

moved parse_volume_id to PVE::Storage::Plugin::parse_volume_id
This commit is contained in:
Dietmar Maurer
2013-01-31 11:36:49 +01:00
parent 188aca388e
commit a7f3d90919
2 changed files with 33 additions and 8 deletions

View File

@ -257,15 +257,10 @@ sub parse_vmid {
return int($vmid); return int($vmid);
} }
PVE::JSONSchema::register_format('pve-volume-id', \&parse_volume_id);
sub parse_volume_id { sub parse_volume_id {
my ($volid, $noerr) = @_; my ($volid, $noerr) = @_;
if ($volid =~ m/^([a-z][a-z0-9\-\_\.]*[a-z0-9]):(.+)$/i) { return PVE::Storage::Plugin::parse_volume_id($volid, $noerr);
return wantarray ? ($1, $2) : $1;
}
return undef if $noerr;
die "unable to parse volume ID '$volid'\n";
} }
sub volume_is_base { sub volume_is_base {

View File

@ -178,6 +178,17 @@ sub verify_options {
return $value; 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 { sub private {
return $defaultData; return $defaultData;
@ -545,10 +556,29 @@ sub free_image {
if (! -f $path) { if (! -f $path) {
warn "disk image '$path' does not exists\n"; warn "disk image '$path' does not exists\n";
} else { return undef;
unlink $path;
} }
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; return undef;
} }