Skip to content

Commit

Permalink
vmm: Refactor reset func to use ResetError
Browse files Browse the repository at this point in the history
Signed-off-by: Adam Jensen <[email protected]>
  • Loading branch information
acj committed Jan 31, 2024
1 parent 8e02dc1 commit 8f182ad
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
9 changes: 4 additions & 5 deletions src/vmm/src/devices/virtio/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use utils::eventfd::EventFd;

use super::mmio::{VIRTIO_MMIO_INT_CONFIG, VIRTIO_MMIO_INT_VRING};
use super::queue::Queue;
use super::ActivateError;
use super::{ActivateError, ResetError};
use crate::devices::virtio::AsAny;
use crate::logger::{error, warn};
use crate::vstate::memory::GuestMemoryMmap;
Expand Down Expand Up @@ -174,10 +174,9 @@ pub trait VirtioDevice: AsAny + Send {
/// Checks if the resources of this device are activated.
fn is_activated(&self) -> bool;

/// Optionally deactivates this device and returns ownership of the guest memory map, interrupt
/// event, and queue events.
fn reset(&mut self) -> Option<(EventFd, Vec<EventFd>)> {
None
/// Optionally deactivates this device.
fn reset(&mut self) -> Result<(), ResetError> {
Err(ResetError::NotImplemented)
}
}

Expand Down
10 changes: 7 additions & 3 deletions src/vmm/src/devices/virtio/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,12 @@ impl MmioTransport {
let mut device_status = self.device_status;
let reset_result = self.locked_device().reset();
match reset_result {
Some((_interrupt_evt, mut _queue_evts)) => {}
None => {
Ok(_) => {
// The device MUST initialize device status to 0 upon reset.
device_status = INIT;
}
Err(e) => {
warn!("failed to reset virtio device: {:?}", e);
device_status |= FAILED;
}
}
Expand Down Expand Up @@ -469,7 +473,7 @@ pub(crate) mod tests {
let m = single_region_mem(0x1000);
let mut dummy = DummyDevice::new();
// Validate reset is no-op.
assert!(dummy.reset().is_none());
assert!(dummy.reset().is_err());
let mut d = MmioTransport::new(m, Arc::new(Mutex::new(dummy)), false);

// We just make sure here that the implementation of a mmio device behaves as we expect,
Expand Down

0 comments on commit 8f182ad

Please sign in to comment.