mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Rename ConsoleOutput to ConsoleTransport
This is not just used for determine the output but also the input to the console where this can be bidirectional. Signed-off-by: Rob Bradford <rbradford@meta.com>
This commit is contained in:
@@ -56,7 +56,7 @@ pub enum ConsoleDeviceError {
|
||||
type ConsoleDeviceResult<T> = result::Result<T, ConsoleDeviceError>;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ConsoleOutput {
|
||||
pub enum ConsoleTransport {
|
||||
File(Arc<File>),
|
||||
Pty(Arc<File>),
|
||||
Tty(Arc<File>),
|
||||
@@ -67,10 +67,10 @@ pub enum ConsoleOutput {
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct ConsoleInfo {
|
||||
pub console_main_fd: ConsoleOutput,
|
||||
pub serial_main_fd: ConsoleOutput,
|
||||
pub console_main_fd: ConsoleTransport,
|
||||
pub serial_main_fd: ConsoleTransport,
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
pub debug_main_fd: ConsoleOutput,
|
||||
pub debug_main_fd: ConsoleTransport,
|
||||
}
|
||||
|
||||
fn modify_mode<F: FnOnce(&mut termios)>(
|
||||
@@ -185,7 +185,7 @@ pub(crate) fn pre_create_console_devices(vmm: &mut Vmm) -> ConsoleDeviceResult<C
|
||||
ConsoleOutputMode::File => {
|
||||
let file = File::create(vmconfig.console.file.as_ref().unwrap())
|
||||
.map_err(ConsoleDeviceError::CreateConsoleDevice)?;
|
||||
ConsoleOutput::File(Arc::new(file))
|
||||
ConsoleTransport::File(Arc::new(file))
|
||||
}
|
||||
ConsoleOutputMode::Pty => {
|
||||
let (main_fd, sub_fd, path) =
|
||||
@@ -200,7 +200,7 @@ pub(crate) fn pre_create_console_devices(vmm: &mut Vmm) -> ConsoleDeviceResult<C
|
||||
)
|
||||
.map_err(ConsoleDeviceError::StartSigwinchListener)?,
|
||||
));
|
||||
ConsoleOutput::Pty(Arc::new(main_fd))
|
||||
ConsoleTransport::Pty(Arc::new(main_fd))
|
||||
}
|
||||
ConsoleOutputMode::Tty => {
|
||||
// Duplicating the file descriptors like this is needed as otherwise
|
||||
@@ -222,26 +222,26 @@ pub(crate) fn pre_create_console_devices(vmm: &mut Vmm) -> ConsoleDeviceResult<C
|
||||
|
||||
// Make sure stdout is in raw mode, if it's a terminal.
|
||||
set_raw_mode(&stdout, &mut original_termios_opt)?;
|
||||
ConsoleOutput::Tty(Arc::new(stdout))
|
||||
ConsoleTransport::Tty(Arc::new(stdout))
|
||||
}
|
||||
ConsoleOutputMode::Socket => {
|
||||
return Err(ConsoleDeviceError::NoSocketOptionSupportForConsoleDevice);
|
||||
}
|
||||
ConsoleOutputMode::Null => ConsoleOutput::Null,
|
||||
ConsoleOutputMode::Off => ConsoleOutput::Off,
|
||||
ConsoleOutputMode::Null => ConsoleTransport::Null,
|
||||
ConsoleOutputMode::Off => ConsoleTransport::Off,
|
||||
},
|
||||
serial_main_fd: match vmconfig.serial.mode {
|
||||
ConsoleOutputMode::File => {
|
||||
let file = File::create(vmconfig.serial.file.as_ref().unwrap())
|
||||
.map_err(ConsoleDeviceError::CreateConsoleDevice)?;
|
||||
ConsoleOutput::File(Arc::new(file))
|
||||
ConsoleTransport::File(Arc::new(file))
|
||||
}
|
||||
ConsoleOutputMode::Pty => {
|
||||
let (main_fd, sub_fd, path) =
|
||||
create_pty().map_err(ConsoleDeviceError::CreateConsoleDevice)?;
|
||||
set_raw_mode(&sub_fd.as_raw_fd(), &mut original_termios_opt)?;
|
||||
vmconfig.serial.file = Some(path.clone());
|
||||
ConsoleOutput::Pty(Arc::new(main_fd))
|
||||
ConsoleTransport::Pty(Arc::new(main_fd))
|
||||
}
|
||||
ConsoleOutputMode::Tty => {
|
||||
// During vm_shutdown, when serial device is closed, FD#2(STDOUT)
|
||||
@@ -257,41 +257,41 @@ pub(crate) fn pre_create_console_devices(vmm: &mut Vmm) -> ConsoleDeviceResult<C
|
||||
// Make sure stdout is in raw mode, if it's a terminal.
|
||||
set_raw_mode(&stdout, &mut original_termios_opt)?;
|
||||
|
||||
ConsoleOutput::Tty(Arc::new(stdout))
|
||||
ConsoleTransport::Tty(Arc::new(stdout))
|
||||
}
|
||||
ConsoleOutputMode::Socket => {
|
||||
let listener = UnixListener::bind(vmconfig.serial.socket.as_ref().unwrap())
|
||||
.map_err(ConsoleDeviceError::CreateConsoleDevice)?;
|
||||
ConsoleOutput::Socket(Arc::new(listener))
|
||||
ConsoleTransport::Socket(Arc::new(listener))
|
||||
}
|
||||
ConsoleOutputMode::Null => ConsoleOutput::Null,
|
||||
ConsoleOutputMode::Off => ConsoleOutput::Off,
|
||||
ConsoleOutputMode::Null => ConsoleTransport::Null,
|
||||
ConsoleOutputMode::Off => ConsoleTransport::Off,
|
||||
},
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
debug_main_fd: match vmconfig.debug_console.mode {
|
||||
ConsoleOutputMode::File => {
|
||||
let file = File::create(vmconfig.debug_console.file.as_ref().unwrap())
|
||||
.map_err(ConsoleDeviceError::CreateConsoleDevice)?;
|
||||
ConsoleOutput::File(Arc::new(file))
|
||||
ConsoleTransport::File(Arc::new(file))
|
||||
}
|
||||
ConsoleOutputMode::Pty => {
|
||||
let (main_fd, sub_fd, path) =
|
||||
create_pty().map_err(ConsoleDeviceError::CreateConsoleDevice)?;
|
||||
set_raw_mode(&sub_fd.as_raw_fd(), &mut original_termios_opt)?;
|
||||
vmconfig.debug_console.file = Some(path.clone());
|
||||
ConsoleOutput::Pty(Arc::new(main_fd))
|
||||
ConsoleTransport::Pty(Arc::new(main_fd))
|
||||
}
|
||||
ConsoleOutputMode::Tty => {
|
||||
let out =
|
||||
dup_stdout().map_err(|e| ConsoleDeviceError::CreateConsoleDevice(e.into()))?;
|
||||
set_raw_mode(&out, &mut original_termios_opt)?;
|
||||
ConsoleOutput::Tty(Arc::new(out))
|
||||
ConsoleTransport::Tty(Arc::new(out))
|
||||
}
|
||||
ConsoleOutputMode::Socket => {
|
||||
return Err(ConsoleDeviceError::NoSocketOptionSupportForConsoleDevice);
|
||||
}
|
||||
ConsoleOutputMode::Null => ConsoleOutput::Null,
|
||||
ConsoleOutputMode::Off => ConsoleOutput::Off,
|
||||
ConsoleOutputMode::Null => ConsoleTransport::Null,
|
||||
ConsoleOutputMode::Off => ConsoleTransport::Off,
|
||||
},
|
||||
};
|
||||
|
||||
|
||||
@@ -116,7 +116,7 @@ use vm_migration::{
|
||||
use vm_virtio::{AccessPlatform, VirtioDeviceType};
|
||||
use vmm_sys_util::eventfd::EventFd;
|
||||
|
||||
use crate::console_devices::{ConsoleDeviceError, ConsoleInfo, ConsoleOutput};
|
||||
use crate::console_devices::{ConsoleDeviceError, ConsoleInfo, ConsoleTransport};
|
||||
use crate::cpu::{CPU_MANAGER_ACPI_SIZE, CpuManager};
|
||||
use crate::device_tree::{DeviceNode, DeviceTree};
|
||||
use crate::interrupt::{LegacyUserspaceInterruptManager, MsiInterruptManager};
|
||||
@@ -2334,17 +2334,17 @@ impl DeviceManager {
|
||||
|
||||
fn add_virtio_console_device(
|
||||
&mut self,
|
||||
console_fd: ConsoleOutput,
|
||||
console_fd: ConsoleTransport,
|
||||
resize_pipe: Option<Arc<File>>,
|
||||
) -> DeviceManagerResult<Option<Arc<virtio_devices::ConsoleResizer>>> {
|
||||
let console_config = self.config.lock().unwrap().console.clone();
|
||||
let endpoint = match console_fd {
|
||||
ConsoleOutput::File(file) => Endpoint::File(file),
|
||||
ConsoleOutput::Pty(file) => {
|
||||
ConsoleTransport::File(file) => Endpoint::File(file),
|
||||
ConsoleTransport::Pty(file) => {
|
||||
self.console_resize_pipe = resize_pipe;
|
||||
Endpoint::PtyPair(Arc::new(file.try_clone().unwrap()), file)
|
||||
}
|
||||
ConsoleOutput::Tty(stdout) => {
|
||||
ConsoleTransport::Tty(stdout) => {
|
||||
if stdout.is_terminal() {
|
||||
self.console_resize_pipe = resize_pipe;
|
||||
}
|
||||
@@ -2365,11 +2365,11 @@ impl DeviceManager {
|
||||
Endpoint::File(stdout)
|
||||
}
|
||||
}
|
||||
ConsoleOutput::Socket(_) => {
|
||||
ConsoleTransport::Socket(_) => {
|
||||
return Err(DeviceManagerError::NoSocketOptionSupportForConsoleDevice);
|
||||
}
|
||||
ConsoleOutput::Null => Endpoint::Null,
|
||||
ConsoleOutput::Off => return Ok(None),
|
||||
ConsoleTransport::Null => Endpoint::Null,
|
||||
ConsoleTransport::Off => return Ok(None),
|
||||
};
|
||||
let id = String::from(CONSOLE_DEVICE_NAME);
|
||||
|
||||
@@ -2434,19 +2434,21 @@ impl DeviceManager {
|
||||
let console_info = console_info.unwrap();
|
||||
|
||||
let serial_writer: Option<Box<dyn io::Write + Send>> = match console_info.serial_main_fd {
|
||||
ConsoleOutput::File(ref file) | ConsoleOutput::Tty(ref file) => {
|
||||
ConsoleTransport::File(ref file) | ConsoleTransport::Tty(ref file) => {
|
||||
Some(Box::new(Arc::clone(file)))
|
||||
}
|
||||
ConsoleOutput::Off
|
||||
| ConsoleOutput::Null
|
||||
| ConsoleOutput::Pty(_)
|
||||
| ConsoleOutput::Socket(_) => None,
|
||||
ConsoleTransport::Off
|
||||
| ConsoleTransport::Null
|
||||
| ConsoleTransport::Pty(_)
|
||||
| ConsoleTransport::Socket(_) => None,
|
||||
};
|
||||
|
||||
if !matches!(console_info.serial_main_fd, ConsoleOutput::Off) {
|
||||
if !matches!(console_info.serial_main_fd, ConsoleTransport::Off) {
|
||||
let serial = self.add_serial_device(interrupt_manager, serial_writer)?;
|
||||
self.serial_manager = match console_info.serial_main_fd {
|
||||
ConsoleOutput::Pty(_) | ConsoleOutput::Tty(_) | ConsoleOutput::Socket(_) => {
|
||||
ConsoleTransport::Pty(_)
|
||||
| ConsoleTransport::Tty(_)
|
||||
| ConsoleTransport::Socket(_) => {
|
||||
let serial_manager = SerialManager::new(
|
||||
serial,
|
||||
console_info.serial_main_fd,
|
||||
@@ -2472,14 +2474,15 @@ impl DeviceManager {
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
{
|
||||
let debug_console_writer: Option<Box<dyn io::Write + Send>> =
|
||||
match console_info.debug_main_fd {
|
||||
ConsoleOutput::File(file) | ConsoleOutput::Tty(file) => Some(Box::new(file)),
|
||||
ConsoleOutput::Off
|
||||
| ConsoleOutput::Null
|
||||
| ConsoleOutput::Pty(_)
|
||||
| ConsoleOutput::Socket(_) => None,
|
||||
};
|
||||
let debug_console_writer: Option<Box<dyn io::Write + Send>> = match console_info
|
||||
.debug_main_fd
|
||||
{
|
||||
ConsoleTransport::File(file) | ConsoleTransport::Tty(file) => Some(Box::new(file)),
|
||||
ConsoleTransport::Off
|
||||
| ConsoleTransport::Null
|
||||
| ConsoleTransport::Pty(_)
|
||||
| ConsoleTransport::Socket(_) => None,
|
||||
};
|
||||
if let Some(writer) = debug_console_writer {
|
||||
let _ = self.add_debug_console_device(writer)?;
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ use serial_buffer::SerialBuffer;
|
||||
use thiserror::Error;
|
||||
use vmm_sys_util::eventfd::EventFd;
|
||||
|
||||
use crate::console_devices::ConsoleOutput;
|
||||
use crate::console_devices::ConsoleTransport;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum Error {
|
||||
@@ -114,7 +114,7 @@ pub struct SerialManager {
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
serial: Arc<Mutex<Pl011>>,
|
||||
epoll_file: File,
|
||||
in_file: ConsoleOutput,
|
||||
in_file: ConsoleTransport,
|
||||
kill_evt: EventFd,
|
||||
handle: Option<thread::JoinHandle<()>>,
|
||||
pty_write_out: Option<Arc<AtomicBool>>,
|
||||
@@ -125,14 +125,14 @@ impl SerialManager {
|
||||
pub fn new(
|
||||
#[cfg(any(target_arch = "x86_64", target_arch = "riscv64"))] serial: Arc<Mutex<Serial>>,
|
||||
#[cfg(target_arch = "aarch64")] serial: Arc<Mutex<Pl011>>,
|
||||
mut output: ConsoleOutput,
|
||||
mut output: ConsoleTransport,
|
||||
socket: Option<PathBuf>,
|
||||
) -> Result<Option<Self>> {
|
||||
let mut socket_path: Option<PathBuf> = None;
|
||||
|
||||
let in_fd = match output {
|
||||
ConsoleOutput::Pty(ref fd) => fd.as_raw_fd(),
|
||||
ConsoleOutput::Tty(_)
|
||||
ConsoleTransport::Pty(ref fd) => fd.as_raw_fd(),
|
||||
ConsoleTransport::Tty(_)
|
||||
// If running on an interactive TTY then accept input
|
||||
// SAFETY: trivially safe
|
||||
if unsafe { libc::isatty(libc::STDIN_FILENO) == 1 } =>
|
||||
@@ -155,13 +155,13 @@ impl SerialManager {
|
||||
return Err(Error::SetNonBlocking(std::io::Error::last_os_error()));
|
||||
}
|
||||
|
||||
output = ConsoleOutput::Tty(Arc::new(stdin_clone));
|
||||
output = ConsoleTransport::Tty(Arc::new(stdin_clone));
|
||||
fd
|
||||
}
|
||||
ConsoleOutput::Tty(_) => {
|
||||
ConsoleTransport::Tty(_) => {
|
||||
return Ok(None);
|
||||
}
|
||||
ConsoleOutput::Socket(ref listener) => {
|
||||
ConsoleTransport::Socket(ref listener) => {
|
||||
if let Some(path_in_socket) = socket {
|
||||
socket_path = Some(path_in_socket.clone());
|
||||
}
|
||||
@@ -181,7 +181,7 @@ impl SerialManager {
|
||||
)
|
||||
.map_err(Error::Epoll)?;
|
||||
|
||||
let epoll_fd_data = if let ConsoleOutput::Socket(_) = output {
|
||||
let epoll_fd_data = if let ConsoleTransport::Socket(_) = output {
|
||||
EpollDispatch::Socket
|
||||
} else {
|
||||
EpollDispatch::File
|
||||
@@ -196,7 +196,7 @@ impl SerialManager {
|
||||
.map_err(Error::Epoll)?;
|
||||
|
||||
let mut pty_write_out = None;
|
||||
if let ConsoleOutput::Pty(ref file) = output {
|
||||
if let ConsoleTransport::Pty(ref file) = output {
|
||||
let write_out = Arc::new(AtomicBool::new(false));
|
||||
pty_write_out = Some(write_out.clone());
|
||||
let writer = file.try_clone().map_err(Error::FileClone)?;
|
||||
@@ -295,7 +295,7 @@ impl SerialManager {
|
||||
}
|
||||
};
|
||||
|
||||
if matches!(in_file, ConsoleOutput::Pty(_)) && num_events == 0 {
|
||||
if matches!(in_file, ConsoleTransport::Pty(_)) && num_events == 0 {
|
||||
// This very specific case happens when the serial is connected
|
||||
// to a PTY. We know EPOLLHUP is always present when there's nothing
|
||||
// connected at the other end of the PTY. That's why getting no event
|
||||
@@ -320,7 +320,7 @@ impl SerialManager {
|
||||
.map_err(Error::AcceptConnection)?;
|
||||
}
|
||||
|
||||
let ConsoleOutput::Socket(ref listener) = in_file else {
|
||||
let ConsoleTransport::Socket(ref listener) = in_file else {
|
||||
unreachable!();
|
||||
};
|
||||
|
||||
@@ -349,7 +349,7 @@ impl SerialManager {
|
||||
if event.events & libc::EPOLLIN as u32 != 0 {
|
||||
let mut input = [0u8; 64];
|
||||
let count = match &in_file {
|
||||
ConsoleOutput::Socket(_) => {
|
||||
ConsoleTransport::Socket(_) => {
|
||||
if let Some(mut serial_reader) = reader.as_ref() {
|
||||
let count = serial_reader
|
||||
.read(&mut input)
|
||||
@@ -371,11 +371,10 @@ impl SerialManager {
|
||||
0
|
||||
}
|
||||
}
|
||||
ConsoleOutput::Pty(file) | ConsoleOutput::Tty(file) => {
|
||||
(&**file)
|
||||
.read(&mut input)
|
||||
.map_err(Error::ReadInput)?
|
||||
}
|
||||
ConsoleTransport::Pty(file)
|
||||
| ConsoleTransport::Tty(file) => (&**file)
|
||||
.read(&mut input)
|
||||
.map_err(Error::ReadInput)?,
|
||||
_ => unreachable!(),
|
||||
};
|
||||
|
||||
@@ -432,7 +431,7 @@ impl Drop for SerialManager {
|
||||
if let Some(handle) = self.handle.take() {
|
||||
handle.join().ok();
|
||||
}
|
||||
if let ConsoleOutput::Socket(_) = self.in_file
|
||||
if let ConsoleTransport::Socket(_) = self.in_file
|
||||
&& let Some(socket_path) = self.socket_path.as_ref()
|
||||
{
|
||||
std::fs::remove_file(socket_path.as_os_str())
|
||||
|
||||
Reference in New Issue
Block a user