Skip to content

Commit 99e1f24

Browse files
committed
rustfmt: run it on doc examples
Signed-off-by: Diana Popa <[email protected]>
1 parent 763a80c commit 99e1f24

File tree

37 files changed

+146
-290
lines changed

37 files changed

+146
-290
lines changed

api_server/src/parsed_request.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ fn log_received_api_request(api_description: String) {
114114
/// * `method` - one of `GET`, `PATCH`, `PUT`
115115
/// * `path` - path of the API request
116116
/// * `body` - body of the API request
117-
///
118117
fn describe(method: Method, path: &str, body: Option<&Body>) -> String {
119118
match (path, body) {
120119
("/mmds", Some(_)) | (_, None) => format!("synchronous {:?} request on {:?}", method, path),

cpuid/src/bit_helper.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,9 @@ pub trait BitRangeExt<T> {
6464
fn get_mask(&self) -> T;
6565

6666
/// Checks if the current BitRange is valid for type `T`.
67-
///
6867
fn is_valid(&self) -> bool;
6968

7069
/// Asserts if `self.is_valid()` returns true.
71-
///
7270
fn check(&self) {
7371
assert!(self.is_valid(), "Invalid BitRange");
7472
}
@@ -98,14 +96,11 @@ macro_rules! bit_range {
9896
}
9997

10098
/// Trait containing helper methods for bit operations.
101-
///
10299
pub trait BitHelper {
103100
/// Reads the value of the bit at position `pos`
104-
///
105101
fn read_bit(&self, pos: u32) -> bool;
106102

107103
/// Changes the value of the bit at position `pos` to `val`
108-
///
109104
fn write_bit(&mut self, pos: u32, val: bool) -> &mut Self;
110105

111106
/// Reads the value stored within the specified range of bits

cpuid/src/brand_string.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ const BRAND_STRING_AMD: &[u8] = b"AMD EPYC";
2626
///
2727
/// This is achieved by bypassing the `O(n)` indexing, heap allocation, and the unicode checks
2828
/// done by `std::string::String`.
29-
///
3029
#[derive(Clone)]
3130
pub struct BrandString {
3231
/// Flattened buffer, holding an array of 32-bit register values.
@@ -62,7 +61,6 @@ impl BrandString {
6261
const MAX_LEN: usize = Self::REG_BUF_SIZE * 4 - 1;
6362

6463
/// Creates an empty brand string (0-initialized)
65-
///
6664
fn new() -> Self {
6765
Self {
6866
reg_buf: [0; Self::REG_BUF_SIZE],

cpuid/src/common.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ pub fn get_cpuid(function: u32, count: u32) -> Result<CpuidResult, Error> {
5656
}
5757

5858
/// Extracts the CPU vendor id from leaf 0x0.
59-
///
6059
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
6160
pub fn get_vendor_id() -> Result<[u8; 12], Error> {
6261
match get_cpuid(0, 0) {

cpuid/src/template/c3.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ fn update_extended_feature_info_entry(
153153
}
154154

155155
/// Sets up the cpuid entries for a given VCPU following a C3 template.
156-
///
157156
struct C3CpuidTransformer {}
158157

159158
impl CpuidTransformer for C3CpuidTransformer {

cpuid/src/template/t2.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ fn update_extended_feature_info_entry(
144144
}
145145

146146
/// Sets up the cpuid entries for a given VCPU following a T2 template.
147-
///
148147
struct T2CpuidTransformer {}
149148

150149
impl CpuidTransformer for T2CpuidTransformer {

cpuid/src/transformer/common.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ pub fn update_cache_parameters_entry(
9898
}
9999

100100
/// Replaces the `cpuid` entries corresponding to `function` with the entries from the host's cpuid.
101-
///
102101
pub fn use_host_cpuid_function(
103102
cpuid: &mut CpuId,
104103
function: u32,

cpuid/src/transformer/mod.rs

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use brand_string::Reg as BsReg;
1313
use common::get_vendor_id;
1414

1515
/// Structure containing the specifications of the VM
16-
///
1716
pub struct VmSpec {
1817
/// The vendor id of the CPU
1918
cpu_vendor_id: [u8; 12],
@@ -30,7 +29,6 @@ pub struct VmSpec {
3029
impl VmSpec {
3130
/// Creates a new instance of VmSpec with the specified parameters
3231
/// The brand string is deduced from the vendor_id
33-
///
3432
pub fn new(cpu_id: u8, cpu_count: u8, ht_enabled: bool) -> Result<VmSpec, Error> {
3533
let cpu_vendor_id = get_vendor_id().map_err(Error::InternalError)?;
3634

@@ -44,7 +42,6 @@ impl VmSpec {
4442
}
4543

4644
/// Returns an immutable reference to cpu_vendor_id
47-
///
4845
pub fn cpu_vendor_id(&self) -> &[u8; 12] {
4946
&self.cpu_vendor_id
5047
}
@@ -65,17 +62,14 @@ pub type EntryTransformerFn =
6562
fn(entry: &mut kvm_cpuid_entry2, vm_spec: &VmSpec) -> Result<(), Error>;
6663

6764
/// Generic trait that provides methods for transforming the cpuid
68-
///
6965
pub trait CpuidTransformer {
7066
/// Trait main function. It processes the cpuid and makes the desired transformations.
7167
/// The default logic can be overwritten if needed. For example see `AmdCpuidTransformer`.
72-
///
7368
fn process_cpuid(&self, cpuid: &mut CpuId, vm_spec: &VmSpec) -> Result<(), Error> {
7469
self.process_entries(cpuid, vm_spec)
7570
}
7671

7772
/// Iterates through all the cpuid entries and calls the associated transformer for each one.
78-
///
7973
fn process_entries(&self, cpuid: &mut CpuId, vm_spec: &VmSpec) -> Result<(), Error> {
8074
for entry in cpuid.as_mut_slice().iter_mut() {
8175
let maybe_transformer_fn = self.entry_transformer_fn(entry);
@@ -89,7 +83,6 @@ pub trait CpuidTransformer {
8983
}
9084

9185
/// Gets the associated transformer for a cpuid entry
92-
///
9386
fn entry_transformer_fn(&self, _entry: &mut kvm_cpuid_entry2) -> Option<EntryTransformerFn> {
9487
None
9588
}

devices/src/virtio/vsock/csm/connection.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
/// consume it. If that data can't be forwarded straight to the host stream, we'll
2323
/// have to store it in a buffer (and flush it at a later time). Vsock flow control
2424
/// ensures that our TX buffer doesn't overflow.
25-
///
2625
// The code in this file is best read with a fresh memory of the vsock protocol inner-workings.
2726
// To help with that, here is a
2827
//
@@ -79,7 +78,6 @@
7978
// 2. The receiver can be proactive, and send VSOCK_OP_CREDIT_UPDATE packet, whenever
8079
// it thinks its peer's information is out of date.
8180
// Our implementation uses the proactive approach.
82-
//
8381
use std::io::{ErrorKind, Read, Write};
8482
use std::num::Wrapping;
8583
use std::os::unix::io::{AsRawFd, RawFd};
@@ -94,7 +92,6 @@ use super::{ConnState, Error, PendingRx, PendingRxSet, Result};
9492

9593
/// A self-managing connection object, that handles communication between a guest-side AF_VSOCK
9694
/// socket and a host-side `Read + Write + AsRawFd` stream.
97-
///
9895
pub struct VsockConnection<S: Read + Write + AsRawFd> {
9996
/// The current connection state.
10097
state: ConnState,
@@ -150,7 +147,6 @@ where
150147
/// packet;
151148
/// - `Err(VsockError::PktBufMissing)`: the packet would've been filled in with data, but
152149
/// it is missing the data buffer.
153-
///
154150
fn recv_pkt(&mut self, pkt: &mut VsockPacket) -> VsockResult<()> {
155151
// Perform some generic initialization that is the same for any packet operation (e.g.
156152
// source, destination, credit, etc).
@@ -264,7 +260,6 @@ where
264260
///
265261
/// Returns:
266262
/// always `Ok(())`: the packet has been consumed;
267-
///
268263
fn send_pkt(&mut self, pkt: &VsockPacket) -> VsockResult<()> {
269264
// Update the peer credit information.
270265
self.peer_buf_alloc = pkt.buf_alloc();
@@ -374,7 +369,6 @@ where
374369
}
375370

376371
/// Check if the connection has any pending packet addressed to the peer.
377-
///
378372
fn has_pending_rx(&self) -> bool {
379373
!self.pending_rx.is_empty()
380374
}
@@ -388,7 +382,6 @@ where
388382
///
389383
/// The connection is interested in being notified about EPOLLIN / EPOLLOUT events on the
390384
/// host stream.
391-
///
392385
fn get_polled_fd(&self) -> RawFd {
393386
self.stream.as_raw_fd()
394387
}
@@ -399,7 +392,6 @@ where
399392
/// - data is available to be read from the host stream, so that it can store an RW pending
400393
/// RX indication; and
401394
/// - data can be written to the host stream, and the TX buffer needs to be flushed.
402-
///
403395
fn get_polled_evset(&self) -> epoll::Events {
404396
let mut evset = epoll::Events::empty();
405397
if !self.tx_buf.is_empty() {
@@ -418,7 +410,6 @@ where
418410
}
419411

420412
/// Notify the connection about an event (or set of events) that it was interested in.
421-
///
422413
fn notify(&mut self, evset: epoll::Events) {
423414
if evset.contains(epoll::Events::EPOLLIN) {
424415
// Data can be read from the host stream. Setting a Rw pending indication, so that
@@ -464,7 +455,6 @@ where
464455
S: Read + Write + AsRawFd,
465456
{
466457
/// Create a new guest-initiated connection object.
467-
///
468458
pub fn new_peer_init(
469459
stream: S,
470460
local_cid: u64,
@@ -492,7 +482,6 @@ where
492482
}
493483

494484
/// Create a new host-initiated connection object.
495-
///
496485
pub fn new_local_init(
497486
stream: S,
498487
local_cid: u64,
@@ -520,7 +509,6 @@ where
520509

521510
/// Check if there is an expiry (kill) timer set for this connection, sometime in the
522511
/// future.
523-
///
524512
pub fn will_expire(&self) -> bool {
525513
match self.expiry {
526514
None => false,
@@ -530,7 +518,6 @@ where
530518

531519
/// Check if this connection needs to be scheduled for forceful termination, due to its
532520
/// kill timer having expired.
533-
///
534521
pub fn has_expired(&self) -> bool {
535522
match self.expiry {
536523
None => false,
@@ -539,14 +526,12 @@ where
539526
}
540527

541528
/// Get the kill timer value, if one is set.
542-
///
543529
pub fn expiry(&self) -> Option<Instant> {
544530
self.expiry
545531
}
546532

547533
/// Schedule the connection to be forcefully terminated ASAP (i.e. the next time the
548534
/// connection is asked to yield a packet, via `recv_pkt()`).
549-
///
550535
pub fn kill(&mut self) {
551536
self.state = ConnState::Killed;
552537
self.pending_rx.insert(PendingRx::Rst);
@@ -556,7 +541,6 @@ where
556541
///
557542
/// Raw data can either be sent straight to the host stream, or to our TX buffer, if the
558543
/// former fails.
559-
///
560544
fn send_bytes(&mut self, buf: &[u8]) -> Result<()> {
561545
// If there is data in the TX buffer, that means we're already registered for EPOLLOUT
562546
// events on the underlying stream. Therefore, there's no point in attempting a write
@@ -593,27 +577,23 @@ where
593577
}
594578

595579
/// Check if the credit information the peer has last received from us is outdated.
596-
///
597580
fn peer_needs_credit_update(&self) -> bool {
598581
(self.fwd_cnt - self.last_fwd_cnt_to_peer).0 as usize >= defs::CONN_CREDIT_UPDATE_THRESHOLD
599582
}
600583

601584
/// Check if we need to ask the peer for a credit update before sending any more data its
602585
/// way.
603-
///
604586
fn need_credit_update_from_peer(&self) -> bool {
605587
self.peer_avail_credit() == 0
606588
}
607589

608590
/// Get the maximum number of bytes that we can send to our peer, without overflowing its
609591
/// buffer.
610-
///
611592
fn peer_avail_credit(&self) -> usize {
612593
(Wrapping(self.peer_buf_alloc as u32) - (self.rx_cnt - self.peer_fwd_cnt)).0 as usize
613594
}
614595

615596
/// Prepare a packet header for transmission to our peer.
616-
///
617597
fn init_pkt<'a>(&self, pkt: &'a mut VsockPacket) -> &'a mut VsockPacket {
618598
// Make sure the header is zeroed-out first.
619599
// This looks sub-optimal, but it is actually optimized-out in the compiled code to be

devices/src/virtio/vsock/csm/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//
44
/// This module implements our vsock connection state machine. The heavy lifting is done by
55
/// `connection::VsockConnection`, while this file only defines some constants and helper structs.
6-
///
76
mod connection;
87
mod txbuf;
98

@@ -37,7 +36,6 @@ pub enum Error {
3736
type Result<T> = std::result::Result<T, Error>;
3837

3938
/// A vsock connection state.
40-
///
4139
#[derive(Debug, PartialEq)]
4240
pub enum ConnState {
4341
/// The connection has been initiated by the host end, but is yet to be confirmed by the guest.
@@ -60,7 +58,6 @@ pub enum ConnState {
6058
/// For instance, after being notified that there is available data to be read from the host stream
6159
/// (via `notify()`), the connection will store a `PendingRx::Rw` to be later inspected by
6260
/// `recv_pkt()`.
63-
///
6461
#[derive(Clone, Copy, PartialEq)]
6562
enum PendingRx {
6663
/// We need to yield a connection request packet (VSOCK_OP_REQUEST).
@@ -76,50 +73,43 @@ enum PendingRx {
7673
}
7774
impl PendingRx {
7875
/// Transform the enum value into a bitmask, that can be used for set operations.
79-
///
8076
fn into_mask(self) -> u16 {
8177
1u16 << (self as u16)
8278
}
8379
}
8480

8581
/// A set of RX indications (`PendingRx` items).
86-
///
8782
struct PendingRxSet {
8883
data: u16,
8984
}
9085

9186
impl PendingRxSet {
9287
/// Insert an item into the set.
93-
///
9488
fn insert(&mut self, it: PendingRx) {
9589
self.data |= it.into_mask();
9690
}
9791

9892
/// Remove an item from the set and return:
9993
/// - true, if the item was in the set; or
10094
/// - false, if the item wasn't in the set.
101-
///
10295
fn remove(&mut self, it: PendingRx) -> bool {
10396
let ret = self.contains(it);
10497
self.data &= !it.into_mask();
10598
ret
10699
}
107100

108101
/// Check if an item is present in this set.
109-
///
110102
fn contains(&self, it: PendingRx) -> bool {
111103
self.data & it.into_mask() != 0
112104
}
113105

114106
/// Check if the set is empty.
115-
///
116107
fn is_empty(&self) -> bool {
117108
self.data == 0
118109
}
119110
}
120111

121112
/// Create a set containing only one item.
122-
///
123113
impl From<PendingRx> for PendingRxSet {
124114
fn from(it: PendingRx) -> Self {
125115
Self {

0 commit comments

Comments
 (0)