[pve-devel] [PATCH_V5 pve-container 5/5] Add full clone with running CT

Wolfgang Link w.link at proxmox.com
Tue Jun 7 15:08:44 CEST 2016


With this patch it is possible to make a full clone from an running container,
if the underlying Storage provides snapshots.
---
 src/PVE/API2/LXC.pm | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index b6977b4..b224274 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -1153,7 +1153,8 @@ __PACKAGE__->register_method({
 
 	my $clonefn = sub {
 
-	    die "Clone can't be done online\n." if  PVE::LXC::check_running($vmid);
+	    my $running = PVE::LXC::check_running($vmid);
+
 	    # do all tests after lock
 	    # we also try to do all tests before we fork the worker
 	    my $conf = PVE::LXC::Config->load_config($vmid);
@@ -1173,6 +1174,13 @@ __PACKAGE__->register_method({
 	    my $mountpoints = {};
 	    my $fullclone = {};
 	    my $vollist = [];
+	    my $clone_volumes = [];
+
+	    #create snapshot for full clone to minimize downtime
+	    if ($running && !$snapname) {
+		$snapname = 'cloneCT';
+		PVE::LXC::Config->snapshot_create($vmid, $snapname);
+	    }
 
 	    foreach my $opt (keys %$oldconf) {
 		my $value = $oldconf->{$opt};
@@ -1255,6 +1263,10 @@ __PACKAGE__->register_method({
 
 		    PVE::AccessControl::add_vm_to_pool($newid, $pool) if $pool;
 		};
+
+		if (defined($snapname) && $snapname eq 'cloneCT') {
+		    PVE::LXC::Config->snapshot_delete($vmid, $snapname, 1);
+		}
 		if (my $err = $@) {
 		    unlink $conffile;
 
-- 
2.1.4





More information about the pve-devel mailing list