vmm: Allow preserving the source VM after snapshot

Extend the migration protocol with a `preserve_source` option so that a
source VM can be preserved. This benefits the snapshot case where the
offload daemon can now snapshot a VM without tearing it down.

Signed-off-by: Sebastien Boeuf <sboeuf@meta.com>
Assisted-by: Claude:claude-opus-4-8
This commit is contained in:
Sebastien Boeuf
2026-07-23 01:43:25 -07:00
parent b47c26fa56
commit 17b5deeaed
4 changed files with 99 additions and 15 deletions

View File

@@ -1670,8 +1670,11 @@ impl Vmm {
};
transport::send_config(&mut socket, &vm_migration_config)?;
// Let every Migratable object know about the migration being started.
vm.start_migration()?;
// Let every Migratable object know about the migration being started
// unless the source VM must be preserved.
if !send_data_migration.preserve_source {
vm.start_migration()?;
}
if send_data_migration.local
|| matches!(send_data_migration.memory_mode, MigrationMode::Postcopy)
@@ -1716,8 +1719,11 @@ impl Vmm {
// We release the locks early to enable locking them on the destination host.
// The VM is already stopped.
vm.release_disk_locks()
.map_err(|e| MigratableError::UnlockError(anyhow!("{e}")))?;
// Keep the locks held if the source VM must be preserved.
if !send_data_migration.preserve_source {
vm.release_disk_locks()
.map_err(|e| MigratableError::UnlockError(anyhow!("{e}")))?;
}
// For postcopy, serve faults before sending State so the destination
// can fault pages in during restore.
@@ -1809,7 +1815,12 @@ impl Vmm {
}
// Let every Migratable object know about the migration being complete
vm.complete_migration()
// unless the source VM must be preserved.
if send_data_migration.preserve_source {
Ok(())
} else {
vm.complete_migration()
}
}
/// Serve `Command::PageFault` requests from local guest memory on the fault
@@ -2031,6 +2042,7 @@ impl Vmm {
vm,
migration_result: migration_res,
initial_vm_state,
preserve_source,
} = migration_worker_handle.join();
let mut try_resume_vm_after_failed_migration = |mut vm: Vm| {
@@ -2056,6 +2068,10 @@ impl Vmm {
};
match migration_res {
Ok(()) if preserve_source => {
// Give the source VM back to the VMM.
self.vm = VmOwnership::Owned(vm);
}
Ok(()) => {
self.vm = VmOwnership::None;
let mut vm = vm;