From: Kevin Wolf <kwolf@redhat.com>
To: virtio-comment@lists.linux.dev
Cc: kwolf@redhat.com, rjones@redhat.com, stefanha@redhat.com,
mst@redhat.com, cohuck@redhat.com
Subject: [PATCH 1/1] virtio-blk: Support extended device identifiers
Date: Fri, 4 Dec 2026 10:38:04 +0100 [thread overview]
Message-ID: <20261204093804.16684-2-kwolf@redhat.com> (raw)
In-Reply-To: <20261204093804.16684-1-kwolf@redhat.com>
So far, VIRTIO_BLK_T_GET_ID requests returned arbitrary ASCII strings
that were limited to 20 bytes and had no particular meaning attached.
Both of these properties are too limiting for some use cases.
While in theory, 20 ASCII bytes are enough to distinguish all devices of
a single machine, in practice users want descriptive names and sometimes
can't even freely choose the identifier. A common case is conversion of
an existing VM from a different device type while keeping the existing
(potentially longer) identifier so that the OS can stilll recognise the
disk with an identifier it stored before the conversion (e.g. think of
/dev/disk/by-id/ paths).
A different use case involves identifying the disk with a WWID, which
should be separate from the serial and have a defined structure and
meaning.
This adds a flag VIRTIO_BLK_F_EXT_GET_ID to enable an extended form of
the request type that supports multiple different identifier types and
identifier lengths up to 255 bytes.
There are two noteworthy compatibility considerations:
- There are concerns that applications might exist that cannot handle an
extension of the existing identifier (now called serial in agreement
with the implementations in Linux and QEMU) to more than 20 bytes.
While no such applications are known and it is generally expected that
new VMs can make use of longer strings without any problems, an
alternative device identifcation string is introduced so that a short
serial can be kept while still making a longer string available to the
driver.
- QEMU has an implementation bug that makes it accept a configuration
with serials longer than 20 bytes, but truncates it to 20 bytes in
VIRTIO_BLK_T_GET_ID. This has no impact on the device behaviour
specified in this change, but drivers may want to facilitate upgrades
from truncated serials to their full version by exposing the device
both with the full serial and a version truncated to 20 bytes (e.g.
for symlinks created in udev rules).
Signed-off-by: Kevin Wolf <kwolf@redhat.com>
---
device-types/blk/description.tex | 80 ++++++++++++++++++++++++++++++--
1 file changed, 75 insertions(+), 5 deletions(-)
diff --git a/device-types/blk/description.tex b/device-types/blk/description.tex
index 3b3a4e7..e8408c0 100644
--- a/device-types/blk/description.tex
+++ b/device-types/blk/description.tex
@@ -73,6 +73,10 @@ \subsection{Feature bits}\label{sec:Device Types / Block Device / Feature bits}
VIRTIO_BLK_REQ_FLAG_OUT_FUA flag in the \field{flags} bitfield of the
\field{virtio_blk_req} structure for VIRTIO_BLK_T_OUT requests.
+\item[VIRTIO_BLK_F_EXT_GET_ID (20)] Device supports the extended version of the
+ VIRTIO_BLK_T_GET_ID request type, which enables multiple identifier types
+ and longer values.
+
\end{description}
\subsubsection{Legacy Interface: Feature bits}\label{sec:Device Types / Block Device / Feature bits / Legacy Interface: Feature bits}
@@ -122,7 +126,9 @@ \subsection{Device configuration layout}\label{sec:Device Types / Block Device /
le32 max_write_zeroes_sectors;
le32 max_write_zeroes_seg;
u8 write_zeroes_may_unmap;
- u8 unused1[3];
+ u8 serial_len;
+ u8 device_id_len;
+ u8 scsi_name_len;
le32 max_secure_erase_sectors;
le32 max_secure_erase_seg;
le32 secure_erase_sector_alignment;
@@ -222,6 +228,19 @@ \subsection{Device configuration layout}\label{sec:Device Types / Block Device /
terminated by the device with a "zone resources exceeded" error as defined for
specific commands later.
+If the device offers VIRTIO_BLK_F_EXT_GET_ID, the following fields are valid
+and contain the length of an identification string in bytes, not including any
+trailing NUL characters. A value of 0 means that the respective identifier is
+not provided by the device. The fields can be read before the driver accepts
+the feature.
+
+\begin{itemize}
+\item \field{serial_len} is the length of the serial string (in previous
+ versions of the standard the single device ID string).
+\item \field{device_id_len} is the length of the secondary device ID string.
+\item \field{scsi_name_len} is the length of the SCSI name string.
+\end{itemize}
+
\subsubsection{Legacy Interface: Device configuration layout}\label{sec:Device Types / Block Device / Device configuration layout / Legacy Interface: Device configuration layout}
When using the legacy interface, transitional devices and drivers
MUST format the fields in struct virtio_blk_config
@@ -515,9 +534,45 @@ \subsection{Device Operation}\label{sec:Device Types / Block Device / Device Ope
the device to discard the specified range, provided that following reads return
zeroes.
-VIRTIO_BLK_T_GET_ID requests fetch the device ID string from the device into
-\field{data}. The device ID string is a NUL-padded ASCII string up to 20 bytes
-long. If the string is 20 bytes long then there is no NUL terminator.
+VIRTIO_BLK_T_GET_ID requests fetch a device ID string from the device into
+\field{data}.
+
+If the VIRTIO_BLK_F_EXT_GET_ID feature is negotiated, \field{sector} selects
+the device identifier type from of the following types:
+
+\begin{lstlisting}
+#define VIRTIO_BLK_ID_SERIAL 0
+#define VIRTIO_BLK_ID_DEVICE_ID 1
+#define VIRTIO_BLK_ID_SCSI_NAME 2
+\end{lstlisting}
+
+The device identifier types are defined as follows:
+\begin{itemize}
+\item[VIRTIO_BLK_ID_SERIAL] is an arbitrary NUL-terminated ASCII string (in
+ previous versions of the standard the single device ID string) serving as
+ the serial string.
+\item[VIRTIO_BLK_ID_DEVICE_ID] is also an arbitrary NUL-terminated ASCII string
+ and serves as an alternative device identifier primarily for cases where
+ the serial string cannot be extended beyond the traditional 20 bytes limit
+ for compatibility reasons, but a longer identification string is still
+ needed.
+\item[VIRTIO_BLK_ID_SCSI_NAME] is a NUL-terminated UTF-8 string to be
+ interpreted as a SCSI name string as defined by the SCSI Primary Commands
+ specification for VPD page 83h, designator type 8h.
+\end{itemize}
+
+The length field in the device configuration structure is of type u8 for all
+device identifier types, which limits their length to 255 bytes plus the
+terminating NUL byte.
+
+If \field{data} is longer than the requested device identifier including the
+terminating NUL byte, the device will put the device identifier at the start of
+\field{data} and the value of the remaining bytes in \field{data} is undefined.
+
+If the VIRTIO_BLK_F_EXT_GET_ID feature is not negotiated, the request always
+fetches the serial string, which is then a NUL-padded (not only NUL-terminated)
+ASCII string up to 20 bytes long. If the string is 20 bytes long, then there
+is no NUL terminator.
The \field{data} used for VIRTIO_BLK_T_GET_LIFETIME requests is populated
by the device, and is of the form
@@ -911,7 +966,11 @@ \subsection{Device Operation}\label{sec:Device Types / Block Device / Device Ope
virtio_blk_discard_write_zeroes for VIRTIO_BLK_T_DISCARD,
VIRTIO_BLK_T_SECURE_ERASE and VIRTIO_BLK_T_WRITE_ZEROES requests.
-The length of \field{data} MUST be 20 bytes for VIRTIO_BLK_T_GET_ID requests.
+If VIRTIO_BLK_F_EXT_GET_ID is not negotiated, the length of \field{data} MUST
+be 20 bytes for VIRTIO_BLK_T_GET_ID requests and \field{sector} SHOULD be 0.
+
+If VIRTIO_BLK_F_EXT_GET_ID is negotiated, \field{sector} MUST be a valid device
+identifier type.
VIRTIO_BLK_T_DISCARD requests MUST NOT contain more than
\field{max_discard_seg} struct virtio_blk_discard_write_zeroes segments in
@@ -1070,6 +1129,17 @@ \subsection{Device Operation}\label{sec:Device Types / Block Device / Device Ope
for implementations that do not wish to be safe against such data losses.
\end{note}
+If in a VIRTIO_BLK_T_GET_ID request, \field{data} is too short to keep the full
+device identifier, the device SHOULD set \field{status} to VIRTIO_BLK_S_IOERR
+and SHOULD NOT write to \field{data}. If VIRTIO_BLK_F_EXT_GET_ID was not
+negotiated, but the serial string of the device is longer than 20 bytes, this
+is always the case.
+
+If VIRTIO_BLK_F_EXT_GET_ID was negotiated and \field{sector} does not contain a
+valid device identifier type or the specified device identifier type is not
+available on the device, the device MUST set \field{status} to
+VIRTIO_BLK_S_UNSUPP and MUST NOT write to \field{data}.
+
If the device is backed by storage providing lifetime metrics (such as eMMC
or UFS persistent storage), the device SHOULD offer the VIRTIO_BLK_F_LIFETIME
flag. The flag MUST NOT be offered if the device is backed by storage for which
--
2.56.1
next prev parent reply other threads:[~2026-12-04 9:38 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-12-04 9:38 [PATCH 0/1] virtio-blk: Support extended device identifiers Kevin Wolf
2026-12-04 9:38 ` Kevin Wolf [this message]
2026-12-04 10:36 ` [PATCH 1/1] " Manos Pitsidianakis
2026-12-04 9:54 ` [PATCH 0/1] " Richard W.M. Jones
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=20261204093804.16684-2-kwolf@redhat.com \
--to=kwolf@redhat.com \
--cc=cohuck@redhat.com \
--cc=mst@redhat.com \
--cc=rjones@redhat.com \
--cc=stefanha@redhat.com \
--cc=virtio-comment@lists.linux.dev \
/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