Merge pull request #2957 from haircommander/export-RangeToBits

libctr/cg/systemd: export rangeToBits
This commit is contained in:
Mrunal Patel
2021-05-21 13:36:16 -04:00
committed by GitHub
4 changed files with 6 additions and 6 deletions
+2 -2
View File
@@ -476,7 +476,7 @@ func addCpuset(cm *dbusConnManager, props *[]systemdDbus.Property, cpus, mems st
}
if cpus != "" {
bits, err := rangeToBits(cpus)
bits, err := RangeToBits(cpus)
if err != nil {
return fmt.Errorf("resources.CPU.Cpus=%q conversion error: %w",
cpus, err)
@@ -485,7 +485,7 @@ func addCpuset(cm *dbusConnManager, props *[]systemdDbus.Property, cpus, mems st
newProp("AllowedCPUs", bits))
}
if mems != "" {
bits, err := rangeToBits(mems)
bits, err := RangeToBits(mems)
if err != nil {
return fmt.Errorf("resources.CPU.Mems=%q conversion error: %w",
mems, err)
+2 -2
View File
@@ -9,11 +9,11 @@ import (
"github.com/willf/bitset"
)
// rangeToBits converts a text representation of a CPU mask (as written to
// RangeToBits converts a text representation of a CPU mask (as written to
// or read from cgroups' cpuset.* files, e.g. "1,3-5") to a slice of bytes
// with the corresponding bits set (as consumed by systemd over dbus as
// AllowedCPUs/AllowedMemoryNodes unit property value).
func rangeToBits(str string) ([]byte, error) {
func RangeToBits(str string) ([]byte, error) {
bits := &bitset.BitSet{}
for _, r := range strings.Split(str, ",") {
+1 -1
View File
@@ -40,7 +40,7 @@ func TestRangeToBits(t *testing.T) {
}
for _, tc := range testCases {
out, err := rangeToBits(tc.in)
out, err := RangeToBits(tc.in)
if err != nil {
if !tc.isErr {
t.Errorf("case %q: unexpected error: %v", tc.in, err)
+1 -1
View File
@@ -96,7 +96,7 @@ func unifiedResToSystemdProps(cm *dbusConnManager, res map[string]string) (props
newProp("CPUWeight", num))
case "cpuset.cpus", "cpuset.mems":
bits, err := rangeToBits(v)
bits, err := RangeToBits(v)
if err != nil {
return nil, fmt.Errorf("unified resource %q=%q conversion error: %w", k, v, err)
}