From f6143a54899626fd373a37ead43fd7bf138691a2 Mon Sep 17 00:00:00 2001 From: Changyuan Lyu Date: Sun, 12 Jan 2025 22:24:03 -0800 Subject: [PATCH] fix(vm): only report the root failure Signed-off-by: Changyuan Lyu --- alioth-cli/src/main.rs | 4 +--- alioth/src/board/board.rs | 19 +++++++++++-------- alioth/src/vm.rs | 24 ++++++++++++------------ 3 files changed, 24 insertions(+), 23 deletions(-) diff --git a/alioth-cli/src/main.rs b/alioth-cli/src/main.rs index a14e589..76e36d0 100644 --- a/alioth-cli/src/main.rs +++ b/alioth-cli/src/main.rs @@ -488,9 +488,7 @@ fn main_run(args: RunArgs) -> Result<(), Error> { } vm.boot().context(error::BootVm)?; - for result in vm.wait() { - result.context(error::WaitVm)?; - } + vm.wait().context(error::WaitVm)?; Ok(()) } diff --git a/alioth/src/board/board.rs b/alioth/src/board/board.rs index 6941979..44e7e6f 100644 --- a/alioth/src/board/board.rs +++ b/alioth/src/board/board.rs @@ -401,15 +401,18 @@ where let mut vcpu = self.create_vcpu(id, &event_tx)?; let ret = self.run_vcpu_inner(id, &mut vcpu, &boot_rx); - if ret.is_err() && !matches!(ret, Err(Error::PeerFailure { .. })) { - log::warn!("VCPU-{id} reported error, unblocking other VCPUs..."); - let mut mp_sync = self.mp_sync.lock(); - mp_sync.fatal = true; - if mp_sync.count > 0 { - self.cond_var.notify_all(); - } - } event_tx.send(id).unwrap(); + + if matches!(ret, Ok(_) | Err(Error::PeerFailure { .. })) { + return Ok(()); + } + + log::warn!("VCPU-{id} reported error, unblocking other VCPUs..."); + let mut mp_sync = self.mp_sync.lock(); + mp_sync.fatal = true; + if mp_sync.count > 0 { + self.cond_var.notify_all(); + } ret } diff --git a/alioth/src/vm.rs b/alioth/src/vm.rs index cff20c8..d2d6df7 100644 --- a/alioth/src/vm.rs +++ b/alioth/src/vm.rs @@ -273,7 +273,7 @@ where Ok(()) } - pub fn wait(&self) -> Vec> { + pub fn wait(&self) -> Result<()> { self.event_rx.recv().unwrap(); let vcpus = self.board.vcpus.read(); for _ in 1..vcpus.len() { @@ -281,17 +281,17 @@ where } drop(vcpus); let mut vcpus = self.board.vcpus.write(); - vcpus - .drain(..) - .enumerate() - .map(|(id, (handle, _))| match handle.join() { - Err(e) => { - log::error!("cannot join vcpu {}: {:?}", id, e); - Ok(()) - } - Ok(r) => r.context(error::Vcpu { id: id as u32 }), - }) - .collect() + let mut ret = Ok(()); + for (id, (handle, _)) in vcpus.drain(..).enumerate() { + let Ok(r) = handle.join() else { + log::error!("Cannot join VCPU-{id}"); + continue; + }; + if r.is_err() && ret.is_ok() { + ret = r.context(error::Vcpu { id: id as u32 }); + } + } + ret } }