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:
Stefano Garzarella 2025-07-17 12:53:16 +02:00
parent 55f5b29971
commit 92b9df3bfd
10 changed files with 59 additions and 90 deletions

View file

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

View file

@ -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(())

View file

@ -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}"),
}
}
}

View file

@ -105,13 +105,13 @@ impl std::fmt::Display for Error {
Error::UsedAddress => write!(f, "invalid virtqueue used table address"),
Error::AvailAddress => write!(f, "invalid virtqueue available table address"),
Error::LogAddress => write!(f, "invalid virtqueue log address"),
Error::IOError(e) => write!(f, "IO error: {}", e),
Error::IOError(e) => write!(f, "IO error: {e}"),
#[cfg(feature = "vhost-kern")]
Error::VhostOpen(e) => write!(f, "failure in opening vhost file: {}", e),
Error::VhostOpen(e) => write!(f, "failure in opening vhost file: {e}"),
#[cfg(feature = "vhost-kern")]
Error::IoctlError(e) => write!(f, "failure in vhost ioctl: {}", e),
Error::IoctlError(e) => write!(f, "failure in vhost ioctl: {e}"),
#[cfg(feature = "vhost-user")]
Error::VhostUserProtocol(e) => write!(f, "vhost-user: {}", e),
Error::VhostUserProtocol(e) => write!(f, "vhost-user: {e}"),
}
}
}
@ -176,6 +176,6 @@ mod tests {
fn test_convert_from_vhost_user_error() {
let e: Error = vhost_user::Error::OversizedMsg.into();
assert_eq!(format!("{}", e), "vhost-user: oversized message");
assert_eq!(format!("{e}"), "vhost-user: oversized message");
}
}

View file

@ -509,7 +509,7 @@ mod tests {
} else if device_id == 2 {
(60, 1, 1, 1, 0)
} else {
panic!("Unexpected device id {}", device_id)
panic!("Unexpected device id {device_id}")
};
validate_ioctl!(vdpa.get_config_size(), config_size);

View file

@ -109,7 +109,7 @@ impl Backend {
) -> io::Result<u64> {
self.node()
.send_message(request, body, fds)
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("{}", e)))
.map_err(|e| io::Error::other(format!("{e}")))
}
/// Create a new instance from a `UnixStream` object.
@ -146,10 +146,7 @@ impl VhostUserFrontendReqHandler for Backend {
/// Forward vhost-user shared-object add request to the frontend.
fn shared_object_add(&self, uuid: &VhostUserSharedMsg) -> HandlerResult<u64> {
if !self.node().shared_object_negotiated {
return Err(io::Error::new(
io::ErrorKind::Other,
"Shared Object feature not negotiated",
));
return Err(io::Error::other("Shared Object feature not negotiated"));
}
self.send_message(BackendReq::SHARED_OBJECT_ADD, uuid, None)
}
@ -157,10 +154,7 @@ impl VhostUserFrontendReqHandler for Backend {
/// Forward vhost-user shared-object remove request to the frontend.
fn shared_object_remove(&self, uuid: &VhostUserSharedMsg) -> HandlerResult<u64> {
if !self.node().shared_object_negotiated {
return Err(io::Error::new(
io::ErrorKind::Other,
"Shared Object feature not negotiated",
));
return Err(io::Error::other("Shared Object feature not negotiated"));
}
self.send_message(BackendReq::SHARED_OBJECT_REMOVE, uuid, None)
}
@ -172,10 +166,7 @@ impl VhostUserFrontendReqHandler for Backend {
fd: &dyn AsRawFd,
) -> HandlerResult<u64> {
if !self.node().shared_object_negotiated {
return Err(io::Error::new(
io::ErrorKind::Other,
"Shared Object feature not negotiated",
));
return Err(io::Error::other("Shared Object feature not negotiated"));
}
self.send_message(
BackendReq::SHARED_OBJECT_LOOKUP,

View file

@ -21,7 +21,7 @@ struct BackendInternal {
}
fn io_err_convert_fn(info: &str) -> impl Fn(vhost_user::Error) -> io::Error + '_ {
move |e| io::Error::new(io::ErrorKind::Other, format!("{info}: {e}"))
move |e| io::Error::other(format!("{info}: {e}"))
}
impl BackendInternal {

View file

@ -551,7 +551,7 @@ impl VhostUserMemoryRegion {
self.memory_size as usize,
)
.map_err(MmapError::MmapRegion)
.map_err(|e| Error::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e)))
.map_err(|e| Error::ReqHandlerError(io::Error::other(e)))
}
fn is_valid(&self) -> bool {
@ -592,7 +592,7 @@ impl VhostUserMemoryRegion {
MmapRegion::<B>::from_range(range)
.map_err(MmapError::MmapRegion)
.map_err(|e| Error::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e)))
.map_err(|e| Error::ReqHandlerError(io::Error::other(e)))
}
fn is_valid(&self) -> bool {

View file

@ -105,7 +105,7 @@ impl std::fmt::Display for Error {
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
match self {
Error::InvalidParam => write!(f, "invalid parameters"),
Error::InvalidOperation(reason) => write!(f, "invalid operation: {}", reason),
Error::InvalidOperation(reason) => write!(f, "invalid operation: {reason}"),
Error::InactiveFeature(bits) => write!(f, "inactive feature: {}", bits.bits()),
Error::InactiveOperation(bits) => {
write!(f, "inactive protocol operation: {}", bits.bits())
@ -115,14 +115,14 @@ impl std::fmt::Display for Error {
Error::Disconnected => write!(f, "peer disconnected"),
Error::OversizedMsg => write!(f, "oversized message"),
Error::IncorrectFds => write!(f, "wrong number of attached fds"),
Error::SocketError(e) => write!(f, "socket error: {}", e),
Error::SocketConnect(e) => write!(f, "can't connect to peer: {}", e),
Error::SocketBroken(e) => write!(f, "socket is broken: {}", e),
Error::SocketRetry(e) => write!(f, "temporary socket error: {}", e),
Error::SocketError(e) => write!(f, "socket error: {e}"),
Error::SocketConnect(e) => write!(f, "can't connect to peer: {e}"),
Error::SocketBroken(e) => write!(f, "socket is broken: {e}"),
Error::SocketRetry(e) => write!(f, "temporary socket error: {e}"),
Error::BackendInternalError => write!(f, "backend internal error"),
Error::FrontendInternalError => write!(f, "Frontend internal error"),
Error::FeatureMismatch => write!(f, "virtio/protocol features mismatch"),
Error::ReqHandlerError(e) => write!(f, "handler failed to handle request: {}", e),
Error::ReqHandlerError(e) => write!(f, "handler failed to handle request: {e}"),
Error::MemFdCreateError => {
write!(f, "handler failed to allocate memfd during get_inflight_fd")
}
@ -178,6 +178,7 @@ impl std::convert::From<vmm_sys_util::errno::Error> for Error {
/// * - Error::SocketBroken: the underline socket is broken.
/// * - Error::SocketError: other socket related errors.
#[allow(unreachable_patterns)] // EWOULDBLOCK equals to EGAIN on linux
#[allow(clippy::match_overlapping_arm)] // EWOULDBLOCK equals to EGAIN on linux
fn from(err: vmm_sys_util::errno::Error) -> Self {
match err.errno() {
// The socket is marked nonblocking and the requested operation would block.