vmm: Move MemoryRangeTable creation to the MemoryManager

The function memory_range_table() will be reused by the MemoryManager in
a following patch to describe all the ranges that we should snapshot.

Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
Sebastien Boeuf
2021-09-27 13:43:04 +02:00
committed by Bo Chen
parent 86f86c5348
commit 1ea63f50a1
2 changed files with 28 additions and 26 deletions

View File

@@ -41,8 +41,8 @@ use vm_memory::{
GuestMemory, GuestMemoryAtomic, GuestMemoryError, GuestMemoryRegion, GuestUsize, MmapRegion,
};
use vm_migration::{
protocol::MemoryRangeTable, Migratable, MigratableError, Pausable, Snapshot,
SnapshotDataSection, Snapshottable, Transportable, VersionMapped,
protocol::MemoryRange, protocol::MemoryRangeTable, Migratable, MigratableError, Pausable,
Snapshot, SnapshotDataSection, Snapshottable, Transportable, VersionMapped,
};
#[cfg(feature = "acpi")]
@@ -1508,6 +1508,24 @@ impl MemoryManager {
pub fn memory_zones(&self) -> &MemoryZones {
&self.memory_zones
}
pub fn memory_range_table(&self) -> std::result::Result<MemoryRangeTable, MigratableError> {
let mut table = MemoryRangeTable::default();
for memory_zone in self.memory_zones.values() {
for region in memory_zone.regions() {
table.push(MemoryRange {
gpa: region.start_addr().raw_value(),
length: region.len() as u64,
});
}
if let Some(virtio_mem_zone) = memory_zone.virtio_mem_zone() {
table.extend(virtio_mem_zone.plugged_ranges());
}
}
Ok(table)
}
}
#[cfg(feature = "acpi")]