Skip to content

Commit

Permalink
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.

While at it, don't forget to save the new resources into the manager's
internal state (previously only fs driver did that).

Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
  • Loading branch information
kolyshkin committed Apr 15, 2021
1 parent 49653ed commit b022cff
Show file tree
Hide file tree
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
Expand Up @@ -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
Expand Down Expand Up @@ -308,6 +308,7 @@ func (m *manager) Set(r *configs.Resources) error {
}
}

m.cgroups.Resources = r
return nil
}

Expand Down
3 changes: 3 additions & 0 deletions libcontainer/cgroups/fs2/fs2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 4 additions & 0 deletions libcontainer/cgroups/systemd/v1.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -392,6 +395,7 @@ func (m *legacyManager) Set(r *configs.Resources) error {
}
}

m.cgroups.Resources = r
return nil
}

Expand Down
10 changes: 9 additions & 1 deletion libcontainer/cgroups/systemd/v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit b022cff

Please sign in to comment.