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

staging: add workspace-wide rustfmt lints #552

Draft
wants to merge 6 commits into
base: main
Choose a base branch
from
Draft
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
9 changes: 9 additions & 0 deletions .buildkite/cargo-rustfmt.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"tests": [
{
"test_name": "staging: style",
"command": "cd staging && cargo +nightly fmt --all -- --config-path rustfmt.toml --check"
}
]
}

2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# staging: fix rustfmt lints from previous commit
61d211d1069631ed185d5799f92ae0498af7b9a3
76 changes: 76 additions & 0 deletions staging/rustfmt.toml
epilys marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
edition = "2021"
epilys marked this conversation as resolved.
Show resolved Hide resolved
# Format generated files. A file is considered generated if any of the first
# five lines contain a @generated comment marker. (default value is true)
format_generated_files = false
# Format code snippet included in doc comments. (default value is false)
format_code_in_doc_comments = true
# Format the metavariable matching patterns in macros. (default value is false)
format_macro_matchers = true
# Control the case of the letters in hexadecimal literal values (default value is Preserve)
hex_literal_case = "Upper"
match_block_trailing_comma = false
# Controls how imports are structured in use statements. Imports will be merged
# or split to the configured level of granularity. (default value is Preserve)
imports_granularity = "Crate"
# Unix or Windows line endings (default value is Auto)
newline_style = "Unix"
# Convert /* */ comments to // comments where possible. (default value is false)
normalize_comments = true
# Convert #![doc] and #[doc] attributes to //! and /// doc comments. (default value is false)
normalize_doc_attributes = true
# Reorder impl items. type and const are put first, then macros and methods. (default value is false)
reorder_impl_items = true
# Format string literals where necessary. (default value is false)
format_strings = true
# Discard existing import groups, and create three groups for:
#
# std, core and alloc,
# external crates,
# self, super and crate imports.
group_imports = "StdExternalCrate"
# Break comments to fit on the line (default value is false)
wrap_comments = true
# Minimum number of blank lines which must be put between items. If two items
# have fewer blank lines between them, additional blank lines are inserted.
# (default value is 0)
blank_lines_upper_bound = 1
# Replace strings of _ wildcards by a single .. in tuple patterns (default value is false)
condense_wildcard_suffixes = true
# Use field initialize shorthand if possible. (default value is false)
use_field_init_shorthand = true
# Which version of the formatting rules to use. Version::One is
# backwards-compatible with Rustfmt 1.0. Other versions are only backwards
# compatible within a major version number. (default value is "One"
version = "Two"

## Default values
#
## Max width for code snippets included in doc comments. Only used if
## format_code_in_doc_comments is true. (default value)
#doc_comment_code_block_width = 100
## Format the bodies of macros. (default value)
#format_macro_bodies = true
## Use tab characters for indentation, spaces for alignment. (default value)
#hard_tabs = false
## Indent style of imports (default value)
#imports_indent = "Block"
## Item layout inside a imports block. (default value)
#imports_layout = "Mixed"
## Indent on expressions or items. (default value)
#indent_style = "Block"
## (default value)
#max_width = 100
## Merge multiple derives into a single one. (default value)
#merge_derives = true
## Remove nested parens. (default value)
#remove_nested_parens = true
## Number of spaces per tab (default value)
#tab_spaces = 4
## How to handle trailing commas for lists (default value)
#trailing_comma = "Vertical"
## Add trailing semicolon after break, continue and return. (default value)
#trailing_semicolon = true
## Reorder import and extern crate statements alphabetically in groups (a group is separated by a newline). (default value)
#reorder_imports = true
## Reorder mod declarations alphabetically in group. (default value)
#reorder_modules = true
2 changes: 1 addition & 1 deletion staging/vhost-device-sound/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ readme = "README.md"
keywords = ["vhost", "sound", "virtio-sound", "virtio-snd", "virtio"]
categories = ["multimedia::audio", "virtualization"]
license = "Apache-2.0 OR BSD-3-Clause"
edition = "2018"
edition = "2021"

[features]
xen = ["vm-memory/xen", "vhost/xen", "vhost-user-backend/xen"]
Expand Down
7 changes: 0 additions & 7 deletions staging/vhost-device-sound/rustfmt.toml

This file was deleted.

11 changes: 5 additions & 6 deletions staging/vhost-device-sound/src/audio_backends/alsa.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
/// Alsa backend
//
// Manos Pitsidianakis <[email protected]>
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
use std::{
Expand Down Expand Up @@ -734,6 +733,11 @@ impl AudioBackend for AlsaBackend {
start Start,
}

send_action! {
ctrl set_parameters SetParameters,
ctrl release Release,
}

fn stop(&self, id: u32) -> CrateResult<()> {
if let Some(Err(err)) = self
.streams
Expand All @@ -746,9 +750,4 @@ impl AudioBackend for AlsaBackend {
}
Ok(())
}

send_action! {
ctrl set_parameters SetParameters,
ctrl release Release,
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ impl AudioBackend for PwBackend {
}
let mut param = [Pod::from_bytes(&value_clone).unwrap()];

//callback to negotiate new set of streams
// callback to negotiate new set of streams
stream
.update_params(&mut param)
.expect("could not update params");
Expand Down
4 changes: 2 additions & 2 deletions staging/vhost-device-sound/src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -698,8 +698,8 @@ impl VhostUserSoundBackend {
}

impl VhostUserBackend for VhostUserSoundBackend {
type Vring = VringRwLock;
type Bitmap = ();
type Vring = VringRwLock;

fn num_queues(&self) -> usize {
NUM_QUEUES as usize
Expand Down Expand Up @@ -1104,7 +1104,7 @@ mod tests {

let queues_per_thread = backend.queues_per_thread();
assert_eq!(queues_per_thread.len(), 1);
assert_eq!(queues_per_thread[0], 0xf);
assert_eq!(queues_per_thread[0], 0xF);

let config = backend.get_config(0, 8);
assert_eq!(config.len(), 8);
Expand Down
8 changes: 4 additions & 4 deletions staging/vhost-device-sound/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ macro_rules! set_new_state {
}

impl PCMState {
pub fn new() -> Self {
Self::default()
}

set_new_state!(
set_parameters,
Self::SetParameters,
Expand All @@ -142,6 +138,10 @@ impl PCMState {
set_new_state!(stop, Self::Stop, Self::Start);

set_new_state!(release, Self::Release, Self::Prepare | Self::Stop);

pub fn new() -> Self {
Self::default()
}
}

impl std::fmt::Display for PCMState {
Expand Down
12 changes: 6 additions & 6 deletions staging/vhost-device-sound/src/virtio_sound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -250,12 +250,12 @@ pub struct VirtioSoundJackInfo {
// reading its content from byte array.
unsafe impl ByteValued for VirtioSoundJackInfo {}

///If the VIRTIO_SND_JACK_F_REMAP feature bit is set in the jack information
/// If the VIRTIO_SND_JACK_F_REMAP feature bit is set in the jack information
/// Remap control request
#[derive(Copy, Clone, Debug, Default, PartialEq, Eq)]
#[repr(C)]
pub struct VirtioSoundJackRemap {
pub hdr: VirtioSoundJackHeader, /* .code = VIRTIO_SND_R_JACK_REMAP */
pub hdr: VirtioSoundJackHeader, // .code = VIRTIO_SND_R_JACK_REMAP
pub association: Le32,
pub sequence: Le32,
}
Expand All @@ -279,9 +279,9 @@ unsafe impl ByteValued for VirtioSoundPcmHeader {}
#[repr(C)]
pub struct VirtioSoundPcmInfo {
pub hdr: VirtioSoundInfo,
pub features: Le32, /* 1 << VIRTIO_SND_PCM_F_XXX */
pub formats: Le64, /* 1 << VIRTIO_SND_PCM_FMT_XXX */
pub rates: Le64, /* 1 << VIRTIO_SND_PCM_RATE_XXX */
pub features: Le32, // 1 << VIRTIO_SND_PCM_F_XXX
pub formats: Le64, // 1 << VIRTIO_SND_PCM_FMT_XXX
pub rates: Le64, // 1 << VIRTIO_SND_PCM_RATE_XXX
pub direction: u8,
pub channels_min: u8,
pub channels_max: u8,
Expand All @@ -299,7 +299,7 @@ pub struct VirtioSndPcmSetParams {
pub hdr: VirtioSoundPcmHeader,
pub buffer_bytes: Le32,
pub period_bytes: Le32,
pub features: Le32, /* 1 << VIRTIO_SND_PCM_F_XXX */
pub features: Le32, // 1 << VIRTIO_SND_PCM_F_XXX
pub channels: u8,
pub format: u8,
pub rate: u8,
Expand Down
7 changes: 0 additions & 7 deletions staging/vhost-device-video/rustfmt.toml

This file was deleted.

8 changes: 5 additions & 3 deletions staging/vhost-device-video/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,11 @@ mod tests {
assert!(stream.is_queue_streaming(QueueType::InputQueue));
assert!(stream.all_resources_state(QueueType::InputQueue, ResourceState::Queued));
// Resource can be found by index
assert!(stream
.find_resource_mut_by_index(0, QueueType::InputQueue)
.is_some());
assert!(
stream
.find_resource_mut_by_index(0, QueueType::InputQueue)
.is_some()
);
{
let res = stream
.find_resource_mut(resource_id, QueueType::InputQueue)
Expand Down
2 changes: 1 addition & 1 deletion staging/vhost-device-video/src/vhu_video.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,8 @@ impl VuVideoBackend {

/// VhostUserBackend trait methods
impl VhostUserBackendMut for VuVideoBackend {
type Vring = VringRwLock;
type Bitmap = ();
type Vring = VringRwLock;

fn num_queues(&self) -> usize {
NUM_QUEUES
Expand Down
26 changes: 16 additions & 10 deletions staging/vhost-device-video/src/vhu_video_thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -632,12 +632,16 @@ mod tests {
#[rstest]
fn test_video_poller(dummy_fd: EventFd) {
let poller = VideoPoller::new().unwrap();
assert!(poller
.add(dummy_fd.as_raw_fd(), PollerEvent::new(EventType::Write, 1))
.is_ok());
assert!(poller
.modify(dummy_fd.as_raw_fd(), PollerEvent::new(EventType::Read, 1))
.is_ok());
assert!(
poller
.add(dummy_fd.as_raw_fd(), PollerEvent::new(EventType::Write, 1))
.is_ok()
);
assert!(
poller
.modify(dummy_fd.as_raw_fd(), PollerEvent::new(EventType::Read, 1))
.is_ok()
);

// Poller captures a read event.
dummy_fd.write(1).unwrap();
Expand Down Expand Up @@ -786,10 +790,12 @@ mod tests {
);
thread.mem = Some(mem.clone());

assert!(thread
.poller
.add(dummy_fd.as_raw_fd(), PollerEvent::new(EventType::Read, 1))
.is_ok());
assert!(
thread
.poller
.add(dummy_fd.as_raw_fd(), PollerEvent::new(EventType::Read, 1))
.is_ok()
);

let vring = VringRwLock::new(mem, 0x1000).unwrap();
vring.set_queue_info(0x100, 0x200, 0x300).unwrap();
Expand Down
4 changes: 2 additions & 2 deletions staging/vhost-device-video/src/video.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause
#![allow(dead_code)] //TODO: remove
#![allow(dead_code)] // TODO: remove
// Struct definitions use the kernel-style naming for consistency
#![allow(non_camel_case_types)]

Expand Down Expand Up @@ -311,7 +311,7 @@ impl VideoCmd {
) -> vhu_video::Result<Self> {
use self::VideoCmd::*;
macro_rules! read_body {
($a: expr) => {
($a:expr) => {
desc_chain.read_body(0, $a)
};
}
Expand Down
32 changes: 15 additions & 17 deletions staging/vhost-device-video/src/video_backends/v4l2_decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,18 +398,16 @@ impl VideoBackend for V4L2Decoder {
for resource in stream.queued_resources_mut(queue_type) {
resource.ready_with(video::BufferFlags::ERR, 0);
}
/*
* QUEUE_CLEAR behaviour from virtio-video spec
* Return already queued buffers back from the input or the output queue
* of the device. The device SHOULD return all of the buffers from the
* respective queue as soon as possible without pushing the buffers through
* the processing pipeline.
*
* From v4l2 PoV we issue a VIDIOC_STREAMOFF on the queue which will abort
* or finish any DMA in progress, unlocks any user pointer buffers locked
* in physical memory, and it removes all buffers from the incoming and
* outgoing queues.
*/
// QUEUE_CLEAR behaviour from virtio-video spec
// Return already queued buffers back from the input or the output queue
// of the device. The device SHOULD return all of the buffers from the
// respective queue as soon as possible without pushing the buffers through
// the processing pipeline.
//
// From v4l2 PoV we issue a VIDIOC_STREAMOFF on the queue which will abort
// or finish any DMA in progress, unlocks any user pointer buffers locked
// in physical memory, and it removes all buffers from the incoming and
// outgoing queues.
if let Err(e) = v4l2r::ioctl::streamoff(stream, queue) {
warn!("streamoff failed: {}", e);
return Sync(video::CmdResponse::Error(InvalidParameter));
Expand Down Expand Up @@ -492,9 +490,9 @@ impl VideoBackend for V4L2Decoder {
return Sync(video::CmdResponse::Error(InvalidParameter));
};

/*if queue_type.direction() == v4l2r::QueueDirection::Capture {
todo!("compose on CAPTURE");
}*/
// if queue_type.direction() == v4l2r::QueueDirection::Capture {
// todo!("compose on CAPTURE");
// }

Sync(video::CmdResponse::OkNoData)
}
Expand Down Expand Up @@ -891,7 +889,7 @@ mod tests {
Some(v4l2_fmtdesc {
index,
type_: v4l2r::bindings::v4l2_buf_type_V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE,
pixelformat: 0x3231564e, // NV12
pixelformat: 0x3231564E, // NV12
// SAFETY: test environment only.
..unsafe { mem::zeroed() }
})
Expand Down Expand Up @@ -1106,7 +1104,7 @@ mod tests {
fn test_v4l2_backend_helpers(test_dir: TempDir) {
let v4l2_device = VideoDeviceMock::new(&test_dir);
let decoder = V4L2Decoder::new(Path::new(&v4l2_device.path)).unwrap();
let nv12 = u32::from_le(0x3231564e);
let nv12 = u32::from_le(0x3231564E);
assert_matches!(
V4L2Decoder::v4l2_get_selection(&decoder.video_device, video::QueueType::InputQueue),
None
Expand Down