mirror of
https://github.com/opencontainers/runc.git
synced 2026-07-10 21:53:57 +08:00
Merge pull request #2957 from haircommander/export-RangeToBits
libctr/cg/systemd: export rangeToBits
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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, ",") {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user