[pve-devel] [PATCH 01/14] qmp_read_avail : reworks

Alexandre Derumier aderumier at odiso.com
Tue Jun 26 06:34:10 CEST 2012


qmp response could me more than 1 json.

we can have 1 json with event info, and 1 json with return infos.

We die if we receive an error message in response.

Signed-off-by: Alexandre Derumier <aderumier at odiso.com>
---
 PVE/QemuServer.pm |   16 ++++++++++++++--
 1 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/PVE/QemuServer.pm b/PVE/QemuServer.pm
index 47c122e..def9da0 100644
--- a/PVE/QemuServer.pm
+++ b/PVE/QemuServer.pm
@@ -2702,8 +2702,20 @@ my $qmp_read_avail = sub {
     }
 
     die "qmp read timeout\n" if !scalar(@ready);
-    my $obj = from_json($res);
-    return $obj;
+   
+    my @jsons = split("\n", $res);
+    my $obj = {};
+    my $event = {};
+    my $return = {};
+    foreach my $json (@jsons) {
+	$obj = from_json($json);
+	$event = $obj->{event} if exists $obj->{event};
+	$return = $obj->{QMP} if exists $obj->{QMP};
+	$return = $obj->{"return"} if exists $obj->{"return"};
+	die $obj->{error}->{desc} if exists $obj->{error}->{desc} && $obj->{error}->{desc} !~ m/Connection can not be completed immediately/;
+    }
+
+    return ($return,$event);
 };
 
 sub __read_avail {
-- 
1.7.2.5




More information about the pve-devel mailing list