Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rustfmt: run it on doc examples too #1368

Merged
merged 3 commits into from
Nov 11, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion api_server/src/parsed_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,6 @@ fn log_received_api_request(api_description: String) {
/// * `method` - one of `GET`, `PATCH`, `PUT`
/// * `path` - path of the API request
/// * `body` - body of the API request
///
fn describe(method: Method, path: &str, body: Option<&Body>) -> String {
match (path, body) {
("/mmds", Some(_)) | (_, None) => format!("synchronous {:?} request on {:?}", method, path),
Expand Down
5 changes: 0 additions & 5 deletions cpuid/src/bit_helper.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,9 @@ pub trait BitRangeExt<T> {
fn get_mask(&self) -> T;

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

/// Asserts if `self.is_valid()` returns true.
///
fn check(&self) {
assert!(self.is_valid(), "Invalid BitRange");
}
Expand Down Expand Up @@ -98,14 +96,11 @@ macro_rules! bit_range {
}

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

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

/// Reads the value stored within the specified range of bits
Expand Down
2 changes: 0 additions & 2 deletions cpuid/src/brand_string.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ const BRAND_STRING_AMD: &[u8] = b"AMD EPYC";
///
/// This is achieved by bypassing the `O(n)` indexing, heap allocation, and the unicode checks
/// done by `std::string::String`.
///
#[derive(Clone)]
pub struct BrandString {
/// Flattened buffer, holding an array of 32-bit register values.
Expand Down Expand Up @@ -62,7 +61,6 @@ impl BrandString {
const MAX_LEN: usize = Self::REG_BUF_SIZE * 4 - 1;

/// Creates an empty brand string (0-initialized)
///
fn new() -> Self {
Self {
reg_buf: [0; Self::REG_BUF_SIZE],
Expand Down
1 change: 0 additions & 1 deletion cpuid/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ pub fn get_cpuid(function: u32, count: u32) -> Result<CpuidResult, Error> {
}

/// Extracts the CPU vendor id from leaf 0x0.
///
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub fn get_vendor_id() -> Result<[u8; 12], Error> {
match get_cpuid(0, 0) {
Expand Down
1 change: 0 additions & 1 deletion cpuid/src/template/c3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,6 @@ fn update_extended_feature_info_entry(
}

/// Sets up the cpuid entries for a given VCPU following a C3 template.
///
struct C3CpuidTransformer {}

impl CpuidTransformer for C3CpuidTransformer {
Expand Down
1 change: 0 additions & 1 deletion cpuid/src/template/t2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ fn update_extended_feature_info_entry(
}

/// Sets up the cpuid entries for a given VCPU following a T2 template.
///
struct T2CpuidTransformer {}

impl CpuidTransformer for T2CpuidTransformer {
Expand Down
1 change: 0 additions & 1 deletion cpuid/src/transformer/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ pub fn update_cache_parameters_entry(
}

/// Replaces the `cpuid` entries corresponding to `function` with the entries from the host's cpuid.
///
pub fn use_host_cpuid_function(
cpuid: &mut CpuId,
function: u32,
Expand Down
7 changes: 0 additions & 7 deletions cpuid/src/transformer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use brand_string::Reg as BsReg;
use common::get_vendor_id;

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

Expand All @@ -44,7 +42,6 @@ impl VmSpec {
}

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

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

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

/// Gets the associated transformer for a cpuid entry
///
fn entry_transformer_fn(&self, _entry: &mut kvm_cpuid_entry2) -> Option<EntryTransformerFn> {
None
}
Expand Down
20 changes: 0 additions & 20 deletions devices/src/virtio/vsock/csm/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
/// consume it. If that data can't be forwarded straight to the host stream, we'll
/// have to store it in a buffer (and flush it at a later time). Vsock flow control
/// ensures that our TX buffer doesn't overflow.
///
// The code in this file is best read with a fresh memory of the vsock protocol inner-workings.
// To help with that, here is a
//
Expand Down Expand Up @@ -79,7 +78,6 @@
// 2. The receiver can be proactive, and send VSOCK_OP_CREDIT_UPDATE packet, whenever
// it thinks its peer's information is out of date.
// Our implementation uses the proactive approach.
//
use std::io::{ErrorKind, Read, Write};
use std::num::Wrapping;
use std::os::unix::io::{AsRawFd, RawFd};
Expand All @@ -94,7 +92,6 @@ use super::{ConnState, Error, PendingRx, PendingRxSet, Result};

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

/// Check if the connection has any pending packet addressed to the peer.
///
fn has_pending_rx(&self) -> bool {
!self.pending_rx.is_empty()
}
Expand All @@ -388,7 +382,6 @@ where
///
/// The connection is interested in being notified about EPOLLIN / EPOLLOUT events on the
/// host stream.
///
fn get_polled_fd(&self) -> RawFd {
self.stream.as_raw_fd()
}
Expand All @@ -399,7 +392,6 @@ where
/// - data is available to be read from the host stream, so that it can store an RW pending
/// RX indication; and
/// - data can be written to the host stream, and the TX buffer needs to be flushed.
///
fn get_polled_evset(&self) -> epoll::Events {
let mut evset = epoll::Events::empty();
if !self.tx_buf.is_empty() {
Expand All @@ -418,7 +410,6 @@ where
}

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

/// Create a new host-initiated connection object.
///
pub fn new_local_init(
stream: S,
local_cid: u64,
Expand Down Expand Up @@ -520,7 +509,6 @@ where

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

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

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

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

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

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

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

/// Prepare a packet header for transmission to our peer.
///
fn init_pkt<'a>(&self, pkt: &'a mut VsockPacket) -> &'a mut VsockPacket {
// Make sure the header is zeroed-out first.
// This looks sub-optimal, but it is actually optimized-out in the compiled code to be
Expand Down
10 changes: 0 additions & 10 deletions devices/src/virtio/vsock/csm/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
//
/// This module implements our vsock connection state machine. The heavy lifting is done by
/// `connection::VsockConnection`, while this file only defines some constants and helper structs.
///
mod connection;
mod txbuf;

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

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

/// A set of RX indications (`PendingRx` items).
///
struct PendingRxSet {
data: u16,
}

impl PendingRxSet {
/// Insert an item into the set.
///
fn insert(&mut self, it: PendingRx) {
self.data |= it.into_mask();
}

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

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

/// Check if the set is empty.
///
fn is_empty(&self) -> bool {
self.data == 0
}
}

/// Create a set containing only one item.
///
impl From<PendingRx> for PendingRxSet {
fn from(it: PendingRx) -> Self {
Self {
Expand Down
Loading