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 Apr 21, 2015
1 parent bada39c commit 6893ab1
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
10 changes: 5 additions & 5 deletions cgroups/systemd/apply_systemd.go
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,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 @@ -312,8 +312,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 @@ -377,7 +377,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 @@ -52,8 +52,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
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 @@ -92,6 +93,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 @@ -222,7 +228,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 6893ab1

Please sign in to comment.