dragonball: update for review

update for review

Fixes: #3785
Signed-off-by: Quanwei Zhou <quanweiZhou@linux.alibaba.com>
This commit is contained in:
Quanwei Zhou 2022-07-11 07:57:40 +08:00 committed by quanwei.zqw
parent 274598ae56
commit 3c989521b1
7 changed files with 29 additions and 32 deletions

View File

@ -5,7 +5,7 @@
use serde_derive::{Deserialize, Serialize};
/// Default guest kernel command line:
/// - `reboot=k` shut down the guest on reboot, instead of well... rebooting;
/// - `reboot=k` shutdown the guest on reboot, instead of well... rebooting;
/// - `panic=1` on panic, reboot after 1 second;
/// - `pci=off` do not scan for PCI devices (ser boot time);
/// - `nomodules` disable loadable kernel module support;

View File

@ -332,7 +332,7 @@ impl VmmService {
Ok(VmmData::Empty)
}
/// Set virtual machine configuration configurations.
/// Set virtual machine configuration.
pub fn set_vm_configuration(
&mut self,
vmm: &mut Vmm,
@ -498,8 +498,7 @@ impl VmmService {
}
#[cfg(feature = "virtio-blk")]
// Only call this function as part of the API.
// If the drive_id does not exist, a new Block Device Config is added to the list.
// Remove the device
fn remove_block_device(
&mut self,
vmm: &mut Vmm,

View File

@ -372,8 +372,7 @@ impl BlockDeviceMgr {
for info in mgr.info_list.iter() {
info.config.check_conflicts(&config)?;
}
let config2 = config.clone();
let index = mgr.create(config2)?;
let index = mgr.create(config.clone())?;
if !ctx.is_hotplug {
return Ok(());
}
@ -497,8 +496,6 @@ impl BlockDeviceMgr {
) -> std::result::Result<Box<Block<GuestAddressSpaceImpl>>, virtio::Error> {
let epoll_mgr = ctx.epoll_mgr.clone().ok_or(virtio::Error::InvalidInput)?;
// Safe to unwrap() because we have verified it when parsing device type.
//let path = cfg.path_on_host.to_str().unwrap();
let mut block_files: Vec<Box<dyn Ufile>> = vec![];
match cfg.device_type {
@ -762,7 +759,7 @@ impl BlockDeviceMgr {
}
impl Default for BlockDeviceMgr {
/// Constructor for the BlockDeviceConfigs. It initializes an empty LinkedList.
/// Constructor for the BlockDeviceMgr. It initializes an empty LinkedList.
fn default() -> BlockDeviceMgr {
BlockDeviceMgr {
info_list: VecDeque::<BlockDeviceInfo>::new(),

View File

@ -12,9 +12,9 @@ use std::io;
use std::sync::{Arc, Mutex};
use dbs_device::device_manager::Error as IoManagerError;
use dbs_legacy_devices::SerialDevice;
#[cfg(target_arch = "aarch64")]
use dbs_legacy_devices::RTCDevice;
use dbs_legacy_devices::SerialDevice;
use vmm_sys_util::eventfd::EventFd;
// The I8042 Data Port (IO Port 0x60) is used for reading data that was received from a I8042 device or from the I8042 controller itself and writing data to a I8042 device or to the I8042 controller itself.
@ -149,10 +149,10 @@ pub(crate) mod x86_64 {
#[cfg(target_arch = "aarch64")]
pub(crate) mod aarch64 {
use super::*;
use dbs_device::device_manager::{IoManager};
use dbs_device::device_manager::IoManager;
use dbs_device::resources::DeviceResources;
use std::collections::HashMap;
use kvm_ioctls::VmFd;
use std::collections::HashMap;
type Result<T> = ::std::result::Result<T, Error>;
@ -194,7 +194,7 @@ pub(crate) mod aarch64 {
) -> Result<(Arc<Mutex<SerialDevice>>, EventFd)> {
let eventfd = EventFd::new(libc::EFD_NONBLOCK).map_err(Error::EventFd)?;
let device = Arc::new(Mutex::new(SerialDevice::new(
eventfd.try_clone().map_err(Error::EventFd)?
eventfd.try_clone().map_err(Error::EventFd)?,
)));
bus.register_device_io(device.clone(), resources.get_all_resources())

View File

@ -3,18 +3,20 @@
//! Device manager to manage IO devices for a virtual machine.
#[cfg(target_arch = "aarch64")]
use std::collections::HashMap;
use std::io;
use std::sync::{Arc, Mutex, MutexGuard};
use std::collections::HashMap;
use arc_swap::ArcSwap;
use dbs_address_space::AddressSpace;
#[cfg(target_arch = "aarch64")]
use dbs_arch::{DeviceType, MMIODeviceInfo};
use dbs_device::device_manager::{Error as IoManagerError, IoManager, IoManagerContext};
use dbs_device::resources::Resource;
#[cfg(target_arch = "aarch64")]
use dbs_device::resources::DeviceResources;
use dbs_device::resources::Resource;
use dbs_device::DeviceIo;
use dbs_interrupt::KvmIrqManager;
use dbs_legacy_devices::ConsoleHandler;
@ -54,7 +56,10 @@ pub mod console_manager;
pub use self::console_manager::ConsoleManager;
mod legacy;
pub use self::legacy::{Error as LegacyDeviceError, LegacyDeviceManager, aarch64::{COM1, COM2, RTC}};
pub use self::legacy::{Error as LegacyDeviceError, LegacyDeviceManager};
#[cfg(target_arch = "aarch64")]
pub use self::legacy::aarch64::{COM1, COM2, RTC};
#[cfg(feature = "virtio-vsock")]
/// Device manager for user-space vsock devices.
@ -333,9 +338,7 @@ impl DeviceOpContext {
let (mmio_base, mmio_size, irq) = DeviceManager::get_virtio_mmio_device_info(device)?;
let dev_type;
let device_id;
if let Some(mmiov2_device) =
device.as_any().downcast_ref::<DbsMmioV2Device>()
{
if let Some(mmiov2_device) = device.as_any().downcast_ref::<DbsMmioV2Device>() {
dev_type = mmiov2_device.get_device_type();
device_id = None;
} else {
@ -534,19 +537,20 @@ impl DeviceManager {
&mut self,
ctx: &mut DeviceOpContext,
) -> std::result::Result<(), StartMicroVmError> {
#[cfg(
any(target_arch = "x86_64",
all(target_arch = "aarch64", feature = "dbs-virtio-devices")
)
)]
#[cfg(any(
target_arch = "x86_64",
all(target_arch = "aarch64", feature = "dbs-virtio-devices")
))]
{
let mut tx = ctx.io_context.begin_tx();
let legacy_manager;
#[cfg(target_arch = "x86_64")]
{
let legacy_manager =
LegacyDeviceManager::create_manager(&mut tx.io_manager, Some(self.vm_fd.clone()));
legacy_manager = LegacyDeviceManager::create_manager(
&mut tx.io_manager,
Some(self.vm_fd.clone()),
);
}
#[cfg(target_arch = "aarch64")]
@ -817,10 +821,7 @@ impl DeviceManager {
.get_legacy_irq()
.ok_or(DeviceMgrError::GetDeviceResource)?;
if let Some(mmio_dev) = device
.as_any()
.downcast_ref::<DbsMmioV2Device>()
{
if let Some(mmio_dev) = device.as_any().downcast_ref::<DbsMmioV2Device>() {
if let Resource::MmioAddressRange { base, size } = mmio_dev.get_mmio_cfg_res() {
return Ok((base, size, irq));
}

View File

@ -12,7 +12,7 @@
#[cfg(feature = "dbs-virtio-devices")]
use dbs_virtio_devices::Error as VirtIoError;
use crate::{address_space_manager, device_manager, vcpu, vm, resource_manager};
use crate::{address_space_manager, device_manager, resource_manager, vcpu, vm};
/// Shorthand result type for internal VMM commands.
pub type Result<T> = std::result::Result<T, Error>;

View File

@ -64,7 +64,7 @@ impl TryFrom<AddressMessage> for Address {
}
}
pub(crate) fn parse_ip(ip: &Vec<u8>, family: u8) -> Result<IpAddr> {
pub(crate) fn parse_ip(ip: &[u8], family: u8) -> Result<IpAddr> {
let support_len = if family as u16 == AF_INET { 4 } else { 16 };
if ip.len() != support_len {
return Err(anyhow!(