]> git.proxmox.com Git - qemu-server.git/commitdiff
shutdown by Qemu Guest Agent if the agent flag in the config is set
authorWolfgang Link <wolfgang@linksystems.org>
Wed, 26 Nov 2014 10:11:40 +0000 (11:11 +0100)
committerDietmar Maurer <dietmar@proxmox.com>
Mon, 1 Dec 2014 08:50:12 +0000 (09:50 +0100)
Important: "guest-shutdown" returns only by error a message.

Signed-off-by: Wolfgang Link <wolfgang@linksystems.org>
PVE/QMPClient.pm
PVE/QemuServer.pm

index d67bc01e94283747a62ed66052f3c5c8a7d7aa09..f4416e8a2643dc0f8326f32d1fd60822a3982ba2 100755 (executable)
@@ -87,7 +87,8 @@ sub cmd {
                 $cmd->{execute} eq 'query-block-jobs' ||
                 $cmd->{execute} eq 'backup-cancel' ||
                 $cmd->{execute} eq 'query-savevm' ||
-                $cmd->{execute} eq 'delete-drive-snapshot' ||
+                $cmd->{execute} eq 'delete-drive-snapshot' || 
+                $cmd->{execute} eq 'guest-shutdown' ||
                 $cmd->{execute} eq 'snapshot-drive'  ) {
            $timeout = 10*60; # 10 mins ?
        } else {
@@ -261,7 +262,6 @@ sub queue_execute {
                my $cmd = { execute => 'qmp_capabilities', arguments => {} };
                unshift @{$self->{queue}->{$vmid}}, $cmd;
            }
-
            $self->{mux}->set_timeout($fh, $timeout);
        };
        if (my $err = $@) {
@@ -295,7 +295,11 @@ sub mux_close {
     my $vmid = $self->{fhs_lookup}->{$fh} || 'undef';
     return if !defined($vmid);
 
-    $self->{errors}->{$vmid} = "client closed connection\n" if !$self->{errors}->{$vmid};
+    if(!$self->{no_answer}){
+       $self->{errors}->{$vmid} = "client closed connection\n" if !$self->{errors}->{$vmid};  
+    } else {
+       delete $self->{no_anwser}; 
+    }
 }
 
 # mux_input is called when input is available on one of
@@ -401,4 +405,40 @@ sub mux_timeout {
     &$check_queue($self);
 }
 
+sub mux_eof {
+    my ($self, $mux, $fh, $input) = @_;
+    my $vmid = $self->{fhs_lookup}->{$fh};
+    if(check_no_answer($self->{current}->{$vmid}->{execute})){
+       my @jsons = split("\n", $$input);
+
+       my $obj = from_json($jsons[0]);
+
+       my $cmdid = $obj->{return};
+       die "received responsed without command id\n" if !$cmdid;
+
+       my $curcmd = $self->{current}->{$vmid};
+       die "unable to lookup current command for VM $vmid\n" if !$curcmd;
+
+       delete $self->{current}->{$vmid};
+
+       $self->{no_answer} = 1;
+      }
+}
+
+sub check_no_answer {
+    my($cmd) = @_;
+
+    if ($cmd eq 'guest-shutdown'){
+       return 1;
+    } elsif ($cmd eq 'guest-suspend-ram'){
+       return 1;
+    } elsif ($cmd eq 'guest-suspend-disk'){
+       return 1;
+    } elsif ($cmd eq 'guest-suspend-hybrid'){
+       return 1;
+    }
+    return 0;
+}
+
 1;
index 6407670d5003279e5d1969abc233cc4e3bb3d40f..21d642a4a8776c2fdd48f7ed0e89b595aa1d9347 100644 (file)
@@ -3614,11 +3614,15 @@ sub vm_stop {
        }
 
        $timeout = 60 if !defined($timeout);
-
+       my $config = load_config($vmid);
+       
        eval {
            if ($shutdown) {
-               $nocheck ? vm_mon_cmd_nocheck($vmid, "system_powerdown") : vm_mon_cmd($vmid, "system_powerdown");
-
+               if($config->{agent}){
+                   vm_mon_cmd($vmid,"guest-shutdown");
+               } else {
+                   $nocheck ? vm_mon_cmd_nocheck($vmid, "system_powerdown") : vm_mon_cmd($vmid, "system_powerdown");
+               }
            } else {
                $nocheck ? vm_mon_cmd_nocheck($vmid, "quit") : vm_mon_cmd($vmid, "quit");
            }