arch, pci, vmm: Initial switch to the hypervisor crate

Start moving the vmm, arch and pci crates to being hypervisor agnostic
by using the hypervisor trait and abstractions. This is not a complete
switch and there are still some remaining KVM dependencies.

Signed-off-by: Muminul Islam <muislam@microsoft.com>
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Muminul Islam
2020-06-01 19:29:54 -07:00
committed by Samuel Ortiz
parent c48d0c1a67
commit e4dee57e81
24 changed files with 294 additions and 1023 deletions
+20 -3
View File
@@ -5,6 +5,7 @@
extern crate anyhow;
extern crate arc_swap;
extern crate hypervisor;
#[macro_use]
extern crate lazy_static;
#[macro_use]
@@ -213,6 +214,7 @@ pub fn start_vmm_thread(
api_sender: Sender<ApiRequest>,
api_receiver: Receiver<ApiRequest>,
seccomp_level: &SeccompLevel,
hypervisor: Arc<dyn hypervisor::Hypervisor>,
) -> Result<thread::JoinHandle<Result<()>>> {
let http_api_event = api_event.try_clone().map_err(Error::EventFdClone)?;
@@ -232,7 +234,7 @@ pub fn start_vmm_thread(
// Apply seccomp filter for VMM thread.
SeccompFilter::apply(vmm_seccomp_filter).map_err(Error::ApplySeccompFilter)?;
let mut vmm = Vmm::new(vmm_version.to_string(), api_event, vmm_path)?;
let mut vmm = Vmm::new(vmm_version.to_string(), api_event, vmm_path, hypervisor)?;
vmm.control_loop(Arc::new(api_receiver))
})
@@ -253,10 +255,16 @@ pub struct Vmm {
vm: Option<Vm>,
vm_config: Option<Arc<Mutex<VmConfig>>>,
vmm_path: PathBuf,
hypervisor: Arc<dyn hypervisor::Hypervisor>,
}
impl Vmm {
fn new(vmm_version: String, api_evt: EventFd, vmm_path: PathBuf) -> Result<Self> {
fn new(
vmm_version: String,
api_evt: EventFd,
vmm_path: PathBuf,
hypervisor: Arc<dyn hypervisor::Hypervisor>,
) -> Result<Self> {
let mut epoll = EpollContext::new().map_err(Error::Epoll)?;
let exit_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::EventFdCreate)?;
let reset_evt = EventFd::new(EFD_NONBLOCK).map_err(Error::EventFdCreate)?;
@@ -286,6 +294,7 @@ impl Vmm {
vm: None,
vm_config: None,
vmm_path,
hypervisor,
})
}
@@ -301,6 +310,7 @@ impl Vmm {
exit_evt,
reset_evt,
self.vmm_path.clone(),
self.hypervisor.clone(),
)?;
self.vm = Some(vm);
}
@@ -370,6 +380,7 @@ impl Vmm {
self.vmm_path.clone(),
source_url,
restore_cfg.prefault,
self.hypervisor.clone(),
)?;
self.vm = Some(vm);
@@ -413,7 +424,13 @@ impl Vmm {
if self.reset_evt.read().is_ok() {
warn!("Spurious second reset event received. Ignoring.");
}
self.vm = Some(Vm::new(config, exit_evt, reset_evt, self.vmm_path.clone())?);
self.vm = Some(Vm::new(
config,
exit_evt,
reset_evt,
self.vmm_path.clone(),
self.hypervisor.clone(),
)?);
}
// Then we start the new VM.