mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-22 12:35:19 +00:00
vmm: vm: Factorize the KVM setup code
Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
parent
3eb11069d0
commit
1a2c1f9751
@ -251,12 +251,7 @@ pub struct Vm {
|
||||
}
|
||||
|
||||
impl Vm {
|
||||
pub fn new(
|
||||
config: Arc<Mutex<VmConfig>>,
|
||||
exit_evt: EventFd,
|
||||
reset_evt: EventFd,
|
||||
vmm_path: PathBuf,
|
||||
) -> Result<Self> {
|
||||
fn kvm_new() -> Result<(Kvm, Arc<VmFd>)> {
|
||||
let kvm = Kvm::new().map_err(Error::KvmNew)?;
|
||||
|
||||
// Check required capabilities:
|
||||
@ -272,14 +267,6 @@ impl Vm {
|
||||
return Err(Error::CapabilityMissing(Cap::SplitIrqchip));
|
||||
}
|
||||
|
||||
let kernel = File::open(&config.lock().unwrap().kernel.as_ref().unwrap().path)
|
||||
.map_err(Error::KernelFile)?;
|
||||
|
||||
let initramfs = match &config.lock().unwrap().initramfs {
|
||||
Some(initramfs) => Some(File::open(&initramfs.path).map_err(Error::InitramfsFile)?),
|
||||
None => None,
|
||||
};
|
||||
|
||||
let fd: VmFd;
|
||||
loop {
|
||||
match kvm.create_vm() {
|
||||
@ -303,7 +290,6 @@ impl Vm {
|
||||
fd.set_tss_address(arch::x86_64::layout::KVM_TSS_ADDRESS.raw_value() as usize)
|
||||
.map_err(Error::VmSetup)?;
|
||||
|
||||
let mut cpuid_patches = Vec::new();
|
||||
// Create split irqchip
|
||||
// Only the local APIC is emulated in kernel, both PICs and IOAPIC
|
||||
// are not.
|
||||
@ -312,6 +298,31 @@ impl Vm {
|
||||
cap.args[0] = ioapic::NUM_IOAPIC_PINS as u64;
|
||||
fd.enable_cap(&cap).map_err(Error::VmSetup)?;
|
||||
|
||||
Ok((kvm, fd))
|
||||
}
|
||||
|
||||
pub fn new(
|
||||
config: Arc<Mutex<VmConfig>>,
|
||||
exit_evt: EventFd,
|
||||
reset_evt: EventFd,
|
||||
vmm_path: PathBuf,
|
||||
) -> Result<Self> {
|
||||
let (kvm, fd) = Vm::kvm_new()?;
|
||||
|
||||
let kernel = File::open(&config.lock().unwrap().kernel.as_ref().unwrap().path)
|
||||
.map_err(Error::KernelFile)?;
|
||||
|
||||
let initramfs = config
|
||||
.lock()
|
||||
.unwrap()
|
||||
.initramfs
|
||||
.as_ref()
|
||||
.map(|i| File::open(&i.path))
|
||||
.transpose()
|
||||
.map_err(Error::InitramfsFile)?;
|
||||
|
||||
let mut cpuid_patches = Vec::new();
|
||||
|
||||
// Patch tsc deadline timer bit
|
||||
cpuid_patches.push(cpu::CpuidPatch {
|
||||
function: 1,
|
||||
|
Loading…
x
Reference in New Issue
Block a user