Skip to content

Commit b798309

Browse files
committed
chore(clippy): update code with new lints
With a new Rust version, new Clippy entered our repository. This commit aligns our codebase with guidance provided by new lints. Signed-off-by: Egor Lazarchuk <[email protected]>
1 parent c81078c commit b798309

35 files changed

+73
-94
lines changed

Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ resolver = "2"
99

1010
[workspace.lints.rust]
1111
missing_debug_implementations = "warn"
12+
unexpected_cfgs = { level = "warn", check-cfg = ['cfg(kani)'] }
1213

1314
[workspace.lints.clippy]
1415
ptr_as_ptr = "warn"

src/firecracker/src/api_server/request/actions.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ struct ActionBody {
3030

3131
pub(crate) fn parse_put_actions(body: &Body) -> Result<ParsedRequest, RequestError> {
3232
METRICS.put_api_requests.actions_count.inc();
33-
let action_body = serde_json::from_slice::<ActionBody>(body.raw()).map_err(|err| {
33+
let action_body = serde_json::from_slice::<ActionBody>(body.raw()).inspect_err(|_| {
3434
METRICS.put_api_requests.actions_fails.inc();
35-
err
3635
})?;
3736

3837
match action_body.action_type {

src/firecracker/src/api_server/request/boot_source.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ use super::Body;
1111
pub(crate) fn parse_put_boot_source(body: &Body) -> Result<ParsedRequest, RequestError> {
1212
METRICS.put_api_requests.boot_source_count.inc();
1313
Ok(ParsedRequest::new_sync(VmmAction::ConfigureBootSource(
14-
serde_json::from_slice::<BootSourceConfig>(body.raw()).map_err(|err| {
14+
serde_json::from_slice::<BootSourceConfig>(body.raw()).inspect_err(|_| {
1515
METRICS.put_api_requests.boot_source_fails.inc();
16-
err
1716
})?,
1817
)))
1918
}

src/firecracker/src/api_server/request/drive.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ pub(crate) fn parse_put_drive(
2020
return Err(RequestError::EmptyID);
2121
};
2222

23-
let device_cfg = serde_json::from_slice::<BlockDeviceConfig>(body.raw()).map_err(|err| {
23+
let device_cfg = serde_json::from_slice::<BlockDeviceConfig>(body.raw()).inspect_err(|_| {
2424
METRICS.put_api_requests.drive_fails.inc();
25-
err
2625
})?;
2726

2827
if id != device_cfg.drive_id {
@@ -51,9 +50,8 @@ pub(crate) fn parse_patch_drive(
5150
};
5251

5352
let block_device_update_cfg: BlockDeviceUpdateConfig =
54-
serde_json::from_slice::<BlockDeviceUpdateConfig>(body.raw()).map_err(|err| {
53+
serde_json::from_slice::<BlockDeviceUpdateConfig>(body.raw()).inspect_err(|_| {
5554
METRICS.patch_api_requests.drive_fails.inc();
56-
err
5755
})?;
5856

5957
if id != block_device_update_cfg.drive_id {

src/firecracker/src/api_server/request/logger.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ use super::Body;
1010
pub(crate) fn parse_put_logger(body: &Body) -> Result<ParsedRequest, RequestError> {
1111
METRICS.put_api_requests.logger_count.inc();
1212
let res = serde_json::from_slice::<vmm::logger::LoggerConfig>(body.raw());
13-
let config = res.map_err(|err| {
13+
let config = res.inspect_err(|_| {
1414
METRICS.put_api_requests.logger_fails.inc();
15-
err
1615
})?;
1716
Ok(ParsedRequest::new_sync(VmmAction::ConfigureLogger(config)))
1817
}

src/firecracker/src/api_server/request/machine_configuration.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ pub(crate) fn parse_get_machine_config() -> Result<ParsedRequest, RequestError>
1515

1616
pub(crate) fn parse_put_machine_config(body: &Body) -> Result<ParsedRequest, RequestError> {
1717
METRICS.put_api_requests.machine_cfg_count.inc();
18-
let config = serde_json::from_slice::<MachineConfig>(body.raw()).map_err(|err| {
18+
let config = serde_json::from_slice::<MachineConfig>(body.raw()).inspect_err(|_| {
1919
METRICS.put_api_requests.machine_cfg_fails.inc();
20-
err
2120
})?;
2221

2322
// Check for the presence of deprecated `cpu_template` field.
@@ -44,9 +43,8 @@ pub(crate) fn parse_put_machine_config(body: &Body) -> Result<ParsedRequest, Req
4443
pub(crate) fn parse_patch_machine_config(body: &Body) -> Result<ParsedRequest, RequestError> {
4544
METRICS.patch_api_requests.machine_cfg_count.inc();
4645
let config_update =
47-
serde_json::from_slice::<MachineConfigUpdate>(body.raw()).map_err(|err| {
46+
serde_json::from_slice::<MachineConfigUpdate>(body.raw()).inspect_err(|_| {
4847
METRICS.patch_api_requests.machine_cfg_fails.inc();
49-
err
5048
})?;
5149

5250
if config_update.is_empty() {

src/firecracker/src/api_server/request/metrics.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,8 @@ use super::Body;
1111
pub(crate) fn parse_put_metrics(body: &Body) -> Result<ParsedRequest, RequestError> {
1212
METRICS.put_api_requests.metrics_count.inc();
1313
Ok(ParsedRequest::new_sync(VmmAction::ConfigureMetrics(
14-
serde_json::from_slice::<MetricsConfig>(body.raw()).map_err(|err| {
14+
serde_json::from_slice::<MetricsConfig>(body.raw()).inspect_err(|_| {
1515
METRICS.put_api_requests.metrics_fails.inc();
16-
err
1716
})?,
1817
)))
1918
}

src/firecracker/src/api_server/request/mmds.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,8 @@ pub(crate) fn parse_get_mmds() -> Result<ParsedRequest, RequestError> {
1616
}
1717

1818
fn parse_put_mmds_config(body: &Body) -> Result<ParsedRequest, RequestError> {
19-
let config: MmdsConfig = serde_json::from_slice(body.raw()).map_err(|err| {
19+
let config: MmdsConfig = serde_json::from_slice(body.raw()).inspect_err(|_| {
2020
METRICS.put_api_requests.mmds_fails.inc();
21-
err
2221
})?;
2322
// Construct the `ParsedRequest` object.
2423
let version = config.version;
@@ -42,9 +41,8 @@ pub(crate) fn parse_put_mmds(
4241
METRICS.put_api_requests.mmds_count.inc();
4342
match path_second_token {
4443
None => Ok(ParsedRequest::new_sync(VmmAction::PutMMDS(
45-
serde_json::from_slice(body.raw()).map_err(|err| {
44+
serde_json::from_slice(body.raw()).inspect_err(|_| {
4645
METRICS.put_api_requests.mmds_fails.inc();
47-
err
4846
})?,
4947
))),
5048
Some("config") => parse_put_mmds_config(body),
@@ -61,9 +59,8 @@ pub(crate) fn parse_put_mmds(
6159
pub(crate) fn parse_patch_mmds(body: &Body) -> Result<ParsedRequest, RequestError> {
6260
METRICS.patch_api_requests.mmds_count.inc();
6361
Ok(ParsedRequest::new_sync(VmmAction::PatchMMDS(
64-
serde_json::from_slice(body.raw()).map_err(|err| {
62+
serde_json::from_slice(body.raw()).inspect_err(|_| {
6563
METRICS.patch_api_requests.mmds_fails.inc();
66-
err
6764
})?,
6865
)))
6966
}

src/firecracker/src/api_server/request/net.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,8 @@ pub(crate) fn parse_put_net(
2020
return Err(RequestError::EmptyID);
2121
};
2222

23-
let netif = serde_json::from_slice::<NetworkInterfaceConfig>(body.raw()).map_err(|err| {
23+
let netif = serde_json::from_slice::<NetworkInterfaceConfig>(body.raw()).inspect_err(|_| {
2424
METRICS.put_api_requests.network_fails.inc();
25-
err
2625
})?;
2726
if id != netif.iface_id.as_str() {
2827
METRICS.put_api_requests.network_fails.inc();
@@ -53,9 +52,8 @@ pub(crate) fn parse_patch_net(
5352
};
5453

5554
let netif =
56-
serde_json::from_slice::<NetworkInterfaceUpdateConfig>(body.raw()).map_err(|err| {
55+
serde_json::from_slice::<NetworkInterfaceUpdateConfig>(body.raw()).inspect_err(|_| {
5756
METRICS.patch_api_requests.network_fails.inc();
58-
err
5957
})?;
6058
if id != netif.iface_id {
6159
METRICS.patch_api_requests.network_count.inc();

src/firecracker/src/api_server/request/vsock.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ use super::Body;
1010

1111
pub(crate) fn parse_put_vsock(body: &Body) -> Result<ParsedRequest, RequestError> {
1212
METRICS.put_api_requests.vsock_count.inc();
13-
let vsock_cfg = serde_json::from_slice::<VsockDeviceConfig>(body.raw()).map_err(|err| {
13+
let vsock_cfg = serde_json::from_slice::<VsockDeviceConfig>(body.raw()).inspect_err(|_| {
1414
METRICS.put_api_requests.vsock_fails.inc();
15-
err
1615
})?;
1716

1817
// Check for the presence of deprecated `vsock_id` field.

src/vmm/src/devices/legacy/serial.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ mod tests {
386386
),
387387
input: None::<std::io::Stdin>,
388388
};
389-
serial.serial.raw_input(&[b'a', b'b', b'c']).unwrap();
389+
serial.serial.raw_input(b"abc").unwrap();
390390

391391
let invalid_reads_before = metrics.missed_read_count.count();
392392
let mut v = [0x00; 2];

src/vmm/src/devices/virtio/balloon/metrics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
//!
3232
//! The system implements 1 type of metrics:
3333
//! * Shared Incremental Metrics (SharedIncMetrics) - dedicated for the metrics which need a counter
34-
//! (i.e the number of times an API request failed). These metrics are reset upon flush.
34+
//! (i.e the number of times an API request failed). These metrics are reset upon flush.
3535
3636
use serde::ser::SerializeMap;
3737
use serde::{Serialize, Serializer};

src/vmm/src/devices/virtio/block/virtio/metrics.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
//!
7373
//! The system implements 1 type of metrics:
7474
//! * Shared Incremental Metrics (SharedIncMetrics) - dedicated for the metrics which need a counter
75-
//! (i.e the number of times an API request failed). These metrics are reset upon flush.
75+
//! (i.e the number of times an API request failed). These metrics are reset upon flush.
76+
//!
7677
//! We add BlockDeviceMetrics entries from block::metrics::METRICS into Block device instead of
7778
//! Block device having individual separate BlockDeviceMetrics entries because Block device is not
7879
//! accessible from signal handlers to flush metrics and block::metrics::METRICS is.

src/vmm/src/devices/virtio/iovec.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -264,10 +264,11 @@ impl<const L: u16> IoVecBufferMut<L> {
264264
// We use get_slice instead of `get_host_address` here in order to have the whole
265265
// range of the descriptor chain checked, i.e. [addr, addr + len) is a valid memory
266266
// region in the GuestMemoryMmap.
267-
let slice = mem.get_slice(desc.addr, desc.len as usize).map_err(|err| {
268-
self.vecs.pop_back(nr_iovecs);
269-
err
270-
})?;
267+
let slice = mem
268+
.get_slice(desc.addr, desc.len as usize)
269+
.inspect_err(|_| {
270+
self.vecs.pop_back(nr_iovecs);
271+
})?;
271272
// We need to mark the area of guest memory that will be mutated through this
272273
// IoVecBufferMut as dirty ahead of time, as we loose access to all
273274
// vm-memory related information after converting down to iovecs.
@@ -288,9 +289,8 @@ impl<const L: u16> IoVecBufferMut<L> {
288289
length = length
289290
.checked_add(desc.len)
290291
.ok_or(IoVecError::OverflowedDescriptor)
291-
.map_err(|err| {
292+
.inspect_err(|_| {
292293
self.vecs.pop_back(nr_iovecs);
293-
err
294294
})?;
295295

296296
next_descriptor = desc.next_descriptor();

src/vmm/src/devices/virtio/mmio.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ const MMIO_VERSION: u32 = 2;
3838
///
3939
/// 1. Mmio reads and writes must be sent to this device at what is referred to here as MMIO base.
4040
/// 1. `Mmio::queue_evts` must be installed at `virtio::NOTIFY_REG_OFFSET` offset from the MMIO
41-
/// base. Each event in the array must be signaled if the index is written at that offset.
41+
/// base. Each event in the array must be signaled if the index is written at that offset.
4242
/// 1. `Mmio::interrupt_evt` must signal an interrupt that the guest driver is listening to when it
43-
/// is written to.
43+
/// is written to.
4444
///
4545
/// Typically one page (4096 bytes) of MMIO address space is sufficient to handle this transport
4646
/// and inner virtio device.

src/vmm/src/devices/virtio/net/device.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -514,10 +514,9 @@ impl Net {
514514
NetError::VnetHeaderMissing
515515
})?;
516516

517-
let headers = frame_bytes_from_buf(&headers[..header_len]).map_err(|e| {
517+
let headers = frame_bytes_from_buf(&headers[..header_len]).inspect_err(|_| {
518518
error!("VNET headers missing in TX frame");
519519
net_metrics.tx_malformed_frames.inc();
520-
e
521520
})?;
522521

523522
if let Some(ns) = mmds_ns {

src/vmm/src/devices/virtio/net/metrics.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@
7575
//!
7676
//! The system implements 1 types of metrics:
7777
//! * Shared Incremental Metrics (SharedIncMetrics) - dedicated for the metrics which need a counter
78-
//! (i.e the number of times an API request failed). These metrics are reset upon flush.
78+
//! (i.e the number of times an API request failed). These metrics are reset upon flush.
79+
//!
7980
//! We use net::metrics::METRICS instead of adding an entry of NetDeviceMetrics
8081
//! in Net so that metrics are accessible to be flushed even from signal handlers.
8182

src/vmm/src/devices/virtio/queue.rs

+5-8
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,8 @@ impl Iterator for DescriptorIterator {
172172
type Item = DescriptorChain;
173173

174174
fn next(&mut self) -> Option<Self::Item> {
175-
self.0.take().map(|desc| {
175+
self.0.take().inspect(|desc| {
176176
self.0 = desc.next_descriptor();
177-
desc
178177
})
179178
}
180179
}
@@ -560,10 +559,9 @@ impl Queue {
560559
// index is bound by the queue size
561560
let desc_index = unsafe { self.avail_ring_ring_get(usize::from(idx)) };
562561

563-
DescriptorChain::checked_new(self.desc_table_ptr, self.actual_size(), desc_index).map(
564-
|dc| {
562+
DescriptorChain::checked_new(self.desc_table_ptr, self.actual_size(), desc_index).inspect(
563+
|_| {
565564
self.next_avail += Wrapping(1);
566-
dc
567565
},
568566
)
569567
}
@@ -575,9 +573,8 @@ impl Queue {
575573
}
576574

577575
/// Write used element into used_ring ring.
578-
/// - [`ring_index_offset`] is an offset added to
579-
/// the current [`self.next_used`] to obtain actual index
580-
/// into used_ring.
576+
/// - [`ring_index_offset`] is an offset added to the current [`self.next_used`] to obtain
577+
/// actual index into used_ring.
581578
pub fn write_used_element(
582579
&mut self,
583580
ring_index_offset: u16,

src/vmm/src/devices/virtio/rng/device.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,8 @@ impl Entropy {
119119
}
120120

121121
let mut rand_bytes = vec![0; self.buffer.len() as usize];
122-
rand::fill(&mut rand_bytes).map_err(|err| {
122+
rand::fill(&mut rand_bytes).inspect_err(|_| {
123123
METRICS.host_rng_fails.inc();
124-
err
125124
})?;
126125

127126
// It is ok to unwrap here. We are writing `iovec.len()` bytes at offset 0.

src/vmm/src/devices/virtio/rng/metrics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
//!
3232
//! The system implements 1 type of metrics:
3333
//! * Shared Incremental Metrics (SharedIncMetrics) - dedicated for the metrics which need a counter
34-
//! (i.e the number of times an API request failed). These metrics are reset upon flush.
34+
//! (i.e the number of times an API request failed). These metrics are reset upon flush.
3535
3636
use serde::ser::SerializeMap;
3737
use serde::{Serialize, Serializer};

src/vmm/src/devices/virtio/vhost_user_metrics.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@
6464
//!
6565
//! The system implements 2 type of metrics:
6666
//! * Shared Incremental Metrics (SharedIncMetrics) - dedicated for the metrics which need a counter
67-
//! (i.e the number of times activating a device failed). These metrics are reset upon flush.
67+
//! (i.e the number of times activating a device failed). These metrics are reset upon flush.
6868
//! * Shared Store Metrics (SharedStoreMetrics) - are targeted at keeping a persistent value, it is
6969
//! `not` intended to act as a counter (i.e for measure the process start up time for example).
70+
//!
7071
//! We add VhostUserDeviceMetrics entries from vhost_user_metrics::METRICS into vhost_user device
7172
//! instead of vhost_user device having individual separate VhostUserDeviceMetrics entries because
7273
//! vhost_user device is not accessible from signal handlers to flush metrics and

src/vmm/src/devices/virtio/vsock/event_handler.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use std::fmt::Debug;
99

1010
/// The vsock object implements the runtime logic of our vsock device:
1111
/// 1. Respond to TX queue events by wrapping virtio buffers into `VsockPacket`s, then sending
12-
/// those packets to the `VsockBackend`;
12+
/// those packets to the `VsockBackend`;
1313
/// 2. Forward backend FD event notifications to the `VsockBackend`;
1414
/// 3. Fetch incoming packets from the `VsockBackend` and place them into the virtio RX queue;
1515
/// 4. Whenever we have processed some virtio buffers (either TX or RX), let the driver know by

src/vmm/src/devices/virtio/vsock/metrics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
//!
3535
//! The system implements 1 type of metrics:
3636
//! * Shared Incremental Metrics (SharedIncMetrics) - dedicated for the metrics which need a counter
37-
//! (i.e the number of times an API request failed). These metrics are reset upon flush.
37+
//! (i.e the number of times an API request failed). These metrics are reset upon flush.
3838
3939
use serde::ser::SerializeMap;
4040
use serde::{Serialize, Serializer};

src/vmm/src/devices/virtio/vsock/packet.rs

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//! virtio queue:
88
//! - the packet header; and
99
//! - the packet data/buffer.
10+
//!
1011
//! There is a 1:1 relation between descriptor chains and packets: the first (chain head) holds
1112
//! the header, and an optional second descriptor holds the data. The second descriptor is only
1213
//! present for data packets (VSOCK_OP_RW).

src/vmm/src/devices/virtio/vsock/unix/muxer.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,12 @@
2424
/// destination port to which it wants to connect);
2525
/// 3. Some event was triggered for a connected Unix socket, that belongs to a
2626
/// `VsockConnection`.
27-
/// The muxer gets notified about all of these events, because, as a `VsockEpollListener`
28-
/// implementor, it gets to register a nested epoll FD into the main VMM epolling loop. All
29-
/// other pollable FDs are then registered under this nested epoll FD.
30-
/// To route all these events to their handlers, the muxer uses another `HashMap` object,
31-
/// mapping `RawFd`s to `EpollListener`s.
27+
///
28+
/// The muxer gets notified about all of these events, because, as a `VsockEpollListener`
29+
/// implementor, it gets to register a nested epoll FD into the main VMM epolling loop. All
30+
/// other pollable FDs are then registered under this nested epoll FD.
31+
/// To route all these events to their handlers, the muxer uses another `HashMap` object,
32+
/// mapping `RawFd`s to `EpollListener`s.
3233
use std::collections::{HashMap, HashSet};
3334
use std::fmt::Debug;
3435
use std::io::Read;

src/vmm/src/devices/virtio/vsock/unix/muxer_rxq.rs

+1
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ impl MuxerRxQ {
6767
/// A push will fail when:
6868
/// - trying to push a connection key onto an out-of-sync, or full queue; or
6969
/// - trying to push an RST onto a queue already full of RSTs.
70+
///
7071
/// RSTs take precedence over connections, because connections can always be queried for
7172
/// pending RX data later. Aside from this queue, there is no other storage for RSTs, so
7273
/// failing to push one means that we have to drop the packet.

src/vmm/src/dumbo/pdu/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,7 @@ enum ChecksumProto {
6666
/// * `bytes` - Raw bytes of a TCP packet or a UDP datagram
6767
/// * `src_addr` - IPv4 source address
6868
/// * `dst_addr` - IPv4 destination address
69-
/// * `protocol` - **must** be either `PROTOCOL_TCP` or `PROTOCOL_UDP` defined in
70-
/// `ipv4` module
69+
/// * `protocol` - **must** be either `PROTOCOL_TCP` or `PROTOCOL_UDP` defined in `ipv4` module
7170
///
7271
/// More details about TCP checksum computation can be found [here].
7372
///

src/vmm/src/dumbo/tcp/endpoint.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -281,9 +281,8 @@ impl Endpoint {
281281
tcp_payload_src,
282282
timestamp_cycles(),
283283
) {
284-
Ok(write_result) => write_result.map(|segment| {
284+
Ok(write_result) => write_result.inspect(|segment| {
285285
self.response_seq += Wrapping(u32::from(segment.inner().payload_len()));
286-
segment
287286
}),
288287
Err(_) => {
289288
METRICS.mmds.tx_errors.inc();

0 commit comments

Comments
 (0)