Skip to content

Commit

Permalink
Merge pull request #2787 from jprendes/rustfmt
Browse files Browse the repository at this point in the history
Add `rustfmt.toml` to standardize formatting
  • Loading branch information
utam0k authored May 16, 2024
2 parents 218cf18 + 20b4602 commit 2b86907
Show file tree
Hide file tree
Showing 162 changed files with 994 additions and 989 deletions.
6 changes: 6 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Ignore commits in the blame view
# see:
# https://docs.github.com/en/repositories/working-with-files/using-files/viewing-a-file#ignore-commits-in-the-blame-view

# Bulk apply formatting
13a3fd516e9904d5cd7ef20ead76dd70cd172fe7
4 changes: 3 additions & 1 deletion .github/workflows/basic.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ jobs:
- name: Setup Rust toolchain and cache
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
components: rustfmt, clippy
components: clippy
- name: Install nightly rustfmt
run: rustup toolchain install nightly --component rustfmt --profile minimal --no-self-update
- name: typos-action
uses: crate-ci/[email protected]
- name: Install just
Expand Down
12 changes: 4 additions & 8 deletions crates/libcgroups/examples/bpf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,15 @@ use anyhow::Result;

#[cfg(feature = "cgroupsv2_devices")]
mod bpf {
use anyhow::{bail, Result};
use clap::Arg;
use clap::Command;
use oci_spec::runtime::LinuxDeviceCgroup;
use std::os::unix::io::AsRawFd;
use std::path::Path;

use anyhow::{bail, Result};
use clap::{Arg, Command};
use libcgroups::v2::devices::{bpf, emulator, program};
use nix::fcntl::OFlag;
use nix::sys::stat::Mode;

use libcgroups::v2::devices::bpf;
use libcgroups::v2::devices::emulator;
use libcgroups::v2::devices::program;
use oci_spec::runtime::LinuxDeviceCgroup;

const LICENSE: &str = "Apache";
fn cli() -> Command {
Expand Down
25 changes: 9 additions & 16 deletions crates/libcgroups/src/common.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,19 @@
use std::{
fmt::{Debug, Display},
fs::{self, File},
io::{BufRead, BufReader, Write},
path::{Path, PathBuf, StripPrefixError},
time::Duration,
};

use nix::{
sys::statfs::{statfs, CGROUP2_SUPER_MAGIC, TMPFS_MAGIC},
unistd::Pid,
};
use std::fmt::{Debug, Display};
use std::fs::{self, File};
use std::io::{BufRead, BufReader, Write};
use std::path::{Path, PathBuf, StripPrefixError};
use std::time::Duration;

use nix::sys::statfs::{statfs, CGROUP2_SUPER_MAGIC, TMPFS_MAGIC};
use nix::unistd::Pid;
use oci_spec::runtime::LinuxResources;
#[cfg(any(feature = "cgroupsv2_devices", feature = "v1"))]
use oci_spec::runtime::{
LinuxDevice, LinuxDeviceBuilder, LinuxDeviceCgroup, LinuxDeviceCgroupBuilder, LinuxDeviceType,
};

use super::systemd;
use super::v1;
use super::v2;

use super::stats::Stats;
use super::{systemd, v1, v2};

pub const CGROUP_PROCS: &str = "cgroup.procs";
pub const DEFAULT_CGROUP_ROOT: &str = "/sys/fs/cgroup";
Expand Down
19 changes: 8 additions & 11 deletions crates/libcgroups/src/stats.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
use serde::Serialize;
use std::{
collections::HashMap,
fmt::Display,
fs,
num::ParseIntError,
path::{Path, PathBuf},
};
use std::collections::HashMap;
use std::fmt::Display;
use std::fs;
use std::num::ParseIntError;
use std::path::{Path, PathBuf};

use crate::common::{WrapIoResult, WrappedIoError};
use serde::Serialize;

use super::common;
use crate::common::{WrapIoResult, WrappedIoError};

pub(crate) trait StatsProvider {
type Error;
Expand Down Expand Up @@ -475,9 +473,8 @@ fn parse_psi(stat_line: &str, path: &Path) -> Result<PSIData, WrappedIoError> {

#[cfg(test)]
mod tests {
use crate::test::set_fixture;

use super::*;
use crate::test::set_fixture;

#[test]
fn test_supported_page_sizes_gigabyte() {
Expand Down
1 change: 0 additions & 1 deletion crates/libcgroups/src/systemd/controller.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::collections::HashMap;

use super::dbus_native::serialize::Variant;

use crate::common::ControllerOpt;

pub(super) trait Controller {
Expand Down
5 changes: 2 additions & 3 deletions crates/libcgroups/src/systemd/cpu.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::collections::HashMap;

use super::dbus_native::serialize::Variant;
use oci_spec::runtime::LinuxCpu;

use super::controller::Controller;
use super::dbus_native::serialize::Variant;
use crate::common::ControllerOpt;

pub const CPU_WEIGHT: &str = "CPUWeight";
Expand Down Expand Up @@ -95,9 +95,8 @@ mod tests {
use oci_spec::runtime::LinuxCpuBuilder;

use super::super::dbus_native::serialize::DbusSerialize;
use crate::recast;

use super::*;
use crate::recast;

#[test]
fn test_set_shares() -> Result<()> {
Expand Down
8 changes: 3 additions & 5 deletions crates/libcgroups/src/systemd/cpuset.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::collections::HashMap;

use super::dbus_native::serialize::Variant;
use fixedbitset::FixedBitSet;
use oci_spec::runtime::LinuxCpu;

use crate::common::ControllerOpt;

use super::controller::Controller;
use super::dbus_native::serialize::Variant;
use crate::common::ControllerOpt;

pub const ALLOWED_CPUS: &str = "AllowedCPUs";
pub const ALLOWED_NODES: &str = "AllowedMemoryNodes";
Expand Down Expand Up @@ -139,9 +138,8 @@ mod tests {
use oci_spec::runtime::LinuxCpuBuilder;

use super::super::dbus_native::serialize::DbusSerialize;
use crate::recast;

use super::*;
use crate::recast;

#[test]
fn to_bitmask_single_value() -> Result<()> {
Expand Down
4 changes: 3 additions & 1 deletion crates/libcgroups/src/systemd/dbus_native/client.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
use super::{serialize::Variant, utils::SystemdClientError};
use std::collections::HashMap;
use std::path::PathBuf;

use super::serialize::Variant;
use super::utils::SystemdClientError;

pub trait SystemdClient {
fn is_system(&self) -> bool;

Expand Down
18 changes: 10 additions & 8 deletions crates/libcgroups/src/systemd/dbus_native/dbus.rs
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
use crate::systemd::dbus_native::serialize::{DbusSerialize, Structure, Variant};

use super::client::SystemdClient;
use super::message::*;
use super::proxy::Proxy;
use super::utils::{DbusError, Result, SystemdClientError};
use nix::sys::socket;
use std::collections::HashMap;
use std::io::{IoSlice, IoSliceMut};
use std::os::fd::AsRawFd;
use std::path::PathBuf;
use std::sync::atomic::{AtomicU32, Ordering};

use nix::sys::socket;

use super::client::SystemdClient;
use super::message::*;
use super::proxy::Proxy;
use super::utils::{DbusError, Result, SystemdClientError};
use crate::systemd::dbus_native::serialize::{DbusSerialize, Structure, Variant};

const REPLY_BUF_SIZE: usize = 128; // seems good enough tradeoff between extra size and repeated calls

/// NOTE that this is meant for a single-threaded use, and concurrent
Expand Down Expand Up @@ -461,9 +462,10 @@ impl SystemdClient for DbusConnection {

#[cfg(test)]
mod tests {
use nix::unistd::getuid;

use super::super::utils::Result;
use super::{uid_to_hex_str, DbusConnection, SystemdClientError};
use nix::unistd::getuid;

#[test]
fn test_uid_to_hex_str() {
Expand Down
6 changes: 2 additions & 4 deletions crates/libcgroups/src/systemd/dbus_native/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -489,11 +489,9 @@ impl Message {

#[cfg(test)]
mod tests {
use crate::systemd::dbus_native::serialize::{Structure, Variant};

use super::super::serialize::DbusSerialize;
use super::{Header, HeaderKind, HeaderValue, MessageType};
use super::{Message, Result};
use super::{Header, HeaderKind, HeaderValue, Message, MessageType, Result};
use crate::systemd::dbus_native::serialize::{Structure, Variant};
// The hardcoded serialized values are captured from
// original dbus library communication
// and manually decoded.
Expand Down
60 changes: 28 additions & 32 deletions crates/libcgroups/src/systemd/manager.rs
Original file line number Diff line number Diff line change
@@ -1,32 +1,30 @@
use std::{
collections::HashMap,
convert::Infallible,
fmt::{Debug, Display},
fs::{self},
path::Component::RootDir,
};

use nix::{unistd::Pid, NixPath};
use std::collections::HashMap;
use std::convert::Infallible;
use std::fmt::{Debug, Display};
use std::fs::{self};
use std::path::Component::RootDir;
use std::path::{Path, PathBuf};

use super::{
controller::Controller,
controller_type::{ControllerType, CONTROLLER_TYPES},
cpu::Cpu,
cpuset::CpuSet,
dbus_native::{client::SystemdClient, dbus::DbusConnection, utils::SystemdClientError},
memory::Memory,
pids::Pids,
};
use crate::{
common::{
self, AnyCgroupManager, CgroupManager, ControllerOpt, FreezerState, JoinSafelyError,
PathBufExt, WrapIoResult, WrappedIoError,
},
systemd::{dbus_native::serialize::Variant, unified::Unified},
v2::manager::V2ManagerError,
use nix::unistd::Pid;
use nix::NixPath;

use super::controller::Controller;
use super::controller_type::{ControllerType, CONTROLLER_TYPES};
use super::cpu::Cpu;
use super::cpuset::CpuSet;
use super::dbus_native::client::SystemdClient;
use super::dbus_native::dbus::DbusConnection;
use super::dbus_native::utils::SystemdClientError;
use super::memory::Memory;
use super::pids::Pids;
use crate::common::{
self, AnyCgroupManager, CgroupManager, ControllerOpt, FreezerState, JoinSafelyError,
PathBufExt, WrapIoResult, WrappedIoError,
};
use crate::{stats::Stats, v2::manager::Manager as FsManager};
use crate::stats::Stats;
use crate::systemd::dbus_native::serialize::Variant;
use crate::systemd::unified::Unified;
use crate::v2::manager::{Manager as FsManager, V2ManagerError};

const CGROUP_CONTROLLERS: &str = "cgroup.controllers";
const CGROUP_SUBTREE_CONTROL: &str = "cgroup.subtree_control";
Expand Down Expand Up @@ -436,12 +434,10 @@ mod tests {
use anyhow::{Context, Result};

use super::*;
use crate::{
common::DEFAULT_CGROUP_ROOT,
systemd::dbus_native::{
client::SystemdClient, serialize::Variant, utils::SystemdClientError,
},
};
use crate::common::DEFAULT_CGROUP_ROOT;
use crate::systemd::dbus_native::client::SystemdClient;
use crate::systemd::dbus_native::serialize::Variant;
use crate::systemd::dbus_native::utils::SystemdClientError;

struct TestSystemdClient {}

Expand Down
8 changes: 3 additions & 5 deletions crates/libcgroups/src/systemd/memory.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
use std::collections::HashMap;

use super::dbus_native::serialize::Variant;
use oci_spec::runtime::LinuxMemory;

use crate::common::ControllerOpt;

use super::controller::Controller;
use super::dbus_native::serialize::Variant;
use crate::common::ControllerOpt;

pub const MEMORY_MIN: &str = "MemoryMin";
pub const MEMORY_LOW: &str = "MemoryLow";
Expand Down Expand Up @@ -118,9 +117,8 @@ mod tests {
use oci_spec::runtime::LinuxMemoryBuilder;

use super::super::dbus_native::serialize::DbusSerialize;
use crate::recast;

use super::*;
use crate::recast;

#[test]
fn test_set_valid_memory_low() -> Result<()> {
Expand Down
16 changes: 8 additions & 8 deletions crates/libcgroups/src/systemd/pids.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
use std::{collections::HashMap, convert::Infallible};
use std::collections::HashMap;
use std::convert::Infallible;

use super::dbus_native::serialize::Variant;
use oci_spec::runtime::LinuxPids;

use crate::common::ControllerOpt;

use super::controller::Controller;
use super::dbus_native::serialize::Variant;
use crate::common::ControllerOpt;

pub const TASKS_MAX: &str = "TasksMax";

Expand Down Expand Up @@ -43,13 +43,13 @@ impl Pids {
#[cfg(test)]
mod tests {

use super::super::dbus_native::serialize::DbusSerialize;
use crate::recast;

use super::*;
use anyhow::{anyhow, Context, Result};
use oci_spec::runtime::{LinuxPidsBuilder, LinuxResources, LinuxResourcesBuilder};

use super::super::dbus_native::serialize::DbusSerialize;
use super::*;
use crate::recast;

fn setup(resources: &LinuxResources) -> (ControllerOpt, HashMap<&str, Variant>) {
let properties = HashMap::new();
let options = ControllerOpt {
Expand Down
20 changes: 9 additions & 11 deletions crates/libcgroups/src/systemd/unified.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::collections::HashMap;
use std::num::ParseIntError;

use super::controller::Controller;
use super::cpu::{self, convert_shares_to_cgroup2};
use super::cpuset::{self, to_bitmask, BitmaskError};
use super::dbus_native::serialize::Variant;
use std::{collections::HashMap, num::ParseIntError};

use super::{
controller::Controller,
cpu::{self, convert_shares_to_cgroup2},
cpuset::{self, to_bitmask, BitmaskError},
memory, pids,
};
use super::{memory, pids};
use crate::common::ControllerOpt;

#[derive(thiserror::Error, Debug)]
Expand Down Expand Up @@ -155,12 +154,11 @@ impl Unified {

#[cfg(test)]
mod tests {
use super::super::dbus_native::serialize::DbusSerialize;
use anyhow::{Context, Result};

use crate::recast;

use super::super::dbus_native::serialize::DbusSerialize;
use super::*;
use crate::recast;

#[test]
fn test_set() -> Result<()> {
Expand Down
Loading

0 comments on commit 2b86907

Please sign in to comment.