1
0
Fork 0
mirror of https://github.com/containers/youki synced 2024-05-10 09:36:13 +02:00

cargo clippy.

This commit is contained in:
utam0k 2021-05-23 15:08:33 +09:00
parent f8b4f85c61
commit 69fc8fe296
2 changed files with 47 additions and 24 deletions

31
Cargo.lock generated
View File

@ -6,6 +6,15 @@ version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "0.7.18"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1e37cfd5e7657ada45f742d6e99ca5788580b5c529dc78faf11ece6dc702656f"
dependencies = [
"memchr",
]
[[package]]
name = "anyhow"
version = "1.0.38"
@ -319,9 +328,9 @@ dependencies = [
[[package]]
name = "memchr"
version = "2.3.4"
version = "2.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
checksum = "b16bd47d9e329435e309c58469fe0791c2d0d1ba96ec0954152a5ae2b04387dc"
[[package]]
name = "miniz_oxide"
@ -509,6 +518,23 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "regex"
version = "1.5.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d07a8629359eb56f1e2fb1652bb04212c072a87ba68546a04065d525673ac461"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.6.25"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f497285884f3fcff424ffc933e56d7cbca511def0c9831a7f9b5f6153e3cc89b"
[[package]]
name = "ryu"
version = "1.0.5"
@ -712,6 +738,7 @@ dependencies = [
"once_cell",
"prctl",
"procfs",
"regex",
"serde",
"serde_json",
]

View File

@ -3,13 +3,13 @@ use std::{fs::remove_dir, path::Path};
use anyhow::Result;
use nix::unistd::Pid;
use procfs::process::{Process};
use procfs::process::Process;
use crate::{cgroups::ControllerType, spec::LinuxResources, utils::PathBufExt};
use super::{devices::Devices, hugetlb::Hugetlb, Controller};
const CONTROLLERS: &'static [ControllerType] = &[ControllerType::Devices, ControllerType::HugeTlb];
const CONTROLLERS: &[ControllerType] = &[ControllerType::Devices, ControllerType::HugeTlb];
pub struct Manager {
subsystems: HashMap<String, PathBuf>,
}
@ -17,13 +17,14 @@ pub struct Manager {
impl Manager {
pub fn new(cgroup_path: PathBuf) -> Result<Self> {
let mut subsystems = HashMap::<String, PathBuf>::new();
for subsystem in CONTROLLERS.into_iter().map(|c|c.to_string()) {
subsystems.insert(subsystem.to_owned(),Self::get_subsystem_path(&cgroup_path, &subsystem)?);
for subsystem in CONTROLLERS.iter().map(|c| c.to_string()) {
subsystems.insert(
subsystem.to_owned(),
Self::get_subsystem_path(&cgroup_path, &subsystem)?,
);
}
Ok(Manager {
subsystems,
})
Ok(Manager { subsystems })
}
pub fn apply(&self, linux_resources: &LinuxResources, pid: Pid) -> Result<()> {
@ -53,15 +54,12 @@ impl Manager {
let mount = Process::myself()?
.mountinfo()?
.into_iter()
.filter(|m| {
m.fs_type == "cgroup"
&& m.mount_point.ends_with(subsystem)
})
.filter(|m| m.fs_type == "cgroup" && m.mount_point.ends_with(subsystem))
.collect::<Vec<_>>()
.pop()
.unwrap();
let cgroup = Process::myself()?
let cgroup = Process::myself()?
.cgroups()?
.into_iter()
.filter(|c| c.controllers.contains(&subsystem.to_owned()))
@ -69,16 +67,14 @@ impl Manager {
.pop()
.unwrap();
let p = if cgroup_path.to_string_lossy().into_owned().is_empty() {
mount
.mount_point
.join_absolute_path(Path::new(&cgroup.pathname))?
} else {
mount
.mount_point
.join_absolute_path(&cgroup_path)?
};
let p = if cgroup_path.to_string_lossy().into_owned().is_empty() {
mount
.mount_point
.join_absolute_path(Path::new(&cgroup.pathname))?
} else {
mount.mount_point.join_absolute_path(&cgroup_path)?
};
Ok(p)
Ok(p)
}
}