[pve-devel] [PATCH 03/20] rbd: add volume_protect && volume_unprotect
Alexandre Derumier
aderumier at odiso.com
Mon Dec 3 14:32:28 CET 2012
We use the rbd protect command to protect a snapshot.
This is mandatory for clone a snapshot.
The rbd volume need to be at format V2
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/Storage/RBDPlugin.pm | 55 +++++++++++++++++++++++++++++++++++++++++-----
1 file changed, 50 insertions(+), 5 deletions(-)
diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
index 60bd4e8..c388cab 100644
--- a/PVE/Storage/RBDPlugin.pm
+++ b/PVE/Storage/RBDPlugin.pm
@@ -21,7 +21,6 @@ my $rbd_cmd = sub {
'--auth_supported', $scfg->{authsupported}, $op];
push @$cmd, @options if scalar(@options);
-
return $cmd;
};
@@ -41,6 +40,7 @@ my $rados_cmd = sub {
return $cmd;
};
+
sub rbd_ls {
my ($scfg, $storeid) = @_;
@@ -75,19 +75,32 @@ sub rbd_ls {
}
sub rbd_volume_info {
- my ($scfg, $storeid, $volname) = @_;
+ my ($scfg, $storeid, $volname, $snap) = @_;
+
+ my $cmd = undef;
+
+ if($snap){
+ $cmd = &$rbd_cmd($scfg, $storeid, 'info', $volname, '--snap', $snap);
+ }else{
+ $cmd = &$rbd_cmd($scfg, $storeid, 'info', $volname);
+ }
+
- my $cmd = &$rbd_cmd($scfg, $storeid, 'info', $volname);
my $size = undef;
my $parent = undef;
+ my $format = undef;
+ my $protected = undef;
my $parser = sub {
my $line = shift;
-
if ($line =~ m/size (\d+) MB in (\d+) objects/) {
$size = $1;
} elsif ($line =~ m/parent:\s(\S+)\/(\S+)/) {
$parent = $2;
+ } elsif ($line =~ m/format:\s(\d+)/) {
+ $format = $1;
+ } elsif ($line =~ m/protected:\s(\S+)/) {
+ $protected = $1;
}
};
@@ -95,7 +108,7 @@ sub rbd_volume_info {
$size = $size*1024*1024 if $size;
- return ($size, $parent);
+ return ($size, $parent, $format, $protected);
}
sub addslashes {
@@ -352,4 +365,36 @@ sub volume_snapshot_delete {
return undef;
}
+sub volume_protect {
+ my ($class, $scfg, $storeid, $volname, $snap) = @_;
+
+ die "missing snapshot name" if !$snap;
+
+ my (undef, undef, $format, $protected) = rbd_volume_info($scfg, $storeid, $volname, , $snap);
+
+ die "rbd image must be at format V2" if $format ne "2";
+
+ if ($protected eq "False"){
+ my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'protect', $volname, '--snap', $snap);
+ run_command($cmd, errmsg => "rbd protect $volname snap $snap' error", errfunc => sub {});
+ }
+}
+
+sub volume_unprotect {
+ my ($class, $scfg, $storeid, $volname, $snap) = @_;
+
+ die "missing snapshot name" if !$snap;
+
+ my (undef, undef, $format, $protected) = rbd_volume_info($scfg, $storeid, $volname, , $snap);
+
+ die "rbd image must be at format V2" if $format ne "2";
+
+ if ($protected eq "True"){
+ my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'unprotect', $volname, '--snap', $snap);
+ run_command($cmd, errmsg => "rbd unprotect $volname snap $snap' error", errfunc => sub {});
+ }
+}
+
+
+
1;
--
1.7.10.4
More information about the pve-devel
mailing list