vmm: memory_manager: Pass MemoryConfig to simplify the new() prototype

Signed-off-by: Samuel Ortiz <sameo@linux.intel.com>
This commit is contained in:
Samuel Ortiz 2020-03-16 18:04:50 +01:00 committed by Rob Bradford
parent 622f3f8fb6
commit ef2b11ee6c
2 changed files with 15 additions and 26 deletions

View File

@ -3,7 +3,7 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
// //
use crate::config::HotplugMethod; use crate::config::{HotplugMethod, MemoryConfig};
#[cfg(feature = "acpi")] #[cfg(feature = "acpi")]
use acpi_tables::{aml, aml::Aml}; use acpi_tables::{aml, aml::Aml};
use arch::RegionType; use arch::RegionType;
@ -209,14 +209,10 @@ impl MemoryManager {
pub fn new( pub fn new(
allocator: Arc<Mutex<SystemAllocator>>, allocator: Arc<Mutex<SystemAllocator>>,
fd: Arc<VmFd>, fd: Arc<VmFd>,
boot_ram: u64, config: &MemoryConfig,
hotplug_method: HotplugMethod,
hotplug_size: Option<u64>,
backing_file: &Option<PathBuf>,
mergeable: bool,
) -> Result<Arc<Mutex<MemoryManager>>, Error> { ) -> Result<Arc<Mutex<MemoryManager>>, Error> {
// Init guest memory // Init guest memory
let arch_mem_regions = arch::arch_memory_regions(boot_ram); let arch_mem_regions = arch::arch_memory_regions(config.size);
let ram_regions: Vec<(GuestAddress, usize)> = arch_mem_regions let ram_regions: Vec<(GuestAddress, usize)> = arch_mem_regions
.iter() .iter()
@ -227,7 +223,7 @@ impl MemoryManager {
let mut mem_regions = Vec::new(); let mut mem_regions = Vec::new();
for region in ram_regions.iter() { for region in ram_regions.iter() {
mem_regions.push(MemoryManager::create_ram_region( mem_regions.push(MemoryManager::create_ram_region(
backing_file, &config.file,
region.0, region.0,
region.1, region.1,
)?); )?);
@ -246,14 +242,14 @@ impl MemoryManager {
let mut virtiomem_region = None; let mut virtiomem_region = None;
let mut virtiomem_resize = None; let mut virtiomem_resize = None;
if let Some(size) = hotplug_size { if let Some(size) = config.hotplug_size {
if hotplug_method == HotplugMethod::VirtioMem { if config.hotplug_method == HotplugMethod::VirtioMem {
let start_addr = GuestAddress( let start_addr = GuestAddress(
(start_of_device_area.0 + vm_virtio::VIRTIO_MEM_DEFAULT_BLOCK_SIZE - 1) (start_of_device_area.0 + vm_virtio::VIRTIO_MEM_DEFAULT_BLOCK_SIZE - 1)
& (!(vm_virtio::VIRTIO_MEM_DEFAULT_BLOCK_SIZE - 1)), & (!(vm_virtio::VIRTIO_MEM_DEFAULT_BLOCK_SIZE - 1)),
); );
virtiomem_region = Some(MemoryManager::create_ram_region( virtiomem_region = Some(MemoryManager::create_ram_region(
backing_file, &config.file,
start_addr, start_addr,
size as usize, size as usize,
)?); )?);
@ -279,12 +275,12 @@ impl MemoryManager {
fd, fd,
hotplug_slots, hotplug_slots,
selected_slot: 0, selected_slot: 0,
backing_file: backing_file.clone(), backing_file: config.file.clone(),
mergeable, mergeable: config.mergeable,
allocator: allocator.clone(), allocator: allocator.clone(),
hotplug_method, hotplug_method: config.hotplug_method.clone(),
boot_ram, boot_ram: config.size,
current_ram: boot_ram, current_ram: config.size,
next_hotplug_slot: 0, next_hotplug_slot: 0,
virtiomem_region: virtiomem_region.clone(), virtiomem_region: virtiomem_region.clone(),
virtiomem_resize, virtiomem_resize,
@ -295,7 +291,7 @@ impl MemoryManager {
region.start_addr().raw_value(), region.start_addr().raw_value(),
region.len() as u64, region.len() as u64,
region.as_ptr() as u64, region.as_ptr() as u64,
mergeable, config.mergeable,
false, false,
)?; )?;
Ok(()) Ok(())
@ -306,7 +302,7 @@ impl MemoryManager {
region.start_addr().raw_value(), region.start_addr().raw_value(),
region.len() as u64, region.len() as u64,
region.as_ptr() as u64, region.as_ptr() as u64,
mergeable, config.mergeable,
false, false,
)?; )?;
allocator allocator

View File

@ -334,21 +334,14 @@ impl Vm {
.ok_or(Error::CreateSystemAllocator)?, .ok_or(Error::CreateSystemAllocator)?,
)); ));
let memory_config = config.lock().unwrap().memory.clone();
let memory_manager = MemoryManager::new( let memory_manager = MemoryManager::new(
allocator.clone(), allocator.clone(),
fd.clone(), fd.clone(),
memory_config.size, &config.lock().unwrap().memory.clone(),
memory_config.hotplug_method,
memory_config.hotplug_size,
&memory_config.file,
memory_config.mergeable,
) )
.map_err(Error::MemoryManager)?; .map_err(Error::MemoryManager)?;
let guest_memory = memory_manager.lock().unwrap().guest_memory(); let guest_memory = memory_manager.lock().unwrap().guest_memory();
let device_manager = DeviceManager::new( let device_manager = DeviceManager::new(
fd.clone(), fd.clone(),
config.clone(), config.clone(),