mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Make serial port controllable via command line
Add a "--serial" command line that takes as input either "off", "tty" (default and current behaviour) and "file=/path/to/file". When "--serial off" is used the serial device is not added to the VM configuration at all. Integration tests added that check for interrupts present (or not) and that when sending to a file the file contains the expected serial output. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
@@ -50,6 +50,8 @@ pub enum Error<'a> {
|
||||
ParsePmemFileParam,
|
||||
/// Failed parsing size parameter.
|
||||
ParseSizeParam(std::num::ParseIntError),
|
||||
/// Failed parsing serial parameter.
|
||||
ParseSerialParam,
|
||||
}
|
||||
pub type Result<'a, T> = result::Result<T, Error<'a>>;
|
||||
|
||||
@@ -63,6 +65,7 @@ pub struct VmParams<'a> {
|
||||
pub rng: &'a str,
|
||||
pub fs: Option<Vec<&'a str>>,
|
||||
pub pmem: Option<Vec<&'a str>>,
|
||||
pub serial: &'a str,
|
||||
}
|
||||
|
||||
fn parse_size(size: &str) -> Result<u64> {
|
||||
@@ -338,6 +341,41 @@ impl<'a> PmemConfig<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(PartialEq)]
|
||||
pub enum SerialOutputMode {
|
||||
Off,
|
||||
Tty,
|
||||
File,
|
||||
}
|
||||
|
||||
pub struct SerialConfig<'a> {
|
||||
pub file: Option<&'a Path>,
|
||||
pub mode: SerialOutputMode,
|
||||
}
|
||||
|
||||
impl<'a> SerialConfig<'a> {
|
||||
pub fn parse(param: &'a str) -> Result<Self> {
|
||||
if param == "off" {
|
||||
Ok(Self {
|
||||
mode: SerialOutputMode::Off,
|
||||
file: None,
|
||||
})
|
||||
} else if param == "tty" {
|
||||
Ok(Self {
|
||||
mode: SerialOutputMode::Tty,
|
||||
file: None,
|
||||
})
|
||||
} else if param.starts_with("file=") {
|
||||
Ok(Self {
|
||||
mode: SerialOutputMode::File,
|
||||
file: Some(Path::new(¶m[5..])),
|
||||
})
|
||||
} else {
|
||||
Err(Error::ParseSerialParam)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct VmConfig<'a> {
|
||||
pub cpus: CpusConfig,
|
||||
pub memory: MemoryConfig<'a>,
|
||||
@@ -348,6 +386,7 @@ pub struct VmConfig<'a> {
|
||||
pub rng: RngConfig<'a>,
|
||||
pub fs: Option<Vec<FsConfig<'a>>>,
|
||||
pub pmem: Option<Vec<PmemConfig<'a>>>,
|
||||
pub serial: SerialConfig<'a>,
|
||||
}
|
||||
|
||||
impl<'a> VmConfig<'a> {
|
||||
@@ -398,6 +437,7 @@ impl<'a> VmConfig<'a> {
|
||||
rng: RngConfig::parse(vm_params.rng)?,
|
||||
fs,
|
||||
pmem,
|
||||
serial: SerialConfig::parse(vm_params.serial)?,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user