From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gate001.proxmox.com (gate001.proxmox.com [IPv6:2a0f:8001:1:32::40]) by lore.proxmox.com (Postfix) with ESMTPS id 90A271FF0DF for ; Thu, 15 Oct 2026 09:54:40 +0200 (CEST) Received: from gate001.proxmox.com (localhost.localdomain [127.0.0.1]) by gate001.proxmox.com (Proxmox) with ESMTP id CD98421514; Thu, 15 Oct 2026 09:54:33 +0200 (CEST) From: Dominik Csapak 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 Message-ID: <20261015075428.572882-6-d.csapak@proxmox.com> X-Mailer: git-send-email 2.47.3 In-Reply-To: <20261015075428.572882-1-d.csapak@proxmox.com> References: <20261015075428.572882-1-d.csapak@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL 0.368 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: PDPONEDYYIIYJ5ZPY3UHPJJRLXWUJCKR X-Message-ID-Hash: PDPONEDYYIIYJ5ZPY3UHPJJRLXWUJCKR X-MailFrom: d.csapak@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: 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 --- 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