Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion src/vmm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ gdb = ["arrayvec", "gdbstub", "gdbstub_arch"]

acpi_tables = { path = "../acpi-tables" }
aes-gcm = { version = "0.10.1", default-features = false, features = ["aes"] }
anyhow = "1.0.100"
arrayvec = { version = "0.7.6", optional = true }
aws-lc-rs = { version = "1.14.0", features = ["bindgen"] }
base64 = "0.22.1"
Expand Down
32 changes: 0 additions & 32 deletions src/vmm/src/device_manager/mmio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@ use crate::arch::{RTC_MEM_START, SERIAL_MEM_START};
#[cfg(target_arch = "aarch64")]
use crate::devices::legacy::{RTCDevice, SerialDevice};
use crate::devices::pseudo::BootTimer;
use crate::devices::virtio::device::VirtioDevice;
use crate::devices::virtio::transport::mmio::MmioTransport;
use crate::vstate::bus::{Bus, BusError};
#[cfg(target_arch = "x86_64")]
Expand All @@ -41,12 +40,6 @@ pub enum MmioError {
BusInsert(#[from] BusError),
/// Failed to allocate requested resourc: {0}
Cmdline(#[from] linux_loader::cmdline::Error),
/// Failed to find the device on the bus.
DeviceNotFound,
/// Invalid device type found on the MMIO bus.
InvalidDeviceType,
/// {0}
InternalDeviceError(String),
/// Could not create IRQ for MMIO device: {0}
CreateIrq(#[from] std::io::Error),
/// Invalid MMIO IRQ configuration.
Expand Down Expand Up @@ -407,31 +400,6 @@ impl MMIODeviceManager {
Ok(())
}

/// Run fn `f()` for the virtio device matching `virtio_type` and `id`.
pub fn with_virtio_device_with_id<T, F>(
&self,
virtio_type: u32,
id: &str,
f: F,
) -> Result<(), MmioError>
where
T: VirtioDevice + 'static + Debug,
F: FnOnce(&mut T) -> Result<(), String>,
{
if let Some(device) = self.get_virtio_device(virtio_type, id) {
let virtio_device = device.inner.lock().expect("Poisoned lock").device();
let mut dev = virtio_device.lock().expect("Poisoned lock");
f(dev
.as_mut_any()
.downcast_mut::<T>()
.ok_or(MmioError::InvalidDeviceType)?)
.map_err(MmioError::InternalDeviceError)?;
} else {
return Err(MmioError::DeviceNotFound);
}
Ok(())
}

#[cfg(target_arch = "aarch64")]
pub fn virtio_device_info(&self) -> Vec<&MMIODeviceInfo> {
let mut device_info = Vec::new();
Expand Down
29 changes: 5 additions & 24 deletions src/vmm/src/device_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,8 @@ pub enum AttachDeviceError {
#[derive(Debug, thiserror::Error, displaydoc::Display)]
/// Error while searching for a VirtIO device
pub enum FindDeviceError {
/// Device type is invalid
InvalidDeviceType,
/// Device not found
DeviceNotFound,
/// Internal Device error: {0}
InternalDeviceError(anyhow::Error),
}

#[derive(Debug)]
Expand Down Expand Up @@ -372,36 +368,21 @@ impl DeviceManager {
}

/// Run fn `f()` for the virtio device matching `virtio_type` and `id`.
pub fn try_with_virtio_device_with_id<T, F, R, E>(
&self,
id: &str,
f: F,
) -> Result<R, FindDeviceError>
pub fn with_virtio_device<T, F, R>(&self, id: &str, f: F) -> Result<R, FindDeviceError>
where
T: VirtioDevice + 'static + Debug,
E: std::error::Error + 'static + Send + Sync,
F: FnOnce(&mut T) -> Result<R, E>,
F: FnOnce(&mut T) -> R,
{
if let Some(device) = self.get_virtio_device(T::const_device_type(), id) {
let mut dev = device.lock().expect("Poisoned lock");
f(dev
Ok(f(dev
.as_mut_any()
.downcast_mut::<T>()
.ok_or(FindDeviceError::InvalidDeviceType)?)
.map_err(|e| FindDeviceError::InternalDeviceError(e.into()))
.expect("Invalid device for a given device type")))
} else {
Err(FindDeviceError::DeviceNotFound)
}
}

/// Run fn `f()` for the virtio device matching `virtio_type` and `id`.
pub fn with_virtio_device_with_id<T, F, R>(&self, id: &str, f: F) -> Result<R, FindDeviceError>
where
T: VirtioDevice + 'static + Debug,
F: FnOnce(&mut T) -> R,
{
self.try_with_virtio_device_with_id(id, |dev: &mut T| Ok::<R, FindDeviceError>(f(dev)))
}
}

#[derive(Debug, Default, Clone, Serialize, Deserialize)]
Expand Down Expand Up @@ -471,7 +452,7 @@ impl<'a> Persist<'a> for DeviceManager {
fn restore(
constructor_args: Self::ConstructorArgs,
state: &Self::State,
) -> Result<Self, Self::Error> {
) -> std::result::Result<Self, Self::Error> {
// Setup legacy devices in case of x86
#[cfg(target_arch = "x86_64")]
let legacy_devices = Self::create_legacy_devices(
Expand Down
22 changes: 11 additions & 11 deletions src/vmm/src/device_manager/pci_mngr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use event_manager::{MutEventSubscriber, SubscriberOps};
use log::{debug, error, warn};
use serde::{Deserialize, Serialize};

use super::persist::{MmdsState, SharedDeviceType};
use super::persist::MmdsState;
use crate::devices::pci::PciSegment;
use crate::devices::virtio::balloon::Balloon;
use crate::devices::virtio::balloon::persist::{BalloonConstructorArgs, BalloonState};
Expand Down Expand Up @@ -419,8 +419,8 @@ impl<'a> Persist<'a> for PciDevices {

constructor_args
.vm_resources
.update_from_restored_device(SharedDeviceType::Balloon(device.clone()))
.unwrap();
.balloon
.set_device(device.clone());

pci_devices
.restore_pci_device(
Expand All @@ -444,8 +444,8 @@ impl<'a> Persist<'a> for PciDevices {

constructor_args
.vm_resources
.update_from_restored_device(SharedDeviceType::VirtioBlock(device.clone()))
.unwrap();
.block
.add_virtio_device(device.clone());

pci_devices
.restore_pci_device(
Expand Down Expand Up @@ -494,8 +494,8 @@ impl<'a> Persist<'a> for PciDevices {

constructor_args
.vm_resources
.update_from_restored_device(SharedDeviceType::Network(device.clone()))
.unwrap();
.net_builder
.add_device(device.clone());

pci_devices
.restore_pci_device(
Expand Down Expand Up @@ -527,8 +527,8 @@ impl<'a> Persist<'a> for PciDevices {

constructor_args
.vm_resources
.update_from_restored_device(SharedDeviceType::Vsock(device.clone()))
.unwrap();
.vsock
.set_device(device.clone());

pci_devices
.restore_pci_device(
Expand All @@ -550,8 +550,8 @@ impl<'a> Persist<'a> for PciDevices {

constructor_args
.vm_resources
.update_from_restored_device(SharedDeviceType::Entropy(device.clone()))
.unwrap();
.entropy
.set_device(device.clone());

pci_devices
.restore_pci_device(
Expand Down
30 changes: 11 additions & 19 deletions src/vmm/src/device_manager/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ use crate::devices::virtio::vsock::persist::{
};
use crate::devices::virtio::vsock::{Vsock, VsockError, VsockUnixBackend, VsockUnixBackendError};
use crate::mmds::data_store::MmdsVersion;
use crate::resources::{ResourcesError, VmResources};
use crate::resources::VmResources;
use crate::snapshot::Persist;
use crate::vmm_config::mmds::MmdsConfigError;
use crate::vstate::bus::BusError;
Expand Down Expand Up @@ -73,8 +73,6 @@ pub enum DevicePersistError {
MmdsConfig(#[from] MmdsConfigError),
/// Entropy: {0}
Entropy(#[from] EntropyError),
/// Resource misconfiguration: {0}. Is the snapshot file corrupted?
ResourcesError(#[from] ResourcesError),
/// Could not activate device: {0}
DeviceActivation(#[from] ActivateError),
}
Expand Down Expand Up @@ -128,17 +126,6 @@ pub struct DeviceStates {
pub entropy_device: Option<VirtioDeviceState<EntropyState>>,
}

/// A type used to extract the concrete `Arc<Mutex<T>>` for each of the device
/// types when restoring from a snapshot.
#[derive(Debug)]
pub enum SharedDeviceType {
VirtioBlock(Arc<Mutex<Block>>),
Network(Arc<Mutex<Net>>),
Balloon(Arc<Mutex<Balloon>>),
Vsock(Arc<Mutex<Vsock<VsockUnixBackend>>>),
Entropy(Arc<Mutex<Entropy>>),
}

pub struct MMIODevManagerConstructorArgs<'a> {
pub mem: &'a GuestMemoryMmap,
pub vm: &'a Arc<Vm>,
Expand Down Expand Up @@ -422,7 +409,8 @@ impl<'a> Persist<'a> for MMIODeviceManager {

constructor_args
.vm_resources
.update_from_restored_device(SharedDeviceType::Balloon(device.clone()))?;
.balloon
.set_device(device.clone());

restore_helper(
device.clone(),
Expand All @@ -444,7 +432,8 @@ impl<'a> Persist<'a> for MMIODeviceManager {

constructor_args
.vm_resources
.update_from_restored_device(SharedDeviceType::VirtioBlock(device.clone()))?;
.block
.add_virtio_device(device.clone());

restore_helper(
device.clone(),
Expand Down Expand Up @@ -483,7 +472,8 @@ impl<'a> Persist<'a> for MMIODeviceManager {

constructor_args
.vm_resources
.update_from_restored_device(SharedDeviceType::Network(device.clone()))?;
.net_builder
.add_device(device.clone());

restore_helper(
device.clone(),
Expand Down Expand Up @@ -512,7 +502,8 @@ impl<'a> Persist<'a> for MMIODeviceManager {

constructor_args
.vm_resources
.update_from_restored_device(SharedDeviceType::Vsock(device.clone()))?;
.vsock
.set_device(device.clone());

restore_helper(
device.clone(),
Expand All @@ -536,7 +527,8 @@ impl<'a> Persist<'a> for MMIODeviceManager {

constructor_args
.vm_resources
.update_from_restored_device(SharedDeviceType::Entropy(device.clone()))?;
.entropy
.set_device(device.clone());

restore_helper(
device.clone(),
Expand Down
Loading
Loading