From 30d83d4d2fa046349bfe4fac7ae9ce6d7549d638 Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Sun, 13 Jun 2021 18:03:22 -0700 Subject: [PATCH] libct/cg/fs/blkio: do not set weight == 0 For per-device weight, you can set weight and/or leaf weight. The problem is, with the recent fix to use BFQ on cgroup v1, if per-device weights are set, the code tries to set device weight to blkio.bfq.weight, and the leaf weight to blkio.leaf_weight_device. The latter file does not exist on kernels v5.0, meaning one can not set any per-device weights at all. The fix is to only set weights if they are non-zero (i.e. set). The test case will come in a following commit. Fixes: 6339d8a0dd7a72 Signed-off-by: Kir Kolyshkin --- libcontainer/cgroups/fs/blkio.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/libcontainer/cgroups/fs/blkio.go b/libcontainer/cgroups/fs/blkio.go index 8aa8fcdc41e..88012a2f5f1 100644 --- a/libcontainer/cgroups/fs/blkio.go +++ b/libcontainer/cgroups/fs/blkio.go @@ -41,11 +41,15 @@ func (s *BlkioGroup) Set(path string, r *configs.Resources) error { } } for _, wd := range r.BlkioWeightDevice { - if err := cgroups.WriteFile(path, s.weightDeviceFilename, wd.WeightString()); err != nil { - return err + if wd.Weight != 0 { + if err := cgroups.WriteFile(path, s.weightDeviceFilename, wd.WeightString()); err != nil { + return err + } } - if err := cgroups.WriteFile(path, "blkio.leaf_weight_device", wd.LeafWeightString()); err != nil { - return err + if wd.LeafWeight != 0 { + if err := cgroups.WriteFile(path, "blkio.leaf_weight_device", wd.LeafWeightString()); err != nil { + return err + } } } for _, td := range r.BlkioThrottleReadBpsDevice {