diff options
author | Alyssa Ross <hi@alyssa.is> | 2020-06-07 09:47:21 +0000 |
---|---|---|
committer | Alyssa Ross <hi@alyssa.is> | 2020-07-02 12:33:02 +0000 |
commit | f57267d7e998ffec48794723b188b35489acfeec (patch) | |
tree | d0612accc4c8a20942bf333cb15e34c4203c1c4c /src | |
parent | b7f9c8db01cd673a8b20bb5649f6cd06371b9695 (diff) | |
download | crosvm-f57267d7e998ffec48794723b188b35489acfeec.tar crosvm-f57267d7e998ffec48794723b188b35489acfeec.tar.gz crosvm-f57267d7e998ffec48794723b188b35489acfeec.tar.bz2 crosvm-f57267d7e998ffec48794723b188b35489acfeec.tar.lz crosvm-f57267d7e998ffec48794723b188b35489acfeec.tar.xz crosvm-f57267d7e998ffec48794723b188b35489acfeec.tar.zst crosvm-f57267d7e998ffec48794723b188b35489acfeec.zip |
devices: enable adding Wl sockets at runtime
Diffstat (limited to 'src')
-rw-r--r-- | src/linux.rs | 19 | ||||
-rw-r--r-- | src/main.rs | 29 |
2 files changed, 45 insertions, 3 deletions
diff --git a/src/linux.rs b/src/linux.rs index d5e12cd..3ef323e 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -11,6 +11,7 @@ use std::ffi::{CStr, OsString}; use std::fmt::{self, Display}; use std::fs::{File, OpenOptions}; use std::io::{self, stdin, Read}; +use std::iter::once; use std::mem; use std::net::Ipv4Addr; #[cfg(feature = "gpu")] @@ -61,7 +62,8 @@ use vm_control::{ DiskControlResult, UsbControlSocket, VmControlResponseSocket, VmIrqRequest, VmIrqResponse, VmIrqResponseSocket, VmMemoryControlRequestSocket, VmMemoryControlResponseSocket, VmMemoryRequest, VmMemoryResponse, VmMsyncRequest, VmMsyncRequestSocket, VmMsyncResponse, - VmMsyncResponseSocket, VmRequest, VmRunMode, + VmMsyncResponseSocket, VmRequest, VmRunMode, WlControlCommand, WlControlRequestSocket, + WlControlResponseSocket, WlControlResult, }; use crate::{Config, DiskOption, Executable, SharedDir, SharedDirKind, TouchDeviceOption}; @@ -772,6 +774,7 @@ fn create_wayland_device( vm_socket: VmMemoryControlRequestSocket, resource_bridge: Option<virtio::resource_bridge::ResourceRequestSocket>, memory_params: MemoryParams, + control_socket: WlControlResponseSocket, ) -> DeviceResult { let mut wayland_socket_paths = cfg.wayland_socket_paths.clone(); @@ -799,6 +802,7 @@ fn create_wayland_device( wayland_paths: wayland_socket_paths.clone(), vm_socket, resource_bridge, + control_socket, }) .unwrap(), ), @@ -1100,6 +1104,7 @@ fn create_virtio_devices( balloon_device_control_socket: BalloonControlResponseSocket, disk_device_control_sockets: &mut Vec<DiskControlResponseSocket>, pmem_device_control_sockets: &mut Vec<VmMsyncRequestSocket>, + wl_device_control_socket: WlControlResponseSocket, ) -> DeviceResult<Vec<VirtioDeviceStub>> { let mut devs = Vec::new(); @@ -1194,6 +1199,7 @@ fn create_virtio_devices( wayland_device_control_socket, wl_resource_bridge, mem_params, + wl_device_control_socket, )?); } @@ -1307,6 +1313,7 @@ fn create_devices( disk_device_control_sockets: &mut Vec<DiskControlResponseSocket>, pmem_device_control_sockets: &mut Vec<VmMsyncRequestSocket>, usb_provider: HostBackendDeviceProvider, + wl_device_control_socket: WlControlResponseSocket, ) -> DeviceResult<Vec<(Box<dyn PciDevice>, Option<Minijail>)>> { let stubs = create_virtio_devices( &cfg, @@ -1321,6 +1328,7 @@ fn create_devices( balloon_device_control_socket, disk_device_control_sockets, pmem_device_control_sockets, + wl_device_control_socket, )?; let mut pci_devices = Vec::new(); @@ -1852,6 +1860,9 @@ pub fn run_config(cfg: Config) -> Result<()> { msg_socket::pair::<VmIrqResponse, VmIrqRequest>().map_err(Error::CreateSocket)?; control_sockets.push(TaggedControlSocket::VmIrq(ioapic_host_socket)); + let (wl_host_socket, wl_device_control_socket) = + msg_socket::pair::<WlControlCommand, WlControlResult>().map_err(Error::CreateSocket)?; + let mut servers = vec![]; let mut memfd_socket_path = None; @@ -1899,6 +1910,7 @@ pub fn run_config(cfg: Config) -> Result<()> { &mut disk_device_control_sockets, &mut pmem_device_control_sockets, usb_provider, + wl_device_control_socket, ) }, ) @@ -1911,6 +1923,7 @@ pub fn run_config(cfg: Config) -> Result<()> { balloon_host_socket, &disk_host_sockets, usb_control_socket, + wl_host_socket, sigchld_fd, sandbox, ) @@ -1923,6 +1936,7 @@ fn run_control( balloon_host_socket: BalloonControlRequestSocket, disk_host_sockets: &[DiskControlRequestSocket], usb_control_socket: UsbControlSocket, + wl_host_socket: WlControlRequestSocket, sigchld_fd: SignalFd, sandbox: bool, ) -> Result<()> { @@ -2049,7 +2063,7 @@ fn run_control( // to the event loop, so that when they become ready, we can process their queues. After the // initial queue is processed, the device becomes ready, and the socket is removed from the // event loop. - for socket in disk_host_sockets.iter().map(AsRef::as_ref) { + for socket in once(wl_host_socket.as_ref()).chain(disk_host_sockets.iter().map(AsRef::as_ref)) { let token = Token::DeviceReady { sock_fd: socket.as_raw_fd(), }; @@ -2261,6 +2275,7 @@ fn run_control( &balloon_host_socket, &disk_host_sockets, &usb_control_socket, + &wl_host_socket, ); match device_socket diff --git a/src/main.rs b/src/main.rs index 87ecdb6..e5b5053 100644 --- a/src/main.rs +++ b/src/main.rs @@ -34,7 +34,7 @@ use sys_util::{ }; use vm_control::{ BalloonControlCommand, DiskControlCommand, MaybeOwnedFd, UsbControlCommand, UsbControlResult, - VmControlRequestSocket, VmRequest, VmResponse, USB_CONTROL_MAX_PORTS, + VmControlRequestSocket, VmRequest, VmResponse, WlControlCommand, USB_CONTROL_MAX_PORTS, }; fn executable_is_plugin(executable: &Option<Executable>) -> bool { @@ -2178,6 +2178,31 @@ fn modify_usb(mut args: std::env::Args) -> std::result::Result<(), ()> { } } +fn wl_cmd(mut args: std::env::Args) -> std::result::Result<(), ()> { + if args.len() < 2 { + print_help("crosvm wl", "SUBCOMMAND VM_SOCKET...", &[]); + println!("Manage attached virtio Wayland sockets."); + println!("Subcommands:"); + println!(" add NAME PATH VM_SOCKET"); + return Err(()); + } + let subcommand: &str = &args.next().unwrap(); + + let request = match subcommand { + "add" => { + let name = args.next().unwrap(); + let path = args.next().unwrap().into(); + VmRequest::WlCommand(WlControlCommand::AddSocket { name, path }) + } + _ => { + error!("Unknown wl subcommand '{}'", subcommand); + return Err(()); + } + }; + + vms_request(&request, args) +} + fn print_usage() { print_help("crosvm", "[stop|run]", &[]); println!("Commands:"); @@ -2189,6 +2214,7 @@ fn print_usage() { println!(" create_qcow2 Create a new qcow2 disk image file."); println!(" disk Manage attached virtual disk devices."); println!(" usb Manage attached virtual USB devices."); + println!(" wl Manage attached virtio_wl sockets."); println!(" version Show package version."); } @@ -2233,6 +2259,7 @@ fn crosvm_main() -> std::result::Result<(), ()> { Some("create_qcow2") => create_qcow2(args), Some("disk") => disk_cmd(args), Some("usb") => modify_usb(args), + Some("wl") => wl_cmd(args), Some("version") => pkg_version(), Some(c) => { println!("invalid subcommand: {:?}", c); |