diff --git a/crates/libcontainer/src/config.rs b/crates/libcontainer/src/config.rs index 8d4bb694c1..e025b514d5 100644 --- a/crates/libcontainer/src/config.rs +++ b/crates/libcontainer/src/config.rs @@ -45,7 +45,10 @@ pub struct YoukiConfig { } impl<'a> YoukiConfig { - pub fn from_spec(spec: &'a Spec, cgroup_config: Option) -> Result { + pub fn from_spec( + spec: &'a Spec, + cgroup_config: Option, + ) -> Result { Ok(YoukiConfig { hooks: spec.hooks().clone(), cgroup_config, diff --git a/crates/libcontainer/src/container/builder_impl.rs b/crates/libcontainer/src/container/builder_impl.rs index 86f2da9b93..8df01524c4 100644 --- a/crates/libcontainer/src/container/builder_impl.rs +++ b/crates/libcontainer/src/container/builder_impl.rs @@ -10,6 +10,7 @@ use oci_spec::runtime::Spec; use super::{Container, ContainerStatus}; use crate::error::{LibcontainerError, MissingSpecError}; +use crate::hooks; use crate::notify_socket::NotifyListener; use crate::process::args::{ContainerArgs, ContainerType}; use crate::process::intel_rdt::delete_resctrl_subdirectory; @@ -17,7 +18,6 @@ use crate::process::{self}; use crate::syscall::syscall::SyscallType; use crate::user_ns::UserNamespaceConfig; use crate::workload::Executor; -use crate::hooks; pub(super) struct ContainerBuilderImpl { /// Flag indicating if an init or a tenant container should be created @@ -72,11 +72,7 @@ impl ContainerBuilderImpl { if let ContainerType::InitContainer { container } = &self.container_type { if let Some(hooks) = self.spec.hooks() { - hooks::run_hooks( - hooks.create_runtime().as_ref(), - container, - None, - )? + hooks::run_hooks(hooks.create_runtime().as_ref(), container, None)? } } diff --git a/crates/libcontainer/src/container/container_delete.rs b/crates/libcontainer/src/container/container_delete.rs index c73c69eb6b..ece0ed189b 100644 --- a/crates/libcontainer/src/container/container_delete.rs +++ b/crates/libcontainer/src/container/container_delete.rs @@ -93,12 +93,10 @@ impl Container { } if let Some(hooks) = config.hooks.as_ref() { - hooks::run_hooks(hooks.poststop().as_ref(), self, None).map_err( - |err| { - tracing::error!(err = ?err, "failed to run post stop hooks"); - err - }, - )?; + hooks::run_hooks(hooks.poststop().as_ref(), self, None).map_err(|err| { + tracing::error!(err = ?err, "failed to run post stop hooks"); + err + })?; } } Err(err) => { diff --git a/crates/libcontainer/src/container/container_events.rs b/crates/libcontainer/src/container/container_events.rs index 6be6418d01..9a4f39f626 100644 --- a/crates/libcontainer/src/container/container_events.rs +++ b/crates/libcontainer/src/container/container_events.rs @@ -39,8 +39,7 @@ impl Container { None => return Err(LibcontainerError::CgroupsMissing), }; - let cgroup_manager = - libcgroups::common::create_cgroup_manager(cgroup_config)?; + let cgroup_manager = libcgroups::common::create_cgroup_manager(cgroup_config)?; match stats { true => { let stats = cgroup_manager.stats()?; diff --git a/crates/libcontainer/src/container/container_kill.rs b/crates/libcontainer/src/container/container_kill.rs index 14d82b10be..d4ebe95fed 100644 --- a/crates/libcontainer/src/container/container_kill.rs +++ b/crates/libcontainer/src/container/container_kill.rs @@ -83,15 +83,13 @@ impl Container { match get_cgroup_setup()? { libcgroups::common::CgroupSetup::Legacy | libcgroups::common::CgroupSetup::Hybrid => { - let cmanager = libcgroups::common::create_cgroup_manager( - cgroup_config - )?; + let cmanager = libcgroups::common::create_cgroup_manager(cgroup_config)?; cmanager.freeze(libcgroups::common::FreezerState::Thawed)?; } libcgroups::common::CgroupSetup::Unified => {} } } else { - return Err(LibcontainerError::CgroupsMissing) + return Err(LibcontainerError::CgroupsMissing); } } Ok(()) @@ -104,8 +102,7 @@ impl Container { }; let signal = signal.into().into_raw(); - let cmanager = - libcgroups::common::create_cgroup_manager(cgroup_config)?; + let cmanager = libcgroups::common::create_cgroup_manager(cgroup_config)?; if let Err(e) = cmanager.freeze(libcgroups::common::FreezerState::Frozen) { tracing::warn!( diff --git a/crates/libcontainer/src/container/container_pause.rs b/crates/libcontainer/src/container/container_pause.rs index e0af5746f0..aed4660121 100644 --- a/crates/libcontainer/src/container/container_pause.rs +++ b/crates/libcontainer/src/container/container_pause.rs @@ -37,8 +37,7 @@ impl Container { None => return Err(LibcontainerError::CgroupsMissing), }; - let cmanager = - libcgroups::common::create_cgroup_manager(cgroup_config)?; + let cmanager = libcgroups::common::create_cgroup_manager(cgroup_config)?; cmanager.freeze(FreezerState::Frozen)?; tracing::debug!("saving paused status"); diff --git a/crates/libcontainer/src/container/container_resume.rs b/crates/libcontainer/src/container/container_resume.rs index 67b845e50a..dc6cc4ad3b 100644 --- a/crates/libcontainer/src/container/container_resume.rs +++ b/crates/libcontainer/src/container/container_resume.rs @@ -38,8 +38,7 @@ impl Container { None => return Err(LibcontainerError::CgroupsMissing), }; - let cmanager = - libcgroups::common::create_cgroup_manager(cgroup_config)?; + let cmanager = libcgroups::common::create_cgroup_manager(cgroup_config)?; // resume the frozen container cmanager.freeze(FreezerState::Thawed)?; diff --git a/crates/libcontainer/src/container/init_builder.rs b/crates/libcontainer/src/container/init_builder.rs index 457bad4513..2ec5bccaf6 100644 --- a/crates/libcontainer/src/container/init_builder.rs +++ b/crates/libcontainer/src/container/init_builder.rs @@ -59,8 +59,7 @@ impl InitContainerBuilder { let container_dir = self.create_container_dir()?; let mut container = self.create_container_state(&container_dir)?; - container - .set_annotations(spec.annotations().clone()); + container.set_annotations(spec.annotations().clone()); let notify_path = container_dir.join(NOTIFY_FILE); // convert path of root file system of the container to absolute path @@ -84,7 +83,8 @@ impl InitContainerBuilder { let mut cgroup_config = None; if self.use_cgroups { let linux = spec.linux().as_ref().ok_or(MissingSpecError::Linux)?; - let cgroups_path = utils::get_cgroup_path(linux.cgroups_path(), &self.base.container_id); + let cgroups_path = + utils::get_cgroup_path(linux.cgroups_path(), &self.base.container_id); cgroup_config = Some(libcgroups::common::CgroupConfig { cgroup_path: cgroups_path, systemd_cgroup: self.use_systemd || user_ns_config.is_some(), diff --git a/crates/libcontainer/src/process/container_main_process.rs b/crates/libcontainer/src/process/container_main_process.rs index eda7a11fc3..6302aa1c50 100644 --- a/crates/libcontainer/src/process/container_main_process.rs +++ b/crates/libcontainer/src/process/container_main_process.rs @@ -127,8 +127,10 @@ pub fn container_main_process(container_args: &ContainerArgs) -> Result<(Pid, bo #[cfg(feature = "libseccomp")] if let Some(seccomp) = linux.seccomp() { let container_state = match &container_args.container_type { - ContainerType::InitContainer { container } => &container.state, - ContainerType::TenantContainer { .. } => return Err(ProcessError::ContainerStateRequired), + ContainerType::InitContainer { container } => &container.state, + ContainerType::TenantContainer { .. } => { + return Err(ProcessError::ContainerStateRequired) + } }; let state = crate::container::ContainerProcessState { oci_version: container_args.spec.version().to_string(), @@ -148,8 +150,8 @@ pub fn container_main_process(container_args: &ContainerArgs) -> Result<(Pid, bo if let Some(intel_rdt) = linux.intel_rdt() { let container_id = match &container_args.container_type { - ContainerType::InitContainer { container } => Some(container.id()), - ContainerType::TenantContainer { .. } => None, + ContainerType::InitContainer { container } => Some(container.id()), + ContainerType::TenantContainer { .. } => None, }; need_to_clean_up_intel_rdt_subdirectory = setup_intel_rdt(container_id, &init_pid, intel_rdt)?; diff --git a/crates/youki/src/commands/create.rs b/crates/youki/src/commands/create.rs index 907233c72e..02928dcbe9 100644 --- a/crates/youki/src/commands/create.rs +++ b/crates/youki/src/commands/create.rs @@ -13,7 +13,12 @@ use crate::workload::executor::default_executor; // can be given impression that is is running on a complete system, but on the system which // it is running, it is just another process, and has attributes such as pid, file descriptors, etc. // associated with it like any other process. -pub fn create(args: Create, root_path: PathBuf, systemd_cgroup: bool, use_cgroups: bool) -> Result<()> { +pub fn create( + args: Create, + root_path: PathBuf, + systemd_cgroup: bool, + use_cgroups: bool, +) -> Result<()> { ContainerBuilder::new(args.container_id.clone(), SyscallType::default()) .with_executor(default_executor()) .with_pid_file(args.pid_file.as_ref())? diff --git a/crates/youki/src/main.rs b/crates/youki/src/main.rs index e3c64dc799..40eac1d2bb 100644 --- a/crates/youki/src/main.rs +++ b/crates/youki/src/main.rs @@ -131,14 +131,16 @@ fn main() -> Result<()> { CommonCmd::Pause(pause) => commands::pause::pause(pause, root_path), CommonCmd::Ps(ps) => commands::ps::ps(ps, root_path), CommonCmd::Resume(resume) => commands::resume::resume(resume, root_path), - CommonCmd::Run(run) => match commands::run::run(run, root_path, systemd_cgroup, use_cgroups) { - Ok(exit_code) => std::process::exit(exit_code), - Err(e) => { - tracing::error!("error in executing command: {:?}", e); - eprintln!("run failed : {e}"); - std::process::exit(-1); + CommonCmd::Run(run) => { + match commands::run::run(run, root_path, systemd_cgroup, use_cgroups) { + Ok(exit_code) => std::process::exit(exit_code), + Err(e) => { + tracing::error!("error in executing command: {:?}", e); + eprintln!("run failed : {e}"); + std::process::exit(-1); + } } - }, + } CommonCmd::Spec(spec) => commands::spec_json::spec(spec), CommonCmd::Update(update) => commands::update::update(update, root_path), },