fn create_vm(&self) -> hypervisor::Result<Arc<dyn vm::Vm>> {
        let fd: VmFd;
        loop {
            match self.mshv.create_vm() {
                Ok(res) => fd = res,
                Err(e) => {
                    if e.errno() == libc::EINTR {
                        // If the error returned is EINTR, which means the
                        // ioctl has been interrupted, we have to retry as
                        // this can't be considered as a regular error.
                        continue;
                    } else {
                        return Err(hypervisor::HypervisorError::VmCreate(e.into()));
                    }
                }
            }
            break;
        }

        let msr_list = self.get_msr_list()?;
        let num_msrs = msr_list.as_fam_struct_ref().nmsrs as usize;
        let mut msrs = MsrEntries::new(num_msrs);
        let indices = msr_list.as_slice();
        let msr_entries = msrs.as_mut_slice();
        for (pos, index) in indices.iter().enumerate() {
            msr_entries[pos].index = *index;
        }
        let vm_fd = Arc::new(fd);

        let irqfds = Mutex::new(HashMap::new());
        let ioeventfds = Arc::new(RwLock::new(HashMap::new()));
        let gsi_routes = Arc::new(RwLock::new(HashMap::new()));

        Ok(Arc::new(MshvVm {
            fd: vm_fd,
            msrs,
            irqfds,
            ioeventfds,
            gsi_routes,
            hv_state: hv_state_init(),
            vmmops: None,
        }))
    }
/// Create a mshv vm object and return the object as Vm trait object
/// Example
/// # extern crate hypervisor;
/// # use hypervisor::MshvHypervisor;
/// use hypervisor::MshvVm;
/// let hypervisor = MshvHypervisor::new().unwrap();
/// let vm = hypervisor.create_vm().unwrap()
///
Create a mshv vm object and return the object as Vm trait object
Example
Create a mshv vm object and return the object as Vm trait object Example
fn create_vm(&self) -> hypervisor::Result<Arc<dyn vm::Vm>> {
        let fd: VmFd;
        loop {
            match self.mshv.create_vm() {
                Ok(res) => fd = res,
                Err(e) => {
                    if e.errno() == libc::EINTR {
                        // If the error returned is EINTR, which means the
                        // ioctl has been interrupted, we have to retry as
                        // this can't be considered as a regular error.
                        continue;
                    } else {
                        return Err(hypervisor::HypervisorError::VmCreate(e.into()));
                    }
                }
            }
            break;
        }
        let msr_list = self.get_msr_list()?;
        let num_msrs = msr_list.as_fam_struct_ref().nmsrs as usize;
        let mut msrs = MsrEntries::new(num_msrs);
        let indices = msr_list.as_slice();
        let msr_entries = msrs.as_mut_slice();
        for (pos, index) in indices.iter().enumerate() {
            msr_entries[pos].index = *index;
        }
        let vm_fd = Arc::new(fd);
        let irqfds = Mutex::new(HashMap::new());
        let ioeventfds = Arc::new(RwLock::new(HashMap::new()));
        let gsi_routes = Arc::new(RwLock::new(HashMap::new()));
        Ok(Arc::new(MshvVm {
            fd: vm_fd,
            msrs,
            irqfds,
            ioeventfds,
            gsi_routes,
            hv_state: hv_state_init(),
            vmmops: None,
        }))
    }
fn create_vm ( & self ) -> hypervisor :: Result < Arc < dyn vm :: Vm > > { let fd : VmFd ; loop { match self . mshv . create_vm ( ) { Ok ( res ) => fd = res , Err ( e ) => { if e . errno ( ) == libc :: EINTR { // If the error returned is EINTR, which means the // ioctl has been interrupted, we have to retry as // this can't be considered as a regular error. continue ; } else { return Err ( hypervisor :: HypervisorError :: VmCreate ( e . into ( ) ) ) ; } } } break ; } let msr_list = self . get_msr_list ( ) ? ; let num_msrs = msr_list . as_fam_struct_ref ( ) . nmsrs as usize ; let mut msrs = MsrEntries :: new ( num_msrs ) ; let indices = msr_list . as_slice ( ) ; let msr_entries = msrs . as_mut_slice ( ) ; for ( pos , index ) in indices . iter ( ) . enumerate ( ) { msr_entries [ pos ] . index = * index ; } let vm_fd = Arc :: new ( fd ) ; let irqfds = Mutex :: new ( HashMap :: new ( ) ) ; let ioeventfds = Arc :: new ( RwLock :: new ( HashMap :: new ( ) ) ) ; let gsi_routes = Arc :: new ( RwLock :: new ( HashMap :: new ( ) ) ) ; Ok ( Arc :: new ( MshvVm { fd : vm_fd , msrs , irqfds , ioeventfds , gsi_routes , hv_state : hv_state_init ( ) , vmmops : None , } ) ) }
Create a mshv vm object and return the object as Vm trait object
Example
Create a mshv vm object and return the object as Vm trait object Example
&self
&self
extern crate hypervisor;
None
use hypervisor::mshvhypervisor;
use hypervisor::MshvVm;
let hypervisor = MshvHypervisor::new().unwrap();
let vm = hypervisor.create_vm().unwrap()
use hypervisor :: MshvVm ; let hypervisor = MshvHypervisor :: new () . unwrap () ; let vm = hypervisor . create_vm () . unwrap ()