Skip to content

Commit

Permalink
Merge pull request #65 from containers/fix/device-type-a
Browse files Browse the repository at this point in the history
The type a of device was needed to mean All.
  • Loading branch information
saschagrunert authored Sep 8, 2021
2 parents eec87cf + 5dd06f8 commit c08b362
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 8 additions & 3 deletions src/runtime/linux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,9 @@ pub struct LinuxIdMapping {
#[serde(rename_all = "lowercase")]
/// Device types
pub enum LinuxDeviceType {
/// All
A,

/// block (buffered)
B,

Expand All @@ -178,14 +181,15 @@ pub enum LinuxDeviceType {

impl Default for LinuxDeviceType {
fn default() -> LinuxDeviceType {
LinuxDeviceType::B
LinuxDeviceType::A
}
}

impl LinuxDeviceType {
/// Retrieve a string reference for the device type.
pub fn as_str(&self) -> &str {
match self {
Self::A => "a",
Self::B => "b",
Self::C => "c",
Self::U => "u",
Expand Down Expand Up @@ -1121,16 +1125,17 @@ fn some_none_generator_util<T: Arbitrary>(g: &mut Gen) -> Option<T> {
#[cfg(feature = "proptests")]
impl Arbitrary for LinuxDeviceCgroup {
fn arbitrary(g: &mut Gen) -> LinuxDeviceCgroup {
let typ_choices = ["b", "c", "u", "p"];
let typ_choices = ["a", "b", "c", "u", "p"];

let typ_chosen = g.choose(&typ_choices).unwrap();

let typ = match typ_chosen.to_string().as_str() {
"a" => LinuxDeviceType::A,
"b" => LinuxDeviceType::B,
"c" => LinuxDeviceType::C,
"u" => LinuxDeviceType::U,
"p" => LinuxDeviceType::P,
_ => LinuxDeviceType::B,
_ => LinuxDeviceType::A,
};

let access_choices = ["rwm", "m"];
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ fn test_linux_device_cgroup_to_string() {

let ldc = LinuxDeviceCgroupBuilder::default()
.allow(true)
.typ(LinuxDeviceType::B)
.typ(LinuxDeviceType::A)
.major(1)
.minor(9)
.access("rwm".to_string())
.build()
.expect("build device cgroup");
assert_eq!(ldc.to_string(), "b 1:9 rwm");
assert_eq!(ldc.to_string(), "a 1:9 rwm");
}

0 comments on commit c08b362

Please sign in to comment.