[pve-devel] [PATCH 3/6] clone live vm : add support for multiple jobs

Alexandre Derumier aderumier at odiso.com
Tue Nov 8 04:29:31 CET 2016


Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/API2/Qemu.pm | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 34a5d5d..0d5569c 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -2421,21 +2421,29 @@ __PACKAGE__->register_method({
 		my $upid = shift;
 
 		my $newvollist = [];
+		my $jobs = {};
 
 		eval {
 		    local $SIG{INT} = $SIG{TERM} = $SIG{QUIT} = $SIG{HUP} = sub { die "interrupted by signal\n"; };
 
 		    PVE::Storage::activate_volumes($storecfg, $vollist, $snapname);
 
+		    my $total_jobs = scalar(keys %{$drives});
+		    my $i = 1;
+		    my $skipcomplete = 1;
+
 		    foreach my $opt (keys %$drives) {
+
 			my $drive = $drives->{$opt};
+			$skipcomplete = undef if $total_jobs == $i; #finish after last drive
 
 			my $newdrive = PVE::QemuServer::clone_disk($storecfg, $vmid, $running, $opt, $drive, $snapname,
-								   $newid, $storage, $format, $fullclone->{$opt}, $newvollist);
+								   $newid, $storage, $format, $fullclone->{$opt}, $newvollist, $jobs, $skipcomplete);
 
 			$newconf->{$opt} = PVE::QemuServer::print_drive($vmid, $newdrive);
 
 			PVE::QemuConfig->write_config($newid, $newconf);
+			$i++;
 		    }
 
 		    delete $newconf->{lock};
@@ -2456,6 +2464,8 @@ __PACKAGE__->register_method({
 		if (my $err = $@) {
 		    unlink $conffile;
 
+		    eval { PVE::QemuServer::qemu_blockjobs_cancel($vmid, $jobs) };
+
 		    sleep 1; # some storage like rbd need to wait before release volume - really?
 
 		    foreach my $volid (@$newvollist) {
-- 
2.1.4




More information about the pve-devel mailing list