mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
misc: Fix clippy error from beta compiler
Rust has a new way of constructing other error and clippy complains if
we are still using the older way to construct error message. Thus,
migrate to the new approach suggested by the clippy.
Warning from beta compiler:
error: this can be `std::io::Error::other(_)`
--> block/src/vhdx/mod.rs:142:17
|
| / std::io::Error::new(
| | std::io::ErrorKind::Other,
| | format!("Failed to update VHDx header: {e}"),
| | )
| |_________________^
|
= help: for further information visit
https://rust-lang.github.io/rust-clippy/master/index.html#io_other_error
help: use `std::io::Error::other`
std::io::Error::other(
format!("Failed to update VHDx header: {e}"),
Signed-off-by: Jinank Jain <jinankjain@microsoft.com>
This commit is contained in:
@@ -573,14 +573,12 @@ impl DeviceRelocation for AddressManager {
|
||||
.lock()
|
||||
.unwrap()
|
||||
.allocate_io_addresses(Some(GuestAddress(new_base)), len as GuestUsize, None)
|
||||
.ok_or_else(|| {
|
||||
io::Error::new(io::ErrorKind::Other, "failed allocating new IO range")
|
||||
})?;
|
||||
.ok_or_else(|| io::Error::other("failed allocating new IO range"))?;
|
||||
|
||||
// Update PIO bus
|
||||
self.io_bus
|
||||
.update_range(old_base, len, new_base, len)
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
|
||||
.map_err(io::Error::other)?;
|
||||
}
|
||||
PciBarRegionType::Memory32BitRegion | PciBarRegionType::Memory64BitRegion => {
|
||||
let allocators = if region_type == PciBarRegionType::Memory32BitRegion {
|
||||
@@ -604,12 +602,7 @@ impl DeviceRelocation for AddressManager {
|
||||
.lock()
|
||||
.unwrap()
|
||||
.allocate(Some(GuestAddress(new_base)), len as GuestUsize, Some(len))
|
||||
.ok_or_else(|| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"failed allocating new MMIO range",
|
||||
)
|
||||
})?;
|
||||
.ok_or_else(|| io::Error::other("failed allocating new MMIO range"))?;
|
||||
|
||||
break;
|
||||
}
|
||||
@@ -618,7 +611,7 @@ impl DeviceRelocation for AddressManager {
|
||||
// Update MMIO bus
|
||||
self.mmio_bus
|
||||
.update_range(old_base, len, new_base, len)
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
|
||||
.map_err(io::Error::other)?;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -637,18 +630,14 @@ impl DeviceRelocation for AddressManager {
|
||||
}
|
||||
|
||||
if !resource_updated {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!(
|
||||
"Couldn't find a resource with base 0x{old_base:x} for device {id}"
|
||||
),
|
||||
));
|
||||
return Err(io::Error::other(format!(
|
||||
"Couldn't find a resource with base 0x{old_base:x} for device {id}"
|
||||
)));
|
||||
}
|
||||
} else {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("Couldn't find device {id} from device tree"),
|
||||
));
|
||||
return Err(io::Error::other(format!(
|
||||
"Couldn't find device {id} from device tree"
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -659,10 +648,7 @@ impl DeviceRelocation for AddressManager {
|
||||
for (event, addr) in virtio_pci_dev.ioeventfds(old_base) {
|
||||
let io_addr = IoEventAddress::Mmio(addr);
|
||||
self.vm.unregister_ioevent(event, &io_addr).map_err(|e| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("failed to unregister ioevent: {e:?}"),
|
||||
)
|
||||
io::Error::other(format!("failed to unregister ioevent: {e:?}"))
|
||||
})?;
|
||||
}
|
||||
for (event, addr) in virtio_pci_dev.ioeventfds(new_base) {
|
||||
@@ -670,10 +656,7 @@ impl DeviceRelocation for AddressManager {
|
||||
self.vm
|
||||
.register_ioevent(event, &io_addr, None)
|
||||
.map_err(|e| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("failed to register ioevent: {e:?}"),
|
||||
)
|
||||
io::Error::other(format!("failed to register ioevent: {e:?}"))
|
||||
})?;
|
||||
}
|
||||
} else {
|
||||
@@ -691,10 +674,7 @@ impl DeviceRelocation for AddressManager {
|
||||
);
|
||||
|
||||
self.vm.remove_user_memory_region(mem_region).map_err(|e| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("failed to remove user memory region: {e:?}"),
|
||||
)
|
||||
io::Error::other(format!("failed to remove user memory region: {e:?}"))
|
||||
})?;
|
||||
|
||||
// Create new mapping by inserting new region to KVM.
|
||||
@@ -708,19 +688,15 @@ impl DeviceRelocation for AddressManager {
|
||||
);
|
||||
|
||||
self.vm.create_user_memory_region(mem_region).map_err(|e| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("failed to create user memory regions: {e:?}"),
|
||||
)
|
||||
io::Error::other(format!("failed to create user memory regions: {e:?}"))
|
||||
})?;
|
||||
|
||||
// Update shared memory regions to reflect the new mapping.
|
||||
shm_regions.addr = GuestAddress(new_base);
|
||||
virtio_dev.set_shm_regions(shm_regions).map_err(|e| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("failed to update shared memory regions: {e:?}"),
|
||||
)
|
||||
io::Error::other(format!(
|
||||
"failed to update shared memory regions: {e:?}"
|
||||
))
|
||||
})?;
|
||||
}
|
||||
}
|
||||
@@ -804,7 +780,7 @@ impl AccessPlatform for SevSnpPageAccessProxy {
|
||||
fn translate_gva(&self, base: u64, size: u64) -> std::result::Result<u64, std::io::Error> {
|
||||
self.vm
|
||||
.gain_page_access(base, size as u32)
|
||||
.map_err(|e| io::Error::new(io::ErrorKind::Other, e))?;
|
||||
.map_err(io::Error::other)?;
|
||||
Ok(base)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ impl InterruptRoute {
|
||||
let irq_fd = EventFd::new(libc::EFD_NONBLOCK)?;
|
||||
let gsi = allocator
|
||||
.allocate_gsi()
|
||||
.ok_or_else(|| io::Error::new(io::ErrorKind::Other, "Failed allocating new GSI"))?;
|
||||
.ok_or_else(|| io::Error::other("Failed allocating new GSI"))?;
|
||||
|
||||
Ok(InterruptRoute {
|
||||
gsi,
|
||||
@@ -42,12 +42,8 @@ impl InterruptRoute {
|
||||
|
||||
pub fn enable(&self, vm: &Arc<dyn hypervisor::Vm>) -> Result<()> {
|
||||
if !self.registered.load(Ordering::Acquire) {
|
||||
vm.register_irqfd(&self.irq_fd, self.gsi).map_err(|e| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("Failed registering irq_fd: {e}"),
|
||||
)
|
||||
})?;
|
||||
vm.register_irqfd(&self.irq_fd, self.gsi)
|
||||
.map_err(|e| io::Error::other(format!("Failed registering irq_fd: {e}")))?;
|
||||
|
||||
// Update internals to track the irq_fd as "registered".
|
||||
self.registered.store(true, Ordering::Release);
|
||||
@@ -58,12 +54,8 @@ impl InterruptRoute {
|
||||
|
||||
pub fn disable(&self, vm: &Arc<dyn hypervisor::Vm>) -> Result<()> {
|
||||
if self.registered.load(Ordering::Acquire) {
|
||||
vm.unregister_irqfd(&self.irq_fd, self.gsi).map_err(|e| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("Failed unregistering irq_fd: {e}"),
|
||||
)
|
||||
})?;
|
||||
vm.unregister_irqfd(&self.irq_fd, self.gsi)
|
||||
.map_err(|e| io::Error::other(format!("Failed unregistering irq_fd: {e}")))?;
|
||||
|
||||
// Update internals to track the irq_fd as "unregistered".
|
||||
self.registered.store(false, Ordering::Release);
|
||||
@@ -107,12 +99,9 @@ impl MsiInterruptGroup {
|
||||
entry_vec.push(entry.route);
|
||||
}
|
||||
|
||||
self.vm.set_gsi_routing(&entry_vec).map_err(|e| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("Failed setting GSI routing: {e}"),
|
||||
)
|
||||
})
|
||||
self.vm
|
||||
.set_gsi_routing(&entry_vec)
|
||||
.map_err(|e| io::Error::other(format!("Failed setting GSI routing: {e}")))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -152,10 +141,9 @@ impl InterruptSourceGroup for MsiInterruptGroup {
|
||||
return route.trigger();
|
||||
}
|
||||
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("trigger: Invalid interrupt index {index}"),
|
||||
))
|
||||
Err(io::Error::other(format!(
|
||||
"trigger: Invalid interrupt index {index}"
|
||||
)))
|
||||
}
|
||||
|
||||
fn notifier(&self, index: InterruptIndex) -> Option<EventFd> {
|
||||
@@ -203,10 +191,9 @@ impl InterruptSourceGroup for MsiInterruptGroup {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("update: Invalid interrupt index {index}"),
|
||||
))
|
||||
Err(io::Error::other(format!(
|
||||
"update: Invalid interrupt index {index}"
|
||||
)))
|
||||
}
|
||||
|
||||
fn set_gsi(&self) -> Result<()> {
|
||||
@@ -232,12 +219,7 @@ impl InterruptSourceGroup for LegacyUserspaceInterruptGroup {
|
||||
.lock()
|
||||
.unwrap()
|
||||
.service_irq(self.irq as usize)
|
||||
.map_err(|e| {
|
||||
io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
format!("failed to inject IRQ #{}: {:?}", self.irq, e),
|
||||
)
|
||||
})
|
||||
.map_err(|e| io::Error::other(format!("failed to inject IRQ #{}: {:?}", self.irq, e)))
|
||||
}
|
||||
|
||||
fn update(
|
||||
|
||||
Reference in New Issue
Block a user