summary refs log tree commit diff
path: root/vm_control
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2020-06-07 09:47:21 +0000
committerAlyssa Ross <hi@alyssa.is>2020-07-02 12:33:02 +0000
commitf57267d7e998ffec48794723b188b35489acfeec (patch)
treed0612accc4c8a20942bf333cb15e34c4203c1c4c /vm_control
parentb7f9c8db01cd673a8b20bb5649f6cd06371b9695 (diff)
downloadcrosvm-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 'vm_control')
-rw-r--r--vm_control/src/lib.rs46
1 files changed, 46 insertions, 0 deletions
diff --git a/vm_control/src/lib.rs b/vm_control/src/lib.rs
index a9784b1..e800624 100644
--- a/vm_control/src/lib.rs
+++ b/vm_control/src/lib.rs
@@ -15,6 +15,7 @@ use std::fs::File;
 use std::io::{Seek, SeekFrom};
 use std::mem::ManuallyDrop;
 use std::os::unix::io::{AsRawFd, FromRawFd, RawFd};
+use std::path::PathBuf;
 
 use libc::{EINVAL, EIO, ENODEV};
 
@@ -511,6 +512,27 @@ impl VmMsyncRequest {
     }
 }
 
+#[derive(MsgOnSocket, Debug)]
+pub enum WlControlCommand {
+    AddSocket { name: String, path: PathBuf },
+}
+
+#[derive(MsgOnSocket, Debug)]
+pub enum WlControlResult {
+    Ready,
+    Ok,
+    Err(SysError),
+}
+
+impl From<Result<()>> for WlControlResult {
+    fn from(result: Result<()>) -> Self {
+        match result {
+            Ok(()) => Self::Ok,
+            Err(e) => Self::Err(e),
+        }
+    }
+}
+
 pub type BalloonControlRequestSocket = MsgSocket<BalloonControlCommand, BalloonControlResult>;
 pub type BalloonControlResponseSocket = MsgSocket<BalloonControlResult, BalloonControlCommand>;
 
@@ -531,6 +553,9 @@ pub type VmMsyncResponseSocket = MsgSocket<VmMsyncResponse, VmMsyncRequest>;
 pub type VmControlRequestSocket = MsgSocket<VmRequest, VmResponse>;
 pub type VmControlResponseSocket = MsgSocket<VmResponse, VmRequest>;
 
+pub type WlControlRequestSocket = MsgSocket<WlControlCommand, WlControlResult>;
+pub type WlControlResponseSocket = MsgSocket<WlControlResult, WlControlCommand>;
+
 /// A request to the main process to perform some operation on the VM.
 ///
 /// Unless otherwise noted, each request should expect a `VmResponse::Ok` to be received on success.
@@ -552,6 +577,8 @@ pub enum VmRequest {
     },
     /// Command to use controller.
     UsbCommand(UsbControlCommand),
+    /// Command for wl driver.
+    WlCommand(WlControlCommand),
 }
 
 fn register_memory(
@@ -592,6 +619,7 @@ impl VmRequest {
         balloon_host_socket: &'s BalloonControlRequestSocket,
         disk_host_sockets: &'s [DiskControlRequestSocket],
         usb_control_socket: &'s UsbControlSocket,
+        wl_host_socket: &'s WlControlRequestSocket,
     ) -> Option<&'s UnixSeqpacket> {
         use VmRequest::*;
         match *self {
@@ -601,6 +629,7 @@ impl VmRequest {
             BalloonCommand(_) => Some(balloon_host_socket.as_ref()),
             DiskCommand { disk_index, .. } => disk_host_sockets.get(disk_index).map(AsRef::as_ref),
             UsbCommand(_) => Some(usb_control_socket.as_ref()),
+            WlCommand(_) => Some(wl_host_socket.as_ref()),
         }
     }
 
@@ -696,6 +725,20 @@ impl VmRequest {
                     }
                 }
             }
+            VmRequest::WlCommand(ref cmd) => {
+                let socket = socket.unwrap();
+                if let Err(e) = socket.send_msg_on_socket(cmd) {
+                    error!("fail to send command to wl control socket: {}", e);
+                    return VmResponse::Err(SysError::new(EIO));
+                }
+                match socket.recv_msg_on_socket() {
+                    Ok(response) => VmResponse::WlResponse(response),
+                    Err(e) => {
+                        error!("fail to recv command from usb control socket: {}", e);
+                        VmResponse::Err(SysError::new(EIO))
+                    }
+                }
+            }
         }
     }
 }
@@ -727,6 +770,8 @@ pub enum VmResponse {
     },
     /// Results of usb control commands.
     UsbResponse(UsbControlResult),
+    /// Results of wl control commands.
+    WlResponse(WlControlResult),
 }
 
 impl Display for VmResponse {
@@ -755,6 +800,7 @@ impl Display for VmResponse {
                 balloon_actual, stats
             ),
             UsbResponse(result) => write!(f, "usb control request get result {:?}", result),
+            WlResponse(result) => write!(f, "wl control request get result {:?}", result),
         }
     }
 }