vmm: Create virtio-vsock device

Based on previous patch introducing the new flag "--vsock", this commit
creates a new virtio-vsock device based on the presence of this flag.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf 2019-09-04 11:14:54 -07:00
parent 11e7ece9f5
commit 4ccc81fdf9

View File

@ -73,6 +73,9 @@ pub enum DeviceManagerError {
/// Cannot create virtio-pmem device
CreateVirtioPmem(io::Error),
/// Cannot create virtio-vsock device
CreateVirtioVsock(io::Error),
/// Failed parsing disk image format
DetectImageType(qcow::Error),
@ -460,6 +463,9 @@ impl DeviceManager {
&interrupt_info,
)?;
// Add virtio-vsock if required
DeviceManager::add_virtio_vsock_devices(vm_info, allocator, pci, buses, &interrupt_info)?;
Ok(())
}
@ -785,6 +791,34 @@ impl DeviceManager {
Ok(())
}
fn add_virtio_vsock_devices(
vm_info: &VmInfo,
allocator: &mut SystemAllocator,
pci: &mut PciConfigIo,
buses: &mut BusInfo,
interrupt_info: &InterruptInfo,
) -> DeviceManagerResult<()> {
// Add vsock if required
if let Some(vsock_list_cfg) = &vm_info.vm_cfg.vsock {
for vsock_cfg in vsock_list_cfg.iter() {
let vsock_device = vm_virtio::Vsock::new(vsock_cfg.cid)
.map_err(DeviceManagerError::CreateVirtioVsock)?;
DeviceManager::add_virtio_pci_device(
Box::new(vsock_device),
vm_info.memory,
allocator,
vm_info.vm_fd,
pci,
buses,
&interrupt_info,
)?;
}
}
Ok(())
}
fn create_kvm_device(vm: &Arc<VmFd>) -> DeviceManagerResult<DeviceFd> {
let mut vfio_dev = kvm_bindings::kvm_create_device {
type_: kvm_bindings::kvm_device_type_KVM_DEV_TYPE_VFIO,