[pve-devel] [PATCH v7 pve-storage 07/10] Implement support for cloning images.

mir at datanom.net mir at datanom.net
Tue Jun 20 22:39:59 CEST 2017


From: Michael Rasmussen <mir at datanom.net>

Signed-off-by: Michael Rasmussen <mir at datanom.net>
---
 PVE/Storage/FreeNASPlugin.pm | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/PVE/Storage/FreeNASPlugin.pm b/PVE/Storage/FreeNASPlugin.pm
index 943eeab..9c0136d 100644
--- a/PVE/Storage/FreeNASPlugin.pm
+++ b/PVE/Storage/FreeNASPlugin.pm
@@ -963,6 +963,33 @@ sub create_base {
 sub clone_image {
     my ($class, $scfg, $storeid, $volname, $vmid, $snap) = @_;
 
+    $snap ||= "__base__$vmid";
+
+    my ($vtype, $basename, $basevmid, undef, undef, $isBase, $format) =
+        $class->parse_volname($volname);
+
+    die "clone_image only works on base images\n" unless $isBase;
+
+    my $name = $freenas_find_free_diskname->($storeid, $scfg, $vmid, $format);
+
+    $class->volume_snapshot($scfg, $storeid, $basename, $snap);
+    
+    my $data = {
+        name => "$scfg->{pool}/$name"
+    };
+    $freenas_request->(
+        $scfg, 'POST', "storage/snapshot/$scfg->{pool}/$basename\@$snap/clone/", encode_json($data));
+
+    $name = "$basename/$name";
+    # get ZFS dataset name from PVE volname
+    my (undef, $clonedname) = $class->parse_volname($name);
+
+    $freenas_create_lun->($scfg, $vmid, $clonedname);
+    
+    my $res = $class->deactivate_volume($storeid, $scfg, $basename);
+    die "Could not deactivate volume '$basename'\n" unless $res;
+    
+    return $name;
 }
 
 sub alloc_image {
-- 
2.11.0


----

This mail was virus scanned and spam checked before delivery.
This mail is also DKIM signed. See header dkim-signature.




More information about the pve-devel mailing list