diff --git a/src/dragonball/src/address_space_manager.rs b/src/dragonball/src/address_space_manager.rs index bcc1083a9d..6e4144618c 100644 --- a/src/dragonball/src/address_space_manager.rs +++ b/src/dragonball/src/address_space_manager.rs @@ -35,8 +35,8 @@ use nix::unistd::dup; #[cfg(feature = "atomic-guest-memory")] use vm_memory::GuestMemoryAtomic; use vm_memory::{ - address::Address, FileOffset, GuestAddress, GuestAddressSpace, GuestMemoryMmap, GuestMemoryRegion, - GuestRegionMmap, GuestUsize, MemoryRegionAddress, MmapRegion, + address::Address, FileOffset, GuestAddress, GuestAddressSpace, GuestMemoryMmap, + GuestMemoryRegion, GuestRegionMmap, GuestUsize, MemoryRegionAddress, MmapRegion, }; use crate::resource_manager::ResourceManager; @@ -270,7 +270,7 @@ impl AddressSpaceMgr { let size = info .size .checked_shl(20) - .ok_or_else(|| AddressManagerError::InvalidOperation)?; + .ok_or(AddressManagerError::InvalidOperation)?; // Guest memory does not intersect with the MMIO hole. // TODO: make it work for ARM (issue #4307) @@ -281,13 +281,13 @@ impl AddressSpaceMgr { regions.push(region); start_addr = start_addr .checked_add(size) - .ok_or_else(|| AddressManagerError::InvalidOperation)?; + .ok_or(AddressManagerError::InvalidOperation)?; } else { // Add guest memory below the MMIO hole, avoid splitting the memory region // if the available address region is small than MINIMAL_SPLIT_SPACE MiB. let mut below_size = dbs_boot::layout::MMIO_LOW_START .checked_sub(start_addr) - .ok_or_else(|| AddressManagerError::InvalidOperation)?; + .ok_or(AddressManagerError::InvalidOperation)?; if below_size < (MINIMAL_SPLIT_SPACE) { below_size = 0; } else { @@ -299,12 +299,12 @@ impl AddressSpaceMgr { let above_start = dbs_boot::layout::MMIO_LOW_END + 1; let above_size = size .checked_sub(below_size) - .ok_or_else(|| AddressManagerError::InvalidOperation)?; + .ok_or(AddressManagerError::InvalidOperation)?; let region = self.create_region(above_start, above_size, info, &mut param)?; regions.push(region); start_addr = above_start .checked_add(above_size) - .ok_or_else(|| AddressManagerError::InvalidOperation)?; + .ok_or(AddressManagerError::InvalidOperation)?; } } @@ -502,7 +502,7 @@ impl AddressSpaceMgr { fn configure_numa(&self, mmap_reg: &MmapRegion, node_id: u32) -> Result<()> { let nodemask = 1_u64 .checked_shl(node_id) - .ok_or_else(|| AddressManagerError::InvalidOperation)?; + .ok_or(AddressManagerError::InvalidOperation)?; let res = unsafe { libc::syscall( libc::SYS_mbind, diff --git a/src/dragonball/src/api/v1/boot_source.rs b/src/dragonball/src/api/v1/boot_source.rs index 8ff7e030dc..612de04a18 100644 --- a/src/dragonball/src/api/v1/boot_source.rs +++ b/src/dragonball/src/api/v1/boot_source.rs @@ -18,7 +18,7 @@ pub const DEFAULT_KERNEL_CMDLINE: &str = "reboot=k panic=1 pci=off nomodules 825 i8042.noaux i8042.nomux i8042.nopnp i8042.dumbkbd"; /// Strongly typed data structure used to configure the boot source of the microvm. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)] +#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, Default)] #[serde(deny_unknown_fields)] pub struct BootSourceConfig { /// Path of the kernel image. diff --git a/src/dragonball/src/api/v1/instance_info.rs b/src/dragonball/src/api/v1/instance_info.rs index ae159aa614..86174a2fd7 100644 --- a/src/dragonball/src/api/v1/instance_info.rs +++ b/src/dragonball/src/api/v1/instance_info.rs @@ -10,7 +10,7 @@ use serde_derive::{Deserialize, Serialize}; /// When Dragonball starts, the instance state is Uninitialized. Once start_microvm method is /// called, the state goes from Uninitialized to Starting. The state is changed to Running until /// the start_microvm method ends. Halting and Halted are currently unsupported. -#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Serialize)] +#[derive(Copy, Clone, Debug, Deserialize, PartialEq, Eq, Serialize)] pub enum InstanceState { /// Microvm is not initialized. Uninitialized, @@ -29,7 +29,7 @@ pub enum InstanceState { } /// The state of async actions -#[derive(Debug, Deserialize, Serialize, Clone, PartialEq)] +#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)] pub enum AsyncState { /// Uninitialized Uninitialized, diff --git a/src/dragonball/src/api/v1/machine_config.rs b/src/dragonball/src/api/v1/machine_config.rs index e4ae228679..7d78f3e443 100644 --- a/src/dragonball/src/api/v1/machine_config.rs +++ b/src/dragonball/src/api/v1/machine_config.rs @@ -10,7 +10,7 @@ pub const MAX_SUPPORTED_VCPUS: u8 = 254; pub const MEMORY_HOTPLUG_ALIGHMENT: u8 = 64; /// Errors associated with configuring the microVM. -#[derive(Debug, PartialEq, thiserror::Error)] +#[derive(Debug, PartialEq, Eq, thiserror::Error)] pub enum VmConfigError { /// Cannot update the configuration of the microvm post boot. #[error("update operation is not allowed after boot")] diff --git a/src/dragonball/src/api/v1/vmm_action.rs b/src/dragonball/src/api/v1/vmm_action.rs index 96ca6d1508..ac1742e953 100644 --- a/src/dragonball/src/api/v1/vmm_action.rs +++ b/src/dragonball/src/api/v1/vmm_action.rs @@ -89,7 +89,7 @@ pub enum VmmActionError { /// This enum represents the public interface of the VMM. Each action contains various /// bits of information (ids, paths, etc.). -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub enum VmmAction { /// Configure the boot source of the microVM using `BootSourceConfig`. /// This action can only be called before the microVM has booted. @@ -298,7 +298,6 @@ impl VmmService { let mut cmdline = linux_loader::cmdline::Cmdline::new(dbs_boot::layout::CMDLINE_MAX_SIZE); let boot_args = boot_source_config .boot_args - .clone() .unwrap_or_else(|| String::from(DEFAULT_KERNEL_CMDLINE)); cmdline .insert_str(boot_args) @@ -681,7 +680,7 @@ mod tests { let response = from_vmm.try_recv(); assert!(response.is_ok()); - (&self.f)(*response.unwrap()); + (self.f)(*response.unwrap()); } } diff --git a/src/dragonball/src/config_manager.rs b/src/dragonball/src/config_manager.rs index fbb66611c3..34a2af2e0f 100644 --- a/src/dragonball/src/config_manager.rs +++ b/src/dragonball/src/config_manager.rs @@ -46,7 +46,7 @@ pub trait ConfigItem { } /// Struct to manage a group of configuration items. -#[derive(Debug, Default, Deserialize, PartialEq, Serialize)] +#[derive(Debug, Default, Deserialize, PartialEq, Eq, Serialize)] pub struct ConfigInfos where T: ConfigItem + Clone, @@ -316,7 +316,7 @@ where } /// Configuration information for RateLimiter token bucket. -#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, PartialEq, Eq, Serialize)] pub struct TokenBucketConfigInfo { /// The size for the token bucket. A TokenBucket of `size` total capacity will take `refill_time` /// milliseconds to go from zero tokens to total capacity. @@ -349,7 +349,7 @@ impl From<&TokenBucketConfigInfo> for TokenBucket { } /// Configuration information for RateLimiter objects. -#[derive(Clone, Debug, Default, Deserialize, PartialEq, Serialize)] +#[derive(Clone, Debug, Default, Deserialize, PartialEq, Eq, Serialize)] pub struct RateLimiterConfigInfo { /// Data used to initialize the RateLimiter::bandwidth bucket. pub bandwidth: TokenBucketConfigInfo, diff --git a/src/dragonball/src/device_manager/blk_dev_mgr.rs b/src/dragonball/src/device_manager/blk_dev_mgr.rs index 4f0fa1e4b0..a34b951653 100644 --- a/src/dragonball/src/device_manager/blk_dev_mgr.rs +++ b/src/dragonball/src/device_manager/blk_dev_mgr.rs @@ -106,7 +106,7 @@ pub enum BlockDeviceError { } /// Type of low level storage device/protocol for virtio-blk devices. -#[derive(Clone, Copy, Debug, PartialEq, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] pub enum BlockDeviceType { /// Unknown low level device type. Unknown, @@ -131,7 +131,7 @@ impl BlockDeviceType { } /// Configuration information for a block device. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)] pub struct BlockDeviceConfigUpdateInfo { /// Unique identifier of the drive. pub drive_id: String, @@ -151,7 +151,7 @@ impl BlockDeviceConfigUpdateInfo { } /// Configuration information for a block device. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)] pub struct BlockDeviceConfigInfo { /// Unique identifier of the drive. pub drive_id: String, @@ -625,7 +625,7 @@ impl BlockDeviceMgr { // we need to satisfy the condition by which a VMM can only have on root device if block_device_config.is_root_device { if self.has_root_block { - return Err(BlockDeviceError::RootBlockDeviceAlreadyAdded); + Err(BlockDeviceError::RootBlockDeviceAlreadyAdded) } else { self.has_root_block = true; self.read_only_root = block_device_config.is_read_only; diff --git a/src/dragonball/src/device_manager/fs_dev_mgr.rs b/src/dragonball/src/device_manager/fs_dev_mgr.rs index 76b1d2d93d..dca0e649e3 100644 --- a/src/dragonball/src/device_manager/fs_dev_mgr.rs +++ b/src/dragonball/src/device_manager/fs_dev_mgr.rs @@ -89,7 +89,7 @@ pub enum FsDeviceError { } /// Configuration information for a vhost-user-fs device. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)] pub struct FsDeviceConfigInfo { /// vhost-user socket path. pub sock_path: String, @@ -201,7 +201,7 @@ impl FsDeviceConfigInfo { } /// Configuration information for virtio-fs. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)] pub struct FsDeviceConfigUpdateInfo { /// virtiofs mount tag name used inside the guest. /// used as the device name during mount. @@ -242,7 +242,7 @@ impl ConfigItem for FsDeviceConfigInfo { } /// Configuration information of manipulating backend fs for a virtiofs device. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)] +#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, Default)] pub struct FsMountConfigInfo { /// Mount operations, mount, update, umount pub ops: String, diff --git a/src/dragonball/src/device_manager/mod.rs b/src/dragonball/src/device_manager/mod.rs index 8e1b3456fc..75eaef6ac3 100644 --- a/src/dragonball/src/device_manager/mod.rs +++ b/src/dragonball/src/device_manager/mod.rs @@ -147,7 +147,11 @@ pub type Result = ::std::result::Result; /// Type of the dragonball virtio devices. #[cfg(feature = "dbs-virtio-devices")] pub type DbsVirtioDevice = Box< - dyn VirtioDevice, + dyn VirtioDevice< + GuestAddressSpaceImpl, + virtio_queue::QueueStateSync, + vm_memory::GuestRegionMmap, + >, >; /// Type of the dragonball virtio mmio devices. @@ -997,7 +1001,7 @@ impl DeviceManager { { self.vsock_manager .get_default_connector() - .map(|d| Some(d)) + .map(Some) .unwrap_or(None) } #[cfg(not(feature = "virtio-vsock"))] diff --git a/src/dragonball/src/device_manager/virtio_net_dev_mgr.rs b/src/dragonball/src/device_manager/virtio_net_dev_mgr.rs index 3283a00d91..c0b0f62daa 100644 --- a/src/dragonball/src/device_manager/virtio_net_dev_mgr.rs +++ b/src/dragonball/src/device_manager/virtio_net_dev_mgr.rs @@ -93,7 +93,7 @@ pub enum VirtioNetDeviceError { } /// Configuration information for virtio net devices. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)] pub struct VirtioNetDeviceConfigUpdateInfo { /// ID of the guest network interface. pub iface_id: String, @@ -123,7 +123,7 @@ impl VirtioNetDeviceConfigUpdateInfo { } /// Configuration information for virtio net devices. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize, Default)] +#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize, Default)] pub struct VirtioNetDeviceConfigInfo { /// ID of the guest network interface. pub iface_id: String, @@ -264,7 +264,7 @@ impl VirtioNetDeviceMgr { config.use_generic_irq.unwrap_or(USE_GENERIC_IRQ), ) .map_err(VirtioNetDeviceError::DeviceManager)?; - ctx.insert_hotplug_mmio_device(&dev.clone(), None) + ctx.insert_hotplug_mmio_device(&dev, None) .map_err(VirtioNetDeviceError::DeviceManager)?; // live-upgrade need save/restore device from info.device. mgr.info_list[device_index].set_device(dev); diff --git a/src/dragonball/src/device_manager/vsock_dev_mgr.rs b/src/dragonball/src/device_manager/vsock_dev_mgr.rs index 4f0f074134..8588471b71 100644 --- a/src/dragonball/src/device_manager/vsock_dev_mgr.rs +++ b/src/dragonball/src/device_manager/vsock_dev_mgr.rs @@ -70,7 +70,7 @@ pub enum VsockDeviceError { } /// Configuration information for a vsock device. -#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)] +#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)] pub struct VsockDeviceConfigInfo { /// ID of the vsock device. pub id: String, diff --git a/src/dragonball/src/resource_manager.rs b/src/dragonball/src/resource_manager.rs index 2cb32c0546..4565344826 100644 --- a/src/dragonball/src/resource_manager.rs +++ b/src/dragonball/src/resource_manager.rs @@ -36,7 +36,7 @@ const PIO_MAX: u16 = 0xFFFF; const MMIO_SPACE_RESERVED: u64 = 0x400_0000; /// Errors associated with resource management operations -#[derive(Debug, PartialEq, thiserror::Error)] +#[derive(Debug, PartialEq, Eq, thiserror::Error)] pub enum ResourceError { /// Unknown/unsupported resource type. #[error("unsupported resource type")] @@ -569,9 +569,7 @@ impl ResourceManager { Resource::KvmMemSlot(slot) => self.free_kvm_mem_slot(*slot), Resource::MacAddresss(_) => Ok(()), }; - if result.is_err() { - return result; - } + result?; } Ok(()) } @@ -588,9 +586,9 @@ mod tests { // Allocate/free shared IRQs multiple times. assert_eq!(mgr.allocate_legacy_irq(true, None).unwrap(), SHARED_IRQ); assert_eq!(mgr.allocate_legacy_irq(true, None).unwrap(), SHARED_IRQ); - mgr.free_legacy_irq(SHARED_IRQ); - mgr.free_legacy_irq(SHARED_IRQ); - mgr.free_legacy_irq(SHARED_IRQ); + mgr.free_legacy_irq(SHARED_IRQ).unwrap(); + mgr.free_legacy_irq(SHARED_IRQ).unwrap(); + mgr.free_legacy_irq(SHARED_IRQ).unwrap(); // Allocate specified IRQs. assert_eq!( @@ -598,7 +596,7 @@ mod tests { .unwrap(), LEGACY_IRQ_BASE + 10 ); - mgr.free_legacy_irq(LEGACY_IRQ_BASE + 10); + mgr.free_legacy_irq(LEGACY_IRQ_BASE + 10).unwrap(); assert_eq!( mgr.allocate_legacy_irq(false, Some(LEGACY_IRQ_BASE + 10)) .unwrap(), @@ -635,19 +633,19 @@ mod tests { let mgr = ResourceManager::new(None); let msi = mgr.allocate_msi_irq(3).unwrap(); - mgr.free_msi_irq(msi, 3); + mgr.free_msi_irq(msi, 3).unwrap(); let msi = mgr.allocate_msi_irq(3).unwrap(); - mgr.free_msi_irq(msi, 3); + mgr.free_msi_irq(msi, 3).unwrap(); let irq = mgr.allocate_msi_irq_aligned(8).unwrap(); assert_eq!(irq & 0x7, 0); - mgr.free_msi_irq(msi, 8); + mgr.free_msi_irq(msi, 8).unwrap(); let irq = mgr.allocate_msi_irq_aligned(8).unwrap(); assert_eq!(irq & 0x7, 0); let irq = mgr.allocate_msi_irq_aligned(512).unwrap(); assert_eq!(irq, 512); - mgr.free_msi_irq(irq, 512); + mgr.free_msi_irq(irq, 512).unwrap(); let irq = mgr.allocate_msi_irq_aligned(512).unwrap(); assert_eq!(irq, 512); @@ -690,9 +688,9 @@ mod tests { }, ]; let resources = mgr.allocate_device_resources(&requests, false).unwrap(); - mgr.free_device_resources(&resources); + mgr.free_device_resources(&resources).unwrap(); let resources = mgr.allocate_device_resources(&requests, false).unwrap(); - mgr.free_device_resources(&resources); + mgr.free_device_resources(&resources).unwrap(); requests.push(ResourceConstraint::PioAddress { range: Some((0xc000, 0xc000)), align: 0x1000, @@ -702,7 +700,7 @@ mod tests { let resources = mgr .allocate_device_resources(&requests[0..requests.len() - 1], false) .unwrap(); - mgr.free_device_resources(&resources); + mgr.free_device_resources(&resources).unwrap(); } #[test] @@ -721,7 +719,7 @@ mod tests { let mgr = ResourceManager::new(None); assert_eq!(mgr.allocate_kvm_mem_slot(1, None).unwrap(), 0); assert_eq!(mgr.allocate_kvm_mem_slot(1, Some(200)).unwrap(), 200); - mgr.free_kvm_mem_slot(200); + mgr.free_kvm_mem_slot(200).unwrap(); assert_eq!(mgr.allocate_kvm_mem_slot(1, Some(200)).unwrap(), 200); assert_eq!( mgr.allocate_kvm_mem_slot(1, Some(KVM_USER_MEM_SLOTS)) diff --git a/src/dragonball/src/vcpu/vcpu_impl.rs b/src/dragonball/src/vcpu/vcpu_impl.rs index ae5d404d1a..85f2888ced 100644 --- a/src/dragonball/src/vcpu/vcpu_impl.rs +++ b/src/dragonball/src/vcpu/vcpu_impl.rs @@ -533,16 +533,11 @@ impl Vcpu { fn check_io_port_info(&self, addr: u16, data: &[u8]) -> Result { let mut checked = false; - match addr { - // debug info signal - MAGIC_IOPORT_DEBUG_INFO => { - if data.len() == 4 { - let data = unsafe { std::ptr::read(data.as_ptr() as *const u32) }; - log::warn!("KDBG: guest kernel debug info: 0x{:x}", data); - checked = true; - } - } - _ => {} + // debug info signal + if addr == MAGIC_IOPORT_DEBUG_INFO && data.len() == 4 { + let data = unsafe { std::ptr::read(data.as_ptr() as *const u32) }; + log::warn!("KDBG: guest kernel debug info: 0x{:x}", data); + checked = true; }; Ok(checked) diff --git a/src/dragonball/src/vm/mod.rs b/src/dragonball/src/vm/mod.rs index 1d78ac31cb..39f5483e9c 100644 --- a/src/dragonball/src/vm/mod.rs +++ b/src/dragonball/src/vm/mod.rs @@ -67,7 +67,7 @@ pub enum VmError { } /// Configuration information for user defined NUMA nodes. -#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)] pub struct NumaRegionInfo { /// memory size for this region (unit: MiB) pub size: u64, @@ -80,7 +80,7 @@ pub struct NumaRegionInfo { } /// Information for cpu topology to guide guest init -#[derive(Clone, Debug, Serialize, Deserialize, PartialEq)] +#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] pub struct CpuTopology { /// threads per core to indicate hyperthreading is enabled or not pub threads_per_core: u8, @@ -104,7 +104,7 @@ impl Default for CpuTopology { } /// Configuration information for virtual machine instance. -#[derive(Clone, Debug, PartialEq)] +#[derive(Clone, Debug, PartialEq, Eq)] pub struct VmConfigInfo { /// Number of vcpu to start. pub vcpu_count: u8,