vmm: Obtain sequential KVM memory slot numbers from MemoryManager

This removes the need to handle a mutable integer and also centralises
the allocation of these slot numbers.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford
2019-12-20 15:17:49 +00:00
parent 260cebb8cf
commit 61cfe3e72d
3 changed files with 31 additions and 30 deletions

View File

@@ -21,7 +21,7 @@ use kvm_ioctls::*;
pub struct MemoryManager {
guest_memory: Arc<RwLock<GuestMemoryMmap>>,
ram_regions: u32,
next_kvm_memory_slot: u32,
start_of_device_area: GuestAddress,
end_of_device_area: GuestAddress,
}
@@ -192,7 +192,7 @@ impl MemoryManager {
Ok(Arc::new(Mutex::new(MemoryManager {
guest_memory,
ram_regions: ram_regions.len() as u32,
next_kvm_memory_slot: ram_regions.len() as u32,
start_of_device_area,
end_of_device_area,
})))
@@ -202,10 +202,6 @@ impl MemoryManager {
self.guest_memory.clone()
}
pub fn ram_regions(&self) -> u32 {
self.ram_regions
}
pub fn start_of_device_area(&self) -> GuestAddress {
self.start_of_device_area
}
@@ -213,4 +209,10 @@ impl MemoryManager {
pub fn end_of_device_area(&self) -> GuestAddress {
self.end_of_device_area
}
pub fn allocate_kvm_memory_slot(&mut self) -> u32 {
let slot_id = self.next_kvm_memory_slot;
self.next_kvm_memory_slot += 1;
slot_id
}
}