[pve-devel] [PATCH 2/8] plugin : add volume_clone

Alexandre Derumier aderumier at odiso.com
Mon Nov 5 14:46:01 CET 2012


we can clone a .raw or qcow2 file, the child image must be in qcow2 format.

Vm cannot be running

we set the parent as readonly before cloning

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

diff --git a/PVE/Storage/Plugin.pm b/PVE/Storage/Plugin.pm
index 800639c..3f3c674 100644
--- a/PVE/Storage/Plugin.pm
+++ b/PVE/Storage/Plugin.pm
@@ -555,6 +555,27 @@ sub volume_snapshot_delete {
     return undef;
 }
 
+sub volume_clone {
+    my ($class, $scfg, $storeid, $volnamesrc, $volnamedst, $snap, $running) = @_;
+
+    die "The src image must be qcow2 or raw format" if $volnamesrc !~ m/\.(raw|qcow2)$/;
+
+    die "The cloned image must be qcow2 format" if $volnamedst !~ m/\.(qcow2)$/;
+
+    die "you can't clone if vm is running" if $running;
+
+    my $pathsrc = $class->path($scfg, $volnamesrc);
+    my $pathdst = $class->path($scfg, $volnamedst);
+
+    my $cmd = ['/usr/bin/chattr', '+i', $pathsrc];
+    run_command($cmd);
+
+    $cmd = ['/usr/bin/qemu-img', 'create','-b', $pathsrc, '-f', 'qcow2', $pathdst];
+    run_command($cmd);
+
+    return undef;
+}
+
 sub list_images {
     my ($class, $storeid, $scfg, $vmid, $vollist, $cache) = @_;
 
-- 
1.7.10.4




More information about the pve-devel mailing list