diff --git a/vm-migration/src/protocol.rs b/vm-migration/src/protocol.rs index ae6836d98..fac7c5cc5 100644 --- a/vm-migration/src/protocol.rs +++ b/vm-migration/src/protocol.rs @@ -362,17 +362,9 @@ impl Response { }) } - pub fn ok_or_abandon( - self, - fd: &mut T, - error: MigratableError, - ) -> Result - where - T: Read + Write, - { + /// Return the response if its status is `Ok`; return the caller-provided error for any other status. + pub fn ok_or_error(self, error: MigratableError) -> Result { if self.status != Status::Ok { - Request::abandon().write_to(fd)?; - Response::read_from(fd)?; return Err(error); } Ok(self) diff --git a/vmm/src/migration/transport.rs b/vmm/src/migration/transport.rs index f5f490b29..cadec0a46 100644 --- a/vmm/src/migration/transport.rs +++ b/vmm/src/migration/transport.rs @@ -1115,9 +1115,7 @@ pub(crate) fn expect_ok_response( socket: &mut SocketStream, error: MigratableError, ) -> Result<(), MigratableError> { - Response::read_from(socket)? - .ok_or_abandon(socket, error) - .map(|_| ()) + Response::read_from(socket)?.ok_or_error(error).map(|_| ()) } /// Send a request and validate that the peer responds with OK. diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 71b9363cf..ba60357fe 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -3026,10 +3026,9 @@ impl Vm { .context("Error sending memory fd") .map_err(MigratableError::MigrateSend)?; - Response::read_from(socket)?.ok_or_abandon( - socket, - MigratableError::MigrateSend(anyhow!("Error during memory fd migration")), - )?; + Response::read_from(socket)?.ok_or_error(MigratableError::MigrateSend(anyhow!( + "Error during memory fd migration" + )))?; } Ok(())