Skip to content

Commit

Permalink
make sure to log any unimplemented controllers.
Browse files Browse the repository at this point in the history
  • Loading branch information
utam0k committed Jun 16, 2021
1 parent 2f14718 commit 242c57d
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/cgroups/v2/controller_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ pub enum ControllerType {
Memory,
HugeTlb,
Pids,
Unknown(String),
}

impl ToString for ControllerType {
Expand All @@ -16,6 +17,7 @@ impl ToString for ControllerType {
Self::Memory => "memory".into(),
Self::HugeTlb => "hugetlb".into(),
Self::Pids => "pids".into(),
Self::Unknown(tpe) => tpe.into(),
}
}
}
12 changes: 8 additions & 4 deletions src/cgroups/v2/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use std::{
path::{Path, PathBuf},
};

use anyhow::{anyhow, Result};
use anyhow::{bail, Result};

use nix::unistd::Pid;
use oci_spec::LinuxResources;
Expand Down Expand Up @@ -80,10 +80,10 @@ impl Manager {
) -> Result<Vec<ControllerType>> {
let controllers_path = self.root_path.join(cgroup_path).join(CGROUP_CONTROLLERS);
if !controllers_path.exists() {
return Err(anyhow!(
bail!(
"cannot get available controllers. {:?} does not exist",
controllers_path
));
)
}

let mut controllers = Vec::new();
Expand All @@ -95,7 +95,7 @@ impl Manager {
"io" => controllers.push(ControllerType::Io),
"memory" => controllers.push(ControllerType::Memory),
"pids" => controllers.push(ControllerType::Pids),
_ => continue,
tpe => controllers.push(ControllerType::Unknown(tpe.to_string())),
}
}

Expand Down Expand Up @@ -123,6 +123,10 @@ impl CgroupManager for Manager {
ControllerType::Io => Io::apply(linux_resources, &&full_cgroup_path)?,
ControllerType::Memory => Memory::apply(linux_resources, &full_cgroup_path)?,
ControllerType::Pids => Pids::apply(linux_resources, &&full_cgroup_path)?,
ControllerType::Unknown(tpe) => {
log::warn!("Controller {} is not yet implemented.", tpe);
continue;
}
}
}

Expand Down

0 comments on commit 242c57d

Please sign in to comment.