Skip to content

Commit 92b9df3

Browse files
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 <[email protected]>
1 parent 55f5b29 commit 92b9df3

File tree

10 files changed

+59
-90
lines changed

10 files changed

+59
-90
lines changed

vhost-user-backend/src/event_loop.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -32,14 +32,14 @@ pub enum VringEpollError {
3232
impl Display for VringEpollError {
3333
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
3434
match self {
35-
VringEpollError::EpollCreateFd(e) => write!(f, "cannot create epoll fd: {}", e),
36-
VringEpollError::EpollWait(e) => write!(f, "failed to wait for epoll event: {}", e),
37-
VringEpollError::RegisterExitEvent(e) => write!(f, "cannot register exit event: {}", e),
35+
VringEpollError::EpollCreateFd(e) => write!(f, "cannot create epoll fd: {e}"),
36+
VringEpollError::EpollWait(e) => write!(f, "failed to wait for epoll event: {e}"),
37+
VringEpollError::RegisterExitEvent(e) => write!(f, "cannot register exit event: {e}"),
3838
VringEpollError::HandleEventReadKick(e) => {
39-
write!(f, "cannot read vring kick event: {}", e)
39+
write!(f, "cannot read vring kick event: {e}")
4040
}
4141
VringEpollError::HandleEventBackendHandling(e) => {
42-
write!(f, "failed to handle epoll event: {}", e)
42+
write!(f, "failed to handle epoll event: {e}")
4343
}
4444
}
4545
}
@@ -175,7 +175,7 @@ where
175175
Some(evset) => evset,
176176
None => {
177177
let evbits = event.events;
178-
println!("epoll: ignoring unknown event set: 0x{:x}", evbits);
178+
println!("epoll: ignoring unknown event set: 0x{evbits:x}");
179179
continue;
180180
}
181181
};

vhost-user-backend/src/handler.rs

Lines changed: 25 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,13 @@ impl std::fmt::Display for VhostUserHandlerError {
6161
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
6262
match self {
6363
VhostUserHandlerError::CreateVring(e) => {
64-
write!(f, "failed to create vring: {}", e)
64+
write!(f, "failed to create vring: {e}")
6565
}
6666
VhostUserHandlerError::CreateEpollHandler(e) => {
67-
write!(f, "failed to create vring epoll handler: {}", e)
67+
write!(f, "failed to create vring epoll handler: {e}")
6868
}
6969
VhostUserHandlerError::SpawnVringWorker(e) => {
70-
write!(f, "failed spawning the vring worker: {}", e)
70+
write!(f, "failed spawning the vring worker: {e}")
7171
}
7272
VhostUserHandlerError::MissingMemoryMapping => write!(f, "Missing memory mapping"),
7373
}
@@ -318,9 +318,7 @@ where
318318
region.mmap_region(file)?,
319319
GuestAddress(region.guest_phys_addr),
320320
)
321-
.map_err(|e| {
322-
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
323-
})?;
321+
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
324322
mappings.push(AddrMapping {
325323
#[cfg(feature = "postcopy")]
326324
local_addr: guest_region.as_ptr() as u64,
@@ -331,19 +329,16 @@ where
331329
regions.push(guest_region);
332330
}
333331

334-
let mem = GuestMemoryMmap::from_regions(regions).map_err(|e| {
335-
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
336-
})?;
332+
let mem = GuestMemoryMmap::from_regions(regions)
333+
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
337334

338335
// Updating the inner GuestMemory object here will cause all our vrings to
339336
// see the new one the next time they call to `atomic_mem.memory()`.
340337
self.atomic_mem.lock().unwrap().replace(mem);
341338

342339
self.backend
343340
.update_memory(self.atomic_mem.clone())
344-
.map_err(|e| {
345-
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
346-
})?;
341+
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
347342
self.mappings = mappings;
348343

349344
Ok(())
@@ -377,15 +372,15 @@ where
377372
.ok_or(VhostUserError::InvalidParam)?;
378373

379374
if !self.mappings.is_empty() {
380-
let desc_table = self.vmm_va_to_gpa(descriptor).map_err(|e| {
381-
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
382-
})?;
383-
let avail_ring = self.vmm_va_to_gpa(available).map_err(|e| {
384-
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
385-
})?;
386-
let used_ring = self.vmm_va_to_gpa(used).map_err(|e| {
387-
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
388-
})?;
375+
let desc_table = self
376+
.vmm_va_to_gpa(descriptor)
377+
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
378+
let avail_ring = self
379+
.vmm_va_to_gpa(available)
380+
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
381+
let used_ring = self
382+
.vmm_va_to_gpa(used)
383+
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
389384
vring
390385
.set_queue_info(desc_table, avail_ring, used_ring)
391386
.map_err(|_| VhostUserError::InvalidParam)?;
@@ -575,10 +570,7 @@ where
575570
fn get_shared_object(&mut self, uuid: VhostUserSharedMsg) -> VhostUserResult<File> {
576571
match self.backend.get_shared_object(uuid) {
577572
Ok(shared_file) => Ok(shared_file),
578-
Err(e) => Err(VhostUserError::ReqHandlerError(io::Error::new(
579-
io::ErrorKind::Other,
580-
e,
581-
))),
573+
Err(e) => Err(VhostUserError::ReqHandlerError(io::Error::other(e))),
582574
}
583575
}
584576

@@ -614,9 +606,7 @@ where
614606
region.mmap_region(file)?,
615607
GuestAddress(region.guest_phys_addr),
616608
)
617-
.map_err(|e| {
618-
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
619-
})?,
609+
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?,
620610
);
621611

622612
let addr_mapping = AddrMapping {
@@ -631,17 +621,13 @@ where
631621
.atomic_mem
632622
.memory()
633623
.insert_region(guest_region)
634-
.map_err(|e| {
635-
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
636-
})?;
624+
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
637625

638626
self.atomic_mem.lock().unwrap().replace(mem);
639627

640628
self.backend
641629
.update_memory(self.atomic_mem.clone())
642-
.map_err(|e| {
643-
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
644-
})?;
630+
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
645631

646632
self.mappings.push(addr_mapping);
647633

@@ -653,17 +639,13 @@ where
653639
.atomic_mem
654640
.memory()
655641
.remove_region(GuestAddress(region.guest_phys_addr), region.memory_size)
656-
.map_err(|e| {
657-
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
658-
})?;
642+
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
659643

660644
self.atomic_mem.lock().unwrap().replace(mem);
661645

662646
self.backend
663647
.update_memory(self.atomic_mem.clone())
664-
.map_err(|e| {
665-
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
666-
})?;
648+
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
667649

668650
self.mappings
669651
.retain(|mapping| mapping.gpa_base != region.guest_phys_addr);
@@ -697,9 +679,7 @@ where
697679
.non_blocking(true)
698680
.user_mode_only(false)
699681
.create()
700-
.map_err(|e| {
701-
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
702-
})?;
682+
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
703683

704684
// We need to duplicate the uffd fd because we need both
705685
// to return File with fd and store fd inside uffd.
@@ -725,8 +705,7 @@ where
725705
#[cfg(feature = "postcopy")]
726706
fn postcopy_listen(&mut self) -> VhostUserResult<()> {
727707
let Some(ref uffd) = self.uffd else {
728-
return Err(VhostUserError::ReqHandlerError(io::Error::new(
729-
io::ErrorKind::Other,
708+
return Err(VhostUserError::ReqHandlerError(io::Error::other(
730709
"No registered UFFD handler",
731710
)));
732711
};
@@ -736,9 +715,7 @@ where
736715
mapping.local_addr as *mut libc::c_void,
737716
mapping.size as usize,
738717
)
739-
.map_err(|e| {
740-
VhostUserError::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e))
741-
})?;
718+
.map_err(|e| VhostUserError::ReqHandlerError(io::Error::other(e)))?;
742719
}
743720

744721
Ok(())

vhost-user-backend/src/lib.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,17 @@ pub enum Error {
6767
impl Display for Error {
6868
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
6969
match self {
70-
Error::NewVhostUserHandler(e) => write!(f, "cannot create vhost user handler: {}", e),
71-
Error::CreateBackendListener(e) => write!(f, "cannot create backend listener: {}", e),
70+
Error::NewVhostUserHandler(e) => write!(f, "cannot create vhost user handler: {e}"),
71+
Error::CreateBackendListener(e) => write!(f, "cannot create backend listener: {e}"),
7272
Error::CreateBackendReqHandler(e) => {
73-
write!(f, "cannot create backend req handler: {}", e)
73+
write!(f, "cannot create backend req handler: {e}")
7474
}
7575
Error::CreateVhostUserListener(e) => {
76-
write!(f, "cannot create vhost-user listener: {}", e)
76+
write!(f, "cannot create vhost-user listener: {e}")
7777
}
78-
Error::StartDaemon(e) => write!(f, "failed to start daemon: {}", e),
78+
Error::StartDaemon(e) => write!(f, "failed to start daemon: {e}"),
7979
Error::WaitDaemon(_e) => write!(f, "failed to wait for daemon exit"),
80-
Error::HandleRequest(e) => write!(f, "failed to handle request: {}", e),
80+
Error::HandleRequest(e) => write!(f, "failed to handle request: {e}"),
8181
}
8282
}
8383
}

vhost/src/lib.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ impl std::fmt::Display for Error {
105105
Error::UsedAddress => write!(f, "invalid virtqueue used table address"),
106106
Error::AvailAddress => write!(f, "invalid virtqueue available table address"),
107107
Error::LogAddress => write!(f, "invalid virtqueue log address"),
108-
Error::IOError(e) => write!(f, "IO error: {}", e),
108+
Error::IOError(e) => write!(f, "IO error: {e}"),
109109
#[cfg(feature = "vhost-kern")]
110-
Error::VhostOpen(e) => write!(f, "failure in opening vhost file: {}", e),
110+
Error::VhostOpen(e) => write!(f, "failure in opening vhost file: {e}"),
111111
#[cfg(feature = "vhost-kern")]
112-
Error::IoctlError(e) => write!(f, "failure in vhost ioctl: {}", e),
112+
Error::IoctlError(e) => write!(f, "failure in vhost ioctl: {e}"),
113113
#[cfg(feature = "vhost-user")]
114-
Error::VhostUserProtocol(e) => write!(f, "vhost-user: {}", e),
114+
Error::VhostUserProtocol(e) => write!(f, "vhost-user: {e}"),
115115
}
116116
}
117117
}
@@ -176,6 +176,6 @@ mod tests {
176176
fn test_convert_from_vhost_user_error() {
177177
let e: Error = vhost_user::Error::OversizedMsg.into();
178178

179-
assert_eq!(format!("{}", e), "vhost-user: oversized message");
179+
assert_eq!(format!("{e}"), "vhost-user: oversized message");
180180
}
181181
}

vhost/src/vhost_kern/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ impl<T: VhostKernBackend> VhostBackend for T {
202202
/// # Arguments
203203
/// * `queue_index` - Index of the queue to set addresses for.
204204
/// * `config_data` - Vring config data, addresses of desc_table, avail_ring
205-
/// and used_ring are in the guest address space.
205+
/// and used_ring are in the guest address space.
206206
fn set_vring_addr(&self, queue_index: usize, config_data: &VringConfigData) -> Result<()> {
207207
if !self.is_valid(config_data) {
208208
return Err(Error::InvalidQueue);

vhost/src/vhost_kern/vdpa.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ impl<AS: GuestAddressSpace> VhostKernVdpa<AS> {
6767
/// # Arguments
6868
/// * `queue_index` - Index of the queue to set addresses for.
6969
/// * `config_data` - Vring config data, addresses of desc_table, avail_ring
70-
/// and used_ring are in the guest address space.
70+
/// and used_ring are in the guest address space.
7171
pub fn set_vring_addr(&self, queue_index: usize, config_data: &VringConfigData) -> Result<()> {
7272
if !self.is_valid(config_data) {
7373
return Err(Error::InvalidQueue);
@@ -509,7 +509,7 @@ mod tests {
509509
} else if device_id == 2 {
510510
(60, 1, 1, 1, 0)
511511
} else {
512-
panic!("Unexpected device id {}", device_id)
512+
panic!("Unexpected device id {device_id}")
513513
};
514514

515515
validate_ioctl!(vdpa.get_config_size(), config_size);

vhost/src/vhost_user/backend_req.rs

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ impl Backend {
109109
) -> io::Result<u64> {
110110
self.node()
111111
.send_message(request, body, fds)
112-
.map_err(|e| io::Error::new(io::ErrorKind::Other, format!("{}", e)))
112+
.map_err(|e| io::Error::other(format!("{e}")))
113113
}
114114

115115
/// Create a new instance from a `UnixStream` object.
@@ -146,21 +146,15 @@ impl VhostUserFrontendReqHandler for Backend {
146146
/// Forward vhost-user shared-object add request to the frontend.
147147
fn shared_object_add(&self, uuid: &VhostUserSharedMsg) -> HandlerResult<u64> {
148148
if !self.node().shared_object_negotiated {
149-
return Err(io::Error::new(
150-
io::ErrorKind::Other,
151-
"Shared Object feature not negotiated",
152-
));
149+
return Err(io::Error::other("Shared Object feature not negotiated"));
153150
}
154151
self.send_message(BackendReq::SHARED_OBJECT_ADD, uuid, None)
155152
}
156153

157154
/// Forward vhost-user shared-object remove request to the frontend.
158155
fn shared_object_remove(&self, uuid: &VhostUserSharedMsg) -> HandlerResult<u64> {
159156
if !self.node().shared_object_negotiated {
160-
return Err(io::Error::new(
161-
io::ErrorKind::Other,
162-
"Shared Object feature not negotiated",
163-
));
157+
return Err(io::Error::other("Shared Object feature not negotiated"));
164158
}
165159
self.send_message(BackendReq::SHARED_OBJECT_REMOVE, uuid, None)
166160
}
@@ -172,10 +166,7 @@ impl VhostUserFrontendReqHandler for Backend {
172166
fd: &dyn AsRawFd,
173167
) -> HandlerResult<u64> {
174168
if !self.node().shared_object_negotiated {
175-
return Err(io::Error::new(
176-
io::ErrorKind::Other,
177-
"Shared Object feature not negotiated",
178-
));
169+
return Err(io::Error::other("Shared Object feature not negotiated"));
179170
}
180171
self.send_message(
181172
BackendReq::SHARED_OBJECT_LOOKUP,

vhost/src/vhost_user/gpu_backend_req.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ struct BackendInternal {
2121
}
2222

2323
fn io_err_convert_fn(info: &str) -> impl Fn(vhost_user::Error) -> io::Error + '_ {
24-
move |e| io::Error::new(io::ErrorKind::Other, format!("{info}: {e}"))
24+
move |e| io::Error::other(format!("{info}: {e}"))
2525
}
2626

2727
impl BackendInternal {

vhost/src/vhost_user/message.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ impl VhostUserMemoryRegion {
551551
self.memory_size as usize,
552552
)
553553
.map_err(MmapError::MmapRegion)
554-
.map_err(|e| Error::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e)))
554+
.map_err(|e| Error::ReqHandlerError(io::Error::other(e)))
555555
}
556556

557557
fn is_valid(&self) -> bool {
@@ -592,7 +592,7 @@ impl VhostUserMemoryRegion {
592592

593593
MmapRegion::<B>::from_range(range)
594594
.map_err(MmapError::MmapRegion)
595-
.map_err(|e| Error::ReqHandlerError(io::Error::new(io::ErrorKind::Other, e)))
595+
.map_err(|e| Error::ReqHandlerError(io::Error::other(e)))
596596
}
597597

598598
fn is_valid(&self) -> bool {

vhost/src/vhost_user/mod.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ impl std::fmt::Display for Error {
105105
fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
106106
match self {
107107
Error::InvalidParam => write!(f, "invalid parameters"),
108-
Error::InvalidOperation(reason) => write!(f, "invalid operation: {}", reason),
108+
Error::InvalidOperation(reason) => write!(f, "invalid operation: {reason}"),
109109
Error::InactiveFeature(bits) => write!(f, "inactive feature: {}", bits.bits()),
110110
Error::InactiveOperation(bits) => {
111111
write!(f, "inactive protocol operation: {}", bits.bits())
@@ -115,14 +115,14 @@ impl std::fmt::Display for Error {
115115
Error::Disconnected => write!(f, "peer disconnected"),
116116
Error::OversizedMsg => write!(f, "oversized message"),
117117
Error::IncorrectFds => write!(f, "wrong number of attached fds"),
118-
Error::SocketError(e) => write!(f, "socket error: {}", e),
119-
Error::SocketConnect(e) => write!(f, "can't connect to peer: {}", e),
120-
Error::SocketBroken(e) => write!(f, "socket is broken: {}", e),
121-
Error::SocketRetry(e) => write!(f, "temporary socket error: {}", e),
118+
Error::SocketError(e) => write!(f, "socket error: {e}"),
119+
Error::SocketConnect(e) => write!(f, "can't connect to peer: {e}"),
120+
Error::SocketBroken(e) => write!(f, "socket is broken: {e}"),
121+
Error::SocketRetry(e) => write!(f, "temporary socket error: {e}"),
122122
Error::BackendInternalError => write!(f, "backend internal error"),
123123
Error::FrontendInternalError => write!(f, "Frontend internal error"),
124124
Error::FeatureMismatch => write!(f, "virtio/protocol features mismatch"),
125-
Error::ReqHandlerError(e) => write!(f, "handler failed to handle request: {}", e),
125+
Error::ReqHandlerError(e) => write!(f, "handler failed to handle request: {e}"),
126126
Error::MemFdCreateError => {
127127
write!(f, "handler failed to allocate memfd during get_inflight_fd")
128128
}
@@ -178,6 +178,7 @@ impl std::convert::From<vmm_sys_util::errno::Error> for Error {
178178
/// * - Error::SocketBroken: the underline socket is broken.
179179
/// * - Error::SocketError: other socket related errors.
180180
#[allow(unreachable_patterns)] // EWOULDBLOCK equals to EGAIN on linux
181+
#[allow(clippy::match_overlapping_arm)] // EWOULDBLOCK equals to EGAIN on linux
181182
fn from(err: vmm_sys_util::errno::Error) -> Self {
182183
match err.errno() {
183184
// The socket is marked nonblocking and the requested operation would block.

0 commit comments

Comments
 (0)