Skip to content

Commit

Permalink
qga: Fail faster if guest panics
Browse files Browse the repository at this point in the history
Before, if guest panics, QgaWrapper still waits up to 60s/120s to return
a failure to the user. There's no need for that. Let's make it fail fast
by circuit breaking if qemu has already exited.

This closes #99.
  • Loading branch information
danobi committed Dec 3, 2024
1 parent acf1858 commit 04b7642
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/qemu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1063,7 +1063,7 @@ impl Qemu {
debug!("QMP info: {:#?}", qmp_info);

// Connect to QGA socket
let qga = QgaWrapper::new(&self.qga_sock, host_supports_kvm(&self.arch));
let qga = QgaWrapper::new(&self.qga_sock, host_supports_kvm(&self.arch), &mut child);
let qga = match qga {
Ok(q) => q,
Err(e) => {
Expand Down
10 changes: 9 additions & 1 deletion src/qga.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use std::os::unix::net::UnixStream;
use std::path::Path;
use std::process::Child;
use std::str::FromStr;
use std::thread;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -56,7 +57,8 @@ impl QgaWrapper {
///
/// `sock` is the path to the QGA socket.
/// `has_kvm` whether or not host supports KVM
pub fn new(sock: &Path, has_kvm: bool) -> Result<Self> {
/// `qemu` is the guest VM
pub fn new(sock: &Path, has_kvm: bool, qemu: &mut Child) -> Result<Self> {
let timeout = if has_kvm {
KVM_TIMEOUT
} else {
Expand All @@ -68,6 +70,12 @@ impl QgaWrapper {
let end = Instant::now() + timeout;
let mut i = 0;
while Instant::now() < end {
// Circuit break if guest already exited. This can happen if guest VM panics.
// A common example is guest kernel is not built with proper vmtest kconfig.
if let Ok(Some(_)) = qemu.try_wait() {
bail!("Qemu exited while trying to connect to QGA. Did the guest panic?");
}

info!("Connecting to QGA ({i})");
i += 1;
let qga_stream = match UnixStream::connect(sock) {
Expand Down

0 comments on commit 04b7642

Please sign in to comment.