From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [45.144.208.40]) by lore.proxmox.com (Postfix) with ESMTPS id 2355B1FF0C0 for ; Wed, 18 Nov 2026 15:36:07 +0100 (CET) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id 7C8D521711; Wed, 18 Nov 2026 15:35:59 +0100 (CET) From: Fiona Ebner To: pve-devel@lists.proxmox.com Subject: [PATCH qemu-server v3 6/9] partially fix #7836: allow mirror for drive with read-only flag when using blockdev Date: Wed, 18 Nov 2026 15:27:50 +0100 Message-ID: <20261118143549.199143-7-f.ebner@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261118143549.199143-1-f.ebner@proxmox.com> References: <20261118143549.199143-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: 1795012553436 X-SPAM-LEVEL: Spam detection results: 0 AWL 0.248 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: NERPHU5DJMOJRIX2BZZWPRWFS2VURLXT X-Message-ID-Hash: NERPHU5DJMOJRIX2BZZWPRWFS2VURLXT 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 --- No changes in v3. 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 507ae1bd..ebe4c331 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; } @@ -528,6 +534,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) = @@ -540,6 +554,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( $device_id, $target_node_name, -- 2.47.3