This field is only valid when the VIRTIO_BLK_F_BLK_SIZE feature bit is set. The blk_size field represents the smallest addressable unit of data that can be read from or written to the device. It is always a power of two and typically ranges from 512 bytes to larger values such as 4 KB. Linux/Windows systems typically use 512-byte/4-KB block sizes. This description provides clarity on the constraints of the blk_size field. Signed-off-by: Max Gurtovoy <mgurtovoy@xxxxxxxxxx> --- device-types/blk/description.tex | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/device-types/blk/description.tex b/device-types/blk/description.tex index 2712ada..88a7591 100644 --- a/device-types/blk/description.tex +++ b/device-types/blk/description.tex @@ -3,7 +3,10 @@ \section{Block Device}\label{sec:Device Types / Block Device} The virtio block device is a simple virtual block device (ie. disk). Read and write requests (and other exotic requests) are placed in one of its queues, and serviced (probably out of order) by the -device except where noted. +device except where noted. Each block device consists of a sequence of logical +blocks. A logical block represents the smallest addressable unit of data that +can be read from or written to the device. The logical block size is always a +power of two. Logical block sizes may be 512 bytes, 1KB, 2KB, 4KB, 8KB, etc. \subsection{Device ID}\label{sec:Device Types / Block Device / Device ID} 2 @@ -135,6 +138,9 @@ \subsection{Device configuration layout}\label{sec:Device Types / Block Device / present. The availability of the others all depend on various feature bits as indicated above. +The field \field{blk_size} exists only if VIRTIO_BLK_F_BLK_SIZE is set. This field +reports the logical block size of the device, expressed in bytes. + The field \field{num_queues} only exists if VIRTIO_BLK_F_MQ is set. This field specifies the number of queues. @@ -228,7 +234,7 @@ \subsection{Device Initialization}\label{sec:Device Types / Block Device / Devic \item The device size can be read from \field{capacity}. \item If the VIRTIO_BLK_F_BLK_SIZE feature is negotiated, - \field{blk_size} can be read to determine the optimal sector size + \field{blk_size} can be read to determine the logical block size for the driver to use. This does not affect the units used in the protocol (always 512 bytes), but awareness of the correct value can affect performance. @@ -282,6 +288,12 @@ \subsection{Device Initialization}\label{sec:Device Types / Block Device / Devic \drivernormative{\subsubsection}{Device Initialization}{Device Types / Block Device / Device Initialization} +Drivers MUST negotiate VIRTIO_BLK_F_BLK_SIZE if the feature is offered by the +device. + +If the VIRTIO_BLK_F_BLK_SIZE feature is not offered by the device, then drivers +MAY assume that the logical block size is 512 bytes. + Drivers SHOULD NOT negotiate VIRTIO_BLK_F_FLUSH if they are incapable of sending VIRTIO_BLK_T_FLUSH commands. @@ -319,6 +331,10 @@ \subsection{Device Initialization}\label{sec:Device Types / Block Device / Devic \devicenormative{\subsubsection}{Device Initialization}{Device Types / Block Device / Device Initialization} +Devices SHOULD always offer VIRTIO_BLK_F_BLK_SIZE feature. When this feature is +offered, devices MUST initialize \field{blk_size} to a power of two greater +than or equal to 512. + Devices SHOULD always offer VIRTIO_BLK_F_FLUSH, and MUST offer it if they offer VIRTIO_BLK_F_CONFIG_WCE. -- 2.18.1