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 5/9] blockdev: implement reopen function
Date: Fri, 24 Jul 2026 16:32:26 +0200	[thread overview]
Message-ID: <20260724143240.211130-6-f.ebner@proxmox.com> (raw)
In-Reply-To: <20260724143240.211130-1-f.ebner@proxmox.com>

Similar to the attach() function, but for re-opening an already
attached block node. Currently limited to non-throttle nodes.

Signed-off-by: Fiona Ebner <f.ebner@proxmox.com>
---
 src/PVE/QemuServer/Blockdev.pm | 68 ++++++++++++++++++++++++++++------
 1 file changed, 57 insertions(+), 11 deletions(-)

diff --git a/src/PVE/QemuServer/Blockdev.pm b/src/PVE/QemuServer/Blockdev.pm
index 879e1aab..dea46ca0 100644
--- a/src/PVE/QemuServer/Blockdev.pm
+++ b/src/PVE/QemuServer/Blockdev.pm
@@ -548,6 +548,33 @@ my sub blockdev_add {
 
 =pod
 
+=head3 generate_drive_blockdev_for_peer
+
+Helper for the C<attach> and C<reopen> functions, see C<attach> for the parameter descriptions.
+Returns the generated blockdev and the QMP peer information.
+
+=cut
+
+my sub generate_drive_blockdev_for_peer {
+    my ($storecfg, $id, $drive, $options) = @_;
+
+    my $qmp_peer = $options->{qsd} ? qsd_qmp_peer($id) : vm_qmp_peer($id);
+
+    my $machine_version;
+    if ($options->{qsd}) { # qemu-storage-daemon runs with the installed binary version
+        $machine_version =
+            'pc-i440fx-' . PVE::QemuServer::Machine::latest_installed_machine_version();
+    } else {
+        $machine_version = PVE::QemuServer::Machine::get_current_qemu_machine($id);
+    }
+
+    my $blockdev = generate_drive_blockdev($storecfg, $drive, $machine_version, $options);
+
+    return ($blockdev, $qmp_peer);
+}
+
+=pod
+
 =head3 attach
 
     my ($node_name, $read_only) = attach($storecfg, $id, $drive, $options);
@@ -596,17 +623,7 @@ state image.
 sub attach {
     my ($storecfg, $id, $drive, $options) = @_;
 
-    my $qmp_peer = $options->{qsd} ? qsd_qmp_peer($id) : vm_qmp_peer($id);
-
-    my $machine_version;
-    if ($options->{qsd}) { # qemu-storage-daemon runs with the installed binary version
-        $machine_version =
-            'pc-i440fx-' . PVE::QemuServer::Machine::latest_installed_machine_version();
-    } else {
-        $machine_version = PVE::QemuServer::Machine::get_current_qemu_machine($id);
-    }
-
-    my $blockdev = generate_drive_blockdev($storecfg, $drive, $machine_version, $options);
+    my ($blockdev, $qmp_peer) = generate_drive_blockdev_for_peer($storecfg, $id, $drive, $options);
 
     my $throttle_group_id;
     if (parse_top_node_name($blockdev->{'node-name'})) { # device top nodes need a throttle group
@@ -713,6 +730,35 @@ sub detach_fleecing_block_nodes {
     }
 }
 
+=pod
+
+=head3 reopen
+
+    reopen($storecfg, $id, $drive, $options);
+
+Re-open the already attached drive C<$drive> of the VM C<$id> while considering the additional
+options C<$options>. See C<attach> for the description of parameters and options. The C<no-throttle>
+option is currently required to be set.
+
+=cut
+
+sub reopen {
+    my ($storecfg, $id, $drive, $options) = @_;
+
+    # Will need additional consideration regarding the throttle group objects.
+    die "reopen for a throttle node is not implemented yet\n" if !$options->{'no-throttle'};
+
+    my ($blockdev, $qmp_peer) = generate_drive_blockdev_for_peer($storecfg, $id, $drive, $options);
+
+    if ($blockdev->{driver} eq 'zeroinit') { # zero-init does not support re-open, defer to child
+        $blockdev = $blockdev->{file};
+    }
+
+    qmp_cmd($qmp_peer, 'blockdev-reopen', options => [$blockdev]);
+
+    return;
+}
+
 sub resize {
     my ($vmid, $deviceid, $storecfg, $volid, $size) = @_;
 
-- 
2.47.3





  parent reply	other threads:[~2026-07-24 14:34 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-24 14:32 [PATCH-SERIES qemu/qemu-server 0/9] mirror: fix regressions with blockdev and allow migration with 'ro' flag Fiona Ebner
2026-07-24 14:32 ` [PATCH qemu 1/9] add patch to allow mirror job to use non-root block node Fiona Ebner
2026-07-24 14:32 ` [PATCH qemu-server 2/9] partially fix #7299: fix regression with guest IO limits applying to mirror job Fiona Ebner
2026-07-24 14:32 ` [PATCH qemu-server 3/9] partially fix #7299: migrate: fix regression with guest IO limits applying to NBD export Fiona Ebner
2026-07-24 14:32 ` [PATCH qemu-server 4/9] blockdev: attach: support explicitly attaching as writeable Fiona Ebner
2026-07-24 14:32 ` Fiona Ebner [this message]
2026-07-24 14:32 ` [PATCH qemu-server 6/9] partially fix #7836: allow mirror for drive with read-only flag when using blockdev Fiona Ebner
2026-07-24 14:32 ` [PATCH qemu-server 7/9] qm: schema: declare 'nbdstop' command as being for internal use only Fiona Ebner
2026-07-24 14:32 ` [PATCH qemu-server 8/9] migrate: log messages from remote nbdstop command Fiona Ebner
2026-07-24 14:32 ` [PATCH qemu-server 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=20260724143240.211130-6-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