vmm: device_manager: Add an MMIO devices creation routine

In order to reduce the DeviceManager's new() complexity, we can move the
MMIO devices creation code into its own routine.

Fixes: #441

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2019-11-18 12:35:05 +01:00 committed by Sebastien Boeuf
parent 79b8f8e477
commit a2ee681665

View File

@ -472,29 +472,13 @@ impl DeviceManager {
&interrupt_info, &interrupt_info,
)?; )?;
} else if cfg!(feature = "mmio_support") { } else if cfg!(feature = "mmio_support") {
#[cfg(feature = "mmio_support")] DeviceManager::add_mmio_devices(
{ vm_info,
for (device, _) in virtio_devices { &address_manager,
let mmio_addr = address_manager virtio_devices,
.allocator &interrupt_info,
.lock() &mut cmdline_additions,
.unwrap() )?;
.allocate_mmio_addresses(None, MMIO_LEN, Some(MMIO_LEN));
if let Some(addr) = mmio_addr {
DeviceManager::add_virtio_mmio_device(
device,
vm_info.memory,
&address_manager,
vm_info.vm_fd,
&interrupt_info,
addr,
&mut cmdline_additions,
)?;
} else {
error!("Unable to allocate MMIO address!");
}
}
}
} }
Ok(DeviceManager { Ok(DeviceManager {
@ -610,6 +594,41 @@ impl DeviceManager {
Ok(()) Ok(())
} }
#[allow(unused_variables, unused_mut)]
fn add_mmio_devices(
vm_info: &VmInfo,
address_manager: &Arc<AddressManager>,
virtio_devices: Vec<(Box<dyn vm_virtio::VirtioDevice>, bool)>,
interrupt_info: &InterruptInfo,
mut cmdline_additions: &mut Vec<String>,
) -> DeviceManagerResult<()> {
#[cfg(feature = "mmio_support")]
{
for (device, _) in virtio_devices {
let mmio_addr = address_manager
.allocator
.lock()
.unwrap()
.allocate_mmio_addresses(None, MMIO_LEN, Some(MMIO_LEN));
if let Some(addr) = mmio_addr {
DeviceManager::add_virtio_mmio_device(
device,
vm_info.memory,
&address_manager,
vm_info.vm_fd,
&interrupt_info,
addr,
&mut cmdline_additions,
)?;
} else {
error!("Unable to allocate MMIO address!");
}
}
}
Ok(())
}
fn make_ioapic( fn make_ioapic(
vm_info: &VmInfo, vm_info: &VmInfo,
address_manager: &Arc<AddressManager>, address_manager: &Arc<AddressManager>,