diff --git a/.buildkite/cargo-rustfmt.json b/.buildkite/cargo-rustfmt.json new file mode 100644 index 000000000..039c5ebe4 --- /dev/null +++ b/.buildkite/cargo-rustfmt.json @@ -0,0 +1,9 @@ +{ + "tests": [ + { + "test_name": "staging: style", + "command": "cd staging && cargo +nightly fmt --all -- --config-path rustfmt.toml --check" + } + ] +} + diff --git a/.git-blame-ignore-revs b/.git-blame-ignore-revs new file mode 100644 index 000000000..3cde3281a --- /dev/null +++ b/.git-blame-ignore-revs @@ -0,0 +1,2 @@ +# staging: fix rustfmt lints from previous commit +61d211d1069631ed185d5799f92ae0498af7b9a3 diff --git a/staging/rustfmt.toml b/staging/rustfmt.toml new file mode 100644 index 000000000..35d818818 --- /dev/null +++ b/staging/rustfmt.toml @@ -0,0 +1,76 @@ +edition = "2021" +# 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 diff --git a/staging/vhost-device-sound/Cargo.toml b/staging/vhost-device-sound/Cargo.toml index 9bf2b7014..d896ba5cb 100644 --- a/staging/vhost-device-sound/Cargo.toml +++ b/staging/vhost-device-sound/Cargo.toml @@ -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"] diff --git a/staging/vhost-device-sound/rustfmt.toml b/staging/vhost-device-sound/rustfmt.toml deleted file mode 100644 index c6f0942d7..000000000 --- a/staging/vhost-device-sound/rustfmt.toml +++ /dev/null @@ -1,7 +0,0 @@ -edition = "2018" -format_generated_files = false -format_code_in_doc_comments = true -format_strings = true -imports_granularity = "Crate" -group_imports = "StdExternalCrate" -wrap_comments = true diff --git a/staging/vhost-device-sound/src/audio_backends/alsa.rs b/staging/vhost-device-sound/src/audio_backends/alsa.rs index d219fda1f..ae94db528 100644 --- a/staging/vhost-device-sound/src/audio_backends/alsa.rs +++ b/staging/vhost-device-sound/src/audio_backends/alsa.rs @@ -1,5 +1,4 @@ /// Alsa backend -// // Manos Pitsidianakis // SPDX-License-Identifier: Apache-2.0 or BSD-3-Clause use std::{ @@ -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 @@ -746,9 +750,4 @@ impl AudioBackend for AlsaBackend { } Ok(()) } - - send_action! { - ctrl set_parameters SetParameters, - ctrl release Release, - } } diff --git a/staging/vhost-device-sound/src/audio_backends/pipewire.rs b/staging/vhost-device-sound/src/audio_backends/pipewire.rs index 1f472cded..12ca6f106 100644 --- a/staging/vhost-device-sound/src/audio_backends/pipewire.rs +++ b/staging/vhost-device-sound/src/audio_backends/pipewire.rs @@ -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"); diff --git a/staging/vhost-device-sound/src/device.rs b/staging/vhost-device-sound/src/device.rs index 5dff291ec..b4a7eae05 100644 --- a/staging/vhost-device-sound/src/device.rs +++ b/staging/vhost-device-sound/src/device.rs @@ -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 @@ -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); diff --git a/staging/vhost-device-sound/src/stream.rs b/staging/vhost-device-sound/src/stream.rs index 8dfb4ccfd..38006fc1c 100644 --- a/staging/vhost-device-sound/src/stream.rs +++ b/staging/vhost-device-sound/src/stream.rs @@ -121,10 +121,6 @@ macro_rules! set_new_state { } impl PCMState { - pub fn new() -> Self { - Self::default() - } - set_new_state!( set_parameters, Self::SetParameters, @@ -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 { diff --git a/staging/vhost-device-sound/src/virtio_sound.rs b/staging/vhost-device-sound/src/virtio_sound.rs index bb9744cf9..8a062331f 100644 --- a/staging/vhost-device-sound/src/virtio_sound.rs +++ b/staging/vhost-device-sound/src/virtio_sound.rs @@ -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, } @@ -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, @@ -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, diff --git a/staging/vhost-device-video/rustfmt.toml b/staging/vhost-device-video/rustfmt.toml deleted file mode 100644 index c6f0942d7..000000000 --- a/staging/vhost-device-video/rustfmt.toml +++ /dev/null @@ -1,7 +0,0 @@ -edition = "2018" -format_generated_files = false -format_code_in_doc_comments = true -format_strings = true -imports_granularity = "Crate" -group_imports = "StdExternalCrate" -wrap_comments = true diff --git a/staging/vhost-device-video/src/stream.rs b/staging/vhost-device-video/src/stream.rs index 88398b303..405bdf0e3 100644 --- a/staging/vhost-device-video/src/stream.rs +++ b/staging/vhost-device-video/src/stream.rs @@ -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) diff --git a/staging/vhost-device-video/src/vhu_video.rs b/staging/vhost-device-video/src/vhu_video.rs index 98903a20d..92d986a30 100644 --- a/staging/vhost-device-video/src/vhu_video.rs +++ b/staging/vhost-device-video/src/vhu_video.rs @@ -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 diff --git a/staging/vhost-device-video/src/vhu_video_thread.rs b/staging/vhost-device-video/src/vhu_video_thread.rs index 96018d426..674d27a53 100644 --- a/staging/vhost-device-video/src/vhu_video_thread.rs +++ b/staging/vhost-device-video/src/vhu_video_thread.rs @@ -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(); @@ -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(); diff --git a/staging/vhost-device-video/src/video.rs b/staging/vhost-device-video/src/video.rs index f3e4543b6..c48501e5b 100644 --- a/staging/vhost-device-video/src/video.rs +++ b/staging/vhost-device-video/src/video.rs @@ -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)] @@ -311,7 +311,7 @@ impl VideoCmd { ) -> vhu_video::Result { use self::VideoCmd::*; macro_rules! read_body { - ($a: expr) => { + ($a:expr) => { desc_chain.read_body(0, $a) }; } diff --git a/staging/vhost-device-video/src/video_backends/v4l2_decoder.rs b/staging/vhost-device-video/src/video_backends/v4l2_decoder.rs index db84f751c..df860c096 100644 --- a/staging/vhost-device-video/src/video_backends/v4l2_decoder.rs +++ b/staging/vhost-device-video/src/video_backends/v4l2_decoder.rs @@ -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)); @@ -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) } @@ -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() } }) @@ -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