Skip to content

Commit 9f98096

Browse files
weltlinglikebreath
authored andcommitted
block: Add UnsupportedFlags error variant for flag validation
Introduce ExecuteError::UnsupportedFlags to carry both the request type and the rejected flags value, replacing the generic ExecuteError::Unsupported at discard and write zeroes flag validation sites. This provides structured context for debugging without changing the returned VIRTIO_BLK_S_UNSUPP status. Signed-off-by: Anatol Belski <anbelski@linux.microsoft.com>
1 parent e4e2a37 commit 9f98096

1 file changed

Lines changed: 11 additions & 2 deletions

File tree

block/src/lib.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ pub enum ExecuteError {
169169
WriteAll(#[source] io::Error),
170170
#[error("Unsupported request: {0}")]
171171
Unsupported(u32),
172+
#[error("Unsupported flags {flags:#x} for request type {request_type}")]
173+
UnsupportedFlags { request_type: u32, flags: u32 },
172174
#[error("Failed to submit io uring")]
173175
SubmitIoUring(#[source] io::Error),
174176
#[error("Failed to get guest address")]
@@ -199,6 +201,7 @@ impl ExecuteError {
199201
ExecuteError::Write(_) => VIRTIO_BLK_S_IOERR,
200202
ExecuteError::WriteAll(_) => VIRTIO_BLK_S_IOERR,
201203
ExecuteError::Unsupported(_) => VIRTIO_BLK_S_UNSUPP,
204+
ExecuteError::UnsupportedFlags { .. } => VIRTIO_BLK_S_UNSUPP,
202205
ExecuteError::SubmitIoUring(_) => VIRTIO_BLK_S_IOERR,
203206
ExecuteError::GetHostAddress(_) => VIRTIO_BLK_S_IOERR,
204207
ExecuteError::AsyncRead(_) => VIRTIO_BLK_S_IOERR,
@@ -630,7 +633,10 @@ impl Request {
630633
// Per virtio spec v1.2 reject discard if any flag is set, including unmap.
631634
if discard_flags != 0 {
632635
warn!("Unsupported flags {discard_flags:#x} in discard request");
633-
return Err(ExecuteError::Unsupported(VIRTIO_BLK_T_DISCARD));
636+
return Err(ExecuteError::UnsupportedFlags {
637+
request_type: VIRTIO_BLK_T_DISCARD,
638+
flags: discard_flags,
639+
});
634640
}
635641

636642
let discard_sector = u64::from_le_bytes(discard_sector);
@@ -696,7 +702,10 @@ impl Request {
696702
// Per virtio spec v1.2 reject write zeroes if any unknown flag is set.
697703
if (wz_flags & !VIRTIO_BLK_WRITE_ZEROES_FLAG_UNMAP) != 0 {
698704
warn!("Unsupported flags {wz_flags:#x} in write zeroes request");
699-
return Err(ExecuteError::Unsupported(VIRTIO_BLK_T_WRITE_ZEROES));
705+
return Err(ExecuteError::UnsupportedFlags {
706+
request_type: VIRTIO_BLK_T_WRITE_ZEROES,
707+
flags: wz_flags,
708+
});
700709
}
701710

702711
let wz_offset = wz_sector * SECTOR_SIZE;

0 commit comments

Comments
 (0)