vmm: move function to send dirty pages into transport module

On-behalf-of: SAP sebastian.eydam@sap.com
Signed-off-by: Sebastian Eydam <sebastian.eydam@cyberus-technology.de>
This commit is contained in:
Sebastian Eydam
2026-03-09 10:13:09 +01:00
committed by Bo Chen
parent 693cdccbb0
commit e03c0f7708
2 changed files with 31 additions and 30 deletions
+29 -1
View File
@@ -12,9 +12,10 @@ use std::result::Result;
use anyhow::{Context, anyhow};
use log::info;
use serde_json;
use vm_migration::protocol::{Request, Response};
use vm_migration::protocol::{MemoryRangeTable, Request, Response};
use vm_migration::{MigratableError, Snapshot};
use crate::vm::Vm;
use crate::{SocketStream, VmMigrationConfig};
/// Extract a UNIX socket path from a "unix:" migration URL.
@@ -135,3 +136,30 @@ pub(crate) fn send_state(
MigratableError::MigrateSend(anyhow!("Error during state migration")),
)
}
/// Transmits the given [`MemoryRangeTable`] over the wire if there is at
/// least one region.
///
/// Sends a memory migration request, the range table, and the corresponding
/// guest memory regions over the given socket. Waits for acknowledgment
/// from the destination.
pub(crate) fn vm_send_dirty_pages(
vm: &mut Vm,
socket: &mut SocketStream,
table: &MemoryRangeTable,
) -> Result<(), MigratableError> {
if table.regions().is_empty() {
return Ok(());
}
Request::memory(table.length()).write_to(socket)?;
table.write_to(socket)?;
// And then the memory itself
vm.send_memory_regions(table, socket)?;
expect_ok_response(
socket,
MigratableError::MigrateSend(anyhow!("Error during dirty memory migration")),
)?;
Ok(())
}