mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-22 11:22:26 +00:00
hypervisor: Support creating a VM of a specified KVM type
This is necessary to support creating a TD VM. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
57ce0986f7
commit
1c54fc3ab7
@ -15,7 +15,6 @@ use crate::x86_64::MsrList;
|
|||||||
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
|
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
|
||||||
use kvm_ioctls::Cap;
|
use kvm_ioctls::Cap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use thiserror::Error;
|
use thiserror::Error;
|
||||||
|
|
||||||
#[derive(Error, Debug)]
|
#[derive(Error, Debug)]
|
||||||
@ -87,6 +86,12 @@ pub trait Hypervisor: Send + Sync {
|
|||||||
fn create_vm(&self) -> Result<Arc<dyn Vm>>;
|
fn create_vm(&self) -> Result<Arc<dyn Vm>>;
|
||||||
#[cfg(feature = "kvm")]
|
#[cfg(feature = "kvm")]
|
||||||
///
|
///
|
||||||
|
/// Create a Vm of a specific type using the underlying hypervisor
|
||||||
|
/// Return a hypervisor-agnostic Vm trait object
|
||||||
|
///
|
||||||
|
fn create_vm_with_type(&self, vm_type: u64) -> Result<Arc<dyn Vm>>;
|
||||||
|
#[cfg(feature = "kvm")]
|
||||||
|
///
|
||||||
/// Returns the size of the memory mapping required to use the vcpu's structures
|
/// Returns the size of the memory mapping required to use the vcpu's structures
|
||||||
///
|
///
|
||||||
fn get_vcpu_mmap_size(&self) -> Result<usize>;
|
fn get_vcpu_mmap_size(&self) -> Result<usize>;
|
||||||
|
@ -521,18 +521,18 @@ impl KvmHypervisor {
|
|||||||
/// let vm = hypervisor.create_vm().expect("new VM fd creation failed");
|
/// let vm = hypervisor.create_vm().expect("new VM fd creation failed");
|
||||||
///
|
///
|
||||||
impl hypervisor::Hypervisor for KvmHypervisor {
|
impl hypervisor::Hypervisor for KvmHypervisor {
|
||||||
/// Create a KVM vm object and return the object as Vm trait object
|
/// Create a KVM vm object of a specific VM type and return the object as Vm trait object
|
||||||
/// Example
|
/// Example
|
||||||
/// # extern crate hypervisor;
|
/// # extern crate hypervisor;
|
||||||
/// # use hypervisor::KvmHypervisor;
|
/// # use hypervisor::KvmHypervisor;
|
||||||
/// use hypervisor::KvmVm;
|
/// use hypervisor::KvmVm;
|
||||||
/// let hypervisor = KvmHypervisor::new().unwrap();
|
/// let hypervisor = KvmHypervisor::new().unwrap();
|
||||||
/// let vm = hypervisor.create_vm().unwrap()
|
/// let vm = hypervisor.create_vm_with_type(KvmVmType::LegacyVm).unwrap()
|
||||||
///
|
///
|
||||||
fn create_vm(&self) -> hypervisor::Result<Arc<dyn vm::Vm>> {
|
fn create_vm_with_type(&self, vm_type: u64) -> hypervisor::Result<Arc<dyn vm::Vm>> {
|
||||||
let fd: VmFd;
|
let fd: VmFd;
|
||||||
loop {
|
loop {
|
||||||
match self.kvm.create_vm() {
|
match self.kvm.create_vm_with_type(vm_type) {
|
||||||
Ok(res) => fd = res,
|
Ok(res) => fd = res,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if e.errno() == libc::EINTR {
|
if e.errno() == libc::EINTR {
|
||||||
@ -577,6 +577,18 @@ impl hypervisor::Hypervisor for KvmHypervisor {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Create a KVM vm object and return the object as Vm trait object
|
||||||
|
/// Example
|
||||||
|
/// # extern crate hypervisor;
|
||||||
|
/// # use hypervisor::KvmHypervisor;
|
||||||
|
/// use hypervisor::KvmVm;
|
||||||
|
/// let hypervisor = KvmHypervisor::new().unwrap();
|
||||||
|
/// let vm = hypervisor.create_vm().unwrap()
|
||||||
|
///
|
||||||
|
fn create_vm(&self) -> hypervisor::Result<Arc<dyn vm::Vm>> {
|
||||||
|
self.create_vm_with_type(0) // Create with default platform type
|
||||||
|
}
|
||||||
|
|
||||||
fn check_required_extensions(&self) -> hypervisor::Result<()> {
|
fn check_required_extensions(&self) -> hypervisor::Result<()> {
|
||||||
check_required_kvm_extensions(&self.kvm).expect("Missing KVM capabilities");
|
check_required_kvm_extensions(&self.kvm).expect("Missing KVM capabilities");
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
x
Reference in New Issue
Block a user