Skip to content

Commit

Permalink
fix: Refactor vmm builder code to simplify logic
Browse files Browse the repository at this point in the history
eliminate the unnecessary usage of the event_manager argument

Signed-off-by: tommady <tommady@users.noreply.github.com>
  • Loading branch information
tommady committed Nov 15, 2024
1 parent 0bf17fb commit 6b97c07
Showing 1 changed file with 7 additions and 12 deletions.
19 changes: 7 additions & 12 deletions src/vmm/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,15 +299,13 @@ pub mod aarch64 {

pub fn create_vmm_and_vcpus(
instance_info: &InstanceInfo,
event_manager: &mut EventManager,
guest_memory: GuestMemoryMmap,
uffd: Option<Uffd>,
vm_config: &VmConfig,
kvm_capabilities: Vec<KvmCapability>,
) -> Result<(Vmm, Vec<Vcpu>), StartMicrovmError> {
let mut vmm = build_vmm(
instance_info,
event_manager,
guest_memory,
uffd,
vm_config,
Expand Down Expand Up @@ -449,15 +447,13 @@ pub mod x86_64 {

pub fn create_vmm_and_vcpus(
instance_info: &InstanceInfo,
event_manager: &mut EventManager,
guest_memory: GuestMemoryMmap,
uffd: Option<Uffd>,
vm_config: &VmConfig,
kvm_capabilities: Vec<KvmCapability>,
) -> Result<(Vmm, Vec<Vcpu>), StartMicrovmError> {
let mut vmm = build_vmm(
instance_info,
event_manager,
guest_memory,
uffd,
vm_config,
Expand All @@ -473,7 +469,6 @@ pub mod x86_64 {

fn build_vmm(
instance_info: &InstanceInfo,
event_manager: &mut EventManager,
guest_memory: GuestMemoryMmap,
uffd: Option<Uffd>,
vm_config: &VmConfig,
Expand Down Expand Up @@ -508,7 +503,7 @@ fn build_vmm(
let pio_device_manager = {
// Serial device setup.
let serial_device =
setup_serial_device(event_manager, std::io::stdin(), io::stdout()).map_err(Internal)?;
setup_serial_device(std::io::stdin(), io::stdout()).map_err(Internal)?;

// x86_64 uses the i8042 reset event as the Vmm exit event.
let reset_evt = vcpus_exit_evt
Expand Down Expand Up @@ -583,16 +578,17 @@ pub fn build_microvm_for_boot(
#[cfg(target_arch = "x86_64")]
let (mut vmm, mut vcpus) = x86_64::create_vmm_and_vcpus(
instance_info,
event_manager,
guest_memory,
None,
&vm_resources.vm_config,
cpu_template.kvm_capabilities.clone(),
)?;
#[cfg(target_arch = "x86_64")]
event_manager.add_subscriber(vmm.pio_device_manager.stdio_serial.clone());

#[cfg(target_arch = "aarch64")]
let (mut vmm, mut vcpus) = aarch64::create_vmm_and_vcpus(
instance_info,
event_manager,
guest_memory,
None,
&vm_resources.vm_config,
Expand Down Expand Up @@ -794,16 +790,16 @@ pub fn build_microvm_from_snapshot(
#[cfg(target_arch = "x86_64")]
let (mut vmm, mut vcpus) = x86_64::create_vmm_and_vcpus(
instance_info,
event_manager,
guest_memory.clone(),
uffd,
&vm_resources.vm_config,
microvm_state.vm_state.kvm_cap_modifiers.clone(),
)?;
#[cfg(target_arch = "x86_64")]
event_manager.add_subscriber(vmm.pio_device_manager.stdio_serial.clone());
#[cfg(target_arch = "aarch64")]
let (mut vmm, mut vcpus) = aarch64::create_vmm_and_vcpus(
instance_info,
event_manager,
guest_memory.clone(),
uffd,
&vm_resources.vm_config,
Expand Down Expand Up @@ -968,7 +964,6 @@ where

/// Sets up the serial device.
pub fn setup_serial_device(
event_manager: &mut EventManager,
input: std::io::Stdin,
out: std::io::Stdout,
) -> Result<Arc<Mutex<BusDevice>>, VmmError> {
Expand All @@ -985,7 +980,7 @@ pub fn setup_serial_device(
),
input: Some(input),
})));
event_manager.add_subscriber(serial.clone());

Ok(serial)
}

Expand Down

0 comments on commit 6b97c07

Please sign in to comment.