[pve-devel] [PATCH qemu-server 23/31] block job: factor out helper for common mirror QMP options
Fiona Ebner
f.ebner at proxmox.com
Wed Jun 25 17:56:46 CEST 2025
To be re-used by blockdev-mirror.
Signed-off-by: Fiona Ebner <f.ebner at proxmox.com>
---
src/PVE/QemuServer/BlockJob.pm | 50 ++++++++++++++++++++--------------
1 file changed, 29 insertions(+), 21 deletions(-)
diff --git a/src/PVE/QemuServer/BlockJob.pm b/src/PVE/QemuServer/BlockJob.pm
index 8a74636c..0013bde6 100644
--- a/src/PVE/QemuServer/BlockJob.pm
+++ b/src/PVE/QemuServer/BlockJob.pm
@@ -212,6 +212,33 @@ sub qemu_drive_mirror_monitor {
}
}
+my sub common_mirror_qmp_options {
+ my ($device_id, $qemu_target, $src_bitmap, $bwlimit) = @_;
+
+ my $opts = {
+ timeout => 10,
+ device => "$device_id",
+ sync => "full",
+ target => $qemu_target,
+ 'auto-dismiss' => JSON::false,
+ };
+
+ if (defined($src_bitmap)) {
+ $opts->{sync} = 'incremental';
+ $opts->{bitmap} = $src_bitmap;
+ print "drive mirror re-using dirty bitmap '$src_bitmap'\n";
+ }
+
+ if (defined($bwlimit)) {
+ $opts->{speed} = $bwlimit * 1024;
+ print "drive mirror is starting for $device_id with bandwidth limit: ${bwlimit} KB/s\n";
+ } else {
+ print "drive mirror is starting for $device_id\n";
+ }
+
+ return $opts;
+}
+
sub qemu_drive_mirror {
my (
$vmid,
@@ -247,29 +274,10 @@ sub qemu_drive_mirror {
$qemu_target = $is_zero_initialized ? "zeroinit:$dst_path" : $dst_path;
}
- my $opts = {
- timeout => 10,
- device => "$device_id",
- mode => "existing",
- sync => "full",
- target => $qemu_target,
- 'auto-dismiss' => JSON::false,
- };
+ my $opts = common_mirror_qmp_options($device_id, $qemu_target, $src_bitmap, $bwlimit);
+ $opts->{mode} = "existing";
$opts->{format} = $format if $format;
- if (defined($src_bitmap)) {
- $opts->{sync} = 'incremental';
- $opts->{bitmap} = $src_bitmap;
- print "drive mirror re-using dirty bitmap '$src_bitmap'\n";
- }
-
- if (defined($bwlimit)) {
- $opts->{speed} = $bwlimit * 1024;
- print "drive mirror is starting for $device_id with bandwidth limit: ${bwlimit} KB/s\n";
- } else {
- print "drive mirror is starting for $device_id\n";
- }
-
# if a job already runs for this device we get an error, catch it for cleanup
eval { mon_cmd($vmid, "drive-mirror", %$opts); };
if (my $err = $@) {
--
2.47.2
More information about the pve-devel
mailing list