rustjail: fix blkio conversion

BFQ weight controller is using the same BFQ weight scheme (i.e 1->1000).
Therefore, there is no need to do the conversion.

More details here: https://github.com/opencontainers/runc/pull/2786

Fixes: #1440

Signed-off-by: Manabu Sugimoto <Manabu.Sugimoto@sony.com>
This commit is contained in:
Manabu Sugimoto 2021-02-21 16:26:55 +09:00
parent 29d4abf23a
commit dcea08697a

View File

@ -274,36 +274,22 @@ 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,
) -> Result<()> { ) -> Result<()> {
info!(sl!(), "cgroup manager set block io"); info!(sl!(), "cgroup manager set block io");
if cg.v2() { res.blkio.weight = blkio.weight;
res.blkio.weight = convert_blk_io_to_v2_value(blkio.weight); res.blkio.leaf_weight = blkio.leaf_weight;
res.blkio.leaf_weight = convert_blk_io_to_v2_value(blkio.leaf_weight);
} else {
res.blkio.weight = blkio.weight;
res.blkio.leaf_weight = blkio.leaf_weight;
}
let mut blk_device_resources = vec![]; let mut blk_device_resources = vec![];
for d in blkio.weight_device.iter() { for d in blkio.weight_device.iter() {
let (w, lw) = if cg.v2() {
(
convert_blk_io_to_v2_value(blkio.weight),
convert_blk_io_to_v2_value(blkio.leaf_weight),
)
} else {
(blkio.weight, blkio.leaf_weight)
};
let dr = BlkIoDeviceResource { let dr = BlkIoDeviceResource {
major: d.blk.major as u64, major: d.blk.major as u64,
minor: d.blk.minor as u64, minor: d.blk.minor as u64,
weight: w, weight: blkio.weight,
leaf_weight: lw, leaf_weight: blkio.leaf_weight,
}; };
blk_device_resources.push(dr); blk_device_resources.push(dr);
} }
@ -1107,20 +1093,6 @@ fn convert_memory_swap_to_v2_value(memory_swap: i64, memory: i64) -> Result<i64>
Ok(memory_swap - memory) Ok(memory_swap - memory)
} }
// Since the OCI spec is designed for cgroup v1, in some cases
// there is need to convert from the cgroup v1 configuration to cgroup v2
// the formula for BlkIOWeight is y = (1 + (x - 10) * 9999 / 990)
// convert linearly from [10-1000] to [1-10000]
// https://github.com/opencontainers/runc/blob/a5847db387ae28c0ca4ebe4beee1a76900c86414/libcontainer/cgroups/utils.go#L382
fn convert_blk_io_to_v2_value(blk_io_weight: Option<u16>) -> Option<u16> {
let v = blk_io_weight.unwrap_or(0);
if v != 0 {
return None;
}
Some(1 + (v - 10) * 9999 / 990 as u16)
}
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; use super::*;