all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: "Michael Köppl" <m.koeppl@proxmox.com>
To: pve-devel@lists.proxmox.com
Subject: [PATCH qemu-server 1/2] drive device: use configured serial as SCSI device ID
Date: Wed, 28 Oct 2026 20:07:12 +0100	[thread overview]
Message-ID: <20261028190713.2788477-2-m.koeppl@proxmox.com> (raw)
In-Reply-To: <20261028190713.2788477-1-m.koeppl@proxmox.com>

Since the switch to '-blockdev', the device ID of SCSI disks is
explicitly set to the drive name, even if serial is configured. So with
machine version 10.0 or newer, a SCSI disk with a serial reports the
drive name (e.g. 'drive-scsi1') and the /dev/disk/by-id paths that udev
derives from it no longer contain the serial. In a guest running Proxmox
VE, the disk list API endpoint (/nodes/<node>/disks/list) therefore does
not report the configured serial either.

Set the device ID explicitly to the serial if one is configured, like
libvirt does since its switch to '-blockdev' [0]. For serials of up to
20 bytes, this is the same device ID that QEMU used by default with
'-drive'.

Relying on QEMU's default instead would not work for all serials. QEMU
accepts serials of up to 36 bytes [1], but only uses serials of up to
20 bytes as the default device ID and refuses to start the device for
longer ones instead of truncating them [2][3].

As this changes what the guest sees, only do so starting with machine
version 11.1+pve1. Check it with the version guard, so that only VMs
with a SCSI disk with a serial require the new revision.

[0]: https://gitlab.com/libvirt/libvirt/-/commit/a1dce96236f6d35167924fa7e6a70f58f394b23c
[1]: https://lists.gnu.org/archive/html/qemu-stable/2016-09/msg00117.html
[2]: https://lists.gnu.org/archive/html/qemu-block/2024-06/msg00027.html
[3]: https://github.com/systemd/systemd/issues/39262

Fixes: 46d1225e ("drive device: fix regression with missing '/dev/disk/by-id' paths")

Signed-off-by: Michael Köppl <m.koeppl@proxmox.com>
---
Added a machine version 11.1+pve1 specifically for this. If it makes
more sense to wait for 11.2, considering this is not an urgent issue,
I'll of course send a v2. Should be a bit simpler to implement anyway.

 src/PVE/QemuServer.pm             |  7 ++++---
 src/PVE/QemuServer/DriveDevice.pm | 22 +++++++++++++++++++---
 src/PVE/QemuServer/Machine.pm     |  6 ++++++
 3 files changed, 29 insertions(+), 6 deletions(-)

diff --git a/src/PVE/QemuServer.pm b/src/PVE/QemuServer.pm
index 1efeeb66..36471bdf 100644
--- a/src/PVE/QemuServer.pm
+++ b/src/PVE/QemuServer.pm
@@ -3686,9 +3686,10 @@ sub config_to_command {
                 push @$devices, '-drive', $drive_cmd;
             }

-            push @$devices, '-device', print_drivedevice_full(
-                $storecfg, $conf, $vmid, $drive, $arch, $machine_type,
-            );
+            push @$devices, '-device',
+                print_drivedevice_full(
+                    $storecfg, $conf, $vmid, $drive, $arch, $machine_type, $version_guard,
+                );
         },
     );

diff --git a/src/PVE/QemuServer/DriveDevice.pm b/src/PVE/QemuServer/DriveDevice.pm
index 621fcc2b..980a217a 100644
--- a/src/PVE/QemuServer/DriveDevice.pm
+++ b/src/PVE/QemuServer/DriveDevice.pm
@@ -69,13 +69,23 @@ sub get_max_scsihw_index {
 }

 sub print_drivedevice_full {
-    my ($storecfg, $conf, $vmid, $drive, $arch, $machine_type) = @_;
+    my (
+        $storecfg,
+        $conf,
+        $vmid,
+        $drive,
+        $arch,
+        $machine_type,
+        $version_guard, # checks the machine version and records the required +pveX revision
+    ) = @_;

     my $device = '';
     my $maxdev = 0;

     my $machine_version =
         PVE::QemuServer::Machine::extract_version($machine_type, kvm_user_version());
+    # when hotplugging, the machine is already running, so there is no required version to record
+    $version_guard //= sub { return min_version($machine_version, @_); };
     my $has_write_cache = 1; # whether the device has a 'write-cache' option

     my $use_blockdev = min_version($machine_version, 10, 0);
@@ -112,9 +122,15 @@ sub print_drivedevice_full {
         $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.
+        # that only ide-cd and ide-hd have a 'device_id' option. Since machine version 11.1+pve1,
+        # a configured serial is used as the device ID, like QEMU's default with -drive.
         if ($use_blockdev && ($device_type eq 'cd' || $device_type eq 'hd')) {
-            $device .= ",device_id=drive-${drive_id}";
+            if ($drive->{serial} && $version_guard->(11, 1, 1)) {
+                my $serial = _escape_qemu_arg_value(URI::Escape::uri_unescape($drive->{serial}));
+                $device .= ",device_id=$serial";
+            } else {
+                $device .= ",device_id=drive-${drive_id}";
+            }
         }

         if ($drive->{ssd} && ($device_type eq 'block' || $device_type eq 'hd')) {
diff --git a/src/PVE/QemuServer/Machine.pm b/src/PVE/QemuServer/Machine.pm
index 35161d1f..68cc5daf 100644
--- a/src/PVE/QemuServer/Machine.pm
+++ b/src/PVE/QemuServer/Machine.pm
@@ -50,6 +50,12 @@ our $PVE_MACHINE_VERSION = {
             '+pve2' => 'Enable hv_emcs for Windows 11/2022/2025 to mitigate issues with VBS.',
         },
     },
+    '11.1' => {
+        highest => 1,
+        revisions => {
+            '+pve1' => 'Use the configured serial as device ID for SCSI disks.',
+        },
+    },
 };

 my $machine_fmt = {
--
2.47.3





  reply	other threads:[~2026-10-28 19:07 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-28 19:07 [PATCH qemu-server 0/2] use configured serial as SCSI device ID Michael Köppl
2026-10-28 19:07 ` Michael Köppl [this message]
2026-10-28 19:07 ` [PATCH qemu-server 2/2] test: cfg2cmd: add tests for SCSI disks with a serial Michael Köppl

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=20261028190713.2788477-2-m.koeppl@proxmox.com \
    --to=m.koeppl@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.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal