From 7552f4db610377b54ef9740553b936f4cc4f793b Mon Sep 17 00:00:00 2001 From: Wei Liu Date: Mon, 22 Jun 2020 16:31:42 +0000 Subject: [PATCH] vmm: device_manager: restore error handling When the hypervisor crate was introduced, a few places that handled errors were commented out in favor of unwrap, but that's bad practice. Restore proper error handling in those places in this patch. We cannot use from_raw_os_error anymore because it is wrapped deep under hypervisor crate. Create new custom errors instead. Fixes: e4dee57e81369 ("arch, pci, vmm: Initial switch to the hypervisor crate") Signed-off-by: Wei Liu --- vmm/src/device_manager.rs | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/vmm/src/device_manager.rs b/vmm/src/device_manager.rs index 3e8c53315..4a3f779cf 100644 --- a/vmm/src/device_manager.rs +++ b/vmm/src/device_manager.rs @@ -564,16 +564,25 @@ impl DeviceRelocation for AddressManager { if bar_addr == new_base { for (event, addr) in virtio_pci_dev.ioeventfds(old_base) { let io_addr = IoEventAddress::Mmio(addr); - self.vm_fd.unregister_ioevent(event, &io_addr).unwrap(); - /* - map_err(io::Error::from_raw_os_error( - hypervisor::HypervisorVmError::UnregisterIoEvent, - ))?; */ + self.vm_fd + .unregister_ioevent(event, &io_addr) + .map_err(|e| { + io::Error::new( + io::ErrorKind::Other, + format!("failed to unregister ioevent: {:?}", e), + ) + })?; } for (event, addr) in virtio_pci_dev.ioeventfds(new_base) { let io_addr = IoEventAddress::Mmio(addr); - self.vm_fd.register_ioevent(event, &io_addr, None).unwrap(); - //.map_err(|e| io::Error::from_raw_os_error(e.errno()))?; + self.vm_fd + .register_ioevent(event, &io_addr, None) + .map_err(|e| { + io::Error::new( + io::ErrorKind::Other, + format!("failed to register ioevent: {:?}", e), + ) + })?; } } else { let virtio_dev = virtio_pci_dev.virtio_device(); @@ -589,8 +598,12 @@ impl DeviceRelocation for AddressManager { flags: 0, }; - self.vm_fd.set_user_memory_region(mem_region).unwrap(); - //.map_err(|e| io::Error::from_raw_os_error(e.errno()))?; + self.vm_fd.set_user_memory_region(mem_region).map_err(|e| { + io::Error::new( + io::ErrorKind::Other, + format!("failed to set user memory region: {:?}", e), + ) + })?; // Create new mapping by inserting new region to KVM. mem_region.guest_phys_addr = new_base;