mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-08-06 03:55:03 +00:00
vm_qmp_command : reworks of the sub
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
This commit is contained in:
parent
f667373f27
commit
d967756b10
@ -2825,11 +2825,11 @@ sub vm_monitor_command {
|
|||||||
}
|
}
|
||||||
|
|
||||||
sub vm_qmp_command {
|
sub vm_qmp_command {
|
||||||
my ($vmid, $cmdstr, $nocheck) = @_;
|
my ($vmid, $cmd, $nocheck) = @_;
|
||||||
|
|
||||||
#http://git.qemu.org/?p=qemu.git;a=blob;f=qmp-commands.hx;h=db980fa811325aeca8ad43472ba468702d4a25a2;hb=HEAD
|
#http://git.qemu.org/?p=qemu.git;a=blob;f=qmp-commands.hx;h=db980fa811325aeca8ad43472ba468702d4a25a2;hb=HEAD
|
||||||
my $res;
|
my $res;
|
||||||
|
my $event;
|
||||||
eval {
|
eval {
|
||||||
die "VM $vmid not running\n" if !check_running($vmid, $nocheck);
|
die "VM $vmid not running\n" if !check_running($vmid, $nocheck);
|
||||||
|
|
||||||
@ -2843,14 +2843,14 @@ sub vm_qmp_command {
|
|||||||
|
|
||||||
# hack: migrate sometime blocks the monitor (when migrate_downtime
|
# hack: migrate sometime blocks the monitor (when migrate_downtime
|
||||||
# is set)
|
# is set)
|
||||||
#if ($cmdstr =~ m/^(info\s+migrate|migrate\s)/) {
|
|
||||||
# $timeout = 60*60; # 1 hour
|
$timeout = 60*60 if ($cmd->{execute} =~ m/(migrate)$/);
|
||||||
#}
|
|
||||||
|
|
||||||
# read banner;
|
# read banner;
|
||||||
my $data = &$qmp_read_avail($sock, $timeout);
|
my $data = &$qmp_read_avail($sock, $timeout);
|
||||||
# '{"QMP": {"version": {"qemu": {"micro": 93, "minor": 0, "major": 1}, "package": " (qemu-kvm-devel)"}, "capabilities": []}} ';
|
# '{"QMP": {"version": {"qemu": {"micro": 93, "minor": 0, "major": 1}, "package": " (qemu-kvm-devel)"}, "capabilities": []}} ';
|
||||||
die "got unexpected qemu qmp banner\n" if !$data->{QMP};
|
die "got unexpected qemu qmp banner\n" if !$data;
|
||||||
|
|
||||||
my $sel = new IO::Select;
|
my $sel = new IO::Select;
|
||||||
$sel->add($sock);
|
$sel->add($sock);
|
||||||
@ -2869,34 +2869,31 @@ sub vm_qmp_command {
|
|||||||
|
|
||||||
$res = &$qmp_read_avail($sock, $timeout);
|
$res = &$qmp_read_avail($sock, $timeout);
|
||||||
# res = '{"return": {}}
|
# res = '{"return": {}}
|
||||||
die "qmp negociation error\n" if !$res->{return};
|
die "qmp negociation error\n" if !$res;
|
||||||
|
|
||||||
$timeout = 20;
|
$timeout = 20;
|
||||||
|
|
||||||
my $fullcmd;
|
my $cmdjson;
|
||||||
if (ref($cmdstr) eq "HASH") {
|
|
||||||
#generate json from hash for complex cmd
|
#generate json from hash for complex cmd
|
||||||
$fullcmd = to_json($cmdstr);
|
$cmdjson = to_json($cmd);
|
||||||
|
|
||||||
if ($fullcmd->{execute} =~ m/^(info\s+migrate|migrate\s)/) {
|
if ($cmd->{execute} =~ m/(migrate)$/) {
|
||||||
$timeout = 60*60; # 1 hour
|
$timeout = 60*60; # 1 hour
|
||||||
} elsif ($fullcmd->{execute} =~ m/^(eject|change)/) {
|
} elsif ($cmd->{execute} =~ m/^(eject|change)/) {
|
||||||
$timeout = 60; # note: cdrom mount command is slow
|
$timeout = 60; # note: cdrom mount command is slow
|
||||||
}
|
|
||||||
} else {
|
|
||||||
#execute command for simple action
|
|
||||||
$fullcmd = '{ "execute": "' . $cmdstr . '" }';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (!($b = $sock->syswrite($fullcmd)) || ($b != length($fullcmd))) {
|
if (!($b = $sock->syswrite($cmdjson)) || ($b != length($cmdjson))) {
|
||||||
die "monitor write error - $!";
|
die "monitor write error - $!";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (ref($cmdstr) ne "HASH") {
|
return if ($cmd->{execute} eq 'q') || ($cmd->{execute} eq 'quit');
|
||||||
return if ($cmdstr eq 'q') || ($cmdstr eq 'quit');
|
|
||||||
}
|
|
||||||
|
|
||||||
$res = &$qmp_read_avail($sock, $timeout);
|
|
||||||
|
($res,$event) = &$qmp_read_avail($sock, $timeout);
|
||||||
};
|
};
|
||||||
|
|
||||||
my $err = $@;
|
my $err = $@;
|
||||||
|
Loading…
Reference in New Issue
Block a user