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 <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2021-09-08 15:12:36 +01:00 committed by Bo Chen
parent 951ad3495e
commit 387753ae1d
3 changed files with 35 additions and 70 deletions

View File

@ -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")]

View File

@ -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<Arc<Mutex<Pl011>>>,
console_resizer: Option<Arc<virtio_devices::ConsoleResizer>>,
input: Option<ConsoleInput>,
}
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<PtyPair>,
console_pty: Option<PtyPair>,
) -> DeviceManagerResult<Arc<Console>> {
let console_config = self.config.lock().unwrap().console.clone();
let serial_config = self.config.lock().unwrap().serial.clone();
let serial_writer: Option<Box<dyn io::Write + Send>> = 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,
}))
}

View File

@ -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)?;
};
}