vmm: migration: flatten control flow in send_migration()

Move the error branch to the top and remove unnecessary nesting in
send_migration().

This change is purely mechanical and introduces no functional changes.
It simplifies the control flow and prepares the code for the following
migration-related improvements in this series.

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
Philipp Schuster
2026-03-10 09:26:28 +01:00
committed by Rob Bradford
parent 3cbbce353e
commit b5169ff419

View File

@@ -2364,41 +2364,42 @@ impl RequestHandler for Vmm {
)));
}
if let Some(vm) = self.vm.as_mut() {
Self::send_migration(
vm,
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
self.hypervisor.as_ref(),
&send_data_migration,
)
.map_err(|migration_err| {
error!("Migration failed: {migration_err:?}");
let vm = self
.vm
.as_mut()
.ok_or_else(|| MigratableError::MigrateSend(anyhow!("VM is not running")))?;
// Stop logging dirty pages only for non-local migrations
if !send_data_migration.local
&& let Err(e) = vm.stop_dirty_log()
{
return e;
}
Self::send_migration(
vm,
#[cfg(all(feature = "kvm", target_arch = "x86_64"))]
self.hypervisor.as_ref(),
&send_data_migration,
)
.map_err(|migration_err| {
error!("Migration failed: {migration_err:?}");
if vm.get_state() == VmState::Paused
&& let Err(e) = vm.resume()
{
return e;
}
// Stop logging dirty pages only for non-local migrations
if !send_data_migration.local
&& let Err(e) = vm.stop_dirty_log()
{
return e;
}
migration_err
})?;
if vm.get_state() == VmState::Paused
&& let Err(e) = vm.resume()
{
return e;
}
// Shutdown the VM after the migration succeeded
self.exit_evt.write(1).map_err(|e| {
MigratableError::MigrateSend(anyhow!(
"Failed shutting down the VM after migration: {e:?}"
))
})
} else {
Err(MigratableError::MigrateSend(anyhow!("VM is not running")))
}
migration_err
})?;
// Shutdown the VM after the migration succeeded
self.exit_evt.write(1).map_err(|e| {
MigratableError::MigrateSend(anyhow!(
"Failed shutting down the VM after migration: {e:?}"
))
})
}
}