Skip to content

Commit f9f9159

Browse files
committed
vmm: Refactor console port autoconfiguration into separate function
Signed-off-by: Matej Hrica <[email protected]>
1 parent a5d1f47 commit f9f9159

File tree

2 files changed

+26
-15
lines changed

2 files changed

+26
-15
lines changed

examples/external_kernel

27.4 KB
Binary file not shown.

src/vmm/src/builder.rs

Lines changed: 26 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1851,29 +1851,25 @@ fn attach_fs_devices(
18511851
Ok(())
18521852
}
18531853

1854-
fn attach_console_devices(
1854+
/// Creates ports for autoconfigured console based on file descriptors and console output path.
1855+
/// Returns the configured ports and optional terminal restore closure that needs to be
1856+
/// registered as an exit observer.
1857+
fn autoconfigure_console_ports(
18551858
vmm: &mut Vmm,
1856-
event_manager: &mut EventManager,
1857-
intc: IrqChip,
18581859
vm_resources: &VmResources,
18591860
cfg: Option<&DefaultVirtioConsoleConfig>,
1860-
id_number: u32,
1861-
) -> std::result::Result<(), StartMicrovmError> {
1861+
creating_implicit_console: bool,
1862+
) -> std::result::Result<Vec<PortDescription>, StartMicrovmError> {
18621863
use self::StartMicrovmError::*;
18631864

1864-
let creating_implicit_console = cfg.is_none();
18651865
let mut console_output_path: Option<PathBuf> = None;
1866-
1867-
// we don't care about the console output that was set for the vm_resources
1868-
// if the implicit console is disabled
18691866
if let Some(path) = vm_resources.console_output.clone() {
1870-
// only set the console output for the implicit console
18711867
if !vm_resources.disable_implicit_console && creating_implicit_console {
18721868
console_output_path = Some(path)
18731869
}
18741870
}
18751871

1876-
let ports = if console_output_path.is_some() {
1872+
if console_output_path.is_some() {
18771873
let file = File::create(console_output_path.unwrap()).map_err(OpenConsoleFile)?;
18781874
// Manually emulate our Legacy behavior: In the case of output_path we have always used the
18791875
// stdin to determine the console size
@@ -1883,11 +1879,11 @@ fn attach_console_devices(
18831879
} else {
18841880
port_io::term_fixed_size(0, 0)
18851881
};
1886-
vec![PortDescription::console(
1882+
Ok(vec![PortDescription::console(
18871883
Some(port_io::input_empty().unwrap()),
18881884
Some(port_io::output_file(file).unwrap()),
18891885
term_fd,
1890-
)]
1886+
)])
18911887
} else {
18921888
let (input_fd, output_fd, err_fd) = match cfg {
18931889
Some(c) => (c.input_fd, c.output_fd, c.err_fd),
@@ -1982,8 +1978,23 @@ fn attach_console_devices(
19821978
));
19831979
}
19841980

1985-
ports
1986-
};
1981+
Ok(ports)
1982+
}
1983+
}
1984+
1985+
fn attach_console_devices(
1986+
vmm: &mut Vmm,
1987+
event_manager: &mut EventManager,
1988+
intc: IrqChip,
1989+
vm_resources: &VmResources,
1990+
cfg: Option<&DefaultVirtioConsoleConfig>,
1991+
id_number: u32,
1992+
) -> std::result::Result<(), StartMicrovmError> {
1993+
use self::StartMicrovmError::*;
1994+
1995+
let creating_implicit_console = cfg.is_none();
1996+
1997+
let ports = autoconfigure_console_ports(vmm, vm_resources, cfg, creating_implicit_console)?;
19871998

19881999
let console = Arc::new(Mutex::new(devices::virtio::Console::new(ports).unwrap()));
19892000

0 commit comments

Comments
 (0)