From: Fiona Ebner <f.ebner@proxmox.com>
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 [thread overview]
Message-ID: <20261118143549.199143-7-f.ebner@proxmox.com> (raw)
In-Reply-To: <20261118143549.199143-1-f.ebner@proxmox.com>
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 <f.ebner@proxmox.com>
---
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
next prev parent reply other threads:[~2026-11-18 14:36 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-18 14:27 [PATCH-SERIES qemu/qemu-server v3 0/9] mirror: fix regressions with blockdev and allow migration with 'ro' flag Fiona Ebner
2026-11-18 14:27 ` [PATCH qemu v3 1/9] patches/extra: allow mirror job to use non-root block node Fiona Ebner
2026-11-18 14:27 ` [PATCH qemu-server v3 2/9] partially fix #7299: fix regression with guest IO limits applying to mirror job Fiona Ebner
2026-11-18 14:27 ` [PATCH qemu-server v3 3/9] partially fix #7299: migrate: fix regression with guest IO limits applying to NBD export Fiona Ebner
2026-11-18 14:27 ` [PATCH qemu-server v3 4/9] blockdev: attach: support explicitly attaching as writeable Fiona Ebner
2026-11-18 14:27 ` [PATCH qemu-server v3 5/9] blockdev: implement reopen function Fiona Ebner
2026-11-18 14:27 ` Fiona Ebner [this message]
2026-11-18 14:27 ` [PATCH qemu-server v3 7/9] qm: schema: declare 'nbdstop' command as being for internal use only Fiona Ebner
2026-11-18 14:27 ` [PATCH qemu-server v3 8/9] migrate: log messages from remote nbdstop command Fiona Ebner
2026-11-18 14:27 ` [PATCH qemu-server v3 9/9] partially fix #7836: allow migration for drive with read-only flag when using blockdev Fiona Ebner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261118143549.199143-7-f.ebner@proxmox.com \
--to=f.ebner@proxmox.com \
--cc=pve-devel@lists.proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.