hypervisor: add create_passthrough_device call to Vm trait

That function is going to return a handle for passthrough related
operations.

Move create_kvm_device code there.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu
2020-07-17 15:16:45 +00:00
committed by Samuel Ortiz
parent 7bfe87b7af
commit ff8d7bfe83
3 changed files with 28 additions and 14 deletions

View File

@@ -255,6 +255,17 @@ impl vm::Vm for KvmVm {
fn check_extension(&self, c: Cap) -> bool {
self.fd.check_extension(c)
}
/// Create a device that is used for passthrough
fn create_passthrough_device(&self) -> vm::Result<DeviceFd> {
let mut vfio_dev = kvm_create_device {
type_: kvm_device_type_KVM_DEV_TYPE_VFIO,
fd: 0,
flags: 0,
};
self.create_device(&mut vfio_dev)
.map_err(|e| vm::HypervisorVmError::CreatePassthroughDevice(e.into()))
}
}
/// Wrapper over KVM system ioctls.
pub struct KvmHypervisor {