[pve-devel] [PATCH 7/7] RBD: snap purge does not support automatic unprotect so list all snapshots and then unprotect and delete them

Stefan Priebe s.priebe at profihost.ag
Thu Feb 6 14:04:58 CET 2014


Signed-off-by: Stefan Priebe <s.priebe at profihost.ag>
---
 PVE/Storage/RBDPlugin.pm |   32 +++++++++++++++++++++-----------
 1 file changed, 21 insertions(+), 11 deletions(-)

diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
index 4a53a01..0c61824 100644
--- a/PVE/Storage/RBDPlugin.pm
+++ b/PVE/Storage/RBDPlugin.pm
@@ -6,6 +6,7 @@ use IO::File;
 use PVE::Tools qw(run_command trim);
 use PVE::Storage::Plugin;
 use PVE::JSONSchema qw(get_standard_option);
+use JSON;
 
 use base qw(PVE::Storage::Plugin);
 
@@ -393,19 +394,12 @@ sub free_image {
     my ($vtype, $name, $vmid, undef, undef, undef) =
 	$class->parse_volname($volname);
 
-    if ($isBase) {
-	my $snap = '__base__';
-	my (undef, undef, undef, $protected) = rbd_volume_info($scfg, $storeid, $name, $snap);
-	if ($protected){
-	    my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'unprotect', $name, '--snap', $snap);
-	    run_rbd_command($cmd, errmsg => "rbd unprotect $name snap '$snap' error");
-	}
+    my $snaplist = volume_snapshot_ls($class, $storeid, $scfg, $volname);
+    foreach my $snap (@$snaplist) {
+	$class->volume_snapshot_delete($scfg, $storeid, $volname, $snap->{name}, 0);
     }
 
-    my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'purge',  $name);
-    run_rbd_command($cmd, errmsg => "rbd snap purge '$volname' error");
-
-    $cmd = &$rbd_cmd($scfg, $storeid, 'rm', $name);
+    my $cmd = &$rbd_cmd($scfg, $storeid, 'rm', $name);
     run_rbd_command($cmd, errmsg => "rbd rm '$volname' error");
 
     return undef;
@@ -523,6 +517,22 @@ sub volume_snapshot {
     return undef;
 }
 
+sub volume_snapshot_ls {
+    my ($class, $storeid, $scfg, $volname) = @_;
+
+    my ($vtype, $name, $vmid) = $class->parse_volname($volname);
+
+    my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'ls', $name, '--format', 'json');
+
+    my $out = "";
+    run_rbd_command($cmd, errmsg => "rbd error", outfunc => sub {$out.=shift});
+
+    my $list = decode_json($out);
+
+    return $list;
+}
+
+
 sub volume_snapshot_rollback {
     my ($class, $scfg, $storeid, $volname, $snap) = @_;
 
-- 
1.7.10.4




More information about the pve-devel mailing list