Skip to content

Commit

Permalink
fix cargo clippy warning in cgroups.
Browse files Browse the repository at this point in the history
  • Loading branch information
utam0k committed Sep 7, 2021
1 parent d4e1069 commit 69bcb07
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 35 deletions.
4 changes: 2 additions & 2 deletions cgroups/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion cgroups/src/v1/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ impl Manager {
let p = if cgroup_path.to_string_lossy().into_owned().is_empty() {
mount_point.join_safely(Path::new(&cgroup.pathname))?
} else if cgroup_path.is_absolute() {
mount_point.join_safely(&cgroup_path)?
mount_point.join_safely(cgroup_path)?
} else {
mount_point.join(cgroup_path)
};
Expand Down
3 changes: 2 additions & 1 deletion cgroups/src/v2/devices/bpf.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use anyhow::{bail, Result};
use std::os::unix::io::RawFd;
use std::ptr;

// FIXME: add tests

Expand All @@ -14,7 +15,7 @@ pub fn prog_load(license: &str, insns: &[u8]) -> Result<RawFd> {
insns_cnt as u64,
license as *const _ as *const i8,
0,
0 as *mut i8,
ptr::null_mut::<i8>(),
0,
)
};
Expand Down
2 changes: 1 addition & 1 deletion cgroups/src/v2/devices/controller.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use oci_spec::{LinuxDeviceCgroup, LinuxResources};
use crate::common::{default_allow_devices, default_devices};
use crate::v2::controller::Controller;

const LICENSE: &'static str = &"Apache";
const LICENSE: &str = "Apache";

pub struct Devices {}

Expand Down
2 changes: 1 addition & 1 deletion cgroups/src/v2/devices/emulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl Emulator {
pub fn add_rule(&mut self, rule: &oci_spec::LinuxDeviceCgroup) -> Result<()> {
// special case, switch to blacklist or whitelist and clear all existing rules
// NOTE: we ignore other fields when type='a', this is same as cgroup v1 and runc
if rule.typ.clone().unwrap_or_default() == oci_spec::LinuxDeviceType::A {
if rule.typ.unwrap_or_default() == oci_spec::LinuxDeviceType::A {
self.default_allow = rule.allow;
self.rules.clear();
return Ok(());
Expand Down
5 changes: 3 additions & 2 deletions cgroups/src/v2/devices/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub struct Program {
}

impl Program {
pub fn from_rules(rules: &Vec<LinuxDeviceCgroup>, default_allow: bool) -> Result<Self> {
pub fn from_rules(rules: &[LinuxDeviceCgroup], default_allow: bool) -> Result<Self> {
let mut prog = Program {
prog: BpfCode::new(),
};
Expand Down Expand Up @@ -90,7 +90,7 @@ impl Program {
}

fn add_rule(&mut self, rule: &LinuxDeviceCgroup) -> Result<()> {
let dev_type = bpf_dev_type(rule.typ.clone().unwrap_or_default())?;
let dev_type = bpf_dev_type(rule.typ.unwrap_or_default())?;
let access = bpf_access(rule.access.clone().unwrap_or_default())?;
let has_access = access
!= (libbpf_sys::BPF_DEVCG_ACC_READ
Expand Down Expand Up @@ -245,6 +245,7 @@ fn bpf_cgroup_dev_ctx(
Ok(mem)
}

#[cfg(test)]
mod tests {
use super::*;

Expand Down
7 changes: 3 additions & 4 deletions cgroups/src/v2/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,12 @@ impl CgroupManager for Manager {
Devices::apply(linux_resources, &self.cgroup_path)?;

for pseudoctlr in PSEUDO_CONTROLLER_TYPES {
match pseudoctlr {
PseudoControllerType::Unified => Unified::apply(
if let PseudoControllerType::Unified = pseudoctlr {
Unified::apply(
linux_resources,
&self.cgroup_path,
self.get_available_controllers()?,
)?,
_ => {}
)?
}
}

Expand Down
53 changes: 30 additions & 23 deletions cgroups/src/v2/unified.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ impl Unified {
#[cfg(test)]
mod tests {
use std::array::IntoIter;
use std::collections::HashMap;
use std::fs;
use std::iter::FromIterator;

use crate::test::{create_temp_dir, set_fixture};
use crate::v2::controller_type::ControllerType;
Expand All @@ -64,13 +62,16 @@ mod tests {
let cpu_weight_path = set_fixture(&tmp, "cpu.weight", "").unwrap();

let resources = LinuxResources {
unified: Some(HashMap::<_, _>::from_iter(IntoIter::new([
(
"hugetlb.1GB.limit_in_bytes".to_owned(),
"72348034".to_owned(),
),
("cpu.weight".to_owned(), "5000".to_owned()),
]))),
unified: Some(
IntoIter::new([
(
"hugetlb.1GB.limit_in_bytes".to_owned(),
"72348034".to_owned(),
),
("cpu.weight".to_owned(), "5000".to_owned()),
])
.collect(),
),
..Default::default()
};

Expand All @@ -91,13 +92,16 @@ mod tests {
create_temp_dir("test_set_unified_failed_to_write_subsystem_not_enabled").unwrap();

let resources = LinuxResources {
unified: Some(HashMap::<_, _>::from_iter(IntoIter::new([
(
"hugetlb.1GB.limit_in_bytes".to_owned(),
"72348034".to_owned(),
),
("cpu.weight".to_owned(), "5000".to_owned()),
]))),
unified: Some(
IntoIter::new([
(
"hugetlb.1GB.limit_in_bytes".to_owned(),
"72348034".to_owned(),
),
("cpu.weight".to_owned(), "5000".to_owned()),
])
.collect(),
),
..Default::default()
};

Expand All @@ -114,13 +118,16 @@ mod tests {
let tmp = create_temp_dir("test_set_unified_failed_to_write_subsystem_enabled").unwrap();

let resources = LinuxResources {
unified: Some(HashMap::<_, _>::from_iter(IntoIter::new([
(
"hugetlb.1GB.limit_in_bytes".to_owned(),
"72348034".to_owned(),
),
("cpu.weight".to_owned(), "5000".to_owned()),
]))),
unified: Some(
IntoIter::new([
(
"hugetlb.1GB.limit_in_bytes".to_owned(),
"72348034".to_owned(),
),
("cpu.weight".to_owned(), "5000".to_owned()),
])
.collect(),
),
..Default::default()
};

Expand Down

0 comments on commit 69bcb07

Please sign in to comment.