Commit 6ea787b258 for qemu.org
commit 6ea787b2587ca4652f3ebfd2c08b26922fe073a9
Author: Kevin Wolf <kwolf@redhat.com>
Date: Fri Oct 30 00:10:00 2026 +0100
virtio-blk: Deprecate silent truncation of serial
Commit a8686a9b, which made serial a qdev property instead of relying on
-drive options, accidentally allowed specifying serial strings of
arbitraty length while the virtio-blk protocol can only communicate 20
characters to the guest. This means that a longer serial number on the
command line is silently truncated to 20 characters from the guest
perspective.
This is obviously bad behaviour. People are specifying longer serials in
practice and guests will see something different than what was
configured. Instead of silent truncation, this should be an error.
Deprecate the silent truncation for now as a first step towards making
it an error later.
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Message-ID: <20261029231001.194240-4-kwolf@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
diff --git a/docs/about/deprecated.rst b/docs/about/deprecated.rst
index dab47b6ca3..0891bbc44d 100644
--- a/docs/about/deprecated.rst
+++ b/docs/about/deprecated.rst
@@ -362,6 +362,19 @@ the addition of volatile memory support, it is now necessary to distinguish
between persistent and volatile memory backends. As such, memdev is deprecated
in favor of persistent-memdev.
+``-device virtio-blk,serial=more_than_20_characters`` (since 11.2)
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The ``virtio-blk`` device has a limitation of 20 characters for the serial
+string. Accidentally, QEMU started accepting longer strings on the command line
+in version 0.15.0, but it was still silently truncated to 20 characters for
+guests.
+
+Specifying a longer serial than can be exposed to the guest is a configuration
+error and deprecated; it will become a hard error in later versions. If the
+truncation is intentional, explicitly specify the serial already in truncated
+form on the command line instead.
+
Block device options
''''''''''''''''''''
diff --git a/hw/block/virtio-blk.c b/hw/block/virtio-blk.c
index 3f236f22d5..eeeb405127 100644
--- a/hw/block/virtio-blk.c
+++ b/hw/block/virtio-blk.c
@@ -1849,6 +1849,12 @@ static void virtio_blk_device_realize(DeviceState *dev, Error **errp)
return;
}
+ if (conf->serial && strlen(conf->serial) > VIRTIO_BLK_ID_BYTES) {
+ warn_report("serial is longer than %d characters and will be truncated "
+ "for the guest. This configuration is deprecated.",
+ VIRTIO_BLK_ID_BYTES);
+ }
+
if (!blkconf_apply_backend_options(&conf->conf,
!blk_supports_write_perm(conf->conf.blk),
true, errp)) {