Skip to content

Commit

Permalink
fix(vm): only report the root failure
Browse files Browse the repository at this point in the history
Signed-off-by: Changyuan Lyu <[email protected]>
  • Loading branch information
Lencerf committed Jan 13, 2025
1 parent 545ff34 commit f6143a5
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 23 deletions.
4 changes: 1 addition & 3 deletions alioth-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

Expand Down
19 changes: 11 additions & 8 deletions alioth/src/board/board.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
24 changes: 12 additions & 12 deletions alioth/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -273,25 +273,25 @@ where
Ok(())
}

pub fn wait(&self) -> Vec<Result<()>> {
pub fn wait(&self) -> Result<()> {
self.event_rx.recv().unwrap();
let vcpus = self.board.vcpus.read();
for _ in 1..vcpus.len() {
self.event_rx.recv().unwrap();
}
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
}
}

Expand Down

0 comments on commit f6143a5

Please sign in to comment.