agent/oci: Change name case to make clippy happy

Recent versions of clippy (e.g. in Rust 1.51) complain about a number
of names in the oci crate, which don't obey Rust's normal CamelCasing
conventions.

It's pretty clear that these don't obey the usual rules because they
are attempting to preserve conventional casing of existing acronyms
they incorporate ("VM", "POSIX", etc.).  However, it's been my
experience that matching the case and name conventions of your
environs is more important than matching case with external norms.

Therefore, this patch changes all the identifiers in the oci crate to
match Rust conventions.  Their users in the rustjail crate are updated
to match.

fixes #1611

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
This commit is contained in:
David Gibson 2021-04-14 19:33:06 +10:00
parent 3f5fdae0d8
commit eaec5a6c06
5 changed files with 83 additions and 83 deletions

View File

@ -58,7 +58,7 @@ pub struct Spec {
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub windows: Option<Windows<String>>, pub windows: Option<Windows<String>>,
#[serde(skip_serializing_if = "Option::is_none")] #[serde(skip_serializing_if = "Option::is_none")]
pub vm: Option<VM>, pub vm: Option<Vm>,
} }
impl Spec { impl Spec {
@ -71,7 +71,7 @@ impl Spec {
} }
} }
pub type LinuxRlimit = POSIXRlimit; pub type LinuxRlimit = PosixRlimit;
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
pub struct Process { pub struct Process {
@ -93,7 +93,7 @@ pub struct Process {
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
pub capabilities: Option<LinuxCapabilities>, pub capabilities: Option<LinuxCapabilities>,
#[serde(default, skip_serializing_if = "Vec::is_empty")] #[serde(default, skip_serializing_if = "Vec::is_empty")]
pub rlimits: Vec<POSIXRlimit>, pub rlimits: Vec<PosixRlimit>,
#[serde(default, rename = "noNewPrivileges")] #[serde(default, rename = "noNewPrivileges")]
pub no_new_privileges: bool, pub no_new_privileges: bool,
#[serde( #[serde(
@ -199,9 +199,9 @@ pub struct Hooks {
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
pub struct Linux { pub struct Linux {
#[serde(default, rename = "uidMappings", skip_serializing_if = "Vec::is_empty")] #[serde(default, rename = "uidMappings", skip_serializing_if = "Vec::is_empty")]
pub uid_mappings: Vec<LinuxIDMapping>, pub uid_mappings: Vec<LinuxIdMapping>,
#[serde(default, rename = "gidMappings", skip_serializing_if = "Vec::is_empty")] #[serde(default, rename = "gidMappings", skip_serializing_if = "Vec::is_empty")]
pub gid_mappings: Vec<LinuxIDMapping>, pub gid_mappings: Vec<LinuxIdMapping>,
#[serde(default, skip_serializing_if = "HashMap::is_empty")] #[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub sysctl: HashMap<String, String>, pub sysctl: HashMap<String, String>,
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
@ -261,7 +261,7 @@ pub const UTSNAMESPACE: &str = "uts";
pub const CGROUPNAMESPACE: &str = "cgroup"; pub const CGROUPNAMESPACE: &str = "cgroup";
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
pub struct LinuxIDMapping { pub struct LinuxIdMapping {
#[serde(default, rename = "containerID")] #[serde(default, rename = "containerID")]
pub container_id: u32, pub container_id: u32,
#[serde(default, rename = "hostID")] #[serde(default, rename = "hostID")]
@ -271,7 +271,7 @@ pub struct LinuxIDMapping {
} }
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
pub struct POSIXRlimit { pub struct PosixRlimit {
#[serde(default)] #[serde(default)]
pub r#type: String, pub r#type: String,
#[serde(default)] #[serde(default)]
@ -297,7 +297,7 @@ pub struct LinuxInterfacePriority {
} }
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
pub struct LinuxBlockIODevice { pub struct LinuxBlockIoDevice {
#[serde(default)] #[serde(default)]
pub major: i64, pub major: i64,
#[serde(default)] #[serde(default)]
@ -307,7 +307,7 @@ pub struct LinuxBlockIODevice {
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
pub struct LinuxWeightDevice { pub struct LinuxWeightDevice {
#[serde(flatten)] #[serde(flatten)]
pub blk: LinuxBlockIODevice, pub blk: LinuxBlockIoDevice,
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
pub weight: Option<u16>, pub weight: Option<u16>,
#[serde( #[serde(
@ -321,13 +321,13 @@ pub struct LinuxWeightDevice {
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
pub struct LinuxThrottleDevice { pub struct LinuxThrottleDevice {
#[serde(flatten)] #[serde(flatten)]
pub blk: LinuxBlockIODevice, pub blk: LinuxBlockIoDevice,
#[serde(default)] #[serde(default)]
pub rate: u64, pub rate: u64,
} }
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
pub struct LinuxBlockIO { pub struct LinuxBlockIo {
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
pub weight: Option<u16>, pub weight: Option<u16>,
#[serde( #[serde(
@ -391,7 +391,7 @@ pub struct LinuxMemory {
} }
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
pub struct LinuxCPU { pub struct LinuxCpu {
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
pub shares: Option<u64>, pub shares: Option<u64>,
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
@ -453,11 +453,11 @@ pub struct LinuxResources {
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
pub memory: Option<LinuxMemory>, pub memory: Option<LinuxMemory>,
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
pub cpu: Option<LinuxCPU>, pub cpu: Option<LinuxCpu>,
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
pub pids: Option<LinuxPids>, pub pids: Option<LinuxPids>,
#[serde(skip_serializing_if = "Option::is_none", rename = "blockIO")] #[serde(skip_serializing_if = "Option::is_none", rename = "blockIO")]
pub block_io: Option<LinuxBlockIO>, pub block_io: Option<LinuxBlockIo>,
#[serde( #[serde(
default, default,
skip_serializing_if = "Vec::is_empty", skip_serializing_if = "Vec::is_empty",
@ -517,7 +517,7 @@ pub struct Solaris {
#[serde(default, skip_serializing_if = "Vec::is_empty")] #[serde(default, skip_serializing_if = "Vec::is_empty")]
pub anet: Vec<SolarisAnet>, pub anet: Vec<SolarisAnet>,
#[serde(default, skip_serializing_if = "Option::is_none", rename = "cappedCPU")] #[serde(default, skip_serializing_if = "Option::is_none", rename = "cappedCPU")]
pub capped_cpu: Option<SolarisCappedCPU>, pub capped_cpu: Option<SolarisCappedCpu>,
#[serde( #[serde(
default, default,
skip_serializing_if = "Option::is_none", skip_serializing_if = "Option::is_none",
@ -527,7 +527,7 @@ pub struct Solaris {
} }
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
pub struct SolarisCappedCPU { pub struct SolarisCappedCpu {
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default, skip_serializing_if = "String::is_empty")]
pub ncpus: String, pub ncpus: String,
} }
@ -605,7 +605,7 @@ pub struct WindowsResources {
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
pub memory: Option<WindowsMemoryResources>, pub memory: Option<WindowsMemoryResources>,
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
pub cpu: Option<WindowsCPUResources>, pub cpu: Option<WindowsCpuResources>,
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
pub storage: Option<WindowsStorageResources>, pub storage: Option<WindowsStorageResources>,
} }
@ -617,7 +617,7 @@ pub struct WindowsMemoryResources {
} }
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
pub struct WindowsCPUResources { pub struct WindowsCpuResources {
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
pub count: Option<u64>, pub count: Option<u64>,
#[serde(default, skip_serializing_if = "Option::is_none")] #[serde(default, skip_serializing_if = "Option::is_none")]
@ -675,14 +675,14 @@ pub struct WindowsHyperV {
} }
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
pub struct VM { pub struct Vm {
pub hypervisor: VMHypervisor, pub hypervisor: VmHypervisor,
pub kernel: VMKernel, pub kernel: VmKernel,
pub image: VMImage, pub image: VmImage,
} }
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
pub struct VMHypervisor { pub struct VmHypervisor {
#[serde(default)] #[serde(default)]
pub path: String, pub path: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default, skip_serializing_if = "String::is_empty")]
@ -690,7 +690,7 @@ pub struct VMHypervisor {
} }
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
pub struct VMKernel { pub struct VmKernel {
#[serde(default)] #[serde(default)]
pub path: String, pub path: String,
#[serde(default, skip_serializing_if = "String::is_empty")] #[serde(default, skip_serializing_if = "String::is_empty")]
@ -700,7 +700,7 @@ pub struct VMKernel {
} }
#[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Default, Clone, PartialEq)]
pub struct VMImage { pub struct VmImage {
#[serde(default)] #[serde(default)]
pub path: String, pub path: String,
#[serde(default)] #[serde(default)]
@ -801,11 +801,11 @@ pub struct LinuxIntelRdt {
#[derive(Debug, Serialize, Deserialize, Copy, Clone, PartialEq)] #[derive(Debug, Serialize, Deserialize, Copy, Clone, PartialEq)]
#[serde(rename_all = "lowercase")] #[serde(rename_all = "lowercase")]
pub enum ContainerState { pub enum ContainerState {
CREATING, Creating,
CREATED, Created,
RUNNING, Running,
STOPPED, Stopped,
PAUSED, Paused,
} }
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
@ -846,7 +846,7 @@ mod tests {
let expected = State { let expected = State {
version: "0.2.0".to_string(), version: "0.2.0".to_string(),
id: "oci-container1".to_string(), id: "oci-container1".to_string(),
status: ContainerState::RUNNING, status: ContainerState::Running,
pid: 4422, pid: 4422,
bundle: "/containers/redis".to_string(), bundle: "/containers/redis".to_string(),
annotations: [("myKey".to_string(), "myValue".to_string())] annotations: [("myKey".to_string(), "myValue".to_string())]
@ -1271,12 +1271,12 @@ mod tests {
ambient: vec!["CAP_NET_BIND_SERVICE".to_string()], ambient: vec!["CAP_NET_BIND_SERVICE".to_string()],
}), }),
rlimits: vec![ rlimits: vec![
crate::POSIXRlimit { crate::PosixRlimit {
r#type: "RLIMIT_CORE".to_string(), r#type: "RLIMIT_CORE".to_string(),
hard: 1024, hard: 1024,
soft: 1024, soft: 1024,
}, },
crate::POSIXRlimit { crate::PosixRlimit {
r#type: "RLIMIT_NOFILE".to_string(), r#type: "RLIMIT_NOFILE".to_string(),
hard: 1024, hard: 1024,
soft: 1024, soft: 1024,
@ -1408,12 +1408,12 @@ mod tests {
.cloned() .cloned()
.collect(), .collect(),
linux: Some(crate::Linux { linux: Some(crate::Linux {
uid_mappings: vec![crate::LinuxIDMapping { uid_mappings: vec![crate::LinuxIdMapping {
container_id: 0, container_id: 0,
host_id: 1000, host_id: 1000,
size: 32000, size: 32000,
}], }],
gid_mappings: vec![crate::LinuxIDMapping { gid_mappings: vec![crate::LinuxIdMapping {
container_id: 0, container_id: 0,
host_id: 1000, host_id: 1000,
size: 32000, size: 32000,
@ -1458,7 +1458,7 @@ mod tests {
swappiness: Some(0), swappiness: Some(0),
disable_oom_killer: Some(false), disable_oom_killer: Some(false),
}), }),
cpu: Some(crate::LinuxCPU { cpu: Some(crate::LinuxCpu {
shares: Some(1024), shares: Some(1024),
quota: Some(1000000), quota: Some(1000000),
period: Some(500000), period: Some(500000),
@ -1468,17 +1468,17 @@ mod tests {
mems: "0-7".to_string(), mems: "0-7".to_string(),
}), }),
pids: Some(crate::LinuxPids { limit: 32771 }), pids: Some(crate::LinuxPids { limit: 32771 }),
block_io: Some(crate::LinuxBlockIO { block_io: Some(crate::LinuxBlockIo {
weight: Some(10), weight: Some(10),
leaf_weight: Some(10), leaf_weight: Some(10),
weight_device: vec![ weight_device: vec![
crate::LinuxWeightDevice { crate::LinuxWeightDevice {
blk: crate::LinuxBlockIODevice { major: 8, minor: 0 }, blk: crate::LinuxBlockIoDevice { major: 8, minor: 0 },
weight: Some(500), weight: Some(500),
leaf_weight: Some(300), leaf_weight: Some(300),
}, },
crate::LinuxWeightDevice { crate::LinuxWeightDevice {
blk: crate::LinuxBlockIODevice { blk: crate::LinuxBlockIoDevice {
major: 8, major: 8,
minor: 16, minor: 16,
}, },
@ -1487,13 +1487,13 @@ mod tests {
}, },
], ],
throttle_read_bps_device: vec![crate::LinuxThrottleDevice { throttle_read_bps_device: vec![crate::LinuxThrottleDevice {
blk: crate::LinuxBlockIODevice { major: 8, minor: 0 }, blk: crate::LinuxBlockIoDevice { major: 8, minor: 0 },
rate: 600, rate: 600,
}], }],
throttle_write_bps_device: vec![], throttle_write_bps_device: vec![],
throttle_read_iops_device: vec![], throttle_read_iops_device: vec![],
throttle_write_iops_device: vec![crate::LinuxThrottleDevice { throttle_write_iops_device: vec![crate::LinuxThrottleDevice {
blk: crate::LinuxBlockIODevice { blk: crate::LinuxBlockIoDevice {
major: 8, major: 8,
minor: 16, minor: 16,
}, },

View File

@ -24,7 +24,7 @@ use anyhow::{anyhow, Context, Result};
use libc::{self, pid_t}; use libc::{self, pid_t};
use nix::errno::Errno; use nix::errno::Errno;
use oci::{ use oci::{
LinuxBlockIO, LinuxCPU, LinuxDevice, LinuxDeviceCgroup, LinuxHugepageLimit, LinuxMemory, LinuxBlockIo, LinuxCpu, LinuxDevice, LinuxDeviceCgroup, LinuxHugepageLimit, LinuxMemory,
LinuxNetwork, LinuxPids, LinuxResources, LinuxNetwork, LinuxPids, LinuxResources,
}; };
@ -272,7 +272,7 @@ fn set_hugepages_resources(
fn set_block_io_resources( fn set_block_io_resources(
_cg: &cgroups::Cgroup, _cg: &cgroups::Cgroup,
blkio: &LinuxBlockIO, blkio: &LinuxBlockIo,
res: &mut cgroups::Resources, res: &mut cgroups::Resources,
) { ) {
info!(sl!(), "cgroup manager set block io"); info!(sl!(), "cgroup manager set block io");
@ -302,7 +302,7 @@ fn set_block_io_resources(
build_blk_io_device_throttle_resource(&blkio.throttle_write_iops_device); build_blk_io_device_throttle_resource(&blkio.throttle_write_iops_device);
} }
fn set_cpu_resources(cg: &cgroups::Cgroup, cpu: &LinuxCPU) -> Result<()> { fn set_cpu_resources(cg: &cgroups::Cgroup, cpu: &LinuxCpu) -> Result<()> {
info!(sl!(), "cgroup manager set cpu"); info!(sl!(), "cgroup manager set cpu");
let cpuset_controller: &CpuSetController = cg.controller_of().unwrap(); let cpuset_controller: &CpuSetController = cg.controller_of().unwrap();

View File

@ -5,7 +5,7 @@
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use libc::pid_t; use libc::pid_t;
use oci::{ContainerState, LinuxDevice, LinuxIDMapping}; use oci::{ContainerState, LinuxDevice, LinuxIdMapping};
use oci::{Hook, Linux, LinuxNamespace, LinuxResources, Spec}; use oci::{Hook, Linux, LinuxNamespace, LinuxResources, Spec};
use std::clone::Clone; use std::clone::Clone;
use std::ffi::{CStr, CString}; use std::ffi::{CStr, CString};
@ -83,8 +83,8 @@ pub struct ContainerStatus {
impl ContainerStatus { impl ContainerStatus {
fn new() -> Self { fn new() -> Self {
ContainerStatus { ContainerStatus {
pre_status: ContainerState::CREATED, pre_status: ContainerState::Created,
cur_status: ContainerState::CREATED, cur_status: ContainerState::Created,
} }
} }
@ -255,7 +255,7 @@ pub struct State {
} }
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Clone)]
pub struct SyncPC { pub struct SyncPc {
#[serde(default)] #[serde(default)]
pid: pid_t, pid: pid_t,
} }
@ -268,7 +268,7 @@ pub trait Container: BaseContainer {
impl Container for LinuxContainer { impl Container for LinuxContainer {
fn pause(&mut self) -> Result<()> { fn pause(&mut self) -> Result<()> {
let status = self.status(); let status = self.status();
if status != ContainerState::RUNNING && status != ContainerState::CREATED { if status != ContainerState::Running && status != ContainerState::Created {
return Err(anyhow!( return Err(anyhow!(
"failed to pause container: current status is: {:?}", "failed to pause container: current status is: {:?}",
status status
@ -281,7 +281,7 @@ impl Container for LinuxContainer {
.unwrap() .unwrap()
.freeze(FreezerState::Frozen)?; .freeze(FreezerState::Frozen)?;
self.status.transition(ContainerState::PAUSED); self.status.transition(ContainerState::Paused);
return Ok(()); return Ok(());
} }
Err(anyhow!("failed to get container's cgroup manager")) Err(anyhow!("failed to get container's cgroup manager"))
@ -289,7 +289,7 @@ impl Container for LinuxContainer {
fn resume(&mut self) -> Result<()> { fn resume(&mut self) -> Result<()> {
let status = self.status(); let status = self.status();
if status != ContainerState::PAUSED { if status != ContainerState::Paused {
return Err(anyhow!("container status is: {:?}, not paused", status)); return Err(anyhow!("container status is: {:?}, not paused", status));
} }
@ -299,7 +299,7 @@ impl Container for LinuxContainer {
.unwrap() .unwrap()
.freeze(FreezerState::Thawed)?; .freeze(FreezerState::Thawed)?;
self.status.transition(ContainerState::RUNNING); self.status.transition(ContainerState::Running);
return Ok(()); return Ok(());
} }
Err(anyhow!("failed to get container's cgroup manager")) Err(anyhow!("failed to get container's cgroup manager"))
@ -734,7 +734,7 @@ impl BaseContainer for LinuxContainer {
}; };
let status = self.status(); let status = self.status();
let pid = if status != ContainerState::STOPPED { let pid = if status != ContainerState::Stopped {
self.init_process_pid self.init_process_pid
} else { } else {
0 0
@ -997,7 +997,7 @@ impl BaseContainer for LinuxContainer {
if init { if init {
self.exec()?; self.exec()?;
self.status.transition(ContainerState::RUNNING); self.status.transition(ContainerState::Running);
} }
Ok(()) Ok(())
@ -1019,7 +1019,7 @@ impl BaseContainer for LinuxContainer {
} }
} }
self.status.transition(ContainerState::STOPPED); self.status.transition(ContainerState::Stopped);
mount::umount2( mount::umount2(
spec.root.as_ref().unwrap().path.as_str(), spec.root.as_ref().unwrap().path.as_str(),
MntFlags::MNT_DETACH, MntFlags::MNT_DETACH,
@ -1055,7 +1055,7 @@ impl BaseContainer for LinuxContainer {
.unwrap() .unwrap()
.as_secs(); .as_secs();
self.status.transition(ContainerState::RUNNING); self.status.transition(ContainerState::Running);
unistd::close(fd)?; unistd::close(fd)?;
Ok(()) Ok(())
@ -1302,7 +1302,7 @@ async fn join_namespaces(
Ok(()) Ok(())
} }
fn write_mappings(logger: &Logger, path: &str, maps: &[LinuxIDMapping]) -> Result<()> { fn write_mappings(logger: &Logger, path: &str, maps: &[LinuxIdMapping]) -> Result<()> {
let data = maps let data = maps
.iter() .iter()
.filter(|m| m.size != 0) .filter(|m| m.size != 0)
@ -1588,7 +1588,7 @@ mod tests {
&OCIState { &OCIState {
version: "1.2.3".to_string(), version: "1.2.3".to_string(),
id: "321".to_string(), id: "321".to_string(),
status: ContainerState::RUNNING, status: ContainerState::Running,
pid: 2, pid: 2,
bundle: "".to_string(), bundle: "".to_string(),
annotations: Default::default(), annotations: Default::default(),
@ -1611,7 +1611,7 @@ mod tests {
&OCIState { &OCIState {
version: "1.2.3".to_string(), version: "1.2.3".to_string(),
id: "321".to_string(), id: "321".to_string(),
status: ContainerState::RUNNING, status: ContainerState::Running,
pid: 2, pid: 2,
bundle: "".to_string(), bundle: "".to_string(),
annotations: Default::default(), annotations: Default::default(),
@ -1630,10 +1630,10 @@ mod tests {
fn test_status_transtition() { fn test_status_transtition() {
let mut status = ContainerStatus::new(); let mut status = ContainerStatus::new();
let status_table: [ContainerState; 4] = [ let status_table: [ContainerState; 4] = [
ContainerState::CREATED, ContainerState::Created,
ContainerState::RUNNING, ContainerState::Running,
ContainerState::PAUSED, ContainerState::Paused,
ContainerState::STOPPED, ContainerState::Stopped,
]; ];
for s in status_table.iter() { for s in status_table.iter() {
@ -1770,7 +1770,7 @@ mod tests {
fn test_linuxcontainer_pause_bad_status() { fn test_linuxcontainer_pause_bad_status() {
let ret = new_linux_container_and_then(|mut c: LinuxContainer| { let ret = new_linux_container_and_then(|mut c: LinuxContainer| {
// Change state to pause, c.pause() should fail // Change state to pause, c.pause() should fail
c.status.transition(ContainerState::PAUSED); c.status.transition(ContainerState::Paused);
c.pause().map_err(|e| anyhow!(e)) c.pause().map_err(|e| anyhow!(e))
}); });
@ -1802,7 +1802,7 @@ mod tests {
fn test_linuxcontainer_resume_bad_status() { fn test_linuxcontainer_resume_bad_status() {
let ret = new_linux_container_and_then(|mut c: LinuxContainer| { let ret = new_linux_container_and_then(|mut c: LinuxContainer| {
// Change state to created, c.resume() should fail // Change state to created, c.resume() should fail
c.status.transition(ContainerState::CREATED); c.status.transition(ContainerState::Created);
c.resume().map_err(|e| anyhow!(e)) c.resume().map_err(|e| anyhow!(e))
}); });
@ -1813,7 +1813,7 @@ mod tests {
#[test] #[test]
fn test_linuxcontainer_resume_cgroupmgr_is_none() { fn test_linuxcontainer_resume_cgroupmgr_is_none() {
let ret = new_linux_container_and_then(|mut c: LinuxContainer| { let ret = new_linux_container_and_then(|mut c: LinuxContainer| {
c.status.transition(ContainerState::PAUSED); c.status.transition(ContainerState::Paused);
c.cgroup_manager = None; c.cgroup_manager = None;
c.resume().map_err(|e| anyhow!(e)) c.resume().map_err(|e| anyhow!(e))
}); });
@ -1826,7 +1826,7 @@ mod tests {
let ret = new_linux_container_and_then(|mut c: LinuxContainer| { let ret = new_linux_container_and_then(|mut c: LinuxContainer| {
c.cgroup_manager = FsManager::new("").ok(); c.cgroup_manager = FsManager::new("").ok();
// Change status to paused, this way we can resume it // Change status to paused, this way we can resume it
c.status.transition(ContainerState::PAUSED); c.status.transition(ContainerState::Paused);
c.resume().map_err(|e| anyhow!(e)) c.resume().map_err(|e| anyhow!(e))
}); });

View File

@ -109,7 +109,7 @@ pub fn process_grpc_to_oci(p: &grpc::Process) -> oci::Process {
let rlimits = { let rlimits = {
let mut r = Vec::new(); let mut r = Vec::new();
for lm in p.Rlimits.iter() { for lm in p.Rlimits.iter() {
r.push(oci::POSIXRlimit { r.push(oci::PosixRlimit {
r#type: lm.Type.clone(), r#type: lm.Type.clone(),
hard: lm.Hard, hard: lm.Hard,
soft: lm.Soft, soft: lm.Soft,
@ -179,15 +179,15 @@ fn hooks_grpc_to_oci(h: &grpc::Hooks) -> oci::Hooks {
} }
} }
fn idmap_grpc_to_oci(im: &grpc::LinuxIDMapping) -> oci::LinuxIDMapping { fn idmap_grpc_to_oci(im: &grpc::LinuxIDMapping) -> oci::LinuxIdMapping {
oci::LinuxIDMapping { oci::LinuxIdMapping {
container_id: im.ContainerID, container_id: im.ContainerID,
host_id: im.HostID, host_id: im.HostID,
size: im.Size, size: im.Size,
} }
} }
fn idmaps_grpc_to_oci(ims: &[grpc::LinuxIDMapping]) -> Vec<oci::LinuxIDMapping> { fn idmaps_grpc_to_oci(ims: &[grpc::LinuxIDMapping]) -> Vec<oci::LinuxIdMapping> {
let mut r = Vec::new(); let mut r = Vec::new();
for im in ims.iter() { for im in ims.iter() {
r.push(idmap_grpc_to_oci(im)); r.push(idmap_grpc_to_oci(im));
@ -201,7 +201,7 @@ fn throttle_devices_grpc_to_oci(
let mut r = Vec::new(); let mut r = Vec::new();
for td in tds.iter() { for td in tds.iter() {
r.push(oci::LinuxThrottleDevice { r.push(oci::LinuxThrottleDevice {
blk: oci::LinuxBlockIODevice { blk: oci::LinuxBlockIoDevice {
major: td.Major, major: td.Major,
minor: td.Minor, minor: td.Minor,
}, },
@ -215,7 +215,7 @@ fn weight_devices_grpc_to_oci(wds: &[grpc::LinuxWeightDevice]) -> Vec<oci::Linux
let mut r = Vec::new(); let mut r = Vec::new();
for wd in wds.iter() { for wd in wds.iter() {
r.push(oci::LinuxWeightDevice { r.push(oci::LinuxWeightDevice {
blk: oci::LinuxBlockIODevice { blk: oci::LinuxBlockIoDevice {
major: wd.Major, major: wd.Major,
minor: wd.Minor, minor: wd.Minor,
}, },
@ -226,7 +226,7 @@ fn weight_devices_grpc_to_oci(wds: &[grpc::LinuxWeightDevice]) -> Vec<oci::Linux
r r
} }
fn blockio_grpc_to_oci(blk: &grpc::LinuxBlockIO) -> oci::LinuxBlockIO { fn blockio_grpc_to_oci(blk: &grpc::LinuxBlockIO) -> oci::LinuxBlockIo {
let weight_device = weight_devices_grpc_to_oci(blk.WeightDevice.as_ref()); let weight_device = weight_devices_grpc_to_oci(blk.WeightDevice.as_ref());
let throttle_read_bps_device = throttle_devices_grpc_to_oci(blk.ThrottleReadBpsDevice.as_ref()); let throttle_read_bps_device = throttle_devices_grpc_to_oci(blk.ThrottleReadBpsDevice.as_ref());
let throttle_write_bps_device = let throttle_write_bps_device =
@ -236,7 +236,7 @@ fn blockio_grpc_to_oci(blk: &grpc::LinuxBlockIO) -> oci::LinuxBlockIO {
let throttle_write_iops_device = let throttle_write_iops_device =
throttle_devices_grpc_to_oci(blk.ThrottleWriteIOPSDevice.as_ref()); throttle_devices_grpc_to_oci(blk.ThrottleWriteIOPSDevice.as_ref());
oci::LinuxBlockIO { oci::LinuxBlockIo {
weight: Some(blk.Weight as u16), weight: Some(blk.Weight as u16),
leaf_weight: Some(blk.LeafWeight as u16), leaf_weight: Some(blk.LeafWeight as u16),
weight_device, weight_device,
@ -290,7 +290,7 @@ pub fn resources_grpc_to_oci(res: &grpc::LinuxResources) -> oci::LinuxResources
let cpu = if res.CPU.is_some() { let cpu = if res.CPU.is_some() {
let c = res.CPU.as_ref().unwrap(); let c = res.CPU.as_ref().unwrap();
Some(oci::LinuxCPU { Some(oci::LinuxCpu {
shares: Some(c.Shares), shares: Some(c.Shares),
quota: Some(c.Quota), quota: Some(c.Quota),
period: Some(c.Period), period: Some(c.Period),

View File

@ -6,7 +6,7 @@
use crate::container::Config; use crate::container::Config;
use anyhow::{anyhow, Context, Error, Result}; use anyhow::{anyhow, Context, Error, Result};
use nix::errno::Errno; use nix::errno::Errno;
use oci::{Linux, LinuxIDMapping, LinuxNamespace, Spec}; use oci::{Linux, LinuxIdMapping, LinuxNamespace, Spec};
use std::collections::HashMap; use std::collections::HashMap;
use std::path::{Component, PathBuf}; use std::path::{Component, PathBuf};
@ -107,7 +107,7 @@ fn security(oci: &Spec) -> Result<()> {
Ok(()) Ok(())
} }
fn idmapping(maps: &[LinuxIDMapping]) -> Result<()> { fn idmapping(maps: &[LinuxIdMapping]) -> Result<()> {
for map in maps { for map in maps {
if map.size > 0 { if map.size > 0 {
return Ok(()); return Ok(());
@ -238,7 +238,7 @@ fn rootless_euid_mapping(oci: &Spec) -> Result<()> {
Ok(()) Ok(())
} }
fn has_idmapping(maps: &[LinuxIDMapping], id: u32) -> bool { fn has_idmapping(maps: &[LinuxIdMapping], id: u32) -> bool {
for map in maps { for map in maps {
if id >= map.container_id && id < map.container_id + map.size { if id >= map.container_id && id < map.container_id + map.size {
return true; return true;
@ -441,7 +441,7 @@ mod tests {
usernamespace(&spec).unwrap(); usernamespace(&spec).unwrap();
let mut linux = Linux::default(); let mut linux = Linux::default();
linux.uid_mappings = vec![LinuxIDMapping { linux.uid_mappings = vec![LinuxIdMapping {
container_id: 0, container_id: 0,
host_id: 1000, host_id: 1000,
size: 0, size: 0,
@ -450,7 +450,7 @@ mod tests {
usernamespace(&spec).unwrap_err(); usernamespace(&spec).unwrap_err();
let mut linux = Linux::default(); let mut linux = Linux::default();
linux.uid_mappings = vec![LinuxIDMapping { linux.uid_mappings = vec![LinuxIdMapping {
container_id: 0, container_id: 0,
host_id: 1000, host_id: 1000,
size: 100, size: 100,
@ -497,12 +497,12 @@ mod tests {
path: "/sys/cgroups/user".to_owned(), path: "/sys/cgroups/user".to_owned(),
}, },
]; ];
linux.uid_mappings = vec![LinuxIDMapping { linux.uid_mappings = vec![LinuxIdMapping {
container_id: 0, container_id: 0,
host_id: 1000, host_id: 1000,
size: 1000, size: 1000,
}]; }];
linux.gid_mappings = vec![LinuxIDMapping { linux.gid_mappings = vec![LinuxIdMapping {
container_id: 0, container_id: 0,
host_id: 1000, host_id: 1000,
size: 1000, size: 1000,