From ecf81e0f05e7221ec9ccd9b09691e83ccddc1109 Mon Sep 17 00:00:00 2001 From: Jakub Staron Date: Thu, 11 Apr 2019 11:43:39 -0700 Subject: 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 Tested-by: kokoro Reviewed-by: Daniel Verkamp --- vm_control/src/lib.rs | 45 +++++++++++++++++++++++++++++++++++++++------ 1 file changed, 39 insertions(+), 6 deletions(-) (limited to 'vm_control') 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 @@ -91,6 +91,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 { @@ -133,7 +155,11 @@ impl Display for UsbControlResult { } } +pub type DiskControlRequestSocket = MsgSocket; +pub type DiskControlResponseSocket = MsgSocket; + pub type UsbControlSocket = MsgSocket; + pub type VmControlRequestSocket = MsgSocket; pub type VmControlResponseSocket = MsgSocket; @@ -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, balloon_host_socket: &UnixSeqpacket, - disk_host_sockets: &[MsgSocket], + 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)) -- cgit 1.4.1