From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 3F6151FF0B3 for ; Wed, 11 Nov 2026 13:03:04 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 1BFFA216ED; Wed, 11 Nov 2026 13:02:22 +0100 (CET) From: Fiona Ebner To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server v2 6/9] partially fix #7836: allow mirror for drive with read-only flag when using blockdev Date: Wed, 11 Nov 2026 13:01:45 +0100 Message-ID: <20261111120211.110737-7-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261111120211.110737-1-f.ebner@proxmox.com> References: <20261111120211.110737-1-f.ebner@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Bm-Milter-Handled: 55990f41-d878-4baa-be0a-ee34c49e34d2 X-Bm-Transport-Timestamp: 1794398534947 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.278 Adjusted score from AWL reputation of From: address DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment (newer systems) RCVD_IN_DNSWL_MED -2.3 Sender listed at https://www.dnswl.org/, medium trust SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record Message-ID-Hash: I4WWY2UJ4VVN7SJQR2WJJ7ALAGTM6RO4 X-Message-ID-Hash: I4WWY2UJ4VVN7SJQR2WJJ7ALAGTM6RO4 X-MailFrom: f.ebner@proxmox.com X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header X-Mailman-Version: 3.3.10 Precedence: list List-Id: Proxmox VE development discussion List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: The switch to -blockdev in Proxmox VE 9 introduced a regression, making clone of a VM with a read-only drive fail. The reason is that the target node is also attached as read-only and thus cannot serve as the mirror target. To fix the issue, open the mirror target as writeable initially and in case the VM switched to the new drive, re-open as read-only later. Note that the drive device is always read-only for the guest, because the top throttle node is. Signed-off-by: Fiona Ebner --- Changes in v2: * Use a callback directly rather than passing data around and calling a new helper function. * In v1 the reopen was done directly after 'job-complete', but this might be racy. Reopen only after the job actually finished. src/PVE/QemuServer/BlockJob.pm | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/PVE/QemuServer/BlockJob.pm b/src/PVE/QemuServer/BlockJob.pm index 2e4e275e..bedcdc9d 100644 --- a/src/PVE/QemuServer/BlockJob.pm +++ b/src/PVE/QemuServer/BlockJob.pm @@ -121,7 +121,13 @@ sub monitor { my $complete = defined($jobs->{$job_id}->{complete}) && $vanished; if ($complete || ($vanished && $completion eq 'auto')) { print "$job_id: $op-job finished\n"; - delete $jobs->{$job_id}; + my $job_info = delete $jobs->{$job_id}; + + if ($completion ne 'cancel' && $job_info->{'reopen-after-switch'}) { + eval { $job_info->{'reopen-after-switch'}->(); }; + warn "reopen after switch: $@" if $@; + } + next; } @@ -521,6 +527,14 @@ sub blockdev_mirror { } } + # If the drive is configured as read-only, attach the mirror target as writeable initially and + # re-open it as read-only later. For the guest, the drive will be seen as read-only if the + # throttle node is, even in case mirror switches to the new target. + my $dest_is_read_only = $dest_drive->{ro}; + if ($dest_is_read_only) { + $attach_dest_opts->{'read-only'} = 0; + } + # Note that if 'aio' is not explicitly set, i.e. default, it can change if source and target # don't both allow or both not allow 'io_uring' as the default. my ($target_node_name) = @@ -533,6 +547,23 @@ sub blockdev_mirror { 'target-node-name' => $target_node_name, }; + if ($dest_is_read_only) { + my $reopen_opts = { $attach_dest_opts->%* }; + delete($reopen_opts->{'read-only'}); # remove the override for re-opening later + + $jobs->{$jobid}->{'reopen-after-switch'} = sub { + eval { + PVE::QemuServer::Blockdev::reopen($storecfg, $vmid, $dest_drive, $reopen_opts); + }; + if (my $err = $@) { + # For the guest, the drive will be seen as read-only if the throttle node already + # is, so a failure here is not too bad. + my $drive_id = PVE::QemuServer::Drive::get_drive_id($dest_drive); + print "$drive_id: failed to re-apply read-only flag below throttle - $err\n"; + } + }; + } + my $qmp_opts = common_mirror_qmp_options( $vmid, $device_id, $target_node_name, $source->{bitmap}, $options->{bwlimit}, ); -- 2.47.3