mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-11-04 19:11:11 +00:00
vmm, virtio-devices: Move BlocksState creation to the MemoryManager
By creating the BlocksState object in the MemoryManager, we can directly provide it to the virtio-mem device when being created. This will allow the MemoryManager through each VirtioMemZone to have a handle onto the blocks that are plugged at any point in time. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
4450c44fbc
commit
e390775bcb
@ -393,7 +393,7 @@ pub struct BlocksState {
|
||||
}
|
||||
|
||||
impl BlocksState {
|
||||
fn new(region_size: u64) -> Self {
|
||||
pub fn new(region_size: u64) -> Self {
|
||||
BlocksState {
|
||||
bitmap: vec![false; (region_size / VIRTIO_MEM_DEFAULT_BLOCK_SIZE) as usize],
|
||||
}
|
||||
@ -810,6 +810,7 @@ impl Mem {
|
||||
initial_size: u64,
|
||||
hugepages: bool,
|
||||
exit_evt: EventFd,
|
||||
blocks_state: Arc<Mutex<BlocksState>>,
|
||||
) -> io::Result<Mem> {
|
||||
let region_len = region.len();
|
||||
|
||||
@ -882,7 +883,7 @@ impl Mem {
|
||||
seccomp_action,
|
||||
hugepages,
|
||||
dma_mapping_handlers: Arc::new(Mutex::new(BTreeMap::new())),
|
||||
blocks_state: Arc::new(Mutex::new(BlocksState::new(config.region_size))),
|
||||
blocks_state,
|
||||
exit_evt,
|
||||
})
|
||||
}
|
||||
|
@ -2694,6 +2694,7 @@ impl DeviceManager {
|
||||
self.exit_evt
|
||||
.try_clone()
|
||||
.map_err(DeviceManagerError::EventFd)?,
|
||||
virtio_mem_zone.blocks_state().clone(),
|
||||
)
|
||||
.map_err(DeviceManagerError::CreateVirtioMem)?,
|
||||
));
|
||||
|
@ -30,6 +30,7 @@ use std::result;
|
||||
use std::sync::{Arc, Barrier, Mutex};
|
||||
use versionize::{VersionMap, Versionize, VersionizeResult};
|
||||
use versionize_derive::Versionize;
|
||||
use virtio_devices::BlocksState;
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use vm_allocator::GsiApic;
|
||||
use vm_allocator::SystemAllocator;
|
||||
@ -73,6 +74,7 @@ pub struct VirtioMemZone {
|
||||
resize_handler: virtio_devices::Resize,
|
||||
hotplugged_size: u64,
|
||||
hugepages: bool,
|
||||
blocks_state: Arc<Mutex<BlocksState>>,
|
||||
}
|
||||
|
||||
impl VirtioMemZone {
|
||||
@ -88,6 +90,15 @@ impl VirtioMemZone {
|
||||
pub fn hugepages(&self) -> bool {
|
||||
self.hugepages
|
||||
}
|
||||
pub fn blocks_state(&self) -> &Arc<Mutex<BlocksState>> {
|
||||
&self.blocks_state
|
||||
}
|
||||
pub fn plugged_ranges(&self) -> MemoryRangeTable {
|
||||
self.blocks_state
|
||||
.lock()
|
||||
.unwrap()
|
||||
.memory_ranges(self.region.start_addr().raw_value(), true)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
@ -699,12 +710,14 @@ impl MemoryManager {
|
||||
virtio_mem_regions.push(region.clone());
|
||||
|
||||
let hotplugged_size = zone.hotplugged_size.unwrap_or(0);
|
||||
let region_size = region.len();
|
||||
memory_zone.virtio_mem_zone = Some(VirtioMemZone {
|
||||
region,
|
||||
resize_handler: virtio_devices::Resize::new(hotplugged_size)
|
||||
.map_err(Error::EventFdFail)?,
|
||||
hotplugged_size,
|
||||
hugepages: zone.hugepages,
|
||||
blocks_state: Arc::new(Mutex::new(BlocksState::new(region_size))),
|
||||
});
|
||||
|
||||
start_of_device_area = start_addr
|
||||
|
Loading…
Reference in New Issue
Block a user