[pve-devel] [PATCH 3/8] rbd : add volume_clone
Alexandre Derumier
aderumier at odiso.com
Mon Nov 5 14:46:02 CET 2012
We need to verify if image format is V2.
We need to protect the snapshot before cloning.
Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
PVE/Storage/RBDPlugin.pm | 36 ++++++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
index cb7a823..16bfd50 100644
--- a/PVE/Storage/RBDPlugin.pm
+++ b/PVE/Storage/RBDPlugin.pm
@@ -72,6 +72,26 @@ sub rbd_ls {
return $list;
}
+sub rbd_info {
+ my ($scfg, $storeid, $volname) = @_;
+
+ my $cmd = &$rbd_cmd($scfg, $storeid, 'info', $volname);
+
+ my $infos = {};
+
+ my $parser = sub {
+ my $line = shift;
+
+ if ($line =~ m/\s+(\S+):\s(\S+)/) {
+ $infos->{$1} = $2;
+ }
+ };
+
+ run_command($cmd, errmsg => "rbd error", errfunc => sub {}, outfunc => $parser);
+
+ return $infos;
+}
+
sub rbd_volume_size {
my ($scfg, $storeid, $volname) = @_;
@@ -345,4 +365,20 @@ sub volume_snapshot_delete {
return undef;
}
+sub volume_clone {
+ my ($class, $scfg, $storeid, $volnamesrc, $volnamedst, $snap, $running) = @_;
+
+ my $infos = rbd_info($volnamesrc."@".$snap);
+ die "rbd image must be at format V2" if $infos->{format} ne "2";
+
+ if ($infos->{protected} ne "True"){
+ my $cmd = &$rbd_cmd($scfg, $storeid, 'snap', 'protect', $volnamesrc, '--snap', $snap);
+ run_command($cmd, errmsg => "rbd protect $volnamesrc snap $snap' error", errfunc => sub {});
+ }
+
+ my $cmd = &$rbd_cmd($scfg, $storeid, 'clone', $volnamesrc, '--snap', $snap, $volnamedst);
+ run_command($cmd, errmsg => "rbd clone $volnamesrc' error", errfunc => sub {});
+ return undef;
+}
+
1;
--
1.7.10.4
More information about the pve-devel
mailing list