Skip to content

Commit

Permalink
chore: add thiserror::Error for QueueError
Browse files Browse the repository at this point in the history
Signed-off-by: Diana Popa <[email protected]>
  • Loading branch information
dianpopa committed Feb 2, 2023
1 parent ef91085 commit 69b8b33
Showing 1 changed file with 4 additions and 17 deletions.
21 changes: 4 additions & 17 deletions src/devices/src/virtio/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// found in the THIRD-PARTY file.

use std::cmp::min;
use std::fmt;
use std::num::Wrapping;
use std::sync::atomic::{fence, Ordering};

Expand All @@ -26,26 +25,14 @@ pub(super) const VIRTQ_DESC_F_WRITE: u16 = 0x2;
// The Virtio Spec 1.0 defines the alignment of VirtIO descriptor is 16 bytes,
// which fulfills the explicit constraint of GuestMemoryMmap::read_obj_from_addr().

#[derive(Debug, derive_more::From)]
#[derive(Debug, thiserror::Error)]
pub enum QueueError {
/// Descriptor index out of bounds.
#[error("Descriptor index out of bounds: {0}.")]
DescIndexOutOfBounds(u16),
/// Attempted an invalid write into the used ring.
UsedRing(GuestMemoryError),
}

impl fmt::Display for QueueError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use self::QueueError::*;

match self {
DescIndexOutOfBounds(val) => write!(f, "Descriptor index out of bounds: {val}"),
UsedRing(err) => write!(
f,
"Failed to write value into the virtio queue used ring: {err}"
),
}
}
#[error("Failed to write value into the virtio queue used ring: {0}")]
UsedRing(#[from] GuestMemoryError),
}

/// A virtio descriptor constraints with C representative.
Expand Down

0 comments on commit 69b8b33

Please sign in to comment.