MCPcopy Create free account
hub / github.com/cloud-hypervisor/cloud-hypervisor / receive_memory_ranges

Function receive_memory_ranges

vmm/src/migration_transport.rs:939–979  ·  view source on GitHub ↗

Receive memory contents for the given range table into guest memory.

(
    guest_memory: &GuestMemoryAtomic<GuestMemoryMmap>,
    req: &Request,
    socket: &mut SocketStream,
)

Source from the content-addressed store, hash-verified

937
938/// Receive memory contents for the given range table into guest memory.
939pub(crate) fn receive_memory_ranges(
940 guest_memory: &GuestMemoryAtomic<GuestMemoryMmap>,
941 req: &Request,
942 socket: &mut SocketStream,
943) -> Result<(), MigratableError> {
944 debug_assert_eq!(req.command(), Command::Memory);
945 // Read the memory table
946 let ranges = MemoryRangeTable::read_from(socket, req.length())?;
947
948 // And then the memory itself
949 let mem = guest_memory.memory();
950
951 for range in ranges.regions() {
952 let mut offset: u64 = 0;
953 // Here we are manually handling the retry in case we can't read the
954 // whole region at once because we can't use the implementation
955 // from vm-memory::GuestMemory of read_exact_from() as it is not
956 // following the correct behavior. For more info about this issue
957 // see: https://github.com/rust-vmm/vm-memory/issues/174
958 loop {
959 let bytes_read = mem
960 .read_volatile_from(
961 GuestAddress(range.gpa + offset),
962 socket,
963 (range.length - offset) as usize,
964 )
965 .map_err(|e| {
966 MigratableError::MigrateReceive(anyhow!(
967 "Error receiving memory from socket: {e}"
968 ))
969 })?;
970 offset += bytes_read as u64;
971
972 if offset == range.length {
973 break;
974 }
975 }
976 }
977
978 Ok(())
979}

Callers 2

worker_receive_memoryMethod · 0.85

Calls 3

memoryMethod · 0.80
lengthMethod · 0.45
regionsMethod · 0.45

Tested by

no test coverage detected