[pve-devel] [PATCH] add new storagecopy feature && add rbdplugin

Alexandre Derumier aderumier at odiso.com
Mon Nov 14 10:08:51 CET 2016


This allow fast volume copy from storage to same storage if storage support it.

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/Storage.pm           | 18 ++++++++++++++++++
 PVE/Storage/RBDPlugin.pm | 22 ++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/PVE/Storage.pm b/PVE/Storage.pm
index a904f4e..bbccc6c 100755
--- a/PVE/Storage.pm
+++ b/PVE/Storage.pm
@@ -651,6 +651,24 @@ sub vdisk_clone {
     });
 }
 
+sub vdisk_copy {
+    my ($cfg, $volid, $vmid, $snap) = @_;
+
+    my ($storeid, $volname) = parse_volume_id($volid);
+
+    my $scfg = storage_config($cfg, $storeid);
+
+    my $plugin = PVE::Storage::Plugin->lookup($scfg->{type});
+
+    activate_storage($cfg, $storeid);
+
+    # lock shared storage
+    return $plugin->cluster_lock_storage($storeid, $scfg->{shared}, undef, sub {
+	my $volname = $plugin->copy_image($scfg, $storeid, $volname, $vmid, $snap);
+	return "$storeid:$volname";
+    });
+}
+
 sub vdisk_create_base {
     my ($cfg, $volid) = @_;
 
diff --git a/PVE/Storage/RBDPlugin.pm b/PVE/Storage/RBDPlugin.pm
index 6459f98..9aac701 100644
--- a/PVE/Storage/RBDPlugin.pm
+++ b/PVE/Storage/RBDPlugin.pm
@@ -440,6 +440,27 @@ sub clone_image {
     return $newvol;
 }
 
+sub copy_image {
+    my ($class, $scfg, $storeid, $volname, $vmid, $snapname) = @_;
+
+    my $name = &$find_free_diskname($storeid, $scfg, $vmid);
+
+    my $newvol = $name;
+
+    $volname = $volname."@".$snapname if $snapname;
+
+    warn "clone $volname to $name\n";
+
+    my $cmd = &$rbd_cmd($scfg, $storeid, 'copy', &$add_pool_to_disk($scfg, $volname), 
+			&$add_pool_to_disk($scfg, $name));
+
+    run_rbd_command($cmd, errmsg => "rbd copy '$volname' error");
+
+    &$krdb_feature_disable($scfg, $storeid, $name);
+
+    return $newvol;
+}
+
 sub alloc_image {
     my ($class, $storeid, $scfg, $vmid, $fmt, $name, $size) = @_;
 
@@ -664,6 +685,7 @@ sub volume_has_feature {
 	clone => { base => 1, snap => 1},
 	template => { current => 1},
 	copy => { base => 1, current => 1, snap => 1},
+	storagecopy => { base => 1, current => 1, snap => 1},
 	sparseinit => { base => 1, current => 1},
     };
 
-- 
2.1.4




More information about the pve-devel mailing list