Receive memory contents for the given range table into guest memory.
(
guest_memory: &GuestMemoryAtomic<GuestMemoryMmap>,
req: &Request,
socket: &mut SocketStream,
)
| 937 | |
| 938 | /// Receive memory contents for the given range table into guest memory. |
| 939 | pub(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 | } |
no test coverage detected