@@ -22,6 +22,7 @@ import (
2222 "github.com/opencontainers/runc/libcontainer/cgroups"
2323 "github.com/opencontainers/runc/libcontainer/configs"
2424 "github.com/opencontainers/runc/libcontainer/criurpc"
25+ "github.com/opencontainers/runc/libcontainer/resourcemanager"
2526 "github.com/opencontainers/runc/libcontainer/system"
2627 "github.com/opencontainers/runc/libcontainer/utils"
2728 "github.com/syndtr/gocapability/capability"
@@ -34,7 +35,7 @@ type linuxContainer struct {
3435 id string
3536 root string
3637 config * configs.Config
37- cgroupManager cgroups. Manager
38+ resourceManagers map [ string ]resourcemanager. ResourceManager
3839 initArgs []string
3940 initProcess parentProcess
4041 initProcessStartTime string
@@ -145,7 +146,7 @@ func (c *linuxContainer) State() (*State, error) {
145146}
146147
147148func (c * linuxContainer ) Processes () ([]int , error ) {
148- pids , err := c .cgroupManager .GetAllPids ()
149+ pids , err := c .resourceManagers [ "cgroups" ] .GetAllPids ()
149150 if err != nil {
150151 return nil , newSystemErrorWithCause (err , "getting all container pids from cgroups" )
151152 }
@@ -157,7 +158,9 @@ func (c *linuxContainer) Stats() (*Stats, error) {
157158 err error
158159 stats = & Stats {}
159160 )
160- if stats .CgroupStats , err = c .cgroupManager .GetStats (); err != nil {
161+ cgroupStats , err := c .resourceManagers ["cgroups" ].GetStats ()
162+ stats .CgroupStats = cgroupStats .(* cgroups.Stats )
163+ if err != nil {
161164 return stats , newSystemErrorWithCause (err , "getting container stats from cgroups" )
162165 }
163166 for _ , iface := range c .config .Networks {
@@ -184,7 +187,12 @@ func (c *linuxContainer) Set(config configs.Config) error {
184187 return newGenericError (fmt .Errorf ("container not running" ), ContainerNotRunning )
185188 }
186189 c .config = & config
187- return c .cgroupManager .Set (c .config )
190+ for _ , resourceManager := range c .resourceManagers {
191+ if err := resourceManager .Set (c .config ); err != nil {
192+ return err
193+ }
194+ }
195+ return nil
188196}
189197
190198func (c * linuxContainer ) Start (process * Process ) error {
@@ -298,7 +306,7 @@ func (c *linuxContainer) start(process *Process, isInit bool) error {
298306
299307func (c * linuxContainer ) Signal (s os.Signal , all bool ) error {
300308 if all {
301- return signalAllProcesses (c .cgroupManager , s )
309+ return signalAllProcesses (c .resourceManagers [ "cgroups" ] , s )
302310 }
303311 if err := c .initProcess .signal (s ); err != nil {
304312 return newSystemErrorWithCause (err , "signaling init process" )
@@ -410,7 +418,7 @@ func (c *linuxContainer) newInitProcess(p *Process, cmd *exec.Cmd, parentPipe, c
410418 cmd : cmd ,
411419 childPipe : childPipe ,
412420 parentPipe : parentPipe ,
413- manager : c . cgroupManager ,
421+ managers : c . resourceManagers ,
414422 config : c .newInitConfig (p ),
415423 container : c ,
416424 process : p ,
@@ -434,7 +442,7 @@ func (c *linuxContainer) newSetnsProcess(p *Process, cmd *exec.Cmd, parentPipe,
434442 }
435443 return & setnsProcess {
436444 cmd : cmd ,
437- cgroupPaths : c .cgroupManager .GetPaths (),
445+ cgroupPaths : c .resourceManagers [ "cgroups" ] .GetPaths (),
438446 childPipe : childPipe ,
439447 parentPipe : parentPipe ,
440448 config : c .newInitConfig (p ),
@@ -491,7 +499,7 @@ func (c *linuxContainer) Pause() error {
491499 }
492500 switch status {
493501 case Running , Created :
494- if err := c .cgroupManager .Freeze (configs .Frozen ); err != nil {
502+ if err := c .resourceManagers [ "cgroups" ] .Freeze (configs .Frozen ); err != nil {
495503 return err
496504 }
497505 return c .state .transition (& pausedState {
@@ -511,7 +519,7 @@ func (c *linuxContainer) Resume() error {
511519 if status != Paused {
512520 return newGenericError (fmt .Errorf ("container not paused" ), ContainerNotPaused )
513521 }
514- if err := c .cgroupManager .Freeze (configs .Thawed ); err != nil {
522+ if err := c .resourceManagers [ "cgroups" ] .Freeze (configs .Thawed ); err != nil {
515523 return err
516524 }
517525 return c .state .transition (& runningState {
@@ -524,15 +532,15 @@ func (c *linuxContainer) NotifyOOM() (<-chan struct{}, error) {
524532 if c .config .Rootless {
525533 return nil , fmt .Errorf ("cannot get OOM notifications from rootless container" )
526534 }
527- return notifyOnOOM (c .cgroupManager .GetPaths ())
535+ return notifyOnOOM (c .resourceManagers [ "cgroups" ] .GetPaths ())
528536}
529537
530538func (c * linuxContainer ) NotifyMemoryPressure (level PressureLevel ) (<- chan struct {}, error ) {
531539 // XXX(cyphar): This requires cgroups.
532540 if c .config .Rootless {
533541 return nil , fmt .Errorf ("cannot get memory pressure notifications from rootless container" )
534542 }
535- return notifyMemoryPressure (c .cgroupManager .GetPaths (), level )
543+ return notifyMemoryPressure (c .resourceManagers [ "cgroups" ] .GetPaths (), level )
536544}
537545
538546// checkCriuVersion checks Criu version greater than or equal to minVersion
@@ -945,7 +953,7 @@ func (c *linuxContainer) Restore(process *Process, criuOpts *CriuOpts) error {
945953
946954func (c * linuxContainer ) criuApplyCgroups (pid int , req * criurpc.CriuReq ) error {
947955 // XXX: Do we need to deal with this case? AFAIK criu still requires root.
948- if err := c .cgroupManager .Apply (pid ); err != nil {
956+ if err := c .resourceManagers [ "cgroups" ] .Apply (pid ); err != nil {
949957 return err
950958 }
951959
@@ -1311,7 +1319,7 @@ func (c *linuxContainer) runType() (Status, error) {
13111319}
13121320
13131321func (c * linuxContainer ) isPaused () (bool , error ) {
1314- data , err := ioutil .ReadFile (filepath .Join (c .cgroupManager .GetPaths ()["freezer" ], "freezer.state" ))
1322+ data , err := ioutil .ReadFile (filepath .Join (c .resourceManagers [ "cgroups" ] .GetPaths ()["freezer" ], "freezer.state" ))
13151323 if err != nil {
13161324 // If freezer cgroup is not mounted, the container would just be not paused.
13171325 if os .IsNotExist (err ) {
@@ -1342,7 +1350,7 @@ func (c *linuxContainer) currentState() (*State, error) {
13421350 Created : c .created ,
13431351 },
13441352 Rootless : c .config .Rootless ,
1345- CgroupPaths : c .cgroupManager .GetPaths (),
1353+ CgroupPaths : c .resourceManagers [ "cgroups" ] .GetPaths (),
13461354 NamespacePaths : make (map [configs.NamespaceType ]string ),
13471355 ExternalDescriptors : externalDescriptors ,
13481356 }
0 commit comments