mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-02-01 17:35:19 +00:00
virtio-devices: mem: Create a MemoryRangeTable from BlocksState
This is going to be useful to let virtio-mem report the list of ranges that are currently plugged, so that both snapshot/restore and migration will copy only what is needed. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
a1caa6549a
commit
4450c44fbc
@ -40,6 +40,7 @@ use vm_memory::{
|
|||||||
Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemoryAtomic,
|
Address, ByteValued, Bytes, GuestAddress, GuestAddressSpace, GuestMemoryAtomic,
|
||||||
GuestMemoryError, GuestMemoryRegion,
|
GuestMemoryError, GuestMemoryRegion,
|
||||||
};
|
};
|
||||||
|
use vm_migration::protocol::MemoryRangeTable;
|
||||||
use vm_migration::{
|
use vm_migration::{
|
||||||
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
|
Migratable, MigratableError, Pausable, Snapshot, Snapshottable, Transportable, VersionMapped,
|
||||||
};
|
};
|
||||||
@ -426,6 +427,26 @@ impl BlocksState {
|
|||||||
fn inner(&self) -> &Vec<bool> {
|
fn inner(&self) -> &Vec<bool> {
|
||||||
&self.bitmap
|
&self.bitmap
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn memory_ranges(&self, start_addr: u64, plugged: bool) -> MemoryRangeTable {
|
||||||
|
let mut bitmap: Vec<u64> = Vec::new();
|
||||||
|
let mut i = 0;
|
||||||
|
for (j, bit) in self.bitmap.iter().enumerate() {
|
||||||
|
if j % 64 == 0 {
|
||||||
|
bitmap.push(0);
|
||||||
|
|
||||||
|
if j != 0 {
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if *bit == plugged {
|
||||||
|
bitmap[i] |= 1 << (j % 64);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
MemoryRangeTable::from_bitmap(bitmap, start_addr, VIRTIO_MEM_DEFAULT_BLOCK_SIZE)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct MemEpollHandler {
|
struct MemEpollHandler {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user