Skip to content

Commit c0958e9

Browse files
fix lint
1 parent b06c55a commit c0958e9

File tree

9 files changed

+38
-46
lines changed

9 files changed

+38
-46
lines changed

core/Cargo.toml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ clap = "2.33"
2929
criterion = { version = "0.3", optional = true }
3030
futures-lite = "1.11"
3131
libc = "0.2"
32-
metrics-core = { version = "0.5", optional = true }
33-
metrics-runtime = { version = "0.13", optional = true, default-features = false }
32+
metrics = "0.14"
3433
once_cell = "1.7"
3534
proptest = { version = "1.0", optional = true }
3635
regex = "1"
@@ -44,10 +43,9 @@ criterion = "0.3"
4443
proptest = { version = "1.0", default-features = false, features = ["default-code-coverage"] }
4544

4645
[features]
47-
default = ["metrics"]
46+
default = []
4847
compile_failure = [] # compiler tests to check mutability rules are followed
49-
full = ["metrics", "pcap-dump", "testils"]
50-
metrics = ["metrics-core", "metrics-runtime"]
48+
full = ["pcap-dump", "testils"]
5149
pcap-dump = []
5250
testils = ["criterion", "proptest"]
5351

core/src/ffi/dpdk.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ pub(crate) fn mempool_lookup<S: Into<String>>(name: S) -> Result<MempoolPtr> {
132132
}
133133

134134
/// Returns the number of elements which have been allocated from the mempool.
135+
#[allow(dead_code)]
135136
pub(crate) fn mempool_in_use_count(mp: &MempoolPtr) -> usize {
136137
unsafe { cffi::rte_mempool_in_use_count(mp.deref()) as usize }
137138
}
@@ -197,14 +198,14 @@ pub(crate) fn get_next_lcore(
197198

198199
match unsafe { cffi::rte_get_next_lcore(i, skip_master, wrap) } {
199200
cffi::RTE_MAX_LCORE => None,
200-
id @ _ => Some(LcoreId(id)),
201+
id => Some(LcoreId(id)),
201202
}
202203
}
203204

204205
/// The function passed to `rte_eal_remote_launch`.
205206
unsafe extern "C" fn lcore_fn<F>(arg: *mut raw::c_void) -> raw::c_int
206207
where
207-
F: FnOnce() -> () + Send + 'static,
208+
F: FnOnce() + Send + 'static,
208209
{
209210
let f = Box::from_raw(arg as *mut F);
210211

@@ -221,7 +222,7 @@ where
221222
/// Launches a function on another lcore.
222223
pub(crate) fn eal_remote_launch<F>(worker_id: LcoreId, f: F) -> Result<()>
223224
where
224-
F: FnOnce() -> () + Send + 'static,
225+
F: FnOnce() + Send + 'static,
225226
{
226227
let ptr = Box::into_raw(Box::new(f)) as *mut raw::c_void;
227228

@@ -299,11 +300,10 @@ pub(crate) fn eth_dev_adjust_nb_rx_tx_desc(
299300

300301
/// Returns the value of promiscuous mode for a device.
301302
pub(crate) fn eth_promiscuous_get(port_id: PortId) -> bool {
302-
match unsafe { cffi::rte_eth_promiscuous_get(port_id.0).into_result(DpdkError::from_errno) } {
303-
Ok(1) => true,
304-
// assuming port_id is valid, we treat error as mode disabled.
305-
_ => false,
306-
}
303+
let mode =
304+
unsafe { cffi::rte_eth_promiscuous_get(port_id.0).into_result(DpdkError::from_errno) };
305+
// assuming port_id is valid, treats Ok(0) and Err(_) both as disabled.
306+
matches!(mode, Ok(1))
307307
}
308308

309309
/// Enables receipt in promiscuous mode for a device.
@@ -326,11 +326,10 @@ pub(crate) fn eth_promiscuous_disable(port_id: PortId) -> Result<()> {
326326

327327
/// Returns the value of allmulticast mode for a device.
328328
pub(crate) fn eth_allmulticast_get(port_id: PortId) -> bool {
329-
match unsafe { cffi::rte_eth_allmulticast_get(port_id.0).into_result(DpdkError::from_errno) } {
330-
Ok(1) => true,
331-
// assuming port_id is valid, we treat error as mode disabled.
332-
_ => false,
333-
}
329+
let mode =
330+
unsafe { cffi::rte_eth_allmulticast_get(port_id.0).into_result(DpdkError::from_errno) };
331+
// assuming port_id is valid, treats Ok(0) and Err(_) both as disabled.
332+
matches!(mode, Ok(1))
334333
}
335334

336335
/// Enables the receipt of any multicast frame by a device.

core/src/ffi/pcap.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ use super::{AsStr, EasyPtr, ToCString, ToResult};
2020
use crate::ffi::dpdk::MbufPtr;
2121
use anyhow::Result;
2222
use capsule_ffi as cffi;
23-
use libc;
2423
use std::ops::DerefMut;
2524
use std::os::raw;
2625
use std::ptr;

core/src/lib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
//!
8383
//! ## Feature flags
8484
//!
85-
//! - `default`: Enables metrics by default.
85+
//! - `default`: None of the features are enabled.
8686
//! - `pcap-dump`: Enables capturing port traffic to `pcap` files.
8787
//! - `testils`: Enables utilities for unit testing and benchmarking.
8888
//! - `full`: Enables all features.
@@ -107,7 +107,6 @@
107107
//! [rr]: https://rr-project.org/
108108
//! [README]: https://github.com/capsule-rs/capsule/blob/master/README.md
109109
//! [sandbox repo]: https://github.com/capsule-rs/sandbox
110-
//! [`metrics`]: crate::metrics
111110
//! [kni]: https://github.com/capsule-rs/capsule/tree/master/examples/kni
112111
//! [nat64]: https://github.com/capsule-rs/capsule/tree/master/examples/nat64
113112
//! [ping4d]: https://github.com/capsule-rs/capsule/tree/master/examples/ping4d

core/src/packets/mbuf.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ impl Mbuf {
365365
/// free the raw pointer after use. Otherwise the buffer is leaked.
366366
#[inline]
367367
pub(crate) fn into_easyptr(self) -> MbufPtr {
368-
let ptr = self.inner.ptr().clone();
368+
let ptr = *self.inner.ptr();
369369
mem::forget(self);
370370
ptr.into()
371371
}

core/src/runtime/config.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ impl RuntimeConfig {
123123
}
124124
});
125125

126-
cores.sort();
126+
cores.sort_unstable();
127127
cores.dedup();
128128
cores
129129
}

core/src/runtime/lcore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ mod tests {
156156

157157
#[capsule::test]
158158
fn get_current_lcore_id_from_non_eal() {
159-
let lcore_id = thread::spawn(|| LcoreId::current()).join().expect("panic!");
159+
let lcore_id = thread::spawn(LcoreId::current).join().expect("panic!");
160160

161161
assert_eq!(LcoreId::ANY, lcore_id);
162162
}

core/src/runtime/pcap_dump.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,9 @@ impl Drop for CaptureFile {
7272
/// The pcap dump manager.
7373
pub(crate) struct PcapDump {
7474
output_dir: String,
75+
// we need the extra level of indirection because we need stable
76+
// pointers to pass to ffi code.
77+
#[allow(clippy::vec_box)]
7578
captures: Vec<Box<CaptureFile>>,
7679
}
7780

core/src/runtime/port.rs

Lines changed: 16 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ impl Port {
9090
self.outbox
9191
.as_ref()
9292
.map(|s| Outbox(self.name.clone(), s.clone()))
93-
.ok_or(PortError::TxNotEnabled.into())
93+
.ok_or_else(|| PortError::TxNotEnabled.into())
9494
}
9595

9696
/// Spawns the port receiving loop.
@@ -102,7 +102,7 @@ impl Port {
102102
let shutdown = self.shutdown.as_ref().unwrap();
103103

104104
// can't run loop without assigned rx cores.
105-
ensure!(self.rx_lcores.len() > 0, PortError::RxNotEnabled);
105+
ensure!(!self.rx_lcores.is_empty(), PortError::RxNotEnabled);
106106
// pipeline already set if the trigger is waited on.
107107
ensure!(!shutdown.is_waited(), PortError::PipelineSet);
108108

@@ -292,29 +292,23 @@ async fn tx_loop(
292292
let txq = PortTxQueue { port_id, queue_id };
293293
let mut ptrs = Vec::with_capacity(batch_size);
294294

295-
loop {
296-
if let Ok(ptr) = receiver.recv().await {
297-
ptrs.push(ptr);
298-
299-
// try to batch the packets up to batch size.
300-
for _ in 1..batch_size {
301-
match receiver.try_recv() {
302-
Ok(ptr) => ptrs.push(ptr),
303-
// no more packets to batch, ready to transmit.
304-
Err(_) => break,
305-
}
295+
while let Ok(ptr) = receiver.recv().await {
296+
ptrs.push(ptr);
297+
298+
// try to batch the packets up to batch size.
299+
for _ in 1..batch_size {
300+
match receiver.try_recv() {
301+
Ok(ptr) => ptrs.push(ptr),
302+
// no more packets to batch, ready to transmit.
303+
Err(_) => break,
306304
}
305+
}
307306

308-
txq.transmit(&mut ptrs);
307+
txq.transmit(&mut ptrs);
309308

310-
// cooperatively moves to the back of the execution queue,
311-
// making room for other tasks before transmitting again.
312-
future::yield_now().await;
313-
} else {
314-
// this branch can only be reached if the channel is closed,
315-
// indicating the tx loop should exit.
316-
break;
317-
}
309+
// cooperatively moves to the back of the execution queue,
310+
// making room for other tasks before transmitting again.
311+
future::yield_now().await;
318312
}
319313

320314
debug!(port = ?port_name, lcore = ?LcoreId::current(), "tx loop exited.");

0 commit comments

Comments
 (0)