build: treewide: clippy: collapse nested ifs, use let chains

This bumps the MSRV to 1.88 (also, Rust edition 2024 is mandatory).

Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
On-behalf-of: SAP philipp.schuster@sap.com
This commit is contained in:
Philipp Schuster
2025-08-15 09:00:01 +02:00
committed by Bo Chen
parent f73a6c8d8e
commit c995b72384
40 changed files with 574 additions and 608 deletions

View File

@@ -454,12 +454,11 @@ impl EpollHelperHandler for ConsoleEpollHandler {
}
if self.endpoint.is_pty() {
self.file_event_registered = false;
if event.events & libc::EPOLLHUP as u32 != 0 {
if let Some(pty_write_out) = &self.write_out {
if pty_write_out.load(Ordering::Acquire) {
pty_write_out.store(false, Ordering::Release);
}
}
if event.events & libc::EPOLLHUP as u32 != 0
&& let Some(pty_write_out) = &self.write_out
&& pty_write_out.load(Ordering::Acquire)
{
pty_write_out.store(false, Ordering::Release);
} else {
// If the EPOLLHUP flag is not up on the associated event, we
// can assume the other end of the PTY is connected and therefore
@@ -731,10 +730,10 @@ impl VirtioDevice for Console {
.acked_features
.store(self.common.acked_features, Ordering::Relaxed);
if self.common.feature_acked(VIRTIO_CONSOLE_F_SIZE) {
if let Err(e) = interrupt_cb.trigger(VirtioInterruptType::Config) {
error!("Failed to signal console driver: {:?}", e);
}
if self.common.feature_acked(VIRTIO_CONSOLE_F_SIZE)
&& let Err(e) = interrupt_cb.trigger(VirtioInterruptType::Config)
{
error!("Failed to signal console driver: {:?}", e);
}
let (kill_evt, pause_evt) = self.common.dup_eventfds();

View File

@@ -421,13 +421,12 @@ impl Request {
// If any other mappings exist in the domain for other containers,
// make sure to issue these mappings for the new endpoint/container
if let Some(domain_mappings) = &mapping.domains.read().unwrap().get(&domain_id)
&& let Some(ext_map) = ext_mapping.get(&endpoint)
{
if let Some(ext_map) = ext_mapping.get(&endpoint) {
for (virt_start, addr_map) in &domain_mappings.mappings {
ext_map
.map(*virt_start, addr_map.gpa, addr_map.size)
.map_err(Error::ExternalUnmapping)?;
}
for (virt_start, addr_map) in &domain_mappings.mappings {
ext_map
.map(*virt_start, addr_map.gpa, addr_map.size)
.map_err(Error::ExternalUnmapping)?;
}
}
@@ -654,13 +653,13 @@ fn detach_endpoint_from_domain(
mapping.endpoints.write().unwrap().remove(&endpoint);
// Trigger external unmapping for the endpoint if necessary.
if let Some(domain_mappings) = &mapping.domains.read().unwrap().get(&domain_id) {
if let Some(ext_map) = ext_mapping.get(&endpoint) {
for (virt_start, addr_map) in &domain_mappings.mappings {
ext_map
.unmap(*virt_start, addr_map.size)
.map_err(Error::ExternalUnmapping)?;
}
if let Some(domain_mappings) = &mapping.domains.read().unwrap().get(&domain_id)
&& let Some(ext_map) = ext_mapping.get(&endpoint)
{
for (virt_start, addr_map) in &domain_mappings.mappings {
ext_map
.unmap(*virt_start, addr_map.size)
.map_err(Error::ExternalUnmapping)?;
}
}

View File

@@ -475,11 +475,9 @@ impl MemEpollHandler {
return VIRTIO_MEM_RESP_ERROR;
}
if !plug {
if let Err(e) = self.discard_memory_range(offset, size) {
error!("failed discarding memory range: {:?}", e);
return VIRTIO_MEM_RESP_ERROR;
}
if !plug && let Err(e) = self.discard_memory_range(offset, size) {
error!("failed discarding memory range: {:?}", e);
return VIRTIO_MEM_RESP_ERROR;
}
self.blocks_state

View File

@@ -667,10 +667,10 @@ impl Drop for Net {
}
// Needed to ensure all references to tap FDs are dropped (#4868)
self.common.wait_for_epoll_threads();
if let Some(thread) = self.ctrl_queue_epoll_thread.take() {
if let Err(e) = thread.join() {
error!("Error joining thread: {:?}", e);
}
if let Some(thread) = self.ctrl_queue_epoll_thread.take()
&& let Err(e) = thread.join()
{
error!("Error joining thread: {:?}", e);
}
}
}

View File

@@ -36,12 +36,12 @@ where
thread::Builder::new()
.name(name.to_string())
.spawn(move || {
if !seccomp_filter.is_empty() {
if let Err(e) = apply_filter(&seccomp_filter) {
error!("Error applying seccomp filter: {:?}", e);
thread_exit_evt.write(1).ok();
return;
}
if !seccomp_filter.is_empty()
&& let Err(e) = apply_filter(&seccomp_filter)
{
error!("Error applying seccomp filter: {:?}", e);
thread_exit_evt.write(1).ok();
return;
}
match std::panic::catch_unwind(AssertUnwindSafe(f)) {
Err(_) => {

View File

@@ -261,36 +261,28 @@ impl VirtioPciCommonConfig {
let ready = value == 1;
q.set_ready(ready);
// Translate address of descriptor table and vrings.
if let Some(access_platform) = &self.access_platform {
if ready {
let desc_table = access_platform
.translate_gva(
q.desc_table(),
get_vring_size(VringType::Desc, q.size()),
)
.unwrap();
let avail_ring = access_platform
.translate_gva(
q.avail_ring(),
get_vring_size(VringType::Avail, q.size()),
)
.unwrap();
let used_ring = access_platform
.translate_gva(q.used_ring(), get_vring_size(VringType::Used, q.size()))
.unwrap();
q.set_desc_table_address(
Some((desc_table & 0xffff_ffff) as u32),
Some((desc_table >> 32) as u32),
);
q.set_avail_ring_address(
Some((avail_ring & 0xffff_ffff) as u32),
Some((avail_ring >> 32) as u32),
);
q.set_used_ring_address(
Some((used_ring & 0xffff_ffff) as u32),
Some((used_ring >> 32) as u32),
);
}
if ready && let Some(access_platform) = &self.access_platform {
let desc_table = access_platform
.translate_gva(q.desc_table(), get_vring_size(VringType::Desc, q.size()))
.unwrap();
let avail_ring = access_platform
.translate_gva(q.avail_ring(), get_vring_size(VringType::Avail, q.size()))
.unwrap();
let used_ring = access_platform
.translate_gva(q.used_ring(), get_vring_size(VringType::Used, q.size()))
.unwrap();
q.set_desc_table_address(
Some((desc_table & 0xffff_ffff) as u32),
Some((desc_table >> 32) as u32),
);
q.set_avail_ring_address(
Some((avail_ring & 0xffff_ffff) as u32),
Some((avail_ring >> 32) as u32),
);
q.set_used_ring_address(
Some((used_ring & 0xffff_ffff) as u32),
Some((used_ring >> 32) as u32),
);
}
}),
_ => {

View File

@@ -968,18 +968,17 @@ impl PciDevice for VirtioPciDevice {
if let Resource::PciBar {
index, base, type_, ..
} = resource
&& index == VIRTIO_COMMON_BAR_INDEX
{
if index == VIRTIO_COMMON_BAR_INDEX {
settings_bar_addr = Some(GuestAddress(base));
use_64bit_bar = match type_ {
PciBarType::Io => {
return Err(PciDeviceError::InvalidResource(resource));
}
PciBarType::Mmio32 => false,
PciBarType::Mmio64 => true,
};
break;
}
settings_bar_addr = Some(GuestAddress(base));
use_64bit_bar = match type_ {
PciBarType::Io => {
return Err(PciDeviceError::InvalidResource(resource));
}
PciBarType::Mmio32 => false,
PciBarType::Mmio64 => true,
};
break;
}
}
// Error out if no resource was matching the BAR id.

View File

@@ -213,16 +213,16 @@ impl Blk {
impl Drop for Blk {
fn drop(&mut self) {
if let Some(kill_evt) = self.common.kill_evt.take() {
if let Err(e) = kill_evt.write(1) {
error!("failed to kill vhost-user-blk: {:?}", e);
}
if let Some(kill_evt) = self.common.kill_evt.take()
&& let Err(e) = kill_evt.write(1)
{
error!("failed to kill vhost-user-blk: {:?}", e);
}
self.common.wait_for_epoll_threads();
if let Some(thread) = self.epoll_thread.take() {
if let Err(e) = thread.join() {
error!("Error joining thread: {:?}", e);
}
if let Some(thread) = self.epoll_thread.take()
&& let Err(e) = thread.join()
{
error!("Error joining thread: {:?}", e);
}
}
}
@@ -267,16 +267,15 @@ impl VirtioDevice for Blk {
}
self.config.writeback = data[0];
if let Some(vu) = &self.vu_common.vu {
if let Err(e) = vu
if let Some(vu) = &self.vu_common.vu
&& let Err(e) = vu
.lock()
.unwrap()
.socket_handle()
.set_config(offset as u32, VhostUserConfigFlags::WRITABLE, data)
.map_err(Error::VhostUserSetConfig)
{
error!("Failed setting vhost-user-blk configuration: {:?}", e);
}
{
error!("Failed setting vhost-user-blk configuration: {:?}", e);
}
}
@@ -329,11 +328,11 @@ impl VirtioDevice for Blk {
self.common.resume().ok()?;
}
if let Some(vu) = &self.vu_common.vu {
if let Err(e) = vu.lock().unwrap().reset_vhost_user() {
error!("Failed to reset vhost-user daemon: {:?}", e);
return None;
}
if let Some(vu) = &self.vu_common.vu
&& let Err(e) = vu.lock().unwrap().reset_vhost_user()
{
error!("Failed to reset vhost-user daemon: {:?}", e);
return None;
}
if let Some(kill_evt) = self.common.kill_evt.take() {

View File

@@ -227,10 +227,10 @@ impl Drop for Fs {
let _ = kill_evt.write(1);
}
self.common.wait_for_epoll_threads();
if let Some(thread) = self.epoll_thread.take() {
if let Err(e) = thread.join() {
error!("Error joining thread: {:?}", e);
}
if let Some(thread) = self.epoll_thread.take()
&& let Err(e) = thread.join()
{
error!("Error joining thread: {:?}", e);
}
}
}
@@ -308,11 +308,11 @@ impl VirtioDevice for Fs {
self.common.resume().ok()?;
}
if let Some(vu) = &self.vu_common.vu {
if let Err(e) = vu.lock().unwrap().reset_vhost_user() {
error!("Failed to reset vhost-user daemon: {:?}", e);
return None;
}
if let Some(vu) = &self.vu_common.vu
&& let Err(e) = vu.lock().unwrap().reset_vhost_user()
{
error!("Failed to reset vhost-user daemon: {:?}", e);
return None;
}
if let Some(kill_evt) = self.common.kill_evt.take() {

View File

@@ -243,23 +243,24 @@ impl Net {
impl Drop for Net {
fn drop(&mut self) {
if let Some(kill_evt) = self.common.kill_evt.take() {
if let Err(e) = kill_evt.write(1) {
error!("failed to kill vhost-user-net: {:?}", e);
}
if let Some(kill_evt) = self.common.kill_evt.take()
&& let Err(e) = kill_evt.write(1)
{
error!("failed to kill vhost-user-net: {:?}", e);
}
self.common.wait_for_epoll_threads();
if let Some(thread) = self.epoll_thread.take() {
if let Err(e) = thread.join() {
error!("Error joining thread: {:?}", e);
}
if let Some(thread) = self.epoll_thread.take()
&& let Err(e) = thread.join()
{
error!("Error joining thread: {:?}", e);
}
if let Some(thread) = self.ctrl_queue_epoll_thread.take() {
if let Err(e) = thread.join() {
error!("Error joining thread: {:?}", e);
}
if let Some(thread) = self.ctrl_queue_epoll_thread.take()
&& let Err(e) = thread.join()
{
error!("Error joining thread: {:?}", e);
}
}
}
@@ -382,11 +383,11 @@ impl VirtioDevice for Net {
self.common.resume().ok()?;
}
if let Some(vu) = &self.vu_common.vu {
if let Err(e) = vu.lock().unwrap().reset_vhost_user() {
error!("Failed to reset vhost-user daemon: {:?}", e);
return None;
}
if let Some(vu) = &self.vu_common.vu
&& let Err(e) = vu.lock().unwrap().reset_vhost_user()
{
error!("Failed to reset vhost-user daemon: {:?}", e);
return None;
}
if let Some(kill_evt) = self.common.kill_evt.take() {

View File

@@ -317,17 +317,16 @@ impl VhostUserHandle {
.get_features()
.map_err(Error::VhostUserGetFeatures)?;
if acked_features & VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits() != 0 {
if let Some(acked_protocol_features) =
if acked_features & VhostUserVirtioFeatures::PROTOCOL_FEATURES.bits() != 0
&& let Some(acked_protocol_features) =
VhostUserProtocolFeatures::from_bits(acked_protocol_features)
{
self.vu
.set_protocol_features(acked_protocol_features)
.map_err(Error::VhostUserSetProtocolFeatures)?;
{
self.vu
.set_protocol_features(acked_protocol_features)
.map_err(Error::VhostUserSetProtocolFeatures)?;
if acked_protocol_features.contains(VhostUserProtocolFeatures::REPLY_ACK) {
self.vu.set_hdr_flags(VhostUserHeaderFlag::NEED_REPLY);
}
if acked_protocol_features.contains(VhostUserProtocolFeatures::REPLY_ACK) {
self.vu.set_hdr_flags(VhostUserHeaderFlag::NEED_REPLY);
}
}

View File

@@ -437,10 +437,10 @@ impl VsockMuxer {
if let Some(EpollListener::LocalStream(stream)) = self.listener_map.get_mut(&fd) {
let port = Self::read_local_stream_port(&mut self.partial_command_map, stream);
if let Err(Error::UnixRead(ref e)) = port {
if e.kind() == ErrorKind::WouldBlock {
return;
}
if let Err(Error::UnixRead(ref e)) = port
&& e.kind() == ErrorKind::WouldBlock
{
return;
}
let stream = match self.remove_listener(fd) {

View File

@@ -111,11 +111,12 @@ impl MuxerKillQ {
/// the queue has expired. Otherwise, `None` is returned.
///
pub fn pop(&mut self) -> Option<ConnMapKey> {
if let Some(item) = self.q.front() {
if Instant::now() > item.kill_time {
return Some(self.q.pop_front().unwrap().key);
}
if let Some(item) = self.q.front()
&& Instant::now() > item.kill_time
{
return Some(self.q.pop_front().unwrap().key);
}
None
}