@@ -1851,29 +1851,25 @@ fn attach_fs_devices(
1851
1851
Ok ( ( ) )
1852
1852
}
1853
1853
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 (
1855
1858
vmm : & mut Vmm ,
1856
- event_manager : & mut EventManager ,
1857
- intc : IrqChip ,
1858
1859
vm_resources : & VmResources ,
1859
1860
cfg : Option < & DefaultVirtioConsoleConfig > ,
1860
- id_number : u32 ,
1861
- ) -> std:: result:: Result < ( ) , StartMicrovmError > {
1861
+ creating_implicit_console : bool ,
1862
+ ) -> std:: result:: Result < Vec < PortDescription > , StartMicrovmError > {
1862
1863
use self :: StartMicrovmError :: * ;
1863
1864
1864
- let creating_implicit_console = cfg. is_none ( ) ;
1865
1865
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
1869
1866
if let Some ( path) = vm_resources. console_output . clone ( ) {
1870
- // only set the console output for the implicit console
1871
1867
if !vm_resources. disable_implicit_console && creating_implicit_console {
1872
1868
console_output_path = Some ( path)
1873
1869
}
1874
1870
}
1875
1871
1876
- let ports = if console_output_path. is_some ( ) {
1872
+ if console_output_path. is_some ( ) {
1877
1873
let file = File :: create ( console_output_path. unwrap ( ) ) . map_err ( OpenConsoleFile ) ?;
1878
1874
// Manually emulate our Legacy behavior: In the case of output_path we have always used the
1879
1875
// stdin to determine the console size
@@ -1883,11 +1879,11 @@ fn attach_console_devices(
1883
1879
} else {
1884
1880
port_io:: term_fixed_size ( 0 , 0 )
1885
1881
} ;
1886
- vec ! [ PortDescription :: console(
1882
+ Ok ( vec ! [ PortDescription :: console(
1887
1883
Some ( port_io:: input_empty( ) . unwrap( ) ) ,
1888
1884
Some ( port_io:: output_file( file) . unwrap( ) ) ,
1889
1885
term_fd,
1890
- ) ]
1886
+ ) ] )
1891
1887
} else {
1892
1888
let ( input_fd, output_fd, err_fd) = match cfg {
1893
1889
Some ( c) => ( c. input_fd , c. output_fd , c. err_fd ) ,
@@ -1982,8 +1978,23 @@ fn attach_console_devices(
1982
1978
) ) ;
1983
1979
}
1984
1980
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) ?;
1987
1998
1988
1999
let console = Arc :: new ( Mutex :: new ( devices:: virtio:: Console :: new ( ports) . unwrap ( ) ) ) ;
1989
2000
0 commit comments