[pve-devel] [PATCH qemu-server 13/18] block job: switch qemu_drive_mirror_monitor() to use QMP peer
Fiona Ebner
f.ebner at proxmox.com
Wed Dec 3 14:26:39 CET 2025
Take care to only allow a different destination ID when having the
main QEMU instance as a peer, because the required freeze/thaw or
suspend/resume can only be done then.
Also adds the missing $op argument in the signature of the mocked
function in the migration tests for completeness.
Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
src/PVE/QemuMigrate.pm | 2 +-
src/PVE/QemuServer.pm | 6 ++---
src/PVE/QemuServer/BlockJob.pm | 29 ++++++++++++++---------
src/PVE/QemuServer/Blockdev.pm | 4 ++--
src/test/MigrationTest/QemuMigrateMock.pm | 2 +-
5 files changed, 25 insertions(+), 18 deletions(-)
diff --git a/src/PVE/QemuMigrate.pm b/src/PVE/QemuMigrate.pm
index b7aba504..5177fe8b 100644
--- a/src/PVE/QemuMigrate.pm
+++ b/src/PVE/QemuMigrate.pm
@@ -1545,7 +1545,7 @@ sub phase2 {
# thus, this command changes to it to blockjob complete (see qapi docs)
eval {
PVE::QemuServer::BlockJob::qemu_drive_mirror_monitor(
- $vmid, undef, $self->{storage_migration_jobs}, 'cancel',
+ vm_qmp_peer($vmid), undef, $self->{storage_migration_jobs}, 'cancel',
);
};
if (my $err = $@) {
diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 6f2ee75c..80bbb059 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -7300,7 +7300,7 @@ sub pbs_live_restore {
mon_cmd($vmid, 'cont');
PVE::QemuServer::BlockJob::qemu_drive_mirror_monitor(
- $vmid, undef, $jobs, 'auto', 0, 'stream',
+ vm_qmp_peer($vmid), undef, $jobs, 'auto', 0, 'stream',
);
print "restore-drive jobs finished successfully, removing all tracking block devices"
@@ -7422,7 +7422,7 @@ sub live_import_from_files {
mon_cmd($vmid, 'cont');
PVE::QemuServer::BlockJob::qemu_drive_mirror_monitor(
- $vmid, undef, $jobs, 'auto', 0, 'stream',
+ vm_qmp_peer($vmid), undef, $jobs, 'auto', 0, 'stream',
);
print "restore-drive jobs finished successfully, removing all tracking block devices\n";
@@ -7932,7 +7932,7 @@ sub clone_disk {
# previous drive-mirrors
if (($completion && $completion eq 'complete') && (scalar(keys %$jobs) > 0)) {
PVE::QemuServer::BlockJob::qemu_drive_mirror_monitor(
- $vmid, $newvmid, $jobs, $completion, $qga,
+ vm_qmp_peer($vmid), $newvmid, $jobs, $completion, $qga,
);
}
goto no_data_clone;
diff --git a/src/PVE/QemuServer/BlockJob.pm b/src/PVE/QemuServer/BlockJob.pm
index 49bb13c7..f58bb4f6 100644
--- a/src/PVE/QemuServer/BlockJob.pm
+++ b/src/PVE/QemuServer/BlockJob.pm
@@ -84,7 +84,10 @@ sub qemu_blockjobs_cancel {
# '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 {
- my ($vmid, $vmiddst, $jobs, $completion, $qga, $op) = @_;
+ my ($qmp_peer, $vmiddst, $jobs, $completion, $qga, $op) = @_;
+
+ die "drive mirror: different destination is only supported when peer is main QEMU instance\n"
+ if $vmiddst && $qmp_peer->{type} ne 'qmp';
$completion //= 'complete';
$op //= "mirror";
@@ -96,7 +99,7 @@ sub qemu_drive_mirror_monitor {
while (1) {
die "block job ('$op') timed out\n" if $err_complete > 300;
- my $stats = mon_cmd($vmid, "query-block-jobs");
+ my $stats = qmp_cmd($qmp_peer, "query-block-jobs");
my $ctime = time();
my $running_jobs = {};
@@ -121,9 +124,7 @@ sub qemu_drive_mirror_monitor {
die "$job_id: '$op' has been cancelled\n" if !defined($job);
if ($job && $job->{status} eq 'concluded') {
- qemu_handle_concluded_blockjob(
- vm_qmp_peer($vmid), $job_id, $job, $jobs->{$job_id},
- );
+ qemu_handle_concluded_blockjob($qmp_peer, $job_id, $job, $jobs->{$job_id});
}
my $busy = $job->{busy};
@@ -164,7 +165,8 @@ sub qemu_drive_mirror_monitor {
# do the complete later (or has already been done)
last if $completion eq 'skip' || $completion eq 'auto';
- if ($vmiddst && $vmiddst != $vmid) {
+ if ($qmp_peer->{type} eq 'qmp' && $vmiddst && $vmiddst != $qmp_peer->{id}) {
+ my $vmid = $qmp_peer->{id};
my $agent_running = $qga && qga_check_running($vmid);
if ($agent_running) {
print "freeze filesystem\n";
@@ -177,7 +179,7 @@ sub qemu_drive_mirror_monitor {
}
# if we clone a disk for a new target vm, we don't switch the disk
- qemu_blockjobs_cancel(vm_qmp_peer($vmid), $jobs);
+ qemu_blockjobs_cancel($qmp_peer, $jobs);
if ($agent_running) {
print "unfreeze filesystem\n";
@@ -211,7 +213,7 @@ sub qemu_drive_mirror_monitor {
} else {
die "invalid completion value: $completion\n";
}
- eval { mon_cmd($vmid, $completion_command, device => $job_id) };
+ eval { qmp_cmd($qmp_peer, $completion_command, device => $job_id) };
my $err = $@;
if ($err && $err =~ m/cannot be completed/) {
print "$job_id: block job cannot be completed, trying again.\n";
@@ -234,7 +236,7 @@ sub qemu_drive_mirror_monitor {
my $err = $@;
if ($err) {
- eval { qemu_blockjobs_cancel(vm_qmp_peer($vmid), $jobs) };
+ eval { qemu_blockjobs_cancel($qmp_peer, $jobs) };
die "block job ($op) error: $err";
}
}
@@ -313,7 +315,7 @@ sub qemu_drive_mirror {
die "mirroring error: $err\n";
}
- qemu_drive_mirror_monitor($vmid, $vmiddst, $jobs, $completion, $qga);
+ qemu_drive_mirror_monitor(vm_qmp_peer($vmid), $vmiddst, $jobs, $completion, $qga);
}
# Callers should version guard this (only available with a binary >= QEMU 8.2)
@@ -510,7 +512,12 @@ sub blockdev_mirror {
die "error starting blockdev mirrror - $err";
}
qemu_drive_mirror_monitor(
- $vmid, $dest->{vmid}, $jobs, $completion, $options->{'guest-agent'}, 'mirror',
+ vm_qmp_peer($vmid),
+ $dest->{vmid},
+ $jobs,
+ $completion,
+ $options->{'guest-agent'},
+ 'mirror',
);
}
diff --git a/src/PVE/QemuServer/Blockdev.pm b/src/PVE/QemuServer/Blockdev.pm
index 8db17683..b89b0f68 100644
--- a/src/PVE/QemuServer/Blockdev.pm
+++ b/src/PVE/QemuServer/Blockdev.pm
@@ -1084,7 +1084,7 @@ sub blockdev_commit {
eval {
PVE::QemuServer::BlockJob::qemu_drive_mirror_monitor(
- $vmid, undef, $jobs, $complete, 0, 'commit',
+ vm_qmp_peer($vmid), undef, $jobs, $complete, 0, 'commit',
);
};
if ($@) {
@@ -1165,7 +1165,7 @@ sub blockdev_stream {
eval {
PVE::QemuServer::BlockJob::qemu_drive_mirror_monitor(
- $vmid, undef, $jobs, 'auto', 0, 'stream',
+ vm_qmp_peer($vmid), undef, $jobs, 'auto', 0, 'stream',
);
};
if ($@) {
diff --git a/src/test/MigrationTest/QemuMigrateMock.pm b/src/test/MigrationTest/QemuMigrateMock.pm
index 421f0bb7..d5ae29a4 100644
--- a/src/test/MigrationTest/QemuMigrateMock.pm
+++ b/src/test/MigrationTest/QemuMigrateMock.pm
@@ -176,7 +176,7 @@ $qemu_server_blockjob_module->mock(
common_mirror_mock($source->{vmid}, $drive_id);
},
qemu_drive_mirror_monitor => sub {
- my ($vmid, $vmiddst, $jobs, $completion, $qga) = @_;
+ my ($qmp_peer, $vmiddst, $jobs, $completion, $qga, $op) = @_;
if (
$fail_config->{qemu_drive_mirror_monitor}
--
2.47.3
More information about the pve-devel
mailing list