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

cargo clippy. #52

Merged
merged 2 commits into from
Jun 1, 2021
Merged
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
18 changes: 8 additions & 10 deletions src/cgroups/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
path::{Path, PathBuf},
};

use anyhow::{anyhow, Result};
use anyhow::{bail, Result};
use nix::unistd::Pid;
use oci_spec::LinuxResources;
use procfs::process::Process;
Expand Down Expand Up @@ -74,30 +74,28 @@ pub fn create_cgroup_manager<P: Into<PathBuf>>(cgroup_path: P) -> Result<Box<dyn
match (cgroup_mount, cgroup2_mount) {
(Some(_), None) => {
log::info!("cgroup manager V1 will be used");
return Ok(Box::new(v1::manager::Manager::new(cgroup_path.into())?));
Ok(Box::new(v1::manager::Manager::new(cgroup_path.into())?))
}
(None, Some(cgroup2)) => {
log::info!("cgroup manager V2 will be used");
return Ok(Box::new(v2::manager::Manager::new(
Ok(Box::new(v2::manager::Manager::new(
cgroup2.mount_point,
cgroup_path.into(),
)?));
)?))
}
(Some(_), Some(cgroup2)) => {
let cgroup_override = env::var("YOUKI_PREFER_CGROUPV2");
match cgroup_override {
Ok(v) if v == "true" => {
log::info!("cgroup manager V2 will be used");
return Ok(Box::new(v2::manager::Manager::new(
Ok(Box::new(v2::manager::Manager::new(
cgroup2.mount_point,
cgroup_path.into(),
)?));
}
_ => {
return Ok(Box::new(v1::manager::Manager::new(cgroup_path.into())?))
)?))
}
_ => Ok(Box::new(v1::manager::Manager::new(cgroup_path.into())?)),
}
}
_ => return Err(anyhow!("could not find cgroup filesystem")),
_ => bail!("could not find cgroup filesystem"),
}
}
32 changes: 16 additions & 16 deletions src/cgroups/v2/cpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@ impl Cpu {
}

fn is_realtime_requested(cpu: &LinuxCpu) -> bool {
if let Some(_) = cpu.realtime_period {
if cpu.realtime_period.is_some() {
return true;
}

if let Some(_) = cpu.realtime_runtime {
if cpu.realtime_runtime.is_some() {
return true;
}

Expand All @@ -92,7 +92,7 @@ mod tests {
fn setup(testname: &str, cgroup_file: &str) -> (PathBuf, PathBuf) {
let tmp = create_temp_dir(testname).expect("create temp directory for test");
let cgroup_file = set_fixture(&tmp, cgroup_file, "")
.expect(&format!("set test fixture for {}", cgroup_file));
.unwrap_or_else(|_| panic!("set test fixture for {}", cgroup_file));

(tmp, cgroup_file)
}
Expand All @@ -102,15 +102,15 @@ mod tests {
// arrange
let (tmp, weight) = setup("test_set_shares", CGROUP_CPU_WEIGHT);
let _ = set_fixture(&tmp, CGROUP_CPU_MAX, "")
.expect(&format!("set test fixture for {}", CGROUP_CPU_MAX));
.unwrap_or_else(|_| panic!("set test fixture for {}", CGROUP_CPU_MAX));
let cpu = LinuxCpuBuilder::new().with_shares(22000).build();

// act
Cpu::apply(&tmp, &cpu).expect("apply cpu");

// assert
let content =
fs::read_to_string(weight).expect(&format!("read {} file content", CGROUP_CPU_WEIGHT));
let content = fs::read_to_string(weight)
.unwrap_or_else(|_| panic!("read {} file content", CGROUP_CPU_WEIGHT));
assert_eq!(content, 840.to_string());
}

Expand All @@ -125,8 +125,8 @@ mod tests {
Cpu::apply(&tmp, &cpu).expect("apply cpu");

// assert
let content =
fs::read_to_string(max).expect(&format!("read {} file content", CGROUP_CPU_MAX));
let content = fs::read_to_string(max)
.unwrap_or_else(|_| panic!("read {} file content", CGROUP_CPU_MAX));
assert_eq!(content, format!("{} {}", QUOTA, DEFAULT_PERIOD))
}

Expand All @@ -140,8 +140,8 @@ mod tests {
Cpu::apply(&tmp, &cpu).expect("apply cpu");

// assert
let content =
fs::read_to_string(max).expect(&format!("read {} file content", CGROUP_CPU_MAX));
let content = fs::read_to_string(max)
.unwrap_or_else(|_| panic!("read {} file content", CGROUP_CPU_MAX));
assert_eq!(
content,
format!("{} {}", UNRESTRICTED_QUOTA, DEFAULT_PERIOD)
Expand All @@ -159,8 +159,8 @@ mod tests {
Cpu::apply(&tmp, &cpu).expect("apply cpu");

// assert
let content =
fs::read_to_string(max).expect(&format!("read {} file content", CGROUP_CPU_MAX));
let content = fs::read_to_string(max)
.unwrap_or_else(|_| panic!("read {} file content", CGROUP_CPU_MAX));
assert_eq!(content, format!("{} {}", UNRESTRICTED_QUOTA, PERIOD))
}

Expand All @@ -174,8 +174,8 @@ mod tests {
Cpu::apply(&tmp, &cpu).expect("apply cpu");

// assert
let content =
fs::read_to_string(max).expect(&format!("read {} file content", CGROUP_CPU_MAX));
let content = fs::read_to_string(max)
.unwrap_or_else(|_| panic!("read {} file content", CGROUP_CPU_MAX));
assert_eq!(
content,
format!("{} {}", UNRESTRICTED_QUOTA, DEFAULT_PERIOD)
Expand All @@ -197,8 +197,8 @@ mod tests {
Cpu::apply(&tmp, &cpu).expect("apply cpu");

// assert
let content =
fs::read_to_string(max).expect(&format!("read {} file content", CGROUP_CPU_MAX));
let content = fs::read_to_string(max)
.unwrap_or_else(|_| panic!("read {} file content", CGROUP_CPU_MAX));
assert_eq!(content, format!("{} {}", QUOTA, PERIOD));
}

Expand Down
10 changes: 5 additions & 5 deletions src/cgroups/v2/cpuset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ mod tests {
fn setup(testname: &str, cgroup_file: &str) -> (PathBuf, PathBuf) {
let tmp = create_temp_dir(testname).expect("create temp directory for test");
let cgroup_file = set_fixture(&tmp, cgroup_file, "")
.expect(&format!("set test fixture for {}", cgroup_file));
.unwrap_or_else(|_| panic!("set test fixture for {}", cgroup_file));

(tmp, cgroup_file)
}
Expand All @@ -60,8 +60,8 @@ mod tests {
CpuSet::apply(&tmp, &cpuset).expect("apply cpuset");

// assert
let content =
fs::read_to_string(&cpus).expect(&format!("read {} file content", CGROUP_CPUSET_CPUS));
let content = fs::read_to_string(&cpus)
.unwrap_or_else(|_| panic!("read {} file content", CGROUP_CPUSET_CPUS));
assert_eq!(content, "1-3");
}

Expand All @@ -75,8 +75,8 @@ mod tests {
CpuSet::apply(&tmp, &cpuset).expect("apply cpuset");

// assert
let content =
fs::read_to_string(&mems).expect(&format!("read {} file content", CGROUP_CPUSET_MEMS));
let content = fs::read_to_string(&mems)
.unwrap_or_else(|_| panic!("read {} file content", CGROUP_CPUSET_MEMS));
assert_eq!(content, "1-3");
}
}
2 changes: 1 addition & 1 deletion src/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use crate::stdio::FileDescriptor;
use crate::tty;
use crate::utils;
use crate::{capabilities, command::Command};
use oci_spec;

#[derive(Clap, Debug)]
pub struct Create {
#[clap(short, long)]
Expand Down
1 change: 0 additions & 1 deletion src/process/fork.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use crate::container::ContainerStatus;
use crate::process::{child, init, parent, Process};
use crate::utils;
use crate::{cond::Cond, container::Container};
use oci_spec;

pub fn fork_first<P: AsRef<Path>>(
pid_file: Option<P>,
Expand Down