public inbox for pve-devel@lists.proxmox.com
 help / color / mirror / Atom feed
From: Dominik Csapak <d.csapak@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server 5/5] drive device: check the machine version for blockdev only once
Date: Thu, 15 Oct 2026 09:52:19 +0200	[thread overview]
Message-ID: <20261015075428.572882-6-d.csapak@proxmox.com> (raw)
In-Reply-To: <20261015075428.572882-1-d.csapak@proxmox.com>

print_drivedevice_full checks for machine version 10.0 in five places
to decide whether the drive uses -blockdev. Do the check once, so the
places read as what they decide and only one call needs adapting when
the source of the machine version changes.

No functional change intended.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
---
 src/PVE/QemuServer/DriveDevice.pm | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/src/PVE/QemuServer/DriveDevice.pm b/src/PVE/QemuServer/DriveDevice.pm
index 8974bae0..621fcc2b 100644
--- a/src/PVE/QemuServer/DriveDevice.pm
+++ b/src/PVE/QemuServer/DriveDevice.pm
@@ -78,12 +78,14 @@ sub print_drivedevice_full {
         PVE::QemuServer::Machine::extract_version($machine_type, kvm_user_version());
     my $has_write_cache = 1; # whether the device has a 'write-cache' option
 
+    my $use_blockdev = min_version($machine_version, 10, 0);
+
     my $drive_id = PVE::QemuServer::Drive::get_drive_id($drive);
     if ($drive->{interface} eq 'virtio') {
         my $pciaddr = print_pci_addr("$drive_id", $arch);
         $device = 'virtio-blk-pci';
         # for the switch to -blockdev, there is no blockdev for 'none'
-        if (!min_version($machine_version, 10, 0) || $drive->{file} ne 'none') {
+        if (!$use_blockdev || $drive->{file} ne 'none') {
             $device .= ",drive=drive-$drive_id";
         }
         $device .= ",id=${drive_id}${pciaddr}";
@@ -104,16 +106,14 @@ sub print_drivedevice_full {
                 . ",lun=$drive->{index}";
         }
         # for the switch to -blockdev, there is no blockdev for 'none'
-        if (!min_version($machine_version, 10, 0) || $drive->{file} ne 'none') {
+        if (!$use_blockdev || $drive->{file} ne 'none') {
             $device .= ",drive=drive-$drive_id";
         }
         $device .= ",id=$drive_id";
 
         # For the switch to -blockdev, the SCSI device ID needs to be explicitly specified. Note
         # that only ide-cd and ide-hd have a 'device_id' option.
-        if (
-            min_version($machine_version, 10, 0) && ($device_type eq 'cd' || $device_type eq 'hd')
-        ) {
+        if ($use_blockdev && ($device_type eq 'cd' || $device_type eq 'hd')) {
             $device .= ",device_id=drive-${drive_id}";
         }
 
@@ -169,7 +169,7 @@ sub print_drivedevice_full {
         } else {
             $device .= ",bus=ahci$controller.$unit";
         }
-        if (!min_version($machine_version, 10, 0) || $drive->{file} ne 'none') {
+        if (!$use_blockdev || $drive->{file} ne 'none') {
             $device .= ",drive=drive-$drive_id";
         }
         $device .= ",id=$drive_id";
@@ -198,7 +198,7 @@ sub print_drivedevice_full {
         $device .= ",serial=$serial";
     }
 
-    if (min_version($machine_version, 10, 0)) { # for the switch to -blockdev
+    if ($use_blockdev) { # for the switch to -blockdev
         if (!drive_is_cdrom($drive) && $has_write_cache) {
             my $write_cache = 'on';
             if (my $cache = $drive->{cache}) {
-- 
2.47.3





      parent reply	other threads:[~2026-10-15  7:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-15  7:52 [PATCH qemu-server 0/5] small cleanup/refactor/fixes Dominik Csapak
2026-10-15  7:52 ` [PATCH qemu-server 1/5] helpers: factor out the version parts parsing Dominik Csapak
2026-10-15  7:52 ` [PATCH qemu-server 2/5] usb: drop always-true spice_usb3 feature flag Dominik Csapak
2026-10-15  7:52 ` [PATCH qemu-server 3/5] net: use version guard for the machine version checks of NICs Dominik Csapak
2026-10-15  7:52 ` [PATCH qemu-server 4/5] usb: factor out the default usb bus of the tablet Dominik Csapak
2026-10-15  7:52 ` Dominik Csapak [this message]

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=20261015075428.572882-6-d.csapak@proxmox.com \
    --to=d.csapak@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