[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
Fri Feb 7 12:16:38 CET 2014
Signed-off-by: Stefan Priebe <s.priebe at profihost.ag>
---
PVE/Storage/RBDPlugin.pm | 36 +++++++++++++++++++++++++-----------
1 file changed, 25 insertions(+), 11 deletions(-)
diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
index 72296f6..9b5ad6e 100644
--- a/PVE/Storage/RBDPlugin.pm
+++ b/PVE/Storage/RBDPlugin.pm
@@ -7,6 +7,7 @@ use IO::Handle qw( );
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);
@@ -396,19 +397,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;
@@ -526,6 +520,26 @@ 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});
+
+ # pvedaemon runs with -T switch so every output comming from a command
+ # which may be passed to a new command needs to be regex validated
+ # this (^(.*)$) is very ugly but no better idea
+ $out =~ m/^(.*)$/s;
+ my $list = decode_json($1);
+
+ return $list;
+}
+
+
sub volume_snapshot_rollback {
my ($class, $scfg, $storeid, $volname, $snap) = @_;
--
1.7.10.4
More information about the pve-devel
mailing list