From 387753ae1ddf7233ec4a026d982bbc7135c3dcda Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 8 Sep 2021 15:12:36 +0100 Subject: [PATCH] vmm: Remove concept of "input_enabled" This concept ends up being broken with multiple types on input connected e.g. console on TTY and serial on PTY. Already the code for checking for injecting into the serial device checks that the serial is configured. Signed-off-by: Rob Bradford --- vmm/src/config.rs | 6 --- vmm/src/device_manager.rs | 19 ---------- vmm/src/vm.rs | 80 +++++++++++++++++---------------------- 3 files changed, 35 insertions(+), 70 deletions(-) diff --git a/vmm/src/config.rs b/vmm/src/config.rs index 93e10b4ed..97c7dd6c4 100644 --- a/vmm/src/config.rs +++ b/vmm/src/config.rs @@ -1452,12 +1452,6 @@ pub enum ConsoleOutputMode { Null, } -impl ConsoleOutputMode { - pub fn input_enabled(&self) -> bool { - matches!(self, ConsoleOutputMode::Tty | ConsoleOutputMode::Pty) - } -} - #[derive(Clone, Debug, PartialEq, Deserialize, Serialize)] pub struct ConsoleConfig { #[serde(default = "default_consoleconfig_file")] diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index e5510c85c..7296e6bdc 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -520,10 +520,6 @@ pub fn create_pty(non_blocking: bool) -> io::Result<(File, File, PathBuf)> { Ok((main, unsafe { File::from_raw_fd(sub_fd) }, path)) } -enum ConsoleInput { - Serial, - VirtioConsole, -} #[derive(Default)] pub struct Console { #[cfg(target_arch = "x86_64")] @@ -532,7 +528,6 @@ pub struct Console { #[cfg(target_arch = "aarch64")] serial: Option>>, console_resizer: Option>, - input: Option, } impl Console { @@ -553,10 +548,6 @@ impl Console { resizer.update_console_size(cols, rows) } } - - pub fn input_enabled(&self) -> bool { - self.input.is_some() - } } struct AddressManager { @@ -1770,7 +1761,6 @@ impl DeviceManager { serial_pty: Option, console_pty: Option, ) -> DeviceManagerResult> { - let console_config = self.config.lock().unwrap().console.clone(); let serial_config = self.config.lock().unwrap().serial.clone(); let serial_writer: Option> = match serial_config.mode { ConsoleOutputMode::File => Some(Box::new( @@ -1807,17 +1797,8 @@ impl DeviceManager { let console_resizer = self.add_virtio_console_device(virtio_devices, console_pty)?; - let input = if serial_config.mode.input_enabled() { - Some(ConsoleInput::Serial) - } else if console_config.mode.input_enabled() { - Some(ConsoleInput::VirtioConsole) - } else { - None - }; - Ok(Arc::new(Console { serial, - input, console_resizer, })) } diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index 58e5bb29a..e4e690bce 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -1801,50 +1801,42 @@ impl Vm { } fn setup_interactive(&mut self) -> Result<()> { - if self - .device_manager - .lock() - .unwrap() - .console() - .input_enabled() - { - let console = self.device_manager.lock().unwrap().console().clone(); - let signals = Signals::new(&HANDLED_SIGNALS); - match signals { - Ok(signals) => { - self.signals = Some(signals.handle()); - let exit_evt = self.exit_evt.try_clone().map_err(Error::EventFdClone)?; - let on_tty = self.on_tty; - let signal_handler_seccomp_filter = - get_seccomp_filter(&self.seccomp_action, Thread::SignalHandler) - .map_err(Error::CreateSeccompFilter)?; - self.threads.push( - thread::Builder::new() - .name("signal_handler".to_string()) - .spawn(move || { - if !signal_handler_seccomp_filter.is_empty() { - if let Err(e) = apply_filter(&signal_handler_seccomp_filter) - .map_err(Error::ApplySeccompFilter) - { - error!("Error applying seccomp filter: {:?}", e); - return; - } + let console = self.device_manager.lock().unwrap().console().clone(); + let signals = Signals::new(&HANDLED_SIGNALS); + match signals { + Ok(signals) => { + self.signals = Some(signals.handle()); + let exit_evt = self.exit_evt.try_clone().map_err(Error::EventFdClone)?; + let on_tty = self.on_tty; + let signal_handler_seccomp_filter = + get_seccomp_filter(&self.seccomp_action, Thread::SignalHandler) + .map_err(Error::CreateSeccompFilter)?; + self.threads.push( + thread::Builder::new() + .name("signal_handler".to_string()) + .spawn(move || { + if !signal_handler_seccomp_filter.is_empty() { + if let Err(e) = apply_filter(&signal_handler_seccomp_filter) + .map_err(Error::ApplySeccompFilter) + { + error!("Error applying seccomp filter: {:?}", e); + return; } + } - Vm::os_signal_handler(signals, console, on_tty, exit_evt); - }) - .map_err(Error::SignalHandlerSpawn)?, - ); - } - Err(e) => error!("Signal not found {}", e), + Vm::os_signal_handler(signals, console, on_tty, exit_evt); + }) + .map_err(Error::SignalHandlerSpawn)?, + ); } + Err(e) => error!("Signal not found {}", e), + } - if self.on_tty { - io::stdin() - .lock() - .set_raw_mode() - .map_err(Error::SetTerminalRaw)?; - } + if self.on_tty { + io::stdin() + .lock() + .set_raw_mode() + .map_err(Error::SetTerminalRaw)?; } Ok(()) @@ -1935,11 +1927,9 @@ impl Vm { let mut out = [0u8; 64]; let count = pty.main.read(&mut out).map_err(Error::PtyConsole)?; let console = dm.console(); - if console.input_enabled() { - console - .queue_input_bytes_serial(&out[..count]) - .map_err(Error::Console)?; - } + console + .queue_input_bytes_serial(&out[..count]) + .map_err(Error::Console)?; }; }