From 6233f6f68eb9b21b75f363db9ca8fe8bdaf1b7aa Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Wed, 25 Aug 2021 09:14:42 +0100 Subject: [PATCH] vmm: Send tty input to correct destination Check the config to find out which device is attached to the tty and then send the input from the user into that device (serial or virtio-console.) Fixes: #3005 Signed-off-by: Rob Bradford --- vmm/src/device_manager.rs | 15 --------------- vmm/src/vm.rs | 26 ++++++++++++++++---------- 2 files changed, 16 insertions(+), 25 deletions(-) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 99e803dc1..1c09042fd 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -535,21 +535,6 @@ pub struct Console { } impl Console { - pub fn queue_input_bytes(&self, out: &[u8]) -> vmm_sys_util::errno::Result<()> { - match self.input { - Some(ConsoleInput::Serial) => { - self.queue_input_bytes_serial(out)?; - } - - Some(ConsoleInput::VirtioConsole) => { - self.queue_input_bytes_console(out); - } - None => {} - } - - Ok(()) - } - pub fn queue_input_bytes_serial(&self, out: &[u8]) -> vmm_sys_util::errno::Result<()> { if self.serial.is_some() { self.serial diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index b2d274ba4..6f168943a 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -14,8 +14,8 @@ #[cfg(any(target_arch = "aarch64", feature = "acpi"))] use crate::config::NumaConfig; use crate::config::{ - DeviceConfig, DiskConfig, FsConfig, HotplugMethod, NetConfig, PmemConfig, UserDeviceConfig, - ValidationError, VmConfig, VsockConfig, + ConsoleOutputMode, DeviceConfig, DiskConfig, FsConfig, HotplugMethod, NetConfig, PmemConfig, + UserDeviceConfig, ValidationError, VmConfig, VsockConfig, }; use crate::cpu; use crate::device_manager::{ @@ -1950,19 +1950,25 @@ impl Vm { out[0] = 0x0d; } - if self - .device_manager - .lock() - .unwrap() - .console() - .input_enabled() - { + if matches!( + self.config.lock().unwrap().serial.mode, + ConsoleOutputMode::Tty + ) { self.device_manager .lock() .unwrap() .console() - .queue_input_bytes(&out[..count]) + .queue_input_bytes_serial(&out[..count]) .map_err(Error::Console)?; + } else if matches!( + self.config.lock().unwrap().console.mode, + ConsoleOutputMode::Tty + ) { + self.device_manager + .lock() + .unwrap() + .console() + .queue_input_bytes_console(&out[..count]) } Ok(())