Skip to content
This repository has been archived by the owner on Dec 13, 2018. It is now read-only.

Commit

Permalink
cgroups: Make systemd cgroup parent support to use specified slices.
Browse files Browse the repository at this point in the history
Signed-off-by: Mrunal Patel <[email protected]>
  • Loading branch information
mrunalp committed May 17, 2015
1 parent 94e6c73 commit bd948ae
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 9 deletions.
10 changes: 5 additions & 5 deletions cgroups/systemd/apply_systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ func (m *Manager) Apply(pid int) error {
properties []systemd.Property
)

if c.Slice != "" {
slice = c.Slice
if c.Parent != "" {
slice = c.Parent
}

properties = append(properties,
Expand Down Expand Up @@ -355,8 +355,8 @@ func getSubsystemPath(c *configs.Cgroup, subsystem string) (string, error) {
}

slice := "system.slice"
if c.Slice != "" {
slice = c.Slice
if c.Parent != "" {
slice = c.Parent
}

return filepath.Join(mountpoint, initPath, slice, getUnitName(c)), nil
Expand Down Expand Up @@ -420,7 +420,7 @@ func (m *Manager) Set(container *configs.Config) error {
}

func getUnitName(c *configs.Cgroup) string {
return fmt.Sprintf("%s-%s.scope", c.Parent, c.Name)
return fmt.Sprintf("%s-%s.scope", c.ScopePrefix, c.Name)
}

// Atm we can't use the systemd device support because of two missing things:
Expand Down
4 changes: 2 additions & 2 deletions configs/cgroup.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ type Cgroup struct {
// set the freeze value for the process
Freezer FreezerState `json:"freezer"`

// Parent slice to use for systemd TODO: remove in favor or parent
Slice string `json:"slice"`
// prefix for the scope name
ScopePrefix string `json:"scope_prefix"`

// Whether to disable OOM Killer
OomKillDisable bool `json:"oom_kill_disable"`
Expand Down
2 changes: 1 addition & 1 deletion integration/exec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ func testCpuShares(t *testing.T, systemd bool) {

config := newTemplateConfig(rootfs)
if systemd {
config.Cgroups.Slice = "system.slice"
config.Cgroups.Parent = "system.slice"
}
config.Cgroups.CpuShares = 1

Expand Down
8 changes: 7 additions & 1 deletion nsinit/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var createFlags = []cli.Flag{
cli.IntFlag{Name: "memory-swap", Usage: "set the memory swap limit for the container"},
cli.StringFlag{Name: "cpuset-cpus", Usage: "set the cpuset cpus"},
cli.StringFlag{Name: "cpuset-mems", Usage: "set the cpuset mems"},
cli.StringFlag{Name: "cgroup-parent", Usage: "set the cgroup parent"},
cli.StringFlag{Name: "apparmor-profile", Usage: "set the apparmor profile"},
cli.StringFlag{Name: "process-label", Usage: "set the process label"},
cli.StringFlag{Name: "mount-label", Usage: "set the mount label"},
Expand Down Expand Up @@ -93,6 +94,11 @@ func modify(config *configs.Config, context *cli.Context) {
config.Rootfs = rootfs
}

cgroupParent := context.String("cgroup-parent")
if cgroupParent != "" {
config.Cgroups.Parent = cgroupParent
}

userns_uid := context.Int("userns-root-uid")
if userns_uid != 0 {
config.Namespaces.Add(configs.NEWUSER, "")
Expand Down Expand Up @@ -229,7 +235,7 @@ func getTemplate() *configs.Config {
}),
Cgroups: &configs.Cgroup{
Name: filepath.Base(cwd),
Parent: "nsinit",
ScopePrefix: "nsinit",
AllowAllDevices: false,
AllowedDevices: configs.DefaultAllowedDevices,
},
Expand Down

0 comments on commit bd948ae

Please sign in to comment.