[pve-devel] [POC qemu-server 2/6] create savevm_monitor helper

Fabian Ebner f.ebner at proxmox.com
Thu Apr 8 12:33:12 CEST 2021


Signed-off-by: Fabian Ebner <f.ebner at proxmox.com>
---
 PVE/QemuServer.pm | 38 ++++++++++++++++++++++----------------
 1 file changed, 22 insertions(+), 16 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 5a89853..983fb2f 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -5621,6 +5621,27 @@ sub vm_reboot {
    });
 }
 
+sub savevm_monitor {
+    my ($vmid) = @_;
+
+    for(;;) {
+	my $state = mon_cmd($vmid, "query-savevm");
+	if (!$state->{status}) {
+	    die "savevm not active\n";
+	} elsif ($state->{status} eq 'active') {
+	    sleep(1);
+	    next;
+	} elsif ($state->{status} eq 'completed') {
+	    print "State saved, quitting\n";
+	    return;
+	} elsif ($state->{status} eq 'failed' && $state->{error}) {
+	    die "query-savevm failed with error '$state->{error}'\n"
+	} else {
+	    die "query-savevm returned status '$state->{status}'\n";
+	}
+    }
+}
+
 # note: if using the statestorage parameter, the caller has to check privileges
 sub vm_suspend {
     my ($vmid, $skiplock, $includestate, $statestorage) = @_;
@@ -5672,22 +5693,7 @@ sub vm_suspend {
 	eval {
 	    set_migration_caps($vmid, 1);
 	    mon_cmd($vmid, "savevm-start", statefile => $path);
-	    for(;;) {
-		my $state = mon_cmd($vmid, "query-savevm");
-		if (!$state->{status}) {
-		    die "savevm not active\n";
-		} elsif ($state->{status} eq 'active') {
-		    sleep(1);
-		    next;
-		} elsif ($state->{status} eq 'completed') {
-		    print "State saved, quitting\n";
-		    last;
-		} elsif ($state->{status} eq 'failed' && $state->{error}) {
-		    die "query-savevm failed with error '$state->{error}'\n"
-		} else {
-		    die "query-savevm returned status '$state->{status}'\n";
-		}
-	    }
+	    savevm_monitor($vmid);
 	};
 	my $err = $@;
 
-- 
2.20.1






More information about the pve-devel mailing list