diff options
author | Zach Reizner <zachr@google.com> | 2018-04-24 15:58:07 -0700 |
---|---|---|
committer | chrome-bot <chrome-bot@chromium.org> | 2018-04-26 17:00:37 -0700 |
commit | 28be0c6812d62b54a3974dc55d8d83f34499298e (patch) | |
tree | 9880bf02163e31e41ee7996e2118738d626d4469 | |
parent | da3f64c8fe01dae1eaf1e1fc192dfcd711dc1dbe (diff) | |
download | crosvm-28be0c6812d62b54a3974dc55d8d83f34499298e.tar crosvm-28be0c6812d62b54a3974dc55d8d83f34499298e.tar.gz crosvm-28be0c6812d62b54a3974dc55d8d83f34499298e.tar.bz2 crosvm-28be0c6812d62b54a3974dc55d8d83f34499298e.tar.lz crosvm-28be0c6812d62b54a3974dc55d8d83f34499298e.tar.xz crosvm-28be0c6812d62b54a3974dc55d8d83f34499298e.tar.zst crosvm-28be0c6812d62b54a3974dc55d8d83f34499298e.zip |
crosvm/plugin: fmt plugin module and remove negative error code
This is fixes the last remaining negative error code returned by a Rust function. TEST= cargo test --features plugin BUG=None Change-Id: Ideee89b0f0b1effecc9b5880bcf400c82d9b96f9 Reviewed-on: https://chromium-review.googlesource.com/1026938 Commit-Ready: Zach Reizner <zachr@chromium.org> Tested-by: Zach Reizner <zachr@chromium.org> Reviewed-by: Dmitry Torokhov <dtor@chromium.org>
-rw-r--r-- | src/plugin/mod.rs | 9 | ||||
-rw-r--r-- | src/plugin/process.rs | 44 | ||||
-rw-r--r-- | src/plugin/vcpu.rs | 8 |
3 files changed, 32 insertions, 29 deletions
diff --git a/src/plugin/mod.rs b/src/plugin/mod.rs index 85a0266..6a22494 100644 --- a/src/plugin/mod.rs +++ b/src/plugin/mod.rs @@ -332,8 +332,7 @@ pub fn run_vcpus(kvm: &Kvm, } // We do not really want the signal handler to run... - block_signal(SIGRTMIN() + 0) - .expect("failed to block signal"); + block_signal(SIGRTMIN() + 0).expect("failed to block signal"); // Tell KVM to not block anything when entering kvm run // because we will be using first RT signal to kick the VCPU. vcpu.set_signal_mask(&[]) @@ -386,8 +385,7 @@ pub fn run_vcpus(kvm: &Kvm, // Try to clear the signal that we use to kick VCPU if it is // pending before attempting to handle pause requests. - clear_signal(SIGRTMIN() + 0) - .expect("failed to clear pending signal"); + clear_signal(SIGRTMIN() + 0).expect("failed to clear pending signal"); if let Err(e) = vcpu_plugin.pre_run(&vcpu) { error!("failed to process pause on vcpu {}: {:?}", cpu_id, e); @@ -443,8 +441,7 @@ pub fn run_config(cfg: Config) -> Result<()> { if let Some(mac_address) = cfg.mac_address { let tap = Tap::new(false).map_err(Error::TapOpen)?; tap.set_ip_addr(host_ip).map_err(Error::TapSetIp)?; - tap.set_netmask(netmask) - .map_err(Error::TapSetNetmask)?; + tap.set_netmask(netmask).map_err(Error::TapSetNetmask)?; tap.set_mac_address(mac_address) .map_err(Error::TapSetMacAddress)?; diff --git a/src/plugin/process.rs b/src/plugin/process.rs index 4e7656f..f816955 100644 --- a/src/plugin/process.rs +++ b/src/plugin/process.rs @@ -46,17 +46,19 @@ unsafe impl DataInit for VmPitState {} fn get_vm_state(vm: &Vm, state_set: MainRequest_StateSet) -> SysResult<Vec<u8>> { Ok(match state_set { MainRequest_StateSet::PIC0 => { - VmPicState(vm.get_pic_state(PicId::Primary)?).as_slice().to_vec() + VmPicState(vm.get_pic_state(PicId::Primary)?) + .as_slice() + .to_vec() } MainRequest_StateSet::PIC1 => { - VmPicState(vm.get_pic_state(PicId::Secondary)?).as_slice().to_vec() + VmPicState(vm.get_pic_state(PicId::Secondary)?) + .as_slice() + .to_vec() } MainRequest_StateSet::IOAPIC => { VmIoapicState(vm.get_ioapic_state()?).as_slice().to_vec() } - MainRequest_StateSet::PIT => { - VmPitState(vm.get_pit_state()?).as_slice().to_vec() - } + MainRequest_StateSet::PIT => VmPitState(vm.get_pit_state()?).as_slice().to_vec(), }) } @@ -65,24 +67,24 @@ fn set_vm_state(vm: &Vm, state_set: MainRequest_StateSet, state: &[u8]) -> SysRe MainRequest_StateSet::PIC0 => { vm.set_pic_state(PicId::Primary, &VmPicState::from_slice(state) - .ok_or(SysError::new(EINVAL))? - .0) + .ok_or(SysError::new(EINVAL))? + .0) } MainRequest_StateSet::PIC1 => { vm.set_pic_state(PicId::Secondary, &VmPicState::from_slice(state) - .ok_or(SysError::new(EINVAL))? - .0) + .ok_or(SysError::new(EINVAL))? + .0) } MainRequest_StateSet::IOAPIC => { vm.set_ioapic_state(&VmIoapicState::from_slice(state) - .ok_or(SysError::new(EINVAL))? - .0) + .ok_or(SysError::new(EINVAL))? + .0) } MainRequest_StateSet::PIT => { vm.set_pit_state(&VmPitState::from_slice(state) - .ok_or(SysError::new(EINVAL))? - .0) + .ok_or(SysError::new(EINVAL))? + .0) } } } @@ -404,7 +406,8 @@ impl Process { } fn handle_get_net_config(tap: &net_util::Tap, - config: &mut MainResponse_GetNetConfig) -> SysResult<()> { + config: &mut MainResponse_GetNetConfig) + -> SysResult<()> { // Log any NetError so that the cause can be found later, but extract and return the // underlying errno for the client as well. fn map_net_error(s: &str, e: NetError) -> SysError { @@ -412,7 +415,8 @@ impl Process { e.sys_error() } - let ip_addr = tap.ip_addr().map_err(|e| map_net_error("IP address", e))?; + let ip_addr = tap.ip_addr() + .map_err(|e| map_net_error("IP address", e))?; config.set_host_ipv4_address(u32::from(ip_addr)); let netmask = tap.netmask().map_err(|e| map_net_error("netmask", e))?; @@ -420,8 +424,8 @@ impl Process { let result_mac_addr = config.mut_host_mac_address(); let mac_addr_octets = tap.mac_address() - .map_err(|e| map_net_error("mac address", e))? - .octets(); + .map_err(|e| map_net_error("mac address", e))? + .octets(); result_mac_addr.resize(mac_addr_octets.len(), 0); result_mac_addr.clone_from_slice(&mac_addr_octets); @@ -596,7 +600,7 @@ impl Process { Err(e) => Err(e), } } - None => Err(SysError::new(-ENODATA)), + None => Err(SysError::new(ENODATA)), } } else if request.has_dirty_log() { let dirty_log_response = response.mut_dirty_log(); @@ -617,7 +621,7 @@ impl Process { } Ok(()) } - Err(e) => Err(e) + Err(e) => Err(e), } } else if request.has_get_emulated_cpuid() { let cpuid_response = &mut response.mut_get_emulated_cpuid().entries; @@ -628,7 +632,7 @@ impl Process { } Ok(()) } - Err(e) => Err(e) + Err(e) => Err(e), } } else { Err(SysError::new(ENOTTY)) diff --git a/src/plugin/vcpu.rs b/src/plugin/vcpu.rs index bf40ccc..477cf61 100644 --- a/src/plugin/vcpu.rs +++ b/src/plugin/vcpu.rs @@ -115,8 +115,8 @@ fn set_vcpu_state(vcpu: &Vcpu, state_set: VcpuRequest_StateSet, state: &[u8]) -> } VcpuRequest_StateSet::MP => { vcpu.set_mp_state(&VcpuMpState::from_slice(state) - .ok_or(SysError::new(EINVAL))? - .0) + .ok_or(SysError::new(EINVAL))? + .0) } } } @@ -302,7 +302,9 @@ impl PluginVcpu { /// to this VCPU. pub fn pre_run(&self, vcpu: &Vcpu) -> SysResult<()> { let request = { - let mut lock = self.per_vcpu_state.lock().map_err(|_| SysError::new(EDEADLK))?; + let mut lock = self.per_vcpu_state + .lock() + .map_err(|_| SysError::new(EDEADLK))?; lock.pause_request.take() }; |