diff options
-rw-r--r-- | devices/src/virtio/block.rs | 21 | ||||
-rw-r--r-- | devices/src/virtio/wl.rs | 21 | ||||
-rw-r--r-- | src/linux.rs | 30 | ||||
-rw-r--r-- | src/main.rs | 7 | ||||
-rw-r--r-- | vm_control/src/lib.rs | 2 |
5 files changed, 44 insertions, 37 deletions
diff --git a/devices/src/virtio/block.rs b/devices/src/virtio/block.rs index 71e7e4b..023e1df 100644 --- a/devices/src/virtio/block.rs +++ b/devices/src/virtio/block.rs @@ -18,13 +18,13 @@ use sync::Mutex; use sys_util::Error as SysError; use sys_util::Result as SysResult; use sys_util::{ - net::UnixSeqpacket, EventFd, FileSetLen, FileSync, GuestAddress, GuestMemory, GuestMemoryError, - PollContext, PollToken, PunchHole, TimerFd, WriteZeroes, + EventFd, FileSetLen, FileSync, GuestAddress, GuestMemory, GuestMemoryError, PollContext, + PollToken, PunchHole, TimerFd, WriteZeroes, }; use data_model::{DataInit, Le16, Le32, Le64}; -use msg_socket::{MsgReceiver, MsgSender, MsgSocket}; -use vm_control::{VmRequest, VmResponse}; +use msg_socket::{MsgReceiver, MsgSender}; +use vm_control::{VmControlResponseSocket, VmRequest, VmResponse}; use super::{ DescriptorChain, Queue, VirtioDevice, INTERRUPT_STATUS_CONFIG_CHANGED, @@ -695,7 +695,12 @@ impl<T: DiskFile> Worker<T> { self.interrupt_evt.write(1).unwrap(); } - fn run(&mut self, queue_evt: EventFd, kill_evt: EventFd, control_socket: UnixSeqpacket) { + fn run( + &mut self, + queue_evt: EventFd, + kill_evt: EventFd, + control_socket: VmControlResponseSocket, + ) { #[derive(PollToken)] enum Token { FlushTimer, @@ -714,8 +719,6 @@ impl<T: DiskFile> Worker<T> { }; let mut flush_timer_armed = false; - let control_socket = MsgSocket::<VmResponse, VmRequest>::new(control_socket); - let poll_ctx: PollContext<Token> = match PollContext::new() .and_then(|pc| pc.add(&flush_timer, Token::FlushTimer).and(Ok(pc))) .and_then(|pc| pc.add(&queue_evt, Token::QueueAvailable).and(Ok(pc))) @@ -819,7 +822,7 @@ pub struct Block<T: DiskFile> { disk_size: Arc<Mutex<u64>>, avail_features: u64, read_only: bool, - control_socket: Option<UnixSeqpacket>, + control_socket: Option<VmControlResponseSocket>, } fn build_config_space(disk_size: u64) -> virtio_blk_config { @@ -845,7 +848,7 @@ impl<T: DiskFile> Block<T> { pub fn new( mut disk_image: T, read_only: bool, - control_socket: Option<UnixSeqpacket>, + control_socket: Option<VmControlResponseSocket>, ) -> SysResult<Block<T>> { let disk_size = disk_image.seek(SeekFrom::End(0))? as u64; if disk_size % SECTOR_SIZE != 0 { diff --git a/devices/src/virtio/wl.rs b/devices/src/virtio/wl.rs index 870b5ea..4a6d59d 100644 --- a/devices/src/virtio/wl.rs +++ b/devices/src/virtio/wl.rs @@ -56,10 +56,9 @@ use libc::{dup, EBADF, EINVAL}; use data_model::VolatileMemoryError; use data_model::*; -use msg_socket::{MsgError, MsgReceiver, MsgSender, MsgSocket}; +use msg_socket::{MsgError, MsgReceiver, MsgSender}; #[cfg(feature = "wl-dmabuf")] use resources::GpuMemoryDesc; -use sys_util::net::UnixSeqpacket; use sys_util::{ pipe, round_up_to_page_size, Error, EventFd, FileFlags, GuestAddress, GuestMemory, GuestMemoryError, PollContext, PollToken, Result, ScmSocket, SharedMemory, @@ -72,7 +71,7 @@ use super::resource_bridge::*; use super::{ DescriptorChain, Queue, VirtioDevice, INTERRUPT_STATUS_USED_RING, TYPE_WL, VIRTIO_F_VERSION_1, }; -use vm_control::{MaybeOwnedFd, VmRequest, VmResponse}; +use vm_control::{MaybeOwnedFd, VmControlRequestSocket, VmRequest, VmResponse}; const VIRTWL_SEND_MAX_ALLOCS: usize = 28; const VIRTIO_WL_CMD_VFD_NEW: u32 = 256; @@ -485,15 +484,13 @@ impl From<VolatileMemoryError> for WlError { #[derive(Clone)] struct VmRequester { - inner: Rc<RefCell<MsgSocket<VmRequest, VmResponse>>>, + inner: Rc<RefCell<VmControlRequestSocket>>, } impl VmRequester { - fn new(vm_socket: UnixSeqpacket) -> VmRequester { + fn new(vm_socket: VmControlRequestSocket) -> VmRequester { VmRequester { - inner: Rc::new(RefCell::new(MsgSocket::<VmRequest, VmResponse>::new( - vm_socket, - ))), + inner: Rc::new(RefCell::new(vm_socket)), } } @@ -1003,7 +1000,7 @@ struct WlState { impl WlState { fn new( wayland_path: PathBuf, - vm_socket: UnixSeqpacket, + vm_socket: VmControlRequestSocket, use_transition_flags: bool, resource_bridge: Option<ResourceRequestSocket>, ) -> WlState { @@ -1487,7 +1484,7 @@ impl Worker { in_queue: Queue, out_queue: Queue, wayland_path: PathBuf, - vm_socket: UnixSeqpacket, + vm_socket: VmControlRequestSocket, use_transition_flags: bool, resource_bridge: Option<ResourceRequestSocket>, ) -> Worker { @@ -1677,7 +1674,7 @@ impl Worker { pub struct Wl { kill_evt: Option<EventFd>, wayland_path: PathBuf, - vm_socket: Option<UnixSeqpacket>, + vm_socket: Option<VmControlRequestSocket>, resource_bridge: Option<ResourceRequestSocket>, use_transition_flags: bool, } @@ -1685,7 +1682,7 @@ pub struct Wl { impl Wl { pub fn new<P: AsRef<Path>>( wayland_path: P, - vm_socket: UnixSeqpacket, + vm_socket: VmControlRequestSocket, resource_bridge: Option<ResourceRequestSocket>, ) -> Result<Wl> { Ok(Wl { diff --git a/src/linux.rs b/src/linux.rs index a7b8945..ba95f8c 100644 --- a/src/linux.rs +++ b/src/linux.rs @@ -44,7 +44,10 @@ use sys_util::{ #[cfg(feature = "gpu-forward")] use sys_util::{GuestAddress, MemoryMapping, Protection}; use vhost; -use vm_control::{UsbControlSocket, VmRequest, VmResponse, VmRunMode}; +use vm_control::{ + UsbControlSocket, VmControlRequestSocket, VmControlResponseSocket, VmRequest, VmResponse, + VmRunMode, +}; use crate::{Config, DiskOption, TouchDeviceOption}; @@ -275,7 +278,7 @@ type DeviceResult<T = VirtioDeviceStub> = std::result::Result<T, Error>; fn create_block_device( cfg: &Config, disk: &DiskOption, - disk_device_socket: UnixSeqpacket, + disk_device_socket: VmControlResponseSocket, ) -> DeviceResult { // Special case '/proc/self/fd/*' paths. The FD is already open, just use it. let raw_image: File = if disk.path.parent() == Some(Path::new("/proc/self/fd")) { @@ -568,7 +571,7 @@ fn create_gpu_device( fn create_wayland_device( cfg: &Config, socket_path: &Path, - socket: UnixSeqpacket, + socket: VmControlRequestSocket, resource_bridge: Option<virtio::resource_bridge::ResourceRequestSocket>, ) -> DeviceResult { let wayland_socket_dir = socket_path.parent().ok_or(Error::InvalidWaylandPath)?; @@ -664,9 +667,9 @@ fn create_virtio_devices( cfg: &Config, mem: &GuestMemory, _exit_evt: &EventFd, - wayland_device_socket: UnixSeqpacket, + wayland_device_socket: VmControlRequestSocket, balloon_device_socket: UnixSeqpacket, - disk_device_sockets: &mut Vec<UnixSeqpacket>, + disk_device_sockets: &mut Vec<VmControlResponseSocket>, ) -> DeviceResult<Vec<VirtioDeviceStub>> { let mut devs = Vec::new(); @@ -764,9 +767,9 @@ fn create_devices( cfg: Config, mem: &GuestMemory, exit_evt: &EventFd, - wayland_device_socket: UnixSeqpacket, + wayland_device_socket: VmControlRequestSocket, balloon_device_socket: UnixSeqpacket, - disk_device_sockets: &mut Vec<UnixSeqpacket>, + disk_device_sockets: &mut Vec<VmControlResponseSocket>, usb_provider: HostBackendDeviceProvider, ) -> DeviceResult<Vec<(Box<dyn PciDevice>, Option<Minijail>)>> { let stubs = create_virtio_devices( @@ -1119,8 +1122,8 @@ pub fn run_config(cfg: Config) -> Result<()> { let mut control_sockets = Vec::new(); let (wayland_host_socket, wayland_device_socket) = - UnixSeqpacket::pair().map_err(Error::CreateSocket)?; - control_sockets.push(MsgSocket::<VmResponse, VmRequest>::new(wayland_host_socket)); + msg_socket::pair::<VmResponse, VmRequest>().map_err(Error::CreateSocket)?; + control_sockets.push(wayland_host_socket); // Balloon gets a special socket so balloon requests can be forwarded from the main process. let (balloon_host_socket, balloon_device_socket) = UnixSeqpacket::pair().map_err(Error::CreateSocket)?; @@ -1131,10 +1134,9 @@ pub fn run_config(cfg: Config) -> Result<()> { let disk_count = cfg.disks.len(); for _ in 0..disk_count { let (disk_host_socket, disk_device_socket) = - UnixSeqpacket::pair().map_err(Error::CreateSocket)?; - disk_device_sockets.push(disk_device_socket); - let disk_host_socket = MsgSocket::<VmRequest, VmResponse>::new(disk_host_socket); + msg_socket::pair::<VmRequest, VmResponse>().map_err(Error::CreateSocket)?; disk_host_sockets.push(disk_host_socket); + disk_device_sockets.push(disk_device_socket); } let sandbox = cfg.sandbox; @@ -1201,9 +1203,9 @@ pub fn run_config(cfg: Config) -> Result<()> { fn run_control( mut linux: RunnableLinuxVm, control_server_socket: Option<UnlinkUnixSeqpacketListener>, - mut control_sockets: Vec<MsgSocket<VmResponse, VmRequest>>, + mut control_sockets: Vec<VmControlResponseSocket>, balloon_host_socket: UnixSeqpacket, - disk_host_sockets: &[MsgSocket<VmRequest, VmResponse>], + disk_host_sockets: &[VmControlRequestSocket], usb_control_socket: UsbControlSocket, sigchld_fd: SignalFd, _render_node_host: RenderNodeHost, diff --git a/src/main.rs b/src/main.rs index 2439b79..2242d71 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,7 +58,10 @@ use qcow::QcowFile; use sys_util::{ getpid, kill_process_group, net::UnixSeqpacket, reap_child, syslog, validate_raw_fd, }; -use vm_control::{MaybeOwnedFd, UsbControlCommand, UsbControlResult, VmRequest, VmResponse}; +use vm_control::{ + MaybeOwnedFd, UsbControlCommand, UsbControlResult, VmControlRequestSocket, VmRequest, + VmResponse, +}; use crate::argument::{print_help, set_arguments, Argument}; @@ -842,7 +845,7 @@ fn handle_request( for socket_path in args { match UnixSeqpacket::connect(&socket_path) { Ok(s) => { - let socket = MsgSocket::<VmRequest, VmResponse>::new(s); + let socket: VmControlRequestSocket = MsgSocket::new(s); if let Err(e) = socket.send(request) { error!( "failed to send request to socket at '{}': {}", diff --git a/vm_control/src/lib.rs b/vm_control/src/lib.rs index 70004b0..6573c9a 100644 --- a/vm_control/src/lib.rs +++ b/vm_control/src/lib.rs @@ -142,6 +142,8 @@ impl Display for UsbControlResult { } pub type UsbControlSocket = MsgSocket<UsbControlCommand, UsbControlResult>; +pub type VmControlRequestSocket = MsgSocket<VmRequest, VmResponse>; +pub type VmControlResponseSocket = MsgSocket<VmResponse, VmRequest>; /// A request to the main process to perform some operation on the VM. /// |