vmm: Support direct device assignment

With the VFIO crate, we can now support directly assigned PCI devices
into cloud-hypervisor guests.

We support assigning multiple host devices, through the --device command
line parameter. This parameter takes the host device sysfs path.

Fixes: #60

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz
2019-07-15 11:42:40 +02:00
parent b746dd7116
commit 4d16ca8ae7
5 changed files with 120 additions and 0 deletions

View File

@@ -69,6 +69,7 @@ pub struct VmParams<'a> {
pub pmem: Option<Vec<&'a str>>,
pub serial: &'a str,
pub console: &'a str,
pub devices: Option<Vec<&'a str>>,
}
fn parse_size(size: &str) -> Result<u64> {
@@ -379,6 +380,19 @@ impl<'a> ConsoleConfig<'a> {
}
}
#[derive(Debug)]
pub struct DeviceConfig<'a> {
pub path: &'a Path,
}
impl<'a> DeviceConfig<'a> {
pub fn parse(device: &'a str) -> Result<Self> {
Ok(DeviceConfig {
path: Path::new(device),
})
}
}
pub struct VmConfig<'a> {
pub cpus: CpusConfig,
pub memory: MemoryConfig<'a>,
@@ -391,6 +405,7 @@ pub struct VmConfig<'a> {
pub pmem: Option<Vec<PmemConfig<'a>>>,
pub serial: ConsoleConfig<'a>,
pub console: ConsoleConfig<'a>,
pub devices: Option<Vec<DeviceConfig<'a>>>,
}
impl<'a> VmConfig<'a> {
@@ -437,6 +452,15 @@ impl<'a> VmConfig<'a> {
return Err(Error::ParseTTYParam);
}
let mut devices: Option<Vec<DeviceConfig>> = None;
if let Some(device_list) = &vm_params.devices {
let mut device_config_list = Vec::new();
for item in device_list.iter() {
device_config_list.push(DeviceConfig::parse(item)?);
}
devices = Some(device_config_list);
}
Ok(VmConfig {
cpus: CpusConfig::parse(vm_params.cpus)?,
memory: MemoryConfig::parse(vm_params.memory)?,
@@ -449,6 +473,7 @@ impl<'a> VmConfig<'a> {
pmem,
serial,
console,
devices,
})
}
}