[pve-devel] [PATCH v2 container 3/4] use copy_volume for full clones

Wolfgang Bumiller w.bumiller at proxmox.com
Mon Dec 5 16:06:26 CET 2016


---
 src/PVE/API2/LXC.pm | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 423c90e..1316efe 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -1158,6 +1158,9 @@ __PACKAGE__->register_method({
 
 	my $storage = extract_param($param, 'storage');
 
+	die "Full clone requires a target storage.\n"
+	    if $param->{full} && !$storage;
+
         my $localnode = PVE::INotify::nodename();
 
 	my $storecfg = PVE::Storage::config();
@@ -1211,10 +1214,8 @@ __PACKAGE__->register_method({
 		    if ($mp->{type} eq 'volume') {
 			my $volid = $mp->{volume};
 			if ($param->{full}) {
-			    die "fixme: full clone not implemented";
-
-			    die "Full clone feature for '$volid' is not available\n"
-				if !PVE::Storage::volume_has_feature($storecfg, 'copy', $volid, $snapname, $running);
+			    die "Cannot do full clones on a running container without snapshots\n"
+				if $running && !defined($snapname);
 			    $fullclone->{$opt} = 1;
 			} else {
 			    # not full means clone instead of copy
@@ -1262,17 +1263,20 @@ __PACKAGE__->register_method({
 			my $mp = $mountpoints->{$opt};
 			my $volid = $mp->{volume};
 
+			my $newvolid;
 			if ($fullclone->{$opt}) {
-			    die "fixme: full clone not implemented\n";
+			    print "create full clone of mountpoint $opt ($volid)\n";
+			    $newvolid = PVE::LXC::copy_volume($mp, $newid, $storage, $storecfg, $conf, $snapname);
 			} else {
 			    print "create linked clone of mount point $opt ($volid)\n";
-			    my $newvolid = PVE::Storage::vdisk_clone($storecfg, $volid, $newid, $snapname);
-			    push @$newvollist, $newvolid;
-			    $mp->{volume} = $newvolid;
-
-			    $newconf->{$opt} = PVE::LXC::Config->print_ct_mountpoint($mp, $opt eq 'rootfs');
-			    PVE::LXC::Config->write_config($newid, $newconf);
+			    $newvolid = PVE::Storage::vdisk_clone($storecfg, $volid, $newid, $snapname);
 			}
+
+			push @$newvollist, $newvolid;
+			$mp->{volume} = $newvolid;
+
+			$newconf->{$opt} = PVE::LXC::Config->print_ct_mountpoint($mp, $opt eq 'rootfs');
+			PVE::LXC::Config->write_config($newid, $newconf);
 		    }
 
 		    delete $newconf->{lock};
-- 
2.1.4





More information about the pve-devel mailing list