Skip to content

Commit

Permalink
Merge pull request #3808 from kolyshkin/1.1-cpuset-byte-order
Browse files Browse the repository at this point in the history
[1.1] cgroups: cpuset: fix byte order while parsing cpuset range to bits
  • Loading branch information
mrunalp authored Apr 7, 2023
2 parents e5e8c2a + c197aaf commit ea9fb99
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
5 changes: 5 additions & 0 deletions libcontainer/cgroups/systemd/cpuset.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,10 @@ func RangeToBits(str string) ([]byte, error) {
// do not allow empty values
return nil, errors.New("empty value")
}

// fit cpuset parsing order in systemd
for l, r := 0, len(ret)-1; l < r; l, r = l+1, r-1 {
ret[l], ret[r] = ret[r], ret[l]
}
return ret, nil
}
6 changes: 3 additions & 3 deletions libcontainer/cgroups/systemd/cpuset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ func TestRangeToBits(t *testing.T) {
{in: "4-7", out: []byte{0xf0}},
{in: "0-7", out: []byte{0xff}},
{in: "0-15", out: []byte{0xff, 0xff}},
{in: "16", out: []byte{1, 0, 0}},
{in: "0-3,32-33", out: []byte{3, 0, 0, 0, 0x0f}},
{in: "16", out: []byte{0, 0, 1}},
{in: "0-3,32-33", out: []byte{0x0f, 0, 0, 0, 3}},
// extra spaces and tabs are ok
{in: "1, 2, 1-2", out: []byte{6}},
{in: " , 1 , 3 , 5-7, ", out: []byte{0xea}},
// somewhat large values
{in: "128-130,1", out: []byte{7, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2}},
{in: "128-130,1", out: []byte{2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 7}},

{in: "-", isErr: true},
{in: "1-", isErr: true},
Expand Down

0 comments on commit ea9fb99

Please sign in to comment.