mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Switch to using the serial_manager for serial input
This change switches from handling serial input in the VMM thread to its own thread controlled by the SerialManager. The motivation for this change is to avoid the VMM thread being unable to process events while serial input is happening and vice versa. The change also makes future work flushing the serial buffer on PTY connections easier. Signed-off-by: William Douglas <william.douglas@intel.com>
This commit is contained in:
committed by
Rob Bradford
parent
7b4f56e372
commit
46f6d9597d
+3
-50
@@ -14,16 +14,16 @@
|
||||
#[cfg(any(target_arch = "aarch64", feature = "acpi"))]
|
||||
use crate::config::NumaConfig;
|
||||
use crate::config::{
|
||||
ConsoleOutputMode, DeviceConfig, DiskConfig, FsConfig, HotplugMethod, NetConfig, PmemConfig,
|
||||
UserDeviceConfig, ValidationError, VmConfig, VsockConfig,
|
||||
DeviceConfig, DiskConfig, FsConfig, HotplugMethod, NetConfig, PmemConfig, UserDeviceConfig,
|
||||
ValidationError, VmConfig, VsockConfig,
|
||||
};
|
||||
use crate::cpu;
|
||||
use crate::device_manager::{self, Console, DeviceManager, DeviceManagerError, PtyPair};
|
||||
use crate::device_tree::DeviceTree;
|
||||
use crate::memory_manager::{Error as MemoryManagerError, MemoryManager};
|
||||
use crate::migration::{get_vm_snapshot, url_to_path, VM_SNAPSHOT_FILE};
|
||||
use crate::seccomp_filters::{get_seccomp_filter, Thread};
|
||||
use crate::GuestMemoryMmap;
|
||||
use crate::{cpu, EpollDispatch};
|
||||
use crate::{
|
||||
PciDeviceInfo, CPU_MANAGER_SNAPSHOT_ID, DEVICE_MANAGER_SNAPSHOT_ID, MEMORY_MANAGER_SNAPSHOT_ID,
|
||||
};
|
||||
@@ -1930,53 +1930,6 @@ impl Vm {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn handle_pty(&self, event: EpollDispatch) -> Result<()> {
|
||||
// Could be a little dangerous, picks up a lock on device_manager
|
||||
// and goes into a blocking read. If the epoll loops starts to be
|
||||
// services by multiple threads likely need to revist this.
|
||||
let dm = self.device_manager.lock().unwrap();
|
||||
|
||||
if matches!(event, EpollDispatch::SerialPty) {
|
||||
if let Some(mut pty) = dm.serial_pty() {
|
||||
let mut out = [0u8; 64];
|
||||
let count = pty.main.read(&mut out).map_err(Error::PtyConsole)?;
|
||||
let console = dm.console();
|
||||
console
|
||||
.queue_input_bytes_serial(&out[..count])
|
||||
.map_err(Error::Console)?;
|
||||
};
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn handle_stdin(&self) -> Result<()> {
|
||||
let mut out = [0u8; 64];
|
||||
let count = io::stdin()
|
||||
.lock()
|
||||
.read_raw(&mut out)
|
||||
.map_err(Error::Console)?;
|
||||
|
||||
// Replace "\n" with "\r" to deal with Windows SAC (#1170)
|
||||
if count == 1 && out[0] == 0x0a {
|
||||
out[0] = 0x0d;
|
||||
}
|
||||
|
||||
if matches!(
|
||||
self.config.lock().unwrap().serial.mode,
|
||||
ConsoleOutputMode::Tty
|
||||
) {
|
||||
self.device_manager
|
||||
.lock()
|
||||
.unwrap()
|
||||
.console()
|
||||
.queue_input_bytes_serial(&out[..count])
|
||||
.map_err(Error::Console)?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Gets a thread-safe reference counted pointer to the VM configuration.
|
||||
pub fn get_config(&self) -> Arc<Mutex<VmConfig>> {
|
||||
Arc::clone(&self.config)
|
||||
|
||||
Reference in New Issue
Block a user