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 previously cached resources
(specified either during Manager creation, or previous call to Set()
with non-nil argument).

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 23, 2021
1 parent 0644cf6 commit c3d3dbb
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 2 deletions.
6 changes: 5 additions & 1 deletion libcontainer/cgroups/fs/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,10 @@ 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 r == nil {
return nil
}
}

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

m.cgroups.Resources = r
return nil
}

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

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

m.cgroups.Resources = r
return nil
}

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

func (m *unifiedManager) Set(r *configs.Resources) error {
if r == nil {
r = m.cgroups.Resources
if r == nil {
return nil
}
}
dbusConnection, err := getDbusConnection(m.rootless)
if err != nil {
return err
Expand Down Expand Up @@ -471,7 +477,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 c3d3dbb

Please sign in to comment.