|
@@ -240,6 +240,10 @@ func (c *Manager) Controllers() ([]string, error) {
|
|
return strings.Fields(string(b)), nil
|
|
return strings.Fields(string(b)), nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+func (c *Manager) Update(resources *Resources) error {
|
|
|
|
+ return setResources(c.path, resources)
|
|
|
|
+}
|
|
|
|
+
|
|
type ControllerToggle int
|
|
type ControllerToggle int
|
|
|
|
|
|
const (
|
|
const (
|
|
@@ -701,12 +705,39 @@ func setDevices(path string, devices []specs.LinuxDeviceCgroup) error {
|
|
return nil
|
|
return nil
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+// getSystemdFullPath returns the full systemd path when creating a systemd slice group.
|
|
|
|
+// the reason this is necessary is because the "-" character has a special meaning in
|
|
|
|
+// systemd slice. For example, when creating a slice called "my-group-112233.slice",
|
|
|
|
+// systemd will create a hierarchy like this:
|
|
|
|
+// /sys/fs/cgroup/my.slice/my-group.slice/my-group-112233.slice
|
|
|
|
+func getSystemdFullPath(slice, group string) string {
|
|
|
|
+ return filepath.Join(defaultCgroup2Path, dashesToPath(slice), dashesToPath(group))
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+// dashesToPath converts a slice name with dashes to it's corresponding systemd filesystem path.
|
|
|
|
+func dashesToPath(in string) string {
|
|
|
|
+ path := ""
|
|
|
|
+ if strings.HasSuffix(in, ".slice") && strings.Contains(in, "-") {
|
|
|
|
+ parts := strings.Split(in, "-")
|
|
|
|
+ for i := range parts {
|
|
|
|
+ s := strings.Join(parts[0:i+1], "-")
|
|
|
|
+ if !strings.HasSuffix(s, ".slice") {
|
|
|
|
+ s += ".slice"
|
|
|
|
+ }
|
|
|
|
+ path = filepath.Join(path, s)
|
|
|
|
+ }
|
|
|
|
+ } else {
|
|
|
|
+ path = filepath.Join(path, in)
|
|
|
|
+ }
|
|
|
|
+ return path
|
|
|
|
+}
|
|
|
|
+
|
|
func NewSystemd(slice, group string, pid int, resources *Resources) (*Manager, error) {
|
|
func NewSystemd(slice, group string, pid int, resources *Resources) (*Manager, error) {
|
|
if slice == "" {
|
|
if slice == "" {
|
|
slice = defaultSlice
|
|
slice = defaultSlice
|
|
}
|
|
}
|
|
ctx := context.TODO()
|
|
ctx := context.TODO()
|
|
- path := filepath.Join(defaultCgroup2Path, slice, group)
|
|
|
|
|
|
+ path := getSystemdFullPath(slice, group)
|
|
conn, err := systemdDbus.NewWithContext(ctx)
|
|
conn, err := systemdDbus.NewWithContext(ctx)
|
|
if err != nil {
|
|
if err != nil {
|
|
return &Manager{}, err
|
|
return &Manager{}, err
|
|
@@ -734,12 +765,17 @@ func NewSystemd(slice, group string, pid int, resources *Resources) (*Manager, e
|
|
properties = append(properties, newSystemdProperty("PIDs", []uint32{uint32(pid)}))
|
|
properties = append(properties, newSystemdProperty("PIDs", []uint32{uint32(pid)}))
|
|
}
|
|
}
|
|
|
|
|
|
- if resources.Memory != nil && *resources.Memory.Max != 0 {
|
|
|
|
|
|
+ if resources.Memory != nil && resources.Memory.Min != nil && *resources.Memory.Min != 0 {
|
|
|
|
+ properties = append(properties,
|
|
|
|
+ newSystemdProperty("MemoryMin", uint64(*resources.Memory.Min)))
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if resources.Memory != nil && resources.Memory.Max != nil && *resources.Memory.Max != 0 {
|
|
properties = append(properties,
|
|
properties = append(properties,
|
|
newSystemdProperty("MemoryMax", uint64(*resources.Memory.Max)))
|
|
newSystemdProperty("MemoryMax", uint64(*resources.Memory.Max)))
|
|
}
|
|
}
|
|
|
|
|
|
- if resources.CPU != nil && *resources.CPU.Weight != 0 {
|
|
|
|
|
|
+ if resources.CPU != nil && resources.CPU.Weight != nil && *resources.CPU.Weight != 0 {
|
|
properties = append(properties,
|
|
properties = append(properties,
|
|
newSystemdProperty("CPUWeight", *resources.CPU.Weight))
|
|
newSystemdProperty("CPUWeight", *resources.CPU.Weight))
|
|
}
|
|
}
|
|
@@ -796,9 +832,9 @@ func LoadSystemd(slice, group string) (*Manager, error) {
|
|
if slice == "" {
|
|
if slice == "" {
|
|
slice = defaultSlice
|
|
slice = defaultSlice
|
|
}
|
|
}
|
|
- group = filepath.Join(defaultCgroup2Path, slice, group)
|
|
|
|
|
|
+ path := getSystemdFullPath(slice, group)
|
|
return &Manager{
|
|
return &Manager{
|
|
- path: group,
|
|
|
|
|
|
+ path: path,
|
|
}, nil
|
|
}, nil
|
|
}
|
|
}
|
|
|
|
|