public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Fiona Ebner <f.ebner@proxmox.com>
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	[thread overview]
Message-ID: <20261111120211.110737-7-f.ebner@proxmox.com> (raw)
In-Reply-To: <20261111120211.110737-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>
---

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





  parent reply	other threads:[~2026-11-11 12:03 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-11 12:01 [PATCH-SERIES qemu/qemu-server v2 0/9] mirror: fix regressions with blockdev and allow migration with 'ro' flag Fiona Ebner
2026-11-11 12:01 ` [PATCH qemu v2 1/9] patches/extra: allow mirror job to use non-root block node Fiona Ebner
2026-11-11 12:01 ` [PATCH qemu-server v2 2/9] partially fix #7299: fix regression with guest IO limits applying to mirror job Fiona Ebner
2026-11-11 12:01 ` [PATCH qemu-server v2 3/9] partially fix #7299: migrate: fix regression with guest IO limits applying to NBD export Fiona Ebner
2026-11-11 12:01 ` [PATCH qemu-server v2 4/9] blockdev: attach: support explicitly attaching as writeable Fiona Ebner
2026-11-11 12:01 ` [PATCH qemu-server v2 5/9] blockdev: implement reopen function Fiona Ebner
2026-11-11 12:01 ` Fiona Ebner [this message]
2026-11-11 12:01 ` [PATCH qemu-server v2 7/9] qm: schema: declare 'nbdstop' command as being for internal use only Fiona Ebner
2026-11-11 12:01 ` [PATCH qemu-server v2 8/9] migrate: log messages from remote nbdstop command Fiona Ebner
2026-11-11 12:01 ` [PATCH qemu-server v2 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=20261111120211.110737-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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal