From 32437ed2791882342928e081bcbffeb9c70cdc59 Mon Sep 17 00:00:00 2001 From: Dietmar Maurer Date: Fri, 1 Feb 2013 06:55:39 +0100 Subject: [PATCH] check base image use count inside vdisk_free To make it work with all storage types. --- PVE/Storage.pm | 21 ++++++++++++++++++++- PVE/Storage/ISCSIDirectPlugin.pm | 2 +- PVE/Storage/ISCSIPlugin.pm | 2 +- PVE/Storage/LVMPlugin.pm | 2 +- PVE/Storage/NexentaPlugin.pm | 2 +- PVE/Storage/Plugin.pm | 18 +----------------- PVE/Storage/RBDPlugin.pm | 2 +- PVE/Storage/SheepdogPlugin.pm | 2 +- 8 files changed, 27 insertions(+), 24 deletions(-) diff --git a/PVE/Storage.pm b/PVE/Storage.pm index 2260f06..50bd0c5 100755 --- a/PVE/Storage.pm +++ b/PVE/Storage.pm @@ -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; diff --git a/PVE/Storage/ISCSIDirectPlugin.pm b/PVE/Storage/ISCSIDirectPlugin.pm index 5457601..a2bd38f 100644 --- a/PVE/Storage/ISCSIDirectPlugin.pm +++ b/PVE/Storage/ISCSIDirectPlugin.pm @@ -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"; } diff --git a/PVE/Storage/ISCSIPlugin.pm b/PVE/Storage/ISCSIPlugin.pm index 663ba45..f430897 100644 --- a/PVE/Storage/ISCSIPlugin.pm +++ b/PVE/Storage/ISCSIPlugin.pm @@ -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"; } diff --git a/PVE/Storage/LVMPlugin.pm b/PVE/Storage/LVMPlugin.pm index 77b5afe..25cd310 100644 --- a/PVE/Storage/LVMPlugin.pm +++ b/PVE/Storage/LVMPlugin.pm @@ -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}; diff --git a/PVE/Storage/NexentaPlugin.pm b/PVE/Storage/NexentaPlugin.pm index 3a4e3e2..6f0e257 100644 --- a/PVE/Storage/NexentaPlugin.pm +++ b/PVE/Storage/NexentaPlugin.pm @@ -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); diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm index 9545626..de2818c 100644 --- a/PVE/Storage/Plugin.pm +++ b/PVE/Storage/Plugin.pm @@ -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 $@; diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm index a4060a7..a218bcc 100644 --- a/PVE/Storage/RBDPlugin.pm +++ b/PVE/Storage/RBDPlugin.pm @@ -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 {}); diff --git a/PVE/Storage/SheepdogPlugin.pm b/PVE/Storage/SheepdogPlugin.pm index f7def46..3a71c48 100644 --- a/PVE/Storage/SheepdogPlugin.pm +++ b/PVE/Storage/SheepdogPlugin.pm @@ -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) {