[pve-devel] [PATCH] sheepdog : delete snapshots when deleting volume

Alexandre Derumier aderumier at odiso.com
Wed Oct 31 12:28:37 CET 2012


sheepdog don't delete snapshots automatically when deleting volume

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/Storage/SheepdogPlugin.pm |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/PVE/Storage/SheepdogPlugin.pm b/PVE/Storage/SheepdogPlugin.pm
index 346a2f2..5aff893 100644
--- a/PVE/Storage/SheepdogPlugin.pm
+++ b/PVE/Storage/SheepdogPlugin.pm
@@ -48,6 +48,23 @@ sub sheepdog_ls {
     return $list;
 }
 
+sub sheepdog_snapshot_ls {
+    my ($scfg, $volname) = @_;
+
+    my $cmd = &$collie_cmd($scfg, 'vdi', 'list', '-r');
+
+    my $list = {};
+    run_command($cmd, outfunc => sub {
+        my $line = shift;
+        $line = trim($line);
+	if ($line =~ /s\s(\S+)\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\d+)\s(\S+)\s(\d+)\s(\S+)/) {
+	    $list->{$9} = 1;
+	}
+    });
+
+    return $list;
+}
+
 # Configuration
 
 
@@ -129,6 +146,12 @@ sub alloc_image {
 sub free_image {
     my ($class, $storeid, $scfg, $volname) = @_;
 
+    my $snapshots = sheepdog_snapshot_ls($scfg, $volname);
+    while (my ($snapname) = each %$snapshots) {
+	my $cmd = &$collie_cmd($scfg, 'vdi', 'delete' , '-s', $snapname, $volname);
+	run_command($cmd, errmsg => "sheepdog delete snapshot $snapname $volname' error");
+    }
+
     my $cmd = &$collie_cmd($scfg, 'vdi', 'delete' , $volname);
 
     run_command($cmd, errmsg => "sheepdog delete $volname' error");
-- 
1.7.10.4




More information about the pve-devel mailing list