-
Notifications
You must be signed in to change notification settings - Fork 355
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #83 from Furisto/info-cmd
Add info command
- Loading branch information
Showing
9 changed files
with
167 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
use std::{collections::HashMap, path::PathBuf}; | ||
|
||
use anyhow::{anyhow, Result}; | ||
use procfs::process::Process; | ||
|
||
use super::controller_type::CONTROLLERS; | ||
|
||
pub fn list_subsystem_mount_points() -> Result<HashMap<String, PathBuf>> { | ||
let mut mount_paths = HashMap::with_capacity(CONTROLLERS.len()); | ||
|
||
for controller in CONTROLLERS { | ||
if let Ok(mount_point) = get_subsystem_mount_points(&controller.to_string()) { | ||
mount_paths.insert(controller.to_string(), mount_point); | ||
} | ||
} | ||
|
||
Ok(mount_paths) | ||
} | ||
|
||
pub fn get_subsystem_mount_points(subsystem: &str) -> Result<PathBuf> { | ||
Process::myself()? | ||
.mountinfo()? | ||
.into_iter() | ||
.find(|m| { | ||
if m.fs_type == "cgroup" { | ||
// Some systems mount net_prio and net_cls in the same directory | ||
// other systems mount them in their own diretories. This | ||
// should handle both cases. | ||
if subsystem == "net_cls" { | ||
return m.mount_point.ends_with("net_cls,net_prio") | ||
|| m.mount_point.ends_with("net_prio,net_cls") | ||
|| m.mount_point.ends_with("net_cls"); | ||
} else if subsystem == "net_prio" { | ||
return m.mount_point.ends_with("net_cls,net_prio") | ||
|| m.mount_point.ends_with("net_prio,net_cls") | ||
|| m.mount_point.ends_with("net_prio"); | ||
} | ||
|
||
if subsystem == "cpu" { | ||
return m.mount_point.ends_with("cpu,cpuacct") | ||
|| m.mount_point.ends_with("cpu"); | ||
} | ||
} | ||
m.mount_point.ends_with(&subsystem) | ||
}) | ||
.map(|m| m.mount_point) | ||
.ok_or_else(|| anyhow!("could not find mountpoint for {}", subsystem)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,3 +7,4 @@ mod io; | |
pub mod manager; | ||
mod memory; | ||
mod pids; | ||
pub mod util; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
use std::path::PathBuf; | ||
|
||
use anyhow::{anyhow, Result}; | ||
use procfs::process::Process; | ||
|
||
pub fn get_unified_mount_point() -> Result<PathBuf> { | ||
Process::myself()? | ||
.mountinfo()? | ||
.into_iter() | ||
.find(|m| m.fs_type == "cgroup2") | ||
.map(|m| m.mount_point) | ||
.ok_or_else(|| anyhow!("could not find mountpoint for unified")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
//! Container Runtime written in Rust, inspired by [railcar](https://github.com/oracle/railcar) | ||
//! This crate provides a container runtime which can be used by a high-level container runtime to run containers. | ||
use procfs; | ||
use std::fs; | ||
use std::path::{Path, PathBuf}; | ||
|
||
|
@@ -66,6 +67,8 @@ enum SubCommand { | |
Delete(Delete), | ||
#[clap(version = "0.0.1", author = "utam0k <[email protected]>")] | ||
State(StateArgs), | ||
#[clap(version = "0.0.1", author = "utam0k <[email protected]>")] | ||
Info, | ||
} | ||
|
||
/// This is the entry point in the container runtime. The binary is run by a high-level container runtime, | ||
|
@@ -162,5 +165,46 @@ fn main() -> Result<()> { | |
println!("{}", serde_json::to_string_pretty(&container.state)?); | ||
std::process::exit(0); | ||
} | ||
|
||
SubCommand::Info => { | ||
let uname = nix::sys::utsname::uname(); | ||
println!("{:<18}{}", "Kernel-Release", uname.release()); | ||
println!("{:<18}{}", "Kernel-Version", uname.version()); | ||
println!("{:<18}{}", "Architecture", uname.machine()); | ||
|
||
let cpu_info = procfs::CpuInfo::new()?; | ||
println!("{:<18}{}", "Cores", cpu_info.num_cores()); | ||
let mem_info = procfs::Meminfo::new()?; | ||
println!( | ||
"{:<18}{}", | ||
"Total Memory", | ||
mem_info.mem_total / u64::pow(1024, 2) | ||
); | ||
|
||
let cgroup_fs: Vec<String> = cgroups::common::get_supported_cgroup_fs()? | ||
.into_iter() | ||
.map(|c| c.to_string()) | ||
.collect(); | ||
println!("{:<18}{}", "cgroup version", cgroup_fs.join(" and ")); | ||
|
||
println!("cgroup mounts"); | ||
let mut cgroup_v1_mounts: Vec<String> = | ||
cgroups::v1::util::list_subsystem_mount_points()? | ||
.iter() | ||
.map(|kv| format!(" {:<16}{:?}", kv.0, kv.1)) | ||
.collect(); | ||
|
||
cgroup_v1_mounts.sort(); | ||
for cgroup_mount in cgroup_v1_mounts { | ||
println!("{}", cgroup_mount); | ||
} | ||
|
||
let unified = cgroups::v2::util::get_unified_mount_point(); | ||
if let Ok(mount_point) = unified { | ||
println!(" {:<16}{:?}", "unified", mount_point); | ||
} | ||
|
||
Ok(()) | ||
} | ||
} | ||
} |