From 3db4c003a3a4937f8123eee4ff3ab0ebd39d4745 Mon Sep 17 00:00:00 2001 From: Samuel Ortiz Date: Fri, 3 Jul 2020 10:57:35 +0200 Subject: [PATCH] vmm: cpu: Rename fd variable into something more meaningful The fd naming is quite KVM specific. Since we're now using the hypervisor crate abstractions, we can rename those into something more readable and meaningful. Like e.g. vcpu or vm. Signed-off-by: Samuel Ortiz --- vmm/src/cpu.rs | 42 ++++++++++++++++++++++-------------------- 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/vmm/src/cpu.rs b/vmm/src/cpu.rs index 33d1676f5..341fd474e 100644 --- a/vmm/src/cpu.rs +++ b/vmm/src/cpu.rs @@ -102,8 +102,8 @@ impl fmt::Display for DebugIoPortRange { #[derive(Debug)] pub enum Error { - /// Cannot open the VCPU file descriptor. - VcpuFd(anyhow::Error), + /// Cannot create the vCPU. + VcpuCreate(anyhow::Error), /// Cannot run the VCPUs. VcpuRun(anyhow::Error), @@ -232,7 +232,8 @@ struct InterruptSourceOverride { /// A wrapper around creating and using a kvm-based VCPU. pub struct Vcpu { - fd: Arc, + // The hypervisor abstracted CPU. + vcpu: Arc, id: u8, #[cfg(target_arch = "x86_64")] io_bus: Arc, @@ -255,16 +256,18 @@ impl Vcpu { /// * `vm` - The virtual machine this vcpu will get attached to. pub fn new( id: u8, - fd: &Arc, + vm: &Arc, #[cfg(target_arch = "x86_64")] io_bus: Arc, mmio_bus: Arc, interrupt_controller: Option>>, creation_ts: std::time::Instant, ) -> Result>> { - let kvm_vcpu = fd.create_vcpu(id).map_err(|e| Error::VcpuFd(e.into()))?; + let vcpu = vm + .create_vcpu(id) + .map_err(|e| Error::VcpuCreate(e.into()))?; // Initially the cpuid per vCPU is the one supported by this VM. Ok(Arc::new(Mutex::new(Vcpu { - fd: kvm_vcpu, + vcpu, id, #[cfg(target_arch = "x86_64")] io_bus, @@ -281,13 +284,12 @@ impl Vcpu { /// /// # Arguments /// - /// * `fd` - VcpuFd. /// * `kernel_entry_point` - Kernel entry point address in guest memory and boot protocol used. /// * `vm_memory` - Guest memory. /// * `cpuid` - (x86_64) CpuId, wrapper over the `kvm_cpuid2` structure. pub fn configure( &mut self, - #[cfg(target_arch = "aarch64")] vm_fd: &Arc, + #[cfg(target_arch = "aarch64")] vm: &Arc, kernel_entry_point: Option, vm_memory: &GuestMemoryAtomic, #[cfg(target_arch = "x86_64")] cpuid: CpuId, @@ -295,12 +297,12 @@ impl Vcpu { #[cfg(target_arch = "aarch64")] { self.mpidr = - arch::configure_vcpu(&self.fd, self.id, vm_fd, kernel_entry_point, vm_memory) + arch::configure_vcpu(&self.vcpu, self.id, vm, kernel_entry_point, vm_memory) .map_err(Error::VcpuConfiguration)?; } #[cfg(target_arch = "x86_64")] - arch::configure_vcpu(&self.fd, self.id, kernel_entry_point, vm_memory, cpuid) + arch::configure_vcpu(&self.vcpu, self.id, kernel_entry_point, vm_memory, cpuid) .map_err(Error::VcpuConfiguration)?; Ok(()) @@ -317,7 +319,7 @@ impl Vcpu { /// Note that the state of the VCPU and associated VM must be setup first for this to do /// anything useful. pub fn run(&self) -> Result { - match self.fd.run() { + match self.vcpu.run() { Ok(run) => match run { #[cfg(target_arch = "x86_64")] VcpuExit::IoIn(addr, data) => { @@ -403,7 +405,7 @@ const VCPU_SNAPSHOT_ID: &str = "vcpu"; impl Pausable for Vcpu { fn pause(&mut self) -> std::result::Result<(), MigratableError> { self.saved_state = - Some(self.fd.state().map_err(|e| { + Some(self.vcpu.state().map_err(|e| { MigratableError::Pause(anyhow!("Could not get vCPU state {:?}", e)) })?); @@ -412,7 +414,7 @@ impl Pausable for Vcpu { fn resume(&mut self) -> std::result::Result<(), MigratableError> { if let Some(vcpu_state) = &self.saved_state { - self.fd.set_state(vcpu_state).map_err(|e| { + self.vcpu.set_state(vcpu_state).map_err(|e| { MigratableError::Pause(anyhow!("Could not set the vCPU state {:?}", e)) })?; } @@ -477,7 +479,7 @@ pub struct CpuManager { #[cfg(target_arch = "x86_64")] cpuid: CpuId, #[cfg_attr(target_arch = "aarch64", allow(dead_code))] - fd: Arc, + vm: Arc, vcpus_kill_signalled: Arc, vcpus_pause_signalled: Arc, #[cfg_attr(target_arch = "aarch64", allow(dead_code))] @@ -608,7 +610,7 @@ impl CpuManager { config: &CpusConfig, device_manager: &Arc>, guest_memory: GuestMemoryAtomic, - fd: Arc, + vm: Arc, reset_evt: EventFd, hypervisor: Arc, ) -> Result>> { @@ -627,7 +629,7 @@ impl CpuManager { vm_memory: guest_memory, #[cfg(target_arch = "x86_64")] cpuid, - fd, + vm, vcpus_kill_signalled: Arc::new(AtomicBool::new(false)), vcpus_pause_signalled: Arc::new(AtomicBool::new(false)), vcpu_states, @@ -721,7 +723,7 @@ impl CpuManager { let vcpu = Vcpu::new( cpu_id, - &self.fd, + &self.vm, #[cfg(target_arch = "x86_64")] self.io_bus.clone(), self.mmio_bus.clone(), @@ -738,7 +740,7 @@ impl CpuManager { vcpu.lock() .unwrap() - .fd + .vcpu .set_cpuid2(&cpuid) .map_err(|e| Error::SetSupportedCpusFailed(e.into()))?; } @@ -758,7 +760,7 @@ impl CpuManager { #[cfg(target_arch = "aarch64")] vcpu.lock() .unwrap() - .configure(&self.fd, entry_point, &vm_memory) + .configure(&self.vm, entry_point, &vm_memory) .expect("Failed to configure vCPU"); } @@ -1348,7 +1350,7 @@ impl Pausable for CpuManager { let mut vcpu = vcpu.lock().unwrap(); vcpu.pause()?; #[cfg(target_arch = "x86_64")] - vcpu.fd.notify_guest_clock_paused().map_err(|e| { + vcpu.vcpu.notify_guest_clock_paused().map_err(|e| { MigratableError::Pause(anyhow!("Could not notify guest it has been paused {:?}", e)) })?; }