Transmits the given [`MemoryRangeTable`] and the corresponding guest memory content over the wire if there is at least one range. Sends a memory migration request, the range table, and the corresponding guest memory range over the given socket. Waits for acknowledgment from the destination.
(
guest_memory: &GuestMemoryAtomic<GuestMemoryMmap>,
ranges: &MemoryRangeTable,
socket: &mut SocketStream,
)
| 889 | /// guest memory range over the given socket. Waits for acknowledgment |
| 890 | /// from the destination. |
| 891 | pub(crate) fn send_memory_ranges( |
| 892 | guest_memory: &GuestMemoryAtomic<GuestMemoryMmap>, |
| 893 | ranges: &MemoryRangeTable, |
| 894 | socket: &mut SocketStream, |
| 895 | ) -> Result<(), MigratableError> { |
| 896 | if ranges.regions().is_empty() { |
| 897 | return Ok(()); |
| 898 | } |
| 899 | |
| 900 | // Send the memory table |
| 901 | Request::memory(ranges.length()).write_to(socket)?; |
| 902 | ranges.write_to(socket)?; |
| 903 | |
| 904 | // And then the memory itself |
| 905 | let mem = guest_memory.memory(); |
| 906 | for range in ranges.regions() { |
| 907 | let mut offset: u64 = 0; |
| 908 | // Here we are manually handling the retry in case we can't read the |
| 909 | // whole region at once because we can't use the implementation |
| 910 | // from vm-memory::GuestMemory of write_all_to() as it is not |
| 911 | // following the correct behavior. For more info about this issue |
| 912 | // see: https://github.com/rust-vmm/vm-memory/issues/174 |
| 913 | loop { |
| 914 | let bytes_written = mem |
| 915 | .write_volatile_to( |
| 916 | GuestAddress(range.gpa + offset), |
| 917 | socket, |
| 918 | (range.length - offset) as usize, |
| 919 | ) |
| 920 | .map_err(|e| { |
| 921 | MigratableError::MigrateSend(anyhow!( |
| 922 | "Error transferring memory to socket: {e}" |
| 923 | )) |
| 924 | })?; |
| 925 | offset += bytes_written as u64; |
| 926 | |
| 927 | if offset == range.length { |
| 928 | break; |
| 929 | } |
| 930 | } |
| 931 | } |
| 932 | expect_ok_response( |
| 933 | socket, |
| 934 | MigratableError::MigrateSend(anyhow!("Error during dirty memory migration")), |
| 935 | ) |
| 936 | } |
| 937 | |
| 938 | /// Receive memory contents for the given range table into guest memory. |
| 939 | pub(crate) fn receive_memory_ranges( |