Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
libct/cg: allow Set(nil)
Browse files Browse the repository at this point in the history
As the cgroup config is already supplied during Apply(), allow Set()
to accept nil -- in which case it uses the resources from the config.

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
kolyshkin committed Apr 13, 2021
1 parent 499fb99 commit dc35884
Showing 4 changed files with 18 additions and 2 deletions.
3 changes: 2 additions & 1 deletion libcontainer/cgroups/fs/fs.go
Original file line number Diff line number Diff line change
@@ -276,7 +276,7 @@ func (m *manager) GetStats() (*cgroups.Stats, error) {

func (m *manager) Set(r *configs.Resources) error {
if r == nil {
return nil
r = m.cgroups.Resources
}

// If Paths are set, then we are just joining cgroups paths
@@ -308,6 +308,7 @@ func (m *manager) Set(r *configs.Resources) error {
}
}

m.cgroups.Resources = r
return nil
}

3 changes: 3 additions & 0 deletions libcontainer/cgroups/fs2/fs2.go
Original file line number Diff line number Diff line change
@@ -164,6 +164,9 @@ func (m *manager) Path(_ string) string {
}

func (m *manager) Set(r *configs.Resources) error {
if r == nil {
r = m.config.Resources
}
if err := m.getControllers(); err != nil {
return err
}
4 changes: 4 additions & 0 deletions libcontainer/cgroups/systemd/v1.go
Original file line number Diff line number Diff line change
@@ -337,6 +337,9 @@ func (m *legacyManager) Set(r *configs.Resources) error {
if m.cgroups.Paths != nil {
return nil
}
if r == nil {
r = m.cgroups.Resources
}
if r.Unified != nil {
return cgroups.ErrV1NoUnified
}
@@ -392,6 +395,7 @@ func (m *legacyManager) Set(r *configs.Resources) error {
}
}

m.cgroups.Resources = r
return nil
}

10 changes: 9 additions & 1 deletion libcontainer/cgroups/systemd/v2.go
Original file line number Diff line number Diff line change
@@ -426,6 +426,9 @@ func (m *unifiedManager) GetStats() (*cgroups.Stats, error) {
}

func (m *unifiedManager) Set(r *configs.Resources) error {
if r == nil {
r = m.cgroups.Resources
}
dbusConnection, err := getDbusConnection(m.rootless)
if err != nil {
return err
@@ -471,7 +474,12 @@ func (m *unifiedManager) Set(r *configs.Resources) error {
if err != nil {
return err
}
return fsMgr.Set(r)
if err := fsMgr.Set(r); err != nil {
return err
}

m.cgroups.Resources = r
return nil
}

func (m *unifiedManager) GetPaths() map[string]string {

0 comments on commit dc35884

Please sign in to comment.