chore: fix new clippy warnings
clippy in the new rust toolchain (1.87) in our CI is highlighting something to improve. Mostly done with `cargo clippy --fix` + silence `clippy::match_overlapping_arm` since EWOULDBLOCK equals to EGAIN on linux. Signed-off-by: Stefano Garzarella <sgarzare@redhat.com>
This commit is contained in:
parent
55f5b29971
commit
92b9df3bfd
10 changed files with 59 additions and 90 deletions
|
|
@ -32,14 +32,14 @@ pub enum VringEpollError {
|
|||
impl Display for VringEpollError {
|
||||
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
VringEpollError::EpollCreateFd(e) => write!(f, "cannot create epoll fd: {}", e),
|
||||
VringEpollError::EpollWait(e) => write!(f, "failed to wait for epoll event: {}", e),
|
||||
VringEpollError::RegisterExitEvent(e) => write!(f, "cannot register exit event: {}", e),
|
||||
VringEpollError::EpollCreateFd(e) => write!(f, "cannot create epoll fd: {e}"),
|
||||
VringEpollError::EpollWait(e) => write!(f, "failed to wait for epoll event: {e}"),
|
||||
VringEpollError::RegisterExitEvent(e) => write!(f, "cannot register exit event: {e}"),
|
||||
VringEpollError::HandleEventReadKick(e) => {
|
||||
write!(f, "cannot read vring kick event: {}", e)
|
||||
write!(f, "cannot read vring kick event: {e}")
|
||||
}
|
||||
VringEpollError::HandleEventBackendHandling(e) => {
|
||||
write!(f, "failed to handle epoll event: {}", e)
|
||||
write!(f, "failed to handle epoll event: {e}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -175,7 +175,7 @@ where
|
|||
Some(evset) => evset,
|
||||
None => {
|
||||
let evbits = event.events;
|
||||
println!("epoll: ignoring unknown event set: 0x{:x}", evbits);
|
||||
println!("epoll: ignoring unknown event set: 0x{evbits:x}");
|
||||
continue;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -61,13 +61,13 @@ impl std::fmt::Display for VhostUserHandlerError {
|
|||
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
VhostUserHandlerError::CreateVring(e) => {
|
||||
write!(f, "failed to create vring: {}", e)
|
||||
write!(f, "failed to create vring: {e}")
|
||||
}
|
||||
VhostUserHandlerError::CreateEpollHandler(e) => {
|
||||
write!(f, "failed to create vring epoll handler: {}", e)
|
||||
write!(f, "failed to create vring epoll handler: {e}")
|
||||
}
|
||||
VhostUserHandlerError::SpawnVringWorker(e) => {
|
||||
write!(f, "failed spawning the vring worker: {}", e)
|
||||
write!(f, "failed spawning the vring worker: {e}")
|
||||
}
|
||||
VhostUserHandlerError::MissingMemoryMapping => write!(f, "Missing memory mapping"),
|
||||
}
|
||||
|
|
@ -318,9 +318,7 @@ where
|
|||
region.mmap_region(file)?,
|
||||
GuestAddress(region.guest_phys_addr),
|
||||
)
|
||||
.map_err(|e| {
|
||||
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
|
||||
})?;
|
||||
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
|
||||
mappings.push(AddrMapping {
|
||||
#[cfg(feature = "postcopy")]
|
||||
local_addr: guest_region.as_ptr() as u64,
|
||||
|
|
@ -331,9 +329,8 @@ where
|
|||
regions.push(guest_region);
|
||||
}
|
||||
|
||||
let mem = GuestMemoryMmap::from_regions(regions).map_err(|e| {
|
||||
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
|
||||
})?;
|
||||
let mem = GuestMemoryMmap::from_regions(regions)
|
||||
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
|
||||
|
||||
// Updating the inner GuestMemory object here will cause all our vrings to
|
||||
// see the new one the next time they call to `atomic_mem.memory()`.
|
||||
|
|
@ -341,9 +338,7 @@ where
|
|||
|
||||
self.backend
|
||||
.update_memory(self.atomic_mem.clone())
|
||||
.map_err(|e| {
|
||||
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
|
||||
})?;
|
||||
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
|
||||
self.mappings = mappings;
|
||||
|
||||
Ok(())
|
||||
|
|
@ -377,15 +372,15 @@ where
|
|||
.ok_or(VhostUserError::InvalidParam)?;
|
||||
|
||||
if !self.mappings.is_empty() {
|
||||
let desc_table = self.vmm_va_to_gpa(descriptor).map_err(|e| {
|
||||
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
|
||||
})?;
|
||||
let avail_ring = self.vmm_va_to_gpa(available).map_err(|e| {
|
||||
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
|
||||
})?;
|
||||
let used_ring = self.vmm_va_to_gpa(used).map_err(|e| {
|
||||
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
|
||||
})?;
|
||||
let desc_table = self
|
||||
.vmm_va_to_gpa(descriptor)
|
||||
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
|
||||
let avail_ring = self
|
||||
.vmm_va_to_gpa(available)
|
||||
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
|
||||
let used_ring = self
|
||||
.vmm_va_to_gpa(used)
|
||||
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
|
||||
vring
|
||||
.set_queue_info(desc_table, avail_ring, used_ring)
|
||||
.map_err(|_| VhostUserError::InvalidParam)?;
|
||||
|
|
@ -575,10 +570,7 @@ where
|
|||
fn get_shared_object(&mut self, uuid: VhostUserSharedMsg) -> VhostUserResult<File> {
|
||||
match self.backend.get_shared_object(uuid) {
|
||||
Ok(shared_file) => Ok(shared_file),
|
||||
Err(e) => Err(VhostUserError::ReqHandlerError(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
e,
|
||||
))),
|
||||
Err(e) => Err(VhostUserError::ReqHandlerError(io::Error::other(e))),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -614,9 +606,7 @@ where
|
|||
region.mmap_region(file)?,
|
||||
GuestAddress(region.guest_phys_addr),
|
||||
)
|
||||
.map_err(|e| {
|
||||
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
|
||||
})?,
|
||||
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?,
|
||||
);
|
||||
|
||||
let addr_mapping = AddrMapping {
|
||||
|
|
@ -631,17 +621,13 @@ where
|
|||
.atomic_mem
|
||||
.memory()
|
||||
.insert_region(guest_region)
|
||||
.map_err(|e| {
|
||||
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
|
||||
})?;
|
||||
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
|
||||
|
||||
self.atomic_mem.lock().unwrap().replace(mem);
|
||||
|
||||
self.backend
|
||||
.update_memory(self.atomic_mem.clone())
|
||||
.map_err(|e| {
|
||||
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
|
||||
})?;
|
||||
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
|
||||
|
||||
self.mappings.push(addr_mapping);
|
||||
|
||||
|
|
@ -653,17 +639,13 @@ where
|
|||
.atomic_mem
|
||||
.memory()
|
||||
.remove_region(GuestAddress(region.guest_phys_addr), region.memory_size)
|
||||
.map_err(|e| {
|
||||
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
|
||||
})?;
|
||||
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
|
||||
|
||||
self.atomic_mem.lock().unwrap().replace(mem);
|
||||
|
||||
self.backend
|
||||
.update_memory(self.atomic_mem.clone())
|
||||
.map_err(|e| {
|
||||
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
|
||||
})?;
|
||||
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
|
||||
|
||||
self.mappings
|
||||
.retain(|mapping| mapping.gpa_base != region.guest_phys_addr);
|
||||
|
|
@ -697,9 +679,7 @@ where
|
|||
.non_blocking(true)
|
||||
.user_mode_only(false)
|
||||
.create()
|
||||
.map_err(|e| {
|
||||
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
|
||||
})?;
|
||||
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
|
||||
|
||||
// We need to duplicate the uffd fd because we need both
|
||||
// to return File with fd and store fd inside uffd.
|
||||
|
|
@ -725,8 +705,7 @@ where
|
|||
#[cfg(feature = "postcopy")]
|
||||
fn postcopy_listen(&mut self) -> VhostUserResult<()> {
|
||||
let Some(ref uffd) = self.uffd else {
|
||||
return Err(VhostUserError::ReqHandlerError(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
return Err(VhostUserError::ReqHandlerError(io::Error::other(
|
||||
"No registered UFFD handler",
|
||||
)));
|
||||
};
|
||||
|
|
@ -736,9 +715,7 @@ where
|
|||
mapping.local_addr as *mut libc::c_void,
|
||||
mapping.size as usize,
|
||||
)
|
||||
.map_err(|e| {
|
||||
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
|
||||
})?;
|
||||
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
|
|
|||
|
|
@ -67,17 +67,17 @@ pub enum Error {
|
|||
impl Display for Error {
|
||||
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
|
||||
match self {
|
||||
Error::NewVhostUserHandler(e) => write!(f, "cannot create vhost user handler: {}", e),
|
||||
Error::CreateBackendListener(e) => write!(f, "cannot create backend listener: {}", e),
|
||||
Error::NewVhostUserHandler(e) => write!(f, "cannot create vhost user handler: {e}"),
|
||||
Error::CreateBackendListener(e) => write!(f, "cannot create backend listener: {e}"),
|
||||
Error::CreateBackendReqHandler(e) => {
|
||||
write!(f, "cannot create backend req handler: {}", e)
|
||||
write!(f, "cannot create backend req handler: {e}")
|
||||
}
|
||||
Error::CreateVhostUserListener(e) => {
|
||||
write!(f, "cannot create vhost-user listener: {}", e)
|
||||
write!(f, "cannot create vhost-user listener: {e}")
|
||||
}
|
||||
Error::StartDaemon(e) => write!(f, "failed to start daemon: {}", e),
|
||||
Error::StartDaemon(e) => write!(f, "failed to start daemon: {e}"),
|
||||
Error::WaitDaemon(_e) => write!(f, "failed to wait for daemon exit"),
|
||||
Error::HandleRequest(e) => write!(f, "failed to handle request: {}", e),
|
||||
Error::HandleRequest(e) => write!(f, "failed to handle request: {e}"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue