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: e4dee57e81 ("arch, pci, vmm: Initial switch to the hypervisor crate")
Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu 2020-06-22 16:31:42 +00:00 committed by Rob Bradford
parent cca59bc52f
commit 7552f4db61

View File

@ -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;