[pve-devel] [PATCH 8/8] live clone_vm : suspend or freezefs before block-job-cancel

Alexandre Derumier aderumier at odiso.com
Tue Jan 3 15:03:19 CET 2017


if qga is enabled, we try to freeze the fs before cancelling block job.
if not , we pause the vm.

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/API2/Qemu.pm  |  2 +-
 PVE/QemuServer.pm | 27 ++++++++++++++++++++++-----
 2 files changed, 23 insertions(+), 6 deletions(-)

diff --git a/PVE/API2/Qemu.pm b/PVE/API2/Qemu.pm
index 90d31f6..0bae424 100644
--- a/PVE/API2/Qemu.pm
+++ b/PVE/API2/Qemu.pm
@@ -2472,7 +2472,7 @@ __PACKAGE__->register_method({
 			$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, $jobs, $skipcomplete);
+								   $newid, $storage, $format, $fullclone->{$opt}, $newvollist, $jobs, $skipcomplete, $oldconf->{agent});
 
 			$newconf->{$opt} = PVE::QemuServer::print_drive($vmid, $newdrive);
 
diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 9585832..6d8943c 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5907,7 +5907,7 @@ sub qemu_img_format {
 }
 
 sub qemu_drive_mirror {
-    my ($vmid, $drive, $dst_volid, $vmiddst, $is_zero_initialized, $jobs, $skipcomplete) = @_;
+    my ($vmid, $drive, $dst_volid, $vmiddst, $is_zero_initialized, $jobs, $skipcomplete, $qga) = @_;
 
     $jobs = {} if !$jobs;
 
@@ -5970,11 +5970,11 @@ sub qemu_drive_mirror {
     }
 
 
-    qemu_drive_mirror_monitor ($vmid, $vmiddst, $jobs, $skipcomplete);
+    qemu_drive_mirror_monitor ($vmid, $vmiddst, $jobs, $skipcomplete, $qga);
 }
 
 sub qemu_drive_mirror_monitor {
-    my ($vmid, $vmiddst, $jobs, $skipcomplete) = @_;
+    my ($vmid, $vmiddst, $jobs, $skipcomplete, $qga) = @_;
 
     eval {
 
@@ -6023,8 +6023,25 @@ sub qemu_drive_mirror_monitor {
 		last if $skipcomplete; #do the complete later
 
 		if ($vmiddst && $vmiddst != $vmid) {
+		    if ($qga) {
+			print "freeze filesystem\n";
+			eval { PVE::QemuServer::vm_mon_cmd($vmid, "guest-fsfreeze-freeze"); };
+		    } else {
+			print "suspend vm\n";
+			eval { PVE::QemuServer::vm_suspend($vmid, 1); };
+		    }
+
 		    # if we clone a disk for a new target vm, we don't switch the disk
 		    PVE::QemuServer::qemu_blockjobs_cancel($vmid, $jobs);
+
+		    if ($qga) {
+			print "unfreeze filesystem\n";
+			eval { PVE::QemuServer::vm_mon_cmd($vmid, "guest-fsfreeze-thaw"); };
+		    } else {
+			print "resume vm\n";
+			eval {  PVE::QemuServer::vm_resume($vmid, 1, 1); };
+		    }
+
 		    last;
 		} else {
 
@@ -6109,7 +6126,7 @@ sub qemu_blockjobs_finish_tunnel {
 
 sub clone_disk {
     my ($storecfg, $vmid, $running, $drivename, $drive, $snapname,
-	$newvmid, $storage, $format, $full, $newvollist, $jobs, $skipcomplete) = @_;
+	$newvmid, $storage, $format, $full, $newvollist, $jobs, $skipcomplete, $qga) = @_;
 
     my $newvolid;
 
@@ -6151,7 +6168,7 @@ sub clone_disk {
 		    if $drive->{iothread};
 	    }
 
-	    qemu_drive_mirror($vmid, $drivename, $newvolid, $newvmid, $sparseinit, $jobs, $skipcomplete);
+	    qemu_drive_mirror($vmid, $drivename, $newvolid, $newvmid, $sparseinit, $jobs, $skipcomplete, $qga);
 	}
     }
 
-- 
2.1.4




More information about the pve-devel mailing list