From 4bfeba967b3a00b144d6f302c8b7d023b6a9c1ff Mon Sep 17 00:00:00 2001 From: Alyssa Ross Date: Thu, 29 Aug 2024 20:50:16 +0200 Subject: [PATCH] vmm: fix console resizing DeviceManager::add_virtio_console_device used to create the console resize pipe and assign it to self.console_resize_pipe, but when this was changed to use console_info, that was deleted without replacement. This meant that, even though the console resize pipe was created by pre_create_console_devices, the DeviceManager never found out about it, so console resize didn't work (at least for pty consoles). To fix this, the console resize pipe needs to be passed to the Vm initializer, which is already supported, it was just previously not used for new VMs. Since DeviceManager already stores the console resize pipe in an Arc, and Vmm also needs a copy of it, the sensible thing to do is change DeviceManager::new to take Arc, and then we don't need to dup the file descriptor, which could fail. Fixes: 52eebaf6 ("vmm: refactor DeviceManager to use console_info") Signed-off-by: Alyssa Ross --- vmm/src/console_devices.rs | 12 ++++++------ vmm/src/device_manager.rs | 8 ++++---- vmm/src/lib.rs | 13 +++++-------- vmm/src/vm.rs | 4 ++-- 4 files changed, 17 insertions(+), 20 deletions(-) diff --git a/vmm/src/console_devices.rs b/vmm/src/console_devices.rs index e48dc311e..cdadf1e95 100644 --- a/vmm/src/console_devices.rs +++ b/vmm/src/console_devices.rs @@ -183,14 +183,14 @@ pub(crate) fn pre_create_console_devices(vmm: &mut Vmm) -> ConsoleDeviceResult { // Duplicating the file descriptors like this is needed as otherwise @@ -206,14 +206,14 @@ pub(crate) fn pre_create_console_devices(vmm: &mut Vmm) -> ConsoleDeviceResult ConsoleDeviceResult, - console_resize_pipe: Option, + console_resize_pipe: Option>, original_termios_opt: Arc>>, ) -> DeviceManagerResult<()> { trace_scoped!("create_devices"); @@ -2006,7 +2006,7 @@ impl DeviceManager { &mut self, virtio_devices: &mut Vec, console_fd: Option, - resize_pipe: Option, + resize_pipe: Option>, ) -> DeviceManagerResult>> { let console_config = self.config.lock().unwrap().console.clone(); let endpoint = match console_config.mode { @@ -2024,7 +2024,7 @@ impl DeviceManager { // SAFETY: pty_fd is guaranteed to be a valid fd from // pre_create_console_devices() in vmm/src/console_devices.rs let file = unsafe { File::from_raw_fd(pty_fd) }; - self.console_resize_pipe = resize_pipe.map(Arc::new); + self.console_resize_pipe = resize_pipe; Endpoint::PtyPair(file.try_clone().unwrap(), file) } else { return Err(DeviceManagerError::InvalidConsoleFd); @@ -2113,7 +2113,7 @@ impl DeviceManager { interrupt_manager: &Arc>, virtio_devices: &mut Vec, console_info: Option, - console_resize_pipe: Option, + console_resize_pipe: Option>, ) -> DeviceManagerResult> { let serial_config = self.config.lock().unwrap().serial.clone(); if console_info.is_none() { diff --git a/vmm/src/lib.rs b/vmm/src/lib.rs index 973ed2056..922121655 100644 --- a/vmm/src/lib.rs +++ b/vmm/src/lib.rs @@ -576,7 +576,7 @@ pub struct Vmm { signals: Option, threads: Vec>, original_termios_opt: Arc>>, - console_resize_pipe: Option, + console_resize_pipe: Option>, console_info: Option, } @@ -868,7 +868,7 @@ impl Vmm { activate_evt, timestamp, self.console_info.clone(), - None, + self.console_resize_pipe.as_ref().map(Arc::clone), Arc::clone(&self.original_termios_opt), Some(snapshot), ) @@ -1306,7 +1306,7 @@ impl RequestHandler for Vmm { self.hypervisor.clone(), activate_evt, self.console_info.clone(), - None, + self.console_resize_pipe.as_ref().map(Arc::clone), Arc::clone(&self.original_termios_opt), None, None, @@ -1433,7 +1433,7 @@ impl RequestHandler for Vmm { self.hypervisor.clone(), activate_evt, self.console_info.clone(), - None, + self.console_resize_pipe.as_ref().map(Arc::clone), Arc::clone(&self.original_termios_opt), Some(snapshot), Some(source_url), @@ -1492,10 +1492,7 @@ impl RequestHandler for Vmm { // First we stop the current VM let (config, console_resize_pipe) = if let Some(mut vm) = self.vm.take() { let config = vm.get_config(); - let console_resize_pipe = vm - .console_resize_pipe() - .as_ref() - .map(|pipe| pipe.try_clone().unwrap()); + let console_resize_pipe = vm.console_resize_pipe(); vm.shutdown()?; (config, console_resize_pipe) } else { diff --git a/vmm/src/vm.rs b/vmm/src/vm.rs index a9f7ce211..2013dda28 100644 --- a/vmm/src/vm.rs +++ b/vmm/src/vm.rs @@ -493,7 +493,7 @@ impl Vm { activate_evt: EventFd, timestamp: Instant, console_info: Option, - console_resize_pipe: Option, + console_resize_pipe: Option>, original_termios: Arc>>, snapshot: Option, ) -> Result { @@ -801,7 +801,7 @@ impl Vm { hypervisor: Arc, activate_evt: EventFd, console_info: Option, - console_resize_pipe: Option, + console_resize_pipe: Option>, original_termios: Arc>>, snapshot: Option, source_url: Option<&str>,