[pve-devel] [PATCH_V4 pve-container 4/5] Prevent that a CT run at cloning.

Wolfgang Link w.link at proxmox.com
Wed Jun 1 09:22:26 CEST 2016


If we make a linked clone the CT must be a template so it is not allowed to run.
If we make a full clone, it is safer to have the CT offline.
---
 src/PVE/API2/LXC.pm | 11 +++--------
 src/PVE/LXC.pm      |  4 ++--
 2 files changed, 5 insertions(+), 10 deletions(-)

diff --git a/src/PVE/API2/LXC.pm b/src/PVE/API2/LXC.pm
index 6fb0a62..6fa1da0 100644
--- a/src/PVE/API2/LXC.pm
+++ b/src/PVE/API2/LXC.pm
@@ -1085,20 +1085,15 @@ __PACKAGE__->register_method({
 
 	PVE::Cluster::check_cfs_quorum();
 
-	my $running = PVE::LXC::check_running($vmid) || 0;
-
 	my $clonefn = sub {
 
+	    die "Clone can't be done online\n." if  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);
 
 	    PVE::LXC::Config->check_lock($conf);
 
-	    my $verify_running = PVE::LXC::check_running($vmid) || 0;
-
-	    die "unexpected state change\n" if $verify_running != $running;
-
 	    die "snapshot '$snapname' does not exist\n"
 		if $snapname && !defined( $conf->{snapshots}->{$snapname});
 
@@ -1131,7 +1126,7 @@ __PACKAGE__->register_method({
 			} else {
 			    # not full means clone instead of copy
 			    die "Linked clone feature for '$volid' is not available\n"
-				if !PVE::Storage::volume_has_feature($storecfg, 'clone', $volid, $snapname, $running);
+				if !PVE::Storage::volume_has_feature($storecfg, 'clone', $volid, $snapname, 0);
 			}
 
 			$mountpoints->{$opt} = $mp;
@@ -1177,7 +1172,7 @@ __PACKAGE__->register_method({
 
 			if ($fullclone->{$opt}) {
 			    print "create full clone of mountpoint $opt ($volid)\n";
-			    $newvolid = PVE::LXC::copy_volume($mp, $vmid, $newid, $storage, $storecfg, $conf);
+			    $newvolid = PVE::LXC::copy_volume($mp, $vmid, $newid, $storage, $storecfg, $conf, $snapname);
 			} else {
 			    print "create linked clone of mountpoint $opt ($volid)\n";
 			    $newvolid = PVE::Storage::vdisk_clone($storecfg, $volid, $newid, $snapname);
diff --git a/src/PVE/LXC.pm b/src/PVE/LXC.pm
index 4710215..38c8180 100644
--- a/src/PVE/LXC.pm
+++ b/src/PVE/LXC.pm
@@ -1359,7 +1359,7 @@ sub userns_command {
 }
 
 sub copy_volume {
-    my ($mp, $vmid, $newid, $storage, $storage_cfg, $conf) = @_;
+    my ($mp, $vmid, $newid, $storage, $storage_cfg, $conf, $snapname) = @_;
 
     die "Copy only mountpoints with type 'volume'" if $mp->{type} ne 'volume';
     my $mount_dir = "/tmp/$vmid";
@@ -1393,7 +1393,7 @@ sub copy_volume {
 	mkdir $src;
 
 	#mount for copy mp
-	mountpoint_mount($mp, $src, $storage_cfg);
+	mountpoint_mount($mp, $src, $storage_cfg, $snapname);
 	mountpoint_mount($new_mp, $dest, $storage_cfg);
 
 	PVE::Tools::run_command(['/usr/bin/rsync', '--stats', '-X', '-A', '--numeric-ids',
-- 
2.1.4




More information about the pve-devel mailing list