Skip to content

Commit

Permalink
Bulk apply formatting
Browse files Browse the repository at this point in the history
Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
  • Loading branch information
jprendes committed May 15, 2024
1 parent bdd4f5c commit 13a3fd5
Show file tree
Hide file tree
Showing 158 changed files with 976 additions and 988 deletions.
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
7 changes: 3 additions & 4 deletions crates/libcgroups/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
#![cfg(test)]

use std::io::Write;
use std::path::{Path, PathBuf};

use anyhow::{Context, Result};
use std::{
io::Write,
path::{Path, PathBuf},
};

pub fn setup(cgroup_file: &str) -> (tempfile::TempDir, PathBuf) {
let tmp = tempfile::tempdir().expect("create temp directory for test");
Expand Down
Loading

0 comments on commit 13a3fd5

Please sign in to comment.