mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-23 00:11:16 +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 {
|
impl Vm {
|
||||||
pub fn new(
|
fn kvm_new() -> Result<(Kvm, Arc<VmFd>)> {
|
||||||
config: Arc<Mutex<VmConfig>>,
|
|
||||||
exit_evt: EventFd,
|
|
||||||
reset_evt: EventFd,
|
|
||||||
vmm_path: PathBuf,
|
|
||||||
) -> Result<Self> {
|
|
||||||
let kvm = Kvm::new().map_err(Error::KvmNew)?;
|
let kvm = Kvm::new().map_err(Error::KvmNew)?;
|
||||||
|
|
||||||
// Check required capabilities:
|
// Check required capabilities:
|
||||||
@ -272,14 +267,6 @@ impl Vm {
|
|||||||
return Err(Error::CapabilityMissing(Cap::SplitIrqchip));
|
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;
|
let fd: VmFd;
|
||||||
loop {
|
loop {
|
||||||
match kvm.create_vm() {
|
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)
|
fd.set_tss_address(arch::x86_64::layout::KVM_TSS_ADDRESS.raw_value() as usize)
|
||||||
.map_err(Error::VmSetup)?;
|
.map_err(Error::VmSetup)?;
|
||||||
|
|
||||||
let mut cpuid_patches = Vec::new();
|
|
||||||
// Create split irqchip
|
// Create split irqchip
|
||||||
// Only the local APIC is emulated in kernel, both PICs and IOAPIC
|
// Only the local APIC is emulated in kernel, both PICs and IOAPIC
|
||||||
// are not.
|
// are not.
|
||||||
@ -312,6 +298,31 @@ impl Vm {
|
|||||||
cap.args[0] = ioapic::NUM_IOAPIC_PINS as u64;
|
cap.args[0] = ioapic::NUM_IOAPIC_PINS as u64;
|
||||||
fd.enable_cap(&cap).map_err(Error::VmSetup)?;
|
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
|
// Patch tsc deadline timer bit
|
||||||
cpuid_patches.push(cpu::CpuidPatch {
|
cpuid_patches.push(cpu::CpuidPatch {
|
||||||
function: 1,
|
function: 1,
|
||||||
|
Loading…
Reference in New Issue
Block a user