mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-11-09 13:20:00 +00:00
vm-migration: Introduce Response::ok_or_abandon()
This method will return the existing Response if the status is successful (Status::Ok) otherwise issue a command to abandon the migration and return the desired error. Signed-off-by: Rob Bradford <rbradford@rivosinc.com>
This commit is contained in:
parent
3103526153
commit
e97cee99ef
@ -190,6 +190,22 @@ impl Response {
|
||||
Ok(response)
|
||||
}
|
||||
|
||||
pub fn ok_or_abandon<T>(
|
||||
self,
|
||||
fd: &mut T,
|
||||
error: MigratableError,
|
||||
) -> Result<Response, MigratableError>
|
||||
where
|
||||
T: Read + Write,
|
||||
{
|
||||
if self.status != Status::Ok {
|
||||
Request::abandon().write_to(fd)?;
|
||||
Response::read_from(fd)?;
|
||||
return Err(error);
|
||||
}
|
||||
Ok(self)
|
||||
}
|
||||
|
||||
pub fn write_to(&self, fd: &mut dyn Write) -> Result<(), MigratableError> {
|
||||
fd.write_all(Self::as_slice(self))
|
||||
.map_err(MigratableError::MigrateSocket)
|
||||
|
Loading…
Reference in New Issue
Block a user