mirror of
https://git.proxmox.com/git/qemu-server
synced 2025-05-02 17:20:30 +00:00
make qemu_drive_mirror_monitor more generic
...so it works with other block jobs as well. Intended use case is block-stream, which also requires a new "auto" (wait only) completion mode, since it finishes automatically anyway. Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
This commit is contained in:
parent
43bf6fc982
commit
9e67172296
@ -6880,55 +6880,61 @@ sub qemu_drive_mirror {
|
|||||||
# 'complete': wait until all jobs are ready, block-job-complete them (default)
|
# 'complete': wait until all jobs are ready, block-job-complete them (default)
|
||||||
# 'cancel': wait until all jobs are ready, block-job-cancel them
|
# 'cancel': wait until all jobs are ready, block-job-cancel them
|
||||||
# 'skip': wait until all jobs are ready, return with block jobs in ready state
|
# 'skip': wait until all jobs are ready, return with block jobs in ready state
|
||||||
|
# 'auto': wait until all jobs disappear, only use for jobs which complete automatically
|
||||||
sub qemu_drive_mirror_monitor {
|
sub qemu_drive_mirror_monitor {
|
||||||
my ($vmid, $vmiddst, $jobs, $completion, $qga) = @_;
|
my ($vmid, $vmiddst, $jobs, $completion, $qga, $op) = @_;
|
||||||
|
|
||||||
$completion //= 'complete';
|
$completion //= 'complete';
|
||||||
|
$op //= "mirror";
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
my $err_complete = 0;
|
my $err_complete = 0;
|
||||||
|
|
||||||
while (1) {
|
while (1) {
|
||||||
die "storage migration timed out\n" if $err_complete > 300;
|
die "block job ('$op') timed out\n" if $err_complete > 300;
|
||||||
|
|
||||||
my $stats = mon_cmd($vmid, "query-block-jobs");
|
my $stats = mon_cmd($vmid, "query-block-jobs");
|
||||||
|
|
||||||
my $running_mirror_jobs = {};
|
my $running_jobs = {};
|
||||||
foreach my $stat (@$stats) {
|
foreach my $stat (@$stats) {
|
||||||
next if $stat->{type} ne 'mirror';
|
next if $stat->{type} ne $op;
|
||||||
$running_mirror_jobs->{$stat->{device}} = $stat;
|
$running_jobs->{$stat->{device}} = $stat;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $readycounter = 0;
|
my $readycounter = 0;
|
||||||
|
|
||||||
foreach my $job (keys %$jobs) {
|
foreach my $job (keys %$jobs) {
|
||||||
|
|
||||||
if(defined($jobs->{$job}->{complete}) && !defined($running_mirror_jobs->{$job})) {
|
my $vanished = !defined($running_jobs->{$job});
|
||||||
print "$job : finished\n";
|
my $complete = defined($jobs->{$job}->{complete}) && $vanished;
|
||||||
|
if($complete || ($vanished && $completion eq 'auto')) {
|
||||||
|
print "$job: finished\n";
|
||||||
delete $jobs->{$job};
|
delete $jobs->{$job};
|
||||||
next;
|
next;
|
||||||
}
|
}
|
||||||
|
|
||||||
die "$job: mirroring has been cancelled\n" if !defined($running_mirror_jobs->{$job});
|
die "$job: '$op' has been cancelled\n" if !defined($running_jobs->{$job});
|
||||||
|
|
||||||
my $busy = $running_mirror_jobs->{$job}->{busy};
|
my $busy = $running_jobs->{$job}->{busy};
|
||||||
my $ready = $running_mirror_jobs->{$job}->{ready};
|
my $ready = $running_jobs->{$job}->{ready};
|
||||||
if (my $total = $running_mirror_jobs->{$job}->{len}) {
|
if (my $total = $running_jobs->{$job}->{len}) {
|
||||||
my $transferred = $running_mirror_jobs->{$job}->{offset} || 0;
|
my $transferred = $running_jobs->{$job}->{offset} || 0;
|
||||||
my $remaining = $total - $transferred;
|
my $remaining = $total - $transferred;
|
||||||
my $percent = sprintf "%.2f", ($transferred * 100 / $total);
|
my $percent = sprintf "%.2f", ($transferred * 100 / $total);
|
||||||
|
|
||||||
print "$job: transferred: $transferred bytes remaining: $remaining bytes total: $total bytes progression: $percent % busy: $busy ready: $ready \n";
|
print "$job: transferred: $transferred bytes remaining: $remaining bytes total: $total bytes progression: $percent % busy: $busy ready: $ready \n";
|
||||||
}
|
}
|
||||||
|
|
||||||
$readycounter++ if $running_mirror_jobs->{$job}->{ready};
|
$readycounter++ if $running_jobs->{$job}->{ready};
|
||||||
}
|
}
|
||||||
|
|
||||||
last if scalar(keys %$jobs) == 0;
|
last if scalar(keys %$jobs) == 0;
|
||||||
|
|
||||||
if ($readycounter == scalar(keys %$jobs)) {
|
if ($readycounter == scalar(keys %$jobs)) {
|
||||||
print "all mirroring jobs are ready \n";
|
print "all '$op' jobs are ready\n";
|
||||||
last if $completion eq 'skip'; #do the complete later
|
|
||||||
|
# do the complete later (or has already been done)
|
||||||
|
last if $completion eq 'skip' || $completion eq 'auto';
|
||||||
|
|
||||||
if ($vmiddst && $vmiddst != $vmid) {
|
if ($vmiddst && $vmiddst != $vmid) {
|
||||||
my $agent_running = $qga && qga_check_running($vmid);
|
my $agent_running = $qga && qga_check_running($vmid);
|
||||||
@ -6984,7 +6990,7 @@ sub qemu_drive_mirror_monitor {
|
|||||||
|
|
||||||
if ($err) {
|
if ($err) {
|
||||||
eval { PVE::QemuServer::qemu_blockjobs_cancel($vmid, $jobs) };
|
eval { PVE::QemuServer::qemu_blockjobs_cancel($vmid, $jobs) };
|
||||||
die "mirroring error: $err";
|
die "block job ('$op') error: $err";
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user