check base image use count inside vdisk_free
To make it work with all storage types.
This commit is contained in:
@ -520,7 +520,26 @@ sub vdisk_free {
|
||||
|
||||
# lock shared storage
|
||||
$plugin->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub {
|
||||
my $cleanup_worker = $plugin->free_image($storeid, $scfg, $volname);
|
||||
|
||||
my ($vtype, $name, $vmid, undef, undef, $isBase) =
|
||||
$plugin->parse_volname($volname);
|
||||
|
||||
if ($isBase) {
|
||||
my $vollist = $plugin->list_images($storeid, $scfg);
|
||||
foreach my $info (@$vollist) {
|
||||
my (undef, $tmpvolname) = parse_volume_id($info->{volid});
|
||||
|
||||
my (undef, undef, undef, $basename, $basevmid) =
|
||||
$plugin->parse_volname($tmpvolname);
|
||||
|
||||
if ($basename && $basevmid == $vmid && $basename eq $name) {
|
||||
die "base volume '$volname' is still in use " .
|
||||
"(use by '$tmpvolname')\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
my $cleanup_worker = $plugin->free_image($storeid, $scfg, $volname, $isBase);
|
||||
});
|
||||
|
||||
return if !$cleanup_worker;
|
||||
|
||||
@ -116,7 +116,7 @@ sub alloc_image {
|
||||
}
|
||||
|
||||
sub free_image {
|
||||
my ($class, $storeid, $scfg, $volname) = @_;
|
||||
my ($class, $storeid, $scfg, $volname, $isBase) = @_;
|
||||
|
||||
die "can't free space in iscsi storage\n";
|
||||
}
|
||||
|
||||
@ -302,7 +302,7 @@ sub alloc_image {
|
||||
}
|
||||
|
||||
sub free_image {
|
||||
my ($class, $storeid, $scfg, $volname) = @_;
|
||||
my ($class, $storeid, $scfg, $volname, $isBase) = @_;
|
||||
|
||||
die "can't free space in iscsi storage\n";
|
||||
}
|
||||
|
||||
@ -287,7 +287,7 @@ sub alloc_image {
|
||||
}
|
||||
|
||||
sub free_image {
|
||||
my ($class, $storeid, $scfg, $volname) = @_;
|
||||
my ($class, $storeid, $scfg, $volname, $isBase) = @_;
|
||||
|
||||
my $vg = $scfg->{vgname};
|
||||
|
||||
|
||||
@ -251,7 +251,7 @@ sub alloc_image {
|
||||
}
|
||||
|
||||
sub free_image {
|
||||
my ($class, $storeid, $scfg, $volname) = @_;
|
||||
my ($class, $storeid, $scfg, $volname, $isBase) = @_;
|
||||
|
||||
my ($vtype, $name, $vmid) = $class->parse_volname($volname);
|
||||
|
||||
|
||||
@ -556,7 +556,7 @@ sub alloc_image {
|
||||
}
|
||||
|
||||
sub free_image {
|
||||
my ($class, $storeid, $scfg, $volname) = @_;
|
||||
my ($class, $storeid, $scfg, $volname, $isBase) = @_;
|
||||
|
||||
my $path = $class->path($scfg, $volname);
|
||||
|
||||
@ -565,23 +565,7 @@ sub free_image {
|
||||
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";
|
||||
}
|
||||
}
|
||||
|
||||
# try to remove immutable flag
|
||||
eval { run_command(['/usr/bin/chattr', '-i', $path]); };
|
||||
warn $@ if $@;
|
||||
|
||||
@ -235,7 +235,7 @@ sub alloc_image {
|
||||
}
|
||||
|
||||
sub free_image {
|
||||
my ($class, $storeid, $scfg, $volname) = @_;
|
||||
my ($class, $storeid, $scfg, $volname, $isBase) = @_;
|
||||
|
||||
my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'purge', $volname);
|
||||
run_command($cmd, errmsg => "rbd snap purge $volname' error", outfunc => sub {}, errfunc => sub {});
|
||||
|
||||
@ -186,7 +186,7 @@ sub alloc_image {
|
||||
}
|
||||
|
||||
sub free_image {
|
||||
my ($class, $storeid, $scfg, $volname) = @_;
|
||||
my ($class, $storeid, $scfg, $volname, $isBase) = @_;
|
||||
|
||||
my $snapshots = sheepdog_snapshot_ls($scfg, $volname);
|
||||
while (my ($snapname) = each %$snapshots) {
|
||||
|
||||
Reference in New Issue
Block a user