mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-08-07 10:58:25 +00:00
convert migrate monitor commands to qmp
Signed-off-by: Alexandre Derumier <aderumier@odiso.com>
This commit is contained in:
parent
608164747f
commit
5a7835f572
@ -324,32 +324,34 @@ sub phase2 {
|
|||||||
# start migration
|
# start migration
|
||||||
|
|
||||||
my $start = time();
|
my $start = time();
|
||||||
|
eval {
|
||||||
|
PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "migrate", uri => "tcp:localhost:$lport");
|
||||||
|
};
|
||||||
|
my $merr = $@;
|
||||||
|
|
||||||
my $merr = PVE::QemuServer::vm_monitor_command($vmid, "migrate -d \"tcp:localhost:$lport\"", 1);
|
my $lstat = undef;
|
||||||
|
|
||||||
my $lstat = '';
|
|
||||||
while (1) {
|
while (1) {
|
||||||
sleep (2);
|
sleep (2);
|
||||||
my $stat = PVE::QemuServer::vm_monitor_command($vmid, "info migrate", 1);
|
my $stat = PVE::QemuServer::vm_mon_cmd_nocheck($vmid, "query-migrate");
|
||||||
if ($stat =~ m/^Migration status: (active|completed|failed|cancelled)$/im) {
|
|
||||||
|
if ($stat->{status} =~ m/^(active|completed|failed|cancelled)$/im) {
|
||||||
$merr = undef;
|
$merr = undef;
|
||||||
my $ms = $1;
|
|
||||||
|
|
||||||
if ($stat ne $lstat) {
|
if ($stat->{ram}->{transferred} ne $lstat) {
|
||||||
if ($ms eq 'active') {
|
if ($stat->{status} eq 'active') {
|
||||||
my ($trans, $rem, $total) = (0, 0, 0);
|
my ($trans, $rem, $total) = (0, 0, 0);
|
||||||
$trans = $1 if $stat =~ m/^transferred ram: (\d+) kbytes$/im;
|
$trans = sprintf "%.2f", $stat->{ram}->{transferred}/1024 if $stat->{ram}->{transferred};
|
||||||
$rem = $1 if $stat =~ m/^remaining ram: (\d+) kbytes$/im;
|
$rem = sprintf "%.2f", $stat->{ram}->{remaining}/1024 if $stat->{ram}->{remaining};
|
||||||
$total = $1 if $stat =~ m/^total ram: (\d+) kbytes$/im;
|
$total = sprintf "%.2f", $stat->{ram}->{total}/1024 if $stat->{ram}->{total};
|
||||||
|
|
||||||
$self->log('info', "migration status: $ms (transferred ${trans}KB, " .
|
$self->log('info', "migration status: $stat->{status} (transferred ${trans}KB, " .
|
||||||
"remaining ${rem}KB), total ${total}KB)");
|
"remaining ${rem}KB), total ${total}KB)");
|
||||||
} else {
|
} else {
|
||||||
$self->log('info', "migration status: $ms");
|
$self->log('info', "migration status: $stat->{status}");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($ms eq 'completed') {
|
if ($stat->{status} eq 'completed') {
|
||||||
my $delay = time() - $start;
|
my $delay = time() - $start;
|
||||||
if ($delay > 0) {
|
if ($delay > 0) {
|
||||||
my $mbps = sprintf "%.2f", $conf->{memory}/$delay;
|
my $mbps = sprintf "%.2f", $conf->{memory}/$delay;
|
||||||
@ -357,16 +359,16 @@ sub phase2 {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($ms eq 'failed' || $ms eq 'cancelled') {
|
if ($stat->{status} eq 'failed' || $stat->{status} eq 'cancelled') {
|
||||||
die "aborting\n"
|
die "aborting\n"
|
||||||
}
|
}
|
||||||
|
|
||||||
last if $ms ne 'active';
|
last if $stat->{status} ne 'active';
|
||||||
} else {
|
} else {
|
||||||
die $merr if $merr;
|
die $merr if $merr;
|
||||||
die "unable to parse migration status '$stat' - aborting\n";
|
die "unable to parse migration status '$stat->{status}' - aborting\n";
|
||||||
}
|
}
|
||||||
$lstat = $stat;
|
$lstat = $lstat->{ram}->{transferred};
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user