summary refs log tree commit diff
path: root/vm_control
diff options
context:
space:
mode:
authorJakub Staron <jstaron@google.com>2019-04-11 11:43:39 -0700
committerchrome-bot <chrome-bot@chromium.org>2019-04-19 14:45:21 -0700
commitecf81e0f05e7221ec9ccd9b09691e83ccddc1109 (patch)
tree1fae117dfecec01ee15ce58565a7a8cb0dca5a1e /vm_control
parent4b292afafcd44ca3fc34f483a8edb455a3212cb5 (diff)
downloadcrosvm-ecf81e0f05e7221ec9ccd9b09691e83ccddc1109.tar
crosvm-ecf81e0f05e7221ec9ccd9b09691e83ccddc1109.tar.gz
crosvm-ecf81e0f05e7221ec9ccd9b09691e83ccddc1109.tar.bz2
crosvm-ecf81e0f05e7221ec9ccd9b09691e83ccddc1109.tar.lz
crosvm-ecf81e0f05e7221ec9ccd9b09691e83ccddc1109.tar.xz
crosvm-ecf81e0f05e7221ec9ccd9b09691e83ccddc1109.tar.zst
crosvm-ecf81e0f05e7221ec9ccd9b09691e83ccddc1109.zip
Extracts DiskResize from VmRequest to a new type.
BUG=None
TEST=cargo test
TEST=cargo test --package msg_socket
TEST=cargo test --package devices
TEST=cargo test --package vm_control
TEST=tast -verbose run ${IP} vm.CrostiniStartEverything

Change-Id: Icf26f53d3fd813ab43b8f14079f90628d245eed7
Reviewed-on: https://chromium-review.googlesource.com/1565297
Commit-Ready: ChromeOS CL Exonerator Bot <chromiumos-cl-exonerator@appspot.gserviceaccount.com>
Tested-by: kokoro <noreply+kokoro@google.com>
Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
Diffstat (limited to 'vm_control')
-rw-r--r--vm_control/src/lib.rs45
1 files changed, 39 insertions, 6 deletions
diff --git a/vm_control/src/lib.rs b/vm_control/src/lib.rs
index 9e6cc85..b197e9b 100644
--- a/vm_control/src/lib.rs
+++ b/vm_control/src/lib.rs
@@ -92,6 +92,28 @@ impl Default for VmRunMode {
 }
 
 #[derive(MsgOnSocket, Debug)]
+pub enum DiskControlCommand {
+    /// Resize a disk to `new_size` in bytes.
+    Resize { new_size: u64 },
+}
+
+impl Display for DiskControlCommand {
+    fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
+        use self::DiskControlCommand::*;
+
+        match self {
+            Resize { new_size } => write!(f, "disk_resize {}", new_size),
+        }
+    }
+}
+
+#[derive(MsgOnSocket, Debug)]
+pub enum DiskControlResult {
+    Ok,
+    Err(SysError),
+}
+
+#[derive(MsgOnSocket, Debug)]
 pub enum UsbControlCommand {
     AttachDevice {
         bus: u8,
@@ -133,7 +155,11 @@ impl Display for UsbControlResult {
     }
 }
 
+pub type DiskControlRequestSocket = MsgSocket<DiskControlCommand, DiskControlResult>;
+pub type DiskControlResponseSocket = MsgSocket<DiskControlResult, DiskControlCommand>;
+
 pub type UsbControlSocket = MsgSocket<UsbControlCommand, UsbControlResult>;
+
 pub type VmControlRequestSocket = MsgSocket<VmRequest, VmResponse>;
 pub type VmControlResponseSocket = MsgSocket<VmResponse, VmRequest>;
 
@@ -162,9 +188,12 @@ pub enum VmRequest {
         height: u32,
         format: u32,
     },
-    /// Resize a disk chosen by `disk_index` to `new_size` in bytes.
+    /// Send a command to a disk chosen by `disk_index`.
     /// `disk_index` is a 0-based count of `--disk`, `--rwdisk`, and `-r` command-line options.
-    DiskResize { disk_index: usize, new_size: u64 },
+    DiskCommand {
+        disk_index: usize,
+        command: DiskControlCommand,
+    },
     /// Command to use controller.
     UsbCommand(UsbControlCommand),
 }
@@ -209,7 +238,7 @@ impl VmRequest {
         sys_allocator: &mut SystemAllocator,
         run_mode: &mut Option<VmRunMode>,
         balloon_host_socket: &UnixSeqpacket,
-        disk_host_sockets: &[MsgSocket<VmRequest, VmResponse>],
+        disk_host_sockets: &[DiskControlRequestSocket],
         usb_control_socket: &UsbControlSocket,
     ) -> VmResponse {
         match *self {
@@ -274,15 +303,19 @@ impl VmRequest {
                     Err(e) => VmResponse::Err(e),
                 }
             }
-            VmRequest::DiskResize { disk_index, .. } => {
+            VmRequest::DiskCommand {
+                disk_index,
+                ref command,
+            } => {
                 // Forward the request to the block device process via its control socket.
                 if let Some(sock) = disk_host_sockets.get(disk_index) {
-                    if let Err(e) = sock.send(self) {
+                    if let Err(e) = sock.send(command) {
                         error!("disk socket send failed: {}", e);
                         VmResponse::Err(SysError::new(EINVAL))
                     } else {
                         match sock.recv() {
-                            Ok(result) => result,
+                            Ok(DiskControlResult::Ok) => VmResponse::Ok,
+                            Ok(DiskControlResult::Err(e)) => VmResponse::Err(e),
                             Err(e) => {
                                 error!("disk socket recv failed: {}", e);
                                 VmResponse::Err(SysError::new(EINVAL))