Skip to content

Commit

Permalink
Fix linting issues
Browse files Browse the repository at this point in the history
Signed-off-by: Aidan Hobson Sayers <[email protected]>
  • Loading branch information
aidanhs committed Aug 30, 2024
1 parent 746e7b4 commit db4fb52
Show file tree
Hide file tree
Showing 11 changed files with 40 additions and 40 deletions.
5 changes: 4 additions & 1 deletion crates/libcontainer/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ pub struct YoukiConfig {
}

impl<'a> YoukiConfig {
pub fn from_spec(spec: &'a Spec, cgroup_config: Option<libcgroups::common::CgroupConfig>) -> Result<Self> {
pub fn from_spec(
spec: &'a Spec,
cgroup_config: Option<libcgroups::common::CgroupConfig>,
) -> Result<Self> {
Ok(YoukiConfig {
hooks: spec.hooks().clone(),
cgroup_config,
Expand Down
8 changes: 2 additions & 6 deletions crates/libcontainer/src/container/builder_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@ 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;
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
Expand Down Expand Up @@ -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)?
}
}

Expand Down
10 changes: 4 additions & 6 deletions crates/libcontainer/src/container/container_delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down
3 changes: 1 addition & 2 deletions crates/libcontainer/src/container/container_events.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down
9 changes: 3 additions & 6 deletions crates/libcontainer/src/container/container_kill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand All @@ -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!(
Expand Down
3 changes: 1 addition & 2 deletions crates/libcontainer/src/container/container_pause.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
3 changes: 1 addition & 2 deletions crates/libcontainer/src/container/container_resume.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;

Expand Down
6 changes: 3 additions & 3 deletions crates/libcontainer/src/container/init_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(),
Expand Down
10 changes: 6 additions & 4 deletions crates/libcontainer/src/process/container_main_process.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand All @@ -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)?;
Expand Down
7 changes: 6 additions & 1 deletion crates/youki/src/commands/create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())?
Expand Down
16 changes: 9 additions & 7 deletions crates/youki/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
},
Expand Down

0 comments on commit db4fb52

Please sign in to comment.