Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/firecracker/src/api_server/parsed_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ impl ParsedRequest {
}

pub(crate) fn convert_to_response(
request_outcome: &std::result::Result<VmmData, VmmActionError>,
request_outcome: &Result<VmmData, VmmActionError>,
) -> Response {
match request_outcome {
Ok(vmm_data) => match vmm_data {
Expand Down
10 changes: 5 additions & 5 deletions src/jailer/src/cgroup.rs
Original file line number Diff line number Diff line change
Expand Up @@ -522,7 +522,7 @@ pub mod test_util {
pub fn create_file_with_contents<P: AsRef<Path> + Debug>(
filename: P,
contents: &str,
) -> std::result::Result<(), std::io::Error> {
) -> Result<(), std::io::Error> {
let mut file = OpenOptions::new()
.read(true)
.write(true)
Expand All @@ -534,7 +534,7 @@ pub mod test_util {
Ok(())
}

pub fn new() -> std::result::Result<MockCgroupFs, std::io::Error> {
pub fn new() -> Result<MockCgroupFs, std::io::Error> {
let mock_jailer_dir = TempDir::new().unwrap();
let mock_proc_mounts = mock_jailer_dir.as_path().join("proc/mounts");
let mock_sys_cgroups = mock_jailer_dir.as_path().join("sys_cgroup");
Expand All @@ -557,7 +557,7 @@ pub mod test_util {

// Populate the mocked proc/mounts file with cgroupv2 entries
// Also create a directory structure that simulates cgroupsv2 layout
pub fn add_v2_mounts(&mut self) -> std::result::Result<(), std::io::Error> {
pub fn add_v2_mounts(&mut self) -> Result<(), std::io::Error> {
writeln!(
self.mounts_file,
"cgroupv2 {}/unified cgroup2 rw,nosuid,nodev,noexec,relatime,nsdelegate 0 0",
Expand All @@ -574,7 +574,7 @@ pub mod test_util {
}

// Populate the mocked proc/mounts file with cgroupv1 entries
pub fn add_v1_mounts(&mut self) -> std::result::Result<(), std::io::Error> {
pub fn add_v1_mounts(&mut self) -> Result<(), std::io::Error> {
let controllers = vec![
"memory",
"net_cls,net_prio",
Expand Down Expand Up @@ -610,7 +610,7 @@ mod tests {
use crate::cgroup::test_util::MockCgroupFs;

// Utility function to read the first line in a file
fn read_first_line<P>(filename: P) -> std::result::Result<String, std::io::Error>
fn read_first_line<P>(filename: P) -> Result<String, std::io::Error>
where
P: AsRef<Path> + Debug,
{
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/device_manager/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ impl<'a> Persist<'a> for DeviceManager {
fn restore(
constructor_args: Self::ConstructorArgs,
state: &Self::State,
) -> std::result::Result<Self, Self::Error> {
) -> 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
2 changes: 1 addition & 1 deletion src/vmm/src/device_manager/pci_mngr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ impl<'a> Persist<'a> for PciDevices {
fn restore(
constructor_args: Self::ConstructorArgs,
state: &Self::State,
) -> std::result::Result<Self, Self::Error> {
) -> Result<Self, Self::Error> {
let mem = constructor_args.mem;
let mut pci_devices = PciDevices::new();
if !state.pci_enabled {
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/device_manager/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ impl<'a> Persist<'a> for ACPIDeviceManager {
fn restore(
constructor_args: Self::ConstructorArgs,
state: &Self::State,
) -> std::result::Result<Self, Self::Error> {
) -> Result<Self, Self::Error> {
let mut dev_manager = ACPIDeviceManager::new();
if let Some(vmgenid_args) = &state.vmgenid {
let vmgenid = VmGenId::restore(
Expand Down
2 changes: 1 addition & 1 deletion src/vmm/src/devices/acpi/vmgenid.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ impl<'a> Persist<'a> for VmGenId {
fn restore(
constructor_args: Self::ConstructorArgs,
state: &Self::State,
) -> std::result::Result<Self, Self::Error> {
) -> Result<Self, Self::Error> {
Self::from_parts(GuestAddress(state.addr), state.gsi, constructor_args.mem)
}
}
Expand Down
37 changes: 33 additions & 4 deletions src/vmm/src/devices/virtio/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -197,22 +197,23 @@ pub(crate) mod tests {

#[derive(Debug)]
struct MockVirtioDevice {
avail_features: u64,
acked_features: u64,
}

impl VirtioDevice for MockVirtioDevice {
impl_device_type!(0);

fn avail_features(&self) -> u64 {
todo!()
self.avail_features
}

fn acked_features(&self) -> u64 {
self.acked_features
}

fn set_acked_features(&mut self, _acked_features: u64) {
todo!()
fn set_acked_features(&mut self, acked_features: u64) {
self.acked_features = acked_features
}

fn queues(&self) -> &[Queue] {
Expand Down Expand Up @@ -254,7 +255,10 @@ pub(crate) mod tests {

#[test]
fn test_has_feature() {
let mut device = MockVirtioDevice { acked_features: 0 };
let mut device = MockVirtioDevice {
avail_features: 0,
acked_features: 0,
};

let mock_feature_1 = 1u64;
assert!(!device.has_feature(mock_feature_1));
Expand All @@ -267,4 +271,29 @@ pub(crate) mod tests {
assert!(device.has_feature(mock_feature_1));
assert!(device.has_feature(mock_feature_2));
}

#[test]
fn test_features() {
let features: u64 = 0x11223344_55667788;

let mut device = MockVirtioDevice {
avail_features: features,
acked_features: 0,
};

assert_eq!(
device.avail_features_by_page(0),
(features & 0xFFFFFFFF) as u32,
);
assert_eq!(device.avail_features_by_page(1), (features >> 32) as u32);
for i in 2..10 {
assert_eq!(device.avail_features_by_page(i), 0u32);
}

for i in 0..10 {
device.ack_features_by_page(i, u32::MAX);
}

assert_eq!(device.acked_features, features);
}
}
35 changes: 0 additions & 35 deletions src/vmm/src/devices/virtio/net/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1156,41 +1156,6 @@ pub mod tests {
assert_eq!(net.device_type(), VIRTIO_ID_NET);
}

#[test]
fn test_virtio_device_features() {
let mut net = default_net();
set_mac(&mut net, MacAddr::from_str("11:22:33:44:55:66").unwrap());

// Test `features()` and `ack_features()`.
let features = (1 << VIRTIO_NET_F_GUEST_CSUM)
| (1 << VIRTIO_NET_F_CSUM)
| (1 << VIRTIO_NET_F_GUEST_TSO4)
| (1 << VIRTIO_NET_F_GUEST_TSO6)
| (1 << VIRTIO_NET_F_MAC)
| (1 << VIRTIO_NET_F_GUEST_UFO)
| (1 << VIRTIO_NET_F_HOST_TSO4)
| (1 << VIRTIO_NET_F_HOST_TSO6)
| (1 << VIRTIO_NET_F_HOST_UFO)
| (1 << VIRTIO_F_VERSION_1)
| (1 << VIRTIO_NET_F_MRG_RXBUF)
| (1 << VIRTIO_RING_F_EVENT_IDX);

assert_eq!(
net.avail_features_by_page(0),
(features & 0xFFFFFFFF) as u32,
);
assert_eq!(net.avail_features_by_page(1), (features >> 32) as u32);
for i in 2..10 {
assert_eq!(net.avail_features_by_page(i), 0u32);
}

for i in 0..10 {
net.ack_features_by_page(i, u32::MAX);
}

assert_eq!(net.acked_features, features);
}

#[test]
// Test that `Net::build_tap_offload_features` creates the TAP offload features that we expect
// it to do, based on the available guest features
Expand Down
25 changes: 0 additions & 25 deletions src/vmm/src/devices/virtio/rng/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -410,31 +410,6 @@ mod tests {
assert_eq!(read_config, vec![0; 10]);
}

#[test]
fn test_virtio_device_features() {
let mut entropy_dev = default_entropy();

let features = 1 << VIRTIO_F_VERSION_1;

assert_eq!(
entropy_dev.avail_features_by_page(0),
(features & 0xFFFFFFFF) as u32,
);
assert_eq!(
entropy_dev.avail_features_by_page(1),
(features >> 32) as u32
);
for i in 2..10 {
assert_eq!(entropy_dev.avail_features_by_page(i), 0u32);
}

for i in 0..10 {
entropy_dev.ack_features_by_page(i, u32::MAX);
}

assert_eq!(entropy_dev.acked_features, features);
}

#[test]
fn test_handle_one() {
let mem = create_virtio_mem();
Expand Down
16 changes: 7 additions & 9 deletions src/vmm/src/devices/virtio/transport/pci/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ use std::io::{ErrorKind, Write};
use std::sync::atomic::{AtomicBool, AtomicU16, AtomicU32, AtomicUsize, Ordering};
use std::sync::{Arc, Barrier, Mutex};

use anyhow::anyhow;
use kvm_ioctls::{IoEventAddress, NoDatamatch};
use log::warn;
use pci::{
Expand All @@ -39,7 +38,7 @@ use crate::devices::virtio::transport::{VirtioInterrupt, VirtioInterruptType};
use crate::logger::{debug, error};
use crate::pci::configuration::{PciCapability, PciConfiguration, PciConfigurationState};
use crate::pci::msix::{MsixCap, MsixConfig, MsixConfigState};
use crate::pci::{BarReprogrammingParams, PciDevice};
use crate::pci::{BarReprogrammingParams, DeviceRelocationError, PciDevice};
use crate::snapshot::Persist;
use crate::utils::u64_to_usize;
use crate::vstate::bus::BusDevice;
Expand Down Expand Up @@ -251,11 +250,10 @@ pub struct VirtioPciDeviceState {
#[derive(Debug, thiserror::Error, displaydoc::Display)]
pub enum VirtioPciDeviceError {
/// Failed creating VirtioPciDevice: {0}
CreateVirtioPciDevice(#[from] anyhow::Error),
CreateVirtioPciDevice(#[from] DeviceRelocationError),
/// Error creating MSI configuration: {0}
Msi(#[from] InterruptError),
}
pub type Result<T> = std::result::Result<T, VirtioPciDeviceError>;

pub struct VirtioPciDevice {
id: String,
Expand Down Expand Up @@ -370,7 +368,7 @@ impl VirtioPciDevice {
device: Arc<Mutex<dyn VirtioDevice>>,
msix_vectors: Arc<MsixVectorGroup>,
pci_device_bdf: u32,
) -> Result<Self> {
) -> Result<Self, VirtioPciDeviceError> {
let num_queues = device.lock().expect("Poisoned lock").queues().len();

let msix_config = Arc::new(Mutex::new(MsixConfig::new(
Expand Down Expand Up @@ -419,7 +417,7 @@ impl VirtioPciDevice {
vm: &Arc<Vm>,
device: Arc<Mutex<dyn VirtioDevice>>,
state: VirtioPciDeviceState,
) -> Result<Self> {
) -> Result<Self, VirtioPciDeviceError> {
let msix_config =
MsixConfig::from_state(state.msix_state, vm.clone(), state.pci_device_bdf.into())?;
let vectors = msix_config.vectors.clone();
Expand Down Expand Up @@ -603,7 +601,7 @@ impl VirtioPciDevice {
}

/// Register the IoEvent notification for a VirtIO device
pub fn register_notification_ioevent(&self, vm: &Vm) -> std::result::Result<(), errno::Error> {
pub fn register_notification_ioevent(&self, vm: &Vm) -> Result<(), errno::Error> {
let bar_addr = self.config_bar_addr();
for (i, queue_evt) in self
.device
Expand Down Expand Up @@ -676,7 +674,7 @@ impl VirtioInterruptMsix {
}

impl VirtioInterrupt for VirtioInterruptMsix {
fn trigger(&self, int_type: VirtioInterruptType) -> std::result::Result<(), InterruptError> {
fn trigger(&self, int_type: VirtioInterruptType) -> Result<(), InterruptError> {
let vector = match int_type {
VirtioInterruptType::Config => self.config_vector.load(Ordering::Acquire),
VirtioInterruptType::Queue(queue_index) => *self
Expand Down Expand Up @@ -783,7 +781,7 @@ impl PciDevice for VirtioPciDevice {
self.configuration.detect_bar_reprogramming(reg_idx, data)
}

fn move_bar(&mut self, old_base: u64, new_base: u64) -> std::result::Result<(), anyhow::Error> {
fn move_bar(&mut self, old_base: u64, new_base: u64) -> Result<(), DeviceRelocationError> {
// We only update our idea of the bar in order to support free_bars() above.
// The majority of the reallocation is done inside DeviceManager.
if self.bar_address == old_base {
Expand Down
1 change: 0 additions & 1 deletion src/vmm/src/dumbo/pdu/arp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use std::convert::From;
use std::fmt::Debug;
use std::net::Ipv4Addr;
use std::result::Result;

use super::bytes::{InnerBytes, NetworkBytes, NetworkBytesMut};
use super::ethernet::{self, ETHERTYPE_IPV4};
Expand Down
1 change: 0 additions & 1 deletion src/vmm/src/dumbo/pdu/ethernet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
//! 802.1Q tags.

use std::fmt::Debug;
use std::result::Result;

use super::Incomplete;
use super::bytes::{InnerBytes, NetworkBytes, NetworkBytesMut};
Expand Down
1 change: 0 additions & 1 deletion src/vmm/src/dumbo/pdu/ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
use std::convert::From;
use std::fmt::Debug;
use std::net::Ipv4Addr;
use std::result::Result;

use crate::dumbo::pdu::bytes::{InnerBytes, NetworkBytes, NetworkBytesMut};
use crate::dumbo::pdu::{Incomplete, ethernet};
Expand Down
1 change: 0 additions & 1 deletion src/vmm/src/dumbo/pdu/tcp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use std::cmp::min;
use std::fmt::Debug;
use std::net::Ipv4Addr;
use std::num::NonZeroU16;
use std::result::Result;

use bitflags::bitflags;

Expand Down
1 change: 0 additions & 1 deletion src/vmm/src/mmds/ns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use std::convert::From;
use std::net::Ipv4Addr;
use std::num::NonZeroUsize;
use std::result::Result;
use std::str::FromStr;
use std::sync::{Arc, Mutex};

Expand Down
5 changes: 1 addition & 4 deletions src/vmm/src/mmds/persist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,7 @@ impl Persist<'_> for MmdsNetworkStack {
}
}

fn restore(
mmds: Self::ConstructorArgs,
state: &Self::State,
) -> std::result::Result<Self, Self::Error> {
fn restore(mmds: Self::ConstructorArgs, state: &Self::State) -> Result<Self, Self::Error> {
Ok(MmdsNetworkStack::new(
MacAddr::from_bytes_unchecked(&state.mac_addr),
Ipv4Addr::from(state.ipv4_addr),
Expand Down
4 changes: 2 additions & 2 deletions src/vmm/src/pci/bus.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,7 @@ mod tests {
use super::{PciBus, PciConfigIo, PciConfigMmio, PciRoot};
use crate::pci::bus::{DEVICE_ID_INTEL_VIRT_PCIE_HOST, VENDOR_ID_INTEL};
use crate::pci::configuration::PciConfiguration;
use crate::pci::{BarReprogrammingParams, DeviceRelocation, PciDevice};
use crate::pci::{BarReprogrammingParams, DeviceRelocation, DeviceRelocationError, PciDevice};
use crate::vstate::bus::BusDevice;

#[derive(Debug, Default)]
Expand All @@ -479,7 +479,7 @@ mod tests {
_new_base: u64,
_len: u64,
_pci_dev: &mut dyn PciDevice,
) -> Result<(), anyhow::Error> {
) -> Result<(), DeviceRelocationError> {
self.reloc_cnt
.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
Ok(())
Expand Down
Loading