Merge pull request #11781 from lifupan/fupan_main_qemu

runtime-rs: log out the qemu console when debug enabled
This commit is contained in:
Alex Lyn
2025-09-10 16:59:30 +08:00
committed by GitHub
2 changed files with 32 additions and 1 deletions

View File

@@ -2410,6 +2410,10 @@ impl<'a> QemuCmdLine<'a> {
console_socket_chardev.set_server(true);
console_socket_chardev.set_wait(false);
self.devices.push(Box::new(console_socket_chardev));
self.kernel
.params
.append(&mut KernelParams::from_string("console=hvc0"));
}
pub fn add_virtio_balloon(&mut self) {

View File

@@ -25,11 +25,14 @@ use std::cmp::Ordering;
use std::convert::TryInto;
use std::path::Path;
use std::process::Stdio;
use tokio::sync::{mpsc, Mutex};
use tokio::{
io::{AsyncBufReadExt, BufReader},
process::{Child, ChildStderr, Command},
};
use tokio::{
net::UnixStream,
sync::{mpsc, Mutex},
};
const VSOCK_SCHEME: &str = "vsock";
@@ -223,6 +226,12 @@ impl QemuInner {
}
}
//When hypervisor debug is enabled, output the kernel boot messages for debugging.
if self.config.debug_info.enable_debug {
let stream = UnixStream::connect(console_socket_path.as_os_str()).await?;
tokio::spawn(log_qemu_console(stream));
}
Ok(())
}
@@ -569,6 +578,24 @@ impl QemuInner {
}
}
async fn log_qemu_console(console: UnixStream) -> Result<()> {
info!(sl!(), "starting reading qemu console");
let stderr_reader = BufReader::new(console);
let mut stderr_lines = stderr_reader.lines();
while let Some(buffer) = stderr_lines
.next_line()
.await
.context("next_line() failed on qemu console")?
{
info!(sl!(), "vm console: {:?}", buffer);
}
info!(sl!(), "finished reading qemu console");
Ok(())
}
async fn log_qemu_stderr(stderr: ChildStderr, exit_notify: mpsc::Sender<()>) -> Result<()> {
info!(sl!(), "starting reading qemu stderr");