mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 13:45:20 +00:00
vmm: Use Response::ok_or_abandon() in migration logic
The use of this method removes duplicated code yet provides clarity on the logic. Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
This commit is contained in:
parent
e97cee99ef
commit
de1abe0e30
@ -949,15 +949,10 @@ impl Vmm {
|
||||
table.write_to(socket)?;
|
||||
// And then the memory itself
|
||||
vm.send_memory_regions(&table, socket)?;
|
||||
let res = Response::read_from(socket)?;
|
||||
if res.status() != Status::Ok {
|
||||
warn!("Error during dirty memory migration");
|
||||
Request::abandon().write_to(socket)?;
|
||||
Response::read_from(socket).ok();
|
||||
return Err(MigratableError::MigrateSend(anyhow!(
|
||||
"Error during dirty memory migration"
|
||||
)));
|
||||
}
|
||||
Response::read_from(socket)?.ok_or_abandon(
|
||||
socket,
|
||||
MigratableError::MigrateSend(anyhow!("Error during dirty memory migration")),
|
||||
)?;
|
||||
|
||||
Ok(true)
|
||||
}
|
||||
@ -976,15 +971,10 @@ impl Vmm {
|
||||
|
||||
// Start the migration
|
||||
Request::start().write_to(&mut socket)?;
|
||||
let res = Response::read_from(&mut socket)?;
|
||||
if res.status() != Status::Ok {
|
||||
warn!("Error starting migration");
|
||||
Request::abandon().write_to(&mut socket)?;
|
||||
Response::read_from(&mut socket).ok();
|
||||
return Err(MigratableError::MigrateSend(anyhow!(
|
||||
"Error starting migration"
|
||||
)));
|
||||
}
|
||||
Response::read_from(&mut socket)?.ok_or_abandon(
|
||||
&mut socket,
|
||||
MigratableError::MigrateSend(anyhow!("Error starting migration")),
|
||||
)?;
|
||||
|
||||
// Send config
|
||||
let vm_config = vm.get_config();
|
||||
@ -1031,15 +1021,10 @@ impl Vmm {
|
||||
socket
|
||||
.write_all(&config_data)
|
||||
.map_err(MigratableError::MigrateSocket)?;
|
||||
let res = Response::read_from(&mut socket)?;
|
||||
if res.status() != Status::Ok {
|
||||
warn!("Error during config migration");
|
||||
Request::abandon().write_to(&mut socket)?;
|
||||
Response::read_from(&mut socket).ok();
|
||||
return Err(MigratableError::MigrateSend(anyhow!(
|
||||
"Error during config migration"
|
||||
)));
|
||||
}
|
||||
Response::read_from(&mut socket)?.ok_or_abandon(
|
||||
&mut socket,
|
||||
MigratableError::MigrateSend(anyhow!("Error during config migration")),
|
||||
)?;
|
||||
|
||||
// Let every Migratable object know about the migration being started.
|
||||
vm.start_migration()?;
|
||||
@ -1059,15 +1044,10 @@ impl Vmm {
|
||||
table.write_to(&mut socket)?;
|
||||
// And then the memory itself
|
||||
vm.send_memory_regions(&table, &mut socket)?;
|
||||
let res = Response::read_from(&mut socket)?;
|
||||
if res.status() != Status::Ok {
|
||||
warn!("Error during memory migration");
|
||||
Request::abandon().write_to(&mut socket)?;
|
||||
Response::read_from(&mut socket).ok();
|
||||
return Err(MigratableError::MigrateSend(anyhow!(
|
||||
"Error during memory migration"
|
||||
)));
|
||||
}
|
||||
Response::read_from(&mut socket)?.ok_or_abandon(
|
||||
&mut socket,
|
||||
MigratableError::MigrateSend(anyhow!("Error during dirty memory migration")),
|
||||
)?;
|
||||
|
||||
// Try at most 5 passes of dirty memory sending
|
||||
const MAX_DIRTY_MIGRATIONS: usize = 5;
|
||||
@ -1094,27 +1074,17 @@ impl Vmm {
|
||||
socket
|
||||
.write_all(&snapshot_data)
|
||||
.map_err(MigratableError::MigrateSocket)?;
|
||||
let res = Response::read_from(&mut socket)?;
|
||||
if res.status() != Status::Ok {
|
||||
warn!("Error during state migration");
|
||||
Request::abandon().write_to(&mut socket)?;
|
||||
Response::read_from(&mut socket).ok();
|
||||
return Err(MigratableError::MigrateSend(anyhow!(
|
||||
"Error during state migration"
|
||||
)));
|
||||
}
|
||||
|
||||
Response::read_from(&mut socket)?.ok_or_abandon(
|
||||
&mut socket,
|
||||
MigratableError::MigrateSend(anyhow!("Error during state migration")),
|
||||
)?;
|
||||
// Complete the migration
|
||||
Request::complete().write_to(&mut socket)?;
|
||||
let res = Response::read_from(&mut socket)?;
|
||||
if res.status() != Status::Ok {
|
||||
warn!("Error completing migration");
|
||||
Request::abandon().write_to(&mut socket)?;
|
||||
Response::read_from(&mut socket).ok();
|
||||
return Err(MigratableError::MigrateSend(anyhow!(
|
||||
"Error completing migration"
|
||||
)));
|
||||
}
|
||||
Response::read_from(&mut socket)?.ok_or_abandon(
|
||||
&mut socket,
|
||||
MigratableError::MigrateSend(anyhow!("Error completing migration")),
|
||||
)?;
|
||||
|
||||
info!("Migration complete");
|
||||
|
||||
// Let every Migratable object know about the migration being complete
|
||||
|
@ -93,7 +93,7 @@ use vm_memory::{Address, ByteValued, GuestMemoryRegion, ReadVolatile};
|
||||
use vm_memory::{
|
||||
Bytes, GuestAddress, GuestAddressSpace, GuestMemory, GuestMemoryAtomic, WriteVolatile,
|
||||
};
|
||||
use vm_migration::protocol::{Request, Response, Status};
|
||||
use vm_migration::protocol::{Request, Response};
|
||||
use vm_migration::{
|
||||
protocol::MemoryRangeTable, snapshot_from_id, Migratable, MigratableError, Pausable, Snapshot,
|
||||
Snapshottable, Transportable,
|
||||
@ -2241,15 +2241,10 @@ impl Vm {
|
||||
MigratableError::MigrateSend(anyhow!("Error sending memory fd: {}", e))
|
||||
})?;
|
||||
|
||||
let res = Response::read_from(socket)?;
|
||||
if res.status() != Status::Ok {
|
||||
warn!("Error during memory fd migration");
|
||||
Request::abandon().write_to(socket)?;
|
||||
Response::read_from(socket).ok();
|
||||
return Err(MigratableError::MigrateSend(anyhow!(
|
||||
"Error during memory fd migration"
|
||||
)));
|
||||
}
|
||||
Response::read_from(socket)?.ok_or_abandon(
|
||||
socket,
|
||||
MigratableError::MigrateSend(anyhow!("Error during memory fd migration")),
|
||||
)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
Loading…
Reference in New Issue
Block a user